Added test for query charset converter. YAZ.before.OID.patch
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 10 Apr 2007 14:42:31 +0000 (14:42 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 10 Apr 2007 14:42:31 +0000 (14:42 +0000)
include/yaz/Makefile.am
include/yaz/query-charset.h [new file with mode: 0644]
src/query-charset.c
test/.cvsignore
test/Makefile.am
test/tst_query_charset.c [new file with mode: 0644]

index 7a75208..85ca9c0 100644 (file)
@@ -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 \
 
 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 \
  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 \
  \
  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 (file)
index 0000000..758d0ea
--- /dev/null
@@ -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 <yaz/yconfig.h>
+#include <yaz/proto.h>
+#include <yaz/yaz-iconv.h>
+
+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
+ */
+
index 2001315..421ad52 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2007, Index Data ApS
  * All rights reserved.
  *
  * 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
  */
 
 /** \file query-charset.c
 #include <stdio.h>
 #include <assert.h>
 
 #include <stdio.h>
 #include <assert.h>
 
-#include <yaz/proto.h>
+#include <yaz/query-charset.h>
 #include <yaz/wrbuf.h>
 #include <yaz/wrbuf.h>
-#include <yaz/odr.h>
-#include <yaz/yaz-iconv.h>
 
 void yaz_query_charset_convert_buf(char *buf_in, int len_in,
                                    char **buf_out, int *len_out,
 
 void yaz_query_charset_convert_buf(char *buf_in, int len_in,
                                    char **buf_out, int *len_out,
index cd83936..41d4c65 100644 (file)
@@ -26,6 +26,7 @@ tst_timing
 tst_timing.log
 tst_comstack
 tst_comstack.log
 tst_timing.log
 tst_comstack
 tst_comstack.log
+tst_query_charset
 nfatest1
 nfaxmltest1
 nfaxmltest1.log
 nfatest1
 nfaxmltest1
 nfaxmltest1.log
index 95129f5..bf32645 100644 (file)
@@ -1,11 +1,11 @@
 ## Copyright (C) 1995-2007, Index Data ApS
 ## All rights reserved.
 ## 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 \
 
 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)
 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_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 (file)
index 0000000..c597e65
--- /dev/null
@@ -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 <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/query-charset.h>
+#include <yaz/pquery.h>
+#include <yaz/querytowrbuf.h>
+#include <yaz/test.h>
+
+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
+ */
+