IDZEBRA  2.2.7
inserttest.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #if HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <yaz/log.h>
27 #include <yaz/test.h>
28 #include <yaz/options.h>
29 #include <idzebra/dict.h>
30 
31 #define TERM_SIZE 150
32 #define USERINFO_SIZE 4
33 
34 int main(int argc, char **argv)
35 {
36  BFiles bfs = 0;
37  Dict dict = 0;
38  long no = 1000L;
39 
40  YAZ_CHECK_INIT(argc, argv);
41 
42  if (argc > 1)
43  no = atol(argv[1]);
44  bfs = bfs_create(".:40G", 0);
45  YAZ_CHECK(bfs);
46  if (bfs)
47  {
48  bf_reset(bfs);
49  dict = dict_open(bfs, "dict", 50, 1, 0, 4096);
50  YAZ_CHECK(dict);
51  }
52 
53  if (dict)
54  {
55  int pass;
56  for (pass = 0; pass < 2; pass++)
57  {
58  long i;
59  srandom(9);
60  for (i = 0; i < no; i++)
61  {
62  char userinfo[USERINFO_SIZE + 1];
63  int userlen = USERINFO_SIZE;
64  char lex[TERM_SIZE + 1];
65  int sz = 1 + (random() % (TERM_SIZE- 1));
66  int j;
67  for (j = 0; j < sz; j++)
68  {
69  lex[j] = 1 + (random() & 127L);
70  }
71  lex[j] = 0;
72  for (j = 0; j < userlen; j++)
73  {
74  userinfo[j] = sz + 1;
75  }
76  if (pass == 0)
77  {
78  dict_insert(dict, lex, userlen, userinfo);
79  }
80  else
81  {
82  char *info = dict_lookup(dict, lex);
83  YAZ_CHECK(info);
84  if (!info) {
85  break;
86  }
87  YAZ_CHECK_EQ(userlen, info[0]);
88  YAZ_CHECK(memcmp(userinfo, info + 1, userlen) == 0);
89  }
90  }
91  }
93  }
94 
95  if (bfs)
96  bfs_destroy(bfs);
97  YAZ_CHECK_TERM;
98 }
99 /*
100  * Local variables:
101  * c-basic-offset: 4
102  * c-file-style: "Stroustrup"
103  * indent-tabs-mode: nil
104  * End:
105  * vim: shiftwidth=4 tabstop=8 expandtab
106  */
void bf_reset(BFiles bfs)
Removes register and shadow completely.
Definition: bfile.c:268
BFiles bfs_create(const char *spec, const char *base)
creates a Block files collection
Definition: bfile.c:56
void bfs_destroy(BFiles bfiles)
destroys a block files handle
Definition: bfile.c:73
static void lex(struct DFA_parse *parse_info)
Definition: dfa.c:503
Zebra dictionary.
char * dict_lookup(Dict dict, const char *p)
lookup item in dictionary
Definition: lookup.c:100
Dict dict_open(BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size)
open dictionary
Definition: open.c:50
int dict_insert(Dict dict, const char *p, int userlen, void *userinfo)
insert item into dictionary
Definition: insert.c:439
int dict_close(Dict dict)
closes dictionary
Definition: close.c:32
static Dict dict
Definition: dicttest.c:35
int main(int argc, char **argv)
Definition: inserttest.c:34
#define TERM_SIZE
Definition: inserttest.c:31
#define USERINFO_SIZE
Definition: inserttest.c:32