New module gip: Gateway IPc module.
[egate.git] / util / gwdbtest.c
diff --git a/util/gwdbtest.c b/util/gwdbtest.c
new file mode 100644 (file)
index 0000000..e2f91fc
--- /dev/null
@@ -0,0 +1,56 @@
+/* Gateway db utility test
+ * Europagate, 1995
+ *
+ * $Log: gwdbtest.c,v $
+ * Revision 1.1  1995/03/27 08:25:02  adam
+ * New module gip: Gateway IPc module.
+ * New module gw-db: Gateway hash-db module (user information table).
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <string.h>
+
+#include <gw-db.h>
+
+int main (int argc, char **argv)
+{
+    char word[1024];
+    GW_DB gwdb;
+    int no;
+    void *buf;
+    size_t count;
+    int r;
+    int no_insert = 0;
+
+    gwdb = gw_db_open ("db.test", 1);
+    for (no = 0; scanf ("%s", word) == 1; no++)
+    {
+        r = gw_db_lookup (gwdb, word, strlen(word), & buf, &count);
+        if (r== 0)
+       {
+           char info[25];
+           sprintf (info, "%d", no);
+           if (gw_db_insert (gwdb, word, strlen(word), info, strlen (info)))
+           {
+               printf ("gw_db_insert of %s failed\n", word);
+               exit (1);
+            }
+           no_insert++;
+       }
+       else if (r == 1)
+       {
+           free (buf);
+       }
+       else
+       {
+           printf ("gw_db_lookup of %s failed\n", word);
+           exit (1);
+       }
+    }
+    gw_db_close (gwdb);
+    printf ("Lookup: %d. Insert: %d\n", no, no_insert);
+    exit (0);
+}