-## $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 \
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 \
--- /dev/null
+/*
+ * 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
+ */
+
* 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
#include <stdio.h>
#include <assert.h>
-#include <yaz/proto.h>
+#include <yaz/query-charset.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,
tst_timing.log
tst_comstack
tst_comstack.log
+tst_query_charset
nfatest1
nfaxmltest1
nfaxmltest1.log
## 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)
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
--- /dev/null
+/*
+ * 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
+ */
+