1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2012 Index Data
3 * See the file LICENSE for details.
9 #include <yaz/retrieval.h>
11 #include <yaz/wrbuf.h>
17 #include <libxml/parser.h>
18 #include <libxml/tree.h>
20 yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
22 xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
25 wrbuf_printf(w, "xmlParseMemory");
30 xmlNodePtr ptr = xmlDocGetRootElement(doc);
31 yaz_retrieval_t p = yaz_retrieval_create();
35 const char *srcdir = getenv("srcdir");
37 yaz_retrieval_set_path(p, srcdir);
41 wrbuf_printf(w, "xmlDocGetRootElement");
42 yaz_retrieval_destroy(p);
47 wrbuf_printf(w, "yaz_retrieval_create");
51 int r = yaz_retrieval_configure(p, ptr);
55 wrbuf_puts(w, yaz_retrieval_get_error(p));
56 yaz_retrieval_destroy(p);
65 int conv_configure_test(const char *xmlstring, const char *expect_error,
68 WRBUF w = wrbuf_alloc();
71 yaz_retrieval_t p = conv_configure(xmlstring, w);
75 if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
80 printf("%s\n", wrbuf_cstr(w));
88 yaz_retrieval_destroy(p);
95 yaz_retrieval_destroy(p);
103 static void tst_configure(void)
105 YAZ_CHECK(conv_configure_test("<bad",
106 "xmlParseMemory", 0));
108 YAZ_CHECK(conv_configure_test("<bad/>",
109 "Expected element <retrievalinfo>", 0));
111 YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
113 YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
114 "Element <retrievalinfo>:"
115 " expected element <retrieval>, got <bad>",
118 YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
120 "Missing 'syntax' attribute", 0));
123 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
125 " unknown=\"unknown\""
129 "Element <retrieval>: expected attributes "
130 "'syntax', identifier' or 'name', got "
133 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
135 " syntax=\"unknown_synt\""
139 "Element <retrieval>: unknown attribute "
140 "value syntax='unknown_synt'", 0));
142 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
149 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
152 " name=\"marcxml\"/>"
157 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
161 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
168 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
171 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
176 "Element <retrieval>: expected zero or one element "
177 "<backend>, got <convert>", 0));
179 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
182 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
184 " <backend syntax=\"usmarc\""
185 " schema=\"marcxml\""
189 "Element <backend>: expected attributes 'syntax' or 'name,"
190 " got 'schema'", 0));
192 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
195 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
197 " <backend syntax=\"usmarc\""
204 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
207 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
209 " <backend syntax=\"unknown\""
213 "Element <backend syntax='unknown'>: "
214 "attribute 'syntax' has invalid value "
218 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
221 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
223 " <backend syntax=\"usmarc\""
228 "Element <backend>: expected attributes "
229 "'syntax' or 'name, got 'unknown'", 0));
232 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
233 "<retrieval syntax=\"usmarc\">"
234 "<backend syntax=\"xml\" name=\"dc\">"
235 "<xslt stylesheet=\"test_record_conv.xsl\"/>"
237 " inputcharset=\"utf-8\""
238 " outputcharset=\"non-existent\""
239 " inputformat=\"xml\""
240 " outputformat=\"marc\""
245 "Element <marc inputcharset='utf-8'"
246 " outputcharset='non-existent'>: Unsupported character"
247 " set mapping defined by attribute values", 0));
249 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
250 "<retrieval syntax=\"usmarc\">"
251 "<backend syntax=\"xml\" name=\"dc\">"
252 "<xslt stylesheet=\"test_record_conv.xsl\"/>"
254 " inputcharset=\"utf-8\""
255 " outputcharset=\"marc-8\""
256 " inputformat=\"not-existent\""
257 " outputformat=\"marc\""
262 "Element <marc inputformat='not-existent'>: Unsupported"
263 " 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=\"test_record_conv.xsl\"/>"
271 " inputcharset=\"utf-8\""
272 " outputcharset=\"marc-8\""
273 " inputformat=\"xml\""
274 " outputformat=\"marc\""
280 "Element <retrieval>: "
281 "only one <backend> allowed", 0));
284 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
285 "<retrieval syntax=\"usmarc\">"
286 "<backend syntax=\"xml\" name=\"dc\">"
287 "<xslt stylesheet=\"test_record_conv.xsl\"/>"
289 " inputcharset=\"utf-8\""
290 " outputcharset=\"marc-8\""
291 " inputformat=\"xml\""
292 " outputformat=\"marc\""
299 YAZ_CHECK(conv_configure_test(
301 " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
302 "<retrieval syntax=\"grs-1\"/>"
303 "<retrieval syntax=\"usmarc\" name=\"F\"/>"
304 "<retrieval syntax=\"usmarc\" name=\"B\"/>"
305 "<retrieval syntax=\"xml\" name=\"marcxml\" "
306 " identifier=\"info:srw/schema/1/marcxml-v1.1\">"
307 " <backend syntax=\"usmarc\" name=\"F\">"
308 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
309 " inputcharset=\"marc-8\"/>"
312 "<retrieval syntax=\"xml\" name=\"danmarc\">"
313 " <backend syntax=\"usmarc\" name=\"F\">"
314 " <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
315 " inputcharset=\"marc-8\"/>"
318 "<retrieval syntax=\"xml\" name=\"dc\" "
319 " identifier=\"info:srw/schema/1/dc-v1.1\">"
320 " <backend syntax=\"usmarc\" name=\"F\">"
321 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
322 " inputcharset=\"marc-8\"/>"
323 " <xslt stylesheet=\"test_record_conv.xsl\"/> "
333 int main(int argc, char **argv)
335 YAZ_CHECK_INIT(argc, argv);
337 yaz_log_xml_errors(0, 0 /* disable it */);
348 * c-file-style: "Stroustrup"
349 * indent-tabs-mode: nil
351 * vim: shiftwidth=4 tabstop=8 expandtab