1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 Index Data
3 * See the file LICENSE for details.
10 #include <yaz/ccl_xml.h>
15 static int tst_ccl_query(CCL_bibset bibset,
19 CCL_parser parser = ccl_parser_create(bibset);
24 struct ccl_rpn_node *rpn;
26 rpn = ccl_parser_find_str(parser, query);
29 /* parse ok. check that result is there and match */
30 WRBUF wrbuf = wrbuf_alloc();
31 ccl_pquery(wrbuf, rpn);
33 /* check expect a result and that it matches */
34 if (result && !strcmp(wrbuf_cstr(wrbuf), result))
38 yaz_log(YLOG_WARN, "%s: result does not match", query);
39 yaz_log(YLOG_WARN, " expected %s", result);
40 yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(wrbuf));
50 yaz_log(YLOG_WARN, "%s: parse failed", query);
57 ccl_parser_destroy (parser);
63 CCL_bibset bibset = ccl_qual_mk();
72 CCL_bibset nbibset = ccl_qual_dup(bibset);
80 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
81 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r", "term");
82 ccl_qual_fitem(bibset, "t=x", "reg");
83 ccl_qual_fitem(bibset, "t=z", "z");
84 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
85 ccl_qual_fitem(bibset, "r=r", "date");
86 ccl_qual_fitem(bibset, "r=o", "x");
87 ccl_qual_fitem(bibset, "dc.title", "title");
88 ccl_qual_fitem(bibset, "term dc.title", "comb");
91 strcpy(tstline, "ti u=4 s=pw t=l,r");
92 ccl_qual_line(bibset, tstline);
94 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
95 ccl_qual_line(bibset, tstline);
97 strcpy(tstline, "reg t=x");
98 ccl_qual_line(bibset, tstline);
100 strcpy(tstline, "z t=z");
101 ccl_qual_line(bibset, tstline);
103 strcpy(tstline, "dc.title 1=/my/title");
104 ccl_qual_line(bibset, tstline);
106 strcpy(tstline, "date r=r # ordered relation");
107 ccl_qual_line(bibset, tstline);
109 strcpy(tstline, "x r=o # ordered relation");
110 ccl_qual_line(bibset, tstline);
112 strcpy(tstline, "title dc.title # alias");
113 ccl_qual_line(bibset, tstline);
115 strcpy(tstline, "comb term dc.title # combination");
116 ccl_qual_line(bibset, tstline);
119 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
120 "term 1=1016 s=al,pw t=r\r\n"
124 "dc.title 1=/my/title\n"
128 "comb term dc.title\n"
137 const char *addinfo = 0;
138 const char *xml_str =
140 " <qual name=\"ti\">\n"
141 " <attr type=\"u\" value=\"4\"/>\n"
142 " <attr type=\"s\" value=\"pw\"/>\n"
143 " <attr type=\"t\" value=\"l,r\"/>\n"
145 " <qual name=\"term\">\n"
146 " <attr type=\"1\" value=\"1016\"/>\n"
147 " <attr type=\"s\" value=\"al,pw\"/>\n"
148 " <attr type=\"t\" value=\"r\"/>\n"
150 " <qual name=\"reg\">\n"
151 " <attr type=\"t\" value=\"x\"/>\n"
153 " <qual name=\"z\">\n"
154 " <attr type=\"t\" value=\"z\"/>\n"
156 " <qual name=\"dc.title\">\n"
157 " <attr type=\"1\" value=\"/my/title\"/>\n"
159 " <qual name=\"date\">\n"
160 " <attr type=\"r\" value=\"r\"/>\n"
162 " <qual name=\"x\">\n"
163 " <attr type=\"r\" value=\"o\"/>\n"
165 " <qual name=\"title\">\n"
166 " <qual name=\"dc.title\"/>\n"
168 " <qual name=\"comb\">\n"
169 " <qual name=\"term\"/>\n"
170 " <qual name=\"dc.title\"/>\n"
174 doc = xmlParseMemory(xml_str, strlen(xml_str));
177 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
191 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
193 YAZ_CHECK(tst_ccl_query(bibset, "k\xc3\xb8" "benhavn", "@attr 4=2 @attr 1=1016 k\xc3\xb8" "benhavn "));
195 YAZ_CHECK(tst_ccl_query(bibset, "k\xf8" "benhavn", "@attr 4=2 @attr 1=1016 ""k\xf8" "benhavn "));
197 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
198 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
200 "@attr 4=2 @attr 1=1016 x1 "
201 "@attr 4=2 @attr 1=1016 x2 "));
202 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
203 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
204 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=(x4)", "@attr 1=/my/title x4 "));
205 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
206 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
208 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
210 "@attr 4=2 @attr 1=1016 a "
211 "@attr 4=2 @attr 1=1016 b "));
212 YAZ_CHECK(tst_ccl_query(bibset, "a%(b)",
214 "@attr 4=2 @attr 1=1016 a "
215 "@attr 4=2 @attr 1=1016 b "));
216 YAZ_CHECK(tst_ccl_query(bibset, "(a)%(b)",
218 "@attr 4=2 @attr 1=1016 a "
219 "@attr 4=2 @attr 1=1016 b "));
220 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
222 "@attr 4=2 @attr 1=1016 a "
223 "@attr 4=2 @attr 1=1016 b "));
225 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
227 "@attr 4=2 @attr 1=1016 a "
228 "@attr 4=2 @attr 1=1016 b "));
230 YAZ_CHECK(tst_ccl_query(bibset, "(a)%2(b)",
232 "@attr 4=2 @attr 1=1016 a "
233 "@attr 4=2 @attr 1=1016 b "));
235 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
236 "@prox 0 19 0 2 k 2 "
237 "@attr 4=2 @attr 1=1016 a "
238 "@attr 4=2 @attr 1=1016 b "));
240 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
242 "@attr 4=2 @attr 1=1016 spid "
243 "@attr 4=2 @attr 1=1016 æserne "));
245 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
247 "@attr 4=2 @attr 1=1016 a "
248 "@attr 4=2 @attr 1=1016 b "));
249 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
251 "@attr 4=2 @attr 1=1016 a "
252 "@attr 4=2 @attr 1=1016 b "));
254 YAZ_CHECK(tst_ccl_query(bibset, "a% (b or dc.title=c)",
256 "@attr 4=2 @attr 1=1016 a "
257 "@or @attr 4=2 @attr 1=1016 b "
258 "@attr 4=2 @attr 1=1016 @attr 1=/my/title c "));
260 YAZ_CHECK(tst_ccl_query(bibset, "(a b) % (c)",
261 "@prox 0 1 0 2 k 2 @and "
262 "@attr 4=2 @attr 1=1016 a @attr 4=2 @attr 1=1016 b "
263 "@attr 4=2 @attr 1=1016 c " ));
265 YAZ_CHECK(tst_ccl_query(bibset, "date=1980",
267 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990",
268 "@and @attr 2=4 234 @attr 2=2 1990 "));
269 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990",
270 "@and @attr 2=4 234 @attr 2=2 1990 "));
271 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990",
272 "@and @attr 2=4 234 @attr 2=2 1990 "));
273 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990",
274 "@and @attr 2=4 234 @attr 2=2 1990 "));
275 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980",
277 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980",
279 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980",
280 "@attr 2=3 -1980 "));
281 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980",
283 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980",
284 "@attr 2=3 -1980 "));
285 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990",
286 "@attr 2=3 234-1990 "));
287 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990",
288 "@and @attr 2=4 234 @attr 2=2 1990 "));
289 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b",
290 "@attr 4=1 @attr 1=4 a,b "));
291 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b",
292 "@attr 4=1 @attr 1=4 \"a, b\" "));
293 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b",
294 "@attr 4=2 @attr 1=4 a-b "));
295 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b",
296 "@attr 4=1 @attr 1=4 \"a - b\" "));
298 YAZ_CHECK(tst_ccl_query(bibset, "a?",
299 "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
300 YAZ_CHECK(tst_ccl_query(bibset, "a b",
301 "@and @attr 4=2 @attr 1=1016 a "
302 "@attr 4=2 @attr 1=1016 b "));
304 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
305 "@and @attr 4=2 @attr 1=1016 a "
306 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
308 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
309 "@attr 1=/my/title a "));
311 YAZ_CHECK(tst_ccl_query(bibset, "reg=a?b#\"c?\"",
312 "@attr 5=102 a.*b.c\\\\? "));
313 YAZ_CHECK(tst_ccl_query(bibset, "z=a?b#\"c?\"",
314 "@attr 5=104 a?b#c\\\\? "));
316 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\(",
317 "@attr 5=102 \\\\( "));
318 YAZ_CHECK(tst_ccl_query(bibset, "z=\\(",
321 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\"",
323 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\"",
326 YAZ_CHECK(tst_ccl_query(bibset, "reg=.",
327 "@attr 5=102 \\\\. "));
328 YAZ_CHECK(tst_ccl_query(bibset, "z=.",
331 YAZ_CHECK(tst_ccl_query(bibset, "reg=\".\"",
332 "@attr 5=102 \\\\. "));
333 YAZ_CHECK(tst_ccl_query(bibset, "z=\".\"",
336 YAZ_CHECK(tst_ccl_query(bibset, "reg=?\\?",
337 "@attr 5=102 .*\\\\? "));
338 YAZ_CHECK(tst_ccl_query(bibset, "z=?\\?",
339 "@attr 5=104 ?\\\\? "));
341 YAZ_CHECK(tst_ccl_query(bibset, "reg=\"?\\?\"",
342 "@attr 5=102 \\\\?\\\\? "));
343 YAZ_CHECK(tst_ccl_query(bibset, "z=\"?\\?\"",
344 "@attr 5=104 \\\\?\\\\? "));
346 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\\",
347 "@attr 5=102 \\\\\\\\ "));
348 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\\",
349 "@attr 5=104 \\\\\\\\ "));
351 YAZ_CHECK(tst_ccl_query(bibset, "\\\\",
352 "@attr 4=2 @attr 1=1016 \\\\ "));
354 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
355 "@or @attr 4=2 @attr 1=1016 a "
356 "@attr 1=/my/title a "));
358 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
359 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
360 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
362 YAZ_CHECK(tst_ccl_query(bibset, "\"a\"? \"b?\"",
363 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
364 "@attr 4=2 @attr 1=1016 b? "));
366 YAZ_CHECK(tst_ccl_query(bibset, "@and",
367 "@attr 4=2 @attr 1=1016 \\@and "));
369 YAZ_CHECK(tst_ccl_query(bibset, "a@and",
370 "@attr 4=2 @attr 1=1016 a@and "));
372 YAZ_CHECK(tst_ccl_query(bibset, "}",
373 "@attr 4=2 @attr 1=1016 } "));
375 YAZ_CHECK(tst_ccl_query(bibset, "{",
376 "@attr 4=2 @attr 1=1016 \"{\" "));
378 YAZ_CHECK(tst_ccl_query(bibset, "\"a b c\"",
379 "@attr 4=1 @attr 1=1016 \"a b c\" "));
381 YAZ_CHECK(tst_ccl_query(bibset, "\"a b c \"",
382 "@attr 4=1 @attr 1=1016 \"a b c \" "));
384 ccl_qual_rm(&bibset);
389 CCL_bibset bibset = ccl_qual_mk();
395 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
396 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=z", "term");
398 YAZ_CHECK(tst_ccl_query(bibset, "a*",
399 "@attr 4=2 @attr 1=1016 a* "));
401 YAZ_CHECK(tst_ccl_query(bibset, "a?",
402 "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
404 ccl_qual_fitem(bibset, "*", "@truncation");
405 YAZ_CHECK(tst_ccl_query(bibset, "a*",
406 "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
408 YAZ_CHECK(tst_ccl_query(bibset, "a?",
409 "@attr 5=104 @attr 4=2 @attr 1=1016 a\\\\? "));
411 ccl_qual_fitem(bibset, "og", "@and");
412 ccl_qual_fitem(bibset, "eller", "@or");
413 ccl_qual_fitem(bibset, "ikke", "@not");
415 YAZ_CHECK(tst_ccl_query(bibset, "a og b eller c ikke d",
416 "@not @or @and @attr 4=2 @attr 1=1016 a "
417 "@attr 4=2 @attr 1=1016 b "
418 "@attr 4=2 @attr 1=1016 c "
419 "@attr 4=2 @attr 1=1016 d "));
420 ccl_qual_rm(&bibset);
424 int main(int argc, char **argv)
426 YAZ_CHECK_INIT(argc, argv);
438 * c-file-style: "Stroustrup"
439 * indent-tabs-mode: nil
441 * vim: shiftwidth=4 tabstop=8 expandtab