New tests.
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 6 May 2003 10:07:33 +0000 (10:07 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 6 May 2003 10:07:33 +0000 (10:07 +0000)
util/Makefile.am
util/tsticonv.c
util/tstmatchstr.c [new file with mode: 0644]
util/tstwrbuf.c [new file with mode: 0644]

index ce94b0d..8fb85d8 100644 (file)
@@ -1,10 +1,10 @@
 ## Copyright (C) 1994-2003, Index Data
 ## All rights reserved.
-## $Id: Makefile.am,v 1.17 2003-04-23 20:34:08 adam Exp $
+## $Id: Makefile.am,v 1.18 2003-05-06 10:07:33 adam Exp $
 
 noinst_LTLIBRARIES = libutil.la
 
-TESTS = tsticonv tstnmem
+TESTS = tsticonv tstnmem tstmatchstr tstwrbuf
 
 bin_SCRIPTS = yaz-comp
 
@@ -14,20 +14,30 @@ AM_CPPFLAGS=-I$(top_srcdir)/include
 
 noinst_PROGRAMS = marcdump yaziconv
 
-EXTRA_PROGRAMS = tsticonv tstnmem
+EXTRA_PROGRAMS = tsticonv tstnmem tstmatchstr tstwrbuf
 
+# MARC dumper utility
 marcdump_LDADD = libutil.la 
 marcdump_SOURCES = marcdump.c
 
+# YAZ Iconv utility
 yaziconv_LDADD = libutil.la 
 yaziconv_SOURCES = yaziconv.c
 
+# Tests..
 tsticonv_LDADD = libutil.la
 tsticonv_SOURCES = tsticonv.c
 
 tstnmem_LDADD = libutil.la
 tstnmem_SOURCES = tstnmem.c
 
+tstmatchstr_LDADD = libutil.la
+tstmatchstr_SOURCES = tstmatchstr.c
+
+tstwrbuf_LDADD = libutil.la
+tstwrbuf_SOURCES = tstwrbuf.c
+
+# MARC8 C conversion is generated from charconv.sgm
 marc8.c: charconv.sgm charconv.tcl
        cd $(srcdir); ./charconv.tcl -p marc8 -s 50 charconv.sgm marc8.c
 
index da88d7b..8f4653f 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: tsticonv.c,v 1.1 2003-04-23 20:34:08 adam Exp $
+ * $Id: tsticonv.c,v 1.2 2003-05-06 10:07:33 adam Exp $
  */
 
 #if HAVE_CONFIG_H
@@ -15,6 +15,7 @@
 
 #include <yaz/yaz-util.h>
 
+/* some test strings in ISO-8859-1 format */
 const char *buf[] = {
        "ax" ,
        "\330",
diff --git a/util/tstmatchstr.c b/util/tstmatchstr.c
new file mode 100644 (file)
index 0000000..bb8c9b1
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2002-2003, Index Data
+ * See the file LICENSE for details.
+ *
+ * $Id: tstmatchstr.c,v 1.1 2003-05-06 10:07:33 adam Exp $
+ */
+
+#include <stdio.h>
+
+#include <yaz/yaz-iconv.h>
+
+struct {
+    char *s1;
+    char *s2;
+    int res;
+} comp_strings[] = {
+    "x", "x", 0,
+    "x", "X", 0,
+    "a", "b", 1,
+    "b", "a", 1,
+    "aa","a", 1,
+    "a-", "a", 1,
+    "A-b", "ab", 0,
+    "A--b", "ab", 1,
+    "A--b", "a-b", 1,
+    "A--b", "a--b", 0,
+    "a123",  "a?", 0,
+    "a123",   "a1.3", 0,
+    "a123",   "..?", 0,
+    "a123",   "a1.", 1,
+    "a123",   "a...", 0,
+    0,     0, 0};
+
+int main (int argc, char **argv)
+{
+    int i;
+    for (i = 0; comp_strings[i].s1; i++)
+    {
+        int got = yaz_matchstr(comp_strings[i].s1,comp_strings[i].s2);
+        if (got > 0)
+            got = 1;
+        else if (got < 0)
+            got = -1;
+        if (got != comp_strings[i].res)
+        {
+            printf ("tststr %d got=%d res=%d\n", i,
+                    got, comp_strings[i].res);
+            exit(1);
+        }
+    }
+    exit(0);
+}
+
diff --git a/util/tstwrbuf.c b/util/tstwrbuf.c
new file mode 100644 (file)
index 0000000..c1c3f4a
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2002-2003, Index Data
+ * See the file LICENSE for details.
+ *
+ * $Id: tstwrbuf.c,v 1.1 2003-05-06 10:07:33 adam Exp $
+ */
+
+#include <stdio.h>
+
+#include <yaz/wrbuf.h>
+
+int main (int argc, char **argv)
+{
+    int step;
+    WRBUF wr = wrbuf_alloc();
+
+    wrbuf_free(wr, 1);
+
+    wr = wrbuf_alloc();
+
+    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);
+        if (len != step * (step-1) / 2)
+        {
+            printf ("tstwrbuf 1 %d len=%d\n", step, len);
+            exit(1);
+        }
+        k = 0;
+        for (j = 1; j<step; j++)
+            for (i = 0; i<j; i++)
+            {
+                if (cp[k] != i+1)
+                {
+                    printf ("tstwrbuf 2 %d k=%d\n", k);
+                    exit(1);
+                }
+                k++;
+            }
+        wrbuf_rewind(wr);
+    }
+    wrbuf_free(wr, 1);
+    exit(0);
+}
+