2 * Copyright (C) 1995-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstccl.c,v 1.13 2007-01-08 10:48:07 adam Exp $
11 #include <yaz/ccl_xml.h>
15 static int tst_ccl_query(CCL_bibset bibset,
19 CCL_parser parser = ccl_parser_create();
24 struct ccl_token *token_list;
25 struct ccl_rpn_node *rpn;
27 parser->bibset = bibset;
29 token_list = ccl_parser_tokenize(parser, query);
30 rpn = ccl_parser_find(parser, token_list);
31 ccl_token_del(token_list);
34 /* parse ok. check that result is there and match */
35 WRBUF wrbuf = wrbuf_alloc();
36 ccl_pquery(wrbuf, rpn);
38 /* check expect a result and that it matches */
39 if (result && !strcmp(wrbuf_buf(wrbuf), result))
54 ccl_parser_destroy (parser);
60 CCL_bibset bibset = ccl_qual_mk();
70 ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
71 ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
72 ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
73 ccl_qual_fitem(bibset, "r=r", "date");
74 ccl_qual_fitem(bibset, "r=o", "x");
77 strcpy(tstline, "ti u=4 s=pw t=l,r");
78 ccl_qual_line(bibset, tstline);
80 strcpy(tstline, "term 1=1016 s=al,pw # default term");
81 ccl_qual_line(bibset, tstline);
83 strcpy(tstline, "dc.title 1=/my/title");
84 ccl_qual_line(bibset, tstline);
86 strcpy(tstline, "date r=r # ordered relation");
87 ccl_qual_line(bibset, tstline);
89 strcpy(tstline, "x r=o # ordered relation");
90 ccl_qual_line(bibset, tstline);
93 ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
94 "term 1=1016 s=al,pw\r\n"
96 "dc.title 1=/my/title\n"
107 const char *addinfo = 0;
108 const char *xml_str =
110 " <qual name=\"ti\">\n"
111 " <attr type=\"u\" value=\"4\"/>\n"
112 " <attr type=\"s\" value=\"pw\"/>\n"
113 " <attr type=\"t\" value=\"l,r\"/>\n"
115 " <qual name=\"term\">\n"
116 " <attr type=\"1\" value=\"1016\"/>\n"
117 " <attr type=\"s\" value=\"al,pw\"/>\n"
119 " <qual name=\"dc.title\">\n"
120 " <attr type=\"1\" value=\"/my/title\"/>\n"
122 " <qual name=\"date\">\n"
123 " <attr type=\"r\" value=\"r\"/>\n"
125 " <qual name=\"x\">\n"
126 " <attr type=\"r\" value=\"o\"/>\n"
130 doc = xmlParseMemory(xml_str, strlen(xml_str));
133 r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
145 YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
146 YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
147 YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
149 "@attr 4=2 @attr 1=1016 x1 "
150 "@attr 4=2 @attr 1=1016 x2 "));
151 YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
152 YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
153 YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
154 YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
156 YAZ_CHECK(tst_ccl_query(bibset, "a%b",
158 "@attr 4=2 @attr 1=1016 a "
159 "@attr 4=2 @attr 1=1016 b "));
160 YAZ_CHECK(tst_ccl_query(bibset, "a%1b",
162 "@attr 4=2 @attr 1=1016 a "
163 "@attr 4=2 @attr 1=1016 b "));
165 YAZ_CHECK(tst_ccl_query(bibset, "a%2b",
167 "@attr 4=2 @attr 1=1016 a "
168 "@attr 4=2 @attr 1=1016 b "));
170 YAZ_CHECK(tst_ccl_query(bibset, "a%19b",
171 "@prox 0 19 0 2 k 2 "
172 "@attr 4=2 @attr 1=1016 a "
173 "@attr 4=2 @attr 1=1016 b "));
175 YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne",
177 "@attr 4=2 @attr 1=1016 spid "
178 "@attr 4=2 @attr 1=1016 æserne "));
180 YAZ_CHECK(tst_ccl_query(bibset, "a!b",
182 "@attr 4=2 @attr 1=1016 a "
183 "@attr 4=2 @attr 1=1016 b "));
184 YAZ_CHECK(tst_ccl_query(bibset, "a!2b",
186 "@attr 4=2 @attr 1=1016 a "
187 "@attr 4=2 @attr 1=1016 b "));
189 YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
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=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
192 YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
193 YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
194 YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
195 YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
196 YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
197 YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
198 YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
199 YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
200 YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
201 YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
202 YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 a,\\ b "));
203 YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
204 YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 a\\ -\\ b "));
205 ccl_qual_rm(&bibset);
208 int main(int argc, char **argv)
210 YAZ_CHECK_INIT(argc, argv);
221 * indent-tabs-mode: nil
223 * vim: shiftwidth=4 tabstop=8 expandtab