1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
5 #include <yaz/retrieval.h>
10 #include <yaz/libxml2_error.h>
18 #include <libxml/parser.h>
19 #include <libxml/tree.h>
21 yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
23 xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
26 wrbuf_printf(w, "xmlParseMemory");
31 xmlNodePtr ptr = xmlDocGetRootElement(doc);
32 yaz_retrieval_t p = yaz_retrieval_create();
36 const char *srcdir = getenv("srcdir");
38 yaz_retrieval_set_path(p, srcdir);
42 wrbuf_printf(w, "xmlDocGetRootElement");
43 yaz_retrieval_destroy(p);
48 wrbuf_printf(w, "yaz_retrieval_create");
52 int r = yaz_retrieval_configure(p, ptr);
56 wrbuf_puts(w, yaz_retrieval_get_error(p));
57 yaz_retrieval_destroy(p);
66 int conv_configure_test(const char *xmlstring, const char *expect_error,
69 WRBUF w = wrbuf_alloc();
72 yaz_retrieval_t p = conv_configure(xmlstring, w);
76 if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
81 printf("%s\n", wrbuf_cstr(w));
89 yaz_retrieval_destroy(p);
96 yaz_retrieval_destroy(p);
104 static void tst_configure(void)
106 YAZ_CHECK(conv_configure_test("<bad",
107 "xmlParseMemory", 0));
109 YAZ_CHECK(conv_configure_test("<bad/>",
110 "Expected element <retrievalinfo>", 0));
112 YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
114 YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
115 "Element <retrievalinfo>:"
116 " expected element <retrieval>, got <bad>",
119 YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
121 "Missing 'syntax' attribute", 0));
124 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
126 " unknown=\"unknown\""
130 "Element <retrieval>: expected attributes "
131 "'syntax', identifier' or 'name', got "
134 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
136 " syntax=\"unknown_synt\""
140 "Element <retrieval>: unknown attribute "
141 "value syntax='unknown_synt'", 0));
143 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
150 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
153 " name=\"marcxml\"/>"
158 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
162 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
169 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
172 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
177 "Element <retrieval>: expected zero or one element "
178 "<backend>, got <convert>", 0));
180 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
183 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
185 " <backend syntax=\"usmarc\""
186 " schema=\"marcxml\""
190 "Element <backend>: expected attributes 'syntax' or 'name,"
191 " got 'schema'", 0));
193 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
196 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
198 " <backend syntax=\"usmarc\""
205 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
208 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
210 " <backend syntax=\"unknown\""
214 "Element <backend syntax='unknown'>: "
215 "attribute 'syntax' has invalid value "
219 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
222 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
224 " <backend syntax=\"usmarc\""
229 "Element <backend>: expected attributes "
230 "'syntax' or 'name, got 'unknown'", 0));
233 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
234 "<retrieval syntax=\"usmarc\">"
235 "<backend syntax=\"xml\" name=\"dc\">"
236 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
238 " inputcharset=\"utf-8\""
239 " outputcharset=\"non-existent\""
240 " inputformat=\"xml\""
241 " outputformat=\"marc\""
246 "Element <marc inputcharset='utf-8'"
247 " outputcharset='non-existent'>: Unsupported character"
248 " set mapping defined by attribute values", 0));
250 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
251 "<retrieval syntax=\"usmarc\">"
252 "<backend syntax=\"xml\" name=\"dc\">"
253 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
255 " inputcharset=\"utf-8\""
256 " outputcharset=\"marc-8\""
257 " inputformat=\"not-existent\""
258 " outputformat=\"marc\""
263 "Element <marc inputformat='not-existent'>: Unsupported"
264 " input format defined by attribute value", 0));
266 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
267 "<retrieval syntax=\"usmarc\">"
268 "<backend syntax=\"xml\" name=\"dc\">"
269 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
271 " inputcharset=\"utf-8\""
272 " outputcharset=\"marc-8\""
273 " inputformat=\"xml\""
274 " outputformat=\"marc\""
281 YAZ_CHECK(conv_configure_test(
283 " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
284 "<retrieval syntax=\"grs-1\"/>"
285 "<retrieval syntax=\"usmarc\" name=\"F\"/>"
286 "<retrieval syntax=\"usmarc\" name=\"B\"/>"
287 "<retrieval syntax=\"xml\" name=\"marcxml\" "
288 " identifier=\"info:srw/schema/1/marcxml-v1.1\">"
289 " <backend syntax=\"usmarc\" name=\"F\">"
290 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
291 " inputcharset=\"marc-8\"/>"
294 "<retrieval syntax=\"xml\" name=\"danmarc\">"
295 " <backend syntax=\"usmarc\" name=\"F\">"
296 " <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
297 " inputcharset=\"marc-8\"/>"
300 "<retrieval syntax=\"xml\" name=\"dc\" "
301 " identifier=\"info:srw/schema/1/dc-v1.1\">"
302 " <backend syntax=\"usmarc\" name=\"F\">"
303 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
304 " inputcharset=\"marc-8\"/>"
305 " <xslt stylesheet=\"tst_record_conv.xsl\"/> "
315 int main(int argc, char **argv)
317 YAZ_CHECK_INIT(argc, argv);
319 libxml2_error_to_yazlog(0 /* disable it */, "");
330 * c-file-style: "Stroustrup"
331 * indent-tabs-mode: nil
333 * vim: shiftwidth=4 tabstop=8 expandtab