1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 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");
79 strcpy(tstline, "ti u=4 s=pw t=l,r");
80 ccl_qual_line(bibset, tstline);
82 strcpy(tstline, "term 1=1016 s=al,pw t=r # default term");
83 ccl_qual_line(bibset, tstline);
85 strcpy(tstline, "dc.title 1=/my/title");
86 ccl_qual_line(bibset, tstline);
88 strcpy(tstline, "date r=r # ordered relation");
89 ccl_qual_line(bibset, tstline);
91 strcpy(tstline, "x r=o # ordered relation");
92 ccl_qual_line(bibset, tstline);
95 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
96 "term 1=1016 s=al,pw t=r\r\n"
98 "dc.title 1=/my/title\n"
109 const char *addinfo = 0;
110 const char *xml_str =
112 " <qual name=\"ti\">\n"
113 " <attr type=\"u\" value=\"4\"/>\n"
114 " <attr type=\"s\" value=\"pw\"/>\n"
115 " <attr type=\"t\" value=\"l,r\"/>\n"
117 " <qual name=\"term\">\n"
118 " <attr type=\"1\" value=\"1016\"/>\n"
119 " <attr type=\"s\" value=\"al,pw\"/>\n"
120 " <attr type=\"t\" value=\"r\"/>\n"
122 " <qual name=\"dc.title\">\n"
123 " <attr type=\"1\" value=\"/my/title\"/>\n"
125 " <qual name=\"date\">\n"
126 " <attr type=\"r\" value=\"r\"/>\n"
128 " <qual name=\"x\">\n"
129 " <attr type=\"r\" value=\"o\"/>\n"
133 doc = xmlParseMemory(xml_str, strlen(xml_str));
136 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
150 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
151 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
152 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
154 "@attr 4=2 @attr 1=1016 x1 "
155 "@attr 4=2 @attr 1=1016 x2 "));
156 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
157 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
158 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
159 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
161 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
163 "@attr 4=2 @attr 1=1016 a "
164 "@attr 4=2 @attr 1=1016 b "));
165 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
167 "@attr 4=2 @attr 1=1016 a "
168 "@attr 4=2 @attr 1=1016 b "));
170 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
172 "@attr 4=2 @attr 1=1016 a "
173 "@attr 4=2 @attr 1=1016 b "));
175 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
176 "@prox 0 19 0 2 k 2 "
177 "@attr 4=2 @attr 1=1016 a "
178 "@attr 4=2 @attr 1=1016 b "));
180 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
182 "@attr 4=2 @attr 1=1016 spid "
183 "@attr 4=2 @attr 1=1016 æserne "));
185 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
187 "@attr 4=2 @attr 1=1016 a "
188 "@attr 4=2 @attr 1=1016 b "));
189 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
191 "@attr 4=2 @attr 1=1016 a "
192 "@attr 4=2 @attr 1=1016 b "));
194 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
195 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
196 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
197 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
198 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
199 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
200 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
201 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
202 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
203 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
204 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
205 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
206 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
207 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
208 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
209 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
211 YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
212 YAZ_CHECK(tst_ccl_query(bibset, "a b",
213 "@and @attr 4=2 @attr 1=1016 a "
214 "@attr 4=2 @attr 1=1016 b "));
216 YAZ_CHECK(tst_ccl_query(bibset, "a b?",
217 "@and @attr 4=2 @attr 1=1016 a "
218 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
222 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
224 "@and @attr 4=2 @attr 1=1016 a? "
225 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
227 YAZ_CHECK(tst_ccl_query(bibset, "a? b?",
229 "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
230 "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
232 ccl_qual_rm(&bibset);
235 int main(int argc, char **argv)
237 YAZ_CHECK_INIT(argc, argv);
248 * c-file-style: "Stroustrup"
249 * indent-tabs-mode: nil
251 * vim: shiftwidth=4 tabstop=8 expandtab