1 /* $Id: tstbfile1.c,v 1.6 2007-11-14 09:44:16 adam Exp $
2 Copyright (C) 1995-2007
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
25 #include <idzebra/bfile.h>
32 const char *more_info = 0;
35 bf = bf_xopen(bfs, "tst", /* block size */ 32,
36 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
40 bf_xclose(bf, version, "more info");
42 bf = bf_xopen(bfs, "tst", /* block size */ 32,
43 /* wr */ 1, "tstmagic", &version, &more_info);
49 YAZ_CHECK(strcmp(more_info, "more info") == 0);
50 bf_xclose(bf, version, 0 /* no more info */);
61 bf = bf_xopen(bfs, "tst", /* block size */ 32,
62 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
67 for (i = 1; i<30; i++)
72 YAZ_CHECK_EQ(bf_alloc(bf, i, blocks + bno), 0);
73 for (j = 0; j < i; j++)
75 YAZ_CHECK(blocks[bno + j]);
79 for (i = 0; i<bno; i++)
81 YAZ_CHECK_EQ(bf_free(bf, 1, blocks + i), 0);
83 bf_xclose(bf, version, 0);
98 for(i = 0; i<BLOCKS; i++)
101 bf = bf_xopen(bfs, "tst", /* block size */ 32,
102 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
107 for (pass = 0; pass < 100; pass++)
109 int r = random() % 9;
111 YAZ_CHECK(no_in_use >= 0);
112 YAZ_CHECK(no_in_use <= BLOCKS);
113 if (r < 5 && (BLOCKS - no_in_use) > 0)
117 zint tblocks[BLOCKS];
118 int left = BLOCKS - no_in_use;
119 int to_alloc = 1 + (random() % left);
121 bf_alloc(bf, to_alloc, tblocks);
122 /* transfer from tblocks to blocks */
123 for (i = 0; i<BLOCKS; i++)
127 blocks[i] = tblocks[j++];
134 else if (r < 8 && no_in_use > 0)
137 zint tblocks[BLOCKS];
138 int to_free = 1 + (random() % no_in_use);
139 int start = random() % to_free;
141 for (i = 0; i<BLOCKS; i++)
145 if (j >= start && j < to_free)
147 tblocks[j-start] = blocks[i];
154 YAZ_CHECK(tblocks[to_free-start-1]);
155 bf_free(bf, to_free - start, tblocks);
159 bf_xclose(bf, version, 0);
160 bf = bf_xopen(bfs, "tst", /* block size */ 32,
161 /* wr */ 1, "tstmagic", &version, 0 /* more_info */);
164 bf_xclose(bf, version, 0);
167 static void tst(void)
169 BFiles bfs = bfs_create(0, /* register: current dir, no limit */
170 0 /* base: current dir */
183 int main(int argc, char **argv)
185 YAZ_CHECK_INIT(argc, argv);
194 * indent-tabs-mode: nil
196 * vim: shiftwidth=4 tabstop=8 expandtab