1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
9 #include <yaz/ccl_xml.h>
13 static int tst_ccl_query(CCL_bibset bibset,
17 CCL_parser parser = ccl_parser_create(bibset);
22 struct ccl_rpn_node *rpn;
24 rpn = ccl_parser_find_str(parser, query);
27 /* parse ok. check that result is there and match */
28 WRBUF wrbuf = wrbuf_alloc();
29 ccl_pquery(wrbuf, rpn);
31 /* check expect a result and that it matches */
32 if (result && !strcmp(wrbuf_cstr(wrbuf), result))
47 ccl_parser_destroy (parser);
53 CCL_bibset bibset = ccl_qual_mk();
63 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
64 ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
65 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
66 ccl_qual_fitem(bibset, "r=r", "date");
67 ccl_qual_fitem(bibset, "r=o", "x");
70 strcpy(tstline, "ti u=4 s=pw t=l,r");
71 ccl_qual_line(bibset, tstline);
73 strcpy(tstline, "term 1=1016 s=al,pw # default term");
74 ccl_qual_line(bibset, tstline);
76 strcpy(tstline, "dc.title 1=/my/title");
77 ccl_qual_line(bibset, tstline);
79 strcpy(tstline, "date r=r # ordered relation");
80 ccl_qual_line(bibset, tstline);
82 strcpy(tstline, "x r=o # ordered relation");
83 ccl_qual_line(bibset, tstline);
86 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
87 "term 1=1016 s=al,pw\r\n"
89 "dc.title 1=/my/title\n"
100 const char *addinfo = 0;
101 const char *xml_str =
103 " <qual name=\"ti\">\n"
104 " <attr type=\"u\" value=\"4\"/>\n"
105 " <attr type=\"s\" value=\"pw\"/>\n"
106 " <attr type=\"t\" value=\"l,r\"/>\n"
108 " <qual name=\"term\">\n"
109 " <attr type=\"1\" value=\"1016\"/>\n"
110 " <attr type=\"s\" value=\"al,pw\"/>\n"
112 " <qual name=\"dc.title\">\n"
113 " <attr type=\"1\" value=\"/my/title\"/>\n"
115 " <qual name=\"date\">\n"
116 " <attr type=\"r\" value=\"r\"/>\n"
118 " <qual name=\"x\">\n"
119 " <attr type=\"r\" value=\"o\"/>\n"
123 doc = xmlParseMemory(xml_str, strlen(xml_str));
126 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
140 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
141 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
142 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
144 "@attr 4=2 @attr 1=1016 x1 "
145 "@attr 4=2 @attr 1=1016 x2 "));
146 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
147 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
148 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
149 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
151 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
153 "@attr 4=2 @attr 1=1016 a "
154 "@attr 4=2 @attr 1=1016 b "));
155 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
157 "@attr 4=2 @attr 1=1016 a "
158 "@attr 4=2 @attr 1=1016 b "));
160 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
162 "@attr 4=2 @attr 1=1016 a "
163 "@attr 4=2 @attr 1=1016 b "));
165 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
166 "@prox 0 19 0 2 k 2 "
167 "@attr 4=2 @attr 1=1016 a "
168 "@attr 4=2 @attr 1=1016 b "));
170 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
172 "@attr 4=2 @attr 1=1016 spid "
173 "@attr 4=2 @attr 1=1016 æserne "));
175 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
177 "@attr 4=2 @attr 1=1016 a "
178 "@attr 4=2 @attr 1=1016 b "));
179 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
181 "@attr 4=2 @attr 1=1016 a "
182 "@attr 4=2 @attr 1=1016 b "));
184 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
185 YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
186 YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
187 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
188 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
189 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
190 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
191 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
192 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
193 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
194 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
195 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
196 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
197 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "));
198 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
199 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "));
200 ccl_qual_rm(&bibset);
203 int main(int argc, char **argv)
205 YAZ_CHECK_INIT(argc, argv);
216 * indent-tabs-mode: nil
218 * vim: shiftwidth=4 tabstop=8 expandtab