1 /* $Id: tstisamb.c,v 1.1 2003-06-23 15:36:11 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003
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 Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include <yaz/xmalloc.h>
29 int compare_item(const void *a, const void *b)
33 memcpy(&ia, a, sizeof(int));
34 memcpy(&ib, b, sizeof(int));
38 void *code_start(int mode)
43 void code_item(int mode, void *p, char **dst, char **src)
45 memcpy (*dst, *src, sizeof(int));
46 (*dst) += sizeof(int);
47 (*src) += sizeof(int);
50 void code_reset(void *p)
53 void code_stop(int mode, void *p)
62 int code_read(void *vp, char **dst, int *insertMode)
64 struct read_info *ri = (struct read_info *)vp;
69 if (ri->no == ri->max)
72 memcpy (*dst, &x, sizeof(int));
80 void tst_insert(ISAMB isb, int n)
88 /* insert a number of entries */
92 isamc_i.clientData = &ri;
93 isamc_i.read_item = code_read;
95 isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
97 /* read the entries */
98 pp = isamb_pp_open (isb, isamc_p);
101 while(isamb_pp_read (pp, key_buf))
104 memcpy (&x, key_buf, sizeof(int));
107 yaz_log(LOG_DEBUG, "isamb_pp_read. Got %d (expected %d)",
115 yaz_log(LOG_DEBUG, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
120 isamb_unlink(isb, isamc_p);
123 int main(int argc, char **argv)
130 yaz_log_init_level(LOG_ALL);
132 /* setup method (attributes) */
133 method.compare_item = compare_item;
134 method.code_start = code_start;
135 method.code_item = code_item;
136 method.code_reset = code_reset;
137 method.code_stop = code_stop;
139 /* create block system */
140 bfs = bfs_create(0, 0);
143 yaz_log(LOG_DEBUG, "bfs_create failed");
147 /* create isam handle */
148 isb = isamb_open (bfs, "isamb", 1, &method, 0);
151 yaz_log(LOG_DEBUG, "isamb_open failed");
157 tst_insert(isb, 100);
158 tst_insert(isb, 500);
159 tst_insert(isb, 10000);
161 /* close isam handle */
164 /* exit block system */