avoid disconnect on cancel
[oweals/gnunet.git] / src / datastore / test_datastore_api.c
index 1a753d2bf7d8c76ed9a46838d3ebaedc7cfda849..10a195cfb10eae5ef5efbeb7c3d70c7bce3a673c 100644 (file)
@@ -33,7 +33,7 @@
 
 #define VERBOSE GNUNET_NO
 
-#define START_DATASTORE GNUNET_NO
+#define START_DATASTORE GNUNET_YES
 
 /**
  * How long until we give up on transmitting the message?
@@ -111,10 +111,10 @@ enum RunPhase
     RP_PUT_MULTIPLE,
     RP_PUT_MULTIPLE_NEXT,
     RP_GET_MULTIPLE,
-    RP_GET_MULTIPLE_NEXT,
+    RP_GET_MULTIPLE_NEXT, /* 10 */
     RP_GET_MULTIPLE_DONE,
     RP_UPDATE,
-    RP_UPDATE_VALIDATE,
+    RP_UPDATE_VALIDATE, /* 13 */
     RP_UPDATE_DONE,
     RP_ERROR
   };
@@ -183,7 +183,7 @@ get_reserved (void *cls,
 static void 
 check_value (void *cls,
             const GNUNET_HashCode * key,
-            uint32_t size,
+            size_t size,
             const void *data,
             enum GNUNET_BLOCK_Type type,
             uint32_t priority,
@@ -221,7 +221,7 @@ check_value (void *cls,
 static void 
 delete_value (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
@@ -261,7 +261,7 @@ delete_value (void *cls,
 static void 
 check_nothing (void *cls,
               const GNUNET_HashCode * key,
-              uint32_t size,
+              size_t size,
               const void *data,
               enum GNUNET_BLOCK_Type type,
               uint32_t priority,
@@ -285,7 +285,7 @@ check_nothing (void *cls,
 static void 
 check_multiple (void *cls,
                const GNUNET_HashCode * key,
-               uint32_t size,
+               size_t size,
                const void *data,
                enum GNUNET_BLOCK_Type type,
                uint32_t priority,
@@ -299,6 +299,9 @@ check_multiple (void *cls,
     {
       if (crc->phase != RP_GET_MULTIPLE_DONE)
        {
+         fprintf (stderr, 
+                  "Wrong phase: %d\n",
+                  crc->phase);
          GNUNET_break (0);
          crc->phase = RP_ERROR;
        }
@@ -340,7 +343,7 @@ check_multiple (void *cls,
 static void 
 check_update (void *cls,
              const GNUNET_HashCode * key,
-             uint32_t size,
+             size_t size,
              const void *data,
              enum GNUNET_BLOCK_Type type,
              uint32_t priority,
@@ -352,8 +355,15 @@ check_update (void *cls,
 
   if (key == NULL)
     {
-      GNUNET_assert (crc->phase == RP_UPDATE_DONE);
-      crc->phase = RP_DONE;
+      if (crc->phase != RP_UPDATE_DONE)
+       {
+         GNUNET_break (0);
+         crc->phase = RP_ERROR;
+       }
+      else
+       {
+         crc->phase = RP_DONE;
+       }
       GNUNET_SCHEDULER_add_continuation (crc->sched,
                                         &run_continuation,
                                         crc,
@@ -572,6 +582,28 @@ run_continuation (void *cls,
 }
 
 
+static void
+run_tests (void *cls,
+          int success,
+          const char *msg)
+{
+  struct CpsRunContext *crc = cls;
+
+  if (success != GNUNET_YES)
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed with error `%s' database likely not setup, skipping test.",
+              msg);
+      GNUNET_free (crc);
+      return;
+    }
+  GNUNET_SCHEDULER_add_continuation (crc->sched,
+                                    &run_continuation,
+                                    crc,
+                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+}
+
+
 static void
 run (void *cls,
      struct GNUNET_SCHEDULER_Handle *sched,
@@ -580,6 +612,7 @@ run (void *cls,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct CpsRunContext *crc;
+  static GNUNET_HashCode zkey;
 
   crc = GNUNET_malloc(sizeof(struct CpsRunContext));
   crc->sched = sched;
@@ -587,15 +620,22 @@ run (void *cls,
   crc->phase = RP_PUT;
   now = GNUNET_TIME_absolute_get ();
   datastore = GNUNET_DATASTORE_connect (cfg, sched);
-  GNUNET_SCHEDULER_add_continuation (crc->sched,
-                                    &run_continuation,
-                                    crc,
-                                    GNUNET_SCHEDULER_REASON_PREREQ_DONE);
-
+  if (NULL ==
+      GNUNET_DATASTORE_put (datastore, 0,
+                           &zkey, 4, "TEST",
+                           GNUNET_BLOCK_TYPE_TEST,
+                           0, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
+                           0, 1, GNUNET_TIME_UNIT_MINUTES,
+                           &run_tests, crc))
+    {
+      fprintf (stderr,
+              "Test 'put' operation failed.\n");
+      ok = 1;
+      GNUNET_free (crc);
+    }
 }
 
 
-
 static int
 check ()
 {