aboutsummaryrefslogtreecommitdiff
path: root/src/consensus/test_consensus_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/consensus/test_consensus_api.c')
-rw-r--r--src/consensus/test_consensus_api.c120
1 files changed, 0 insertions, 120 deletions
diff --git a/src/consensus/test_consensus_api.c b/src/consensus/test_consensus_api.c
deleted file mode 100644
index 235a67484..000000000
--- a/src/consensus/test_consensus_api.c
+++ /dev/null
@@ -1,120 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
4
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.
9
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.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file consensus/test_consensus_api.c
23 * @brief testcase for consensus_api.c
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_consensus_service.h"
28#include "gnunet_testing_lib.h"
29
30
31static struct GNUNET_CONSENSUS_Handle *consensus;
32
33static struct GNUNET_HashCode session_id;
34
35static unsigned int elements_received;
36
37
38static void
39conclude_done (void *cls)
40{
41 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "conclude over\n");
42 if (2 != elements_received)
43 GNUNET_assert (0);
44 GNUNET_SCHEDULER_shutdown ();
45}
46
47
48static void
49on_new_element (void *cls,
50 const struct GNUNET_SET_Element *element)
51{
52 elements_received++;
53}
54
55
56static void
57insert_done (void *cls, int success)
58{
59 /* make sure cb is only called once */
60 static int called = GNUNET_NO;
61
62 GNUNET_assert (GNUNET_NO == called);
63 called = GNUNET_YES;
64 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "insert done\n");
65 GNUNET_CONSENSUS_conclude (consensus, &conclude_done, NULL);
66}
67
68
69/**
70 * Signature of the main function of a task.
71 *
72 * @param cls closure
73 */
74static void
75on_shutdown (void *cls)
76{
77 if (NULL != consensus)
78 {
79 GNUNET_CONSENSUS_destroy (consensus);
80 consensus = NULL;
81 }
82}
83
84
85static void
86run (void *cls,
87 const struct GNUNET_CONFIGURATION_Handle *cfg,
88 struct GNUNET_TESTING_Peer *peer)
89{
90 char *str = "foo";
91
92 struct GNUNET_SET_Element el1 = { 4, 0, "foo" };
93 struct GNUNET_SET_Element el2 = { 5, 0, "quux" };
94
95 GNUNET_log_setup ("test_consensus_api",
96 "INFO",
97 NULL);
98 GNUNET_SCHEDULER_add_shutdown (&on_shutdown, NULL);
99
100 GNUNET_CRYPTO_hash (str, strlen (str), &session_id);
101 consensus = GNUNET_CONSENSUS_create (cfg, 0, NULL, &session_id,
102 GNUNET_TIME_relative_to_absolute (
103 GNUNET_TIME_UNIT_SECONDS),
104 GNUNET_TIME_relative_to_absolute (
105 GNUNET_TIME_UNIT_MINUTES),
106 on_new_element, &consensus);
107 GNUNET_assert (consensus != NULL);
108
109 GNUNET_CONSENSUS_insert (consensus, &el1, NULL, &consensus);
110 GNUNET_CONSENSUS_insert (consensus, &el2, &insert_done, &consensus);
111}
112
113
114int
115main (int argc, char **argv)
116{
117 return GNUNET_TESTING_peer_run ("test_consensus_api",
118 "test_consensus.conf",
119 &run, NULL);
120}