Rename C-based tests
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Mar 2010 14:37:11 +0000 (15:37 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 9 Mar 2010 14:37:11 +0000 (15:37 +0100)
63 files changed:
test/.gitignore
test/Makefile.am
test/test_ccl.c [new file with mode: 0644]
test/test_comstack.c [new file with mode: 0644]
test/test_file_glob.c [new file with mode: 0644]
test/test_filepath.c [new file with mode: 0644]
test/test_iconv.c [new file with mode: 0644]
test/test_icu.c [new file with mode: 0644]
test/test_json.c [new file with mode: 0644]
test/test_log.c [new file with mode: 0644]
test/test_log_thread.c [new file with mode: 0644]
test/test_match_glob.c [new file with mode: 0644]
test/test_matchstr.c [new file with mode: 0644]
test/test_nmem.c [new file with mode: 0644]
test/test_odr.c [new file with mode: 0644]
test/test_odrstack.c [new file with mode: 0644]
test/test_oid.c [new file with mode: 0644]
test/test_pquery.c [new file with mode: 0644]
test/test_query_charset.c [new file with mode: 0644]
test/test_record_conv.c [new file with mode: 0644]
test/test_record_conv.xsl [new file with mode: 0644]
test/test_retrieval.c [new file with mode: 0644]
test/test_rpn2cql.c [new file with mode: 0644]
test/test_soap1.c [new file with mode: 0644]
test/test_soap2.c [new file with mode: 0644]
test/test_timing.c [new file with mode: 0644]
test/test_tpath.c [new file with mode: 0644]
test/test_wrbuf.c [new file with mode: 0644]
test/test_xmalloc.c [new file with mode: 0644]
test/test_xml_include.c [new file with mode: 0644]
test/test_xml_include.xml [new file with mode: 0644]
test/test_xmlquery.c [new file with mode: 0644]
test/tst_comstack.c [deleted file]
test/tst_file_glob.c [deleted file]
test/tst_filepath.c [deleted file]
test/tst_icu_I18N.c [deleted file]
test/tst_json.c [deleted file]
test/tst_match_glob.c [deleted file]
test/tst_oid.c [deleted file]
test/tst_query_charset.c [deleted file]
test/tst_record_conv.c [deleted file]
test/tst_record_conv.xsl [deleted file]
test/tst_retrieval.c [deleted file]
test/tst_rpn2cql.c [deleted file]
test/tst_timing.c [deleted file]
test/tst_tpath.c [deleted file]
test/tst_xml_include.c [deleted file]
test/tst_xml_include.xml [deleted file]
test/tstccl.c [deleted file]
test/tsticonv.c [deleted file]
test/tstlog.c [deleted file]
test/tstlogthread.c [deleted file]
test/tstmatchstr.c [deleted file]
test/tstnmem.c [deleted file]
test/tstodr.asn
test/tstodr.c [deleted file]
test/tstodrstack.c [deleted file]
test/tstpquery.c [deleted file]
test/tstsoap1.c [deleted file]
test/tstsoap2.c [deleted file]
test/tstwrbuf.c [deleted file]
test/tstxmalloc.c [deleted file]
test/tstxmlquery.c [deleted file]

index 0ffa500..ad09bef 100644 (file)
@@ -1,38 +1,38 @@
 .deps
 Makefile
 Makefile.in
-tstodrcodec.c
-tstodrcodec.h
+test_odrcodec.c
+test_odrcodec.h
 .libs
-tstccl
-tsticonv
-tstmatchstr
-tstnmem
-tstodr
-tstwrbuf
-tstlog
-tstsoap1
-tstsoap2
-tstodrstack
-tstlogthread
-tstxmlquery
-tstpquery
-tstxmalloc
-tst_filepath
-tst_record_conv
-tst_retrieval
-tst_tpath
-tst_timing
-tst_comstack
-tst_query_charset
-tst_icu_I18N
-tst_match_glob
-tst_rpn2cql
-tst_json
-tst_xml_include
-nfatest1
-nfaxmltest1
-tst_oid
+test_ccl
+test_iconv
+test_matchstr
+test_nmem
+test_odr
+test_wrbuf
+test_log
+test_soap1
+test_soap2
+test_odrstack
+test_logthread
+test_xmlquery
+test_pquery
+test_xmalloc
+test_filepath
+test_record_conv
+test_retrieval
+test_tpath
+test_timing
+test_comstack
+test_query_charset
+test_icu
+test_match_glob
+test_rpn2cql
+test_json
+test_xml_include
+test_oid
+test_file_glob
+test_log_thread
 *.log
 *.o
 *~
index 8937de7..daad0f9 100644 (file)
@@ -1,12 +1,12 @@
 ## This file is part of the YAZ toolkit.
 ## Copyright (C) 1995-2010 Index Data
 
-check_PROGRAMS = tstxmalloc 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_query_charset tst_oid tst_icu_I18N tst_match_glob \
- tst_rpn2cql tst_json tst_xml_include tst_file_glob
+check_PROGRAMS = test_xmalloc test_iconv test_nmem test_matchstr test_wrbuf \
+ test_odr test_ccl test_log \
+ test_soap1 test_soap2 test_odrstack test_log_thread test_xmlquery test_pquery \
+ test_comstack test_filepath test_record_conv test_retrieval test_tpath \
+ test_timing test_query_charset test_oid test_icu test_match_glob \
+ test_rpn2cql test_json test_xml_include test_file_glob
 
 check_SCRIPTS = tstmarc.sh tstmarccol.sh tstcql2xcql.sh tstcql2pqf.sh tsticu.sh
 
@@ -31,7 +31,7 @@ EXTRA_DIST = tstodr.asn tstodrcodec.c tstodrcodec.h cql2xcqlsample \
  marccol5.u8.marc marccol5.u8.1.lst marccol5.u8.2.lst \
  tsticu-0.xml tsticu-0.input tsticu-0.output \
  tsticu-1.xml tsticu-1.input tsticu-1.output \
- tst_record_conv.xsl tst_xml_include.xml
+ test_record_conv.xsl test_xml_include.xml
 
 YAZCOMP = ../util/yaz-asncomp
 YAZCOMPLINE = $(YAZCOMP) -d z.tcl -i yaz -I../include $(YCFLAGS)
@@ -45,41 +45,41 @@ dist-hook:
        cp $(srcdir)/cql2pqf/*.err $(srcdir)/cql2pqf/*.out $(distdir)/cql2pqf
 
 # Rule for generating codecs for our small ASN.1 spec
-tstodrcodec.c tstodrcodec.h: tstodr.asn $(YAZCOMP)
+test_odrcodec.c test_odrcodec.h: tstodr.asn $(YAZCOMP)
        cd $(srcdir); $(YAZCOMP) tstodr.asn
 
 LDADD = ../src/libyaz.la
-tst_icu_I18N_LDADD = ../src/libyaz_icu.la $(ICU_LIBS)
+test_icu_LDADD = ../src/libyaz_icu.la $(ICU_LIBS)
 AM_CFLAGS = $(PTHREAD_CFLAGS)
 
 
 CONFIG_CLEAN_FILES=*.log
 
-tstxmalloc_SOURCES = tstxmalloc.c
-tsticonv_SOURCES = tsticonv.c
-tstnmem_SOURCES = tstnmem.c
-tstmatchstr_SOURCES = tstmatchstr.c
-tstwrbuf_SOURCES = tstwrbuf.c
-tstodr_SOURCES = tstodrcodec.c tstodrcodec.h tstodr.c
-tstodrstack_SOURCES = tstodrstack.c
-tstccl_SOURCES = tstccl.c
-tstlog_SOURCES = tstlog.c
-tstsoap1_SOURCES = tstsoap1.c
-tstsoap2_SOURCES = tstsoap2.c
-tstlogthread_SOURCES = tstlogthread.c
-tstxmlquery_SOURCES = tstxmlquery.c
-tstpquery_SOURCES = tstpquery.c
-tst_comstack_SOURCES = tst_comstack.c
-tst_filepath_SOURCES = tst_filepath.c
-tst_oid_SOURCES = tst_oid.c
-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
-tst_icu_I18N_SOURCES = tst_icu_I18N.c
-tst_match_glob_SOURCES = tst_match_glob.c
-tst_rpn2cql_SOURCES = tst_rpn2cql.c
-tst_json_SOURCES = tst_json.c
-tst_xml_include_SOURCES = tst_xml_include.c
-tst_file_glob_SOURCES = tst_file_glob.c
+test_xmalloc_SOURCES = test_xmalloc.c
+test_iconv_SOURCES = test_iconv.c
+test_nmem_SOURCES = test_nmem.c
+test_matchstr_SOURCES = test_matchstr.c
+test_wrbuf_SOURCES = test_wrbuf.c
+test_odr_SOURCES = test_odrcodec.c test_odrcodec.h test_odr.c
+test_odrstack_SOURCES = test_odrstack.c
+test_ccl_SOURCES = test_ccl.c
+test_log_SOURCES = test_log.c
+test_soap1_SOURCES = test_soap1.c
+test_soap2_SOURCES = test_soap2.c
+test_log_thread_SOURCES = test_log_thread.c
+test_xmlquery_SOURCES = test_xmlquery.c
+test_pquery_SOURCES = test_pquery.c
+test_comstack_SOURCES = test_comstack.c
+test_filepath_SOURCES = test_filepath.c
+test_oid_SOURCES = test_oid.c
+test_record_conv_SOURCES = test_record_conv.c
+test_retrieval_SOURCES = test_retrieval.c
+test_tpath_SOURCES = test_tpath.c
+test_timing_SOURCES = test_timing.c
+test_query_charset_SOURCES = test_query_charset.c
+test_icu_SOURCES = test_icu.c
+test_match_glob_SOURCES = test_match_glob.c
+test_rpn2cql_SOURCES = test_rpn2cql.c
+test_json_SOURCES = test_json.c
+test_xml_include_SOURCES = test_xml_include.c
+test_file_glob_SOURCES = test_file_glob.c
diff --git a/test/test_ccl.c b/test/test_ccl.c
new file mode 100644 (file)
index 0000000..dada1e0
--- /dev/null
@@ -0,0 +1,277 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/* CCL test */
+
+#include <string.h>
+#include <yaz/ccl_xml.h>
+#include <yaz/log.h>
+#include <yaz/test.h>
+
+
+static int tst_ccl_query(CCL_bibset bibset,
+                         const char *query,
+                         const char *result)
+{
+    CCL_parser parser = ccl_parser_create(bibset);
+    int ret = 0;
+
+    if (parser && bibset)
+    {
+        struct ccl_rpn_node *rpn;
+        
+        rpn = ccl_parser_find_str(parser, query);
+        if (rpn)
+        {
+            /* parse ok. check that result is there and match */
+            WRBUF wrbuf = wrbuf_alloc();
+            ccl_pquery(wrbuf, rpn);
+            
+            /* check expect a result and that it matches */
+            if (result && !strcmp(wrbuf_cstr(wrbuf), result))
+                ret = 1;
+            else
+            {
+                yaz_log(YLOG_WARN, "%s: result does not match", query);
+                yaz_log(YLOG_WARN, " expected %s", result);
+                yaz_log(YLOG_WARN, " got      %s", wrbuf_cstr(wrbuf));
+                ret = 0;
+            }
+            ccl_rpn_delete(rpn);
+            wrbuf_destroy(wrbuf);
+        }
+        else 
+        {
+            if (result)
+            {
+                yaz_log(YLOG_WARN, "%s: parse failed", query);
+                ret = 0;
+            }
+            else
+                ret = 1;
+        }
+    }
+    ccl_parser_destroy (parser);
+    return ret;
+}
+
+void tst1(int pass)
+{
+    CCL_bibset bibset = ccl_qual_mk();
+    char tstline[128];
+
+    YAZ_CHECK(bibset);
+    if (!bibset)
+        return;
+
+    switch(pass)
+    {
+    case 0:
+        ccl_qual_fitem(bibset, "u=4    s=pw t=l,r", "ti");
+        ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r",    "term");
+        ccl_qual_fitem(bibset, "1=/my/title",         "dc.title");
+        ccl_qual_fitem(bibset, "r=r",         "date");
+        ccl_qual_fitem(bibset, "r=o",         "x");
+        ccl_qual_fitem(bibset, "dc.title", "title");
+        ccl_qual_fitem(bibset, "term dc.title", "comb");
+        break;
+    case 1:
+        strcpy(tstline, "ti u=4    s=pw t=l,r");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "term 1=1016 s=al,pw t=r  # default term");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "dc.title 1=/my/title");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "date r=r # ordered relation");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "x r=o # ordered relation");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "title dc.title # alias");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "comb term dc.title # combination");
+        ccl_qual_line(bibset, tstline);
+        break;
+    case 2:
+        ccl_qual_buf(bibset, "ti u=4    s=pw t=l,r\n"
+                     "term 1=1016 s=al,pw t=r\r\n"
+                     "\n"
+                     "dc.title 1=/my/title\n"
+                     "date r=r\n" 
+                     "x r=o\n"
+                     "title dc.title\n"
+                     "comb term dc.title\n"
+            );
+        break;
+    case 3:
+#if YAZ_HAVE_XML2
+        if (1)
+        {
+            xmlDocPtr doc;
+            int r;
+            const char *addinfo = 0;
+            const char *xml_str = 
+                "<cclmap>\n"
+                " <qual name=\"ti\">\n"
+                "   <attr type=\"u\" value=\"4\"/>\n"
+                "   <attr type=\"s\" value=\"pw\"/>\n"
+                "   <attr type=\"t\" value=\"l,r\"/>\n"
+                " </qual>\n"
+                " <qual name=\"term\">\n"
+                "   <attr type=\"1\" value=\"1016\"/>\n"
+                "   <attr type=\"s\" value=\"al,pw\"/>\n"
+                "   <attr type=\"t\" value=\"r\"/>\n"
+                " </qual>\n"
+                " <qual name=\"dc.title\">\n"
+                "   <attr type=\"1\" value=\"/my/title\"/>\n"
+                " </qual>\n"
+                " <qual name=\"date\">\n"
+                "   <attr type=\"r\" value=\"r\"/>\n"
+                " </qual>\n"
+                " <qual name=\"x\">\n"
+                "   <attr type=\"r\" value=\"o\"/>\n"
+                " </qual>\n"
+                " <qual name=\"title\">\n"
+                "   <qual name=\"dc.title\"/>\n"
+                " </qual>\n"
+                " <qual name=\"comb\">\n"
+                "   <qual name=\"term\"/>\n"
+                "   <qual name=\"dc.title\"/>\n"
+                " </qual>\n"
+                "</cclmap>\n";
+            
+            doc = xmlParseMemory(xml_str, strlen(xml_str));
+            YAZ_CHECK(doc);
+
+            r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
+            YAZ_CHECK_EQ(r, 0);
+
+            xmlFreeDoc(doc);
+        }
+        break;
+#else
+        return;
+#endif
+    default:
+        YAZ_CHECK(0);
+        return;
+    }
+    
+    YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
+                  "@and "
+                  "@attr 4=2 @attr 1=1016 x1 "
+                  "@attr 4=2 @attr 1=1016 x2 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
+    YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a%b", 
+                  "@prox 0 1 0 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+    YAZ_CHECK(tst_ccl_query(bibset, "a%1b", 
+                  "@prox 0 1 0 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a%2b", 
+                  "@prox 0 2 0 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a%19b", 
+                  "@prox 0 19 0 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne", 
+                  "@prox 0 1 0 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 spid "
+                  "@attr 4=2 @attr 1=1016 æserne "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a!b", 
+                  "@prox 0 1 1 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+    YAZ_CHECK(tst_ccl_query(bibset, "a!2b", 
+                  "@prox 0 2 1 2 k 2 "
+                  "@attr 4=2 @attr 1=1016 a "
+                  "@attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
+    YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
+    YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
+    YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
+    YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
+    YAZ_CHECK(tst_ccl_query(bibset, "a b", 
+                            "@and @attr 4=2 @attr 1=1016 a "
+                            "@attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "a b?", 
+                            "@and @attr 4=2 @attr 1=1016 a "
+                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "title=a", 
+                            "@attr 1=/my/title a "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "comb=a", 
+                            "@or @attr 4=2 @attr 1=1016 a "
+                            "@attr 1=/my/title a "));
+
+    /* Bug #2895 */
+#if 1
+    YAZ_CHECK(tst_ccl_query(bibset, "a? b?", 
+                            /* incorrect. */
+                            "@and @attr 4=2 @attr 1=1016 a? "
+                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
+#else
+    YAZ_CHECK(tst_ccl_query(bibset, "a? b?", 
+                            /* correct */
+                            "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
+                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
+#endif
+    ccl_qual_rm(&bibset);
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst1(0);
+    tst1(1);
+    tst1(2);
+    tst1(3);
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_comstack.c b/test/test_comstack.c
new file mode 100644 (file)
index 0000000..eee72f8
--- /dev/null
@@ -0,0 +1,268 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/comstack.h>
+#include <yaz/tcpip.h>
+
+static void tst_http_request(void)
+{
+    {
+        /* no content, no headers */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\r\n"
+            "\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 16), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 17), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 18), 18);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 19), 18);
+    }
+    {
+        /* one header, no content */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\r\n"
+            "Content-Type: x\r\n"
+            "\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 34), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 35);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 36), 35);
+    }        
+    {
+        /* one content-length header, length 0 */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\r\n"
+            "Content-Length: 0\r\n"
+            "\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 37), 37);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 37);
+    }        
+    {
+        /* one content-length header, length 5 */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\r\n"
+            "Content-Length: 5\r\n"
+            "\r\n"
+            "ABCDE"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 42);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 43), 42);
+    }        
+    {
+        /* LF only in GET, one content-length header, length 5 */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\n"
+            "Content-Length: 5\r\n"
+            "\r\n"
+            "ABCDE"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 41);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 41);
+    }        
+    {
+        /* LF only in all places, one content-length header, length 5 */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "GET / HTTP/1.1\n"
+            "Content-Length: 5\n"
+            "\n"
+            "ABCDE"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 39);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 39);
+    }        
+
+    {
+        /* one header, unknown transfer-encoding (no content) */
+        const char *http_buf = 
+            /*12345678901234567890123456789 */
+            "GET / HTTP/1.1\r\n"
+            "Transfer-Encoding: chunke_\r\n"
+            "\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 45), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 46), 46);
+    }        
+
+    {
+        /* one header, one chunk */
+        const char *http_buf = 
+            /*12345678901234567890123456789 */
+            "GET / HTTP/1.1\r\n"
+            "Transfer-Encoding: chunked\r\n"
+            "\r\n"
+            "3\r\n"
+            "123\r\n"
+            "0\r\n\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 58), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 59), 59);
+    }        
+
+    {
+        /* one header, two chunks */
+        const char *http_buf = 
+            /*12345678901234567890123456789 */
+            "GET / HTTP/1.1\r\n"
+            "Transfer-Encoding: chunked\r\n"
+            "\r\n"
+            "3\r\n"
+            "123\r\n"
+            "2\r\n"
+            "12\n"
+            "0\r\n\r\n"
+            "GET / HTTP/1.0\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 64), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 65), 65);
+    }        
+}
+
+static void tst_http_response(void)
+{
+    {
+        /* unlimited content, no headers */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "HTTP/1.1 200 OK\r\n"
+            "\r\n"
+            "HTTP/1.1 200 OK\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 24), 0);
+    }
+    {
+        /* response, content  */
+        const char *http_buf = 
+            /*123456789012345678 */
+            "HTTP/1.1 200 OK\r\n"
+            "Content-Length: 2\r\n"
+            "\r\n"
+            "12"
+            "HTTP/1.1 200 OK\r\n";
+        
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 0);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 40);
+        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 40);
+    }
+}
+
+/** \brief COMSTACK synopsis from manual, doc/comstack.xml */
+static int comstack_example(const char *server_address_str)
+{    
+    COMSTACK stack;
+    char *buf = 0;
+    int size = 0, length_incoming;
+    void *server_address_ip;
+    int status;
+
+    char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
+    int protocol_package_length = strlen(protocol_package);
+
+    stack = cs_create(tcpip_type, 1, PROTO_HTTP);
+    if (!stack) {
+        perror("cs_create");  /* use perror() here since we have no stack yet */
+        return -1;
+    }
+    
+    server_address_ip = cs_straddr(stack, server_address_str);
+    if (!server_address_ip)
+    {
+        fprintf(stderr, "cs_straddr: address could not be resolved\n");
+        return -1;
+    }
+    
+    status = cs_connect(stack, server_address_ip);
+    if (status != 0) {
+        fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
+        return -1;
+    }
+    
+    status = cs_put(stack, protocol_package, protocol_package_length);
+    if (status) {
+        fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
+        return -1;
+    }
+    
+    /* Now get a response */
+    
+    length_incoming = cs_get(stack, &buf, &size);
+    if (!length_incoming) {
+        fprintf(stderr, "Connection closed\n");
+        return -1;
+    } else if (length_incoming < 0) {
+        fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
+        return -1;
+    }
+    
+    /* Print result */
+    fwrite(buf, length_incoming, 1, stdout);
+    
+    /* clean up */
+    cs_close(stack);
+    if (buf)
+        free(buf);
+    return 0;
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    if (argc == 2)
+       comstack_example(argv[1]);
+    tst_http_request();
+    tst_http_response();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_file_glob.c b/test/test_file_glob.c
new file mode 100644 (file)
index 0000000..8cfc3c3
--- /dev/null
@@ -0,0 +1,84 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <yaz/file_glob.h>
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/wrbuf.h>
+
+void tst_with_path(const char *tpath)
+{
+    yaz_glob_res_t glob_res;
+    int ret = yaz_file_glob(tpath, &glob_res);
+    if (ret == 0)
+    {
+        size_t n = yaz_file_glob_get_num(glob_res);
+        size_t i;
+        for (i = 0; i < n; i++)
+        {
+            yaz_log(YLOG_LOG, "match %s", yaz_file_glob_get_file(glob_res, i));
+        }
+    }
+    yaz_file_globfree(&glob_res);
+}
+
+void tst(void)
+{
+    yaz_glob_res_t glob_res;
+    int ret;
+    WRBUF tpath = wrbuf_alloc();
+    const char *srcdir = getenv("srcdir");
+    
+    if (srcdir)
+    {
+        wrbuf_puts(tpath, srcdir);
+        wrbuf_puts(tpath, "/");
+    }
+    wrbuf_puts(tpath, "Make*.am");
+    ret = yaz_file_glob(wrbuf_cstr(tpath), &glob_res);
+    YAZ_CHECK_EQ(ret, 0);
+
+    YAZ_CHECK_EQ(1, yaz_file_glob_get_num(glob_res));
+    if (yaz_file_glob_get_num(glob_res) == 1)
+    {
+        const char *f = yaz_file_glob_get_file(glob_res, 0);
+        size_t l_match = strlen("Makefile.am");
+        YAZ_CHECK(f && strlen(f) >= l_match);
+        if (f && strlen(f) >= l_match)
+        {
+            YAZ_CHECK(!strcmp(f + strlen(f) - l_match, "Makefile.am"));
+        }
+    }
+    wrbuf_destroy(tpath);
+    yaz_file_globfree(&glob_res);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    if (argc >= 2)
+        tst_with_path(argv[1]);
+    else
+        tst();
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_filepath.c b/test/test_filepath.c
new file mode 100644 (file)
index 0000000..b06bb3d
--- /dev/null
@@ -0,0 +1,42 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <yaz/tpath.h>
+#include <yaz/test.h>
+
+void tst(void)
+{
+    char fullpath[1024];
+    YAZ_CHECK(yaz_filepath_resolve("test_filepath", ".", 0, fullpath));
+    YAZ_CHECK(strcmp(fullpath, "./test_filepath") == 0);
+    YAZ_CHECK(!yaz_filepath_resolve("test_filepath1", ".", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("test_filepath", "bogus", 0, fullpath));
+    YAZ_CHECK(yaz_filepath_resolve("test_filepath", "bogus:.", 0, fullpath));
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_iconv.c b/test/test_iconv.c
new file mode 100644 (file)
index 0000000..352033a
--- /dev/null
@@ -0,0 +1,747 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <yaz/yaz-util.h>
+#include <yaz/test.h>
+
+#define ESC "\x1b"
+
+static int compare_buffers(char *msg, int no,
+                           int expect_len, const char *expect_buf,
+                           int got_len, const char *got_buf)
+{
+    if (expect_len == got_len
+        && !memcmp(expect_buf, got_buf, expect_len))
+        return 1;
+    
+    if (0) /* use 1 see how the buffers differ (for debug purposes) */
+    {
+        int i;
+        printf("tsticonv test=%s i=%d failed\n", msg, no);
+        printf("off got exp\n");
+        for (i = 0; i<got_len || i<expect_len; i++)
+        {
+            char got_char[10];
+            char expect_char[10];
+            
+            if (i < got_len)
+                sprintf(got_char, "%02X", got_buf[i]);
+            else
+                sprintf(got_char, "?  ");
+            
+            if (i < expect_len)
+                sprintf(expect_char, "%02X", expect_buf[i]);
+            else
+                sprintf(expect_char, "?  ");
+            
+            printf("%02d  %s  %s %c\n",
+                   i, got_char, expect_char, got_buf[i] == expect_buf[i] ?
+                   ' ' : '*');
+            
+        }
+    }
+    return 0;
+}
+
+static int tst_convert_l(yaz_iconv_t cd, size_t in_len, const char *in_buf,
+                         size_t expect_len, const char *expect_buf)
+{
+    size_t r;
+    char *inbuf= (char*) in_buf;
+    size_t inbytesleft = in_len > 0 ? in_len : strlen(in_buf);
+    char outbuf0[64];
+    char *outbuf = outbuf0;
+
+    while (inbytesleft)
+    {
+        size_t outbytesleft = outbuf0 + sizeof(outbuf0) - outbuf;
+        if (outbytesleft > 12)
+            outbytesleft = 12;
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        if (r == (size_t) (-1))
+        {
+            int e = yaz_iconv_error(cd);
+            if (e != YAZ_ICONV_E2BIG)
+                return 0;
+        }
+        else
+        {
+            yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
+            break;
+        }
+    }
+
+    return compare_buffers("tsticonv 22", 0,
+                           expect_len, expect_buf,
+                           outbuf - outbuf0, outbuf0);
+}
+
+static int tst_convert_x(yaz_iconv_t cd, const char *buf, const char *cmpbuf,
+                         int expect_error)
+{
+    int ret = 1;
+    WRBUF b = wrbuf_alloc();
+    char outbuf[16];
+    size_t inbytesleft = strlen(buf);
+    const char *inp = buf;
+    int rounds = 0;
+    for (rounds = 0; inbytesleft && rounds < (int) sizeof(outbuf); rounds++)
+    {
+        size_t outbytesleft = sizeof(outbuf);
+        char *outp = outbuf;
+        size_t r = yaz_iconv(cd, (char**) &inp,  &inbytesleft,
+                             &outp, &outbytesleft);
+        wrbuf_write(b, outbuf, outp - outbuf);
+        if (r == (size_t) (-1))
+        {
+            int e = yaz_iconv_error(cd);
+            if (e != YAZ_ICONV_E2BIG)
+            {
+                if (expect_error != -1)
+                    if (e != expect_error)
+                        ret = 0;
+                break;
+            }
+        }
+        else
+        {
+            size_t outbytesleft = sizeof(outbuf);
+            char *outp = outbuf;
+            r = yaz_iconv(cd, 0, 0, &outp, &outbytesleft);
+            wrbuf_write(b, outbuf, outp - outbuf);
+            if (expect_error != -1)
+                if (expect_error)
+                    ret = 0;
+            break;
+        }
+    }
+    if (wrbuf_len(b) == strlen(cmpbuf) 
+        && !memcmp(cmpbuf, wrbuf_buf(b), wrbuf_len(b)))
+        ;
+    else
+    {
+        WRBUF w = wrbuf_alloc();
+
+        ret = 0;
+        wrbuf_rewind(w);
+        wrbuf_puts_escaped(w, buf);
+        yaz_log(YLOG_LOG, "input %s", wrbuf_cstr(w));
+
+        wrbuf_rewind(w);
+        wrbuf_write_escaped(w, wrbuf_buf(b), wrbuf_len(b));
+        yaz_log(YLOG_LOG, "got %s", wrbuf_cstr(w));
+        
+        wrbuf_rewind(w);
+        wrbuf_puts_escaped(w, cmpbuf);
+        yaz_log(YLOG_LOG, "exp %s", wrbuf_cstr(w));
+
+        wrbuf_destroy(w);
+    }
+
+    wrbuf_destroy(b);
+    return ret;
+}
+
+static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf)
+{
+    return tst_convert_x(cd, buf, cmpbuf, 0);
+}
+
+/* some test strings in ISO-8859-1 format */
+static const char *iso_8859_1_a[] = {
+    "ax" ,
+    "\xd8",
+    "eneb\346r",
+    "\xe5" "\xd8",
+    "\xe5" "\xd8" "b",
+    "\xe5" "\xe5",
+    0 };
+
+static void tst_marc8_to_ucs4b(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("UCS4", "MARC8");
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+    
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\033$1" "\x21\x2B\x3B" /* FF1F */ "\033(B" "o",
+                  8, 
+                  "\x00\x00\xFF\x1F" "\x00\x00\x00o"));
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\033$1" "\x6F\x77\x29" /* AE0E */
+                  "\x6F\x52\x7C" /* c0F4 */ "\033(B",
+                  8,
+                  "\x00\x00\xAE\x0E" "\x00\x00\xC0\xF4"));
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\033$1"
+                  "\x21\x50\x6E"  /* UCS 7CFB */
+                  "\x21\x51\x31"  /* UCS 7D71 */
+                  "\x21\x3A\x67"  /* UCS 5B89 */
+                  "\x21\x33\x22"  /* UCS 5168 */
+                  "\x21\x33\x53"  /* UCS 5206 */
+                  "\x21\x44\x2B"  /* UCS 6790 */
+                  "\033(B",
+                  24, 
+                  "\x00\x00\x7C\xFB"
+                  "\x00\x00\x7D\x71"
+                  "\x00\x00\x5B\x89"
+                  "\x00\x00\x51\x68"
+                  "\x00\x00\x52\x06"
+                  "\x00\x00\x67\x90"));
+
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\xB0\xB2",     /* AYN and oSLASH */
+                  8, 
+                  "\x00\x00\x02\xBB"  "\x00\x00\x00\xF8"));
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\xF6\x61",     /* a underscore */
+                  8, 
+                  "\x00\x00\x00\x61"  "\x00\x00\x03\x32"));
+
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\x61\xC2",     /* a, phonorecord mark */
+                  8,
+                  "\x00\x00\x00\x61"  "\x00\x00\x21\x17"));
+
+    /* bug #258 */
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "el" "\xe8" "am\xe8" "an", /* elaman where a is a" */
+                  32,
+                  "\x00\x00\x00" "e"
+                  "\x00\x00\x00" "l"
+                  "\x00\x00\x00" "a"
+                  "\x00\x00\x03\x08"
+                  "\x00\x00\x00" "m"
+                  "\x00\x00\x00" "a"
+                  "\x00\x00\x03\x08"
+                  "\x00\x00\x00" "n"));
+    /* bug #260 */
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\xe5\xe8\x41",
+                  12, 
+                  "\x00\x00\x00\x41" "\x00\x00\x03\x04" "\x00\x00\x03\x08"));
+    /* bug #416 */
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\xEB\x74\xEC\x73",
+                  12,
+                  "\x00\x00\x00\x74" "\x00\x00\x03\x61" "\x00\x00\x00\x73"));
+    /* bug #416 */
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  0,
+                  "\xFA\x74\xFB\x73",
+                  12, 
+                  "\x00\x00\x00\x74" "\x00\x00\x03\x60" "\x00\x00\x00\x73"));
+
+    yaz_iconv_close(cd);
+}
+
+static void tst_ucs4b_to_utf8(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("UTF8", "UCS4");
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  8,
+                  "\x00\x00\xFF\x1F\x00\x00\x00o",
+                  4,
+                  "\xEF\xBC\x9F\x6F"));
+
+    YAZ_CHECK(tst_convert_l(
+                  cd,
+                  8, 
+                  "\x00\x00\xAE\x0E\x00\x00\xC0\xF4",
+                  6,
+                  "\xEA\xB8\x8E\xEC\x83\xB4"));
+    yaz_iconv_close(cd);
+}
+
+static void dconvert(int mandatory, const char *tmpcode)
+{
+    int i;
+    int ret;
+    yaz_iconv_t cd;
+    for (i = 0; iso_8859_1_a[i]; i++)
+    {
+        size_t r;
+        char *inbuf = (char*) iso_8859_1_a[i];
+        size_t inbytesleft = strlen(inbuf);
+        char outbuf0[24];
+        char outbuf1[10];
+        char *outbuf = outbuf0;
+        size_t outbytesleft = sizeof(outbuf0);
+
+        cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
+        YAZ_CHECK(cd || !mandatory);
+        if (!cd)
+            return;
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        YAZ_CHECK(r != (size_t) (-1));
+
+        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
+        YAZ_CHECK(r != (size_t) (-1));
+        yaz_iconv_close(cd);
+        if (r == (size_t) (-1))
+            return;
+        
+        cd = yaz_iconv_open("ISO-8859-1", tmpcode);
+        YAZ_CHECK(cd || !mandatory);
+        if (!cd)
+            return;
+        inbuf = outbuf0;
+        inbytesleft = sizeof(outbuf0) - outbytesleft;
+
+        outbuf = outbuf1;
+        outbytesleft = sizeof(outbuf1);
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        YAZ_CHECK(r != (size_t) (-1));
+
+        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
+        if (r == (size_t)(-1))
+        {
+            fprintf(stderr, "failed\n");
+        }
+        YAZ_CHECK(r != (size_t) (-1));
+
+        if (r != (size_t)(-1)) 
+        {
+            ret = compare_buffers("dconvert", i,
+                                  strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
+                                  sizeof(outbuf1) - outbytesleft, outbuf1);
+            YAZ_CHECK(ret);
+        }
+        yaz_iconv_close(cd);
+    }
+}
+
+int utf8_check(unsigned c)
+{
+    if (sizeof(c) >= 4)
+    {
+        size_t r;
+        char src[4];
+        char dst[4];
+        char utf8buf[6];
+        char *inbuf = src;
+        size_t inbytesleft = 4;
+        char *outbuf = utf8buf;
+        size_t outbytesleft = sizeof(utf8buf);
+        int i;
+        yaz_iconv_t cd = yaz_iconv_open("UTF-8", "UCS4LE");
+        if (!cd)
+            return 0;
+        for (i = 0; i<4; i++)
+            src[i] = c >> (i*8);
+        
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        yaz_iconv_close(cd);
+
+        if (r == (size_t)(-1))
+            return 0;
+
+        cd = yaz_iconv_open("UCS4LE", "UTF-8");
+        if (!cd)
+            return 0;
+        inbytesleft = sizeof(utf8buf) - outbytesleft;
+        inbuf = utf8buf;
+
+        outbuf = dst;
+        outbytesleft = 4;
+
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        if (r == (size_t)(-1))
+            return 0;
+
+        yaz_iconv_close(cd);
+
+        if (memcmp(src, dst, 4))
+            return 0;
+    }
+    return 1;
+}
+        
+static void tst_marc8_to_utf8(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours de math", 
+                          "Cours de math"));
+    /* COMBINING ACUTE ACCENT */
+    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
+                          "Cours de mathe\xcc\x81"));
+
+    YAZ_CHECK(tst_convert(cd, "\xea" "a", "a\xcc\x8a"));
+    YAZ_CHECK(tst_convert(cd, "a" "\xea" "\x1e", "a" "\x1e\xcc\x8a"));
+    YAZ_CHECK(tst_convert(cd, "a" "\xea" "p", "a" "p\xcc\x8a"));
+
+    YAZ_CHECK(tst_convert_x(cd, "a\xea", "a", YAZ_ICONV_EINVAL));
+    YAZ_CHECK(tst_convert(cd, "p", "\xcc\x8a")); /* note: missing p */
+    yaz_iconv(cd, 0, 0, 0, 0);     /* incomplete. so we have to reset */
+
+    /* bug #2115 */
+    YAZ_CHECK(tst_convert(cd, ESC "(N" ESC ")Qp" ESC "(B", "\xd0\x9f"));
+
+    YAZ_CHECK(tst_convert_x(cd, ESC , "", YAZ_ICONV_EINVAL));
+    YAZ_CHECK(tst_convert_x(cd, ESC "(", "", YAZ_ICONV_EINVAL));
+    YAZ_CHECK(tst_convert_x(cd, ESC "(B", "", 0));
+
+    YAZ_CHECK(tst_convert(cd, ESC "(B" "\x31", "1"));  /* ASCII in G0 */
+    YAZ_CHECK(tst_convert(cd, ESC ")B" "\xB1", "1"));  /* ASCII in G1 */
+
+    yaz_iconv_close(cd);
+}
+
+static void tst_marc8s_to_utf8(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8s");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours de math", 
+                          "Cours de math"));
+    /* E9: LATIN SMALL LETTER E WITH ACUTE */
+    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
+                          "Cours de math\xc3\xa9"));
+
+    yaz_iconv_close(cd);
+}
+
+
+static void tst_marc8_to_latin1(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("ISO-8859-1", "MARC8");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "ax", "ax"));
+
+    /* latin capital letter o with stroke */
+    YAZ_CHECK(tst_convert(cd, "\xa2", "\xd8"));
+
+    /* with latin small letter ae */
+    YAZ_CHECK(tst_convert(cd, "eneb\xb5r", "eneb\346r"));
+
+    YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2", "\xe5" "\xd8"));
+
+    YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2" "b", "\xe5" "\xd8" "b"));
+
+    YAZ_CHECK(tst_convert(cd, "\xea" "a"  "\xea" "a", "\xe5" "\xe5"));
+
+    YAZ_CHECK(tst_convert(cd, "Cours de math", 
+                          "Cours de math"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
+                          "Cours de mathé"));
+    YAZ_CHECK(tst_convert(cd, "12345678âe", 
+                          "12345678é"));
+    YAZ_CHECK(tst_convert(cd, "123456789âe", 
+                          "123456789é"));
+    YAZ_CHECK(tst_convert(cd, "1234567890âe", 
+                          "1234567890é"));
+    YAZ_CHECK(tst_convert(cd, "12345678901âe", 
+                          "12345678901é"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathâem", 
+                          "Cours de mathém"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathâematiques", 
+                          "Cours de mathématiques"));
+
+    yaz_iconv_close(cd);
+}
+
+static void tst_utf8_to_marc8(const char *marc8_type)
+{
+    yaz_iconv_t cd = yaz_iconv_open(marc8_type, "UTF-8");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
+
+    /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
+    YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
+
+    /** Pure ASCII. 12 characters (sizeof(outbuf)) */
+    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
+
+    /** Pure ASCII. 13 characters (sizeof(outbuf)+1) */
+    YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
+
+    /** UPPERCASE SCANDINAVIAN O */
+    YAZ_CHECK(tst_convert(cd, "S\xc3\x98", "S\xa2"));
+
+    /** ARING */
+    YAZ_CHECK(tst_convert(cd, "A" "\xCC\x8A", "\xEA" "A"));
+
+    /** A MACRON + UMLAUT, DIAERESIS */
+    YAZ_CHECK(tst_convert(cd, "A" "\xCC\x84" "\xCC\x88",
+                          "\xE5\xE8\x41"));
+    
+    /* Ligature spanning two characters */
+    YAZ_CHECK(tst_convert(cd,
+                          "\x74" "\xCD\xA1" "\x73",  /* UTF-8 */
+                          "\xEB\x74\xEC\x73"));      /* MARC-8 */
+
+    /* Double title spanning two characters */
+    YAZ_CHECK(tst_convert(cd,
+                          "\x74" "\xCD\xA0" "\x73",  /* UTF-8 */
+                          "\xFA\x74\xFB\x73"));      /* MARC-8 */
+
+    /** Ideographic question mark (Unicode FF1F) */
+    YAZ_CHECK(tst_convert(cd,
+                          "\xEF\xBC\x9F" "o",        /* UTF-8 */
+                          "\033$1" "\x21\x2B\x3B" "\033(B" "o" ));
+
+
+    /** Ideographic space per ANSI Z39.64 */
+    YAZ_CHECK(tst_convert(cd,
+                          "\xe3\x80\x80" "o",        /* UTF-8 */
+                          "\033$1" "\x21\x23\x21" "\033(B" "o" ));
+
+    /** Superscript 0 . bug #642 */
+    YAZ_CHECK(tst_convert(cd,
+                          "(\xe2\x81\xb0)",        /* UTF-8 */
+                          "(\033p0\x1bs)"));
+    
+    
+    /** bug #1778 */
+    YAZ_CHECK(tst_convert(cd,
+                          /* offset 0x530 in UTF-8 rec marccol4.u8.marc */
+                          "\xE3\x83\xB3" "\xE3\x82\xBF" 
+                          "\xCC\x84" "\xCC\x84" "\xE3\x83\xBC" /* UTF-8 */,
+                          "\x1B\x24\x31" "\x69\x25\x73"
+                          "\x1B\x28\x42" "\xE5\xE5" "\x1B\x24\x31" 
+                          "\x69\x25\x3F"
+                          "\x69\x21\x3C" "\x1B\x28\x42"));
+
+    
+    /** bug #2120 */
+    YAZ_CHECK(tst_convert(cd, 
+                          "\xCE\x94\xCE\xB5\xCF\x84"
+                          "\xCE\xBF\xCF\x81\xCE\xB1"
+                          "\xCE\xBA\xCE\xB7\xCF\x82\x2C",
+
+                          "\x1B\x28\x53\x45\x66\x78\x72\x75"
+                          "\x61\x6D\x6A\x77"
+                          "\x1B\x28\x42\x2C"
+                  ));
+    {
+        char *inbuf0 = "\xe2\x81\xb0";
+        char *inbuf = inbuf0;
+        size_t inbytesleft = strlen(inbuf);
+        char outbuf0[64];
+        char *outbuf = outbuf0;
+        size_t outbytesleft = sizeof(outbuf0)-1;
+        size_t r;
+#if 0
+        int i;
+#endif
+        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+        YAZ_CHECK(r != (size_t) (-1));
+
+#if 0
+        *outbuf = '\0';  /* so we know when to stop printing */
+        for (i = 0; outbuf0[i]; i++)
+        {
+            int ch = outbuf0[i] & 0xff;
+            yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
+        }
+#endif
+
+        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
+        YAZ_CHECK(r != (size_t) (-1));
+        *outbuf = '\0';  /* for strcmp test below and printing */
+#if 0
+        for (i = 0; outbuf0[i]; i++)
+        {
+            int ch = outbuf0[i] & 0xff;
+            yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
+        }
+#endif
+        YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0);
+    }
+    yaz_iconv(cd, 0, 0, 0, 0);
+    yaz_iconv_close(cd);
+}
+
+static void tst_advance_to_utf8(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("utf-8", "advancegreek");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
+    yaz_iconv_close(cd);
+}
+
+static void tst_utf8_to_advance(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("advancegreek", "utf-8");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
+    yaz_iconv_close(cd);
+}
+
+static void tst_latin1_to_marc8(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("MARC8", "ISO-8859-1");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
+
+    /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
+    YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
+
+    /** Pure ASCII. 12 characters (sizeof(outbuf)) */
+    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
+
+    /** Pure ASCII. 13 characters (sizeof(outbuf)) */
+    YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
+
+    /** D8: UPPERCASE SCANDINAVIAN O */
+    YAZ_CHECK(tst_convert(cd, "S\xd8", "S\xa2"));
+
+    /** E9: LATIN SMALL LETTER E WITH ACUTE */
+    YAZ_CHECK(tst_convert(cd, "Cours de math\xe9", "Cours de mathâe"));
+    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"
+                  ));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathé", "Cours de mathâe" ));
+    YAZ_CHECK(tst_convert(cd, "12345678é","12345678âe"));
+    YAZ_CHECK(tst_convert(cd, "123456789é", "123456789âe"));
+    YAZ_CHECK(tst_convert(cd, "1234567890é","1234567890âe"));
+    YAZ_CHECK(tst_convert(cd, "12345678901é", "12345678901âe"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathém", "Cours de mathâem"));
+    YAZ_CHECK(tst_convert(cd, "Cours de mathématiques",
+                          "Cours de mathâematiques"));
+    yaz_iconv_close(cd);
+}
+
+static void tst_utf8_codes(void)
+{
+    YAZ_CHECK(utf8_check(3));
+    YAZ_CHECK(utf8_check(127));
+    YAZ_CHECK(utf8_check(128));
+    YAZ_CHECK(utf8_check(255));
+    YAZ_CHECK(utf8_check(256));
+    YAZ_CHECK(utf8_check(900));
+    YAZ_CHECK(utf8_check(1000));
+    YAZ_CHECK(utf8_check(10000));
+    YAZ_CHECK(utf8_check(100000));
+    YAZ_CHECK(utf8_check(1000000));
+    YAZ_CHECK(utf8_check(10000000));
+    YAZ_CHECK(utf8_check(100000000));
+}
+
+static void tst_danmarc_to_latin1(void)
+{
+    yaz_iconv_t cd = yaz_iconv_open("iso-8859-1", "danmarc");
+
+    YAZ_CHECK(cd);
+    if (!cd)
+        return;
+
+    YAZ_CHECK(tst_convert(cd, "ax", "ax"));
+
+    YAZ_CHECK(tst_convert(cd, "a@@b", "a@b"));
+    YAZ_CHECK(tst_convert(cd, "a@@@@b", "a@@b"));
+    YAZ_CHECK(tst_convert(cd, "@000ab", "\nb"));
+
+    YAZ_CHECK(tst_convert(cd, "@\xe5", "aa"));
+    YAZ_CHECK(tst_convert(cd, "@\xc5.", "Aa."));
+    
+    yaz_iconv_close(cd);
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+
+    tst_utf8_codes();
+
+    tst_marc8_to_utf8();
+
+    tst_marc8s_to_utf8();
+
+    tst_marc8_to_latin1();
+
+    tst_advance_to_utf8();
+    tst_utf8_to_advance();
+
+    tst_utf8_to_marc8("marc8");
+    tst_utf8_to_marc8("marc8lossy");
+    tst_utf8_to_marc8("marc8lossless");
+
+    tst_danmarc_to_latin1();
+
+    tst_latin1_to_marc8();
+
+    tst_marc8_to_ucs4b();
+    tst_ucs4b_to_utf8();
+
+    dconvert(1, "UTF-8");
+    dconvert(1, "ISO-8859-1");
+    dconvert(1, "UCS4");
+    dconvert(1, "UCS4LE");
+    dconvert(0, "CP865");
+
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_icu.c b/test/test_icu.c
new file mode 100644 (file)
index 0000000..2ad005c
--- /dev/null
@@ -0,0 +1,824 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#define USE_TIMING 0
+#if USE_TIMING
+#include <yaz/timing.h>
+#endif
+
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/wrbuf.h>
+
+#if YAZ_HAVE_ICU
+#include <yaz/icu_I18N.h>
+
+#if YAZ_POSIX_THREADS
+#include <pthread.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#define MAX_KEY_SIZE 256
+struct icu_termmap
+{
+    uint8_t sort_key[MAX_KEY_SIZE]; /* standard C string '\0' terminated */
+    char disp_term[MAX_KEY_SIZE];  /* standard C utf-8 string */
+};
+
+
+static int icu_termmap_cmp(const void *vp1, const void *vp2)
+{
+    struct icu_termmap *itmp1 = *(struct icu_termmap **) vp1;
+    struct icu_termmap *itmp2 = *(struct icu_termmap **) vp2;
+
+    int cmp = 0;
+    
+    cmp = strcmp((const char *)itmp1->sort_key, 
+                 (const char *)itmp2->sort_key);
+    return cmp;
+}
+
+
+static int test_icu_casemap(const char * locale, char action,
+                            const char * src8cstr, const char * chk8cstr)
+{
+    int success = 0;
+    UErrorCode status = U_ZERO_ERROR;
+
+    struct icu_buf_utf8 * src8 = icu_buf_utf8_create(0);
+    struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
+    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
+
+
+    int src8cstr_len = strlen(src8cstr);
+    int chk8cstr_len = strlen(chk8cstr);
+
+    /* converting to UTF16 */
+    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+
+    /* perform case mapping */
+    icu_utf16_casemap(dest16, src16, locale, action, &status);
+  
+    /* converting to UTF8 */
+    icu_utf16_to_utf8(dest8, dest16, &status);
+
+    /* determine success */
+    if (dest8->utf8 
+        && (dest8->utf8_len == strlen(chk8cstr))
+        && !strcmp(chk8cstr, (const char *) dest8->utf8))
+        success = 1;
+    else
+        success = 0;
+
+    /* report failures */
+    if (!success)
+    {
+        yaz_log(YLOG_WARN, "test_icu_casemap failed");
+        yaz_log(YLOG_LOG, "Original string:   '%s' (%d)",
+                src8cstr, src8cstr_len);
+        yaz_log(YLOG_LOG, "icu_casemap '%s:%c' '%s' (%d)", 
+                locale, action, dest8->utf8, dest8->utf8_len);
+        yaz_log(YLOG_LOG, "expected string:   '%s' (%d)",
+                chk8cstr, chk8cstr_len);
+    }
+  
+    /* clean the buffers */
+    icu_buf_utf8_destroy(src8);
+    icu_buf_utf8_destroy(dest8);
+    icu_buf_utf16_destroy(src16);
+    icu_buf_utf16_destroy(dest16);
+    
+    return success;
+}
+
+static void check_icu_casemap(void)
+{
+    /* Locale 'en' */
+
+    /* successful tests */
+    YAZ_CHECK(test_icu_casemap("en", 'l',
+                               "A ReD fOx hunTS sQUirriLs", 
+                               "a red fox hunts squirrils"));
+    
+    YAZ_CHECK(test_icu_casemap("en", 'u',
+                               "A ReD fOx hunTS sQUirriLs", 
+                               "A RED FOX HUNTS SQUIRRILS"));
+    
+    YAZ_CHECK(test_icu_casemap("en", 'f',
+                               "A ReD fOx hunTS sQUirriLs", 
+                               "a red fox hunts squirrils"));
+    
+    YAZ_CHECK(test_icu_casemap("en", 't',
+                               "A ReD fOx hunTS sQUirriLs", 
+                               "A Red Fox Hunts Squirrils"));
+    
+    /* Locale 'da' */
+
+    /* success expected */
+    YAZ_CHECK(test_icu_casemap("da", 'l',
+                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
+                               "åh æble, øs fløde i åen efter blåbærgrøden"));
+
+    YAZ_CHECK(test_icu_casemap("da", 'u',
+                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
+                               "ÅH ÆBLE, ØS FLØDE I ÅEN EFTER BLÅBÆRGRØDEN"));
+
+    YAZ_CHECK(test_icu_casemap("da", 'f',
+                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
+                               "åh æble, øs fløde i åen efter blåbærgrøden"));
+
+    YAZ_CHECK(test_icu_casemap("da", 't',
+                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
+                               "Åh Æble, Øs Fløde I Åen Efter Blåbærgrøden"));
+
+    /* Locale 'de' */
+
+    /* success expected */
+    YAZ_CHECK(test_icu_casemap("de", 'l',
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "zwölf ärgerliche würste rollen über die straße"));
+
+    YAZ_CHECK(test_icu_casemap("de", 'u',
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "ZWÖLF ÄRGERLICHE WÜRSTE ROLLEN ÜBER DIE STRASSE"));
+
+    YAZ_CHECK(test_icu_casemap("de", 'f',
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "zwölf ärgerliche würste rollen über die strasse"));
+
+    YAZ_CHECK(test_icu_casemap("de", 't',
+                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
+                               "Zwölf Ärgerliche Würste Rollen Über Die Straße"));
+
+}
+
+static int test_icu_sortmap(const char * locale, int src_list_len,
+                            const char ** src_list, const char ** chk_list)
+{
+    int success = 1;
+
+    UErrorCode status = U_ZERO_ERROR;
+
+    struct icu_buf_utf8 * buf8 = icu_buf_utf8_create(0);
+    struct icu_buf_utf16 * buf16 = icu_buf_utf16_create(0);
+
+    int i;
+
+    struct icu_termmap * list[src_list_len];
+
+    UCollator *coll = ucol_open(locale, &status); 
+    icu_check_status(status);
+
+    if (U_FAILURE(status))
+        return 0;
+
+    /* assigning display terms and sort keys using buf 8 and buf16 */
+    for (i = 0; i < src_list_len; i++) 
+    {
+
+        list[i] = (struct icu_termmap *) malloc(sizeof(struct icu_termmap));
+
+        /* copy display term */
+        strcpy(list[i]->disp_term, src_list[i]);    
+
+        /* transforming to UTF16 */
+        icu_utf16_from_utf8_cstr(buf16, list[i]->disp_term, &status);
+        icu_check_status(status);
+
+        /* computing sortkeys */
+        icu_sortkey8_from_utf16(coll, buf8, buf16, &status);
+        icu_check_status(status);
+    
+        /* assigning sortkeys */
+        memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
+    } 
+
+    /* do the sorting */
+    qsort(list, src_list_len, sizeof(struct icu_termmap *), icu_termmap_cmp);
+
+    /* checking correct sorting */
+    for (i = 0; i < src_list_len; i++)
+    {
+        if (0 != strcmp(list[i]->disp_term, chk_list[i])){
+            success = 0;
+        }
+    }
+
+    if (!success)
+    {
+        yaz_log(YLOG_LOG, "ERROR"); 
+        yaz_log(YLOG_LOG, "Input str:'%s':", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            yaz_log(YLOG_LOG, "  '%s'", list[i]->disp_term); 
+        }
+        yaz_log(YLOG_LOG, "ICU sort: '%s':", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            yaz_log(YLOG_LOG, " '%s'", list[i]->disp_term); 
+        }
+        yaz_log(YLOG_LOG, "Expected: '%s':", locale); 
+        for (i = 0; i < src_list_len; i++) {
+            yaz_log(YLOG_LOG, " '%s'", chk_list[i]); 
+        }
+    }
+  
+    for (i = 0; i < src_list_len; i++)
+        free(list[i]);
+   
+    ucol_close(coll);
+
+    icu_buf_utf8_destroy(buf8);
+    icu_buf_utf16_destroy(buf16);
+
+    return success;  
+}
+
+static void check_icu_sortmap(void)
+{
+    /* successful tests */
+    size_t en_1_len = 6;
+    const char * en_1_src[6] = {"z", "K", "a", "A", "Z", "k"};
+    const char * en_1_cck[6] = {"a", "A", "k", "K", "z", "Z"};
+    YAZ_CHECK(test_icu_sortmap("en", en_1_len, en_1_src, en_1_cck));
+    YAZ_CHECK(test_icu_sortmap("en_AU", en_1_len, en_1_src, en_1_cck));
+    YAZ_CHECK(test_icu_sortmap("en_CA", en_1_len, en_1_src, en_1_cck));
+    YAZ_CHECK(test_icu_sortmap("en_GB", en_1_len, en_1_src, en_1_cck));
+    YAZ_CHECK(test_icu_sortmap("en_US", en_1_len, en_1_src, en_1_cck));
+    
+    /* successful tests */
+    {
+        size_t da_1_len = 6;
+        const char * da_1_src[6] = {"z", "å", "o", "æ", "a", "ø"};
+        const char * da_1_cck[6] = {"a", "o", "z", "æ", "ø", "å"};
+        YAZ_CHECK(test_icu_sortmap("da", da_1_len, da_1_src, da_1_cck));
+        YAZ_CHECK(test_icu_sortmap("da_DK", da_1_len, da_1_src, da_1_cck));
+    }
+    /* successful tests */
+    {
+        size_t de_1_len = 9;
+        const char * de_1_src[9] = {"u", "ä", "o", "t", "s", "ß", "ü", "ö", "a"};
+        const char * de_1_cck[9] = {"a","ä", "o", "ö", "s", "ß", "t", "u", "ü"};
+        YAZ_CHECK(test_icu_sortmap("de", de_1_len, de_1_src, de_1_cck));
+        YAZ_CHECK(test_icu_sortmap("de_AT", de_1_len, de_1_src, de_1_cck));
+        YAZ_CHECK(test_icu_sortmap("de_DE", de_1_len, de_1_src, de_1_cck));
+    }
+}
+
+static int test_icu_normalizer(const char * rules8cstr,
+                               const char * src8cstr,
+                               const char * chk8cstr)
+{
+    int success = 0;
+    
+    UErrorCode status = U_ZERO_ERROR;
+
+    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
+    struct icu_transform * transform
+        = icu_transform_create(rules8cstr, 'f', 0, &status);
+    icu_check_status(status);
+    
+    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+    icu_check_status(status);
+
+    icu_transform_trans(transform, dest16, src16, &status);
+    icu_check_status(status);
+
+    icu_utf16_to_utf8(dest8, dest16, &status);
+    icu_check_status(status);
+
+
+    if (!strcmp((const char *) dest8->utf8, 
+               (const char *) chk8cstr))
+        success = 1;
+    else
+    {
+        success = 0;
+        yaz_log(YLOG_LOG, "Normalization");
+        yaz_log(YLOG_LOG, " Rules:      '%s'", rules8cstr);
+        yaz_log(YLOG_LOG, " Input:      '%s'", src8cstr);
+        yaz_log(YLOG_LOG, " Normalized: '%s'", dest8->utf8);
+        yaz_log(YLOG_LOG, " Expected:   '%s'", chk8cstr);
+    }
+
+    icu_transform_destroy(transform);
+    icu_buf_utf16_destroy(src16);
+    icu_buf_utf16_destroy(dest16);
+    icu_buf_utf8_destroy(dest8);
+
+    return success;
+}
+
+static void check_icu_normalizer(void)
+{
+    YAZ_CHECK(test_icu_normalizer("[:Punctuation:] Any-Remove",
+                                  "Don't shoot!",
+                                  "Dont shoot"));
+    
+    YAZ_CHECK(test_icu_normalizer("[:Control:] Any-Remove",
+                                  "Don't\n shoot!",
+                                  "Don't shoot!"));
+
+    YAZ_CHECK(test_icu_normalizer("[:Decimal_Number:] Any-Remove",
+                                  "This is 4 you!",
+                                  "This is  you!"));
+
+    YAZ_CHECK(test_icu_normalizer("Lower; [:^Letter:] Remove",
+                                  "Don't shoot!",
+                                  "dontshoot"));
+    
+    YAZ_CHECK(test_icu_normalizer("[:^Number:] Remove",
+                                  "Monday 15th of April",
+                                  "15"));
+
+    YAZ_CHECK(test_icu_normalizer("Lower;"
+                                  "[[:WhiteSpace:][:Punctuation:]] Remove",
+                                  " word4you? ",
+                                  "word4you"));
+
+    YAZ_CHECK(test_icu_normalizer("NFD; [:Nonspacing Mark:] Remove; NFC",
+                                  "à côté de l'alcôve ovoïde",
+                                  "a cote de l'alcove ovoide"));
+}
+
+static int test_icu_tokenizer(const char * locale, char action,
+                              const char * src8cstr, int count)
+{
+    int success = 1;
+
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf16 * tkn16 = icu_buf_utf16_create(0);
+    struct icu_buf_utf8 * tkn8 = icu_buf_utf8_create(0);
+    struct icu_tokenizer * tokenizer = 0;
+
+    /* transforming to UTF16 */
+    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+    icu_check_status(status);
+
+    /* set up tokenizer */
+    tokenizer = icu_tokenizer_create(locale, action, &status);
+    icu_check_status(status);
+    YAZ_CHECK(tokenizer);
+
+    /* attach text buffer to tokenizer */
+    icu_tokenizer_attach(tokenizer, src16, &status);    
+    icu_check_status(status);
+
+    /* perform work on tokens */
+    while (icu_tokenizer_next_token(tokenizer, tkn16, &status))
+    {
+        icu_check_status(status);
+
+        /* converting to UTF8 */
+        icu_utf16_to_utf8(tkn8, tkn16, &status);
+    }
+
+    if (count != icu_tokenizer_token_count(tokenizer))
+    {
+        success = 0;
+        yaz_log(YLOG_LOG, "Tokenizer '%s:%c' Error:", locale, action);
+        yaz_log(YLOG_LOG, " Input:  '%s'", src8cstr);
+        yaz_log(YLOG_LOG, " Tokens: %d", icu_tokenizer_token_count(tokenizer));
+        yaz_log(YLOG_LOG, " Expected: %d", count);
+    }
+
+    icu_tokenizer_destroy(tokenizer);
+    icu_buf_utf16_destroy(src16);
+    icu_buf_utf16_destroy(tkn16);
+    icu_buf_utf8_destroy(tkn8);
+        
+    return success;
+}
+
+static void check_icu_tokenizer(void)
+{
+    const char * en_str 
+        = "O Romeo, Romeo! wherefore art thou Romeo?";
+    
+    YAZ_CHECK(test_icu_tokenizer("en", 's', en_str, 2));
+    YAZ_CHECK(test_icu_tokenizer("en", 'l', en_str, 7));
+    YAZ_CHECK(test_icu_tokenizer("en", 'w', en_str, 16));
+    YAZ_CHECK(test_icu_tokenizer("en", 'c', en_str, 41));
+
+    {
+        const char * da_str 
+            = "Blåbærtærte. Denne kage stammer fra Finland. "
+            "Den er med blåbær, men alle sommerens forskellige bær kan bruges.";
+        
+        YAZ_CHECK(test_icu_tokenizer("da", 's', da_str, 3));
+        YAZ_CHECK(test_icu_tokenizer("dar", 'l', da_str, 17));
+        YAZ_CHECK(test_icu_tokenizer("da", 'w', da_str, 37));
+        YAZ_CHECK(test_icu_tokenizer("da", 'c', da_str, 110));
+    }
+}
+
+static void check_icu_chain(void)
+{
+    const char * en_str 
+        = "O Romeo, Romeo! wherefore art thou\t Romeo?";
+
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+    
+    const char * xml_str = "<icu locale=\"en\">"
+        "<transform rule=\"[:Control:] Any-Remove\"/>"
+        "<tokenize rule=\"l\"/>"
+        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "<display/>"
+        "<casemap rule=\"l\"/>"
+        "</icu>";
+
+    
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+
+    YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        yaz_log(YLOG_LOG, "%d '%s' '%s'",
+                icu_chain_token_number(chain),
+                icu_chain_token_norm(chain),
+                icu_chain_token_display(chain));
+    }
+
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
+
+
+    YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        yaz_log(YLOG_LOG, "%d '%s' '%s'",
+                icu_chain_token_number(chain),
+                icu_chain_token_norm(chain),
+                icu_chain_token_display(chain));
+    }
+
+
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
+
+    icu_chain_destroy(chain);
+}
+
+
+static void check_bug_1140(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+    
+    const char * xml_str = "<icu locale=\"en\">"
+
+        /* if the first rule is normalize instead. Then it works */
+#if 0
+        "<transform rule=\"[:Control:] Any-Remove\"/>"
+#endif
+        "<tokenize rule=\"l\"/>"
+        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "<display/>"
+        "<casemap rule=\"l\"/>"
+        "</icu>";
+
+    
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    YAZ_CHECK(icu_chain_assign_cstr(
+                  chain,  "O Romeo, Romeo! wherefore art thou\t Romeo?",
+                  &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        ;
+        /* printf("%d '%s' '%s'\n",
+           icu_chain_token_number(chain),
+           icu_chain_token_norm(chain),
+           icu_chain_token_display(chain)); */
+    }
+    
+
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
+
+    YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        ;
+        /* printf("%d '%s' '%s'\n",
+           icu_chain_token_number(chain),
+           icu_chain_token_norm(chain),
+           icu_chain_token_display(chain)); */
+    }
+
+    /* we expect 'what' 'is' 'this', i.e. 3 tokens */
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
+
+    icu_chain_destroy(chain);
+}
+
+
+static void check_chain_empty_token(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+
+    const char * xml_str = "<icu locale=\"en\">"
+        "<tokenize rule=\"w\"/>"
+        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "</icu>";
+    
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    YAZ_CHECK(icu_chain_assign_cstr(
+                  chain,  "a string with 15 tokenss and 8 displays",
+                  &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        ;
+        /* printf("%d '%s' '%s'\n",
+           icu_chain_token_number(chain),
+           icu_chain_token_norm(chain),
+           icu_chain_token_display(chain)); */
+    }
+
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 15);
+
+    icu_chain_destroy(chain);
+}
+
+static void check_chain_empty_chain(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+
+    const char * xml_str = "<icu locale=\"en\">"
+        "</icu>";
+    
+    const char * src8 = "some 5487 weired !¤%&(/& sTuFf";
+    char * dest8 = 0;
+
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    xmlNode *xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    YAZ_CHECK(icu_chain_assign_cstr(
+                  chain,  src8,
+                  &status));
+
+    while (icu_chain_next_token(chain, &status))
+    {
+        ;
+        /* printf("%d '%s' '%s'\n",
+           icu_chain_token_number(chain),
+           icu_chain_token_norm(chain),
+           icu_chain_token_display(chain)); */
+    }
+
+    YAZ_CHECK_EQ(icu_chain_token_number(chain), 1);
+
+    dest8 = (char *) icu_chain_token_norm(chain);
+    YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
+    
+    icu_chain_destroy(chain);
+}
+
+static void check_icu_iter1(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+    xmlNode *xml_node;
+    yaz_icu_iter_t iter;
+
+    const char * xml_str = "<icu locale=\"en\">"
+        "<tokenize rule=\"w\"/>"
+        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "</icu>";
+    
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    YAZ_CHECK(doc);
+    if (!doc)
+        return;
+    xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+    if (!xml_node)
+        return ;
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    iter = icu_iter_create(chain);
+    icu_iter_first(iter, "a string with 15 tokens and 8 displays");
+    YAZ_CHECK(iter);
+    if (!iter)
+        return;
+    while (icu_iter_next(iter))
+    {
+        yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
+    }
+    icu_iter_destroy(iter);
+    icu_chain_destroy(chain);
+}
+
+static int test_iter(struct icu_chain *chain, const char *input,
+                     const char *expected)
+{
+    yaz_icu_iter_t iter = icu_iter_create(chain);
+    WRBUF result, second;
+    int success = 1;
+
+    if (!iter)
+    {
+        yaz_log(YLOG_WARN, "test_iter: input=%s !iter", input);
+        return 0;
+    }
+
+    if (icu_iter_next(iter))
+    {
+        yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
+        return 0;
+    }
+
+    result = wrbuf_alloc();
+    icu_iter_first(iter, input);
+    while (icu_iter_next(iter))
+    {
+        wrbuf_puts(result, "[");
+        wrbuf_puts(result, icu_iter_get_norm(iter));
+        wrbuf_puts(result, "]");
+    }
+
+    second = wrbuf_alloc();
+    icu_iter_first(iter, input);
+    while (icu_iter_next(iter))
+    {
+        wrbuf_puts(second, "[");
+        wrbuf_puts(second, icu_iter_get_norm(iter));
+        wrbuf_puts(second, "]");
+    }
+
+    icu_iter_destroy(iter);
+
+    if (strcmp(expected, wrbuf_cstr(result)))
+    {
+        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
+                input, expected, wrbuf_cstr(result));
+        success = 0;
+    }
+
+    if (strcmp(expected, wrbuf_cstr(second)))
+    {
+        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s (2nd)",
+                input, expected, wrbuf_cstr(second));
+        success = 0;
+    }
+
+    wrbuf_destroy(result);
+    wrbuf_destroy(second);
+    return success;
+}
+
+static void *iter_thread(void *p)
+{
+    struct icu_chain *chain = (struct icu_chain *) p;
+    int i;
+    
+    for (i = 0; i < 10000; i++)
+    {
+        YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
+                            "[adobe][acrobat][reader][1991][][1999][]"));
+    }
+    return 0;
+}
+
+static void check_iter_threads(struct icu_chain *chain)
+{
+#if YAZ_POSIX_THREADS
+#define NO_THREADS 1
+
+    pthread_t t[NO_THREADS];
+    int i;
+
+    for (i = 0; i < NO_THREADS; i++)
+        pthread_create(t + i, 0, iter_thread, chain);
+
+    for (i = 0; i < NO_THREADS; i++)
+        pthread_join(t[i], 0);
+#endif
+}
+static void check_icu_iter2(void)
+{
+    UErrorCode status = U_ZERO_ERROR;
+    struct icu_chain * chain = 0;
+    xmlNode *xml_node;
+
+    const char * xml_str = "<icu locale=\"en\">"
+        "<transform rule=\"[:Control:] Any-Remove\"/>"
+        "<tokenize rule=\"l\"/>"
+        "<tokenize rule=\"w\"/>"
+        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+        "<display/>"
+        "<casemap rule=\"l\"/>"
+        "</icu>";
+
+    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
+    YAZ_CHECK(doc);
+    if (!doc)
+        return;
+    xml_node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(xml_node);
+    if (!xml_node)
+        return ;
+
+    chain = icu_chain_xml_config(xml_node, 0, &status);
+
+    xmlFreeDoc(doc);
+    YAZ_CHECK(chain);
+    
+    YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
+                        "[adobe][acrobat][reader][1991][][1999][]"));
+
+    check_iter_threads(chain);
+
+    icu_chain_destroy(chain);
+}
+
+#endif /* YAZ_HAVE_ICU */
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv); 
+    YAZ_CHECK_LOG();
+
+#if YAZ_HAVE_ICU
+
+    check_icu_casemap();
+    check_icu_sortmap();
+    check_icu_normalizer();
+    check_icu_tokenizer();
+    check_icu_chain();
+    check_chain_empty_token();
+    check_chain_empty_chain();
+    check_icu_iter1();
+    check_icu_iter2();
+    
+    check_bug_1140();
+
+#else /* YAZ_HAVE_ICU */
+
+    yaz_log(YLOG_LOG, "ICU unit tests omitted");
+    YAZ_CHECK(0 == 0);
+
+#endif /* YAZ_HAVE_ICU */
+   
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_json.c b/test/test_json.c
new file mode 100644 (file)
index 0000000..eace27e
--- /dev/null
@@ -0,0 +1,213 @@
+/**
+ * \file 
+ * \brief JSON test
+ */
+#include <yaz/test.h>
+#include <yaz/json.h>
+#include <string.h>
+#include <yaz/log.h>
+
+static int expect(json_parser_t p, const char *input, 
+                  const char *output)
+{
+    int ret = 0;
+    struct json_node *n;
+
+    n = json_parser_parse(p, input);
+    if (n == 0 && output == 0)
+        ret = 1;
+    else if (n && output)
+    {
+        WRBUF result = wrbuf_alloc();
+
+        json_write_wrbuf(n, result);
+        if (strcmp(wrbuf_cstr(result), output) == 0)
+            ret = 1;
+        else
+        {
+            yaz_log(YLOG_WARN, "expected '%s' but got '%s'",
+                    output, wrbuf_cstr(result));
+        }
+        wrbuf_destroy(result);
+    }
+    else if (!n)
+    {
+        yaz_log(YLOG_WARN, "expected '%s' but got error '%s'",
+                output, json_parser_get_errmsg(p));
+    }
+    json_remove_node(n);
+    return ret;
+}
+
+static void tst1(void)
+{
+    json_parser_t p = json_parser_create();
+
+    YAZ_CHECK(p);
+    if (!p)
+        return;
+
+    YAZ_CHECK(expect(p, "", 0));
+
+    YAZ_CHECK(expect(p, "1234", "1234"));
+
+    YAZ_CHECK(expect(p, "[ 1234 ]", "[1234]"));
+
+    YAZ_CHECK(expect(p, "{\"k\":tru}", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":null", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":nullx}", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":-", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":+", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"a}", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"a", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"", 0));
+
+    YAZ_CHECK(expect(p, "{", 0));
+
+    YAZ_CHECK(expect(p, "{}", "{}"));
+
+    YAZ_CHECK(expect(p, "{}  extra", 0));
+
+    YAZ_CHECK(expect(p, "{\"a\":[1,2,3}", 0));
+    
+    YAZ_CHECK(expect(p, "{\"a\":[1,2,", 0));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"wa\"}", "{\"k\":\"wa\"}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":null}", "{\"k\":null}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":false}", "{\"k\":false}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":true}", "{\"k\":true}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":12}", "{\"k\":12}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":-12}", "{\"k\":-12}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":1.2e6}", "{\"k\":1.2e+06}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":1e3}", "{\"k\":1000}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"\"}", "{\"k\":\"\"}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":1,\"b\":2}", "{\"a\":1,\"b\":2}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":1,\"b\":2,\"c\":3}",
+                     "{\"a\":1,\"b\":2,\"c\":3}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":[]}", "{\"a\":[]}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":[1]}", "{\"a\":[1]}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":[1,2]}", "{\"a\":[1,2]}"));
+
+    YAZ_CHECK(expect(p, "{\"a\":[1,2,3]}", "{\"a\":[1,2,3]}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"\\t\"}", "{\"k\":\"\x09\"}"));
+
+    YAZ_CHECK(expect(p, "{\"k\":\"\\u0009\"}", "{\"k\":\"\x09\"}"));
+
+    json_parser_destroy(p);
+}
+
+static void tst2(void)
+{
+    struct json_node *n, *n1;
+
+    n = json_parse("{\"a\":1,\"b\":2,\"c\":[true,false,null]}", 0);
+    YAZ_CHECK(n);
+    if (!n)
+        return;
+
+    YAZ_CHECK_EQ(json_count_children(n), 3);
+    
+    n1 = json_get_object(n, "a");
+    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 1.0);
+    YAZ_CHECK_EQ(json_count_children(n1), 0);
+
+    n1 = json_get_object(n, "b");
+    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 2.0);
+    YAZ_CHECK_EQ(json_count_children(n1), 0);
+
+    n1 = json_get_object(n, "b");
+    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 2.0);
+    YAZ_CHECK_EQ(json_count_children(n1), 0);
+
+    n1 = json_get_object(n, "c");
+    YAZ_CHECK(n1 && n1->type == json_node_array);
+    YAZ_CHECK_EQ(json_count_children(n1), 3);
+
+    n1 = json_get_elem(json_get_object(n, "c"), 0);
+    YAZ_CHECK(n1 && n1->type == json_node_true);
+
+    n1 = json_get_elem(json_get_object(n, "c"), 1);
+    YAZ_CHECK(n1 && n1->type == json_node_false);
+
+    n1 = json_get_elem(json_get_object(n, "c"), 2);
+    YAZ_CHECK(n1 && n1->type == json_node_null);
+
+    n1 = json_get_elem(json_get_object(n, "c"), 3);
+    YAZ_CHECK(n1 == 0);
+
+    json_remove_node(n);
+}
+
+static int append_check(const char *a, const char *b, const char *exp)
+{
+    WRBUF w = wrbuf_alloc();
+    struct json_node *n_a, *n_b;
+    int ret = 0;
+
+    n_a = json_parse(a, 0);
+    n_b = json_parse(b, 0);
+    json_append_array(json_get_object(n_a, "a"),
+                      json_detach_object(n_b, "b"));
+
+    json_write_wrbuf(n_a, w);
+
+    if (!strcmp(wrbuf_cstr(w), exp))
+        ret = 1;
+    wrbuf_destroy(w);
+    json_remove_node(n_a);
+    json_remove_node(n_b);
+    return ret;
+}
+
+static void tst3(void)
+{
+    YAZ_CHECK(append_check("{\"a\":[1,2,3]}", "{\"b\":[5,6,7]}",
+                           "{\"a\":[1,2,3,5,6,7]}"));
+
+    YAZ_CHECK(append_check("{\"a\":[]}", "{\"b\":[5,6,7]}",
+                           "{\"a\":[5,6,7]}"));
+
+    YAZ_CHECK(append_check("{\"a\":[1,2,3]}", "{\"b\":[]}",
+                           "{\"a\":[1,2,3]}"));
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst1();
+    tst2();
+    tst3();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
+
diff --git a/test/test_log.c b/test/test_log.c
new file mode 100644 (file)
index 0000000..d4a83e5
--- /dev/null
@@ -0,0 +1,88 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <yaz/options.h>
+#include <yaz/log.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+void hook_func(int level, const char *msg, void *vp)
+{
+    fprintf(stderr, "[HOOK level=%d msg=%s]\n", level, msg);
+}
+
+int main(int argc, char **argv)
+{
+    char *arg;
+    int i, ret;
+    int level = YLOG_LOG;
+    int number = 1;
+    unsigned int wait_between_log = 0;
+
+    while ((ret = options("f:p:v:l:m:n:r:w:Hh", argv, argc, &arg)) != -2)
+    {
+        switch (ret)
+        {
+        case 'r':
+            yaz_log_init_max_size(atoi(arg));
+            break;
+        case 'f':
+            yaz_log_time_format(arg);
+            break;
+        case 'p':
+            yaz_log_init_prefix(arg);
+            break;
+        case 'v':
+            yaz_log_init_level(yaz_log_mask_str(arg));
+            break;
+        case 'l':
+            if (!strcmp(arg, "@"))
+                yaz_log_init_file(0);
+            else
+                yaz_log_init_file(arg);
+            break;
+        case 'n':
+            number = atoi(arg);
+            break;
+        case 'm':        
+            level = yaz_log_module_level(arg);
+            break;
+        case 'w':
+            wait_between_log = atoi(arg);
+            break;
+        case 'H':
+            yaz_log_set_handler(hook_func, 0);
+            break;
+        case 0:
+            for (i = 0; i<number; i++)
+            {
+                yaz_log(level, "%d %s", i, arg);
+#if HAVE_UNISTD_H
+                if (wait_between_log)
+                    sleep(wait_between_log);
+#endif
+            }
+            break;
+        case 'h':
+        default:
+            fprintf(stderr, "tstlog [-f logformat] [-v level] [-l file] "
+                    "[-p prefix] [-m module] [-w sec] [-r max] [-n num] [-H] msg ..\n");
+            exit(1);
+        }
+    }
+    exit(0);
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_log_thread.c b/test/test_log_thread.c
new file mode 100644 (file)
index 0000000..41c4ceb
--- /dev/null
@@ -0,0 +1,89 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <yaz/log.h>
+#include <yaz/options.h>
+
+#if YAZ_POSIX_THREADS
+#include <pthread.h>
+
+
+static void *t_loop2(void *vp)
+{
+    int i, sz = 10;
+
+    for (i = 0; i<sz; i++)
+    {
+#if 0
+        fprintf(stderr, "pr %d\n", i);
+#else
+        yaz_log(YLOG_LOG, "pr %d", i);
+#endif
+    }
+    return 0;
+}
+
+static void t_test(void)
+{
+    pthread_t tids[4];
+    
+    pthread_create(tids+0, 0, t_loop2, 0);
+    pthread_create(tids+1, 0, t_loop2, 0);
+    pthread_create(tids+2, 0, t_loop2, 0);
+    pthread_create(tids+3, 0, t_loop2, 0);
+    
+    pthread_join(tids[0], 0);
+    pthread_join(tids[1], 0);
+    pthread_join(tids[2], 0);
+    pthread_join(tids[3], 0);
+    exit(0);
+}
+#else
+static void t_test(void)
+{
+}
+
+#endif
+
+int main(int argc, char **argv)
+{
+    char *arg;
+    int ret;
+
+    /* t_test is only invoked if a non-option arg is given .. */
+    while ((ret = options("v:l:", argv, argc, &arg)) != -2)
+    {
+        switch (ret)
+        {
+        case 'v':
+            yaz_log_init_level (yaz_log_mask_str(arg));
+            break;
+        case 'l':
+            yaz_log_init_file(arg);
+            break;
+        case 0:
+            t_test();
+            break;
+        default:
+            exit(1);
+        }
+    }
+    return 0;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_match_glob.c b/test/test_match_glob.c
new file mode 100644 (file)
index 0000000..8421752
--- /dev/null
@@ -0,0 +1,59 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <yaz/test.h>
+#include <yaz/match_glob.h>
+#include <stdlib.h>
+#include <string.h>
+
+void tst1(void)
+{
+    YAZ_CHECK_EQ(yaz_match_glob("a", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("", ""), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("a", ""), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("", "a"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("a", "b"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("b", "a"), 0);
+
+    YAZ_CHECK_EQ(yaz_match_glob("?", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("a", "?"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("?", "aa"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("?a", "aa"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("a?", "aa"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("??", "aa"), 1);
+
+    YAZ_CHECK_EQ(yaz_match_glob("*", ""), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("*", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("**", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("*a", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("a*", "a"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("b*", "a"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("*b", "a"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("**b", "a"), 0);
+    YAZ_CHECK_EQ(yaz_match_glob("*b*", "a"), 0);
+
+    YAZ_CHECK_EQ(yaz_match_glob("*:w", "title:w"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("title:w", "title:w"), 1);
+    YAZ_CHECK_EQ(yaz_match_glob("title:*", "title:w"), 1);
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+
+    tst1();
+
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_matchstr.c b/test/test_matchstr.c
new file mode 100644 (file)
index 0000000..bdb9751
--- /dev/null
@@ -0,0 +1,43 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <yaz/matchstr.h>
+#include <yaz/test.h>
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+
+    YAZ_CHECK(yaz_matchstr("x", "x") == 0);
+    YAZ_CHECK(yaz_matchstr("x", "X") == 0);
+    YAZ_CHECK(yaz_matchstr("a", "b") > 0);
+    YAZ_CHECK(yaz_matchstr("b", "a") > 0);
+    YAZ_CHECK(yaz_matchstr("aa","a") > 0);
+    YAZ_CHECK(yaz_matchstr("a-", "a") > 0);
+    YAZ_CHECK(yaz_matchstr("A-b", "ab") == 0);
+    YAZ_CHECK(yaz_matchstr("A--b", "ab") > 0);
+    YAZ_CHECK(yaz_matchstr("A--b", "a-b") > 0);
+    YAZ_CHECK(yaz_matchstr("A--b", "a--b") == 0);
+    YAZ_CHECK(yaz_matchstr("a123",  "a?") == 0);
+    YAZ_CHECK(yaz_matchstr("a123",   "a1.3") == 0);
+    YAZ_CHECK(yaz_matchstr("a123",   "..?") == 0);
+    YAZ_CHECK(yaz_matchstr("a123",   "a1.") > 0);
+    YAZ_CHECK(yaz_matchstr("a123",   "a...") == 0);
+
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_nmem.c b/test/test_nmem.c
new file mode 100644 (file)
index 0000000..80a2e56
--- /dev/null
@@ -0,0 +1,63 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#include <yaz/nmem.h>
+#include <yaz/test.h>
+
+void tst(void)
+{
+    NMEM n;
+    int j;
+    char *cp;
+
+    n = nmem_create();
+    YAZ_CHECK(n);
+
+    for (j = 1; j<500; j++)
+    {
+        cp = (char *) nmem_malloc(n, j);
+        YAZ_CHECK(cp);
+        if ((int) sizeof(long) >= j)
+            *(long*) cp = 123L;
+#if HAVE_LONG_LONG
+        if ((int) sizeof(long long) >= j)
+            *(long long*) cp = 123L;
+#endif
+        if ((int) sizeof(double) >= j)
+            *(double*) cp = 12.2;
+    }
+    
+    for (j = 2000; j<20000; j+= 2000)
+    {
+        cp = (char *) nmem_malloc(n, j);
+        YAZ_CHECK(cp);
+    }
+    nmem_destroy(n);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_odr.c b/test/test_odr.c
new file mode 100644 (file)
index 0000000..63ad290
--- /dev/null
@@ -0,0 +1,386 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <yaz/oid_util.h>
+#include "test_odrcodec.h"
+
+#include <yaz/test.h>
+
+#define MYOID  "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19"
+
+void tst_MySequence1(ODR encode, ODR decode)
+{
+    int ret;
+    char *ber_buf;
+    int ber_len;
+    Yc_MySequence *s = (Yc_MySequence *) odr_malloc(encode, sizeof(*s));
+    Yc_MySequence *t;
+
+    YAZ_CHECK(s);
+    s->first = odr_intdup(encode, 12345);
+    s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second));
+    s->second->buf = (unsigned char *) "hello";
+    s->second->len = 5;
+    s->second->size = 0;
+    s->third = odr_booldup(encode, 1);
+    s->fourth = odr_nullval();
+    s->fifth = odr_intdup(encode, YC_MySequence_enum1);
+    
+    s->myoid = odr_getoidbystr(decode, MYOID);
+
+    ret = yc_MySequence(encode, &s, 0, 0);
+    YAZ_CHECK(ret);
+    if (!ret)
+        return;
+    
+    ber_buf = odr_getbuf(encode, &ber_len, 0);
+
+    odr_setbuf(decode, ber_buf, ber_len, 0);
+
+    ret = yc_MySequence(decode, &t, 0, 0);
+    YAZ_CHECK(ret);
+    if (!ret)
+        return;
+
+    YAZ_CHECK(t);
+
+    YAZ_CHECK(t->first && *t->first == 12345);
+
+    YAZ_CHECK(t->second && t->second->buf && t->second->len == 5);
+
+    YAZ_CHECK(t->second && t->second->buf && t->second->len == 5 &&
+              memcmp(t->second->buf, "hello", t->second->len) == 0);
+
+    YAZ_CHECK(t->third && *t->third == 1);
+
+    YAZ_CHECK(t->fourth);
+
+    YAZ_CHECK(t->fifth && *t->fifth == YC_MySequence_enum1);
+
+    YAZ_CHECK(t->myoid);
+    if (t->myoid)
+    {
+        Odr_oid *myoid = odr_getoidbystr(decode, MYOID);
+
+        YAZ_CHECK(oid_oidcmp(myoid, t->myoid) == 0);
+    }
+}
+
+void tst_MySequence2(ODR encode, ODR decode)
+{
+    int ret;
+    Yc_MySequence *s = (Yc_MySequence *) odr_malloc(encode, sizeof(*s));
+
+    YAZ_CHECK(s);
+    s->first = 0;  /* deliberately miss this .. */
+    s->second = (Odr_oct *) odr_malloc(encode, sizeof(*s->second));
+    s->second->buf = (unsigned char *) "hello";
+    s->second->len = 5;
+    s->second->size = 0;
+    s->third = odr_booldup(encode, 1);
+    s->fourth = odr_nullval();
+    s->fifth = odr_intdup(encode, YC_MySequence_enum1);
+    s->myoid = odr_getoidbystr(encode, MYOID);
+
+    ret = yc_MySequence(encode, &s, 0, 0); /* should fail */
+    YAZ_CHECK(!ret);
+
+    YAZ_CHECK(odr_geterror(encode) == OREQUIRED);
+
+    YAZ_CHECK(strcmp(odr_getelement(encode), "first") == 0);
+    odr_reset(encode);
+
+    YAZ_CHECK(odr_geterror(encode) == ONONE);
+
+    YAZ_CHECK(strcmp(odr_getelement(encode), "") == 0);
+}
+
+void tst_MySequence3(ODR encode, ODR decode)
+{
+    char buf[40];
+    int i;
+    Yc_MySequence *t;
+
+    srand(123);
+    for (i = 0; i < 1000; i++)
+    {
+        int j;
+        for (j = 0; j < (int) sizeof(buf); j++)
+            buf[j] = rand();
+
+        for (j = 1; j < (int) sizeof(buf); j++)
+        {
+            odr_setbuf(decode, buf, j, 0);
+            yc_MySequence(decode, &t, 0, 0);
+            odr_reset(decode);
+        }
+    }
+}
+
+static void tst_berint32(ODR encode, ODR decode)
+{
+    char *buf = 0;
+    int len = 0;
+    Odr_int val;
+    Odr_int ret_val;
+    int r;
+    
+    val = 0;
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 2);
+    YAZ_CHECK_EQ(buf[0], 1);
+    YAZ_CHECK_EQ(buf[1], 0);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, 0);
+
+    val = 1;
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 2);
+    YAZ_CHECK_EQ(buf[0], 1);
+    YAZ_CHECK_EQ(buf[1], 1);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, 1);
+
+    val = -1;
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 2);
+    YAZ_CHECK_EQ(buf[0], 1);
+    YAZ_CHECK_EQ((unsigned char) buf[1], 255);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, -1);
+
+    val = 127;
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 2);
+    YAZ_CHECK_EQ(buf[0], 1);
+    YAZ_CHECK_EQ(buf[1], 127);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, 127);
+
+
+    val = 128;
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 3);
+    YAZ_CHECK_EQ(buf[0], 2);
+    YAZ_CHECK_EQ(buf[1], 0);
+    YAZ_CHECK_EQ(((unsigned char *) buf)[2], 128);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, 128);
+
+    val = 2147483647; /* 2^31-1 */
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 5);
+    YAZ_CHECK_EQ(buf[0], 4);
+    YAZ_CHECK_EQ(buf[1], 127);
+    YAZ_CHECK_EQ((unsigned char) buf[2], 255);
+    YAZ_CHECK_EQ((unsigned char) buf[3], 255);
+    YAZ_CHECK_EQ((unsigned char) buf[4], 255);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, 2147483647);
+
+    val = -2147483647L -1; /* -2^31 */
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 5);
+    YAZ_CHECK_EQ(buf[0], 4);
+    YAZ_CHECK_EQ((unsigned char) buf[1], 128);
+    YAZ_CHECK_EQ(buf[2], 0);
+    YAZ_CHECK_EQ(buf[3], 0);
+    YAZ_CHECK_EQ(buf[4], 0);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, (Odr_int) -2147483647L -1);
+}
+
+static void tst_berint64(ODR encode, ODR decode)
+{
+#if NMEM_64
+    char *buf = 0;
+    int len = 0;
+    Odr_int val;
+    Odr_int ret_val;
+    int r;
+    
+    val = (Odr_int) 2 * 2147483648UL; /* 2^32 */
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 6);
+    YAZ_CHECK_EQ(buf[0], 5);
+    YAZ_CHECK_EQ(buf[1], 1);
+    YAZ_CHECK_EQ(buf[2], 0);
+    YAZ_CHECK_EQ(buf[3], 0);
+    YAZ_CHECK_EQ(buf[4], 0);
+    YAZ_CHECK_EQ(buf[5], 0);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, val);
+
+    val = (Odr_int) -2 * 2147483648UL; /* -2^32 */
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 6);
+    YAZ_CHECK_EQ(buf[0], 5);
+    YAZ_CHECK_EQ((unsigned char) buf[1], 255);
+    YAZ_CHECK_EQ(buf[2], 0);
+    YAZ_CHECK_EQ(buf[3], 0);
+    YAZ_CHECK_EQ(buf[4], 0);
+    YAZ_CHECK_EQ(buf[5], 0);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, val);
+
+    val = (Odr_int) 1000 * 1000000000L; /* 10^12 */
+    odr_reset(encode);
+    r = ber_integer(encode, &val);
+    YAZ_CHECK_EQ(r, 1);
+    buf = odr_getbuf(encode, &len, 0);
+    YAZ_CHECK(buf);
+    YAZ_CHECK_EQ(len, 7);
+    YAZ_CHECK_EQ(buf[0], 6);
+    YAZ_CHECK_EQ(buf[1], 0);
+    YAZ_CHECK_EQ((unsigned char) buf[2], 232);
+    YAZ_CHECK_EQ((unsigned char) buf[3], 212);
+    YAZ_CHECK_EQ((unsigned char) buf[4], 165);
+    YAZ_CHECK_EQ(buf[5], 16);
+    YAZ_CHECK_EQ(buf[6], 0);
+
+    odr_reset(decode);
+    odr_setbuf(decode, buf, len, 0);
+    ber_integer(decode, &ret_val);
+    YAZ_CHECK_EQ(ret_val, val);
+#endif
+}
+
+static void tst(void)
+{
+    ODR odr_encode = odr_createmem(ODR_ENCODE);
+    ODR odr_decode = odr_createmem(ODR_DECODE);
+
+    YAZ_CHECK(odr_encode);
+    YAZ_CHECK(odr_decode);
+
+    tst_MySequence1(odr_encode, odr_decode);
+    tst_MySequence2(odr_encode, odr_decode);
+    tst_MySequence3(odr_encode, odr_decode);
+
+    tst_berint32(odr_encode, odr_decode);
+    tst_berint64(odr_encode, odr_decode);
+
+    odr_destroy(odr_encode);
+    odr_destroy(odr_decode);
+}
+
+/* example from documentation.. 'Using Odr' */
+void do_nothing_useful(Odr_int value)
+{
+    ODR encode, decode;
+    Odr_int *valp, *resvalp;
+    char *bufferp;
+    int len;
+     
+    /* allocate streams */
+    if (!(encode = odr_createmem(ODR_ENCODE)))
+        return;
+    if (!(decode = odr_createmem(ODR_DECODE)))
+        return;
+
+    valp = &value;
+    if (odr_integer(encode, &valp, 0, 0) == 0)
+    {
+        printf("encoding went bad\n");
+        return;
+    }
+    bufferp = odr_getbuf(encode, &len, 0);
+    printf("length of encoded data is %d\n", len);
+
+    /* now let's decode the thing again */
+    odr_setbuf(decode, bufferp, len, 0);
+    if (odr_integer(decode, &resvalp, 0, 0) == 0)
+    {
+        printf("decoding went bad\n");
+        return;
+    }
+    /* ODR_INT_PRINTF format for printf (such as %d) */
+    printf("the value is " ODR_INT_PRINTF "\n", *resvalp);
+
+    /* clean up */
+    odr_destroy(encode);
+    odr_destroy(decode);
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_odrstack.c b/test/test_odrstack.c
new file mode 100644 (file)
index 0000000..e81e4f9
--- /dev/null
@@ -0,0 +1,76 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <stdlib.h>
+#include <yaz/pquery.h>
+#include <yaz/proto.h>
+#include <yaz/test.h>
+
+/** \brief build a 100 level query */
+void test1(void)
+{
+    ODR odr = odr_createmem(ODR_ENCODE);
+    YAZ_PQF_Parser parser = yaz_pqf_create();
+    Z_RPNQuery *rpn_query;
+    char qstr[10000];
+    int i;
+    int ret;
+
+    YAZ_CHECK(odr);
+    YAZ_CHECK(parser);
+
+    *qstr = '\0';
+    for (i = 0; i<100; i++)
+        strcat(qstr, "@and 1 ");
+    strcat(qstr, "1");
+
+    rpn_query = yaz_pqf_parse (parser, odr, qstr);
+    YAZ_CHECK(rpn_query);
+
+    ret = z_RPNQuery(odr, &rpn_query, 0, 0);
+    YAZ_CHECK(ret);
+
+    yaz_pqf_destroy(parser);
+    odr_destroy(odr);
+}
+
+/** \brief build a circular referenced query */
+void test2(void)
+{
+    ODR odr = odr_createmem(ODR_ENCODE);
+    YAZ_PQF_Parser parser = yaz_pqf_create();
+    Z_RPNQuery *rpn_query;
+    int ret;
+
+    YAZ_CHECK(odr);
+
+    rpn_query = yaz_pqf_parse (parser, odr, "@and @and a b c");
+    YAZ_CHECK(rpn_query);
+
+    /* make the circular reference */
+    rpn_query->RPNStructure->u.complex->s1 = rpn_query->RPNStructure;
+
+    ret = z_RPNQuery(odr, &rpn_query, 0, 0);  /* should fail */
+    YAZ_CHECK(!ret);
+
+    yaz_pqf_destroy(parser);
+    odr_destroy(odr);
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    test1();
+    test2();
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_oid.c b/test/test_oid.c
new file mode 100644 (file)
index 0000000..d00c23a
--- /dev/null
@@ -0,0 +1,83 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/oid_db.h>
+
+static void tst(void)
+{
+    char oid_buf[OID_STR_MAX];
+    const char *n;
+    yaz_oid_db_t db;
+    const Odr_oid *c_oid;
+    Odr_oid *oid;
+    NMEM nmem = nmem_create();
+    ODR odr = odr_createmem(ODR_ENCODE);
+
+    db = yaz_oid_std();
+    YAZ_CHECK(db);
+
+    c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "Bib-1");
+    YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
+
+    c_oid = yaz_string_to_oid(db, CLASS_GENERAL, "Bib-1");
+    YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
+
+    c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "unknown");
+    YAZ_CHECK(c_oid == 0);
+
+    oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "1.2.840.10003.3.1", nmem);
+    YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
+
+    oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "unknown", nmem);
+    YAZ_CHECK(oid == 0);
+
+    oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "1.2.840.10003.3.1", odr);
+    YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
+
+    oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "unknown", odr);
+    YAZ_CHECK(oid == 0);
+
+    n = yaz_oid_to_string(db, yaz_oid_attset_bib_1, 0);
+    YAZ_CHECK(n && !strcmp(n, "Bib-1"));
+
+    n = oid_name_to_dotstring(CLASS_ATTSET, "Bib-1", oid_buf);
+    YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.3.1"));
+
+    n = oid_name_to_dotstring(CLASS_DIAGSET, "Bib-1", oid_buf);
+    YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.4.1"));
+
+    n = oid_name_to_dotstring(CLASS_DIAGSET, "unknown", oid_buf);
+    YAZ_CHECK(!n);
+
+    n = oid_name_to_dotstring(CLASS_DIAGSET, "1.2.840.10003.3.1", oid_buf);
+    YAZ_CHECK(!n);
+
+    nmem_destroy(nmem);
+    odr_destroy(odr);
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_pquery.c b/test/test_pquery.c
new file mode 100644 (file)
index 0000000..f76adde
--- /dev/null
@@ -0,0 +1,85 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/wrbuf.h>
+#include <yaz/querytowrbuf.h>
+#include <yaz/pquery.h>
+#include <yaz/test.h>
+
+int expect_pqf(const char *pqf, const char *expect_pqf, int expect_error)
+{
+    YAZ_PQF_Parser parser = yaz_pqf_create();
+    int res = 0;
+    ODR odr = odr_createmem(ODR_ENCODE);
+    Z_RPNQuery *rpn;
+
+    if (!parser)
+        return 0;
+
+    if (!odr)
+        return 0;
+
+    rpn = yaz_pqf_parse(parser, odr, pqf);
+
+    if (!rpn)
+    {
+        const char *msg;
+        size_t offset;
+        int got_error = yaz_pqf_error (parser, &msg, &offset);
+
+        if (expect_error == got_error)
+            res = 1;
+    }
+    else if (expect_error == YAZ_PQF_ERROR_NONE)
+    {
+        WRBUF wrbuf = wrbuf_alloc();
+        
+        if (wrbuf)
+        {
+            yaz_rpnquery_to_wrbuf(wrbuf, rpn);
+            
+            if (!strcmp(wrbuf_cstr(wrbuf), expect_pqf))
+                res = 1;
+            wrbuf_destroy(wrbuf);
+        }
+    }
+    yaz_pqf_destroy(parser);
+    odr_destroy(odr);
+    return res;
+}
+
+static void tst(void)
+{
+    YAZ_CHECK(expect_pqf("a", "@attrset Bib-1 a", YAZ_PQF_ERROR_NONE));
+    YAZ_CHECK(expect_pqf("@attr 1=4 a", "@attrset Bib-1 @attr 1=4 a", YAZ_PQF_ERROR_NONE));
+    YAZ_CHECK(expect_pqf("a b", "", YAZ_PQF_ERROR_EXTRA));
+    YAZ_CHECK(expect_pqf("@and a", "", YAZ_PQF_ERROR_MISSING));
+    YAZ_CHECK(expect_pqf("@attr p=q a", "", YAZ_PQF_ERROR_BAD_INTEGER));
+    YAZ_CHECK(expect_pqf("@prox 0 0 0 0 k 0 a b",
+                         "@attrset Bib-1 @prox 0 0 0 0 k 0 a b",
+                         YAZ_PQF_ERROR_NONE));
+    YAZ_CHECK(expect_pqf("@prox 0 0 0 0 3 0 a b", "",
+                         YAZ_PQF_ERROR_PROXIMITY));
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_query_charset.c b/test/test_query_charset.c
new file mode 100644 (file)
index 0000000..e3c83fc
--- /dev/null
@@ -0,0 +1,95 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/query-charset.h>
+#include <yaz/copy_types.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();
+        Z_RPNQuery *r2 = yaz_copy_z_RPNQuery(rpn, odr);
+
+        YAZ_CHECK(r2);
+        YAZ_CHECK(r2 != rpn);
+        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
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_record_conv.c b/test/test_record_conv.c
new file mode 100644 (file)
index 0000000..dff7f68
--- /dev/null
@@ -0,0 +1,355 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <yaz/record_conv.h>
+#include <yaz/test.h>
+#include <yaz/wrbuf.h>
+#include <string.h>
+#include <yaz/log.h>
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if YAZ_HAVE_XML2
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+yaz_record_conv_t conv_configure(const char *xmlstring, WRBUF w)
+{
+    xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
+    if (!doc)
+    {
+        wrbuf_printf(w, "xmlParseMemory");
+        return 0;
+    }
+    else
+    {
+        xmlNodePtr ptr = xmlDocGetRootElement(doc);
+        yaz_record_conv_t p = yaz_record_conv_create();
+
+        if (p)
+        {
+            const char *srcdir = getenv("srcdir");
+            if (srcdir)
+                yaz_record_conv_set_path(p, srcdir);
+        }
+        if (!ptr)
+        {
+            wrbuf_printf(w, "xmlDocGetRootElement");
+            yaz_record_conv_destroy(p);
+            p = 0;
+        }
+        else if (!p)
+        {
+            wrbuf_printf(w, "yaz_record_conv_create");
+        }
+        else
+        {
+
+
+            int r = yaz_record_conv_configure(p, ptr);
+            
+            if (r)
+            {
+                wrbuf_puts(w, yaz_record_conv_get_error(p));
+                yaz_record_conv_destroy(p);
+                p = 0;
+            }
+        }
+        xmlFreeDoc(doc);
+        return p;
+    }    
+}
+
+int conv_configure_test(const char *xmlstring, const char *expect_error,
+                        yaz_record_conv_t *pt)
+{
+    WRBUF w = wrbuf_alloc();
+    int ret;
+
+    yaz_record_conv_t p = conv_configure(xmlstring, w);
+
+    if (!p)
+    {
+        if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
+            ret = 1;
+        else
+        {
+            ret = 0;
+            printf("%s\n", wrbuf_cstr(w));
+        }
+    }
+    else
+    {
+        if (expect_error)
+            ret = 0;
+        else
+            ret = 1;
+    }
+
+    if (pt)
+        *pt = p;
+    else
+        if (p)
+            yaz_record_conv_destroy(p);
+
+    wrbuf_destroy(w);
+    return ret;
+}
+
+static void tst_configure(void)
+{
+
+
+
+    YAZ_CHECK(conv_configure_test("<bad", "xmlParseMemory", 0));
+
+
+    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
+                                  "<bad/></backend>",
+                                  "Element <backend>: expected <marc> or "
+                                  "<xslt> element, got <bad>", 0));
+
+#if YAZ_HAVE_XSLT
+    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"marc-8\""
+                                  " outputcharset=\"marc-8\""
+                                  "/>"
+                                  "</backend>",
+                                  "Element <marc>: attribute 'inputformat' "
+                                  "required", 0));
+    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
+                                  "<xslt/>"
+                                  "</backend>",
+                                  "Element <xslt>: attribute 'stylesheet' "
+                                  "expected", 0));
+    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "</backend>",
+                                  0, 0));
+#else
+    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "</backend>",
+                                  "xslt unsupported."
+                                  " YAZ compiled without XSLT support", 0));
+#endif 
+}
+
+static int conv_convert_test(yaz_record_conv_t p,
+                             const char *input_record,
+                             const char *output_expect_record)
+{
+    int ret = 0;
+    if (!p)
+    {
+        YAZ_CHECK(ret);
+    }
+    else
+    {
+        WRBUF output_record = wrbuf_alloc();
+        int r = yaz_record_conv_record(p, input_record, strlen(input_record),
+                                       output_record);
+        if (r)
+        {
+            if (output_expect_record)
+            {
+                printf("yaz_record_conv error=%s\n",
+                       yaz_record_conv_get_error(p));
+                ret = 0;
+            }
+            else
+                ret = 1;
+        }
+        else
+        {
+            if (!output_expect_record)
+            {
+                ret = 0;
+            }
+            else if (strcmp(output_expect_record, wrbuf_cstr(output_record)))
+            {
+                ret = 0;
+                printf("got-output_record len=%ld: %s\n", 
+                       (long) wrbuf_len(output_record),
+                       wrbuf_cstr(output_record));
+                printf("output_expect_record len=%ld %s\n",
+                       (long) strlen(output_expect_record),
+                       output_expect_record);
+            }
+            else
+            {
+                ret = 1;
+            }
+        }
+        wrbuf_destroy(output_record);
+    }
+    return ret;
+}
+
+static int conv_convert_test_iter(yaz_record_conv_t p,
+                                  const char *input_record,
+                                  const char *output_expect_record,
+                                  int num_iter)
+{
+    int i;
+    int ret;
+    for (i = 0; i < num_iter; i++)
+    {
+        ret = conv_convert_test(p, input_record, output_expect_record);
+        if (!ret)
+            break;
+    }
+    return ret;
+}
+
+static void tst_convert1(void)
+{
+    yaz_record_conv_t p = 0;
+    const char *marcxml_rec =
+        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
+        "  <leader>00080nam a22000498a 4500</leader>\n"
+        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
+        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
+        "    <subfield code=\"a\">   11224466 </subfield>\n"
+        "  </datafield>\n"
+        "</record>\n";
+    const char *iso2709_rec =
+        "\x30\x30\x30\x38\x30\x6E\x61\x6D\x20\x61\x32\x32\x30\x30\x30\x34"
+        "\x39\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30"
+        "\x30\x30\x30\x30\x30\x31\x30\x30\x30\x31\x37\x30\x30\x30\x31\x33"
+        "\x1E\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x20\x20"
+        "\x1F\x61\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x1D";
+
+    YAZ_CHECK(conv_configure_test("<backend>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>",
+                                  0, &p));
+    YAZ_CHECK(conv_convert_test(p, marcxml_rec, iso2709_rec));
+    yaz_record_conv_destroy(p);
+
+    YAZ_CHECK(conv_configure_test("<backend>"
+                                  "<marc"
+                                  " outputcharset=\"utf-8\""
+                                  " inputcharset=\"marc-8\""
+                                  " outputformat=\"marcxml\""
+                                  " inputformat=\"marc\""
+                                  "/>"
+                                  "</backend>",
+                                  0, &p));
+    YAZ_CHECK(conv_convert_test(p, iso2709_rec, marcxml_rec));
+    yaz_record_conv_destroy(p);
+
+
+    YAZ_CHECK(conv_configure_test("<backend>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "<marc"
+                                  " outputcharset=\"utf-8\""
+                                  " inputcharset=\"marc-8\""
+                                  " outputformat=\"marcxml\""
+                                  " inputformat=\"marc\""
+                                  "/>"
+                                  "</backend>",
+                                  0, &p));
+    YAZ_CHECK(conv_convert_test(p, marcxml_rec, marcxml_rec));
+    yaz_record_conv_destroy(p);
+
+
+    YAZ_CHECK(conv_configure_test("<backend>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "<marc"
+                                  " inputcharset=\"marc-8\""
+                                  " outputformat=\"marcxml\""
+                                  " inputformat=\"marc\""
+                                  "/>"
+                                  "</backend>",
+                                  0, &p));
+    YAZ_CHECK(conv_convert_test(p, marcxml_rec, marcxml_rec));
+    yaz_record_conv_destroy(p);
+}
+
+static void tst_convert2(void)
+{
+    yaz_record_conv_t p = 0;
+    const char *marcxml_rec =
+        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
+        "  <leader>00080nam a22000498a 4500</leader>\n"
+        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
+        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
+        "    <subfield code=\"a\">k&#xf8;benhavn</subfield>\n"
+        "  </datafield>\n"
+        "</record>\n";
+    const char *iso2709_rec =
+        "\x30\x30\x30\x37\x37\x6E\x61\x6D\x20\x61\x32\x32\x30\x30\x30\x34"
+        "\x39\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30"
+        "\x30\x30\x30\x30\x30\x31\x30\x30\x30\x31\x34\x30\x30\x30\x31\x33"
+        "\x1E\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x20\x20"
+        "\x1F\x61\x6b\xb2\x62\x65\x6e\x68\x61\x76\x6e\x1E\x1D";
+
+    YAZ_CHECK(conv_configure_test("<backend>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>",
+                                  0, &p));
+    YAZ_CHECK(conv_convert_test_iter(p, marcxml_rec, iso2709_rec, 100));
+    yaz_record_conv_destroy(p);
+}
+
+#endif
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    yaz_log_xml_errors(0, 0 /* disable log */);
+#if YAZ_HAVE_XML2
+    tst_configure();
+#endif
+#if  YAZ_HAVE_XSLT 
+    tst_convert1();
+    tst_convert2();
+#endif
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_record_conv.xsl b/test/test_record_conv.xsl
new file mode 100644 (file)
index 0000000..21d6d6b
--- /dev/null
@@ -0,0 +1,16 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+<!-- Identity transform stylesheet -->
+
+<xsl:output indent="yes"
+      method="xml"
+      version="1.0"
+      encoding="UTF-8"/>
+
+ <xsl:template match="node()|@*">
+   <xsl:copy>
+     <xsl:apply-templates select="@*|node()"/>
+   </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/test/test_retrieval.c b/test/test_retrieval.c
new file mode 100644 (file)
index 0000000..9b7bf8a
--- /dev/null
@@ -0,0 +1,334 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <yaz/retrieval.h>
+#include <yaz/test.h>
+#include <yaz/wrbuf.h>
+#include <string.h>
+#include <yaz/log.h>
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if YAZ_HAVE_XSLT
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
+{
+    xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
+    if (!doc)
+    {
+        wrbuf_printf(w, "xmlParseMemory");
+        return 0;
+    }
+    else
+    {
+        xmlNodePtr ptr = xmlDocGetRootElement(doc);
+        yaz_retrieval_t p = yaz_retrieval_create();
+
+        if (p)
+        {
+            const char *srcdir = getenv("srcdir");
+            if (srcdir)
+                yaz_retrieval_set_path(p, srcdir);
+        }
+        if (!ptr)
+        {
+            wrbuf_printf(w, "xmlDocGetRootElement");
+            yaz_retrieval_destroy(p);
+            p = 0;
+        }
+        else if (!p)
+        {
+            wrbuf_printf(w, "yaz_retrieval_create");
+        }
+        else
+        {
+            int r = yaz_retrieval_configure(p, ptr);
+            
+            if (r)
+            {
+                wrbuf_puts(w, yaz_retrieval_get_error(p));
+                yaz_retrieval_destroy(p);
+                p = 0;
+            }
+        }
+        xmlFreeDoc(doc);
+        return p;
+    }    
+}
+
+int conv_configure_test(const char *xmlstring, const char *expect_error,
+                        yaz_retrieval_t *pt)
+{
+    WRBUF w = wrbuf_alloc();
+    int ret;
+
+    yaz_retrieval_t p = conv_configure(xmlstring, w);
+
+    if (!p)
+    {
+        if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
+            ret = 1;
+        else
+        {
+            ret = 0;
+            printf("%s\n", wrbuf_cstr(w));
+        }
+    }
+    else
+    {
+        if (expect_error)
+        {
+            ret = 0;
+            yaz_retrieval_destroy(p);
+        }
+        else
+        {
+            if (pt)
+                *pt = p;
+            else
+                yaz_retrieval_destroy(p);
+            ret = 1;
+        }
+    }
+    wrbuf_destroy(w);
+    return ret;
+}
+
+static void tst_configure(void)
+{
+    YAZ_CHECK(conv_configure_test("<bad", 
+                                  "xmlParseMemory", 0));
+
+    YAZ_CHECK(conv_configure_test("<bad/>", 
+                                  "Expected element <retrievalinfo>", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
+                                  "Element <retrievalinfo>:"
+                                  " expected element <retrieval>, got <bad>",
+                                  0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
+                                  "</retrievalinfo>",
+                                  "Missing 'syntax' attribute", 0));
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " unknown=\"unknown\""
+                                  ">"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <retrieval>:  expected attributes "
+                                  "'syntax', identifier' or 'name', got "
+                                  "'unknown'", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"unknown_synt\""
+                                  ">"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <retrieval>:  unknown attribute "
+                                  "value syntax='unknown_synt'", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  "/>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " name=\"marcxml\"/>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " name=\"marcxml\"" 
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  "/>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  " name=\"marcxml\">"
+                                  "<convert/>"
+                                  "</retrieval>" 
+                                  "</retrievalinfo>",
+                                  "Element <retrieval>: expected zero or one element "
+                                  "<backend>, got <convert>", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  " name=\"marcxml\">"
+                                  " <backend syntax=\"usmarc\""
+                                  " schema=\"marcxml\""
+                                  "/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <backend>: expected attributes 'syntax' or 'name,"
+                                  " got 'schema'", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  " name=\"marcxml\">"
+                                  " <backend syntax=\"usmarc\""
+                                  " name=\"marcxml\""
+                                  "/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                  " name=\"marcxml\">"
+                                  " <backend syntax=\"unknown\""
+                                  "/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <backend syntax='unknown'>: "
+                                  "attribute 'syntax' has invalid value "
+                                  "'unknown'", 0));
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval" 
+                                  " syntax=\"usmarc\""
+                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
+                                    " name=\"marcxml\">"
+                                  " <backend syntax=\"usmarc\""
+                                  " unknown=\"silly\""
+                                  "/>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <backend>: expected attributes "
+                                  "'syntax' or 'name, got 'unknown'", 0));
+
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval syntax=\"usmarc\">"
+                                  "<backend syntax=\"xml\" name=\"dc\">"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"non-existent\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <marc inputcharset='utf-8'"
+                                  " outputcharset='non-existent'>: Unsupported character"
+                                  " set mapping defined by attribute values", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval syntax=\"usmarc\">"
+                                  "<backend syntax=\"xml\" name=\"dc\">"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"not-existent\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  "Element <marc inputformat='not-existent'>:  Unsupported"
+                                  " input format defined by attribute value", 0));
+
+    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
+                                  "<retrieval syntax=\"usmarc\">"
+                                  "<backend syntax=\"xml\" name=\"dc\">"
+                                  "<xslt stylesheet=\"test_record_conv.xsl\"/>"
+                                  "<marc"
+                                  " inputcharset=\"utf-8\""
+                                  " outputcharset=\"marc-8\""
+                                  " inputformat=\"xml\""
+                                  " outputformat=\"marc\""
+                                  "/>"
+                                  "</backend>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+    YAZ_CHECK(conv_configure_test(
+                                  "<retrievalinfo "
+                                  " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
+                                  "<retrieval syntax=\"grs-1\"/>"
+                                  "<retrieval syntax=\"usmarc\" name=\"F\"/>"
+                                  "<retrieval syntax=\"usmarc\" name=\"B\"/>"
+                                  "<retrieval syntax=\"xml\" name=\"marcxml\" "
+                                  "           identifier=\"info:srw/schema/1/marcxml-v1.1\">"
+                                  "  <backend syntax=\"usmarc\" name=\"F\">"
+                                  "    <marc inputformat=\"marc\" outputformat=\"marcxml\" "
+                                  "            inputcharset=\"marc-8\"/>"
+                                  "  </backend>"
+                                  "</retrieval>"
+                                  "<retrieval syntax=\"xml\" name=\"danmarc\">"
+                                  "  <backend syntax=\"usmarc\" name=\"F\">"
+                                  "    <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
+                                  "          inputcharset=\"marc-8\"/>"
+                                  "  </backend>"
+                                  "</retrieval>"
+                                  "<retrieval syntax=\"xml\" name=\"dc\" "
+                                  "           identifier=\"info:srw/schema/1/dc-v1.1\">"
+                                  "  <backend syntax=\"usmarc\" name=\"F\">"
+                                  "    <marc inputformat=\"marc\" outputformat=\"marcxml\" "
+                                  "          inputcharset=\"marc-8\"/>"
+                                  "    <xslt stylesheet=\"test_record_conv.xsl\"/> "
+                                  "  </backend>"
+                                  "</retrieval>"
+                                  "</retrievalinfo>",
+                                  0, 0));
+
+}
+
+#endif
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+
+    yaz_log_xml_errors(0, 0 /* disable it */);
+
+#if YAZ_HAVE_XSLT
+    tst_configure();
+#endif
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_rpn2cql.c b/test/test_rpn2cql.c
new file mode 100644 (file)
index 0000000..7aecbb0
--- /dev/null
@@ -0,0 +1,114 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/test.h>
+#include <yaz/log.h>
+#include <yaz/rpn2cql.h>
+#include <yaz/wrbuf.h>
+#include <yaz/pquery.h>
+
+static int compare(cql_transform_t ct, const char *pqf, const char *cql)
+{
+    int ret = 0;
+    ODR odr = odr_createmem(ODR_ENCODE);
+    WRBUF w = wrbuf_alloc();
+    Z_RPNQuery *q = p_query_rpn(odr, pqf);
+    
+    if (q)
+    {
+        int r = cql_transform_rpn2cql_wrbuf(ct, w, q);
+
+        if (r != 0)
+        {
+            /* transform error */
+            yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r);
+            if (!cql) /* also expected error? */
+                ret = 1;
+        }
+        else if (r == 0)
+        {
+            yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w));
+            if (cql && !strcmp(wrbuf_cstr(w), cql))
+            {
+                ret = 1;
+            }
+        }
+    }
+    wrbuf_destroy(w);
+    odr_destroy(odr);
+    return ret;
+}
+
+static void tst1(void)
+{
+    cql_transform_t ct = cql_transform_create();    
+
+    YAZ_CHECK(compare(ct, "abc", "abc"));
+    YAZ_CHECK(compare(ct, "\"a b c\"", "\"a b c\""));
+    YAZ_CHECK(compare(ct, "@and a b", "a and b"));
+    YAZ_CHECK(compare(ct, "@attr 1=field abc", "field=abc"));
+    YAZ_CHECK(compare(ct, "@attr 1=4 abc", 0)); /* should fail */
+
+    cql_transform_define_pattern(ct, "index.title", "1=4");
+    YAZ_CHECK(compare(ct, "@attr 1=4 abc", "title=abc"));
+
+    cql_transform_define_pattern(ct, "index.foo", "1=bar");
+    YAZ_CHECK(compare(ct, "@attr 1=bar abc", "foo=abc"));
+
+    cql_transform_close(ct);
+}
+
+static void tst2(void)
+{
+    WRBUF w = wrbuf_alloc();
+    cql_transform_t ct = 0;
+    const char *srcdir = getenv("srcdir");
+    if (srcdir)
+    {
+        wrbuf_puts(w, srcdir);
+        wrbuf_puts(w, "/");
+    }
+    wrbuf_puts(w, "../etc/pqf.properties");
+    
+    ct = cql_transform_open_fname(wrbuf_cstr(w));
+    YAZ_CHECK(compare(ct, "@attr 1=4 abc", "dc.title=abc"));
+    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 4=108 abc", "dc.title=/exact abc"));
+    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 3=1 @attr 6=1 abc", "dc.title=abc"));
+    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 4=1 @attr 6=1 abc",
+                      "dc.title=abc"));
+    YAZ_CHECK(compare(ct, "@attr 1=1016 abc", "abc"));
+    YAZ_CHECK(compare(ct, "@attr 2=1 @attr 1=30 1980", "dc.date<1980"));
+    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=3 1980", "dc.date=1980"));
+    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=5 1980", "dc.date>1980"));
+    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=2 1980", "dc.date<=1980"));
+    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=4 1980", "dc.date>=1980"));
+
+    YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1"));
+    YAZ_CHECK(compare(ct, "@attr 1=500 abc", 0));
+    cql_transform_close(ct);
+    wrbuf_destroy(w);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst1();
+    tst2();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_soap1.c b/test/test_soap1.c
new file mode 100644 (file)
index 0000000..eb2ba11
--- /dev/null
@@ -0,0 +1,62 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#if YAZ_HAVE_XML2
+#include <libxml/parser.h>
+#endif
+#include <yaz/test.h>
+
+void tst(void)
+{
+#if YAZ_HAVE_XML2
+    xmlChar *buf_out;
+    int len_out;
+    xmlDocPtr doc;
+    xmlNodePtr top;
+#if 0
+    const char *val = "jordb" "\xe6" "r"; /* makes xmlDocDumpMemory hang .. */
+#else
+    const char *val = "jordbaer"; /* OK */
+#endif
+    doc = xmlNewDoc(BAD_CAST "1.0");
+    YAZ_CHECK(doc);
+
+    top = xmlNewNode(0, BAD_CAST "top");
+    YAZ_CHECK(top);
+    
+    xmlNewTextChild(top, 0, BAD_CAST "sub", BAD_CAST val);
+    xmlDocSetRootElement(doc, top);
+    
+    xmlDocDumpMemory(doc, &buf_out, &len_out);
+#if 0
+    printf("%*s", len_out, buf_out);
+#endif
+
+
+/* YAZ_HAVE_XML2 */
+#endif
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+#if YAZ_HAVE_XML2
+    LIBXML_TEST_VERSION;
+#endif
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_soap2.c b/test/test_soap2.c
new file mode 100644 (file)
index 0000000..620f5f3
--- /dev/null
@@ -0,0 +1,67 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <yaz/test.h>
+#include <yaz/srw.h>
+#include <yaz/soap.h>
+
+#if YAZ_HAVE_XML2
+#include <libxml/parser.h>
+
+static void tst_srw(void)
+{
+    const char *charset = 0;
+    char *content_buf = 0;
+    int content_len;
+    int ret;
+    ODR o = odr_createmem(ODR_ENCODE);
+    Z_SOAP_Handler h[2] = {
+        {"http://www.loc.gov/zing/srw/", 0, (Z_SOAP_fun) yaz_srw_codec},
+        {0, 0, 0}
+    };
+    Z_SRW_PDU *sr = yaz_srw_get(o, Z_SRW_searchRetrieve_request);
+    Z_SOAP *p = (Z_SOAP *) odr_malloc(o, sizeof(*p));
+
+    YAZ_CHECK(o);
+    YAZ_CHECK(sr);
+    YAZ_CHECK(p);
+#if 0
+    sr->u.request->query.cql = "jordb" "\xe6" "r"; 
+#else
+    sr->u.request->query.cql = "jordbaer"; 
+#endif
+
+    p->which = Z_SOAP_generic;
+    p->u.generic = (Z_SOAP_Generic *) odr_malloc(o, sizeof(*p->u.generic));
+    p->u.generic->no = 0;
+    p->u.generic->ns = 0;
+    p->u.generic->p = sr;
+    p->ns = "http://schemas.xmlsoap.org/soap/envelope/";
+
+    ret = z_soap_codec_enc(o, &p, &content_buf, &content_len, h, charset);
+    odr_destroy(o);
+    YAZ_CHECK(ret == 0);  /* codec failed ? */
+}
+#endif
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+#if YAZ_HAVE_XML2
+    LIBXML_TEST_VERSION;
+    tst_srw();
+#endif
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_timing.c b/test/test_timing.c
new file mode 100644 (file)
index 0000000..edbca1d
--- /dev/null
@@ -0,0 +1,70 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/timing.h>
+#include <yaz/test.h>
+#include <yaz/log.h>
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+static void tst(void)
+{
+    yaz_timing_t t = yaz_timing_create();
+    double real, user, sys;
+    int i = 0;
+    double x = 0;
+
+    YAZ_CHECK(t);
+    if (!t)
+        return;
+
+#ifdef WIN32
+    Sleep(10);
+#endif
+    for (i = 0; i<5000000; i++)
+        x += i;
+
+    YAZ_CHECK_EQ(i, 5000000);
+
+    yaz_log(YLOG_LOG, "i=%d x=%f", i, x);
+    yaz_timing_stop(t);
+
+    real = yaz_timing_get_real(t);
+    YAZ_CHECK(real == -1.0 || real >= 0.0);
+
+    user = yaz_timing_get_user(t);
+    YAZ_CHECK(user == -1.0 || user >= 0.0);
+
+    sys = yaz_timing_get_sys(t); 
+    YAZ_CHECK(sys == -1.0 || sys >= 0.0);
+
+    yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
+   
+    yaz_timing_destroy(&t);
+    YAZ_CHECK(!t);
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_tpath.c b/test/test_tpath.c
new file mode 100644 (file)
index 0000000..411ae82
--- /dev/null
@@ -0,0 +1,52 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+#include <yaz/tpath.h>
+#include <yaz/test.h>
+#include <string.h>
+#include <yaz/log.h>
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+static void tst_tpath(void)
+{
+    char fullpath[FILENAME_MAX];
+
+    YAZ_CHECK(!yaz_filepath_resolve("etc", 0, 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("etc", "", 0, fullpath)); /* bug #606 */
+    YAZ_CHECK(!yaz_filepath_resolve("etc", ".", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("does_not_exist", "", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("does_not_exist", ".", 0, fullpath));
+    YAZ_CHECK(yaz_filepath_resolve("test_tpath", 0, 0, fullpath));
+
+    YAZ_CHECK(!yaz_filepath_resolve("test_tpath", "", 0, fullpath));
+    YAZ_CHECK(yaz_filepath_resolve("test_tpath", ".", 0, fullpath));
+
+    YAZ_CHECK(!yaz_filepath_resolve("test_tpath", "unknown_dir", 0, fullpath));
+    YAZ_CHECK(yaz_filepath_resolve("test_tpath", "unknown_dir:.", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("test_tpath", "unknown_dir:", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("test_tpath", "unknown_dir:c:", 0, fullpath));
+    YAZ_CHECK(!yaz_filepath_resolve("test_tpath", "unknown_dir:c:\\other", 0, fullpath));
+
+}
+
+int main(int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst_tpath();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_wrbuf.c b/test/test_wrbuf.c
new file mode 100644 (file)
index 0000000..af06e40
--- /dev/null
@@ -0,0 +1,72 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/wrbuf.h>
+#include <yaz/test.h>
+
+static void tstwrbuf(void)
+{
+    int step;
+    WRBUF wr;
+
+    wr = 0;
+    wrbuf_destroy(wr);
+
+    wr = wrbuf_alloc();
+    YAZ_CHECK(wr);
+    wrbuf_destroy(wr);
+
+    wr = wrbuf_alloc();
+
+    YAZ_CHECK(wr);
+
+    for (step = 1; step < 65; step++)
+    {
+        int i, j, k;
+        int len;
+        char buf[64];
+        char *cp;
+        for (j = 1; j<step; j++)
+        {
+            for (i = 0; i<j; i++)
+                buf[i] = i+1;
+            buf[i] = '\0';
+            wrbuf_puts(wr, buf);
+        }
+        
+        cp = wrbuf_buf(wr);
+        len = wrbuf_len(wr);
+        YAZ_CHECK(len == step * (step-1) / 2);
+        k = 0;
+        for (j = 1; j<step; j++)
+            for (i = 0; i<j; i++)
+            {
+                YAZ_CHECK(cp[k] == i+1);
+                k++;
+            }
+        wrbuf_rewind(wr);
+    }
+    wrbuf_destroy(wr);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tstwrbuf();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_xmalloc.c b/test/test_xmalloc.c
new file mode 100644 (file)
index 0000000..877c93f
--- /dev/null
@@ -0,0 +1,61 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <string.h>
+#include <yaz/xmalloc.h>
+#include <yaz/test.h>
+
+void tst(void)
+{
+    char *p = 0;
+
+    p = (char *) xmalloc(10);
+    YAZ_CHECK(p);
+    p = (char *) xrealloc(p, 20);
+    YAZ_CHECK(p);
+    xfree(p);
+
+    p = xstrdup("hello");
+    YAZ_CHECK(p);
+    if (!p)
+        return;
+    YAZ_CHECK(!strcmp(p, "hello"));
+    xfree(p);
+
+    p = xstrndup("hello", 2);
+    YAZ_CHECK(p);
+    if (!p)
+        return;
+    YAZ_CHECK(!strcmp(p, "he"));
+    xfree(p);
+
+    p = xstrndup("hello", 6);
+    YAZ_CHECK(p);
+    if (!p)
+        return;
+    YAZ_CHECK(!strcmp(p, "hello"));
+    xfree(p);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_xml_include.c b/test/test_xml_include.c
new file mode 100644 (file)
index 0000000..7a289be
--- /dev/null
@@ -0,0 +1,78 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <yaz/xml_include.h>
+#include <yaz/test.h>
+
+static void tst_xml_include(void)
+{
+    const char *srcdir = getenv("srcdir");
+    xmlDocPtr doc;
+    xmlNodePtr node;
+    const char *xml_in = "<x><include src=\"test_xml_inc*.xml\"/></x>";
+
+    if (srcdir == 0)
+        srcdir = ".";
+
+    doc = xmlParseMemory(xml_in, strlen(xml_in));
+    YAZ_CHECK(doc);
+    if (!doc)
+        return;
+    node = xmlDocGetRootElement(doc);
+    YAZ_CHECK(node);
+    if (node)
+    {
+        const char *expect =
+            "<?xml version=\"1.0\"?>\n"
+            "<x><!-- begin include src=\"test_xml_inc*.xml\" -->"
+            "<y>some</y>"
+            "<!-- end include src=\"test_xml_inc*.xml\" --></x>\n";
+
+        xmlChar *xml_out;
+        int len_out;
+        int ret = yaz_xml_include_simple(node, srcdir);
+        YAZ_CHECK(ret == 0);
+        xmlDocDumpMemory(doc, &xml_out, &len_out);
+        YAZ_CHECK(xml_out && len_out > 0);
+        if (xml_out && len_out > 0)
+        {
+            YAZ_CHECK(strlen(expect) == len_out);
+            if (strlen(expect) == len_out)
+            {
+                YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
+            }
+            else
+            {
+                fwrite(xml_out, 1, len_out, stdout);
+                fflush(stdout);
+            }
+            xmlFree(xml_out);
+        }
+    }
+    xmlFreeDoc(doc);
+}
+
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    YAZ_CHECK_LOG();
+    tst_xml_include();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/test_xml_include.xml b/test/test_xml_include.xml
new file mode 100644 (file)
index 0000000..da253be
--- /dev/null
@@ -0,0 +1 @@
+<y>some</y>
diff --git a/test/test_xmlquery.c b/test/test_xmlquery.c
new file mode 100644 (file)
index 0000000..c1e9034
--- /dev/null
@@ -0,0 +1,249 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <yaz/wrbuf.h>
+#include <yaz/querytowrbuf.h>
+#include <yaz/xmlquery.h>
+#include <yaz/pquery.h>
+#include <yaz/test.h>
+
+#if YAZ_HAVE_XML2
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#endif
+
+enum pqf2xml_status {
+    PQF_FAILED,
+    QUERY2XML_FAILED,
+    XML_NO_MATCH,
+    XML_MATCH,
+    XML_NO_ERROR
+};
+
+enum pqf2xml_status pqf2xml_text(const char *pqf, const char *expect_xml,
+                                 const char *expect_pqf)
+{
+    YAZ_PQF_Parser parser = yaz_pqf_create();
+    ODR odr = odr_createmem(ODR_ENCODE);
+    Z_RPNQuery *rpn;
+    enum pqf2xml_status status = XML_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
+    {
+#if YAZ_HAVE_XML2
+        xmlDocPtr doc = 0;
+
+        yaz_rpnquery2xml(rpn, &doc);
+        
+        if (!doc)
+            status = QUERY2XML_FAILED;
+        else
+        {
+            char *buf_out;
+            int len_out;
+
+            xmlDocDumpMemory(doc, (xmlChar **) &buf_out, &len_out);
+            
+            if (len_out == (int) strlen(expect_xml)
+                && memcmp(buf_out, expect_xml, len_out) == 0)
+            {
+                Z_Query *query2 = 0;
+                int error_code = 0;
+                const char *addinfo = 0;
+                const xmlNode *root_element = xmlDocGetRootElement(doc);
+                ODR odr2 = odr_createmem(ODR_ENCODE);
+                
+                yaz_xml2query(root_element, &query2, odr2,
+                              &error_code, &addinfo);
+                if (error_code || !query2)
+                    status = XML_NO_MATCH;
+                else
+                {
+                    WRBUF w = wrbuf_alloc();
+                    yaz_query_to_wrbuf(w, query2);
+                    if (!expect_pqf || strcmp(expect_pqf, wrbuf_cstr(w)) == 0)
+                        status = XML_MATCH;
+                    else
+                    {
+                        status = XML_NO_MATCH;
+                        printf("Result: %s\n", wrbuf_cstr(w));
+                    }
+                    wrbuf_destroy(w);
+                }
+                odr_destroy(odr2);
+            }
+            else
+            {
+                printf("%.*s\n", len_out, buf_out);
+                status = XML_NO_MATCH;
+            }
+            xmlFreeDoc(doc);
+            xmlFree(buf_out);
+        }
+#else
+        status = QUERY2XML_FAILED;
+#endif
+    }
+    odr_destroy(odr);
+    return status;
+}
+
+static void tst(void)
+{
+    YAZ_CHECK_EQ(pqf2xml_text("@attr 1=4 bad query", "", 0), PQF_FAILED);
+#if YAZ_HAVE_XML2
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@attr 1=4 computer", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt><attr type=\"1\" value=\"4\"/>"
+                     "<term type=\"general\">computer</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @attr 1=4 computer"
+                     ), XML_MATCH);
+    
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@attr 2=1 @attr 1=title computer",
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt><attr type=\"1\" value=\"title\"/>"
+                     "<attr type=\"2\" value=\"1\"/>"
+                     "<term type=\"general\">computer</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @attr \"1=title\" @attr 2=1 computer"
+                     ), XML_MATCH);
+
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@attr 2=1 @attr exp1 1=1 computer",
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt><attr set=\"Exp-1\" type=\"1\" value=\"1\"/>"
+                     "<attr type=\"2\" value=\"1\"/>"
+                     "<term type=\"general\">computer</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @attr Exp-1 1=1 @attr 2=1 computer"
+                     ), XML_MATCH);
+    
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@and a b", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<operator type=\"and\">"
+                     "<apt><term type=\"general\">a</term></apt>"
+                     "<apt><term type=\"general\">b</term></apt>"
+                     "</operator></rpn></query>\n",
+                     "RPN @attrset Bib-1 @and a b"
+                     ), XML_MATCH);
+    
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@or @and a b c", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<operator type=\"or\">"
+                     "<operator type=\"and\">"
+                     "<apt><term type=\"general\">a</term></apt>"
+                     "<apt><term type=\"general\">b</term></apt></operator>"
+                     "<apt><term type=\"general\">c</term></apt>"
+                     "</operator></rpn></query>\n",
+                     "RPN @attrset Bib-1 @or @and a b c"
+                     ), XML_MATCH);
+
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@set abe", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<rset>abe</rset></rpn></query>\n",
+                     "RPN @attrset Bib-1 @set abe"
+                     ), XML_MATCH);
+
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     /* exclusion, distance, ordered, relationtype, 
+                        knownunit, proxunit */
+                     "@prox 0 3 1 2 k 2           a b", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<operator type=\"prox\" exclusion=\"false\" "
+                     "distance=\"3\" "
+                     "ordered=\"true\" "
+                     "relationType=\"2\" "
+                     "knownProximityUnit=\"2\">"
+                     "<apt><term type=\"general\">a</term></apt>"
+                     "<apt><term type=\"general\">b</term></apt>"
+                     "</operator></rpn></query>\n",
+                     "RPN @attrset Bib-1 @prox 0 3 1 2 k 2 a b"
+                     ), XML_MATCH);
+
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@term numeric 32", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt>"
+                     "<term type=\"numeric\">32</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @term numeric 32"
+                     ), XML_MATCH);
+    
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@term string computer", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt>"
+                     "<term type=\"string\">computer</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @term string computer"
+                     ), XML_MATCH);
+    
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@term null void", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"Bib-1\">"
+                     "<apt>"
+                     "<term type=\"null\"/></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset Bib-1 @term null x"
+                     ), XML_MATCH);
+
+    YAZ_CHECK_EQ(pqf2xml_text(
+                     "@attrset gils @attr 4=2 x", 
+                     "<?xml version=\"1.0\"?>\n"
+                     "<query><rpn set=\"GILS\">"
+                     "<apt>"
+                     "<attr type=\"4\" value=\"2\"/>"
+                     "<term type=\"general\">x</term></apt>"
+                     "</rpn></query>\n",
+                     "RPN @attrset GILS @attr 4=2 x"
+                     ), XML_MATCH);
+#endif
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    tst();
+    YAZ_CHECK_TERM;
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
diff --git a/test/tst_comstack.c b/test/tst_comstack.c
deleted file mode 100644 (file)
index eee72f8..0000000
+++ /dev/null
@@ -1,268 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <yaz/test.h>
-#include <yaz/comstack.h>
-#include <yaz/tcpip.h>
-
-static void tst_http_request(void)
-{
-    {
-        /* no content, no headers */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\r\n"
-            "\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 16), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 17), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 18), 18);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 19), 18);
-    }
-    {
-        /* one header, no content */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\r\n"
-            "Content-Type: x\r\n"
-            "\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 34), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 35);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 36), 35);
-    }        
-    {
-        /* one content-length header, length 0 */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\r\n"
-            "Content-Length: 0\r\n"
-            "\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 35), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 37), 37);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 37);
-    }        
-    {
-        /* one content-length header, length 5 */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\r\n"
-            "Content-Length: 5\r\n"
-            "\r\n"
-            "ABCDE"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 42);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 43), 42);
-    }        
-    {
-        /* LF only in GET, one content-length header, length 5 */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\n"
-            "Content-Length: 5\r\n"
-            "\r\n"
-            "ABCDE"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 41);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 42), 41);
-    }        
-    {
-        /* LF only in all places, one content-length header, length 5 */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "GET / HTTP/1.1\n"
-            "Content-Length: 5\n"
-            "\n"
-            "ABCDE"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 38), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 39);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 39);
-    }        
-
-    {
-        /* one header, unknown transfer-encoding (no content) */
-        const char *http_buf = 
-            /*12345678901234567890123456789 */
-            "GET / HTTP/1.1\r\n"
-            "Transfer-Encoding: chunke_\r\n"
-            "\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 45), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 46), 46);
-    }        
-
-    {
-        /* one header, one chunk */
-        const char *http_buf = 
-            /*12345678901234567890123456789 */
-            "GET / HTTP/1.1\r\n"
-            "Transfer-Encoding: chunked\r\n"
-            "\r\n"
-            "3\r\n"
-            "123\r\n"
-            "0\r\n\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 58), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 59), 59);
-    }        
-
-    {
-        /* one header, two chunks */
-        const char *http_buf = 
-            /*12345678901234567890123456789 */
-            "GET / HTTP/1.1\r\n"
-            "Transfer-Encoding: chunked\r\n"
-            "\r\n"
-            "3\r\n"
-            "123\r\n"
-            "2\r\n"
-            "12\n"
-            "0\r\n\r\n"
-            "GET / HTTP/1.0\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 64), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 65), 65);
-    }        
-}
-
-static void tst_http_response(void)
-{
-    {
-        /* unlimited content, no headers */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "HTTP/1.1 200 OK\r\n"
-            "\r\n"
-            "HTTP/1.1 200 OK\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 24), 0);
-    }
-    {
-        /* response, content  */
-        const char *http_buf = 
-            /*123456789012345678 */
-            "HTTP/1.1 200 OK\r\n"
-            "Content-Length: 2\r\n"
-            "\r\n"
-            "12"
-            "HTTP/1.1 200 OK\r\n";
-        
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 1), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 2), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 39), 0);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 40), 40);
-        YAZ_CHECK_EQ(cs_complete_auto(http_buf, 41), 40);
-    }
-}
-
-/** \brief COMSTACK synopsis from manual, doc/comstack.xml */
-static int comstack_example(const char *server_address_str)
-{    
-    COMSTACK stack;
-    char *buf = 0;
-    int size = 0, length_incoming;
-    void *server_address_ip;
-    int status;
-
-    char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
-    int protocol_package_length = strlen(protocol_package);
-
-    stack = cs_create(tcpip_type, 1, PROTO_HTTP);
-    if (!stack) {
-        perror("cs_create");  /* use perror() here since we have no stack yet */
-        return -1;
-    }
-    
-    server_address_ip = cs_straddr(stack, server_address_str);
-    if (!server_address_ip)
-    {
-        fprintf(stderr, "cs_straddr: address could not be resolved\n");
-        return -1;
-    }
-    
-    status = cs_connect(stack, server_address_ip);
-    if (status != 0) {
-        fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
-        return -1;
-    }
-    
-    status = cs_put(stack, protocol_package, protocol_package_length);
-    if (status) {
-        fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
-        return -1;
-    }
-    
-    /* Now get a response */
-    
-    length_incoming = cs_get(stack, &buf, &size);
-    if (!length_incoming) {
-        fprintf(stderr, "Connection closed\n");
-        return -1;
-    } else if (length_incoming < 0) {
-        fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
-        return -1;
-    }
-    
-    /* Print result */
-    fwrite(buf, length_incoming, 1, stdout);
-    
-    /* clean up */
-    cs_close(stack);
-    if (buf)
-        free(buf);
-    return 0;
-}
-
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    if (argc == 2)
-       comstack_example(argv[1]);
-    tst_http_request();
-    tst_http_response();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_file_glob.c b/test/tst_file_glob.c
deleted file mode 100644 (file)
index 8cfc3c3..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#include <yaz/file_glob.h>
-#include <yaz/test.h>
-#include <yaz/log.h>
-#include <yaz/wrbuf.h>
-
-void tst_with_path(const char *tpath)
-{
-    yaz_glob_res_t glob_res;
-    int ret = yaz_file_glob(tpath, &glob_res);
-    if (ret == 0)
-    {
-        size_t n = yaz_file_glob_get_num(glob_res);
-        size_t i;
-        for (i = 0; i < n; i++)
-        {
-            yaz_log(YLOG_LOG, "match %s", yaz_file_glob_get_file(glob_res, i));
-        }
-    }
-    yaz_file_globfree(&glob_res);
-}
-
-void tst(void)
-{
-    yaz_glob_res_t glob_res;
-    int ret;
-    WRBUF tpath = wrbuf_alloc();
-    const char *srcdir = getenv("srcdir");
-    
-    if (srcdir)
-    {
-        wrbuf_puts(tpath, srcdir);
-        wrbuf_puts(tpath, "/");
-    }
-    wrbuf_puts(tpath, "Make*.am");
-    ret = yaz_file_glob(wrbuf_cstr(tpath), &glob_res);
-    YAZ_CHECK_EQ(ret, 0);
-
-    YAZ_CHECK_EQ(1, yaz_file_glob_get_num(glob_res));
-    if (yaz_file_glob_get_num(glob_res) == 1)
-    {
-        const char *f = yaz_file_glob_get_file(glob_res, 0);
-        size_t l_match = strlen("Makefile.am");
-        YAZ_CHECK(f && strlen(f) >= l_match);
-        if (f && strlen(f) >= l_match)
-        {
-            YAZ_CHECK(!strcmp(f + strlen(f) - l_match, "Makefile.am"));
-        }
-    }
-    wrbuf_destroy(tpath);
-    yaz_file_globfree(&glob_res);
-}
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    if (argc >= 2)
-        tst_with_path(argv[1]);
-    else
-        tst();
-    YAZ_CHECK_TERM;
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_filepath.c b/test/tst_filepath.c
deleted file mode 100644 (file)
index 8abf045..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#include <yaz/tpath.h>
-#include <yaz/test.h>
-
-void tst(void)
-{
-    char fullpath[1024];
-    YAZ_CHECK(yaz_filepath_resolve("tst_filepath", ".", 0, fullpath));
-    YAZ_CHECK(strcmp(fullpath, "./tst_filepath") == 0);
-    YAZ_CHECK(!yaz_filepath_resolve("tst_filepath1", ".", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("tst_filepath", "bogus", 0, fullpath));
-    YAZ_CHECK(yaz_filepath_resolve("tst_filepath", "bogus:.", 0, fullpath));
-}
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    tst();
-    YAZ_CHECK_TERM;
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_icu_I18N.c b/test/tst_icu_I18N.c
deleted file mode 100644 (file)
index 2ad005c..0000000
+++ /dev/null
@@ -1,824 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define USE_TIMING 0
-#if USE_TIMING
-#include <yaz/timing.h>
-#endif
-
-#include <yaz/test.h>
-#include <yaz/log.h>
-#include <yaz/wrbuf.h>
-
-#if YAZ_HAVE_ICU
-#include <yaz/icu_I18N.h>
-
-#if YAZ_POSIX_THREADS
-#include <pthread.h>
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-
-#define MAX_KEY_SIZE 256
-struct icu_termmap
-{
-    uint8_t sort_key[MAX_KEY_SIZE]; /* standard C string '\0' terminated */
-    char disp_term[MAX_KEY_SIZE];  /* standard C utf-8 string */
-};
-
-
-static int icu_termmap_cmp(const void *vp1, const void *vp2)
-{
-    struct icu_termmap *itmp1 = *(struct icu_termmap **) vp1;
-    struct icu_termmap *itmp2 = *(struct icu_termmap **) vp2;
-
-    int cmp = 0;
-    
-    cmp = strcmp((const char *)itmp1->sort_key, 
-                 (const char *)itmp2->sort_key);
-    return cmp;
-}
-
-
-static int test_icu_casemap(const char * locale, char action,
-                            const char * src8cstr, const char * chk8cstr)
-{
-    int success = 0;
-    UErrorCode status = U_ZERO_ERROR;
-
-    struct icu_buf_utf8 * src8 = icu_buf_utf8_create(0);
-    struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
-    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
-    struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
-
-
-    int src8cstr_len = strlen(src8cstr);
-    int chk8cstr_len = strlen(chk8cstr);
-
-    /* converting to UTF16 */
-    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
-
-    /* perform case mapping */
-    icu_utf16_casemap(dest16, src16, locale, action, &status);
-  
-    /* converting to UTF8 */
-    icu_utf16_to_utf8(dest8, dest16, &status);
-
-    /* determine success */
-    if (dest8->utf8 
-        && (dest8->utf8_len == strlen(chk8cstr))
-        && !strcmp(chk8cstr, (const char *) dest8->utf8))
-        success = 1;
-    else
-        success = 0;
-
-    /* report failures */
-    if (!success)
-    {
-        yaz_log(YLOG_WARN, "test_icu_casemap failed");
-        yaz_log(YLOG_LOG, "Original string:   '%s' (%d)",
-                src8cstr, src8cstr_len);
-        yaz_log(YLOG_LOG, "icu_casemap '%s:%c' '%s' (%d)", 
-                locale, action, dest8->utf8, dest8->utf8_len);
-        yaz_log(YLOG_LOG, "expected string:   '%s' (%d)",
-                chk8cstr, chk8cstr_len);
-    }
-  
-    /* clean the buffers */
-    icu_buf_utf8_destroy(src8);
-    icu_buf_utf8_destroy(dest8);
-    icu_buf_utf16_destroy(src16);
-    icu_buf_utf16_destroy(dest16);
-    
-    return success;
-}
-
-static void check_icu_casemap(void)
-{
-    /* Locale 'en' */
-
-    /* successful tests */
-    YAZ_CHECK(test_icu_casemap("en", 'l',
-                               "A ReD fOx hunTS sQUirriLs", 
-                               "a red fox hunts squirrils"));
-    
-    YAZ_CHECK(test_icu_casemap("en", 'u',
-                               "A ReD fOx hunTS sQUirriLs", 
-                               "A RED FOX HUNTS SQUIRRILS"));
-    
-    YAZ_CHECK(test_icu_casemap("en", 'f',
-                               "A ReD fOx hunTS sQUirriLs", 
-                               "a red fox hunts squirrils"));
-    
-    YAZ_CHECK(test_icu_casemap("en", 't',
-                               "A ReD fOx hunTS sQUirriLs", 
-                               "A Red Fox Hunts Squirrils"));
-    
-    /* Locale 'da' */
-
-    /* success expected */
-    YAZ_CHECK(test_icu_casemap("da", 'l',
-                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
-                               "åh æble, øs fløde i åen efter blåbærgrøden"));
-
-    YAZ_CHECK(test_icu_casemap("da", 'u',
-                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
-                               "ÅH ÆBLE, ØS FLØDE I ÅEN EFTER BLÅBÆRGRØDEN"));
-
-    YAZ_CHECK(test_icu_casemap("da", 'f',
-                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
-                               "åh æble, øs fløde i åen efter blåbærgrøden"));
-
-    YAZ_CHECK(test_icu_casemap("da", 't',
-                               "åh ÆbLE, øs fLØde i Åen efter bLåBærGRødeN", 
-                               "Åh Æble, Øs Fløde I Åen Efter Blåbærgrøden"));
-
-    /* Locale 'de' */
-
-    /* success expected */
-    YAZ_CHECK(test_icu_casemap("de", 'l',
-                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                               "zwölf ärgerliche würste rollen über die straße"));
-
-    YAZ_CHECK(test_icu_casemap("de", 'u',
-                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                               "ZWÖLF ÄRGERLICHE WÜRSTE ROLLEN ÜBER DIE STRASSE"));
-
-    YAZ_CHECK(test_icu_casemap("de", 'f',
-                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                               "zwölf ärgerliche würste rollen über die strasse"));
-
-    YAZ_CHECK(test_icu_casemap("de", 't',
-                               "zWÖlf ärgerliche Würste rollen ÜBer die StRAße",
-                               "Zwölf Ärgerliche Würste Rollen Über Die Straße"));
-
-}
-
-static int test_icu_sortmap(const char * locale, int src_list_len,
-                            const char ** src_list, const char ** chk_list)
-{
-    int success = 1;
-
-    UErrorCode status = U_ZERO_ERROR;
-
-    struct icu_buf_utf8 * buf8 = icu_buf_utf8_create(0);
-    struct icu_buf_utf16 * buf16 = icu_buf_utf16_create(0);
-
-    int i;
-
-    struct icu_termmap * list[src_list_len];
-
-    UCollator *coll = ucol_open(locale, &status); 
-    icu_check_status(status);
-
-    if (U_FAILURE(status))
-        return 0;
-
-    /* assigning display terms and sort keys using buf 8 and buf16 */
-    for (i = 0; i < src_list_len; i++) 
-    {
-
-        list[i] = (struct icu_termmap *) malloc(sizeof(struct icu_termmap));
-
-        /* copy display term */
-        strcpy(list[i]->disp_term, src_list[i]);    
-
-        /* transforming to UTF16 */
-        icu_utf16_from_utf8_cstr(buf16, list[i]->disp_term, &status);
-        icu_check_status(status);
-
-        /* computing sortkeys */
-        icu_sortkey8_from_utf16(coll, buf8, buf16, &status);
-        icu_check_status(status);
-    
-        /* assigning sortkeys */
-        memcpy(list[i]->sort_key, buf8->utf8, buf8->utf8_len);    
-    } 
-
-    /* do the sorting */
-    qsort(list, src_list_len, sizeof(struct icu_termmap *), icu_termmap_cmp);
-
-    /* checking correct sorting */
-    for (i = 0; i < src_list_len; i++)
-    {
-        if (0 != strcmp(list[i]->disp_term, chk_list[i])){
-            success = 0;
-        }
-    }
-
-    if (!success)
-    {
-        yaz_log(YLOG_LOG, "ERROR"); 
-        yaz_log(YLOG_LOG, "Input str:'%s':", locale); 
-        for (i = 0; i < src_list_len; i++) {
-            yaz_log(YLOG_LOG, "  '%s'", list[i]->disp_term); 
-        }
-        yaz_log(YLOG_LOG, "ICU sort: '%s':", locale); 
-        for (i = 0; i < src_list_len; i++) {
-            yaz_log(YLOG_LOG, " '%s'", list[i]->disp_term); 
-        }
-        yaz_log(YLOG_LOG, "Expected: '%s':", locale); 
-        for (i = 0; i < src_list_len; i++) {
-            yaz_log(YLOG_LOG, " '%s'", chk_list[i]); 
-        }
-    }
-  
-    for (i = 0; i < src_list_len; i++)
-        free(list[i]);
-   
-    ucol_close(coll);
-
-    icu_buf_utf8_destroy(buf8);
-    icu_buf_utf16_destroy(buf16);
-
-    return success;  
-}
-
-static void check_icu_sortmap(void)
-{
-    /* successful tests */
-    size_t en_1_len = 6;
-    const char * en_1_src[6] = {"z", "K", "a", "A", "Z", "k"};
-    const char * en_1_cck[6] = {"a", "A", "k", "K", "z", "Z"};
-    YAZ_CHECK(test_icu_sortmap("en", en_1_len, en_1_src, en_1_cck));
-    YAZ_CHECK(test_icu_sortmap("en_AU", en_1_len, en_1_src, en_1_cck));
-    YAZ_CHECK(test_icu_sortmap("en_CA", en_1_len, en_1_src, en_1_cck));
-    YAZ_CHECK(test_icu_sortmap("en_GB", en_1_len, en_1_src, en_1_cck));
-    YAZ_CHECK(test_icu_sortmap("en_US", en_1_len, en_1_src, en_1_cck));
-    
-    /* successful tests */
-    {
-        size_t da_1_len = 6;
-        const char * da_1_src[6] = {"z", "å", "o", "æ", "a", "ø"};
-        const char * da_1_cck[6] = {"a", "o", "z", "æ", "ø", "å"};
-        YAZ_CHECK(test_icu_sortmap("da", da_1_len, da_1_src, da_1_cck));
-        YAZ_CHECK(test_icu_sortmap("da_DK", da_1_len, da_1_src, da_1_cck));
-    }
-    /* successful tests */
-    {
-        size_t de_1_len = 9;
-        const char * de_1_src[9] = {"u", "ä", "o", "t", "s", "ß", "ü", "ö", "a"};
-        const char * de_1_cck[9] = {"a","ä", "o", "ö", "s", "ß", "t", "u", "ü"};
-        YAZ_CHECK(test_icu_sortmap("de", de_1_len, de_1_src, de_1_cck));
-        YAZ_CHECK(test_icu_sortmap("de_AT", de_1_len, de_1_src, de_1_cck));
-        YAZ_CHECK(test_icu_sortmap("de_DE", de_1_len, de_1_src, de_1_cck));
-    }
-}
-
-static int test_icu_normalizer(const char * rules8cstr,
-                               const char * src8cstr,
-                               const char * chk8cstr)
-{
-    int success = 0;
-    
-    UErrorCode status = U_ZERO_ERROR;
-
-    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
-    struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
-    struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
-    struct icu_transform * transform
-        = icu_transform_create(rules8cstr, 'f', 0, &status);
-    icu_check_status(status);
-    
-    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
-    icu_check_status(status);
-
-    icu_transform_trans(transform, dest16, src16, &status);
-    icu_check_status(status);
-
-    icu_utf16_to_utf8(dest8, dest16, &status);
-    icu_check_status(status);
-
-
-    if (!strcmp((const char *) dest8->utf8, 
-               (const char *) chk8cstr))
-        success = 1;
-    else
-    {
-        success = 0;
-        yaz_log(YLOG_LOG, "Normalization");
-        yaz_log(YLOG_LOG, " Rules:      '%s'", rules8cstr);
-        yaz_log(YLOG_LOG, " Input:      '%s'", src8cstr);
-        yaz_log(YLOG_LOG, " Normalized: '%s'", dest8->utf8);
-        yaz_log(YLOG_LOG, " Expected:   '%s'", chk8cstr);
-    }
-
-    icu_transform_destroy(transform);
-    icu_buf_utf16_destroy(src16);
-    icu_buf_utf16_destroy(dest16);
-    icu_buf_utf8_destroy(dest8);
-
-    return success;
-}
-
-static void check_icu_normalizer(void)
-{
-    YAZ_CHECK(test_icu_normalizer("[:Punctuation:] Any-Remove",
-                                  "Don't shoot!",
-                                  "Dont shoot"));
-    
-    YAZ_CHECK(test_icu_normalizer("[:Control:] Any-Remove",
-                                  "Don't\n shoot!",
-                                  "Don't shoot!"));
-
-    YAZ_CHECK(test_icu_normalizer("[:Decimal_Number:] Any-Remove",
-                                  "This is 4 you!",
-                                  "This is  you!"));
-
-    YAZ_CHECK(test_icu_normalizer("Lower; [:^Letter:] Remove",
-                                  "Don't shoot!",
-                                  "dontshoot"));
-    
-    YAZ_CHECK(test_icu_normalizer("[:^Number:] Remove",
-                                  "Monday 15th of April",
-                                  "15"));
-
-    YAZ_CHECK(test_icu_normalizer("Lower;"
-                                  "[[:WhiteSpace:][:Punctuation:]] Remove",
-                                  " word4you? ",
-                                  "word4you"));
-
-    YAZ_CHECK(test_icu_normalizer("NFD; [:Nonspacing Mark:] Remove; NFC",
-                                  "à côté de l'alcôve ovoïde",
-                                  "a cote de l'alcove ovoide"));
-}
-
-static int test_icu_tokenizer(const char * locale, char action,
-                              const char * src8cstr, int count)
-{
-    int success = 1;
-
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
-    struct icu_buf_utf16 * tkn16 = icu_buf_utf16_create(0);
-    struct icu_buf_utf8 * tkn8 = icu_buf_utf8_create(0);
-    struct icu_tokenizer * tokenizer = 0;
-
-    /* transforming to UTF16 */
-    icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
-    icu_check_status(status);
-
-    /* set up tokenizer */
-    tokenizer = icu_tokenizer_create(locale, action, &status);
-    icu_check_status(status);
-    YAZ_CHECK(tokenizer);
-
-    /* attach text buffer to tokenizer */
-    icu_tokenizer_attach(tokenizer, src16, &status);    
-    icu_check_status(status);
-
-    /* perform work on tokens */
-    while (icu_tokenizer_next_token(tokenizer, tkn16, &status))
-    {
-        icu_check_status(status);
-
-        /* converting to UTF8 */
-        icu_utf16_to_utf8(tkn8, tkn16, &status);
-    }
-
-    if (count != icu_tokenizer_token_count(tokenizer))
-    {
-        success = 0;
-        yaz_log(YLOG_LOG, "Tokenizer '%s:%c' Error:", locale, action);
-        yaz_log(YLOG_LOG, " Input:  '%s'", src8cstr);
-        yaz_log(YLOG_LOG, " Tokens: %d", icu_tokenizer_token_count(tokenizer));
-        yaz_log(YLOG_LOG, " Expected: %d", count);
-    }
-
-    icu_tokenizer_destroy(tokenizer);
-    icu_buf_utf16_destroy(src16);
-    icu_buf_utf16_destroy(tkn16);
-    icu_buf_utf8_destroy(tkn8);
-        
-    return success;
-}
-
-static void check_icu_tokenizer(void)
-{
-    const char * en_str 
-        = "O Romeo, Romeo! wherefore art thou Romeo?";
-    
-    YAZ_CHECK(test_icu_tokenizer("en", 's', en_str, 2));
-    YAZ_CHECK(test_icu_tokenizer("en", 'l', en_str, 7));
-    YAZ_CHECK(test_icu_tokenizer("en", 'w', en_str, 16));
-    YAZ_CHECK(test_icu_tokenizer("en", 'c', en_str, 41));
-
-    {
-        const char * da_str 
-            = "Blåbærtærte. Denne kage stammer fra Finland. "
-            "Den er med blåbær, men alle sommerens forskellige bær kan bruges.";
-        
-        YAZ_CHECK(test_icu_tokenizer("da", 's', da_str, 3));
-        YAZ_CHECK(test_icu_tokenizer("dar", 'l', da_str, 17));
-        YAZ_CHECK(test_icu_tokenizer("da", 'w', da_str, 37));
-        YAZ_CHECK(test_icu_tokenizer("da", 'c', da_str, 110));
-    }
-}
-
-static void check_icu_chain(void)
-{
-    const char * en_str 
-        = "O Romeo, Romeo! wherefore art thou\t Romeo?";
-
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-    
-    const char * xml_str = "<icu locale=\"en\">"
-        "<transform rule=\"[:Control:] Any-Remove\"/>"
-        "<tokenize rule=\"l\"/>"
-        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
-        "<display/>"
-        "<casemap rule=\"l\"/>"
-        "</icu>";
-
-    
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    xmlNode *xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-
-    YAZ_CHECK(icu_chain_assign_cstr(chain, en_str, &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        yaz_log(YLOG_LOG, "%d '%s' '%s'",
-                icu_chain_token_number(chain),
-                icu_chain_token_norm(chain),
-                icu_chain_token_display(chain));
-    }
-
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
-
-
-    YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        yaz_log(YLOG_LOG, "%d '%s' '%s'",
-                icu_chain_token_number(chain),
-                icu_chain_token_norm(chain),
-                icu_chain_token_display(chain));
-    }
-
-
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
-
-    icu_chain_destroy(chain);
-}
-
-
-static void check_bug_1140(void)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-    
-    const char * xml_str = "<icu locale=\"en\">"
-
-        /* if the first rule is normalize instead. Then it works */
-#if 0
-        "<transform rule=\"[:Control:] Any-Remove\"/>"
-#endif
-        "<tokenize rule=\"l\"/>"
-        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
-        "<display/>"
-        "<casemap rule=\"l\"/>"
-        "</icu>";
-
-    
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    xmlNode *xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-    
-    YAZ_CHECK(icu_chain_assign_cstr(
-                  chain,  "O Romeo, Romeo! wherefore art thou\t Romeo?",
-                  &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
-    }
-    
-
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
-
-    YAZ_CHECK(icu_chain_assign_cstr(chain, "what is this?", &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
-    }
-
-    /* we expect 'what' 'is' 'this', i.e. 3 tokens */
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 3);
-
-    icu_chain_destroy(chain);
-}
-
-
-static void check_chain_empty_token(void)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-
-    const char * xml_str = "<icu locale=\"en\">"
-        "<tokenize rule=\"w\"/>"
-        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
-        "</icu>";
-    
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    xmlNode *xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-    
-    YAZ_CHECK(icu_chain_assign_cstr(
-                  chain,  "a string with 15 tokenss and 8 displays",
-                  &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
-    }
-
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 15);
-
-    icu_chain_destroy(chain);
-}
-
-static void check_chain_empty_chain(void)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-
-    const char * xml_str = "<icu locale=\"en\">"
-        "</icu>";
-    
-    const char * src8 = "some 5487 weired !¤%&(/& sTuFf";
-    char * dest8 = 0;
-
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    xmlNode *xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-    
-    YAZ_CHECK(icu_chain_assign_cstr(
-                  chain,  src8,
-                  &status));
-
-    while (icu_chain_next_token(chain, &status))
-    {
-        ;
-        /* printf("%d '%s' '%s'\n",
-           icu_chain_token_number(chain),
-           icu_chain_token_norm(chain),
-           icu_chain_token_display(chain)); */
-    }
-
-    YAZ_CHECK_EQ(icu_chain_token_number(chain), 1);
-
-    dest8 = (char *) icu_chain_token_norm(chain);
-    YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
-    
-    icu_chain_destroy(chain);
-}
-
-static void check_icu_iter1(void)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-    xmlNode *xml_node;
-    yaz_icu_iter_t iter;
-
-    const char * xml_str = "<icu locale=\"en\">"
-        "<tokenize rule=\"w\"/>"
-        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
-        "</icu>";
-    
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    YAZ_CHECK(doc);
-    if (!doc)
-        return;
-    xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-    if (!xml_node)
-        return ;
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-    
-    iter = icu_iter_create(chain);
-    icu_iter_first(iter, "a string with 15 tokens and 8 displays");
-    YAZ_CHECK(iter);
-    if (!iter)
-        return;
-    while (icu_iter_next(iter))
-    {
-        yaz_log(YLOG_LOG, "[%s]", icu_iter_get_norm(iter));
-    }
-    icu_iter_destroy(iter);
-    icu_chain_destroy(chain);
-}
-
-static int test_iter(struct icu_chain *chain, const char *input,
-                     const char *expected)
-{
-    yaz_icu_iter_t iter = icu_iter_create(chain);
-    WRBUF result, second;
-    int success = 1;
-
-    if (!iter)
-    {
-        yaz_log(YLOG_WARN, "test_iter: input=%s !iter", input);
-        return 0;
-    }
-
-    if (icu_iter_next(iter))
-    {
-        yaz_log(YLOG_WARN, "test_iter: expecting 0 before icu_iter_first");
-        return 0;
-    }
-
-    result = wrbuf_alloc();
-    icu_iter_first(iter, input);
-    while (icu_iter_next(iter))
-    {
-        wrbuf_puts(result, "[");
-        wrbuf_puts(result, icu_iter_get_norm(iter));
-        wrbuf_puts(result, "]");
-    }
-
-    second = wrbuf_alloc();
-    icu_iter_first(iter, input);
-    while (icu_iter_next(iter))
-    {
-        wrbuf_puts(second, "[");
-        wrbuf_puts(second, icu_iter_get_norm(iter));
-        wrbuf_puts(second, "]");
-    }
-
-    icu_iter_destroy(iter);
-
-    if (strcmp(expected, wrbuf_cstr(result)))
-    {
-        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s",
-                input, expected, wrbuf_cstr(result));
-        success = 0;
-    }
-
-    if (strcmp(expected, wrbuf_cstr(second)))
-    {
-        yaz_log(YLOG_WARN, "test_iter: input=%s expected=%s got=%s (2nd)",
-                input, expected, wrbuf_cstr(second));
-        success = 0;
-    }
-
-    wrbuf_destroy(result);
-    wrbuf_destroy(second);
-    return success;
-}
-
-static void *iter_thread(void *p)
-{
-    struct icu_chain *chain = (struct icu_chain *) p;
-    int i;
-    
-    for (i = 0; i < 10000; i++)
-    {
-        YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
-                            "[adobe][acrobat][reader][1991][][1999][]"));
-    }
-    return 0;
-}
-
-static void check_iter_threads(struct icu_chain *chain)
-{
-#if YAZ_POSIX_THREADS
-#define NO_THREADS 1
-
-    pthread_t t[NO_THREADS];
-    int i;
-
-    for (i = 0; i < NO_THREADS; i++)
-        pthread_create(t + i, 0, iter_thread, chain);
-
-    for (i = 0; i < NO_THREADS; i++)
-        pthread_join(t[i], 0);
-#endif
-}
-static void check_icu_iter2(void)
-{
-    UErrorCode status = U_ZERO_ERROR;
-    struct icu_chain * chain = 0;
-    xmlNode *xml_node;
-
-    const char * xml_str = "<icu locale=\"en\">"
-        "<transform rule=\"[:Control:] Any-Remove\"/>"
-        "<tokenize rule=\"l\"/>"
-        "<tokenize rule=\"w\"/>"
-        "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
-        "<display/>"
-        "<casemap rule=\"l\"/>"
-        "</icu>";
-
-    xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
-    YAZ_CHECK(doc);
-    if (!doc)
-        return;
-    xml_node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(xml_node);
-    if (!xml_node)
-        return ;
-
-    chain = icu_chain_xml_config(xml_node, 0, &status);
-
-    xmlFreeDoc(doc);
-    YAZ_CHECK(chain);
-    
-    YAZ_CHECK(test_iter(chain, "Adobe Acrobat Reader, 1991-1999.",
-                        "[adobe][acrobat][reader][1991][][1999][]"));
-
-    check_iter_threads(chain);
-
-    icu_chain_destroy(chain);
-}
-
-#endif /* YAZ_HAVE_ICU */
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv); 
-    YAZ_CHECK_LOG();
-
-#if YAZ_HAVE_ICU
-
-    check_icu_casemap();
-    check_icu_sortmap();
-    check_icu_normalizer();
-    check_icu_tokenizer();
-    check_icu_chain();
-    check_chain_empty_token();
-    check_chain_empty_chain();
-    check_icu_iter1();
-    check_icu_iter2();
-    
-    check_bug_1140();
-
-#else /* YAZ_HAVE_ICU */
-
-    yaz_log(YLOG_LOG, "ICU unit tests omitted");
-    YAZ_CHECK(0 == 0);
-
-#endif /* YAZ_HAVE_ICU */
-   
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_json.c b/test/tst_json.c
deleted file mode 100644 (file)
index eace27e..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-/**
- * \file 
- * \brief JSON test
- */
-#include <yaz/test.h>
-#include <yaz/json.h>
-#include <string.h>
-#include <yaz/log.h>
-
-static int expect(json_parser_t p, const char *input, 
-                  const char *output)
-{
-    int ret = 0;
-    struct json_node *n;
-
-    n = json_parser_parse(p, input);
-    if (n == 0 && output == 0)
-        ret = 1;
-    else if (n && output)
-    {
-        WRBUF result = wrbuf_alloc();
-
-        json_write_wrbuf(n, result);
-        if (strcmp(wrbuf_cstr(result), output) == 0)
-            ret = 1;
-        else
-        {
-            yaz_log(YLOG_WARN, "expected '%s' but got '%s'",
-                    output, wrbuf_cstr(result));
-        }
-        wrbuf_destroy(result);
-    }
-    else if (!n)
-    {
-        yaz_log(YLOG_WARN, "expected '%s' but got error '%s'",
-                output, json_parser_get_errmsg(p));
-    }
-    json_remove_node(n);
-    return ret;
-}
-
-static void tst1(void)
-{
-    json_parser_t p = json_parser_create();
-
-    YAZ_CHECK(p);
-    if (!p)
-        return;
-
-    YAZ_CHECK(expect(p, "", 0));
-
-    YAZ_CHECK(expect(p, "1234", "1234"));
-
-    YAZ_CHECK(expect(p, "[ 1234 ]", "[1234]"));
-
-    YAZ_CHECK(expect(p, "{\"k\":tru}", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":null", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":nullx}", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":-", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":+", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"a}", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"a", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"", 0));
-
-    YAZ_CHECK(expect(p, "{", 0));
-
-    YAZ_CHECK(expect(p, "{}", "{}"));
-
-    YAZ_CHECK(expect(p, "{}  extra", 0));
-
-    YAZ_CHECK(expect(p, "{\"a\":[1,2,3}", 0));
-    
-    YAZ_CHECK(expect(p, "{\"a\":[1,2,", 0));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"wa\"}", "{\"k\":\"wa\"}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":null}", "{\"k\":null}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":false}", "{\"k\":false}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":true}", "{\"k\":true}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":12}", "{\"k\":12}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":-12}", "{\"k\":-12}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":1.2e6}", "{\"k\":1.2e+06}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":1e3}", "{\"k\":1000}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"\"}", "{\"k\":\"\"}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":1,\"b\":2}", "{\"a\":1,\"b\":2}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":1,\"b\":2,\"c\":3}",
-                     "{\"a\":1,\"b\":2,\"c\":3}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":[]}", "{\"a\":[]}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":[1]}", "{\"a\":[1]}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":[1,2]}", "{\"a\":[1,2]}"));
-
-    YAZ_CHECK(expect(p, "{\"a\":[1,2,3]}", "{\"a\":[1,2,3]}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"\\t\"}", "{\"k\":\"\x09\"}"));
-
-    YAZ_CHECK(expect(p, "{\"k\":\"\\u0009\"}", "{\"k\":\"\x09\"}"));
-
-    json_parser_destroy(p);
-}
-
-static void tst2(void)
-{
-    struct json_node *n, *n1;
-
-    n = json_parse("{\"a\":1,\"b\":2,\"c\":[true,false,null]}", 0);
-    YAZ_CHECK(n);
-    if (!n)
-        return;
-
-    YAZ_CHECK_EQ(json_count_children(n), 3);
-    
-    n1 = json_get_object(n, "a");
-    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 1.0);
-    YAZ_CHECK_EQ(json_count_children(n1), 0);
-
-    n1 = json_get_object(n, "b");
-    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 2.0);
-    YAZ_CHECK_EQ(json_count_children(n1), 0);
-
-    n1 = json_get_object(n, "b");
-    YAZ_CHECK(n1 && n1->type == json_node_number && n1->u.number == 2.0);
-    YAZ_CHECK_EQ(json_count_children(n1), 0);
-
-    n1 = json_get_object(n, "c");
-    YAZ_CHECK(n1 && n1->type == json_node_array);
-    YAZ_CHECK_EQ(json_count_children(n1), 3);
-
-    n1 = json_get_elem(json_get_object(n, "c"), 0);
-    YAZ_CHECK(n1 && n1->type == json_node_true);
-
-    n1 = json_get_elem(json_get_object(n, "c"), 1);
-    YAZ_CHECK(n1 && n1->type == json_node_false);
-
-    n1 = json_get_elem(json_get_object(n, "c"), 2);
-    YAZ_CHECK(n1 && n1->type == json_node_null);
-
-    n1 = json_get_elem(json_get_object(n, "c"), 3);
-    YAZ_CHECK(n1 == 0);
-
-    json_remove_node(n);
-}
-
-static int append_check(const char *a, const char *b, const char *exp)
-{
-    WRBUF w = wrbuf_alloc();
-    struct json_node *n_a, *n_b;
-    int ret = 0;
-
-    n_a = json_parse(a, 0);
-    n_b = json_parse(b, 0);
-    json_append_array(json_get_object(n_a, "a"),
-                      json_detach_object(n_b, "b"));
-
-    json_write_wrbuf(n_a, w);
-
-    if (!strcmp(wrbuf_cstr(w), exp))
-        ret = 1;
-    wrbuf_destroy(w);
-    json_remove_node(n_a);
-    json_remove_node(n_b);
-    return ret;
-}
-
-static void tst3(void)
-{
-    YAZ_CHECK(append_check("{\"a\":[1,2,3]}", "{\"b\":[5,6,7]}",
-                           "{\"a\":[1,2,3,5,6,7]}"));
-
-    YAZ_CHECK(append_check("{\"a\":[]}", "{\"b\":[5,6,7]}",
-                           "{\"a\":[5,6,7]}"));
-
-    YAZ_CHECK(append_check("{\"a\":[1,2,3]}", "{\"b\":[]}",
-                           "{\"a\":[1,2,3]}"));
-}
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    tst1();
-    tst2();
-    tst3();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
-
diff --git a/test/tst_match_glob.c b/test/tst_match_glob.c
deleted file mode 100644 (file)
index 8421752..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <yaz/test.h>
-#include <yaz/match_glob.h>
-#include <stdlib.h>
-#include <string.h>
-
-void tst1(void)
-{
-    YAZ_CHECK_EQ(yaz_match_glob("a", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("", ""), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("a", ""), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("", "a"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("a", "b"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("b", "a"), 0);
-
-    YAZ_CHECK_EQ(yaz_match_glob("?", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("a", "?"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("?", "aa"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("?a", "aa"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("a?", "aa"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("??", "aa"), 1);
-
-    YAZ_CHECK_EQ(yaz_match_glob("*", ""), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("*", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("**", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("*a", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("a*", "a"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("b*", "a"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("*b", "a"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("**b", "a"), 0);
-    YAZ_CHECK_EQ(yaz_match_glob("*b*", "a"), 0);
-
-    YAZ_CHECK_EQ(yaz_match_glob("*:w", "title:w"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("title:w", "title:w"), 1);
-    YAZ_CHECK_EQ(yaz_match_glob("title:*", "title:w"), 1);
-}
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-
-    tst1();
-
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_oid.c b/test/tst_oid.c
deleted file mode 100644 (file)
index d00c23a..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <yaz/test.h>
-#include <yaz/log.h>
-#include <yaz/oid_db.h>
-
-static void tst(void)
-{
-    char oid_buf[OID_STR_MAX];
-    const char *n;
-    yaz_oid_db_t db;
-    const Odr_oid *c_oid;
-    Odr_oid *oid;
-    NMEM nmem = nmem_create();
-    ODR odr = odr_createmem(ODR_ENCODE);
-
-    db = yaz_oid_std();
-    YAZ_CHECK(db);
-
-    c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "Bib-1");
-    YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
-
-    c_oid = yaz_string_to_oid(db, CLASS_GENERAL, "Bib-1");
-    YAZ_CHECK(c_oid && oid_oidcmp(c_oid, yaz_oid_attset_bib_1) == 0);
-
-    c_oid = yaz_string_to_oid(db, CLASS_ATTSET, "unknown");
-    YAZ_CHECK(c_oid == 0);
-
-    oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "1.2.840.10003.3.1", nmem);
-    YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
-
-    oid = yaz_string_to_oid_nmem(db, CLASS_ATTSET, "unknown", nmem);
-    YAZ_CHECK(oid == 0);
-
-    oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "1.2.840.10003.3.1", odr);
-    YAZ_CHECK(oid && !oid_oidcmp(oid, yaz_oid_attset_bib_1));
-
-    oid = yaz_string_to_oid_odr(db, CLASS_ATTSET, "unknown", odr);
-    YAZ_CHECK(oid == 0);
-
-    n = yaz_oid_to_string(db, yaz_oid_attset_bib_1, 0);
-    YAZ_CHECK(n && !strcmp(n, "Bib-1"));
-
-    n = oid_name_to_dotstring(CLASS_ATTSET, "Bib-1", oid_buf);
-    YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.3.1"));
-
-    n = oid_name_to_dotstring(CLASS_DIAGSET, "Bib-1", oid_buf);
-    YAZ_CHECK(n && !strcmp(n, "1.2.840.10003.4.1"));
-
-    n = oid_name_to_dotstring(CLASS_DIAGSET, "unknown", oid_buf);
-    YAZ_CHECK(!n);
-
-    n = oid_name_to_dotstring(CLASS_DIAGSET, "1.2.840.10003.3.1", oid_buf);
-    YAZ_CHECK(!n);
-
-    nmem_destroy(nmem);
-    odr_destroy(odr);
-}
-
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    tst();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_query_charset.c b/test/tst_query_charset.c
deleted file mode 100644 (file)
index e3c83fc..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <yaz/query-charset.h>
-#include <yaz/copy_types.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();
-        Z_RPNQuery *r2 = yaz_copy_z_RPNQuery(rpn, odr);
-
-        YAZ_CHECK(r2);
-        YAZ_CHECK(r2 != rpn);
-        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
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_record_conv.c b/test/tst_record_conv.c
deleted file mode 100644 (file)
index 33ede53..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-#include <yaz/record_conv.h>
-#include <yaz/test.h>
-#include <yaz/wrbuf.h>
-#include <string.h>
-#include <yaz/log.h>
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if YAZ_HAVE_XML2
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-yaz_record_conv_t conv_configure(const char *xmlstring, WRBUF w)
-{
-    xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
-    if (!doc)
-    {
-        wrbuf_printf(w, "xmlParseMemory");
-        return 0;
-    }
-    else
-    {
-        xmlNodePtr ptr = xmlDocGetRootElement(doc);
-        yaz_record_conv_t p = yaz_record_conv_create();
-
-        if (p)
-        {
-            const char *srcdir = getenv("srcdir");
-            if (srcdir)
-                yaz_record_conv_set_path(p, srcdir);
-        }
-        if (!ptr)
-        {
-            wrbuf_printf(w, "xmlDocGetRootElement");
-            yaz_record_conv_destroy(p);
-            p = 0;
-        }
-        else if (!p)
-        {
-            wrbuf_printf(w, "yaz_record_conv_create");
-        }
-        else
-        {
-
-
-            int r = yaz_record_conv_configure(p, ptr);
-            
-            if (r)
-            {
-                wrbuf_puts(w, yaz_record_conv_get_error(p));
-                yaz_record_conv_destroy(p);
-                p = 0;
-            }
-        }
-        xmlFreeDoc(doc);
-        return p;
-    }    
-}
-
-int conv_configure_test(const char *xmlstring, const char *expect_error,
-                        yaz_record_conv_t *pt)
-{
-    WRBUF w = wrbuf_alloc();
-    int ret;
-
-    yaz_record_conv_t p = conv_configure(xmlstring, w);
-
-    if (!p)
-    {
-        if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
-            ret = 1;
-        else
-        {
-            ret = 0;
-            printf("%s\n", wrbuf_cstr(w));
-        }
-    }
-    else
-    {
-        if (expect_error)
-            ret = 0;
-        else
-            ret = 1;
-    }
-
-    if (pt)
-        *pt = p;
-    else
-        if (p)
-            yaz_record_conv_destroy(p);
-
-    wrbuf_destroy(w);
-    return ret;
-}
-
-static void tst_configure(void)
-{
-
-
-
-    YAZ_CHECK(conv_configure_test("<bad", "xmlParseMemory", 0));
-
-
-    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
-                                  "<bad/></backend>",
-                                  "Element <backend>: expected <marc> or "
-                                  "<xslt> element, got <bad>", 0));
-
-#if YAZ_HAVE_XSLT
-    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"marc-8\""
-                                  " outputcharset=\"marc-8\""
-                                  "/>"
-                                  "</backend>",
-                                  "Element <marc>: attribute 'inputformat' "
-                                  "required", 0));
-    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
-                                  "<xslt/>"
-                                  "</backend>",
-                                  "Element <xslt>: attribute 'stylesheet' "
-                                  "expected", 0));
-    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "</backend>",
-                                  0, 0));
-#else
-    YAZ_CHECK(conv_configure_test("<backend syntax='usmarc' name='F'>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "</backend>",
-                                  "xslt unsupported."
-                                  " YAZ compiled without XSLT support", 0));
-#endif 
-}
-
-static int conv_convert_test(yaz_record_conv_t p,
-                             const char *input_record,
-                             const char *output_expect_record)
-{
-    int ret = 0;
-    if (!p)
-    {
-        YAZ_CHECK(ret);
-    }
-    else
-    {
-        WRBUF output_record = wrbuf_alloc();
-        int r = yaz_record_conv_record(p, input_record, strlen(input_record),
-                                       output_record);
-        if (r)
-        {
-            if (output_expect_record)
-            {
-                printf("yaz_record_conv error=%s\n",
-                       yaz_record_conv_get_error(p));
-                ret = 0;
-            }
-            else
-                ret = 1;
-        }
-        else
-        {
-            if (!output_expect_record)
-            {
-                ret = 0;
-            }
-            else if (strcmp(output_expect_record, wrbuf_cstr(output_record)))
-            {
-                ret = 0;
-                printf("got-output_record len=%ld: %s\n", 
-                       (long) wrbuf_len(output_record),
-                       wrbuf_cstr(output_record));
-                printf("output_expect_record len=%ld %s\n",
-                       (long) strlen(output_expect_record),
-                       output_expect_record);
-            }
-            else
-            {
-                ret = 1;
-            }
-        }
-        wrbuf_destroy(output_record);
-    }
-    return ret;
-}
-
-static int conv_convert_test_iter(yaz_record_conv_t p,
-                                  const char *input_record,
-                                  const char *output_expect_record,
-                                  int num_iter)
-{
-    int i;
-    int ret;
-    for (i = 0; i < num_iter; i++)
-    {
-        ret = conv_convert_test(p, input_record, output_expect_record);
-        if (!ret)
-            break;
-    }
-    return ret;
-}
-
-static void tst_convert1(void)
-{
-    yaz_record_conv_t p = 0;
-    const char *marcxml_rec =
-        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
-        "  <leader>00080nam a22000498a 4500</leader>\n"
-        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
-        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
-        "    <subfield code=\"a\">   11224466 </subfield>\n"
-        "  </datafield>\n"
-        "</record>\n";
-    const char *iso2709_rec =
-        "\x30\x30\x30\x38\x30\x6E\x61\x6D\x20\x61\x32\x32\x30\x30\x30\x34"
-        "\x39\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30"
-        "\x30\x30\x30\x30\x30\x31\x30\x30\x30\x31\x37\x30\x30\x30\x31\x33"
-        "\x1E\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x20\x20"
-        "\x1F\x61\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x1D";
-
-    YAZ_CHECK(conv_configure_test("<backend>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</backend>",
-                                  0, &p));
-    YAZ_CHECK(conv_convert_test(p, marcxml_rec, iso2709_rec));
-    yaz_record_conv_destroy(p);
-
-    YAZ_CHECK(conv_configure_test("<backend>"
-                                  "<marc"
-                                  " outputcharset=\"utf-8\""
-                                  " inputcharset=\"marc-8\""
-                                  " outputformat=\"marcxml\""
-                                  " inputformat=\"marc\""
-                                  "/>"
-                                  "</backend>",
-                                  0, &p));
-    YAZ_CHECK(conv_convert_test(p, iso2709_rec, marcxml_rec));
-    yaz_record_conv_destroy(p);
-
-
-    YAZ_CHECK(conv_configure_test("<backend>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "<marc"
-                                  " outputcharset=\"utf-8\""
-                                  " inputcharset=\"marc-8\""
-                                  " outputformat=\"marcxml\""
-                                  " inputformat=\"marc\""
-                                  "/>"
-                                  "</backend>",
-                                  0, &p));
-    YAZ_CHECK(conv_convert_test(p, marcxml_rec, marcxml_rec));
-    yaz_record_conv_destroy(p);
-
-
-    YAZ_CHECK(conv_configure_test("<backend>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "<marc"
-                                  " inputcharset=\"marc-8\""
-                                  " outputformat=\"marcxml\""
-                                  " inputformat=\"marc\""
-                                  "/>"
-                                  "</backend>",
-                                  0, &p));
-    YAZ_CHECK(conv_convert_test(p, marcxml_rec, marcxml_rec));
-    yaz_record_conv_destroy(p);
-}
-
-static void tst_convert2(void)
-{
-    yaz_record_conv_t p = 0;
-    const char *marcxml_rec =
-        "<record xmlns=\"http://www.loc.gov/MARC21/slim\">\n"
-        "  <leader>00080nam a22000498a 4500</leader>\n"
-        "  <controlfield tag=\"001\">   11224466 </controlfield>\n"
-        "  <datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"
-        "    <subfield code=\"a\">k&#xf8;benhavn</subfield>\n"
-        "  </datafield>\n"
-        "</record>\n";
-    const char *iso2709_rec =
-        "\x30\x30\x30\x37\x37\x6E\x61\x6D\x20\x61\x32\x32\x30\x30\x30\x34"
-        "\x39\x38\x61\x20\x34\x35\x30\x30\x30\x30\x31\x30\x30\x31\x33\x30"
-        "\x30\x30\x30\x30\x30\x31\x30\x30\x30\x31\x34\x30\x30\x30\x31\x33"
-        "\x1E\x20\x20\x20\x31\x31\x32\x32\x34\x34\x36\x36\x20\x1E\x20\x20"
-        "\x1F\x61\x6b\xb2\x62\x65\x6e\x68\x61\x76\x6e\x1E\x1D";
-
-    YAZ_CHECK(conv_configure_test("<backend>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</backend>",
-                                  0, &p));
-    YAZ_CHECK(conv_convert_test_iter(p, marcxml_rec, iso2709_rec, 100));
-    yaz_record_conv_destroy(p);
-}
-
-#endif
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    yaz_log_xml_errors(0, 0 /* disable log */);
-#if YAZ_HAVE_XML2
-    tst_configure();
-#endif
-#if  YAZ_HAVE_XSLT 
-    tst_convert1();
-    tst_convert2();
-#endif
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_record_conv.xsl b/test/tst_record_conv.xsl
deleted file mode 100644 (file)
index 21d6d6b..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- version="1.0">
-<!-- Identity transform stylesheet -->
-
-<xsl:output indent="yes"
-      method="xml"
-      version="1.0"
-      encoding="UTF-8"/>
-
- <xsl:template match="node()|@*">
-   <xsl:copy>
-     <xsl:apply-templates select="@*|node()"/>
-   </xsl:copy>
- </xsl:template>
-
-</xsl:stylesheet>
diff --git a/test/tst_retrieval.c b/test/tst_retrieval.c
deleted file mode 100644 (file)
index 89ba159..0000000
+++ /dev/null
@@ -1,334 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-#include <yaz/retrieval.h>
-#include <yaz/test.h>
-#include <yaz/wrbuf.h>
-#include <string.h>
-#include <yaz/log.h>
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#if YAZ_HAVE_XSLT
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-
-yaz_retrieval_t conv_configure(const char *xmlstring, WRBUF w)
-{
-    xmlDocPtr doc = xmlParseMemory(xmlstring, strlen(xmlstring));
-    if (!doc)
-    {
-        wrbuf_printf(w, "xmlParseMemory");
-        return 0;
-    }
-    else
-    {
-        xmlNodePtr ptr = xmlDocGetRootElement(doc);
-        yaz_retrieval_t p = yaz_retrieval_create();
-
-        if (p)
-        {
-            const char *srcdir = getenv("srcdir");
-            if (srcdir)
-                yaz_retrieval_set_path(p, srcdir);
-        }
-        if (!ptr)
-        {
-            wrbuf_printf(w, "xmlDocGetRootElement");
-            yaz_retrieval_destroy(p);
-            p = 0;
-        }
-        else if (!p)
-        {
-            wrbuf_printf(w, "yaz_retrieval_create");
-        }
-        else
-        {
-            int r = yaz_retrieval_configure(p, ptr);
-            
-            if (r)
-            {
-                wrbuf_puts(w, yaz_retrieval_get_error(p));
-                yaz_retrieval_destroy(p);
-                p = 0;
-            }
-        }
-        xmlFreeDoc(doc);
-        return p;
-    }    
-}
-
-int conv_configure_test(const char *xmlstring, const char *expect_error,
-                        yaz_retrieval_t *pt)
-{
-    WRBUF w = wrbuf_alloc();
-    int ret;
-
-    yaz_retrieval_t p = conv_configure(xmlstring, w);
-
-    if (!p)
-    {
-        if (expect_error && !strcmp(wrbuf_cstr(w), expect_error))
-            ret = 1;
-        else
-        {
-            ret = 0;
-            printf("%s\n", wrbuf_cstr(w));
-        }
-    }
-    else
-    {
-        if (expect_error)
-        {
-            ret = 0;
-            yaz_retrieval_destroy(p);
-        }
-        else
-        {
-            if (pt)
-                *pt = p;
-            else
-                yaz_retrieval_destroy(p);
-            ret = 1;
-        }
-    }
-    wrbuf_destroy(w);
-    return ret;
-}
-
-static void tst_configure(void)
-{
-    YAZ_CHECK(conv_configure_test("<bad", 
-                                  "xmlParseMemory", 0));
-
-    YAZ_CHECK(conv_configure_test("<bad/>", 
-                                  "Expected element <retrievalinfo>", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo/>", 0, 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo><bad/></retrievalinfo>",
-                                  "Element <retrievalinfo>:"
-                                  " expected element <retrieval>, got <bad>",
-                                  0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo><retrieval/>"
-                                  "</retrievalinfo>",
-                                  "Missing 'syntax' attribute", 0));
-
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " unknown=\"unknown\""
-                                  ">"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <retrieval>:  expected attributes "
-                                  "'syntax', identifier' or 'name', got "
-                                  "'unknown'", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"unknown_synt\""
-                                  ">"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <retrieval>:  unknown attribute "
-                                  "value syntax='unknown_synt'", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  "/>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " name=\"marcxml\"/>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " name=\"marcxml\"" 
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  "/>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  " name=\"marcxml\">"
-                                  "<convert/>"
-                                  "</retrieval>" 
-                                  "</retrievalinfo>",
-                                  "Element <retrieval>: expected zero or one element "
-                                  "<backend>, got <convert>", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  " name=\"marcxml\">"
-                                  " <backend syntax=\"usmarc\""
-                                  " schema=\"marcxml\""
-                                  "/>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <backend>: expected attributes 'syntax' or 'name,"
-                                  " got 'schema'", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  " name=\"marcxml\">"
-                                  " <backend syntax=\"usmarc\""
-                                  " name=\"marcxml\""
-                                  "/>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                  " name=\"marcxml\">"
-                                  " <backend syntax=\"unknown\""
-                                  "/>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <backend syntax='unknown'>: "
-                                  "attribute 'syntax' has invalid value "
-                                  "'unknown'", 0));
-
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval" 
-                                  " syntax=\"usmarc\""
-                                  " identifier=\"info:srw/schema/1/marcxml-v1.1\""
-                                    " name=\"marcxml\">"
-                                  " <backend syntax=\"usmarc\""
-                                  " unknown=\"silly\""
-                                  "/>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <backend>: expected attributes "
-                                  "'syntax' or 'name, got 'unknown'", 0));
-
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval syntax=\"usmarc\">"
-                                  "<backend syntax=\"xml\" name=\"dc\">"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"non-existent\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</backend>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <marc inputcharset='utf-8'"
-                                  " outputcharset='non-existent'>: Unsupported character"
-                                  " set mapping defined by attribute values", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval syntax=\"usmarc\">"
-                                  "<backend syntax=\"xml\" name=\"dc\">"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"not-existent\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</backend>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  "Element <marc inputformat='not-existent'>:  Unsupported"
-                                  " input format defined by attribute value", 0));
-
-    YAZ_CHECK(conv_configure_test("<retrievalinfo>"
-                                  "<retrieval syntax=\"usmarc\">"
-                                  "<backend syntax=\"xml\" name=\"dc\">"
-                                  "<xslt stylesheet=\"tst_record_conv.xsl\"/>"
-                                  "<marc"
-                                  " inputcharset=\"utf-8\""
-                                  " outputcharset=\"marc-8\""
-                                  " inputformat=\"xml\""
-                                  " outputformat=\"marc\""
-                                  "/>"
-                                  "</backend>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-    YAZ_CHECK(conv_configure_test(
-                                  "<retrievalinfo "
-                                  " xmlns=\"http://indexdata.com/yaz\" version=\"1.0\">"
-                                  "<retrieval syntax=\"grs-1\"/>"
-                                  "<retrieval syntax=\"usmarc\" name=\"F\"/>"
-                                  "<retrieval syntax=\"usmarc\" name=\"B\"/>"
-                                  "<retrieval syntax=\"xml\" name=\"marcxml\" "
-                                  "           identifier=\"info:srw/schema/1/marcxml-v1.1\">"
-                                  "  <backend syntax=\"usmarc\" name=\"F\">"
-                                  "    <marc inputformat=\"marc\" outputformat=\"marcxml\" "
-                                  "            inputcharset=\"marc-8\"/>"
-                                  "  </backend>"
-                                  "</retrieval>"
-                                  "<retrieval syntax=\"xml\" name=\"danmarc\">"
-                                  "  <backend syntax=\"usmarc\" name=\"F\">"
-                                  "    <marc inputformat=\"marc\" outputformat=\"marcxchange\" "
-                                  "          inputcharset=\"marc-8\"/>"
-                                  "  </backend>"
-                                  "</retrieval>"
-                                  "<retrieval syntax=\"xml\" name=\"dc\" "
-                                  "           identifier=\"info:srw/schema/1/dc-v1.1\">"
-                                  "  <backend syntax=\"usmarc\" name=\"F\">"
-                                  "    <marc inputformat=\"marc\" outputformat=\"marcxml\" "
-                                  "          inputcharset=\"marc-8\"/>"
-                                  "    <xslt stylesheet=\"tst_record_conv.xsl\"/> "
-                                  "  </backend>"
-                                  "</retrieval>"
-                                  "</retrievalinfo>",
-                                  0, 0));
-
-}
-
-#endif
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-
-    yaz_log_xml_errors(0, 0 /* disable it */);
-
-#if YAZ_HAVE_XSLT
-    tst_configure();
-#endif
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_rpn2cql.c b/test/tst_rpn2cql.c
deleted file mode 100644 (file)
index 7aecbb0..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <yaz/test.h>
-#include <yaz/log.h>
-#include <yaz/rpn2cql.h>
-#include <yaz/wrbuf.h>
-#include <yaz/pquery.h>
-
-static int compare(cql_transform_t ct, const char *pqf, const char *cql)
-{
-    int ret = 0;
-    ODR odr = odr_createmem(ODR_ENCODE);
-    WRBUF w = wrbuf_alloc();
-    Z_RPNQuery *q = p_query_rpn(odr, pqf);
-    
-    if (q)
-    {
-        int r = cql_transform_rpn2cql_wrbuf(ct, w, q);
-
-        if (r != 0)
-        {
-            /* transform error */
-            yaz_log(YLOG_LOG, "%s -> Error %d", pqf, r);
-            if (!cql) /* also expected error? */
-                ret = 1;
-        }
-        else if (r == 0)
-        {
-            yaz_log(YLOG_LOG, "%s -> %s", pqf, wrbuf_cstr(w));
-            if (cql && !strcmp(wrbuf_cstr(w), cql))
-            {
-                ret = 1;
-            }
-        }
-    }
-    wrbuf_destroy(w);
-    odr_destroy(odr);
-    return ret;
-}
-
-static void tst1(void)
-{
-    cql_transform_t ct = cql_transform_create();    
-
-    YAZ_CHECK(compare(ct, "abc", "abc"));
-    YAZ_CHECK(compare(ct, "\"a b c\"", "\"a b c\""));
-    YAZ_CHECK(compare(ct, "@and a b", "a and b"));
-    YAZ_CHECK(compare(ct, "@attr 1=field abc", "field=abc"));
-    YAZ_CHECK(compare(ct, "@attr 1=4 abc", 0)); /* should fail */
-
-    cql_transform_define_pattern(ct, "index.title", "1=4");
-    YAZ_CHECK(compare(ct, "@attr 1=4 abc", "title=abc"));
-
-    cql_transform_define_pattern(ct, "index.foo", "1=bar");
-    YAZ_CHECK(compare(ct, "@attr 1=bar abc", "foo=abc"));
-
-    cql_transform_close(ct);
-}
-
-static void tst2(void)
-{
-    WRBUF w = wrbuf_alloc();
-    cql_transform_t ct = 0;
-    const char *srcdir = getenv("srcdir");
-    if (srcdir)
-    {
-        wrbuf_puts(w, srcdir);
-        wrbuf_puts(w, "/");
-    }
-    wrbuf_puts(w, "../etc/pqf.properties");
-    
-    ct = cql_transform_open_fname(wrbuf_cstr(w));
-    YAZ_CHECK(compare(ct, "@attr 1=4 abc", "dc.title=abc"));
-    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 4=108 abc", "dc.title=/exact abc"));
-    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 3=1 @attr 6=1 abc", "dc.title=abc"));
-    YAZ_CHECK(compare(ct, "@attr 1=4 @attr 4=1 @attr 6=1 abc",
-                      "dc.title=abc"));
-    YAZ_CHECK(compare(ct, "@attr 1=1016 abc", "abc"));
-    YAZ_CHECK(compare(ct, "@attr 2=1 @attr 1=30 1980", "dc.date<1980"));
-    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=3 1980", "dc.date=1980"));
-    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=5 1980", "dc.date>1980"));
-    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=2 1980", "dc.date<=1980"));
-    YAZ_CHECK(compare(ct, "@attr 1=30 @attr 2=4 1980", "dc.date>=1980"));
-
-    YAZ_CHECK(compare(ct, "@attr 2=103 @attr 1=_ALLRECORDS 1", "cql.allRecords=1"));
-    YAZ_CHECK(compare(ct, "@attr 1=500 abc", 0));
-    cql_transform_close(ct);
-    wrbuf_destroy(w);
-}
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    tst1();
-    tst2();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_timing.c b/test/tst_timing.c
deleted file mode 100644 (file)
index edbca1d..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <yaz/timing.h>
-#include <yaz/test.h>
-#include <yaz/log.h>
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-static void tst(void)
-{
-    yaz_timing_t t = yaz_timing_create();
-    double real, user, sys;
-    int i = 0;
-    double x = 0;
-
-    YAZ_CHECK(t);
-    if (!t)
-        return;
-
-#ifdef WIN32
-    Sleep(10);
-#endif
-    for (i = 0; i<5000000; i++)
-        x += i;
-
-    YAZ_CHECK_EQ(i, 5000000);
-
-    yaz_log(YLOG_LOG, "i=%d x=%f", i, x);
-    yaz_timing_stop(t);
-
-    real = yaz_timing_get_real(t);
-    YAZ_CHECK(real == -1.0 || real >= 0.0);
-
-    user = yaz_timing_get_user(t);
-    YAZ_CHECK(user == -1.0 || user >= 0.0);
-
-    sys = yaz_timing_get_sys(t); 
-    YAZ_CHECK(sys == -1.0 || sys >= 0.0);
-
-    yaz_log(YLOG_LOG, "real=%f user=%f sys=%f", real, user, sys);
-   
-    yaz_timing_destroy(&t);
-    YAZ_CHECK(!t);
-}
-
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    tst();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_tpath.c b/test/tst_tpath.c
deleted file mode 100644 (file)
index d409624..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-#include <yaz/tpath.h>
-#include <yaz/test.h>
-#include <string.h>
-#include <yaz/log.h>
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-
-static void tst_tpath(void)
-{
-    char fullpath[FILENAME_MAX];
-
-    YAZ_CHECK(!yaz_filepath_resolve("etc", 0, 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("etc", "", 0, fullpath)); /* bug #606 */
-    YAZ_CHECK(!yaz_filepath_resolve("etc", ".", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("does_not_exist", "", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("does_not_exist", ".", 0, fullpath));
-    YAZ_CHECK(yaz_filepath_resolve("tst_tpath", 0, 0, fullpath));
-
-    YAZ_CHECK(!yaz_filepath_resolve("tst_tpath", "", 0, fullpath));
-    YAZ_CHECK(yaz_filepath_resolve("tst_tpath", ".", 0, fullpath));
-
-    YAZ_CHECK(!yaz_filepath_resolve("tst_tpath", "unknown_dir", 0, fullpath));
-    YAZ_CHECK(yaz_filepath_resolve("tst_tpath", "unknown_dir:.", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("tst_tpath", "unknown_dir:", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("tst_tpath", "unknown_dir:c:", 0, fullpath));
-    YAZ_CHECK(!yaz_filepath_resolve("tst_tpath", "unknown_dir:c:\\other", 0, fullpath));
-
-}
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    tst_tpath();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_xml_include.c b/test/tst_xml_include.c
deleted file mode 100644 (file)
index 94a0332..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include <yaz/xml_include.h>
-#include <yaz/test.h>
-
-static void tst_xml_include(void)
-{
-    const char *srcdir = getenv("srcdir");
-    xmlDocPtr doc;
-    xmlNodePtr node;
-    const char *xml_in = "<x><include src=\"tst_xml_inc*.xml\"/></x>";
-
-    if (srcdir == 0)
-        srcdir = ".";
-
-    doc = xmlParseMemory(xml_in, strlen(xml_in));
-    YAZ_CHECK(doc);
-    if (!doc)
-        return;
-    node = xmlDocGetRootElement(doc);
-    YAZ_CHECK(node);
-    if (node)
-    {
-        const char *expect =
-            "<?xml version=\"1.0\"?>\n"
-            "<x><!-- begin include src=\"tst_xml_inc*.xml\" -->"
-            "<y>some</y>"
-            "<!-- end include src=\"tst_xml_inc*.xml\" --></x>\n";
-
-        xmlChar *xml_out;
-        int len_out;
-        int ret = yaz_xml_include_simple(node, srcdir);
-        YAZ_CHECK(ret == 0);
-        xmlDocDumpMemory(doc, &xml_out, &len_out);
-        YAZ_CHECK(xml_out && len_out > 0);
-        if (xml_out && len_out > 0)
-        {
-            YAZ_CHECK(strlen(expect) == len_out);
-            if (strlen(expect) == len_out)
-            {
-                YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
-            }
-            else
-            {
-                fwrite(xml_out, 1, len_out, stdout);
-                fflush(stdout);
-            }
-            xmlFree(xml_out);
-        }
-    }
-    xmlFreeDoc(doc);
-}
-
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    tst_xml_include();
-    YAZ_CHECK_TERM;
-}
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tst_xml_include.xml b/test/tst_xml_include.xml
deleted file mode 100644 (file)
index da253be..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<y>some</y>
diff --git a/test/tstccl.c b/test/tstccl.c
deleted file mode 100644 (file)
index dada1e0..0000000
+++ /dev/null
@@ -1,277 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-/* CCL test */
-
-#include <string.h>
-#include <yaz/ccl_xml.h>
-#include <yaz/log.h>
-#include <yaz/test.h>
-
-
-static int tst_ccl_query(CCL_bibset bibset,
-                         const char *query,
-                         const char *result)
-{
-    CCL_parser parser = ccl_parser_create(bibset);
-    int ret = 0;
-
-    if (parser && bibset)
-    {
-        struct ccl_rpn_node *rpn;
-        
-        rpn = ccl_parser_find_str(parser, query);
-        if (rpn)
-        {
-            /* parse ok. check that result is there and match */
-            WRBUF wrbuf = wrbuf_alloc();
-            ccl_pquery(wrbuf, rpn);
-            
-            /* check expect a result and that it matches */
-            if (result && !strcmp(wrbuf_cstr(wrbuf), result))
-                ret = 1;
-            else
-            {
-                yaz_log(YLOG_WARN, "%s: result does not match", query);
-                yaz_log(YLOG_WARN, " expected %s", result);
-                yaz_log(YLOG_WARN, " got      %s", wrbuf_cstr(wrbuf));
-                ret = 0;
-            }
-            ccl_rpn_delete(rpn);
-            wrbuf_destroy(wrbuf);
-        }
-        else 
-        {
-            if (result)
-            {
-                yaz_log(YLOG_WARN, "%s: parse failed", query);
-                ret = 0;
-            }
-            else
-                ret = 1;
-        }
-    }
-    ccl_parser_destroy (parser);
-    return ret;
-}
-
-void tst1(int pass)
-{
-    CCL_bibset bibset = ccl_qual_mk();
-    char tstline[128];
-
-    YAZ_CHECK(bibset);
-    if (!bibset)
-        return;
-
-    switch(pass)
-    {
-    case 0:
-        ccl_qual_fitem(bibset, "u=4    s=pw t=l,r", "ti");
-        ccl_qual_fitem(bibset, "1=1016 s=al,pw t=r",    "term");
-        ccl_qual_fitem(bibset, "1=/my/title",         "dc.title");
-        ccl_qual_fitem(bibset, "r=r",         "date");
-        ccl_qual_fitem(bibset, "r=o",         "x");
-        ccl_qual_fitem(bibset, "dc.title", "title");
-        ccl_qual_fitem(bibset, "term dc.title", "comb");
-        break;
-    case 1:
-        strcpy(tstline, "ti u=4    s=pw t=l,r");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "term 1=1016 s=al,pw t=r  # default term");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "dc.title 1=/my/title");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "date r=r # ordered relation");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "x r=o # ordered relation");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "title dc.title # alias");
-        ccl_qual_line(bibset, tstline);
-
-        strcpy(tstline, "comb term dc.title # combination");
-        ccl_qual_line(bibset, tstline);
-        break;
-    case 2:
-        ccl_qual_buf(bibset, "ti u=4    s=pw t=l,r\n"
-                     "term 1=1016 s=al,pw t=r\r\n"
-                     "\n"
-                     "dc.title 1=/my/title\n"
-                     "date r=r\n" 
-                     "x r=o\n"
-                     "title dc.title\n"
-                     "comb term dc.title\n"
-            );
-        break;
-    case 3:
-#if YAZ_HAVE_XML2
-        if (1)
-        {
-            xmlDocPtr doc;
-            int r;
-            const char *addinfo = 0;
-            const char *xml_str = 
-                "<cclmap>\n"
-                " <qual name=\"ti\">\n"
-                "   <attr type=\"u\" value=\"4\"/>\n"
-                "   <attr type=\"s\" value=\"pw\"/>\n"
-                "   <attr type=\"t\" value=\"l,r\"/>\n"
-                " </qual>\n"
-                " <qual name=\"term\">\n"
-                "   <attr type=\"1\" value=\"1016\"/>\n"
-                "   <attr type=\"s\" value=\"al,pw\"/>\n"
-                "   <attr type=\"t\" value=\"r\"/>\n"
-                " </qual>\n"
-                " <qual name=\"dc.title\">\n"
-                "   <attr type=\"1\" value=\"/my/title\"/>\n"
-                " </qual>\n"
-                " <qual name=\"date\">\n"
-                "   <attr type=\"r\" value=\"r\"/>\n"
-                " </qual>\n"
-                " <qual name=\"x\">\n"
-                "   <attr type=\"r\" value=\"o\"/>\n"
-                " </qual>\n"
-                " <qual name=\"title\">\n"
-                "   <qual name=\"dc.title\"/>\n"
-                " </qual>\n"
-                " <qual name=\"comb\">\n"
-                "   <qual name=\"term\"/>\n"
-                "   <qual name=\"dc.title\"/>\n"
-                " </qual>\n"
-                "</cclmap>\n";
-            
-            doc = xmlParseMemory(xml_str, strlen(xml_str));
-            YAZ_CHECK(doc);
-
-            r = ccl_xml_config(bibset, xmlDocGetRootElement(doc), &addinfo);
-            YAZ_CHECK_EQ(r, 0);
-
-            xmlFreeDoc(doc);
-        }
-        break;
-#else
-        return;
-#endif
-    default:
-        YAZ_CHECK(0);
-        return;
-    }
-    
-    YAZ_CHECK(tst_ccl_query(bibset, "x1", "@attr 4=2 @attr 1=1016 x1 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "(((((x1)))))", "@attr 4=2 @attr 1=1016 x1 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x1 and x2",
-                  "@and "
-                  "@attr 4=2 @attr 1=1016 x1 "
-                  "@attr 4=2 @attr 1=1016 x2 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "ti=x3", "@attr 4=2 @attr 1=4 x3 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "dc.title=x4", "@attr 1=/my/title x4 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x1 and", 0));
-    YAZ_CHECK(tst_ccl_query(bibset, "tix=x5", 0));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a%b", 
-                  "@prox 0 1 0 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-    YAZ_CHECK(tst_ccl_query(bibset, "a%1b", 
-                  "@prox 0 1 0 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a%2b", 
-                  "@prox 0 2 0 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a%19b", 
-                  "@prox 0 19 0 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "spid%æserne", 
-                  "@prox 0 1 0 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 spid "
-                  "@attr 4=2 @attr 1=1016 æserne "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a!b", 
-                  "@prox 0 1 1 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-    YAZ_CHECK(tst_ccl_query(bibset, "a!2b", 
-                  "@prox 0 2 1 2 k 2 "
-                  "@attr 4=2 @attr 1=1016 a "
-                  "@attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "date=1980", "@attr 2=3 1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=-1980", "@attr 2=2 1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "date=- 1980", "@attr 2=2 1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x=-1980", "@attr 2=3 -1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x=- 1980", "@attr 2=2 1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x= -1980", "@attr 2=3 -1980 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x=234-1990", "@attr 2=3 234-1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "));
-    YAZ_CHECK(tst_ccl_query(bibset, "ti=a,b", "@attr 4=1 @attr 1=4 a,b "));
-    YAZ_CHECK(tst_ccl_query(bibset, "ti=a, b", "@attr 4=1 @attr 1=4 \"a, b\" "));
-    YAZ_CHECK(tst_ccl_query(bibset, "ti=a-b", "@attr 4=2 @attr 1=4 a-b "));
-    YAZ_CHECK(tst_ccl_query(bibset, "ti=a - b", "@attr 4=1 @attr 1=4 \"a - b\" "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a?", "@attr 5=1 @attr 4=2 @attr 1=1016 a "));
-    YAZ_CHECK(tst_ccl_query(bibset, "a b", 
-                            "@and @attr 4=2 @attr 1=1016 a "
-                            "@attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "a b?", 
-                            "@and @attr 4=2 @attr 1=1016 a "
-                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "title=a", 
-                            "@attr 1=/my/title a "));
-
-    YAZ_CHECK(tst_ccl_query(bibset, "comb=a", 
-                            "@or @attr 4=2 @attr 1=1016 a "
-                            "@attr 1=/my/title a "));
-
-    /* Bug #2895 */
-#if 1
-    YAZ_CHECK(tst_ccl_query(bibset, "a? b?", 
-                            /* incorrect. */
-                            "@and @attr 4=2 @attr 1=1016 a? "
-                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
-#else
-    YAZ_CHECK(tst_ccl_query(bibset, "a? b?", 
-                            /* correct */
-                            "@and @attr 5=1 @attr 4=2 @attr 1=1016 a "
-                            "@attr 5=1 @attr 4=2 @attr 1=1016 b "));
-#endif
-    ccl_qual_rm(&bibset);
-}
-
-int main(int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-    YAZ_CHECK_LOG();
-    tst1(0);
-    tst1(1);
-    tst1(2);
-    tst1(3);
-    YAZ_CHECK_TERM;
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tsticonv.c b/test/tsticonv.c
deleted file mode 100644 (file)
index 352033a..0000000
+++ /dev/null
@@ -1,747 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <ctype.h>
-
-#include <yaz/yaz-util.h>
-#include <yaz/test.h>
-
-#define ESC "\x1b"
-
-static int compare_buffers(char *msg, int no,
-                           int expect_len, const char *expect_buf,
-                           int got_len, const char *got_buf)
-{
-    if (expect_len == got_len
-        && !memcmp(expect_buf, got_buf, expect_len))
-        return 1;
-    
-    if (0) /* use 1 see how the buffers differ (for debug purposes) */
-    {
-        int i;
-        printf("tsticonv test=%s i=%d failed\n", msg, no);
-        printf("off got exp\n");
-        for (i = 0; i<got_len || i<expect_len; i++)
-        {
-            char got_char[10];
-            char expect_char[10];
-            
-            if (i < got_len)
-                sprintf(got_char, "%02X", got_buf[i]);
-            else
-                sprintf(got_char, "?  ");
-            
-            if (i < expect_len)
-                sprintf(expect_char, "%02X", expect_buf[i]);
-            else
-                sprintf(expect_char, "?  ");
-            
-            printf("%02d  %s  %s %c\n",
-                   i, got_char, expect_char, got_buf[i] == expect_buf[i] ?
-                   ' ' : '*');
-            
-        }
-    }
-    return 0;
-}
-
-static int tst_convert_l(yaz_iconv_t cd, size_t in_len, const char *in_buf,
-                         size_t expect_len, const char *expect_buf)
-{
-    size_t r;
-    char *inbuf= (char*) in_buf;
-    size_t inbytesleft = in_len > 0 ? in_len : strlen(in_buf);
-    char outbuf0[64];
-    char *outbuf = outbuf0;
-
-    while (inbytesleft)
-    {
-        size_t outbytesleft = outbuf0 + sizeof(outbuf0) - outbuf;
-        if (outbytesleft > 12)
-            outbytesleft = 12;
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        if (r == (size_t) (-1))
-        {
-            int e = yaz_iconv_error(cd);
-            if (e != YAZ_ICONV_E2BIG)
-                return 0;
-        }
-        else
-        {
-            yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
-            break;
-        }
-    }
-
-    return compare_buffers("tsticonv 22", 0,
-                           expect_len, expect_buf,
-                           outbuf - outbuf0, outbuf0);
-}
-
-static int tst_convert_x(yaz_iconv_t cd, const char *buf, const char *cmpbuf,
-                         int expect_error)
-{
-    int ret = 1;
-    WRBUF b = wrbuf_alloc();
-    char outbuf[16];
-    size_t inbytesleft = strlen(buf);
-    const char *inp = buf;
-    int rounds = 0;
-    for (rounds = 0; inbytesleft && rounds < (int) sizeof(outbuf); rounds++)
-    {
-        size_t outbytesleft = sizeof(outbuf);
-        char *outp = outbuf;
-        size_t r = yaz_iconv(cd, (char**) &inp,  &inbytesleft,
-                             &outp, &outbytesleft);
-        wrbuf_write(b, outbuf, outp - outbuf);
-        if (r == (size_t) (-1))
-        {
-            int e = yaz_iconv_error(cd);
-            if (e != YAZ_ICONV_E2BIG)
-            {
-                if (expect_error != -1)
-                    if (e != expect_error)
-                        ret = 0;
-                break;
-            }
-        }
-        else
-        {
-            size_t outbytesleft = sizeof(outbuf);
-            char *outp = outbuf;
-            r = yaz_iconv(cd, 0, 0, &outp, &outbytesleft);
-            wrbuf_write(b, outbuf, outp - outbuf);
-            if (expect_error != -1)
-                if (expect_error)
-                    ret = 0;
-            break;
-        }
-    }
-    if (wrbuf_len(b) == strlen(cmpbuf) 
-        && !memcmp(cmpbuf, wrbuf_buf(b), wrbuf_len(b)))
-        ;
-    else
-    {
-        WRBUF w = wrbuf_alloc();
-
-        ret = 0;
-        wrbuf_rewind(w);
-        wrbuf_puts_escaped(w, buf);
-        yaz_log(YLOG_LOG, "input %s", wrbuf_cstr(w));
-
-        wrbuf_rewind(w);
-        wrbuf_write_escaped(w, wrbuf_buf(b), wrbuf_len(b));
-        yaz_log(YLOG_LOG, "got %s", wrbuf_cstr(w));
-        
-        wrbuf_rewind(w);
-        wrbuf_puts_escaped(w, cmpbuf);
-        yaz_log(YLOG_LOG, "exp %s", wrbuf_cstr(w));
-
-        wrbuf_destroy(w);
-    }
-
-    wrbuf_destroy(b);
-    return ret;
-}
-
-static int tst_convert(yaz_iconv_t cd, const char *buf, const char *cmpbuf)
-{
-    return tst_convert_x(cd, buf, cmpbuf, 0);
-}
-
-/* some test strings in ISO-8859-1 format */
-static const char *iso_8859_1_a[] = {
-    "ax" ,
-    "\xd8",
-    "eneb\346r",
-    "\xe5" "\xd8",
-    "\xe5" "\xd8" "b",
-    "\xe5" "\xe5",
-    0 };
-
-static void tst_marc8_to_ucs4b(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("UCS4", "MARC8");
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-    
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\033$1" "\x21\x2B\x3B" /* FF1F */ "\033(B" "o",
-                  8, 
-                  "\x00\x00\xFF\x1F" "\x00\x00\x00o"));
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\033$1" "\x6F\x77\x29" /* AE0E */
-                  "\x6F\x52\x7C" /* c0F4 */ "\033(B",
-                  8,
-                  "\x00\x00\xAE\x0E" "\x00\x00\xC0\xF4"));
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\033$1"
-                  "\x21\x50\x6E"  /* UCS 7CFB */
-                  "\x21\x51\x31"  /* UCS 7D71 */
-                  "\x21\x3A\x67"  /* UCS 5B89 */
-                  "\x21\x33\x22"  /* UCS 5168 */
-                  "\x21\x33\x53"  /* UCS 5206 */
-                  "\x21\x44\x2B"  /* UCS 6790 */
-                  "\033(B",
-                  24, 
-                  "\x00\x00\x7C\xFB"
-                  "\x00\x00\x7D\x71"
-                  "\x00\x00\x5B\x89"
-                  "\x00\x00\x51\x68"
-                  "\x00\x00\x52\x06"
-                  "\x00\x00\x67\x90"));
-
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\xB0\xB2",     /* AYN and oSLASH */
-                  8, 
-                  "\x00\x00\x02\xBB"  "\x00\x00\x00\xF8"));
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\xF6\x61",     /* a underscore */
-                  8, 
-                  "\x00\x00\x00\x61"  "\x00\x00\x03\x32"));
-
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\x61\xC2",     /* a, phonorecord mark */
-                  8,
-                  "\x00\x00\x00\x61"  "\x00\x00\x21\x17"));
-
-    /* bug #258 */
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "el" "\xe8" "am\xe8" "an", /* elaman where a is a" */
-                  32,
-                  "\x00\x00\x00" "e"
-                  "\x00\x00\x00" "l"
-                  "\x00\x00\x00" "a"
-                  "\x00\x00\x03\x08"
-                  "\x00\x00\x00" "m"
-                  "\x00\x00\x00" "a"
-                  "\x00\x00\x03\x08"
-                  "\x00\x00\x00" "n"));
-    /* bug #260 */
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\xe5\xe8\x41",
-                  12, 
-                  "\x00\x00\x00\x41" "\x00\x00\x03\x04" "\x00\x00\x03\x08"));
-    /* bug #416 */
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\xEB\x74\xEC\x73",
-                  12,
-                  "\x00\x00\x00\x74" "\x00\x00\x03\x61" "\x00\x00\x00\x73"));
-    /* bug #416 */
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  0,
-                  "\xFA\x74\xFB\x73",
-                  12, 
-                  "\x00\x00\x00\x74" "\x00\x00\x03\x60" "\x00\x00\x00\x73"));
-
-    yaz_iconv_close(cd);
-}
-
-static void tst_ucs4b_to_utf8(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("UTF8", "UCS4");
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  8,
-                  "\x00\x00\xFF\x1F\x00\x00\x00o",
-                  4,
-                  "\xEF\xBC\x9F\x6F"));
-
-    YAZ_CHECK(tst_convert_l(
-                  cd,
-                  8, 
-                  "\x00\x00\xAE\x0E\x00\x00\xC0\xF4",
-                  6,
-                  "\xEA\xB8\x8E\xEC\x83\xB4"));
-    yaz_iconv_close(cd);
-}
-
-static void dconvert(int mandatory, const char *tmpcode)
-{
-    int i;
-    int ret;
-    yaz_iconv_t cd;
-    for (i = 0; iso_8859_1_a[i]; i++)
-    {
-        size_t r;
-        char *inbuf = (char*) iso_8859_1_a[i];
-        size_t inbytesleft = strlen(inbuf);
-        char outbuf0[24];
-        char outbuf1[10];
-        char *outbuf = outbuf0;
-        size_t outbytesleft = sizeof(outbuf0);
-
-        cd = yaz_iconv_open(tmpcode, "ISO-8859-1");
-        YAZ_CHECK(cd || !mandatory);
-        if (!cd)
-            return;
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        YAZ_CHECK(r != (size_t) (-1));
-
-        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
-        YAZ_CHECK(r != (size_t) (-1));
-        yaz_iconv_close(cd);
-        if (r == (size_t) (-1))
-            return;
-        
-        cd = yaz_iconv_open("ISO-8859-1", tmpcode);
-        YAZ_CHECK(cd || !mandatory);
-        if (!cd)
-            return;
-        inbuf = outbuf0;
-        inbytesleft = sizeof(outbuf0) - outbytesleft;
-
-        outbuf = outbuf1;
-        outbytesleft = sizeof(outbuf1);
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        YAZ_CHECK(r != (size_t) (-1));
-
-        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
-        if (r == (size_t)(-1))
-        {
-            fprintf(stderr, "failed\n");
-        }
-        YAZ_CHECK(r != (size_t) (-1));
-
-        if (r != (size_t)(-1)) 
-        {
-            ret = compare_buffers("dconvert", i,
-                                  strlen(iso_8859_1_a[i]), iso_8859_1_a[i],
-                                  sizeof(outbuf1) - outbytesleft, outbuf1);
-            YAZ_CHECK(ret);
-        }
-        yaz_iconv_close(cd);
-    }
-}
-
-int utf8_check(unsigned c)
-{
-    if (sizeof(c) >= 4)
-    {
-        size_t r;
-        char src[4];
-        char dst[4];
-        char utf8buf[6];
-        char *inbuf = src;
-        size_t inbytesleft = 4;
-        char *outbuf = utf8buf;
-        size_t outbytesleft = sizeof(utf8buf);
-        int i;
-        yaz_iconv_t cd = yaz_iconv_open("UTF-8", "UCS4LE");
-        if (!cd)
-            return 0;
-        for (i = 0; i<4; i++)
-            src[i] = c >> (i*8);
-        
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        yaz_iconv_close(cd);
-
-        if (r == (size_t)(-1))
-            return 0;
-
-        cd = yaz_iconv_open("UCS4LE", "UTF-8");
-        if (!cd)
-            return 0;
-        inbytesleft = sizeof(utf8buf) - outbytesleft;
-        inbuf = utf8buf;
-
-        outbuf = dst;
-        outbytesleft = 4;
-
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        if (r == (size_t)(-1))
-            return 0;
-
-        yaz_iconv_close(cd);
-
-        if (memcmp(src, dst, 4))
-            return 0;
-    }
-    return 1;
-}
-        
-static void tst_marc8_to_utf8(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours de math", 
-                          "Cours de math"));
-    /* COMBINING ACUTE ACCENT */
-    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
-                          "Cours de mathe\xcc\x81"));
-
-    YAZ_CHECK(tst_convert(cd, "\xea" "a", "a\xcc\x8a"));
-    YAZ_CHECK(tst_convert(cd, "a" "\xea" "\x1e", "a" "\x1e\xcc\x8a"));
-    YAZ_CHECK(tst_convert(cd, "a" "\xea" "p", "a" "p\xcc\x8a"));
-
-    YAZ_CHECK(tst_convert_x(cd, "a\xea", "a", YAZ_ICONV_EINVAL));
-    YAZ_CHECK(tst_convert(cd, "p", "\xcc\x8a")); /* note: missing p */
-    yaz_iconv(cd, 0, 0, 0, 0);     /* incomplete. so we have to reset */
-
-    /* bug #2115 */
-    YAZ_CHECK(tst_convert(cd, ESC "(N" ESC ")Qp" ESC "(B", "\xd0\x9f"));
-
-    YAZ_CHECK(tst_convert_x(cd, ESC , "", YAZ_ICONV_EINVAL));
-    YAZ_CHECK(tst_convert_x(cd, ESC "(", "", YAZ_ICONV_EINVAL));
-    YAZ_CHECK(tst_convert_x(cd, ESC "(B", "", 0));
-
-    YAZ_CHECK(tst_convert(cd, ESC "(B" "\x31", "1"));  /* ASCII in G0 */
-    YAZ_CHECK(tst_convert(cd, ESC ")B" "\xB1", "1"));  /* ASCII in G1 */
-
-    yaz_iconv_close(cd);
-}
-
-static void tst_marc8s_to_utf8(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("UTF-8", "MARC8s");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours de math", 
-                          "Cours de math"));
-    /* E9: LATIN SMALL LETTER E WITH ACUTE */
-    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
-                          "Cours de math\xc3\xa9"));
-
-    yaz_iconv_close(cd);
-}
-
-
-static void tst_marc8_to_latin1(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("ISO-8859-1", "MARC8");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "ax", "ax"));
-
-    /* latin capital letter o with stroke */
-    YAZ_CHECK(tst_convert(cd, "\xa2", "\xd8"));
-
-    /* with latin small letter ae */
-    YAZ_CHECK(tst_convert(cd, "eneb\xb5r", "eneb\346r"));
-
-    YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2", "\xe5" "\xd8"));
-
-    YAZ_CHECK(tst_convert(cd, "\xea" "a\xa2" "b", "\xe5" "\xd8" "b"));
-
-    YAZ_CHECK(tst_convert(cd, "\xea" "a"  "\xea" "a", "\xe5" "\xe5"));
-
-    YAZ_CHECK(tst_convert(cd, "Cours de math", 
-                          "Cours de math"));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathâe", 
-                          "Cours de mathé"));
-    YAZ_CHECK(tst_convert(cd, "12345678âe", 
-                          "12345678é"));
-    YAZ_CHECK(tst_convert(cd, "123456789âe", 
-                          "123456789é"));
-    YAZ_CHECK(tst_convert(cd, "1234567890âe", 
-                          "1234567890é"));
-    YAZ_CHECK(tst_convert(cd, "12345678901âe", 
-                          "12345678901é"));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathâem", 
-                          "Cours de mathém"));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathâematiques", 
-                          "Cours de mathématiques"));
-
-    yaz_iconv_close(cd);
-}
-
-static void tst_utf8_to_marc8(const char *marc8_type)
-{
-    yaz_iconv_t cd = yaz_iconv_open(marc8_type, "UTF-8");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
-
-    /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
-    YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
-
-    /** Pure ASCII. 12 characters (sizeof(outbuf)) */
-    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
-
-    /** Pure ASCII. 13 characters (sizeof(outbuf)+1) */
-    YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
-
-    /** UPPERCASE SCANDINAVIAN O */
-    YAZ_CHECK(tst_convert(cd, "S\xc3\x98", "S\xa2"));
-
-    /** ARING */
-    YAZ_CHECK(tst_convert(cd, "A" "\xCC\x8A", "\xEA" "A"));
-
-    /** A MACRON + UMLAUT, DIAERESIS */
-    YAZ_CHECK(tst_convert(cd, "A" "\xCC\x84" "\xCC\x88",
-                          "\xE5\xE8\x41"));
-    
-    /* Ligature spanning two characters */
-    YAZ_CHECK(tst_convert(cd,
-                          "\x74" "\xCD\xA1" "\x73",  /* UTF-8 */
-                          "\xEB\x74\xEC\x73"));      /* MARC-8 */
-
-    /* Double title spanning two characters */
-    YAZ_CHECK(tst_convert(cd,
-                          "\x74" "\xCD\xA0" "\x73",  /* UTF-8 */
-                          "\xFA\x74\xFB\x73"));      /* MARC-8 */
-
-    /** Ideographic question mark (Unicode FF1F) */
-    YAZ_CHECK(tst_convert(cd,
-                          "\xEF\xBC\x9F" "o",        /* UTF-8 */
-                          "\033$1" "\x21\x2B\x3B" "\033(B" "o" ));
-
-
-    /** Ideographic space per ANSI Z39.64 */
-    YAZ_CHECK(tst_convert(cd,
-                          "\xe3\x80\x80" "o",        /* UTF-8 */
-                          "\033$1" "\x21\x23\x21" "\033(B" "o" ));
-
-    /** Superscript 0 . bug #642 */
-    YAZ_CHECK(tst_convert(cd,
-                          "(\xe2\x81\xb0)",        /* UTF-8 */
-                          "(\033p0\x1bs)"));
-    
-    
-    /** bug #1778 */
-    YAZ_CHECK(tst_convert(cd,
-                          /* offset 0x530 in UTF-8 rec marccol4.u8.marc */
-                          "\xE3\x83\xB3" "\xE3\x82\xBF" 
-                          "\xCC\x84" "\xCC\x84" "\xE3\x83\xBC" /* UTF-8 */,
-                          "\x1B\x24\x31" "\x69\x25\x73"
-                          "\x1B\x28\x42" "\xE5\xE5" "\x1B\x24\x31" 
-                          "\x69\x25\x3F"
-                          "\x69\x21\x3C" "\x1B\x28\x42"));
-
-    
-    /** bug #2120 */
-    YAZ_CHECK(tst_convert(cd, 
-                          "\xCE\x94\xCE\xB5\xCF\x84"
-                          "\xCE\xBF\xCF\x81\xCE\xB1"
-                          "\xCE\xBA\xCE\xB7\xCF\x82\x2C",
-
-                          "\x1B\x28\x53\x45\x66\x78\x72\x75"
-                          "\x61\x6D\x6A\x77"
-                          "\x1B\x28\x42\x2C"
-                  ));
-    {
-        char *inbuf0 = "\xe2\x81\xb0";
-        char *inbuf = inbuf0;
-        size_t inbytesleft = strlen(inbuf);
-        char outbuf0[64];
-        char *outbuf = outbuf0;
-        size_t outbytesleft = sizeof(outbuf0)-1;
-        size_t r;
-#if 0
-        int i;
-#endif
-        r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
-        YAZ_CHECK(r != (size_t) (-1));
-
-#if 0
-        *outbuf = '\0';  /* so we know when to stop printing */
-        for (i = 0; outbuf0[i]; i++)
-        {
-            int ch = outbuf0[i] & 0xff;
-            yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
-        }
-#endif
-
-        r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
-        YAZ_CHECK(r != (size_t) (-1));
-        *outbuf = '\0';  /* for strcmp test below and printing */
-#if 0
-        for (i = 0; outbuf0[i]; i++)
-        {
-            int ch = outbuf0[i] & 0xff;
-            yaz_log(YLOG_LOG, "ch%d %02X %c", i, ch, ch >= ' ' ? ch : '?');
-        }
-#endif
-        YAZ_CHECK(strcmp("\033p0\x1bs", outbuf0) == 0);
-    }
-    yaz_iconv(cd, 0, 0, 0, 0);
-    yaz_iconv_close(cd);
-}
-
-static void tst_advance_to_utf8(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("utf-8", "advancegreek");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
-    yaz_iconv_close(cd);
-}
-
-static void tst_utf8_to_advance(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("advancegreek", "utf-8");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
-    yaz_iconv_close(cd);
-}
-
-static void tst_latin1_to_marc8(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("MARC8", "ISO-8859-1");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "Cours ", "Cours "));
-
-    /** Pure ASCII. 11 characters (sizeof(outbuf)-1) */
-    YAZ_CHECK(tst_convert(cd, "Cours de mat", "Cours de mat"));
-
-    /** Pure ASCII. 12 characters (sizeof(outbuf)) */
-    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"));
-
-    /** Pure ASCII. 13 characters (sizeof(outbuf)) */
-    YAZ_CHECK(tst_convert(cd, "Cours de math.", "Cours de math."));
-
-    /** D8: UPPERCASE SCANDINAVIAN O */
-    YAZ_CHECK(tst_convert(cd, "S\xd8", "S\xa2"));
-
-    /** E9: LATIN SMALL LETTER E WITH ACUTE */
-    YAZ_CHECK(tst_convert(cd, "Cours de math\xe9", "Cours de mathâe"));
-    YAZ_CHECK(tst_convert(cd, "Cours de math", "Cours de math"
-                  ));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathé", "Cours de mathâe" ));
-    YAZ_CHECK(tst_convert(cd, "12345678é","12345678âe"));
-    YAZ_CHECK(tst_convert(cd, "123456789é", "123456789âe"));
-    YAZ_CHECK(tst_convert(cd, "1234567890é","1234567890âe"));
-    YAZ_CHECK(tst_convert(cd, "12345678901é", "12345678901âe"));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathém", "Cours de mathâem"));
-    YAZ_CHECK(tst_convert(cd, "Cours de mathématiques",
-                          "Cours de mathâematiques"));
-    yaz_iconv_close(cd);
-}
-
-static void tst_utf8_codes(void)
-{
-    YAZ_CHECK(utf8_check(3));
-    YAZ_CHECK(utf8_check(127));
-    YAZ_CHECK(utf8_check(128));
-    YAZ_CHECK(utf8_check(255));
-    YAZ_CHECK(utf8_check(256));
-    YAZ_CHECK(utf8_check(900));
-    YAZ_CHECK(utf8_check(1000));
-    YAZ_CHECK(utf8_check(10000));
-    YAZ_CHECK(utf8_check(100000));
-    YAZ_CHECK(utf8_check(1000000));
-    YAZ_CHECK(utf8_check(10000000));
-    YAZ_CHECK(utf8_check(100000000));
-}
-
-static void tst_danmarc_to_latin1(void)
-{
-    yaz_iconv_t cd = yaz_iconv_open("iso-8859-1", "danmarc");
-
-    YAZ_CHECK(cd);
-    if (!cd)
-        return;
-
-    YAZ_CHECK(tst_convert(cd, "ax", "ax"));
-
-    YAZ_CHECK(tst_convert(cd, "a@@b", "a@b"));
-    YAZ_CHECK(tst_convert(cd, "a@@@@b", "a@@b"));
-    YAZ_CHECK(tst_convert(cd, "@000ab", "\nb"));
-
-    YAZ_CHECK(tst_convert(cd, "@\xe5", "aa"));
-    YAZ_CHECK(tst_convert(cd, "@\xc5.", "Aa."));
-    
-    yaz_iconv_close(cd);
-}
-
-
-int main (int argc, char **argv)
-{
-    YAZ_CHECK_INIT(argc, argv);
-
-    tst_utf8_codes();
-
-    tst_marc8_to_utf8();
-
-    tst_marc8s_to_utf8();
-
-    tst_marc8_to_latin1();
-
-    tst_advance_to_utf8();
-    tst_utf8_to_advance();
-
-    tst_utf8_to_marc8("marc8");
-    tst_utf8_to_marc8("marc8lossy");
-    tst_utf8_to_marc8("marc8lossless");
-
-    tst_danmarc_to_latin1();
-
-    tst_latin1_to_marc8();
-
-    tst_marc8_to_ucs4b();
-    tst_ucs4b_to_utf8();
-
-    dconvert(1, "UTF-8");
-    dconvert(1, "ISO-8859-1");
-    dconvert(1, "UCS4");
-    dconvert(1, "UCS4LE");
-    dconvert(0, "CP865");
-
-    YAZ_CHECK_TERM;
-}
-/*
- * Local variables:
- * c-basic-offset: 4
- * c-file-style: "Stroustrup"
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
-
diff --git a/test/tstlog.c b/test/tstlog.c
deleted file mode 100644 (file)
index d4a83e5..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
- * See the file LICENSE for details.
- */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <yaz/options.h>
-#include <yaz/log.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-void hook_func(int level, const char *msg, void *vp)
-{
-    fprintf(stderr, "[HOOK level=%d msg=%s]\n", level, msg);
-}
-
-int main(int argc, char **argv)
-{
-    char *arg;
-    int i, ret;
-    int level = YLOG_LOG;
-    int number = 1;
-    unsigned int wait_between_log = 0;
-
-    while ((ret = options("f:p:v:l:m:n:r:w:Hh", argv, argc, &arg)) != -2)
-    {
-        switch (ret)
-        {
-        case 'r':
-            yaz_log_init_max_size(atoi(arg));
-            break;
-        case 'f':
-            yaz_log_time_format(arg);
-            break;
-        case 'p':
-            yaz_log_init_prefix(arg);
-            break;
-        case 'v':
-            yaz_log_init_level(yaz_log_mask_str(arg));
-            break;
-        case 'l':
-            if (!strcmp(arg, "@"))
-                yaz_log_init_file(0);
-            else
-                yaz_log_init_file(arg);
-            break;
-        case 'n':
-            number = atoi(arg);
-            break;
-        case 'm':        
-            level = yaz_log_module_level(arg);
-            break;
-        case 'w':