/*
This file is part of GNUnet.
- Copyright (C) 2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2015 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
static const struct GNUNET_CONFIGURATION_Handle *config;
+static struct GNUNET_SCHEDULER_Task *tt;
+
static void
add_element_str (struct GNUNET_SET_Handle *set, char *str)
* Signature of the main function of a task.
*
* @param cls closure
- * @param tc context information (why was this task triggered now)
*/
static void
-timeout_fail (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+timeout_fail (void *cls)
{
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
+ tt = NULL;
GNUNET_SCHEDULER_shutdown ();
ret = 1;
}
}
-
-void
+static void
check_count (struct GNUNET_SET_Handle *set,
char *what,
unsigned int expected_count,
}
-void test_done (void *cls)
+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 ();
}
-void check_new_set_count (void *cls)
+static void
+check_new_set_count (void *cls)
{
- check_count (set2, "new set", 2, &test_done, NULL);
+ check_count (set2, "new set", 4, &test_done, NULL);
}
-void copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
+static void
+copy_done (void *cls, struct GNUNET_SET_Handle *new_set)
{
printf ("copy done\n");
set2 = new_set;
remove_element_str (set2, "spam");
+ add_element_str (set2, "new1");
+ add_element_str (set2, "new2");
+ remove_element_str (set2, "new2");
+ remove_element_str (set2, "new3");
// Check that set1 didn't change.
- check_count (set1, "old set", 3, &check_new_set_count, NULL);
+ check_count (set1, "old set", 3,
+ &check_new_set_count, NULL);
}
-void test_copy (void *cls)
+static void
+test_copy (void *cls)
{
printf ("about to copy\n");
GNUNET_SET_copy_lazy (set1, copy_done, NULL);
const struct GNUNET_CONFIGURATION_Handle *cfg,
struct GNUNET_TESTING_Peer *peer)
{
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
- &timeout_fail,
- NULL);
+ tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
+ &timeout_fail,
+ NULL);
config = cfg;
GNUNET_TESTING_peer_get_identity (peer,
set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
add_element_str (set1, "foo");
add_element_str (set1, "bar");
+ /* duplicate -- ignored */
+ add_element_str (set1, "bar");
remove_element_str (set1, "foo");
+ /* non-existent -- ignored */
+ remove_element_str (set1, "nonexist1");
add_element_str (set1, "spam");
+ /* duplicate -- ignored */
+ remove_element_str (set1, "foo");
add_element_str (set1, "eggs");
check_count (set1, "initial test", 3, &test_copy, NULL);
int
main (int argc, char **argv)
{
- if (0 != GNUNET_TESTING_peer_run ("test_set_api",
+ if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy",
"test_set.conf",
&run, NULL))
{