CCL: split-list deals with multiple use attr YAZ-844
[yaz-moved-to-github.git] / test / test_ccl.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5 #if HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8
9 #include <string.h>
10 #include <yaz/ccl_xml.h>
11 #include <yaz/log.h>
12 #include <yaz/test.h>
13
14
15 static int tst_ccl_query(CCL_bibset bibset,
16                          const char *query,
17                          const char *result)
18 {
19     CCL_parser parser = ccl_parser_create(bibset);
20     int ret = 0;
21
22     if (parser && bibset)
23     {
24         struct ccl_rpn_node *rpn;
25
26         rpn = ccl_parser_find_str(parser, query);
27         if (rpn)
28         {
29             /* parse ok. check that result is there and match */
30             WRBUF wrbuf = wrbuf_alloc();
31             ccl_pquery(wrbuf, rpn);
32
33             /* check expect a result and that it matches */
34             if (result && !strcmp(wrbuf_cstr(wrbuf), result))
35                 ret = 1;
36             else
37             {
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));
41                 ret = 0;
42             }
43             ccl_rpn_delete(rpn);
44             wrbuf_destroy(wrbuf);
45         }
46         else
47         {
48             if (result)
49             {
50                 yaz_log(YLOG_WARN, "%s: parse failed", query);
51                 ret = 0;
52             }
53             else
54                 ret = 1;
55         }
56     }
57     ccl_parser_destroy (parser);
58     return ret;
59 }
60
61 void tst1(int pass)
62 {
63     CCL_bibset bibset = ccl_qual_mk();
64     char tstline[128];
65
66     YAZ_CHECK(bibset);
67     if (!bibset)
68         return;
69
70     if (pass == 1)
71     {
72         CCL_bibset nbibset = ccl_qual_dup(bibset);
73         ccl_qual_rm(&bibset);
74         bibset = nbibset;
75     }
76
77     switch(pass)
78     {
79     case 0:
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 u=2", "splitlist");
91         ccl_qual_fitem(bibset, "s=sl u=2 u=3", "s2");
92         break;
93     case 1:
94         strcpy(tstline, "ti u=4    s=pw t=l,r");
95         ccl_qual_line(bibset, tstline);
96
97         strcpy(tstline, "term 1=1016 s=al,pw t=r  # default term");
98         ccl_qual_line(bibset, tstline);
99
100         strcpy(tstline, "reg t=x");
101         ccl_qual_line(bibset, tstline);
102
103         strcpy(tstline, "z t=z");
104         ccl_qual_line(bibset, tstline);
105
106         strcpy(tstline, "dc.title 1=/my/title");
107         ccl_qual_line(bibset, tstline);
108
109         strcpy(tstline, "date r=r,omiteq # ordered relation");
110         ccl_qual_line(bibset, tstline);
111
112         strcpy(tstline, "x r=o # ordered relation");
113         ccl_qual_line(bibset, tstline);
114
115         strcpy(tstline, "title dc.title # alias");
116         ccl_qual_line(bibset, tstline);
117
118         strcpy(tstline, "comb term dc.title # combination");
119         ccl_qual_line(bibset, tstline);
120
121         strcpy(tstline, "ag s=ag");
122         ccl_qual_line(bibset, tstline);
123
124         strcpy(tstline, "splitlist s=sl u=2");
125         ccl_qual_line(bibset, tstline);
126
127         strcpy(tstline, "s2 s=sl u=2 u=3");
128         ccl_qual_line(bibset, tstline);
129         break;
130     case 2:
131         ccl_qual_buf(bibset, "ti u=4    s=pw t=l,r\n"
132                      "term 1=1016 s=al,pw t=r\r\n"
133                      "\n"
134                      "reg t=x\r\n"
135                      "z t=z\r\n"
136                      "dc.title 1=/my/title\n"
137                      "date r=r,omiteq\n"
138                      "x r=o\n"
139                      "title dc.title\n"
140                      "comb term dc.title\n"
141                      "ag s=ag\n"
142                      "splitlist s=sl u=2\n"
143                      "s2 s=sl u=2 u=3\n"
144             );
145         break;
146     case 3:
147 #if YAZ_HAVE_XML2
148         if (1)
149         {
150             xmlDocPtr doc;
151             int r;
152             const char *addinfo = 0;
153             const char *xml_str =
154                 "<cclmap>\n"
155                 " <qual name=\"ti\">\n"
156                 "   <attr type=\"u\" value=\"4\"/>\n"
157                 "   <attr type=\"s\" value=\"pw\"/>\n"
158                 "   <attr type=\"t\" value=\"l,r\"/>\n"
159                 " </qual>\n"
160                 " <qual name=\"term\">\n"
161                 "   <attr type=\"1\" value=\"1016\"/>\n"
162                 "   <attr type=\"s\" value=\"al,pw\"/>\n"
163                 "   <attr type=\"t\" value=\"r\"/>\n"
164                 " </qual>\n"
165                 " <qual name=\"reg\">\n"
166                 "   <attr type=\"t\" value=\"x\"/>\n"
167                 " </qual>\n"
168                 " <qual name=\"z\">\n"
169                 "   <attr type=\"t\" value=\"z\"/>\n"
170                 " </qual>\n"
171                 " <qual name=\"dc.title\">\n"
172                 "   <attr type=\"1\" value=\"/my/title\"/>\n"
173                 " </qual>\n"
174                 " <qual name=\"date\">\n"
175                 "   <attr type=\"r\" value=\"r,omiteq\"/>\n"
176                 " </qual>\n"
177                 " <qual name=\"x\">\n"
178                 "   <attr type=\"r\" value=\"o\"/>\n"
179                 " </qual>\n"
180                 " <qual name=\"title\">\n"
181                 "   <qual name=\"dc.title\"/>\n"
182                 " </qual>\n"
183                 " <qual name=\"comb\">\n"
184                 "   <qual name=\"term\"/>\n"
185                 "   <qual name=\"dc.title\"/>\n"
186                 " </qual>\n"
187                 " <qual name=\"ag\">\n"
188                 "   <attr type=\"s\" value=\"ag\"/>\n"
189                 " </qual>\n"
190                 " <qual name=\"splitlist\">\n"
191                 "   <attr type=\"s\" value=\"sl\"/>\n"
192                 "   <attr type=\"u\" value=\"2\"/>\n"
193                 " </qual>\n"
194                 " <qual name=\"s2\">\n"
195                 "   <attr type=\"s\" value=\"sl\"/>\n"
196                 "   <attr type=\"u\" value=\"2\"/>\n"
197                 "   <attr type=\"u\" value=\"3\"/>\n"
198                 " </qual>\n"
199                 "</cclmap>\n";
200
201             doc = xmlParseMemory(xml_str, strlen(xml_str));
202             YAZ_CHECK(doc);
203
204             r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
205             YAZ_CHECK_EQ(r, 0);
206
207             xmlFreeDoc(doc);
208         }
209         break;
210 #else
211         return;
212 #endif
213     default:
214         YAZ_CHECK(0);
215         return;
216     }
217
218     YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
219
220     YAZ_CHECK(tst_ccl_query(bibset, "k\xc3\xb8" "benhavn", "@attr 4=2 @attr 1=1016 k\xc3\xb8" "benhavn "));
221
222     YAZ_CHECK(tst_ccl_query(bibset, "k\xf8" "benhavn", "@attr 4=2 @attr 1=1016 ""k\xf8" "benhavn "));
223
224     YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
225     YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
226                   "@and "
227                   "@attr 4=2 @attr 1=1016 x1 "
228                   "@attr 4=2 @attr 1=1016 x2 "));
229     YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
230     YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
231     YAZ_CHECK(tst_ccl_query(bibset, "dc.title=(x4)", "@attr 1=/my/title x4 "));
232     YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
233     YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
234
235     YAZ_CHECK(tst_ccl_query(bibset, "a%b",
236                   "@prox 0 1 0 2 k 2 "
237                   "@attr 4=2 @attr 1=1016 a "
238                   "@attr 4=2 @attr 1=1016 b "));
239     YAZ_CHECK(tst_ccl_query(bibset, "a%(b)",
240                   "@prox 0 1 0 2 k 2 "
241                   "@attr 4=2 @attr 1=1016 a "
242                   "@attr 4=2 @attr 1=1016 b "));
243     YAZ_CHECK(tst_ccl_query(bibset, "(a)%(b)",
244                   "@prox 0 1 0 2 k 2 "
245                   "@attr 4=2 @attr 1=1016 a "
246                   "@attr 4=2 @attr 1=1016 b "));
247     YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
248                   "@prox 0 1 0 2 k 2 "
249                   "@attr 4=2 @attr 1=1016 a "
250                   "@attr 4=2 @attr 1=1016 b "));
251
252     YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
253                   "@prox 0 2 0 2 k 2 "
254                   "@attr 4=2 @attr 1=1016 a "
255                   "@attr 4=2 @attr 1=1016 b "));
256
257     YAZ_CHECK(tst_ccl_query(bibset, "(a)%2(b)",
258                   "@prox 0 2 0 2 k 2 "
259                   "@attr 4=2 @attr 1=1016 a "
260                   "@attr 4=2 @attr 1=1016 b "));
261
262     YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
263                   "@prox 0 19 0 2 k 2 "
264                   "@attr 4=2 @attr 1=1016 a "
265                   "@attr 4=2 @attr 1=1016 b "));
266
267     YAZ_CHECK(tst_ccl_query(bibset, "spid%├Žserne",
268                   "@prox 0 1 0 2 k 2 "
269                   "@attr 4=2 @attr 1=1016 spid "
270                   "@attr 4=2 @attr 1=1016 ├Žserne "));
271
272     YAZ_CHECK(tst_ccl_query(bibset, "a!b",
273                   "@prox 0 1 1 2 k 2 "
274                   "@attr 4=2 @attr 1=1016 a "
275                   "@attr 4=2 @attr 1=1016 b "));
276     YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
277                   "@prox 0 2 1 2 k 2 "
278                   "@attr 4=2 @attr 1=1016 a "
279                   "@attr 4=2 @attr 1=1016 b "));
280
281     YAZ_CHECK(tst_ccl_query(bibset, "a% (b or dc.title=c)",
282                             "@prox 0 1 0 2 k 2 "
283                             "@attr 4=2 @attr 1=1016 a "
284                             "@or @attr 4=2 @attr 1=1016 b "
285                             "@attr 4=2 @attr 1=/my/title c "
286     ));
287
288     YAZ_CHECK(tst_ccl_query(bibset, "(a b) % (c)",
289                             "@prox 0 1 0 2 k 2 @and "
290                             "@attr 4=2 @attr 1=1016 a @attr 4=2 @attr 1=1016 b "
291                             "@attr 4=2 @attr 1=1016 c " ));
292
293     YAZ_CHECK(tst_ccl_query(bibset, "date=1980",
294                             "1980 "));
295     YAZ_CHECK(tst_ccl_query(bibset, "(date=1980)",
296                             "1980 "));
297     YAZ_CHECK(tst_ccl_query(bibset, "date>1980",
298                             "@attr 2=5 1980 "));
299     YAZ_CHECK(tst_ccl_query(bibset, "date>=1980",
300                             "@attr 2=4 1980 "));
301     YAZ_CHECK(tst_ccl_query(bibset, "date<1980",
302                             "@attr 2=1 1980 "));
303     YAZ_CHECK(tst_ccl_query(bibset, "date<=1980",
304                             "@attr 2=2 1980 "));
305     YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990",
306                             "@and @attr 2=4 234 @attr 2=2 1990 "));
307     YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990",
308                             "@and @attr 2=4 234 @attr 2=2 1990 "));
309     YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990",
310                             "@and @attr 2=4 234 @attr 2=2 1990 "));
311     YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990",
312                             "@and @attr 2=4 234 @attr 2=2 1990 "));
313     YAZ_CHECK(tst_ccl_query(bibset, "date=-1980",
314                             "@attr 2=2 1980 "));
315     YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980",
316                             "@attr 2=2 1980 "));
317     YAZ_CHECK(tst_ccl_query(bibset, "x=-1980",
318                             "@attr 2=3 -1980 "));
319     YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980",
320                             "@attr 2=2 1980 "));
321     YAZ_CHECK(tst_ccl_query(bibset, "x= -1980",
322                             "@attr 2=3 -1980 "));
323     YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990",
324                             "@attr 2=3 234-1990 "));
325     YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990",
326                             "@and @attr 2=4 234 @attr 2=2 1990 "));
327     YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b",
328                             "@attr 4=1 @attr 1=4 a,b "));
329     YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b",
330                             "@attr 4=1 @attr 1=4 \"a, b\" "));
331     YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b",
332                             "@attr 4=2 @attr 1=4 a-b "));
333     YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b",
334                             "@attr 4=1 @attr 1=4 \"a - b\" "));
335
336     YAZ_CHECK(tst_ccl_query(bibset, "a?",
337                             "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
338     YAZ_CHECK(tst_ccl_query(bibset, "a b",
339                             "@and @attr 4=2 @attr 1=1016 a "
340                             "@attr 4=2 @attr 1=1016 b "));
341
342     YAZ_CHECK(tst_ccl_query(bibset, "a b?",
343                             "@and @attr 4=2 @attr 1=1016 a "
344                             "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
345
346     YAZ_CHECK(tst_ccl_query(bibset, "title=a",
347                             "@attr 1=/my/title a "));
348
349     YAZ_CHECK(tst_ccl_query(bibset, "reg=a?b#\"c?\"",
350                             "@attr 5=102 a.*b.c\\\\? "));
351     YAZ_CHECK(tst_ccl_query(bibset, "z=a?b#\"c?\"",
352                             "@attr 5=104 a?b#c\\\\? "));
353
354     YAZ_CHECK(tst_ccl_query(bibset, "reg=\\(",
355                             "( "));
356     YAZ_CHECK(tst_ccl_query(bibset, "z=\\(",
357                             "( "));
358
359     YAZ_CHECK(tst_ccl_query(bibset, "z=a b#",
360                             "@attr 5=104 \"a b#\" "));
361
362     YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\"",
363                             "\"\\\"\" "));
364     YAZ_CHECK(tst_ccl_query(bibset, "z=\\\"",
365                             "\"\\\"\" "));
366
367     YAZ_CHECK(tst_ccl_query(bibset, "reg=.",
368                             ". "));
369     YAZ_CHECK(tst_ccl_query(bibset, "z=.",
370                             ". "));
371
372     YAZ_CHECK(tst_ccl_query(bibset, "reg=\".\"",
373                             ". "));
374     YAZ_CHECK(tst_ccl_query(bibset, "z=\".\"",
375                             ". "));
376
377     YAZ_CHECK(tst_ccl_query(bibset, "reg=?\\?",
378                             "@attr 5=102 .*\\\\? "));
379     YAZ_CHECK(tst_ccl_query(bibset, "z=?\\?",
380                             "@attr 5=104 ?\\\\? "));
381
382     YAZ_CHECK(tst_ccl_query(bibset, "reg=\"?\\?\"",
383                             "?? "));
384     YAZ_CHECK(tst_ccl_query(bibset, "z=\"?\\?\"",
385                             "?? "));
386
387     YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\\",
388                             "\\\\ "));
389     YAZ_CHECK(tst_ccl_query(bibset, "z=\\\\",
390                             "\\\\ "));
391
392     YAZ_CHECK(tst_ccl_query(bibset, "\\\\",
393                             "@attr 4=2 @attr 1=1016 \\\\ "));
394
395     YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
396                             "@or @attr 4=2 @attr 1=1016 a "
397                             "@attr 1=/my/title a "));
398
399     YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
400                             "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
401                             "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
402
403     YAZ_CHECK(tst_ccl_query(bibset, "\"a\"? \"b?\"",
404                             "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
405                             "@attr 4=2 @attr 1=1016 b? "));
406
407     YAZ_CHECK(tst_ccl_query(bibset, "@and",
408                             "@attr 4=2 @attr 1=1016 \\@and "));
409
410     YAZ_CHECK(tst_ccl_query(bibset, "a@and",
411                             "@attr 4=2 @attr 1=1016 a@and "));
412
413     YAZ_CHECK(tst_ccl_query(bibset, "}",
414                             "@attr 4=2 @attr 1=1016 } "));
415
416     YAZ_CHECK(tst_ccl_query(bibset, "{",
417                             "@attr 4=2 @attr 1=1016 \"{\" "));
418
419     YAZ_CHECK(tst_ccl_query(bibset, "\"a b c\"",
420                             "@attr 4=1 @attr 1=1016 \"a b c\" "));
421
422     YAZ_CHECK(tst_ccl_query(bibset, "\"a b  c  \"",
423                             "@attr 4=1 @attr 1=1016 \"a b  c  \" "));
424
425     YAZ_CHECK(tst_ccl_query(bibset, "ag=a",
426                             "@attr 4=2 a "));
427
428     YAZ_CHECK(tst_ccl_query(bibset, "ag=a b",
429                             "@attr 4=2 \"a b\" "));
430
431     YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"c d\"",
432                             "@and @attr 4=2 \"a b\" @attr 4=1 \"c d\" "));
433
434     YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"c\"",
435                             "@attr 4=2 \"a b c\" "));
436
437     YAZ_CHECK(tst_ccl_query(bibset, "ag=a b \"\"",
438                             "@attr 4=2 \"a b \" "));
439
440     YAZ_CHECK(tst_ccl_query(bibset, "ag=a \"b c\" d",
441                             "@and @and "
442                             "@attr 4=2 a @attr 4=1 \"b c\" @attr 4=2 d "));
443
444     YAZ_CHECK(tst_ccl_query(bibset, "ag=\"a b c\"",
445                             "@attr 4=1 \"a b c\" "));
446
447     YAZ_CHECK(tst_ccl_query(bibset, "ag=\"a b c\" \"d e\"",
448                             "@and @attr 4=1 \"a b c\" @attr 4=1 \"d e\" "));
449
450     YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a", "@attr 1=2 a "));
451     YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b", "@or "
452                             "@and @attr 1=2 a @attr 1=2 b @attr 1=2 \"a b\" "));
453     YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b c", "@or @or @or "
454                             "@and @and @attr 1=2 a @attr 1=2 b @attr 1=2 c "
455                             "@and @attr 1=2 a @attr 1=2 \"b c\" "
456                             "@and @attr 1=2 \"a b\" @attr 1=2 c "
457                             "@attr 1=2 \"a b c\" "));
458
459     YAZ_CHECK(tst_ccl_query(bibset, "s2=a", "@or @attr 1=2 a @attr 1=3 a "));
460
461     YAZ_CHECK(tst_ccl_query(bibset, "s2=a b", "@or "
462                             "@and " "@or @attr 1=2 a @attr 1=3 a "
463                             "@or @attr 1=2 b @attr 1=3 b "
464                             "@or @attr 1=2 \"a b\" @attr 1=3 \"a b\" "));
465
466
467     ccl_qual_rm(&bibset);
468 }
469
470 void tst2(void)
471 {
472     CCL_bibset bibset = ccl_qual_mk();
473
474     YAZ_CHECK(bibset);
475     if (!bibset)
476         return;
477
478     ccl_qual_fitem(bibset, "u=4    s=pw t=l,r", "ti");
479     ccl_qual_fitem(bibset, "1=1016 s=al,pw t=z",    "term");
480
481     YAZ_CHECK(tst_ccl_query(bibset, "a?#",
482                             "@attr 5=104 @attr 4=2 @attr 1=1016 a?# "));
483
484     YAZ_CHECK(tst_ccl_query(bibset, "a b?#",
485                             "@and @attr 4=2 @attr 1=1016 a @attr 5=104 @attr 4=2 @attr 1=1016 b?# "));
486
487     YAZ_CHECK(tst_ccl_query(bibset, "a*",
488                             "@attr 4=2 @attr 1=1016 a* "));
489
490     YAZ_CHECK(tst_ccl_query(bibset, "a?",
491                             "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
492
493     ccl_qual_fitem(bibset, "*", "@truncation");
494     YAZ_CHECK(tst_ccl_query(bibset, "a*",
495                             "@attr 5=104 @attr 4=2 @attr 1=1016 a? "));
496
497     YAZ_CHECK(tst_ccl_query(bibset, "a?",
498                             "@attr 4=2 @attr 1=1016 a? "));
499
500     ccl_qual_fitem(bibset, "?", "@mask");
501     YAZ_CHECK(tst_ccl_query(bibset, "a?",
502                             "@attr 5=104 @attr 4=2 @attr 1=1016 a# "));
503
504
505     ccl_qual_fitem(bibset, "", "@mask");
506     ccl_qual_fitem(bibset, "", "@truncation");
507     YAZ_CHECK(tst_ccl_query(bibset, "a?#",
508                             "@attr 4=2 @attr 1=1016 a?# "));
509
510     ccl_qual_fitem(bibset, "og", "@and");
511     ccl_qual_fitem(bibset, "eller", "@or");
512     ccl_qual_fitem(bibset, "ikke", "@not");
513
514     YAZ_CHECK(tst_ccl_query(bibset, "a og b eller c ikke d",
515                             "@not @or @and @attr 4=2 @attr 1=1016 a "
516                             "@attr 4=2 @attr 1=1016 b "
517                             "@attr 4=2 @attr 1=1016 c "
518                             "@attr 4=2 @attr 1=1016 d "));
519     ccl_qual_rm(&bibset);
520 }
521
522
523 void tst_addinfo(void)
524 {
525     const char *addinfo;
526     int r;
527     CCL_bibset bibset = ccl_qual_mk();
528
529     r = ccl_qual_fitem2(bibset, "u=4    s=pw t=l,r", "ti", &addinfo);
530     YAZ_CHECK(r == 0 && addinfo == 0);
531
532     r = ccl_qual_fitem2(bibset, "1=1016 s=al,pw t=z", "term", &addinfo);
533     YAZ_CHECK(r == 0 && addinfo == 0);
534
535     r = ccl_qual_fitem2(bibset, "x=", "term", &addinfo);
536     YAZ_CHECK(r != 0 && addinfo != 0);
537
538     r = ccl_qual_fitem2(bibset, "12=3", "term", &addinfo);
539     YAZ_CHECK(r == 0 && addinfo == 0);
540
541     r = ccl_qual_fitem2(bibset, "ab=3", "term", &addinfo);
542     YAZ_CHECK(r != 0 && addinfo != 0);
543
544     r = ccl_qual_fitem2(bibset, "x=ab", "term", &addinfo);
545     YAZ_CHECK(r != 0 && addinfo != 0);
546
547     r = ccl_qual_fitem2(bibset, "s=ab", "term", &addinfo);
548     YAZ_CHECK(r == 0 && addinfo == 0);
549
550     ccl_qual_rm(&bibset);
551 }
552
553 int main(int argc, char **argv)
554 {
555     YAZ_CHECK_INIT(argc, argv);
556     YAZ_CHECK_LOG();
557     tst1(0);
558     tst1(1);
559     tst1(2);
560     tst1(3);
561     tst2();
562     tst_addinfo();
563     YAZ_CHECK_TERM;
564 }
565 /*
566  * Local variables:
567  * c-basic-offset: 4
568  * c-file-style: "Stroustrup"
569  * indent-tabs-mode: nil
570  * End:
571  * vim: shiftwidth=4 tabstop=8 expandtab
572  */
573