Added isamb_pp_forward test. Changed messages from test program from
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 2 Jun 2004 06:39:36 +0000 (06:39 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 2 Jun 2004 06:39:36 +0000 (06:39 +0000)
LOG_DEBUG to LOG_WARN so we see them! Test program calling bfs_reset.

isamb/tstisamb.c

index b990d82..78b65b0 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: tstisamb.c,v 1.2 2004-06-01 13:04:29 adam Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
+/* $Id: tstisamb.c,v 1.3 2004-06-02 06:39:36 adam Exp $
+   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
    Index Data Aps
 
 This file is part of the Zebra server.
@@ -77,6 +77,61 @@ int code_read(void *vp, char **dst, int *insertMode)
     return 1;
 }
 
+void tst_forward(ISAMB isb, int n)
+{
+    ISAMC_I isamc_i;
+    ISAMC_P isamc_p;
+    struct read_info ri;
+    int i;
+    ISAMB_PP pp;
+    char key_buf[10];
+
+    /* insert a number of entries */
+    ri.no = 0;
+    ri.max = n;
+
+    isamc_i.clientData = &ri;
+    isamc_i.read_item = code_read;
+    
+    isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
+
+    /* read the entries */
+    pp = isamb_pp_open (isb, isamc_p);
+    
+    for (i = 0; i<ri.max; i++)
+    {
+       int x = -1;
+       int xu = i;
+       isamb_pp_forward(pp, &x, &xu);
+       if (x != xu)
+       {
+           yaz_log(LOG_WARN, "isamb_pp_forward (1). Got %d (expected %d)",
+                   x, xu);
+           exit(4);
+       }
+       ri.no++;
+    }
+    isamb_pp_close(pp);
+    
+    pp = isamb_pp_open (isb, isamc_p);
+    for (i = 0; i<ri.max; i += 100)
+    {
+       int x = -1;
+       int xuntil = i;
+       isamb_pp_forward(pp, &x, &xuntil);
+       if (x != xuntil)
+       {
+           yaz_log(LOG_WARN, "isamb_pp_forward (2). Got %d (expected %d)",
+                   x, xuntil);
+           exit(4);
+       }
+       ri.no++;
+    }
+    isamb_pp_close(pp);
+
+    isamb_unlink(isb, isamc_p);
+}
+
 void tst_insert(ISAMB isb, int n)
 {
     ISAMC_I isamc_i;
@@ -104,7 +159,7 @@ void tst_insert(ISAMB isb, int n)
        memcpy (&x, key_buf, sizeof(int));
        if (x != ri.no)
        {
-           yaz_log(LOG_DEBUG, "isamb_pp_read. Got %d (expected %d)",
+           yaz_log(LOG_WARN, "isamb_pp_read. Got %d (expected %d)",
                    x, ri.no);
            exit(3);
        }
@@ -112,7 +167,7 @@ void tst_insert(ISAMB isb, int n)
     }
     if (ri.no != ri.max)
     {
-       yaz_log(LOG_DEBUG, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
+       yaz_log(LOG_WARN, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
        exit(3);
     }
     isamb_pp_close(pp);
@@ -120,7 +175,7 @@ void tst_insert(ISAMB isb, int n)
     isamb_unlink(isb, isamc_p);
 }
 
-static void log_item(int level, void *b, const char *txt)
+static void log_item(int level, const void *b, const char *txt)
 {
 }
 
@@ -129,7 +184,7 @@ int main(int argc, char **argv)
     BFiles bfs;
     ISAMB isb;
     ISAMC_M method;
-
+    
     if (argc == 2)
        yaz_log_init_level(LOG_ALL);
        
@@ -145,15 +200,17 @@ int main(int argc, char **argv)
     bfs = bfs_create(0, 0);
     if (!bfs)
     {
-       yaz_log(LOG_DEBUG, "bfs_create failed");
+       yaz_log(LOG_WARN, "bfs_create failed");
        exit(1);
     }
 
+    bf_reset(bfs);
+
     /* create isam handle */
     isb = isamb_open (bfs, "isamb", 1, &method, 0);
     if (!isb)
     {
-       yaz_log(LOG_DEBUG, "isamb_open failed");
+       yaz_log(LOG_WARN, "isamb_open failed");
        exit(2);
     }
     tst_insert(isb, 1);
@@ -162,7 +219,7 @@ int main(int argc, char **argv)
     tst_insert(isb, 100);
     tst_insert(isb, 500);
     tst_insert(isb, 10000);
-    
+    tst_forward(isb, 10000);
     /* close isam handle */
     isamb_close(isb);