1 /* $Id: tstbfile2.c,v 1.1 2006-11-08 12:59:27 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);
70 bf = bf_open(bfs, "file", block_size, 1);
75 memset(buf, '\0', block_size);
79 while (bno[0] < max_block)
81 zint next = bno[0] + bno[1];
83 sprintf(buf, ZINT_FORMAT, bno[0]);
84 YAZ_CHECK_EQ(bf_write(bf, bno[0], 0, 0, buf), 0);
92 bf = bf_open(bfs, "file", block_size, 0);
100 while (bno[0] < max_block)
102 zint next = bno[0] + bno[1];
103 memset(buf, '\0', block_size);
105 YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1);
106 YAZ_CHECK_EQ(atoi(buf), bno[0]);
115 bf = bf_open(bfs, "file", block_size, 1);
120 while (bno < max_block)
122 memset(buf, '\0', block_size);
124 sprintf(buf, ZINT_FORMAT, bno);
125 YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0);
132 bf = bf_open(bfs, "file", block_size, 0);
137 while (bno < max_block)
139 memset(buf, '\0', block_size);
141 YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1);
142 YAZ_CHECK_EQ(atoi(buf), bno);
153 int main(int argc, char **argv)
155 YAZ_CHECK_INIT(argc, argv);