2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file consensus/test_consensus_api.c
18 * @brief testcase for consensus_api.c
21 #include "gnunet_util_lib.h"
22 #include "gnunet_consensus_service.h"
23 #include "gnunet_testing_lib.h"
26 static struct GNUNET_CONSENSUS_Handle *consensus;
28 static struct GNUNET_HashCode session_id;
30 static unsigned int elements_received;
34 conclude_done (void *cls)
36 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
37 if (2 != elements_received)
39 GNUNET_SCHEDULER_shutdown ();
43 on_new_element (void *cls,
44 const struct GNUNET_SET_Element *element)
50 insert_done (void *cls, int success)
52 /* make sure cb is only called once */
53 static int called = GNUNET_NO;
54 GNUNET_assert (GNUNET_NO == called);
56 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
57 GNUNET_CONSENSUS_conclude (consensus, &conclude_done, NULL);
62 * Signature of the main function of a task.
67 on_shutdown (void *cls)
69 if (NULL != consensus)
71 GNUNET_CONSENSUS_destroy (consensus);
79 const struct GNUNET_CONFIGURATION_Handle *cfg,
80 struct GNUNET_TESTING_Peer *peer)
84 struct GNUNET_SET_Element el1 = {4, 0, "foo"};
85 struct GNUNET_SET_Element el2 = {5, 0, "quux"};
87 GNUNET_log_setup ("test_consensus_api",
90 GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
92 GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
93 consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
94 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_SECONDS),
95 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
96 on_new_element, &consensus);
97 GNUNET_assert (consensus != NULL);
99 GNUNET_CONSENSUS_insert (consensus, &el1, NULL, &consensus);
100 GNUNET_CONSENSUS_insert (consensus, &el2, &insert_done, &consensus);
105 main (int argc, char **argv)
107 return GNUNET_TESTING_peer_run ("test_consensus_api",
108 "test_consensus.conf",