Added more tests for retrieval/record_conv system. For retrieval, fixed
authorAdam Dickmeiss <adam@indexdata.dk>
Sun, 7 May 2006 17:45:41 +0000 (17:45 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Sun, 7 May 2006 17:45:41 +0000 (17:45 +0000)
error handling which occurred in the case where syntax attribute was
missing from retrieval element. Libxml2/libxslt errors may be sent to
yaz_log via new utility libxml2_error_to_yazlog.

include/yaz/Makefile.am
include/yaz/libxml2_error.h [new file with mode: 0644]
src/Makefile.am
src/libxml2_error.c [new file with mode: 0644]
src/record_conv.c
src/retrieval.c
test/.cvsignore
test/tst_record_conv.c
test/tst_retrieval.c

index 8d63316..8da7306 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am,v 1.30 2006-05-04 20:00:45 adam Exp $
+## $Id: Makefile.am,v 1.31 2006-05-07 17:45:41 adam Exp $
 
 pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \
  diagbib1.h diagsrw.h sortspec.h log.h logrpn.h marcdisp.h nfa.h \
@@ -7,7 +7,7 @@ pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \
  readconf.h record_conv.h retrieval.h statserv.h \
  tcpip.h test.h unix.h tpath.h wrbuf.h xmalloc.h \
  yaz-ccl.h yaz-iconv.h yaz-util.h yaz-version.h yconfig.h proto.h \
- xmlquery.h \
+ xmlquery.h libxml2_error.h \
  \
  ill.h ill-core.h item-req.h z-accdes1.h z-accform1.h \
  z-acckrb1.h z-core.h z-date.h z-diag1.h z-espec1.h z-estask.h z-exp.h \
diff --git a/include/yaz/libxml2_error.h b/include/yaz/libxml2_error.h
new file mode 100644 (file)
index 0000000..4a3dbba
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2006, Index Data ApS
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation, in whole or in part, for any purpose, is hereby granted,
+ * provided that:
+ *
+ * 1. This copyright and permission notice appear in all copies of the
+ * software and its documentation. Notices of copyright or attribution
+ * which appear at the beginning of any file must remain unchanged.
+ *
+ * 2. The name of Index Data or the individual authors may not be used to
+ * endorse or promote products derived from this software without specific
+ * prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
+ * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
+ * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ *
+ * $Id: libxml2_error.h,v 1.1 2006-05-07 17:45:41 adam Exp $
+ */
+
+/**
+ * \file libxml2_error.h
+ * \brief Libxml2 error handler
+ */
+
+#ifndef YAZ_LIBXML2_ERROR_H
+#define YAZ_LIBXML2_ERROR_H
+
+#include <stdio.h>
+#include <yaz/yconfig.h>
+
+YAZ_BEGIN_CDECL
+
+/** \brief direct Libxml2/Libxslt errors to yaz_log
+    \param level yaz_log level to use
+    \param lead_msg leading message (or NULL if none)
+    \retval 0 successful; libxml2 is present
+    \retval -1 failure; libxml2 is not present
+*/
+YAZ_EXPORT
+int libxml2_error_to_yazlog(int level, const char *lead_msg);
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index 27a493a..bf98d9c 100644 (file)
@@ -1,6 +1,6 @@
 ## This file is part of the YAZ toolkit.
 ## Copyright (C) 1994-2006, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.35 2006-05-04 20:00:45 adam Exp $
+## $Id: Makefile.am,v 1.36 2006-05-07 17:45:41 adam Exp $
 
 YAZ_VERSION_INFO=2:1:0
 
@@ -51,7 +51,7 @@ libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \
   odr_null.c ber_null.c odr_int.c ber_int.c odr_tag.c odr_cons.c \
   odr_seq.c odr_oct.c ber_oct.c odr_bit.c ber_bit.c odr_oid.c \
   ber_oid.c odr_use.c odr_choice.c odr_any.c ber_any.c odr.c odr_mem.c \
-  dumpber.c odr_enum.c odr-priv.h \
+  dumpber.c odr_enum.c odr-priv.h libxml2_error.c \
   comstack.c tcpip.c waislen.c unix.c \
   z-accdes1.c z-accform1.c z-acckrb1.c z-core.c \
   z-diag1.c z-espec1.c z-estask.c z-exp.c z-grs.c z-mterm2.c z-opac.c \
diff --git a/src/libxml2_error.c b/src/libxml2_error.c
new file mode 100644 (file)
index 0000000..3241a63
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2006, Index Data ApS
+ * See the file LICENSE for details.
+ *
+ * $Id: libxml2_error.c,v 1.1 2006-05-07 17:45:41 adam Exp $
+ */
+/**
+ * \file libxml2_error.c
+ * \brief Libxml2 error handling
+ */
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <yaz/log.h>
+#include <yaz/libxml2_error.h>
+
+#if HAVE_XML2
+#include <libxml/xmlerror.h>
+#endif
+
+#if HAVE_XSLT
+#include <libxslt/xsltutils.h>
+#endif
+
+static int libxml2_error_level = 0;
+
+static void proxy_xml_error_handler(void *ctx, const char *fmt, ...)
+{
+    char buf[1024];
+
+    va_list ap;
+    va_start(ap, fmt);
+
+#ifdef WIN32
+    vsprintf(buf, fmt, ap);
+#else
+    vsnprintf(buf, sizeof(buf), fmt, ap);
+#endif
+    yaz_log(libxml2_error_level, "%s: %s", (char*) ctx, buf);
+
+    va_end (ap);
+}
+
+int libxml2_error_to_yazlog(int level, const char *lead_msg)
+{
+    libxml2_error_level = level;
+#if HAVE_XSLT
+    xsltSetGenericErrorFunc((void *) "XSLT", proxy_xml_error_handler);
+#endif
+#if HAVE_XML2
+    xmlSetGenericErrorFunc((void *) "XML", proxy_xml_error_handler);
+    return 0;
+#else
+    return -1;
+#endif
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index ab530a5..8c00ebb 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: record_conv.c,v 1.5 2006-05-07 14:48:25 adam Exp $
+ * $Id: record_conv.c,v 1.6 2006-05-07 17:45:41 adam Exp $
  */
 /**
  * \file record_conv.c
@@ -145,7 +145,7 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr)
             stylesheet = (const char *) attr->children->content;
         else
         {
-            wrbuf_printf(p->wr_error, "Bad attribute '%s'."
+            wrbuf_printf(p->wr_error, "Bad attribute '%s'"
                          "Expected stylesheet.", attr->name);
             return -1;
         }
@@ -210,7 +210,7 @@ static int conv_marc(yaz_record_conv_t p, const xmlNode *ptr)
             output_format = (const char *) attr->children->content;
         else
         {
-            wrbuf_printf(p->wr_error, "Bad attribute '%s'.", attr->name);
+            wrbuf_printf(p->wr_error, "Bad attribute '%s'", attr->name);
             return -1;
         }
     }
@@ -323,7 +323,7 @@ int yaz_record_conv_configure(yaz_record_conv_t p, const void *ptr_v)
             else
             {
                 wrbuf_printf(p->wr_error, "Bad element '%s'."
-                             "Expected marc, xslt, ..", ptr->name);
+                              "Expected marc, xslt, ..", ptr->name);
                 return -1;
             }
         }
index 4c2ee60..3ca6d8d 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: retrieval.c,v 1.3 2006-05-07 14:48:25 adam Exp $
+ * $Id: retrieval.c,v 1.4 2006-05-07 17:45:41 adam Exp $
  */
 /**
  * \file retrieval.c
@@ -171,7 +171,7 @@ static int conf_retrieval(yaz_retrieval_t p, const xmlNode *ptr)
     }
     if (!el->syntax)
     {
-        wrbuf_printf(p->wr_error, "Missing 'syntax' attribute.", attr->name);
+        wrbuf_printf(p->wr_error, "Missing 'syntax' attribute");
         return -1;
     }
 
index c982580..e630501 100644 (file)
@@ -19,4 +19,5 @@ tstxmlquery
 tstpquery
 tst_filepath
 tst_record_conv
+tst_retrieval
 nfatest1
index fbd218a..c4f09c4 100644 (file)
@@ -2,13 +2,15 @@
  * Copyright (C) 2005-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: tst_record_conv.c,v 1.6 2006-05-07 14:48:25 adam Exp $
+ * $Id: tst_record_conv.c,v 1.7 2006-05-07 17:45:41 adam Exp $
  *
  */
 #include <yaz/record_conv.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>
@@ -120,6 +122,10 @@ static void tst_configure()
                                   "</convert>",
                                   "Attribute 'inputformat' required", 0));
     YAZ_CHECK(conv_configure_test("<convert>"
+                                  "<xslt/>"
+                                  "</convert>",
+                                  "Missing attribute 'stylesheet'", 0));
+    YAZ_CHECK(conv_configure_test("<convert>"
                                   "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
                                   "<marc"
                                   " inputcharset=\"utf-8\""
@@ -280,6 +286,7 @@ static void tst_convert()
 int main(int argc, char **argv)
 {
     YAZ_CHECK_INIT(argc, argv);
+    libxml2_error_to_yazlog(0 /* disable log */, 0);
 #if HAVE_XSLT
     tst_configure();
     tst_convert();
index cea9da0..db10872 100644 (file)
@@ -2,13 +2,15 @@
  * Copyright (C) 2005-2006, 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.4 2006-05-07 17:45:41 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>
@@ -117,10 +119,11 @@ static void tst_configure()
                                   " Expected 'retrieval'", 0));
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
-                                  "</retrievalinfo>", 0, 0));
+                                  "</retrievalinfo>", 
+                                  "Missing 'syntax' attribute", 0));
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval>\n"
+                                  "<retrieval syntax=\"usmarc\">\n"
                                   "  "
                                   "<convert>"
                                   "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
@@ -136,7 +139,7 @@ static void tst_configure()
                                   0, 0));
 
     YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval>"
+                                  "<retrieval syntax=\"usmarc\">"
                                   "<convert>"
                                   "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
                                   "<marc"
@@ -147,7 +150,7 @@ static void tst_configure()
                                   "/>"
                                   "</convert>"
                                   "</retrieval>"
-                                  "<retrieval>"
+                                  "<retrieval syntax=\"usmarc\">"
                                   "<convert>"
                                   "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
                                   "<marc"
@@ -198,6 +201,9 @@ static void tst_configure()
 int main(int argc, char **argv)
 {
     YAZ_CHECK_INIT(argc, argv);
+
+    libxml2_error_to_yazlog(0 /* disable it */, "");
+
 #if HAVE_XSLT
     tst_configure();
 #endif