1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 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, "term dc.title", "comb");
81 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
82 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r", "term");
83 ccl_qual_fitem(bibset, "t=x", "reg");
84 ccl_qual_fitem(bibset, "t=z", "z");
85 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
86 ccl_qual_fitem(bibset, "r=r,omiteq", "date");
87 ccl_qual_fitem(bibset, "r=o", "x");
88 ccl_qual_fitem(bibset, "dc.title", "title");
89 ccl_qual_fitem(bibset, "s=ag", "ag");
90 ccl_qual_fitem(bibset, "s=sl", "splitlist");
93 strcpy(tstline, "ti u=4 s=pw t=l,r");
94 ccl_qual_line(bibset, tstline);
96 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
97 ccl_qual_line(bibset, tstline);
99 strcpy(tstline, "reg t=x");
100 ccl_qual_line(bibset, tstline);
102 strcpy(tstline, "z t=z");
103 ccl_qual_line(bibset, tstline);
105 strcpy(tstline, "dc.title 1=/my/title");
106 ccl_qual_line(bibset, tstline);
108 strcpy(tstline, "date r=r,omiteq # ordered relation");
109 ccl_qual_line(bibset, tstline);
111 strcpy(tstline, "x r=o # ordered relation");
112 ccl_qual_line(bibset, tstline);
114 strcpy(tstline, "title dc.title # alias");
115 ccl_qual_line(bibset, tstline);
117 strcpy(tstline, "comb term dc.title # combination");
118 ccl_qual_line(bibset, tstline);
120 strcpy(tstline, "ag s=ag");
121 ccl_qual_line(bibset, tstline);
123 strcpy(tstline, "splitlist s=sl");
124 ccl_qual_line(bibset, tstline);
127 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
128 "term 1=1016 s=al,pw t=r\r\n"
132 "dc.title 1=/my/title\n"
136 "comb term dc.title\n"
147 const char *addinfo = 0;
148 const char *xml_str =
150 " <qual name=\"ti\">\n"
151 " <attr type=\"u\" value=\"4\"/>\n"
152 " <attr type=\"s\" value=\"pw\"/>\n"
153 " <attr type=\"t\" value=\"l,r\"/>\n"
155 " <qual name=\"term\">\n"
156 " <attr type=\"1\" value=\"1016\"/>\n"
157 " <attr type=\"s\" value=\"al,pw\"/>\n"
158 " <attr type=\"t\" value=\"r\"/>\n"
160 " <qual name=\"reg\">\n"
161 " <attr type=\"t\" value=\"x\"/>\n"
163 " <qual name=\"z\">\n"
164 " <attr type=\"t\" value=\"z\"/>\n"
166 " <qual name=\"dc.title\">\n"
167 " <attr type=\"1\" value=\"/my/title\"/>\n"
169 " <qual name=\"date\">\n"
170 " <attr type=\"r\" value=\"r,omiteq\"/>\n"
172 " <qual name=\"x\">\n"
173 " <attr type=\"r\" value=\"o\"/>\n"
175 " <qual name=\"title\">\n"
176 " <qual name=\"dc.title\"/>\n"
178 " <qual name=\"comb\">\n"
179 " <qual name=\"term\"/>\n"
180 " <qual name=\"dc.title\"/>\n"
182 " <qual name=\"ag\">\n"
183 " <attr type=\"s\" value=\"ag\"/>\n"
185 " <qual name=\"splitlist\">\n"
186 " <attr type=\"s\" value=\"sl\"/>\n"
190 doc = xmlParseMemory(xml_str, strlen(xml_str));
193 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
207 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
209 YAZ_CHECK(tst_ccl_query(bibset, "k\xc3\xb8" "benhavn", "@attr 4=2 @attr 1=1016 k\xc3\xb8" "benhavn "));
211 YAZ_CHECK(tst_ccl_query(bibset, "k\xf8" "benhavn", "@attr 4=2 @attr 1=1016 ""k\xf8" "benhavn "));
213 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
214 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
216 "@attr 4=2 @attr 1=1016 x1 "
217 "@attr 4=2 @attr 1=1016 x2 "));
218 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
219 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
220 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=(x4)", "@attr 1=/my/title x4 "));
221 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
222 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
224 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
226 "@attr 4=2 @attr 1=1016 a "
227 "@attr 4=2 @attr 1=1016 b "));
228 YAZ_CHECK(tst_ccl_query(bibset, "a%(b)",
230 "@attr 4=2 @attr 1=1016 a "
231 "@attr 4=2 @attr 1=1016 b "));
232 YAZ_CHECK(tst_ccl_query(bibset, "(a)%(b)",
234 "@attr 4=2 @attr 1=1016 a "
235 "@attr 4=2 @attr 1=1016 b "));
236 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
238 "@attr 4=2 @attr 1=1016 a "
239 "@attr 4=2 @attr 1=1016 b "));
241 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
243 "@attr 4=2 @attr 1=1016 a "
244 "@attr 4=2 @attr 1=1016 b "));
246 YAZ_CHECK(tst_ccl_query(bibset, "(a)%2(b)",
248 "@attr 4=2 @attr 1=1016 a "
249 "@attr 4=2 @attr 1=1016 b "));
251 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
252 "@prox 0 19 0 2 k 2 "
253 "@attr 4=2 @attr 1=1016 a "
254 "@attr 4=2 @attr 1=1016 b "));
256 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
258 "@attr 4=2 @attr 1=1016 spid "
259 "@attr 4=2 @attr 1=1016 æserne "));
261 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
263 "@attr 4=2 @attr 1=1016 a "
264 "@attr 4=2 @attr 1=1016 b "));
265 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
267 "@attr 4=2 @attr 1=1016 a "
268 "@attr 4=2 @attr 1=1016 b "));
270 YAZ_CHECK(tst_ccl_query(bibset, "a% (b or dc.title=c)",
272 "@attr 4=2 @attr 1=1016 a "
273 "@or @attr 4=2 @attr 1=1016 b "
274 "@or @attr 4=2 @attr 1=/my/title c "
275 "@attr 4=2 @attr 1=1016 c "
278 YAZ_CHECK(tst_ccl_query(bibset, "(a b) % (c)",
279 "@prox 0 1 0 2 k 2 @and "
280 "@attr 4=2 @attr 1=1016 a @attr 4=2 @attr 1=1016 b "
281 "@attr 4=2 @attr 1=1016 c " ));
283 YAZ_CHECK(tst_ccl_query(bibset, "date=1980",
285 YAZ_CHECK(tst_ccl_query(bibset, "(date=1980)",
287 YAZ_CHECK(tst_ccl_query(bibset, "date>1980",
289 YAZ_CHECK(tst_ccl_query(bibset, "date>=1980",
291 YAZ_CHECK(tst_ccl_query(bibset, "date<1980",
293 YAZ_CHECK(tst_ccl_query(bibset, "date<=1980",
295 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990",
296 "@and @attr 2=4 234 @attr 2=2 1990 "));
297 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990",
298 "@and @attr 2=4 234 @attr 2=2 1990 "));
299 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990",
300 "@and @attr 2=4 234 @attr 2=2 1990 "));
301 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990",
302 "@and @attr 2=4 234 @attr 2=2 1990 "));
303 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980",
305 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980",
307 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980",
308 "@attr 2=3 -1980 "));
309 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980",
311 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980",
312 "@attr 2=3 -1980 "));
313 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990",
314 "@attr 2=3 234-1990 "));
315 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990",
316 "@and @attr 2=4 234 @attr 2=2 1990 "));
317 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b",
318 "@attr 4=1 @attr 1=4 a,b "));
319 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b",
320 "@attr 4=1 @attr 1=4 \"a, b\" "));
321 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b",
322 "@attr 4=2 @attr 1=4 a-b "));
323 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b",
324 "@attr 4=1 @attr 1=4 \"a - b\" "));
326 YAZ_CHECK(tst_ccl_query(bibset, "a?",
327 "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
328 YAZ_CHECK(tst_ccl_query(bibset, "a b",
329 "@and @attr 4=2 @attr 1=1016 a "
330 "@attr 4=2 @attr 1=1016 b "));
332 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
333 "@and @attr 4=2 @attr 1=1016 a "
334 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
336 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
337 "@attr 1=/my/title a "));
339 YAZ_CHECK(tst_ccl_query(bibset, "reg=a?b#\"c?\"",
340 "@attr 5=102 a.*b.c\\\\? "));
341 YAZ_CHECK(tst_ccl_query(bibset, "z=a?b#\"c?\"",
342 "@attr 5=104 a?b#c\\\\? "));
344 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\(",
346 YAZ_CHECK(tst_ccl_query(bibset, "z=\\(",
349 YAZ_CHECK(tst_ccl_query(bibset, "z=a b#",
350 "@attr 5=104 \"a b#\" "));
352 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\"",
354 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\"",
357 YAZ_CHECK(tst_ccl_query(bibset, "reg=.",
359 YAZ_CHECK(tst_ccl_query(bibset, "z=.",
362 YAZ_CHECK(tst_ccl_query(bibset, "reg=\".\"",
364 YAZ_CHECK(tst_ccl_query(bibset, "z=\".\"",
367 YAZ_CHECK(tst_ccl_query(bibset, "reg=?\\?",
368 "@attr 5=102 .*\\\\? "));
369 YAZ_CHECK(tst_ccl_query(bibset, "z=?\\?",
370 "@attr 5=104 ?\\\\? "));
372 YAZ_CHECK(tst_ccl_query(bibset, "reg=\"?\\?\"",
374 YAZ_CHECK(tst_ccl_query(bibset, "z=\"?\\?\"",
377 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\\",
379 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\\",
382 YAZ_CHECK(tst_ccl_query(bibset, "\\\\",
383 "@attr 4=2 @attr 1=1016 \\\\ "));
385 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
386 "@or @attr 4=2 @attr 1=1016 a "
387 "@attr 1=/my/title a "));
389 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
390 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
391 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
393 YAZ_CHECK(tst_ccl_query(bibset, "\"a\"? \"b?\"",
394 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
395 "@attr 4=2 @attr 1=1016 b? "));
397 YAZ_CHECK(tst_ccl_query(bibset, "@and",
398 "@attr 4=2 @attr 1=1016 \\@and "));
400 YAZ_CHECK(tst_ccl_query(bibset, "a@and",
401 "@attr 4=2 @attr 1=1016 a@and "));
403 YAZ_CHECK(tst_ccl_query(bibset, "}",
404 "@attr 4=2 @attr 1=1016 } "));
406 YAZ_CHECK(tst_ccl_query(bibset, "{",
407 "@attr 4=2 @attr 1=1016 \"{\" "));
409 YAZ_CHECK(tst_ccl_query(bibset, "\"a b c\"",
410 "@attr 4=1 @attr 1=1016 \"a b c\" "));
412 YAZ_CHECK(tst_ccl_query(bibset, "\"a b c \"",
413 "@attr 4=1 @attr 1=1016 \"a b c \" "));
415 YAZ_CHECK(tst_ccl_query(bibset, "ag=a",
418 YAZ_CHECK(tst_ccl_query(bibset, "ag=a b",
419 "@attr 4=2 \"a b\" "));
421 YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"c d\"",
422 "@and @attr 4=2 \"a b\" @attr 4=1 \"c d\" "));
424 YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"c\"",
425 "@attr 4=2 \"a b c\" "));
427 YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"\"",
428 "@attr 4=2 \"a b \" "));
430 YAZ_CHECK(tst_ccl_query(bibset, "ag=a \"b c\" d",
432 "@attr 4=2 a @attr 4=1 \"b c\" @attr 4=2 d "));
434 YAZ_CHECK(tst_ccl_query(bibset, "ag=\"a b c\"",
435 "@attr 4=1 \"a b c\" "));
437 YAZ_CHECK(tst_ccl_query(bibset, "ag=\"a b c\" \"d e\"",
438 "@and @attr 4=1 \"a b c\" @attr 4=1 \"d e\" "));
440 YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a", "a "));
441 YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b", "@or "
442 "@and a b \"a b\" "));
443 YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b c", "@or @or @or "
448 ccl_qual_rm(&bibset);
453 CCL_bibset bibset = ccl_qual_mk();
459 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
460 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=z", "term");
462 YAZ_CHECK(tst_ccl_query(bibset, "a?#",
463 "@attr 5=104 @attr 4=2 @attr 1=1016 a?# "));
465 YAZ_CHECK(tst_ccl_query(bibset, "a b?#",
466 "@and @attr 4=2 @attr 1=1016 a @attr 5=104 @attr 4=2 @attr 1=1016 b?# "));
468 YAZ_CHECK(tst_ccl_query(bibset, "a*",
469 "@attr 4=2 @attr 1=1016 a* "));
471 YAZ_CHECK(tst_ccl_query(bibset, "a?",
472 "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
474 ccl_qual_fitem(bibset, "*", "@truncation");
475 YAZ_CHECK(tst_ccl_query(bibset, "a*",
476 "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
478 YAZ_CHECK(tst_ccl_query(bibset, "a?",
479 "@attr 4=2 @attr 1=1016 a? "));
481 ccl_qual_fitem(bibset, "?", "@mask");
482 YAZ_CHECK(tst_ccl_query(bibset, "a?",
483 "@attr 5=104 @attr 4=2 @attr 1=1016 a# "));
486 ccl_qual_fitem(bibset, "", "@mask");
487 ccl_qual_fitem(bibset, "", "@truncation");
488 YAZ_CHECK(tst_ccl_query(bibset, "a?#",
489 "@attr 4=2 @attr 1=1016 a?# "));
491 ccl_qual_fitem(bibset, "og", "@and");
492 ccl_qual_fitem(bibset, "eller", "@or");
493 ccl_qual_fitem(bibset, "ikke", "@not");
495 YAZ_CHECK(tst_ccl_query(bibset, "a og b eller c ikke d",
496 "@not @or @and @attr 4=2 @attr 1=1016 a "
497 "@attr 4=2 @attr 1=1016 b "
498 "@attr 4=2 @attr 1=1016 c "
499 "@attr 4=2 @attr 1=1016 d "));
500 ccl_qual_rm(&bibset);
504 void tst_addinfo(void)
508 CCL_bibset bibset = ccl_qual_mk();
510 r = ccl_qual_fitem2(bibset, "u=4 s=pw t=l,r", "ti", &addinfo);
511 YAZ_CHECK(r == 0 && addinfo == 0);
513 r = ccl_qual_fitem2(bibset, "1=1016 s=al,pw t=z", "term", &addinfo);
514 YAZ_CHECK(r == 0 && addinfo == 0);
516 r = ccl_qual_fitem2(bibset, "x=", "term", &addinfo);
517 YAZ_CHECK(r != 0 && addinfo != 0);
519 r = ccl_qual_fitem2(bibset, "12=3", "term", &addinfo);
520 YAZ_CHECK(r == 0 && addinfo == 0);
522 r = ccl_qual_fitem2(bibset, "ab=3", "term", &addinfo);
523 YAZ_CHECK(r != 0 && addinfo != 0);
525 r = ccl_qual_fitem2(bibset, "x=ab", "term", &addinfo);
526 YAZ_CHECK(r != 0 && addinfo != 0);
528 r = ccl_qual_fitem2(bibset, "s=ab", "term", &addinfo);
529 YAZ_CHECK(r == 0 && addinfo == 0);
531 ccl_qual_rm(&bibset);
534 int main(int argc, char **argv)
536 YAZ_CHECK_INIT(argc, argv);
549 * c-file-style: "Stroustrup"
550 * indent-tabs-mode: nil
552 * vim: shiftwidth=4 tabstop=8 expandtab