(no commit message)
[oweals/gnunet.git] / src / fs / test_fs_namespace_list_updateable.c
index c2351471ec60fa082f5705bf04e19f2653cfa31f..359800f56f352c5de49e96db5a058c73ea3f0087 100644 (file)
 */
 
 /**
- * @file fs/test_fs_namespace.c
- * @brief Test for fs_namespace.c
+ * @file fs/test_fs_namespace_list_updateable.c
+ * @brief Test for fs_namespace_list_updateable.c
  * @author Christian Grothoff
- *
- * TODO:
- * - add timeout task
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -35,8 +32,6 @@
 
 #define START_ARM GNUNET_YES
 
-static struct GNUNET_SCHEDULER_Handle *sched;
-
 static struct PeerContext p1;
 
 static struct GNUNET_FS_Handle *fs;
@@ -58,7 +53,7 @@ struct PeerContext
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
 #if START_ARM
-  pid_t arm_pid;
+  struct GNUNET_OS_Process *arm_proc;
 #endif
 };
 
@@ -76,7 +71,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
 #if START_ARM
-  p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
+  p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
                                         "gnunet-service-arm",
 #if VERBOSE
                                         "-L", "DEBUG",
@@ -91,12 +86,14 @@ static void
 stop_arm (struct PeerContext *p)
 {
 #if START_ARM
-  if (0 != PLIBC_KILL (p->arm_pid, SIGTERM))
+  if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-  if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK)
+  if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "ARM process %u stopped\n", p->arm_pid);
+              "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
+  GNUNET_OS_process_close (p->arm_proc);
+  p->arm_proc = NULL;
 #endif
   if (uri_this != NULL)
     GNUNET_FS_uri_destroy (uri_this);
@@ -111,12 +108,62 @@ stop_arm (struct PeerContext *p)
 
 
 
+static void
+check_next (void *cls,
+           const char *last_id, 
+           const struct GNUNET_FS_Uri *last_uri,
+           const struct GNUNET_CONTAINER_MetaData *last_meta,
+           const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "next"));
+  GNUNET_break (0 == strcmp (next_id, "future"));
+  err -= 4;
+}
+
+
+static void
+check_this_next (void *cls,
+                const char *last_id, 
+                const struct GNUNET_FS_Uri *last_uri,
+                const struct GNUNET_CONTAINER_MetaData *last_meta,
+                const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "this"));
+  GNUNET_break (0 == strcmp (next_id, "next"));
+  err -= 2;
+  err += 4;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      next_id,
+                                      &check_next,
+                                      NULL);
+}
+
+
 static void
 sks_cont_next (void *cls,
               const struct GNUNET_FS_Uri *uri,
               const char *emsg)
 {
   GNUNET_assert (NULL == emsg);
+  err += 2;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      NULL,
+                                      &check_this_next,
+                                      NULL);
+
+}
+
+
+static void
+check_this (void *cls,
+           const char *last_id, 
+           const struct GNUNET_FS_Uri *last_uri,
+           const struct GNUNET_CONTAINER_MetaData *last_meta,
+           const char *next_id)
+{
+  GNUNET_break (0 == strcmp (last_id, "this"));
+  GNUNET_break (0 == strcmp (next_id, "next"));
+  err -= 1;
 }
 
 
@@ -126,7 +173,11 @@ sks_cont_this (void *cls,
               const char *emsg)
 {
   GNUNET_assert (NULL == emsg);
-
+  err = 1;
+  GNUNET_FS_namespace_list_updateable (ns,
+                                      NULL,
+                                      &check_this,
+                                      NULL);
   GNUNET_FS_publish_sks (fs,
                         ns,
                         "next",
@@ -173,15 +224,12 @@ testNamespace ()
 
 static void
 run (void *cls,
-     struct GNUNET_SCHEDULER_Handle *s,
      char *const *args,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
-  sched = s;
   setup_peer (&p1, "test_fs_namespace_data.conf");
-  fs = GNUNET_FS_start (sched,
-                       cfg,
+  fs = GNUNET_FS_start (cfg,
                        "test-fs-namespace",
                        &progress_cb,
                        NULL,