gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37716 - gnunet/src/set


From: gnunet
Subject: [GNUnet-SVN] r37716 - gnunet/src/set
Date: Sun, 14 Aug 2016 13:19:58 +0200

Author: grothoff
Date: 2016-08-14 13:19:58 +0200 (Sun, 14 Aug 2016)
New Revision: 37716

Modified:
   gnunet/src/set/test_set_union_copy.c
Log:
-fix testcase shutdown

Modified: gnunet/src/set/test_set_union_copy.c
===================================================================
--- gnunet/src/set/test_set_union_copy.c        2016-08-14 10:22:51 UTC (rev 
37715)
+++ gnunet/src/set/test_set_union_copy.c        2016-08-14 11:19:58 UTC (rev 
37716)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2015 GNUnet e.V.
+     Copyright (C) 2015, 2016 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -21,6 +21,7 @@
 /**
  * @file set/test_set_union_copy.c
  * @brief testcase for lazy copying of union sets
+ * @author Florian Dold
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
@@ -46,7 +47,8 @@
 
 
 static void
-add_element_str (struct GNUNET_SET_Handle *set, char *str)
+add_element_str (struct GNUNET_SET_Handle *set,
+                 char *str)
 {
   struct GNUNET_SET_Element element;
 
@@ -53,13 +55,16 @@
   element.element_type = 0;
   element.data = str;
   element.size = strlen (str);
-
-  GNUNET_SET_add_element (set, &element, NULL, NULL);
+  GNUNET_SET_add_element (set,
+                          &element,
+                          NULL,
+                          NULL);
 }
 
 
 static void
-remove_element_str (struct GNUNET_SET_Handle *set, char *str)
+remove_element_str (struct GNUNET_SET_Handle *set,
+                    char *str)
 {
   struct GNUNET_SET_Element element;
 
@@ -66,8 +71,10 @@
   element.element_type = 0;
   element.data = str;
   element.size = strlen (str);
-
-  GNUNET_SET_remove_element (set, &element, NULL, NULL);
+  GNUNET_SET_remove_element (set,
+                             &element,
+                             NULL,
+                             NULL);
 }
 
 
@@ -84,14 +91,12 @@
   ret = 1;
 }
 
-typedef void (*Continuation) (void *cls);
 
-
 struct CountIterClosure
 {
   unsigned int expected_count;
   unsigned int ongoing_count;
-  Continuation cont;
+  GNUNET_SCHEDULER_TaskCallback cont;
   void *cont_cls;
   char *what;
 };
@@ -127,7 +132,7 @@
 check_count (struct GNUNET_SET_Handle *set,
              char *what,
              unsigned int expected_count,
-             Continuation cont,
+             GNUNET_SCHEDULER_TaskCallback cont,
              void *cont_cls)
 {
   struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure);
@@ -138,7 +143,10 @@
   ci_cls->cont_cls = cont_cls;
   ci_cls->what = what;
 
-  GNUNET_assert (GNUNET_YES == GNUNET_SET_iterate (set, check_count_iter, 
ci_cls));
+  GNUNET_assert (GNUNET_YES ==
+                 GNUNET_SET_iterate (set,
+                                     &check_count_iter,
+                                     ci_cls));
 }
 
 
@@ -145,12 +153,6 @@
 static void
 test_done (void *cls)
 {
-  if (NULL != set1)
-    GNUNET_SET_destroy (set1);
-  if (NULL != set2)
-    GNUNET_SET_destroy (set2);
-  GNUNET_SCHEDULER_cancel (tt);
-  tt = NULL;
   GNUNET_SCHEDULER_shutdown ();
 }
 
@@ -158,12 +160,17 @@
 static void
 check_new_set_count (void *cls)
 {
-  check_count (set2, "new set", 4, &test_done, NULL);
+  check_count (set2,
+               "new set",
+               4,
+               &test_done,
+               NULL);
 }
 
 
 static void
-copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
+copy_done (void *cls,
+           struct GNUNET_SET_Handle *new_set)
 {
   printf ("copy done\n");
   set2 = new_set;
@@ -174,7 +181,8 @@
   remove_element_str (set2, "new3");
   // Check that set1 didn't change.
   check_count (set1, "old set", 3,
-               &check_new_set_count, NULL);
+               &check_new_set_count,
+               NULL);
 }
 
 
@@ -182,14 +190,41 @@
 test_copy (void *cls)
 {
   printf ("about to copy\n");
-  GNUNET_SET_copy_lazy (set1, copy_done, NULL);
+  GNUNET_SET_copy_lazy (set1,
+                        &copy_done,
+                        NULL);
 }
 
 
+/**
+ * Function run on shutdown.
+ *
+ * @param cls closure
+ */
+static void
+do_shutdown (void *cls)
+{
+  if (NULL != tt)
+  {
+    GNUNET_SCHEDULER_cancel (tt);
+    tt = NULL;
+  }
+  if (NULL != set1)
+  {
+    GNUNET_SET_destroy (set1);
+    set1 = NULL;
+  }
+  if (NULL != set2)
+  {
+    GNUNET_SET_destroy (set2);
+    set2 = NULL;
+  }
+}
 
+
 /**
  * Signature of the 'main' function for a (single-peer) testcase that
- * is run using 'GNUNET_TESTING_peer_run'.
+ * is run using #GNUNET_TESTING_peer_run().
  *
  * @param cls closure
  * @param cfg configuration of the peer that was started
@@ -202,8 +237,9 @@
 {
   tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 5),
                                     &timeout_fail,
-                                    NULL);
-
+                                     NULL);
+  GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+                                 NULL);
   config = cfg;
   GNUNET_TESTING_peer_get_identity (peer,
                                     &local_id);
@@ -221,7 +257,11 @@
   remove_element_str (set1, "foo");
   add_element_str (set1, "eggs");
 
-  check_count (set1, "initial test", 3, &test_copy, NULL);
+  check_count (set1,
+               "initial test",
+               3,
+               &test_copy,
+               NULL);
 }
 
 
@@ -232,7 +272,8 @@
                                     "test_set.conf",
                                     &run, NULL))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failed to start testing peer\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "failed to start testing peer\n");
     return 1;
   }
   return ret;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]