2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file set/test_set_api.c
23 * @brief testcase for consensus_api.c
26 #include "gnunet_util_lib.h"
27 #include "gnunet_testing_lib.h"
28 #include "gnunet_set_service.h"
31 static struct GNUNET_PeerIdentity local_id;
33 static struct GNUNET_HashCode app_id;
34 static struct GNUNET_SET_Handle *set1;
35 static struct GNUNET_SET_Handle *set2;
36 static struct GNUNET_SET_ListenHandle *listen_handle;
37 const static struct GNUNET_CONFIGURATION_Handle *config;
43 result_cb_set1 (void *cls, const struct GNUNET_SET_Element *element,
44 enum GNUNET_SET_Status status)
48 case GNUNET_SET_STATUS_OK:
49 printf ("set 1: got element\n");
51 case GNUNET_SET_STATUS_FAILURE:
52 printf ("set 1: failure\n");
54 case GNUNET_SET_STATUS_DONE:
55 printf ("set 1: done\n");
56 GNUNET_SET_destroy (set1);
65 result_cb_set2 (void *cls, const struct GNUNET_SET_Element *element,
66 enum GNUNET_SET_Status status)
70 case GNUNET_SET_STATUS_OK:
71 printf ("set 2: got element\n");
73 case GNUNET_SET_STATUS_FAILURE:
74 printf ("set 2: failure\n");
76 case GNUNET_SET_STATUS_DONE:
77 printf ("set 2: done\n");
78 GNUNET_SET_destroy (set2);
88 const struct GNUNET_PeerIdentity *other_peer,
89 const struct GNUNET_MessageHeader *context_msg,
90 struct GNUNET_SET_Request *request)
92 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "listen cb called\n");
93 GNUNET_SET_listen_cancel (listen_handle);
95 GNUNET_SET_accept (request, set2,
96 GNUNET_SET_RESULT_ADDED, result_cb_set2, NULL);
101 * Start the set operation.
103 * @param cls closure, unused
108 listen_handle = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION,
109 &app_id, listen_cb, NULL);
110 GNUNET_SET_evaluate (set1, &local_id, &app_id, NULL, 42,
111 GNUNET_SET_RESULT_ADDED,
112 result_cb_set1, NULL);
117 * Initialize the second set, continue
119 * @param cls closure, unused
122 init_set2 (void *cls)
124 struct GNUNET_SET_Element element;
127 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initializing set 2\n");
129 element.data = "hello";
130 element.size = strlen(element.data);
131 GNUNET_SET_add_element (set2, &element, NULL, NULL);
132 element.data = "quux";
133 element.size = strlen(element.data);
134 GNUNET_SET_add_element (set2, &element, start, NULL);
139 * Initialize the first set, continue.
144 struct GNUNET_SET_Element element;
146 element.data = "hello";
147 element.size = strlen(element.data);
148 GNUNET_SET_add_element (set1, &element, NULL, NULL);
149 element.data = "bar";
150 element.size = strlen(element.data);
151 GNUNET_SET_add_element (set1, &element, init_set2, NULL);
153 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "initialized set 1\n");
158 * Signature of the 'main' function for a (single-peer) testcase that
159 * is run using 'GNUNET_TESTING_peer_run'.
162 * @param cfg configuration of the peer that was started
163 * @param peer identity of the peer that was created
167 const struct GNUNET_CONFIGURATION_Handle *cfg,
168 struct GNUNET_TESTING_Peer *peer)
171 static const char* app_str = "gnunet-set";
174 GNUNET_TESTING_peer_get_identity (peer, &local_id);
175 set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
176 set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION);
181 main (int argc, char **argv)
185 ret = GNUNET_TESTING_peer_run ("test_set_api",