1 /* $Id: scantest.c,v 1.4 2005-04-29 18:43:30 adam Exp $
2 Copyright (C) 1995-2005
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
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;
47 printf ("pos=%d idx=%d name=%s\n", pos, idx, name);
52 hi->ar[idx] = malloc(strlen(name)+1);
53 strcpy(hi->ar[idx], name);
57 int tst(Dict dict, int before, int after, char *scan_term, char **cmp_strs,
60 struct handle_info hi;
65 hi.ar = malloc(sizeof(char*) * (after+before+1));
66 for (i = 0; i<after+before; i++)
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 int main(int argc, char **argv)
115 int before = 0, after = 0, number = 10000;
116 char scan_term[1024];
119 strcpy(scan_term, "1004");
120 while ((ret = options("b:a:t:n:v:", argv, argc, &arg)) != -2)
133 strcpy(scan_term, arg);
139 yaz_log_init_level(yaz_log_mask_str(arg));
143 bfs = bfs_create(".:100M", 0);
146 fprintf(stderr, "bfs_create failed\n");
149 dict = dict_open(bfs, "dict", 10, 1, 0, 0);
150 for (i = 10; i<number; i++)
155 r = dict_insert (dict, w, sizeof(int), &i);
158 if (after > 0 || before > 0)
159 tst(dict, before, after, scan_term, 0, 1);
169 strcpy(scan_term, "4499");
170 errors += tst(dict, 2, 2, scan_term, cs, 0);
179 strcpy(scan_term, "45");
180 errors += tst(dict, 2, 2, scan_term, cs, 0);