2 * Copyright (C) 1995-2005, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tstxmlquery.c,v 1.7 2006-01-31 11:01:26 adam Exp $
11 #include <yaz/wrbuf.h>
12 #include <yaz/xmlquery.h>
13 #include <yaz/pquery.h>
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
29 enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml)
31 YAZ_PQF_Parser parser = yaz_pqf_create();
32 ODR odr = odr_createmem(ODR_ENCODE);
34 enum pqf2xml_status status = XML_NO_ERROR;
40 rpn = yaz_pqf_parse(parser, odr, pqf);
42 yaz_pqf_destroy(parser);
51 yaz_rpnquery2xml(rpn, &doc);
54 status = QUERY2XML_FAILED;
60 xmlDocDumpMemory(doc, (xmlChar **) &buf_out, &len_out);
62 if (len_out == strlen(expect_xml)
63 && memcmp(buf_out, expect_xml, len_out) == 0)
69 printf("%.*s\n", len_out, buf_out);
70 status = XML_NO_MATCH;
75 status = QUERY2XML_FAILED;
84 YAZ_CHECK_EQ(pqf2xml_text("@attr 1=4 bad query", ""), PQF_FAILED);
86 YAZ_CHECK_EQ(pqf2xml_text(
88 "<?xml version=\"1.0\"?>\n"
89 "<query set=\"Bib-1\" type=\"rpn\">"
90 "<apt><attr type=\"1\" value=\"4\"/>"
91 "<term>computer</term></apt>"
92 "</query>\n"), XML_MATCH);
94 YAZ_CHECK_EQ(pqf2xml_text(
95 "@attr 2=1 @attr 1=title computer",
96 "<?xml version=\"1.0\"?>\n"
97 "<query set=\"Bib-1\" type=\"rpn\">"
98 "<apt><attr type=\"1\" value=\"title\"/>"
99 "<attr type=\"2\" value=\"1\"/>"
100 "<term>computer</term></apt>"
101 "</query>\n"), XML_MATCH);
103 YAZ_CHECK_EQ(pqf2xml_text(
104 "@attr 2=1 @attr exp1 1=1 computer",
105 "<?xml version=\"1.0\"?>\n"
106 "<query set=\"Bib-1\" type=\"rpn\">"
107 "<apt><attr set=\"Exp-1\" type=\"1\" value=\"1\"/>"
108 "<attr type=\"2\" value=\"1\"/>"
109 "<term>computer</term></apt>"
110 "</query>\n"), XML_MATCH);
112 YAZ_CHECK_EQ(pqf2xml_text(
114 "<?xml version=\"1.0\"?>\n"
115 "<query set=\"Bib-1\" type=\"rpn\">"
116 "<binary type=\"and\">"
117 "<apt><term>a</term></apt><apt><term>b</term></apt>"
118 "</binary></query>\n"), XML_MATCH);
120 YAZ_CHECK_EQ(pqf2xml_text(
122 "<?xml version=\"1.0\"?>\n"
123 "<query set=\"Bib-1\" type=\"rpn\">"
124 "<binary type=\"or\">"
125 "<binary type=\"and\"><apt><term>a</term></apt>"
126 "<apt><term>b</term></apt></binary>"
127 "<apt><term>c</term></apt>"
128 "</binary></query>\n"), XML_MATCH);
130 YAZ_CHECK_EQ(pqf2xml_text(
132 "<?xml version=\"1.0\"?>\n"
133 "<query set=\"Bib-1\" type=\"rpn\">"
134 "<rset>abe</rset></query>\n"), XML_MATCH);
136 YAZ_CHECK_EQ(pqf2xml_text(
137 /* exclusion, distance, ordered, relationtype,
138 knownunit, proxunit */
139 "@prox 0 3 1 2 k 2 a b",
140 "<?xml version=\"1.0\"?>\n"
141 "<query set=\"Bib-1\" type=\"rpn\">"
142 "<binary type=\"prox\" exclusion=\"false\" "
145 "relationType=\"2\" "
146 "knownProximityUnit=\"2\">"
147 "<apt><term>a</term></apt><apt><term>b</term></apt>"
148 "</binary></query>\n"), XML_MATCH);
153 int main (int argc, char **argv)
155 YAZ_CHECK_INIT(argc, argv);
163 * indent-tabs-mode: nil
165 * vim: shiftwidth=4 tabstop=8 expandtab