1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 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, "x1 and", 0));
205 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
207 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
209 "@attr 4=2 @attr 1=1016 a "
210 "@attr 4=2 @attr 1=1016 b "));
211 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
213 "@attr 4=2 @attr 1=1016 a "
214 "@attr 4=2 @attr 1=1016 b "));
216 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
218 "@attr 4=2 @attr 1=1016 a "
219 "@attr 4=2 @attr 1=1016 b "));
221 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
222 "@prox 0 19 0 2 k 2 "
223 "@attr 4=2 @attr 1=1016 a "
224 "@attr 4=2 @attr 1=1016 b "));
226 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
228 "@attr 4=2 @attr 1=1016 spid "
229 "@attr 4=2 @attr 1=1016 æserne "));
231 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
233 "@attr 4=2 @attr 1=1016 a "
234 "@attr 4=2 @attr 1=1016 b "));
235 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
237 "@attr 4=2 @attr 1=1016 a "
238 "@attr 4=2 @attr 1=1016 b "));
240 YAZ_CHECK(tst_ccl_query(bibset, "date=1980",
242 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990",
243 "@and @attr 2=4 234 @attr 2=2 1990 "));
244 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990",
245 "@and @attr 2=4 234 @attr 2=2 1990 "));
246 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990",
247 "@and @attr 2=4 234 @attr 2=2 1990 "));
248 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990",
249 "@and @attr 2=4 234 @attr 2=2 1990 "));
250 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980",
252 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980",
254 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980",
255 "@attr 2=3 -1980 "));
256 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980",
258 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980",
259 "@attr 2=3 -1980 "));
260 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990",
261 "@attr 2=3 234-1990 "));
262 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990",
263 "@and @attr 2=4 234 @attr 2=2 1990 "));
264 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b",
265 "@attr 4=1 @attr 1=4 a,b "));
266 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b",
267 "@attr 4=1 @attr 1=4 \"a, b\" "));
268 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b",
269 "@attr 4=2 @attr 1=4 a-b "));
270 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b",
271 "@attr 4=1 @attr 1=4 \"a - b\" "));
273 YAZ_CHECK(tst_ccl_query(bibset, "a?",
274 "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
275 YAZ_CHECK(tst_ccl_query(bibset, "a b",
276 "@and @attr 4=2 @attr 1=1016 a "
277 "@attr 4=2 @attr 1=1016 b "));
279 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
280 "@and @attr 4=2 @attr 1=1016 a "
281 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
283 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
284 "@attr 1=/my/title a "));
286 YAZ_CHECK(tst_ccl_query(bibset, "reg=a?b#\"c?\"",
287 "@attr 5=102 a.*b.c\\\\? "));
288 YAZ_CHECK(tst_ccl_query(bibset, "z=a?b#\"c?\"",
289 "@attr 5=104 a?b#c\\\\? "));
291 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\(",
292 "@attr 5=102 \\\\( "));
293 YAZ_CHECK(tst_ccl_query(bibset, "z=\\(",
296 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\"",
298 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\"",
301 YAZ_CHECK(tst_ccl_query(bibset, "reg=.",
302 "@attr 5=102 \\\\. "));
303 YAZ_CHECK(tst_ccl_query(bibset, "z=.",
306 YAZ_CHECK(tst_ccl_query(bibset, "reg=\".\"",
307 "@attr 5=102 \\\\. "));
308 YAZ_CHECK(tst_ccl_query(bibset, "z=\".\"",
311 YAZ_CHECK(tst_ccl_query(bibset, "reg=?\\?",
312 "@attr 5=102 .*\\\\? "));
313 YAZ_CHECK(tst_ccl_query(bibset, "z=?\\?",
314 "@attr 5=104 ?\\\\? "));
316 YAZ_CHECK(tst_ccl_query(bibset, "reg=\"?\\?\"",
317 "@attr 5=102 \\\\?\\\\? "));
318 YAZ_CHECK(tst_ccl_query(bibset, "z=\"?\\?\"",
319 "@attr 5=104 \\\\?\\\\? "));
321 YAZ_CHECK(tst_ccl_query(bibset, "reg=\\\\",
322 "@attr 5=102 \\\\\\\\ "));
323 YAZ_CHECK(tst_ccl_query(bibset, "z=\\\\",
324 "@attr 5=104 \\\\\\\\ "));
326 YAZ_CHECK(tst_ccl_query(bibset, "\\\\",
327 "@attr 4=2 @attr 1=1016 \\\\ "));
329 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
330 "@or @attr 4=2 @attr 1=1016 a "
331 "@attr 1=/my/title a "));
333 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
334 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
335 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
337 YAZ_CHECK(tst_ccl_query(bibset, "\"a\"? \"b?\"",
338 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
339 "@attr 4=2 @attr 1=1016 b? "));
341 ccl_qual_rm(&bibset);
344 int main(int argc, char **argv)
346 YAZ_CHECK_INIT(argc, argv);
357 * c-file-style: "Stroustrup"
358 * indent-tabs-mode: nil
360 * vim: shiftwidth=4 tabstop=8 expandtab