2 * Copyright (C) 2005-2007, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tst_retrieval.c,v 1.10 2007-03-19 14:40:07 adam Exp $
8 #include <yaz/retrieval.h>
10 #include <yaz/wrbuf.h>
13 #include <yaz/libxml2_error.h>
21 #include <libxml/parser.h>
22 #include <libxml/tree.h>
24 yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
26 xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
29 wrbuf_printf(w, "xmlParseMemory");
34 xmlNodePtr ptr = xmlDocGetRootElement(doc);
35 yaz_retrieval_t p = yaz_retrieval_create();
39 const char *srcdir = getenv("srcdir");
41 yaz_retrieval_set_path(p, srcdir);
45 wrbuf_printf(w, "xmlDocGetRootElement");
46 yaz_retrieval_destroy(p);
51 wrbuf_printf(w, "yaz_retrieval_create");
55 int r = yaz_retrieval_configure(p, ptr);
59 wrbuf_puts(w, yaz_retrieval_get_error(p));
60 yaz_retrieval_destroy(p);
69 int conv_configure_test(const char *xmlstring, const char *expect_error,
72 WRBUF w = wrbuf_alloc();
75 yaz_retrieval_t p = conv_configure(xmlstring, w);
79 if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
84 printf("%s\n", wrbuf_cstr(w));
92 yaz_retrieval_destroy(p);
99 yaz_retrieval_destroy(p);
107 static void tst_configure(void)
109 YAZ_CHECK(conv_configure_test("<bad",
110 "xmlParseMemory", 0));
112 YAZ_CHECK(conv_configure_test("<bad/>",
113 "Expected element <retrievalinfo>", 0));
115 YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
117 YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
118 "Element <retrievalinfo>:"
119 " expected element <retrieval>, got <bad>",
122 YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
124 "Missing 'syntax' attribute", 0));
127 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
129 " unknown=\"unknown\""
133 "Element <retrieval>: expected attributes "
134 "'syntax', identifier' or 'name', got "
137 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
139 " syntax=\"unknown_synt\""
143 "Element <retrieval>: unknown attribute "
144 "value syntax='unknown_synt'", 0));
146 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
153 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
156 " name=\"marcxml\"/>"
161 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
165 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
172 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
175 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
180 "Element <retrieval>: expected zero or one element "
181 "<backend>, got <convert>", 0));
183 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
186 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
188 " <backend syntax=\"usmarc\""
189 " schema=\"marcxml\""
193 "Element <backend>: expected attributes 'syntax' or 'name,"
194 " got 'schema'", 0));
196 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
199 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
201 " <backend syntax=\"usmarc\""
208 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
211 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
213 " <backend syntax=\"unknown\""
217 "Element <backend syntax='unknown'>: "
218 "attribute 'syntax' has invalid value "
222 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
225 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
227 " <backend syntax=\"usmarc\""
232 "Element <backend>: expected attributes "
233 "'syntax' or 'name, got 'unknown'", 0));
236 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
237 "<retrieval syntax=\"usmarc\">"
238 "<backend syntax=\"xml\" name=\"dc\">"
239 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
241 " inputcharset=\"utf-8\""
242 " outputcharset=\"non-existent\""
243 " inputformat=\"xml\""
244 " outputformat=\"marc\""
249 "Element <marc inputcharset='utf-8'"
250 " outputcharset='non-existent'>: Unsupported character"
251 " set mapping defined by attribute values", 0));
253 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
254 "<retrieval syntax=\"usmarc\">"
255 "<backend syntax=\"xml\" name=\"dc\">"
256 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
258 " inputcharset=\"utf-8\""
259 " outputcharset=\"marc-8\""
260 " inputformat=\"not-existent\""
261 " outputformat=\"marc\""
266 "Element <marc inputformat='not-existent'>: Unsupported"
267 " input format defined by attribute value", 0));
269 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
270 "<retrieval syntax=\"usmarc\">"
271 "<backend syntax=\"xml\" name=\"dc\">"
272 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
274 " inputcharset=\"utf-8\""
275 " outputcharset=\"marc-8\""
276 " inputformat=\"xml\""
277 " outputformat=\"marc\""
284 YAZ_CHECK(conv_configure_test(
286 " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
287 "<retrieval syntax=\"grs-1\"/>"
288 "<retrieval syntax=\"usmarc\" name=\"F\"/>"
289 "<retrieval syntax=\"usmarc\" name=\"B\"/>"
290 "<retrieval syntax=\"xml\" name=\"marcxml\" "
291 " identifier=\"info:srw/schema/1/marcxml-v1.1\">"
292 " <backend syntax=\"usmarc\" name=\"F\">"
293 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
294 " inputcharset=\"marc-8\"/>"
297 "<retrieval syntax=\"xml\" name=\"danmarc\">"
298 " <backend syntax=\"usmarc\" name=\"F\">"
299 " <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
300 " inputcharset=\"marc-8\"/>"
303 "<retrieval syntax=\"xml\" name=\"dc\" "
304 " identifier=\"info:srw/schema/1/dc-v1.1\">"
305 " <backend syntax=\"usmarc\" name=\"F\">"
306 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
307 " inputcharset=\"marc-8\"/>"
308 " <xslt stylesheet=\"tst_record_conv.xsl\"/> "
318 int main(int argc, char **argv)
320 YAZ_CHECK_INIT(argc, argv);
322 libxml2_error_to_yazlog(0 /* disable it */, "");
333 * indent-tabs-mode: nil
335 * vim: shiftwidth=4 tabstop=8 expandtab