1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data
3 * See the file LICENSE for details.
5 #include <yaz/retrieval.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=\"tst_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=\"tst_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));
265 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
266 "<retrieval syntax=\"usmarc\">"
267 "<backend syntax=\"xml\" name=\"dc\">"
268 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
270 " inputcharset=\"utf-8\""
271 " outputcharset=\"marc-8\""
272 " inputformat=\"xml\""
273 " outputformat=\"marc\""
280 YAZ_CHECK(conv_configure_test(
282 " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
283 "<retrieval syntax=\"grs-1\"/>"
284 "<retrieval syntax=\"usmarc\" name=\"F\"/>"
285 "<retrieval syntax=\"usmarc\" name=\"B\"/>"
286 "<retrieval syntax=\"xml\" name=\"marcxml\" "
287 " identifier=\"info:srw/schema/1/marcxml-v1.1\">"
288 " <backend syntax=\"usmarc\" name=\"F\">"
289 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
290 " inputcharset=\"marc-8\"/>"
293 "<retrieval syntax=\"xml\" name=\"danmarc\">"
294 " <backend syntax=\"usmarc\" name=\"F\">"
295 " <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
296 " inputcharset=\"marc-8\"/>"
299 "<retrieval syntax=\"xml\" name=\"dc\" "
300 " identifier=\"info:srw/schema/1/dc-v1.1\">"
301 " <backend syntax=\"usmarc\" name=\"F\">"
302 " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
303 " inputcharset=\"marc-8\"/>"
304 " <xslt stylesheet=\"tst_record_conv.xsl\"/> "
314 int main(int argc, char **argv)
316 YAZ_CHECK_INIT(argc, argv);
318 yaz_log_xml_errors(0, 0 /* disable it */);
329 * c-file-style: "Stroustrup"
330 * indent-tabs-mode: nil
332 * vim: shiftwidth=4 tabstop=8 expandtab