1 /* $Id: scantest.c,v 1.7 2006-08-29 12:31:12 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)
110 char scan_term[1024];
117 strcpy(scan_term, "4499");
118 YAZ_CHECK_EQ(do_scan(dict, 2, 2, scan_term, cs, 0), 0);
126 strcpy(scan_term, "45");
127 YAZ_CHECK_EQ(do_scan(dict, 2, 2, scan_term, cs, 0), 0);
131 int main(int argc, char **argv)
138 int before = 0, after = 0, number = 10000;
139 char scan_term[1024];
142 YAZ_CHECK_INIT(argc, argv);
144 strcpy(scan_term, "1004");
145 while ((ret = options("b:a:t:n:v:", argv, argc, &arg)) != -2)
158 if (strlen(arg) >= sizeof(scan_term)-1)
160 fprintf(stderr, "scan term too long\n");
163 strcpy(scan_term, arg);
169 yaz_log_init_level(yaz_log_mask_str(arg));
173 bfs = bfs_create(".:100M", 0);
178 dict = dict_open(bfs, "dict", 10, 1, 0, 0);
183 /* Insert "10", "11", "12", .. "99", "100", ... number */
184 for (i = 10; i<number; i++)
188 YAZ_CHECK_EQ(dict_insert (dict, w, sizeof(int), &i), 0);
191 if (after > 0 || before > 0)
192 do_scan(dict, before, after, scan_term, 0, 1);
205 * indent-tabs-mode: nil
207 * vim: shiftwidth=4 tabstop=8 expandtab