From: Adam Dickmeiss Date: Sun, 7 May 2006 17:45:41 +0000 (+0000) Subject: Added more tests for retrieval/record_conv system. For retrieval, fixed X-Git-Tag: YAZ.2.1.20~71 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=27481680fb1a69456e789e5bc8e1ec914337287d;p=yaz-moved-to-github.git Added more tests for retrieval/record_conv system. For retrieval, fixed 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. --- diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 8d63316..8da7306 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -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 index 0000000..4a3dbba --- /dev/null +++ b/include/yaz/libxml2_error.h @@ -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 +#include + +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 + */ + diff --git a/src/Makefile.am b/src/Makefile.am index 27a493a..bf98d9c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000..3241a63 --- /dev/null +++ b/src/libxml2_error.c @@ -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 +#include +#include +#include + +#if HAVE_XML2 +#include +#endif + +#if HAVE_XSLT +#include +#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 + */ + diff --git a/src/record_conv.c b/src/record_conv.c index ab530a5..8c00ebb 100644 --- a/src/record_conv.c +++ b/src/record_conv.c @@ -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; } } diff --git a/src/retrieval.c b/src/retrieval.c index 4c2ee60..3ca6d8d 100644 --- a/src/retrieval.c +++ b/src/retrieval.c @@ -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; } diff --git a/test/.cvsignore b/test/.cvsignore index c982580..e630501 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -19,4 +19,5 @@ tstxmlquery tstpquery tst_filepath tst_record_conv +tst_retrieval nfatest1 diff --git a/test/tst_record_conv.c b/test/tst_record_conv.c index fbd218a..c4f09c4 100644 --- a/test/tst_record_conv.c +++ b/test/tst_record_conv.c @@ -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 #include #include #include +#include +#include #if HAVE_CONFIG_H #include @@ -120,6 +122,10 @@ static void tst_configure() "", "Attribute 'inputformat' required", 0)); YAZ_CHECK(conv_configure_test("" + "" + "", + "Missing attribute 'stylesheet'", 0)); + YAZ_CHECK(conv_configure_test("" "" " #include #include #include +#include +#include #if HAVE_CONFIG_H #include @@ -117,10 +119,11 @@ static void tst_configure() " Expected 'retrieval'", 0)); YAZ_CHECK(conv_configure_test("" - "", 0, 0)); + "", + "Missing 'syntax' attribute", 0)); YAZ_CHECK(conv_configure_test("" - "\n" + "\n" " " "" "" @@ -136,7 +139,7 @@ static void tst_configure() 0, 0)); YAZ_CHECK(conv_configure_test("" - "" + "" "" "" "" "" "" - "" + "" "" "" "