1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <idzebra/bfile.h>
29 const char *more_info = 0;
32 bf = bf_xopen(bfs, "tst", /* block size */ 32,
33 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
37 bf_xclose(bf, version, "more info");
39 bf = bf_xopen(bfs, "tst", /* block size */ 32,
40 /* wr */ 1, "tstmagic", &version, &more_info);
46 YAZ_CHECK(strcmp(more_info, "more info") == 0);
47 bf_xclose(bf, version, 0 /* no more info */);
58 bf = bf_xopen(bfs, "tst", /* block size */ 32,
59 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
64 for (i = 1; i<30; i++)
69 YAZ_CHECK_EQ(bf_alloc(bf, i, blocks + bno), 0);
70 for (j = 0; j < i; j++)
72 YAZ_CHECK(blocks[bno + j]);
76 for (i = 0; i<bno; i++)
78 YAZ_CHECK_EQ(bf_free(bf, 1, blocks + i), 0);
80 bf_xclose(bf, version, 0);
95 for(i = 0; i<BLOCKS; i++)
98 bf = bf_xopen(bfs, "tst", /* block size */ 32,
99 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
104 for (pass = 0; pass < 100; pass++)
106 int r = random() % 9;
108 YAZ_CHECK(no_in_use >= 0);
109 YAZ_CHECK(no_in_use <= BLOCKS);
110 if (r < 5 && (BLOCKS - no_in_use) > 0)
114 zint tblocks[BLOCKS];
115 int left = BLOCKS - no_in_use;
116 int to_alloc = 1 + (random() % left);
118 bf_alloc(bf, to_alloc, tblocks);
119 /* transfer from tblocks to blocks */
120 for (i = 0; i<BLOCKS; i++)
124 blocks[i] = tblocks[j++];
131 else if (r < 8 && no_in_use > 0)
134 zint tblocks[BLOCKS];
135 int to_free = 1 + (random() % no_in_use);
136 int start = random() % to_free;
138 for (i = 0; i<BLOCKS; i++)
142 if (j >= start && j < to_free)
144 tblocks[j-start] = blocks[i];
151 YAZ_CHECK(tblocks[to_free-start-1]);
152 bf_free(bf, to_free - start, tblocks);
156 bf_xclose(bf, version, 0);
157 bf = bf_xopen(bfs, "tst", /* block size */ 32,
158 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
161 bf_xclose(bf, version, 0);
164 static void tst(void)
166 BFiles bfs = bfs_create(0, /* register: current dir, no limit */
167 0 /* base: current dir */
180 int main(int argc, char **argv)
182 YAZ_CHECK_INIT(argc, argv);
191 * c-file-style: "Stroustrup"
192 * indent-tabs-mode: nil
194 * vim: shiftwidth=4 tabstop=8 expandtab