2 * Copyright (C) 2005-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: tst_retrieval.c,v 1.2 2006-05-05 18:37:08 adam Exp $
8 #include <yaz/retrieval.h>
10 #include <yaz/wrbuf.h>
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
22 yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
24 xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
27 wrbuf_printf(w, "xmlParseMemory");
32 xmlNodePtr ptr = xmlDocGetRootElement(doc);
33 yaz_retrieval_t p = yaz_retrieval_create();
37 const char *srcdir = getenv("srcdir");
39 yaz_retrieval_set_path(p, srcdir);
43 wrbuf_printf(w, "xmlDocGetRootElement");
44 yaz_retrieval_destroy(p);
49 wrbuf_printf(w, "yaz_retrieval_create");
53 int r = yaz_retrieval_configure(p, ptr);
57 wrbuf_puts(w, yaz_retrieval_get_error(p));
58 yaz_retrieval_destroy(p);
67 int conv_configure_test(const char *xmlstring, const char *expect_error,
70 WRBUF w = wrbuf_alloc();
73 yaz_retrieval_t p = conv_configure(xmlstring, w);
77 if (expect_error && !strcmp(wrbuf_buf(w), expect_error))
82 printf("%.*s\n", wrbuf_len(w), wrbuf_buf(w));
90 yaz_retrieval_destroy(p);
97 yaz_retrieval_destroy(p);
105 static void tst_configure()
107 YAZ_CHECK(conv_configure_test("<bad",
108 "xmlParseMemory", 0));
110 YAZ_CHECK(conv_configure_test("<bad/>",
111 "Missing 'retrievalinfo' element", 0));
113 YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
115 YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
117 " Expected 'retrieval'", 0));
119 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
122 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
124 " inputcharset=\"utf-8\""
125 " outputcharset=\"marc-8\""
126 " inputformat=\"xml\""
127 " outputformat=\"marc\""
134 YAZ_CHECK(conv_configure_test("<retrievalinfo>"
137 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
139 " inputcharset=\"utf-8\""
140 " outputcharset=\"marc-8\""
141 " inputformat=\"xml\""
142 " outputformat=\"marc\""
148 "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
150 " inputcharset=\"utf-8\""
151 " outputcharset=\"marc-8\""
152 " inputformat=\"xml\""
153 " outputformat=\"marc\""
163 int main(int argc, char **argv)
165 YAZ_CHECK_INIT(argc, argv);
175 * indent-tabs-mode: nil
177 * vim: shiftwidth=4 tabstop=8 expandtab