/*
- * Copyright (C) 2005-2006, Index Data ApS
+ * Copyright (C) 2005-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: tst_retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
+ * $Id: tst_retrieval.c,v 1.9 2007-01-03 08:42:16 adam Exp $
*
*/
#include <yaz/retrieval.h>
#include <yaz/test.h>
#include <yaz/wrbuf.h>
#include <string.h>
+#include <yaz/log.h>
+#include <yaz/libxml2_error.h>
#if HAVE_CONFIG_H
#include <config.h>
#endif
-#if HAVE_XSLT
+#if YAZ_HAVE_XSLT
#include <libxml/parser.h>
#include <libxml/tree.h>
return ret;
}
-static void tst_configure()
+static void tst_configure(void)
{
YAZ_CHECK(conv_configure_test("<bad",
"xmlParseMemory", 0));
YAZ_CHECK(conv_configure_test("<bad/>",
- "Missing 'retrievalinfo' element", 0));
+ "Expected element <retrievalinfo>", 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
- "Bad element 'bad'."
- " Expected 'retrieval'", 0));
+ "Element <retrievalinfo>:"
+ " expected element <retrieval>, got <bad>",
+ 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
- "</retrievalinfo>", 0, 0));
+ "</retrievalinfo>",
+ "Missing 'syntax' attribute", 0));
+
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " unknown=\"unknown\""
+ ">"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <retrieval>: expected attributes "
+ "'syntax', identifier' or 'name', got "
+ "'unknown'", 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"unknown_synt\""
+ ">"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <retrieval>: unknown attribute "
+ "value syntax='unknown_synt'", 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ "/>"
+ "</retrievalinfo>",
+ 0, 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " name=\"marcxml\"/>"
+ "</retrievalinfo>",
+ 0, 0));
+
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " name=\"marcxml\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ "/>"
+ "</retrievalinfo>",
+ 0, 0));
+
+
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ " name=\"marcxml\">"
+ "<convert/>"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <retrieval>: expected zero or one element "
+ "<backend>, got <convert>", 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ " name=\"marcxml\">"
+ " <backend syntax=\"usmarc\""
+ " schema=\"marcxml\""
+ "/>"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <backend>: expected attributes 'syntax' or 'name,"
+ " got 'schema'", 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval>\n"
- " "
- "<convert>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ " name=\"marcxml\">"
+ " <backend syntax=\"usmarc\""
+ " name=\"marcxml\""
+ "/>"
+ "</retrieval>"
+ "</retrievalinfo>",
+ 0, 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ " name=\"marcxml\">"
+ " <backend syntax=\"unknown\""
+ "/>"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <backend syntax='unknown'>: "
+ "attribute 'syntax' has invalid value "
+ "'unknown'", 0));
+
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval"
+ " syntax=\"usmarc\""
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+ " name=\"marcxml\">"
+ " <backend syntax=\"usmarc\""
+ " unknown=\"silly\""
+ "/>"
+ "</retrieval>"
+ "</retrievalinfo>",
+ "Element <backend>: expected attributes "
+ "'syntax' or 'name, got 'unknown'", 0));
+
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval syntax=\"usmarc\">"
+ "<backend syntax=\"xml\" name=\"dc\">"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
" inputcharset=\"utf-8\""
- " outputcharset=\"marc-8\""
+ " outputcharset=\"non-existent\""
" inputformat=\"xml\""
" outputformat=\"marc\""
"/>"
- "</convert>"
+ "</backend>"
"</retrieval>"
"</retrievalinfo>",
- 0, 0));
+ "Element <marc inputcharset='utf-8'"
+ " outputcharset='non-existent'>: Unsupported character"
+ " set mapping defined by attribute values", 0));
YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval>"
- "<convert>"
+ "<retrieval syntax=\"usmarc\">"
+ "<backend syntax=\"xml\" name=\"dc\">"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
" inputcharset=\"utf-8\""
" outputcharset=\"marc-8\""
- " inputformat=\"xml\""
+ " inputformat=\"not-existent\""
" outputformat=\"marc\""
"/>"
- "</convert>"
+ "</backend>"
"</retrieval>"
- "<retrieval>"
- "<convert>"
+ "</retrievalinfo>",
+ "Element <marc inputformat='not-existent'>: Unsupported"
+ " input format defined by attribute value", 0));
+
+ YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+ "<retrieval syntax=\"usmarc\">"
+ "<backend syntax=\"xml\" name=\"dc\">"
"<xslt stylesheet=\"tst_record_conv.xsl\"/>"
"<marc"
" inputcharset=\"utf-8\""
" inputformat=\"xml\""
" outputformat=\"marc\""
"/>"
- "</convert>"
+ "</backend>"
"</retrieval>"
"</retrievalinfo>",
0, 0));
-
- YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval"
- " syntax=\"usmarc\""
- " schema=\"marcxml\""
- " identifier=\"info:srw/schema/1/marcxml-v1.1\""
- ">"
- "<convert/>"
+ YAZ_CHECK(conv_configure_test(
+ "<retrievalinfo "
+ " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
+ "<retrieval syntax=\"grs-1\"/>"
+ "<retrieval syntax=\"usmarc\" name=\"F\"/>"
+ "<retrieval syntax=\"usmarc\" name=\"B\"/>"
+ "<retrieval syntax=\"xml\" name=\"marcxml\" "
+ " identifier=\"info:srw/schema/1/marcxml-v1.1\">"
+ " <backend syntax=\"usmarc\" name=\"F\">"
+ " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
+ " inputcharset=\"marc-8\"/>"
+ " </backend>"
"</retrieval>"
- "</retrievalinfo>",
- 0, 0));
-
- YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval"
- " syntax=\"unknown_synt\""
- ">"
- "<convert/>"
+ "<retrieval syntax=\"xml\" name=\"danmarc\">"
+ " <backend syntax=\"usmarc\" name=\"F\">"
+ " <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
+ " inputcharset=\"marc-8\"/>"
+ " </backend>"
"</retrieval>"
- "</retrievalinfo>",
- "Bad syntax 'unknown_synt'", 0));
-
- YAZ_CHECK(conv_configure_test("<retrievalinfo>"
- "<retrieval"
- " backendsyntax=\"unknown_synt\""
- ">"
- "<convert/>"
+ "<retrieval syntax=\"xml\" name=\"dc\" "
+ " identifier=\"info:srw/schema/1/dc-v1.1\">"
+ " <backend syntax=\"usmarc\" name=\"F\">"
+ " <marc inputformat=\"marc\" outputformat=\"marcxml\" "
+ " inputcharset=\"marc-8\"/>"
+ " <xslt stylesheet=\"tst_record_conv.xsl\"/> "
+ " </backend>"
"</retrieval>"
"</retrievalinfo>",
- "Bad backendsyntax 'unknown_synt'", 0));
+ 0, 0));
}
int main(int argc, char **argv)
{
YAZ_CHECK_INIT(argc, argv);
-#if HAVE_XSLT
+
+ libxml2_error_to_yazlog(0 /* disable it */, "");
+
+#if YAZ_HAVE_XSLT
tst_configure();
#endif
YAZ_CHECK_TERM;