1 /* $Id: scantest.c,v 1.8 2006-08-29 13:39:48 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>
37 static int handler(char *name, const char *info, int pos, void *client)
39 struct handle_info *hi = (struct handle_info *) client;
42 idx = hi->a - pos + hi->b;
46 yaz_log(YLOG_DEBUG, "pos=%d idx=%d name=%s", pos, idx, name);
50 hi->ar[idx] = malloc(strlen(name)+1);
51 strcpy(hi->ar[idx], name);
55 int do_scan(Dict dict, int before, int after, char *scan_term, char **cmp_strs,
58 struct handle_info hi;
63 hi.ar = malloc(sizeof(char*) * (after+before+1));
64 for (i = 0; i<after+before; i++)
66 yaz_log(YLOG_DEBUG, "dict_scan before=%d after=%d term=%s",
67 before, after, scan_term);
68 dict_scan (dict, scan_term, &before, &after, &hi, handler);
69 for (i = 0; i<hi.a+hi.b; i++)
75 printf ("--> FAIL cmp_strs == NULL\n");
80 printf ("--> FAIL strs == NULL\n");
83 else if (strcmp(cmp_strs[i], hi.ar[i]))
85 printf ("--> FAIL expected %s\n", cmp_strs[i]);
89 if (verbose || errors)
96 printf ("%s", hi.ar[i]);
108 static void tst(Dict dict, int start, int number)
111 char scan_term[1024];
113 /* insert again with original value again */
114 for (i = start; i < number; i += 100)
119 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 2);
121 /* insert again with differnt value */
122 for (i = start; i < number; i += 100)
127 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 1);
129 /* insert again with original value again */
130 for (i = start; i < number; i += 100)
135 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(v), &v), 1);
144 strcpy(scan_term, "4499");
145 YAZ_CHECK_EQ(do_scan(dict, 2, 2, scan_term, cs, 0), 0);
153 strcpy(scan_term, "45");
154 YAZ_CHECK_EQ(do_scan(dict, 2, 2, scan_term, cs, 0), 0);
159 int main(int argc, char **argv)
165 int before = 0, after = 0, number = 10000;
166 char scan_term[1024];
169 YAZ_CHECK_INIT(argc, argv);
171 strcpy(scan_term, "1004");
172 while ((ret = options("b:a:t:n:v:", argv, argc, &arg)) != -2)
185 if (strlen(arg) >= sizeof(scan_term)-1)
187 fprintf(stderr, "scan term too long\n");
190 strcpy(scan_term, arg);
196 yaz_log_init_level(yaz_log_mask_str(arg));
200 bfs = bfs_create(".:100M", 0);
205 dict = dict_open(bfs, "dict", 10, 1, 0, 0);
211 /* Insert "10", "11", "12", .. "99", "100", ... number */
212 for (i = start; i<number; i++)
216 YAZ_CHECK_EQ(dict_insert(dict, w, sizeof(int), &i), 0);
219 if (after > 0 || before > 0)
220 do_scan(dict, before, after, scan_term, 0, 1);
222 tst(dict, start, number);
233 * indent-tabs-mode: nil
235 * vim: shiftwidth=4 tabstop=8 expandtab