1 /* $Id: tstbfile2.c,v 1.2 2006-11-08 13:05:33 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
29 #include <idzebra/bfile.h>
38 zint max_block = 200000;
40 YAZ_CHECK(block_size <= sizeof(buf));
41 if (!(block_size <= sizeof(buf)))
44 YAZ_CHECK(max_block * block_size < 4 * 1000000); /* 4M */
46 r = mkdir("register", 0777);
47 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
49 r = mkdir("shadow", 0777);
50 YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST));
52 bfs = bfs_create("register.bad:4M", 0 /* base: current dir */);
57 bfs = bfs_create("register:4M", 0 /* base: current dir */);
62 r = bf_cache(bfs, "shadow.bad:4M");
63 YAZ_CHECK_EQ(r, ZEBRA_FAIL);
65 r = bf_cache(bfs, "shadow:4M");
66 YAZ_CHECK_EQ(r, ZEBRA_OK);
71 /* we have to destroy bfs after reset. Unfortunately! */
74 bfs = bfs_create("register:4M", 0 /* base: current dir */);
79 r = bf_cache(bfs, "shadow:4M");
80 YAZ_CHECK_EQ(r, ZEBRA_OK);
83 bf = bf_open(bfs, "file", block_size, 1);
88 memset(buf, '\0', block_size);
92 while (bno[0] < max_block)
94 zint next = bno[0] + bno[1];
96 sprintf(buf, ZINT_FORMAT, bno[0]);
97 YAZ_CHECK_EQ(bf_write(bf, bno[0], 0, 0, buf), 0);
105 bf = bf_open(bfs, "file", block_size, 0);
113 while (bno[0] < max_block)
115 zint next = bno[0] + bno[1];
116 memset(buf, '\0', block_size);
118 YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1);
119 YAZ_CHECK_EQ(atoi(buf), bno[0]);
128 bf = bf_open(bfs, "file", block_size, 1);
133 while (bno < max_block)
135 memset(buf, '\0', block_size);
137 sprintf(buf, ZINT_FORMAT, bno);
138 YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0);
145 bf = bf_open(bfs, "file", block_size, 0);
150 while (bno < max_block)
152 memset(buf, '\0', block_size);
154 YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1);
155 YAZ_CHECK_EQ(atoi(buf), bno);
166 int main(int argc, char **argv)
168 YAZ_CHECK_INIT(argc, argv);