1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
9 #include <yaz/ccl_xml.h>
14 static int tst_ccl_query(CCL_bibset bibset,
18 CCL_parser parser = ccl_parser_create(bibset);
23 struct ccl_rpn_node *rpn;
25 rpn = ccl_parser_find_str(parser, query);
28 /* parse ok. check that result is there and match */
29 WRBUF wrbuf = wrbuf_alloc();
30 ccl_pquery(wrbuf, rpn);
32 /* check expect a result and that it matches */
33 if (result && !strcmp(wrbuf_cstr(wrbuf), result))
37 yaz_log(YLOG_WARN, "%s: result does not match", query);
38 yaz_log(YLOG_WARN, " expected %s", result);
39 yaz_log(YLOG_WARN, " got %s", wrbuf_cstr(wrbuf));
49 yaz_log(YLOG_WARN, "%s: parse failed", query);
56 ccl_parser_destroy (parser);
62 CCL_bibset bibset = ccl_qual_mk();
72 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
73 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r", "term");
74 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
75 ccl_qual_fitem(bibset, "r=r", "date");
76 ccl_qual_fitem(bibset, "r=o", "x");
77 ccl_qual_fitem(bibset, "dc.title", "title");
78 ccl_qual_fitem(bibset, "term dc.title", "comb");
81 strcpy(tstline, "ti u=4 s=pw t=l,r");
82 ccl_qual_line(bibset, tstline);
84 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
85 ccl_qual_line(bibset, tstline);
87 strcpy(tstline, "dc.title 1=/my/title");
88 ccl_qual_line(bibset, tstline);
90 strcpy(tstline, "date r=r # ordered relation");
91 ccl_qual_line(bibset, tstline);
93 strcpy(tstline, "x r=o # ordered relation");
94 ccl_qual_line(bibset, tstline);
96 strcpy(tstline, "title dc.title # alias");
97 ccl_qual_line(bibset, tstline);
99 strcpy(tstline, "comb term dc.title # combination");
100 ccl_qual_line(bibset, tstline);
103 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
104 "term 1=1016 s=al,pw t=r\r\n"
106 "dc.title 1=/my/title\n"
110 "comb term dc.title\n"
119 const char *addinfo = 0;
120 const char *xml_str =
122 " <qual name=\"ti\">\n"
123 " <attr type=\"u\" value=\"4\"/>\n"
124 " <attr type=\"s\" value=\"pw\"/>\n"
125 " <attr type=\"t\" value=\"l,r\"/>\n"
127 " <qual name=\"term\">\n"
128 " <attr type=\"1\" value=\"1016\"/>\n"
129 " <attr type=\"s\" value=\"al,pw\"/>\n"
130 " <attr type=\"t\" value=\"r\"/>\n"
132 " <qual name=\"dc.title\">\n"
133 " <attr type=\"1\" value=\"/my/title\"/>\n"
135 " <qual name=\"date\">\n"
136 " <attr type=\"r\" value=\"r\"/>\n"
138 " <qual name=\"x\">\n"
139 " <attr type=\"r\" value=\"o\"/>\n"
141 " <qual name=\"title\">\n"
142 " <qual name=\"dc.title\"/>\n"
144 " <qual name=\"comb\">\n"
145 " <qual name=\"term\"/>\n"
146 " <qual name=\"dc.title\"/>\n"
150 doc = xmlParseMemory(xml_str, strlen(xml_str));
153 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
167 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
168 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
169 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
171 "@attr 4=2 @attr 1=1016 x1 "
172 "@attr 4=2 @attr 1=1016 x2 "));
173 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
174 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
175 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
176 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
178 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
180 "@attr 4=2 @attr 1=1016 a "
181 "@attr 4=2 @attr 1=1016 b "));
182 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
184 "@attr 4=2 @attr 1=1016 a "
185 "@attr 4=2 @attr 1=1016 b "));
187 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
189 "@attr 4=2 @attr 1=1016 a "
190 "@attr 4=2 @attr 1=1016 b "));
192 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
193 "@prox 0 19 0 2 k 2 "
194 "@attr 4=2 @attr 1=1016 a "
195 "@attr 4=2 @attr 1=1016 b "));
197 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
199 "@attr 4=2 @attr 1=1016 spid "
200 "@attr 4=2 @attr 1=1016 æserne "));
202 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
204 "@attr 4=2 @attr 1=1016 a "
205 "@attr 4=2 @attr 1=1016 b "));
206 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
208 "@attr 4=2 @attr 1=1016 a "
209 "@attr 4=2 @attr 1=1016 b "));
211 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
212 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
213 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
214 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
215 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
216 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
217 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
218 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
219 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
220 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
221 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
222 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
223 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
224 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
225 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
226 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
228 YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
229 YAZ_CHECK(tst_ccl_query(bibset, "a b",
230 "@and @attr 4=2 @attr 1=1016 a "
231 "@attr 4=2 @attr 1=1016 b "));
233 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
234 "@and @attr 4=2 @attr 1=1016 a "
235 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
237 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
238 "@attr 1=/my/title a "));
240 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
241 "@or @attr 4=2 @attr 1=1016 a "
242 "@attr 1=/my/title a "));
246 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, "a? b?",
253 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
254 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
256 ccl_qual_rm(&bibset);
259 int main(int argc, char **argv)
261 YAZ_CHECK_INIT(argc, argv);
272 * c-file-style: "Stroustrup"
273 * indent-tabs-mode: nil
275 * vim: shiftwidth=4 tabstop=8 expandtab