2 * Copyright (C) 2005-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tst_retrieval.c,v 1.6 2006-07-06 10:17:55 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_buf(w), expect_error))
84 printf("%.*s\n", wrbuf_len(w), wrbuf_buf(w));
92 yaz_retrieval_destroy(p);
99 yaz_retrieval_destroy(p);
107 static void tst_configure()
109 YAZ_CHECK(conv_configure_test("<bad",
110 "xmlParseMemory", 0));
112 YAZ_CHECK(conv_configure_test("<bad/>",
113 "Missing 'retrievalinfo' element", 0));
115 YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
117 YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
119 " Expected 'retrieval'", 0));
121 YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
123 "Missing 'syntax' attribute", 0));
125 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
126 "<retrieval syntax=\"usmarc\">\n"
129 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
131 " inputcharset=\"utf-8\""
132 " outputcharset=\"marc-8\""
133 " inputformat=\"xml\""
134 " outputformat=\"marc\""
141 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
142 "<retrieval syntax=\"usmarc\">"
144 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
146 " inputcharset=\"utf-8\""
147 " outputcharset=\"marc-8\""
148 " inputformat=\"xml\""
149 " outputformat=\"marc\""
153 "<retrieval syntax=\"usmarc\">"
155 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
157 " inputcharset=\"utf-8\""
158 " outputcharset=\"marc-8\""
159 " inputformat=\"xml\""
160 " outputformat=\"marc\""
168 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
172 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
179 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
183 " backendsyntax=\"usmarc\""
184 " backendname=\"marcxml\""
185 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
192 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
196 " backendsyntax=\"usmarc\""
197 " backendschema=\"marcxml\""
198 " identifier=\"info:srw/schema/1/marcxml-v1.1\""
203 "Bad attribute 'backendschema'."
204 " Use 'backendname' instead",
208 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
210 " syntax=\"unknown_synt\""
215 "Bad syntax 'unknown_synt'", 0));
217 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
219 " backendsyntax=\"unknown_synt\""
224 "Bad backendsyntax 'unknown_synt'", 0));
230 int main(int argc, char **argv)
232 YAZ_CHECK_INIT(argc, argv);
234 libxml2_error_to_yazlog(0 /* disable it */, "");
245 * indent-tabs-mode: nil
247 * vim: shiftwidth=4 tabstop=8 expandtab