Dont include removed header libxml2_error.h
[yaz-moved-to-github.git] / test / tst_retrieval.c
index 66c9477..89ba159 100644 (file)
@@ -1,16 +1,12 @@
-/*
- * Copyright (C) 2005-2006, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
  * See the file LICENSE for details.
- *
- * $Id: tst_retrieval.c,v 1.6 2006-07-06 10:17:55 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>
@@ -76,12 +72,12 @@ int conv_configure_test(const char *xmlstring, const char *expect_error,
 
     if (!p)
     {
-        if (expect_error && !strcmp(wrbuf_buf(w), expect_error))
+        if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
             ret = 1;
         else
         {
             ret = 0;
-            printf("%.*s\n", wrbuf_len(w), wrbuf_buf(w));
+            printf("%s\n", wrbuf_cstr(w));
         }
     }
     else
@@ -100,67 +96,60 @@ int conv_configure_test(const char *xmlstring, const char *expect_error,
             ret = 1;
         }
     }
-    wrbuf_free(w, 1);
+    wrbuf_destroy(w);
     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>", 
+                                  "</retrievalinfo>",
                                   "Missing 'syntax' attribute", 0));
 
+
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval syntax=\"usmarc\">\n"
-                                  "  "
-                                  "<convert>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</convert>"
+                                  "<retrieval" 
+                                  " unknown=\"unknown\""
+                                  ">"
                                   "</retrieval>"
                                   "</retrievalinfo>",
-                                  0, 0));
+                                  "Element <retrieval>:  expected attributes "
+                                  "'syntax', identifier' or 'name', got "
+                                  "'unknown'", 0));
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval syntax=\"usmarc\">"
-                                  "<convert>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</convert>"
+                                  "<retrieval" 
+                                  " syntax=\"unknown_synt\""
+                                  ">"
                                   "</retrieval>"
-                                  "<retrieval syntax=\"usmarc\">"
-                                  "<convert>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
+                                  "</retrievalinfo>",
+                                  "Element <retrieval>:  unknown attribute "
+                                  "value syntax='unknown_synt'", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
                                   "/>"
-                                  "</convert>"
-                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " name=\"marcxml\"/>"
                                   "</retrievalinfo>",
                                   0, 0));
 
@@ -170,58 +159,153 @@ static void tst_configure()
                                   " syntax=\"usmarc\""
                                   " name=\"marcxml\"" 
                                   " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  ">"
-                                  "<convert/>"
-                                  "</retrieval>"
+                                  "/>"
                                   "</retrievalinfo>",
                                   0, 0));
 
+
+
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
                                   "<retrieval" 
                                   " syntax=\"usmarc\""
-                                  " name=\"marcxml\""
-                                  " backendsyntax=\"usmarc\""
-                                  " backendname=\"marcxml\""
                                   " 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>",
-                                  0, 0));
+                                  "Element <backend>: expected attributes 'syntax' or 'name,"
+                                  " got 'schema'", 0));
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
                                   "<retrieval" 
                                   " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  " name=\"marcxml\">"
+                                  " <backend syntax=\"usmarc\""
                                   " name=\"marcxml\""
-                                  " backendsyntax=\"usmarc\""
-                                  " backendschema=\"marcxml\""
+                                  "/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
                                   " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  ">"
-                                  "<convert/>"
+                                  " name=\"marcxml\">"
+                                  " <backend syntax=\"unknown\""
+                                  "/>"
                                   "</retrieval>"
                                   "</retrievalinfo>",
-                                  "Bad attribute 'backendschema'."
-                                  " Use 'backendname' instead", 
-                                  0));
+                                  "Element <backend syntax='unknown'>: "
+                                  "attribute 'syntax' has invalid value "
+                                  "'unknown'", 0));
 
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
                                   "<retrieval" 
-                                  " syntax=\"unknown_synt\""
-                                  ">"
-                                  "<convert/>"
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                    " name=\"marcxml\">"
+                                  " <backend syntax=\"usmarc\""
+                                  " unknown=\"silly\""
+                                  "/>"
                                   "</retrieval>"
                                   "</retrievalinfo>",
-                                  "Bad syntax 'unknown_synt'", 0));
+                                  "Element <backend>: expected attributes "
+                                  "'syntax' or 'name, got 'unknown'", 0));
+
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " backendsyntax=\"unknown_synt\""
-                                  ">"
-                                  "<convert/>"
+                                  "<retrieval syntax=\"usmarc\">"
+                                  "<backend syntax=\"xml\" name=\"dc\">"
+                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"non-existent\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
                                   "</retrieval>"
                                   "</retrievalinfo>",
-                                  "Bad backendsyntax 'unknown_synt'", 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 syntax=\"usmarc\">"
+                                  "<backend syntax=\"xml\" name=\"dc\">"
+                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"not-existent\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
+                                  "</retrieval>"
+                                  "</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\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    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>"
+                                  "<retrieval syntax=\"xml\" name=\"danmarc\">"
+                                  "  <backend syntax=\"usmarc\" name=\"F\">"
+                                  "    <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
+                                  "          inputcharset=\"marc-8\"/>"
+                                  "  </backend>"
+                                  "</retrieval>"
+                                  "<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>",
+                                  0, 0));
 
 }
 
@@ -231,7 +315,7 @@ int main(int argc, char **argv)
 {
     YAZ_CHECK_INIT(argc, argv);
 
-    libxml2_error_to_yazlog(0 /* disable it */, "");
+    yaz_log_xml_errors(0, 0 /* disable it */);
 
 #if YAZ_HAVE_XSLT
     tst_configure();
@@ -242,6 +326,7 @@ int main(int argc, char **argv)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab