Break long lines in debian/control
[idzebra-moved-to-github.git] / dict / scantest.c
index 79adf9f..45312ee 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the Zebra server.
-   Copyright (C) 1995-2008 Index Data
+   Copyright (C) 1994-2011 Index Data
 
 Zebra is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -17,6 +17,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 */
 
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -42,10 +45,9 @@ static int handler(char *name, const char *info, int pos, void *client)
     else
        idx = -pos - 1;
 
-    yaz_log(YLOG_DEBUG, "pos=%d idx=%d name=%s", pos, idx, name);
     if (idx < 0)
        return 0;
-    if (idx < hi->start_cut || idx >= hi->end_cut)
+    if (idx < hi->start_cut || idx > hi->end_cut)
     {
         return 1;
     }
@@ -72,7 +74,7 @@ int do_scan(Dict dict, int before, int after, const char *sterm,
     hi.a = after;
     hi.b = before;
     hi.ar = malloc(sizeof(char*) * (after+before+1));
-    for (i = 0; i<after+before; i++)
+    for (i = 0; i <= after+before; i++)
        hi.ar[i] = 0;
     yaz_log(YLOG_DEBUG, "dict_scan before=%d after=%d term=%s",
             before, after, scan_term);
@@ -81,7 +83,7 @@ int do_scan(Dict dict, int before, int after, const char *sterm,
     {
         if (!cmp_strs)
         {
-            if (i >= start_cut &&  i < end_cut)
+            if (i >= start_cut &&  i <= end_cut)
             {
                 if (!hi.ar[i])
                 {
@@ -100,7 +102,7 @@ int do_scan(Dict dict, int before, int after, const char *sterm,
         }
         else
        {
-            if (i >= start_cut && i < end_cut)
+            if (i >= start_cut && i <= end_cut)
             {
                 if (!hi.ar[i])
                 {
@@ -175,6 +177,7 @@ static void tst(Dict dict, int start, int number)
         YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 1);
     }
 
+#if 1
     {
         char *cs[] = {
             "4497",
@@ -183,6 +186,8 @@ static void tst(Dict dict, int start, int number)
             "45"};
         YAZ_CHECK_EQ(do_scan(dict, 2, 2, "4499", cs, 0, 0, 3), 0);
     }
+#endif
+#if 1
     {
         char *cs[] = {
             "4498",
@@ -191,9 +196,46 @@ static void tst(Dict dict, int start, int number)
             "450"};
         YAZ_CHECK_EQ(do_scan(dict, 2, 2, "45", cs, 0, 0, 3), 0);
     }
-
+#endif
+#if 1
+    /* bug 4592 */
+    {
+        char *cs[] = {
+            "4499",
+            "45", /* missing entry ! */
+            "450",
+            "4500"};
+        YAZ_CHECK_EQ(do_scan(dict, 4, 0, "4501", cs, 0, 0, 4), 0);
+    }
+#endif
+#if 1
+    {
+        char *cs[] = {
+            "9996",
+            "9997",
+            "9998",
+            "9999"};
+        YAZ_CHECK_EQ(do_scan(dict, 4, 0, "a", cs, 0, 0, 4), 0);
+        YAZ_CHECK_EQ(do_scan(dict, 3, 1, "9999", cs, 0, 0, 4), 0);
+    }
+#endif
+#if 1
+    {
+        char *cs[] = {
+            "10",
+            "100",
+            "1000",
+            "1001" };
+        YAZ_CHECK_EQ(do_scan(dict, 0, 4, "10", cs, 0, 0, 4), 0);
+        YAZ_CHECK_EQ(do_scan(dict, 0, 4, "1", cs, 0, 0, 4), 0);
+        YAZ_CHECK_EQ(do_scan(dict, 0, 4, " ", cs, 0, 0, 4), 0);
+        YAZ_CHECK_EQ(do_scan(dict, 0, 4, "", cs, 0, 0, 4), 0);
+    }
+#endif
+#if 1
     for (i = 0; i < 20; i++)
         YAZ_CHECK_EQ(do_scan(dict, 20, 20, "45", 0, 0, 20-i, 20+i), 0);
+#endif
 }
 
 int main(int argc, char **argv)
@@ -242,7 +284,7 @@ int main(int argc, char **argv)
     if (bfs)
     {
         bf_reset(bfs);
-        dict = dict_open(bfs, "dict", 10, 1, 0, 0);
+        dict = dict_open(bfs, "dict", 100, 1, 0, 0);
         YAZ_CHECK(dict);
     }
     if (dict)
@@ -270,6 +312,7 @@ int main(int argc, char **argv)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab