2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstccl.c,v 1.17 2007-04-27 09:48:28 adam Exp $
11 #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))
49 ccl_parser_destroy (parser);
55 CCL_bibset bibset = ccl_qual_mk();
65 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
66 ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
67 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
68 ccl_qual_fitem(bibset, "r=r", "date");
69 ccl_qual_fitem(bibset, "r=o", "x");
72 strcpy(tstline, "ti u=4 s=pw t=l,r");
73 ccl_qual_line(bibset, tstline);
75 strcpy(tstline, "term 1=1016 s=al,pw # default term");
76 ccl_qual_line(bibset, tstline);
78 strcpy(tstline, "dc.title 1=/my/title");
79 ccl_qual_line(bibset, tstline);
81 strcpy(tstline, "date r=r # ordered relation");
82 ccl_qual_line(bibset, tstline);
84 strcpy(tstline, "x r=o # ordered relation");
85 ccl_qual_line(bibset, tstline);
88 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
89 "term 1=1016 s=al,pw\r\n"
91 "dc.title 1=/my/title\n"
102 const char *addinfo = 0;
103 const char *xml_str =
105 " <qual name=\"ti\">\n"
106 " <attr type=\"u\" value=\"4\"/>\n"
107 " <attr type=\"s\" value=\"pw\"/>\n"
108 " <attr type=\"t\" value=\"l,r\"/>\n"
110 " <qual name=\"term\">\n"
111 " <attr type=\"1\" value=\"1016\"/>\n"
112 " <attr type=\"s\" value=\"al,pw\"/>\n"
114 " <qual name=\"dc.title\">\n"
115 " <attr type=\"1\" value=\"/my/title\"/>\n"
117 " <qual name=\"date\">\n"
118 " <attr type=\"r\" value=\"r\"/>\n"
120 " <qual name=\"x\">\n"
121 " <attr type=\"r\" value=\"o\"/>\n"
125 doc = xmlParseMemory(xml_str, strlen(xml_str));
128 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
142 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
143 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
144 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
146 "@attr 4=2 @attr 1=1016 x1 "
147 "@attr 4=2 @attr 1=1016 x2 "));
148 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
149 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
150 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
151 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
153 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
155 "@attr 4=2 @attr 1=1016 a "
156 "@attr 4=2 @attr 1=1016 b "));
157 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
159 "@attr 4=2 @attr 1=1016 a "
160 "@attr 4=2 @attr 1=1016 b "));
162 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
164 "@attr 4=2 @attr 1=1016 a "
165 "@attr 4=2 @attr 1=1016 b "));
167 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
168 "@prox 0 19 0 2 k 2 "
169 "@attr 4=2 @attr 1=1016 a "
170 "@attr 4=2 @attr 1=1016 b "));
172 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
174 "@attr 4=2 @attr 1=1016 spid "
175 "@attr 4=2 @attr 1=1016 æserne "));
177 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
179 "@attr 4=2 @attr 1=1016 a "
180 "@attr 4=2 @attr 1=1016 b "));
181 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
183 "@attr 4=2 @attr 1=1016 a "
184 "@attr 4=2 @attr 1=1016 b "));
186 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
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=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
190 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
191 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
192 YAZ_CHECK(tst_ccl_query(bibset, "date=- 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=- 1980", "@attr 2=2 1980 "));
195 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
196 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
197 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
198 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
199 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "));
200 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
201 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "));
202 ccl_qual_rm(&bibset);
205 int main(int argc, char **argv)
207 YAZ_CHECK_INIT(argc, argv);
218 * indent-tabs-mode: nil
220 * vim: shiftwidth=4 tabstop=8 expandtab