2007.
[idzebra-moved-to-github.git] / bfile / tstbfile2.c
index 0b221c9..988d352 100644 (file)
@@ -1,5 +1,5 @@
-/* $Id: tstbfile2.c,v 1.1 2006-11-08 12:59:27 adam Exp $
-   Copyright (C) 1995-2006
+/* $Id: tstbfile2.c,v 1.4 2007-01-15 15:10:14 adam Exp $
+   Copyright (C) 1995-2007
    Index Data ApS
 
 This file is part of the Zebra server.
@@ -67,12 +67,26 @@ void tst(void)
 
     bf_reset(bfs);
 
+#if 1
+    /* we have to destroy bfs after reset. Unfortunately! */
+    bfs_destroy(bfs);
+
+    bfs = bfs_create("register:4M", 0 /* base: current dir */);
+    YAZ_CHECK(bfs);
+    if (!bfs)
+       return;
+
+    r = bf_cache(bfs, "shadow:4M");
+    YAZ_CHECK_EQ(r, ZEBRA_OK);
+#endif
+
+    yaz_log(YLOG_LOG, "writing file 1");
     bf = bf_open(bfs, "file", block_size, 1);
     YAZ_CHECK(bf);
     if (bf)
     {
        zint bno[2];
-       memset(buf, '\0', block_size);
+       memset(buf, ' ', block_size);
 
        bno[0] = 0;
        bno[1] = 1;
@@ -89,6 +103,7 @@ void tst(void)
        bf_close(bf);
     }
 
+    yaz_log(YLOG_LOG, "reading file 1");
     bf = bf_open(bfs, "file", block_size, 0);
     YAZ_CHECK(bf);
     if (bf)
@@ -100,7 +115,7 @@ void tst(void)
        while (bno[0] < max_block)
        {
            zint next = bno[0] + bno[1];
-           memset(buf, '\0', block_size);
+           memset(buf, ' ', block_size);
 
            YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1);
            YAZ_CHECK_EQ(atoi(buf), bno[0]);
@@ -112,6 +127,7 @@ void tst(void)
     }
 
 #if 1
+    yaz_log(YLOG_LOG, "writing file 2");
     bf = bf_open(bfs, "file", block_size, 1);
     YAZ_CHECK(bf);
     if (bf)
@@ -119,7 +135,7 @@ void tst(void)
        zint bno = 0;
        while (bno < max_block)
        {
-           memset(buf, '\0', block_size);
+           memset(buf, ' ', block_size);
 
            sprintf(buf, ZINT_FORMAT, bno);
            YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0);
@@ -129,19 +145,22 @@ void tst(void)
        bf_close(bf);
     }
 
+    yaz_log(YLOG_LOG, "reading file 2");
     bf = bf_open(bfs, "file", block_size, 0);
     YAZ_CHECK(bf);
     if (bf)
     {
        zint bno = 0;
+       int step = max_block / 50;
+       
        while (bno < max_block)
        {
-           memset(buf, '\0', block_size);
+           memset(buf, ' ', block_size);
 
            YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1);
            YAZ_CHECK_EQ(atoi(buf), bno);
 
-           bno = bno + 2;
+           bno = bno + 2*step;
        }
        bf_close(bf);
     }