1 /* $Id: tstisamb.c,v 1.8 2004-08-04 08:35:24 adam Exp $
2 Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
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 static void log_item(int level, const void *b, const char *txt)
32 memcpy(&x, b, sizeof(int));
33 yaz_log(LOG_DEBUG, "%s %d", txt, x);
36 static void log_pr(const char *txt)
38 yaz_log(LOG_DEBUG, "%s", txt);
41 int compare_item(const void *a, const void *b)
45 memcpy(&ia, a, sizeof(int));
46 memcpy(&ib, b, sizeof(int));
55 void code_item(void *p, char **dst, const char **src)
57 memcpy (*dst, *src, sizeof(int));
58 (*dst) += sizeof(int);
59 (*src) += sizeof(int);
62 void code_reset(void *p)
65 void code_stop(void *p)
74 int code_read(void *vp, char **dst, int *insertMode)
76 struct read_info *ri = (struct read_info *)vp;
81 if (ri->no == ri->max)
84 memcpy (*dst, &x, sizeof(int));
92 void tst_forward(ISAMB isb, int n)
100 /* insert a number of entries */
104 isamc_i.clientData = &ri;
105 isamc_i.read_item = code_read;
107 isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
109 /* read the entries */
110 pp = isamb_pp_open (isb, isamc_p);
112 for (i = 0; i<ri.max; i +=2 )
116 isamb_pp_forward(pp, &x, &xu);
117 if (x != xu && xu != x+1)
119 yaz_log(LOG_WARN, "isamb_pp_forward (1). Got %d (expected %d)",
127 pp = isamb_pp_open (isb, isamc_p);
128 for (i = 0; i<ri.max; i += 100)
132 isamb_pp_forward(pp, &x, &xu);
133 if (x != xu && xu != x+1)
135 yaz_log(LOG_WARN, "isamb_pp_forward (2). Got %d (expected %d)",
143 isamb_unlink(isb, isamc_p);
146 void tst_insert(ISAMB isb, int n)
154 /* insert a number of entries */
158 isamc_i.clientData = &ri;
159 isamc_i.read_item = code_read;
161 isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
163 /* read the entries */
164 pp = isamb_pp_open (isb, isamc_p);
167 while(isamb_pp_read (pp, key_buf))
170 memcpy (&x, key_buf, sizeof(int));
173 yaz_log(LOG_WARN, "isamb_pp_read. Got %d (expected %d)",
181 yaz_log(LOG_WARN, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
186 isamb_dump(isb, isamc_p, log_pr);
187 isamb_unlink(isb, isamc_p);
190 int main(int argc, char **argv)
197 yaz_log_init_level(LOG_ALL);
199 /* setup method (attributes) */
200 method.compare_item = compare_item;
201 method.log_item = log_item;
202 method.codec.start = code_start;
203 method.codec.encode = code_item;
204 method.codec.decode = code_item;
205 method.codec.reset = code_reset;
206 method.codec.stop = code_stop;
208 /* create block system */
209 bfs = bfs_create(0, 0);
212 yaz_log(LOG_WARN, "bfs_create failed");
218 /* create isam handle */
219 isb = isamb_open (bfs, "isamb", 1, &method, 0);
222 yaz_log(LOG_WARN, "isamb_open failed");
228 tst_insert(isb, 100);
229 tst_insert(isb, 500);
230 tst_insert(isb, 10000);
231 tst_forward(isb, 10000);
232 /* close isam handle */
235 /* exit block system */