From 3bfe867a001cb4e4f88d47541f77a21027719bd5 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Apr 2007 14:42:31 +0000 Subject: [PATCH] Added test for query charset converter. --- include/yaz/Makefile.am | 4 +- include/yaz/query-charset.h | 57 +++++++++++++++++++++++++++ src/query-charset.c | 6 +-- test/.cvsignore | 1 + test/Makefile.am | 5 ++- test/tst_query_charset.c | 92 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 include/yaz/query-charset.h create mode 100644 test/tst_query_charset.c diff --git a/include/yaz/Makefile.am b/include/yaz/Makefile.am index 7a75208..85ca9c0 100644 --- a/include/yaz/Makefile.am +++ b/include/yaz/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am,v 1.39 2007-02-23 10:15:01 adam Exp $ +## $Id: Makefile.am,v 1.40 2007-04-10 14:42:31 adam Exp $ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \ @@ -7,7 +7,7 @@ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h comstack.h \ readconf.h record_conv.h retrieval.h statserv.h \ tcpip.h test.h timing.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 libxml2_error.h xmltypes.h snprintf.h \ + xmlquery.h libxml2_error.h xmltypes.h snprintf.h query-charset.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/query-charset.h b/include/yaz/query-charset.h new file mode 100644 index 0000000..758d0ea --- /dev/null +++ b/include/yaz/query-charset.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1995-2007, Index Data + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Index Data nor the names of its contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* $Id: query-charset.h,v 1.1 2007-04-10 14:42:31 adam Exp $ */ +/** + * \file querytowrbuf.h + * \brief Query to WRBUF (to strings) + */ + +#ifndef YAZ_QUERY_CHARSET_H +#define YAZ_QUERY_CHARSET_H + +#include +#include +#include + +YAZ_BEGIN_CDECL + +YAZ_EXPORT void yaz_query_charset_convert_apt(Z_AttributesPlusTerm *apt, + ODR o, yaz_iconv_t cd); + +YAZ_EXPORT void yaz_query_charset_convert_rpnquery(Z_RPNQuery *q, + ODR o, yaz_iconv_t cd); +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/query-charset.c b/src/query-charset.c index 2001315..421ad52 100644 --- a/src/query-charset.c +++ b/src/query-charset.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * All rights reserved. * - * $Id: query-charset.c,v 1.1 2007-03-21 19:47:28 adam Exp $ + * $Id: query-charset.c,v 1.2 2007-04-10 14:42:31 adam Exp $ */ /** \file query-charset.c @@ -12,10 +12,8 @@ #include #include -#include +#include #include -#include -#include void yaz_query_charset_convert_buf(char *buf_in, int len_in, char **buf_out, int *len_out, diff --git a/test/.cvsignore b/test/.cvsignore index cd83936..41d4c65 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -26,6 +26,7 @@ tst_timing tst_timing.log tst_comstack tst_comstack.log +tst_query_charset nfatest1 nfaxmltest1 nfaxmltest1.log diff --git a/test/Makefile.am b/test/Makefile.am index 95129f5..bf32645 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,11 +1,11 @@ ## Copyright (C) 1995-2007, Index Data ApS ## All rights reserved. -## $Id: Makefile.am,v 1.33 2007-02-25 14:46:51 adam Exp $ +## $Id: Makefile.am,v 1.34 2007-04-10 14:42:31 adam Exp $ check_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf tstodr tstccl tstlog \ tstsoap1 tstsoap2 tstodrstack tstlogthread tstxmlquery tstpquery \ tst_comstack tst_filepath tst_record_conv tst_retrieval tst_tpath \ - tst_timing + tst_timing tst_query_charset check_SCRIPTS = tstcql.sh tstmarciso.sh tstmarcxml.sh tstmarccol.sh TESTS = $(check_PROGRAMS) $(check_SCRIPTS) @@ -62,3 +62,4 @@ tst_record_conv_SOURCES = tst_record_conv.c tst_retrieval_SOURCES = tst_retrieval.c tst_tpath_SOURCES = tst_tpath.c tst_timing_SOURCES = tst_timing.c +tst_query_charset_SOURCES = tst_query_charset.c diff --git a/test/tst_query_charset.c b/test/tst_query_charset.c new file mode 100644 index 0000000..c597e65 --- /dev/null +++ b/test/tst_query_charset.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 1995-2007, Index Data ApS + * See the file LICENSE for details. + * + * $Id: tst_query_charset.c,v 1.1 2007-04-10 14:42:31 adam Exp $ + */ + +#include +#include + +#include +#include +#include +#include + +enum query_charset_status { + NO_ERROR, + PQF_FAILED, + MATCH, + NO_MATCH, + CONV_FAILED +}; + +enum query_charset_status t(yaz_iconv_t cd, + const char *pqf, const char *expect_pqf) +{ + YAZ_PQF_Parser parser = yaz_pqf_create(); + ODR odr = odr_createmem(ODR_ENCODE); + Z_RPNQuery *rpn; + enum query_charset_status status = NO_ERROR; + + YAZ_CHECK(parser); + + YAZ_CHECK(odr); + + rpn = yaz_pqf_parse(parser, odr, pqf); + + yaz_pqf_destroy(parser); + + if (!rpn) + status = PQF_FAILED; + else + { + WRBUF w = wrbuf_alloc(); + + yaz_query_charset_convert_rpnquery(rpn, odr, cd); + yaz_rpnquery_to_wrbuf(w, rpn); + if (!expect_pqf || strcmp(expect_pqf, wrbuf_cstr(w)) == 0) + status = MATCH; + else + { + status = NO_MATCH; + printf("Result: %s\n", wrbuf_cstr(w)); + } + wrbuf_destroy(w); + } + odr_destroy(odr); + return status; +} + +static void tst(void) +{ + yaz_iconv_t cd = yaz_iconv_open("iso-8859-1", "utf-8"); + + YAZ_CHECK(cd); + if (!cd) + return; + + YAZ_CHECK_EQ(t(cd, "@attr 1=4 bad query", 0), PQF_FAILED); + YAZ_CHECK_EQ(t(cd, "@attr 1=4 ok", "@attrset Bib-1 @attr 1=4 ok"), MATCH); + + /* m followed by latin smaller letter ae */ + YAZ_CHECK_EQ(t(cd, "@attr 1=4 m\xc3\xa6", "@attrset Bib-1 @attr 1=4 m\xe6"), MATCH); + + yaz_iconv_close(cd); +} + +int main (int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + tst(); + YAZ_CHECK_TERM; +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ + -- 1.7.10.4