1 /* $Id: scantest.c,v 1.9 2006-09-05 12:50:56 adam Exp $
2 Copyright (C) 1995-2006
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
28 #include <yaz/options.h>
29 #include <idzebra/dict.h>
39 static int handler(char *name, const char *info, int pos, void *client)
41 struct handle_info *hi = (struct handle_info *) client;
44 idx = hi->a - pos + hi->b;
48 yaz_log(YLOG_DEBUG, "pos=%d idx=%d name=%s", pos, idx, name);
51 if (idx < hi->start_cut || idx >= hi->end_cut)
56 hi->ar[idx] = malloc(strlen(name)+1);
57 strcpy(hi->ar[idx], name);
62 int do_scan(Dict dict, int before, int after, const char *sterm,
64 int verbose, int start_cut, int end_cut)
66 struct handle_info hi;
72 strcpy(scan_term, sterm);
73 hi.start_cut = start_cut;
77 hi.ar = malloc(sizeof(char*) * (after+before+1));
78 for (i = 0; i<after+before; i++)
80 yaz_log(YLOG_DEBUG, "dict_scan before=%d after=%d term=%s",
81 before, after, scan_term);
82 dict_scan (dict, scan_term, &before, &after, &hi, handler);
83 for (i = 0; i < hi.a+hi.b; i++)
87 if (i >= start_cut && i < end_cut)
91 printf ("--> FAIL i=%d hi.ar[i] == NULL\n", i);
99 printf ("--> FAIL i=%d hi.ar[i] = %s\n", i, hi.ar[i]);
106 if (i >= start_cut && i < end_cut)
110 printf ("--> FAIL i=%d strs == NULL\n", i);
113 else if (!cmp_strs[i])
115 printf ("--> FAIL i=%d cmp_strs == NULL\n", i);
118 else if (strcmp(cmp_strs[i], hi.ar[i]))
120 printf ("--> FAIL i=%d expected %s\n", i, cmp_strs[i]);
128 printf ("--> FAIL i=%d hi.ar[i] != NULL\n", i);
133 if (verbose || errors)
140 printf ("%s", hi.ar[i]);
152 static void tst(Dict dict, int start, int number)
156 /* insert again with original value again */
157 for (i = start; i < number; i += 100)
162 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 2);
164 /* insert again with different value */
165 for (i = start; i < number; i += 100)
170 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 1);
172 /* insert again with original value again */
173 for (i = start; i < number; i += 100)
178 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 1);
187 YAZ_CHECK_EQ(do_scan(dict, 2, 2, "4499", cs, 0, 0, 3), 0);
195 YAZ_CHECK_EQ(do_scan(dict, 2, 2, "45", cs, 0, 0, 3), 0);
198 for (i = 0; i < 20; i++)
199 YAZ_CHECK_EQ(do_scan(dict, 20, 20, "45", 0, 0, 20-i, 20+i), 0);
202 int main(int argc, char **argv)
208 int before = 0, after = 0, number = 10000;
209 char scan_term[1024];
212 YAZ_CHECK_INIT(argc, argv);
214 strcpy(scan_term, "1004");
215 while ((ret = options("b:a:t:n:v:", argv, argc, &arg)) != -2)
228 if (strlen(arg) >= sizeof(scan_term)-1)
230 fprintf(stderr, "scan term too long\n");
233 strcpy(scan_term, arg);
239 yaz_log_init_level(yaz_log_mask_str(arg));
243 bfs = bfs_create(".:100M", 0);
248 dict = dict_open(bfs, "dict", 10, 1, 0, 0);
254 /* Insert "10", "11", "12", .. "99", "100", ... number */
255 for (i = start; i<number; i++)
259 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(int), &i), 0);
262 if (after > 0 || before > 0)
263 do_scan(dict, before, after, scan_term, 0, 1, 0, after+1);
265 tst(dict, start, number);
276 * indent-tabs-mode: nil
278 * vim: shiftwidth=4 tabstop=8 expandtab