e2f91fc24c150993d2397d38e6152ad45698bfec
[egate.git] / util / gwdbtest.c
1 /* Gateway db utility test
2  * Europagate, 1995
3  *
4  * $Log: gwdbtest.c,v $
5  * Revision 1.1  1995/03/27 08:25:02  adam
6  * New module gip: Gateway IPc module.
7  * New module gw-db: Gateway hash-db module (user information table).
8  *
9  */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <assert.h>
14 #include <string.h>
15
16 #include <gw-db.h>
17
18 int main (int argc, char **argv)
19 {
20     char word[1024];
21     GW_DB gwdb;
22     int no;
23     void *buf;
24     size_t count;
25     int r;
26     int no_insert = 0;
27
28     gwdb = gw_db_open ("db.test", 1);
29     for (no = 0; scanf ("%s", word) == 1; no++)
30     {
31         r = gw_db_lookup (gwdb, word, strlen(word), & buf, &count);
32         if (r== 0)
33         {
34             char info[25];
35             sprintf (info, "%d", no);
36             if (gw_db_insert (gwdb, word, strlen(word), info, strlen (info)))
37             {
38                 printf ("gw_db_insert of %s failed\n", word);
39                 exit (1);
40             }
41             no_insert++;
42         }
43         else if (r == 1)
44         {
45             free (buf);
46         }
47         else
48         {
49             printf ("gw_db_lookup of %s failed\n", word);
50             exit (1);
51         }
52     }
53     gw_db_close (gwdb);
54     printf ("Lookup: %d. Insert: %d\n", no, no_insert);
55     exit (0);
56 }