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, "1=/my/title t=x", "dc.title");
83 ccl_qual_fitem(bibset, "r=r", "date");
84 ccl_qual_fitem(bibset, "r=o", "x");
85 ccl_qual_fitem(bibset, "dc.title", "title");
86 ccl_qual_fitem(bibset, "term dc.title", "comb");
89 strcpy(tstline, "ti u=4 s=pw t=l,r");
90 ccl_qual_line(bibset, tstline);
92 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
93 ccl_qual_line(bibset, tstline);
95 strcpy(tstline, "dc.title 1=/my/title t=x");
96 ccl_qual_line(bibset, tstline);
98 strcpy(tstline, "date r=r # ordered relation");
99 ccl_qual_line(bibset, tstline);
101 strcpy(tstline, "x r=o # ordered relation");
102 ccl_qual_line(bibset, tstline);
104 strcpy(tstline, "title dc.title # alias");
105 ccl_qual_line(bibset, tstline);
107 strcpy(tstline, "comb term dc.title # combination");
108 ccl_qual_line(bibset, tstline);
111 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
112 "term 1=1016 s=al,pw t=r\r\n"
114 "dc.title 1=/my/title t=x\n"
118 "comb term dc.title\n"
127 const char *addinfo = 0;
128 const char *xml_str =
130 " <qual name=\"ti\">\n"
131 " <attr type=\"u\" value=\"4\"/>\n"
132 " <attr type=\"s\" value=\"pw\"/>\n"
133 " <attr type=\"t\" value=\"l,r\"/>\n"
135 " <qual name=\"term\">\n"
136 " <attr type=\"1\" value=\"1016\"/>\n"
137 " <attr type=\"s\" value=\"al,pw\"/>\n"
138 " <attr type=\"t\" value=\"r\"/>\n"
140 " <qual name=\"dc.title\">\n"
141 " <attr type=\"1\" value=\"/my/title\"/>\n"
142 " <attr type=\"t\" value=\"x\"/>\n"
144 " <qual name=\"date\">\n"
145 " <attr type=\"r\" value=\"r\"/>\n"
147 " <qual name=\"x\">\n"
148 " <attr type=\"r\" value=\"o\"/>\n"
150 " <qual name=\"title\">\n"
151 " <qual name=\"dc.title\"/>\n"
153 " <qual name=\"comb\">\n"
154 " <qual name=\"term\"/>\n"
155 " <qual name=\"dc.title\"/>\n"
159 doc = xmlParseMemory(xml_str, strlen(xml_str));
162 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
176 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
178 YAZ_CHECK(tst_ccl_query(bibset, "k\xc3\xb8" "benhavn", "@attr 4=2 @attr 1=1016 k\xc3\xb8" "benhavn "));
180 YAZ_CHECK(tst_ccl_query(bibset, "k\xf8" "benhavn", "@attr 4=2 @attr 1=1016 ""k\xf8" "benhavn "));
182 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
183 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
185 "@attr 4=2 @attr 1=1016 x1 "
186 "@attr 4=2 @attr 1=1016 x2 "));
187 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
188 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
189 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
190 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
192 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
194 "@attr 4=2 @attr 1=1016 a "
195 "@attr 4=2 @attr 1=1016 b "));
196 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
198 "@attr 4=2 @attr 1=1016 a "
199 "@attr 4=2 @attr 1=1016 b "));
201 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
203 "@attr 4=2 @attr 1=1016 a "
204 "@attr 4=2 @attr 1=1016 b "));
206 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
207 "@prox 0 19 0 2 k 2 "
208 "@attr 4=2 @attr 1=1016 a "
209 "@attr 4=2 @attr 1=1016 b "));
211 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
213 "@attr 4=2 @attr 1=1016 spid "
214 "@attr 4=2 @attr 1=1016 æserne "));
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!2b",
222 "@attr 4=2 @attr 1=1016 a "
223 "@attr 4=2 @attr 1=1016 b "));
225 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
226 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
227 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
228 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
229 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
230 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
231 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
232 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
233 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
234 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
235 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
236 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
237 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
238 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
239 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
240 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
242 YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
243 YAZ_CHECK(tst_ccl_query(bibset, "a b",
244 "@and @attr 4=2 @attr 1=1016 a "
245 "@attr 4=2 @attr 1=1016 b "));
247 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
248 "@and @attr 4=2 @attr 1=1016 a "
249 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
251 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
252 "@attr 1=/my/title a "));
254 YAZ_CHECK(tst_ccl_query(bibset, "title=a?b#\"c?\"",
255 "@attr 5=102 @attr 1=/my/title a.*b.c\\\\? "));
257 YAZ_CHECK(tst_ccl_query(bibset, "title=\\(",
258 "@attr 5=102 @attr 1=/my/title \\\\( "));
260 YAZ_CHECK(tst_ccl_query(bibset, "title=.",
261 "@attr 5=102 @attr 1=/my/title \\\\. "));
263 YAZ_CHECK(tst_ccl_query(bibset, "title=\\.",
264 "@attr 5=102 @attr 1=/my/title \\\\. "));
266 YAZ_CHECK(tst_ccl_query(bibset, "title=\".\"",
267 "@attr 5=102 @attr 1=/my/title \\\\. "));
269 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
270 "@or @attr 4=2 @attr 1=1016 a "
271 "@attr 1=/my/title a "));
273 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
274 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
275 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
277 YAZ_CHECK(tst_ccl_query(bibset, "\"a\"? \"b?\"",
278 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
279 "@attr 4=2 @attr 1=1016 b? "));
281 ccl_qual_rm(&bibset);
284 int main(int argc, char **argv)
286 YAZ_CHECK_INIT(argc, argv);
297 * c-file-style: "Stroustrup"
298 * indent-tabs-mode: nil
300 * vim: shiftwidth=4 tabstop=8 expandtab