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();
73 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
74 ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r", "term");
75 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
76 ccl_qual_fitem(bibset, "r=r", "date");
77 ccl_qual_fitem(bibset, "r=o", "x");
78 ccl_qual_fitem(bibset, "dc.title", "title");
79 ccl_qual_fitem(bibset, "term dc.title", "comb");
82 strcpy(tstline, "ti u=4 s=pw t=l,r");
83 ccl_qual_line(bibset, tstline);
85 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
86 ccl_qual_line(bibset, tstline);
88 strcpy(tstline, "dc.title 1=/my/title");
89 ccl_qual_line(bibset, tstline);
91 strcpy(tstline, "date r=r # ordered relation");
92 ccl_qual_line(bibset, tstline);
94 strcpy(tstline, "x r=o # ordered relation");
95 ccl_qual_line(bibset, tstline);
97 strcpy(tstline, "title dc.title # alias");
98 ccl_qual_line(bibset, tstline);
100 strcpy(tstline, "comb term dc.title # combination");
101 ccl_qual_line(bibset, tstline);
104 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
105 "term 1=1016 s=al,pw t=r\r\n"
107 "dc.title 1=/my/title\n"
111 "comb term dc.title\n"
120 const char *addinfo = 0;
121 const char *xml_str =
123 " <qual name=\"ti\">\n"
124 " <attr type=\"u\" value=\"4\"/>\n"
125 " <attr type=\"s\" value=\"pw\"/>\n"
126 " <attr type=\"t\" value=\"l,r\"/>\n"
128 " <qual name=\"term\">\n"
129 " <attr type=\"1\" value=\"1016\"/>\n"
130 " <attr type=\"s\" value=\"al,pw\"/>\n"
131 " <attr type=\"t\" value=\"r\"/>\n"
133 " <qual name=\"dc.title\">\n"
134 " <attr type=\"1\" value=\"/my/title\"/>\n"
136 " <qual name=\"date\">\n"
137 " <attr type=\"r\" value=\"r\"/>\n"
139 " <qual name=\"x\">\n"
140 " <attr type=\"r\" value=\"o\"/>\n"
142 " <qual name=\"title\">\n"
143 " <qual name=\"dc.title\"/>\n"
145 " <qual name=\"comb\">\n"
146 " <qual name=\"term\"/>\n"
147 " <qual name=\"dc.title\"/>\n"
151 doc = xmlParseMemory(xml_str, strlen(xml_str));
154 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
168 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
170 YAZ_CHECK(tst_ccl_query(bibset, "k\xc3\xb8" "benhavn", "@attr 4=2 @attr 1=1016 k\xc3\xb8" "benhavn "));
172 YAZ_CHECK(tst_ccl_query(bibset, "k\xf8" "benhavn", "@attr 4=2 @attr 1=1016 ""k\xf8" "benhavn "));
174 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
175 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
177 "@attr 4=2 @attr 1=1016 x1 "
178 "@attr 4=2 @attr 1=1016 x2 "));
179 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
180 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
181 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
182 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
184 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
186 "@attr 4=2 @attr 1=1016 a "
187 "@attr 4=2 @attr 1=1016 b "));
188 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
190 "@attr 4=2 @attr 1=1016 a "
191 "@attr 4=2 @attr 1=1016 b "));
193 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
195 "@attr 4=2 @attr 1=1016 a "
196 "@attr 4=2 @attr 1=1016 b "));
198 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
199 "@prox 0 19 0 2 k 2 "
200 "@attr 4=2 @attr 1=1016 a "
201 "@attr 4=2 @attr 1=1016 b "));
203 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
205 "@attr 4=2 @attr 1=1016 spid "
206 "@attr 4=2 @attr 1=1016 æserne "));
208 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
210 "@attr 4=2 @attr 1=1016 a "
211 "@attr 4=2 @attr 1=1016 b "));
212 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
214 "@attr 4=2 @attr 1=1016 a "
215 "@attr 4=2 @attr 1=1016 b "));
217 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
218 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
219 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
220 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
221 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
222 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
223 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
224 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
225 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
226 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
227 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
228 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
229 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
230 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
231 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
232 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
234 YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
235 YAZ_CHECK(tst_ccl_query(bibset, "a b",
236 "@and @attr 4=2 @attr 1=1016 a "
237 "@attr 4=2 @attr 1=1016 b "));
239 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
240 "@and @attr 4=2 @attr 1=1016 a "
241 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
243 YAZ_CHECK(tst_ccl_query(bibset, "title=a",
244 "@attr 1=/my/title a "));
246 YAZ_CHECK(tst_ccl_query(bibset, "comb=a",
247 "@or @attr 4=2 @attr 1=1016 a "
248 "@attr 1=/my/title a "));
250 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
252 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
253 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
254 ccl_qual_rm(&bibset);
257 int main(int argc, char **argv)
259 YAZ_CHECK_INIT(argc, argv);
270 * c-file-style: "Stroustrup"
271 * indent-tabs-mode: nil
273 * vim: shiftwidth=4 tabstop=8 expandtab