From c8816fc1830fcfa92a58c82506fa665eeac8713c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 8 Nov 2006 12:59:27 +0000 Subject: [PATCH] Added test of bfile/cfile/mfile system --- bfile/.cvsignore | 3 + bfile/Makefile.am | 5 +- bfile/tstbfile2.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 bfile/tstbfile2.c diff --git a/bfile/.cvsignore b/bfile/.cvsignore index ea47524..d6368a2 100644 --- a/bfile/.cvsignore +++ b/bfile/.cvsignore @@ -5,3 +5,6 @@ Makefile.in *.lo *.la tstbfile1 +tstbfile2 +register +shadow diff --git a/bfile/Makefile.am b/bfile/Makefile.am index 1a0c021..552c686 100644 --- a/bfile/Makefile.am +++ b/bfile/Makefile.am @@ -1,12 +1,13 @@ -## $Id: Makefile.am,v 1.10 2006-07-05 15:03:44 adam Exp $ +## $Id: Makefile.am,v 1.11 2006-11-08 12:59:27 adam Exp $ noinst_LTLIBRARIES = libidzebra-bfile.la -check_PROGRAMS = tstbfile1 +check_PROGRAMS = tstbfile1 tstbfile2 TESTS = $(check_PROGRAMS) tstbfile1_SOURCES = tstbfile1.c +tstbfile2_SOURCES = tstbfile2.c AM_CPPFLAGS = -I$(top_srcdir)/include $(YAZINC) diff --git a/bfile/tstbfile2.c b/bfile/tstbfile2.c new file mode 100644 index 0000000..0b221c9 --- /dev/null +++ b/bfile/tstbfile2.c @@ -0,0 +1,159 @@ +/* $Id: tstbfile2.c,v 1.1 2006-11-08 12:59:27 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS + +This file is part of the Zebra server. + +Zebra is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Zebra is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include +#include +#include +#include +#include +#include +#include + +void tst(void) +{ + int r; + BFiles bfs; + BFile bf; + char buf[256]; + int block_size = 16; + zint max_block = 200000; + + YAZ_CHECK(block_size <= sizeof(buf)); + if (!(block_size <= sizeof(buf))) + return; + + YAZ_CHECK(max_block * block_size < 4 * 1000000); /* 4M */ + + r = mkdir("register", 0777); + YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST)); + + r = mkdir("shadow", 0777); + YAZ_CHECK(r == 0 || (r == -1 && errno == EEXIST)); + + bfs = bfs_create("register.bad:4M", 0 /* base: current dir */); + YAZ_CHECK(!bfs); + if (bfs) + return; + + bfs = bfs_create("register:4M", 0 /* base: current dir */); + YAZ_CHECK(bfs); + if (!bfs) + return; + + r = bf_cache(bfs, "shadow.bad:4M"); + YAZ_CHECK_EQ(r, ZEBRA_FAIL); + + r = bf_cache(bfs, "shadow:4M"); + YAZ_CHECK_EQ(r, ZEBRA_OK); + + bf_reset(bfs); + + bf = bf_open(bfs, "file", block_size, 1); + YAZ_CHECK(bf); + if (bf) + { + zint bno[2]; + memset(buf, '\0', block_size); + + bno[0] = 0; + bno[1] = 1; + while (bno[0] < max_block) + { + zint next = bno[0] + bno[1]; + + sprintf(buf, ZINT_FORMAT, bno[0]); + YAZ_CHECK_EQ(bf_write(bf, bno[0], 0, 0, buf), 0); + + bno[0] = bno[1]; + bno[1] = next; + } + bf_close(bf); + } + + bf = bf_open(bfs, "file", block_size, 0); + YAZ_CHECK(bf); + if (bf) + { + zint bno[2]; + + bno[0] = 0; + bno[1] = 1; + while (bno[0] < max_block) + { + zint next = bno[0] + bno[1]; + memset(buf, '\0', block_size); + + YAZ_CHECK_EQ(bf_read(bf, bno[0], 0, 0, buf), 1); + YAZ_CHECK_EQ(atoi(buf), bno[0]); + + bno[0] = bno[1]; + bno[1] = next; + } + bf_close(bf); + } + +#if 1 + bf = bf_open(bfs, "file", block_size, 1); + YAZ_CHECK(bf); + if (bf) + { + zint bno = 0; + while (bno < max_block) + { + memset(buf, '\0', block_size); + + sprintf(buf, ZINT_FORMAT, bno); + YAZ_CHECK_EQ(bf_write(bf, bno, 0, 0, buf), 0); + + bno = bno + 2; + } + bf_close(bf); + } + + bf = bf_open(bfs, "file", block_size, 0); + YAZ_CHECK(bf); + if (bf) + { + zint bno = 0; + while (bno < max_block) + { + memset(buf, '\0', block_size); + + YAZ_CHECK_EQ(bf_read(bf, bno, 0, 0, buf), 1); + YAZ_CHECK_EQ(atoi(buf), bno); + + bno = bno + 2; + } + bf_close(bf); + } +#endif + bfs_destroy(bfs); +} + + +int main(int argc, char **argv) +{ + YAZ_CHECK_INIT(argc, argv); + tst(); + YAZ_CHECK_TERM; +} + -- 1.7.10.4