aboutsummaryrefslogtreecommitdiff
path: root/src/set/test_set_union_copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/test_set_union_copy.c')
-rw-r--r--src/set/test_set_union_copy.c282
1 files changed, 142 insertions, 140 deletions
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c
index ab76668cc..908527017 100644
--- a/src/set/test_set_union_copy.c
+++ b/src/set/test_set_union_copy.c
@@ -47,34 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt;
47 47
48 48
49static void 49static void
50add_element_str(struct GNUNET_SET_Handle *set, 50add_element_str (struct GNUNET_SET_Handle *set,
51 char *str) 51 char *str)
52{ 52{
53 struct GNUNET_SET_Element element; 53 struct GNUNET_SET_Element element;
54 54
55 element.element_type = 0; 55 element.element_type = 0;
56 element.data = str; 56 element.data = str;
57 element.size = strlen(str); 57 element.size = strlen (str);
58 GNUNET_SET_add_element(set, 58 GNUNET_SET_add_element (set,
59 &element, 59 &element,
60 NULL, 60 NULL,
61 NULL); 61 NULL);
62} 62}
63 63
64 64
65static void 65static void
66remove_element_str(struct GNUNET_SET_Handle *set, 66remove_element_str (struct GNUNET_SET_Handle *set,
67 char *str) 67 char *str)
68{ 68{
69 struct GNUNET_SET_Element element; 69 struct GNUNET_SET_Element element;
70 70
71 element.element_type = 0; 71 element.element_type = 0;
72 element.data = str; 72 element.data = str;
73 element.size = strlen(str); 73 element.size = strlen (str);
74 GNUNET_SET_remove_element(set, 74 GNUNET_SET_remove_element (set,
75 &element, 75 &element,
76 NULL, 76 NULL,
77 NULL); 77 NULL);
78} 78}
79 79
80 80
@@ -84,15 +84,16 @@ remove_element_str(struct GNUNET_SET_Handle *set,
84 * @param cls closure 84 * @param cls closure
85 */ 85 */
86static void 86static void
87timeout_fail(void *cls) 87timeout_fail (void *cls)
88{ 88{
89 tt = NULL; 89 tt = NULL;
90 GNUNET_SCHEDULER_shutdown(); 90 GNUNET_SCHEDULER_shutdown ();
91 ret = 1; 91 ret = 1;
92} 92}
93 93
94 94
95struct CountIterClosure { 95struct CountIterClosure
96{
96 unsigned int expected_count; 97 unsigned int expected_count;
97 unsigned int ongoing_count; 98 unsigned int ongoing_count;
98 GNUNET_SCHEDULER_TaskCallback cont; 99 GNUNET_SCHEDULER_TaskCallback cont;
@@ -102,33 +103,33 @@ struct CountIterClosure {
102 103
103 104
104static int 105static int
105check_count_iter(void *cls, 106check_count_iter (void *cls,
106 const struct GNUNET_SET_Element *element) 107 const struct GNUNET_SET_Element *element)
107{ 108{
108 struct CountIterClosure *ci_cls = cls; 109 struct CountIterClosure *ci_cls = cls;
109 110
110 if (NULL == element) 111 if (NULL == element)
112 {
113 if (ci_cls->expected_count != ci_cls->ongoing_count)
111 { 114 {
112 if (ci_cls->expected_count != ci_cls->ongoing_count) 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 { 116 "Expected count (what: %s) to be %u, but it's actually %u\n",
114 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 117 ci_cls->what,
115 "Expected count (what: %s) to be %u, but it's actually %u\n", 118 ci_cls->expected_count,
116 ci_cls->what, 119 ci_cls->ongoing_count);
117 ci_cls->expected_count, 120 ret = 1;
118 ci_cls->ongoing_count); 121 GNUNET_SCHEDULER_shutdown ();
119 ret = 1;
120 GNUNET_SCHEDULER_shutdown();
121 return GNUNET_NO;
122 }
123 ci_cls->cont(ci_cls->cont_cls);
124 GNUNET_free(ci_cls);
125 return GNUNET_NO; 122 return GNUNET_NO;
126 } 123 }
127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 124 ci_cls->cont (ci_cls->cont_cls);
128 "Set `%s' has element %.*s\n", 125 GNUNET_free (ci_cls);
129 ci_cls->what, 126 return GNUNET_NO;
130 (int)element->size, 127 }
131 (const char *)element->data); 128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Set `%s' has element %.*s\n",
130 ci_cls->what,
131 (int) element->size,
132 (const char *) element->data);
132 133
133 ci_cls->ongoing_count++; 134 ci_cls->ongoing_count++;
134 return GNUNET_YES; 135 return GNUNET_YES;
@@ -136,17 +137,17 @@ check_count_iter(void *cls,
136 137
137 138
138static void 139static void
139check_count(struct GNUNET_SET_Handle *set, 140check_count (struct GNUNET_SET_Handle *set,
140 char *what, 141 char *what,
141 unsigned int expected_count, 142 unsigned int expected_count,
142 GNUNET_SCHEDULER_TaskCallback cont, 143 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 144 void *cont_cls)
144{ 145{
145 struct CountIterClosure *ci_cls = GNUNET_new(struct CountIterClosure); 146 struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure);
146 147
147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Checking count of %s\n", 149 "Checking count of %s\n",
149 what); 150 what);
150 151
151 ci_cls->expected_count = expected_count; 152 ci_cls->expected_count = expected_count;
152 ci_cls->ongoing_count = 0; 153 ci_cls->ongoing_count = 0;
@@ -154,65 +155,65 @@ check_count(struct GNUNET_SET_Handle *set,
154 ci_cls->cont_cls = cont_cls; 155 ci_cls->cont_cls = cont_cls;
155 ci_cls->what = what; 156 ci_cls->what = what;
156 157
157 GNUNET_assert(GNUNET_YES == 158 GNUNET_assert (GNUNET_YES ==
158 GNUNET_SET_iterate(set, 159 GNUNET_SET_iterate (set,
159 &check_count_iter, 160 &check_count_iter,
160 ci_cls)); 161 ci_cls));
161} 162}
162 163
163 164
164static void 165static void
165test_done(void *cls) 166test_done (void *cls)
166{ 167{
167 GNUNET_SCHEDULER_shutdown(); 168 GNUNET_SCHEDULER_shutdown ();
168} 169}
169 170
170 171
171static void 172static void
172check_new_set_count(void *cls) 173check_new_set_count (void *cls)
173{ 174{
174 check_count(set2, 175 check_count (set2,
175 "new set", 176 "new set",
176 3, 177 3,
177 &test_done, 178 &test_done,
178 NULL); 179 NULL);
179} 180}
180 181
181 182
182static void 183static void
183copy_done(void *cls, 184copy_done (void *cls,
184 struct GNUNET_SET_Handle *new_set) 185 struct GNUNET_SET_Handle *new_set)
185{ 186{
186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "copy done\n"); 188 "copy done\n");
188 set2 = new_set; 189 set2 = new_set;
189 remove_element_str(set2, 190 remove_element_str (set2,
190 "k5555"); 191 "k5555");
191 add_element_str(set2, 192 add_element_str (set2,
192 "n66666"); 193 "n66666");
193 add_element_str(set2, 194 add_element_str (set2,
194 "new2butremoved"); 195 "new2butremoved");
195 remove_element_str(set2, 196 remove_element_str (set2,
196 "new2butremoved"); 197 "new2butremoved");
197 remove_element_str(set2, 198 remove_element_str (set2,
198 "new3justremoved"); 199 "new3justremoved");
199 // Check that set1 didn't change. 200 // Check that set1 didn't change.
200 check_count(set1, 201 check_count (set1,
201 "old set", 202 "old set",
202 3, 203 3,
203 &check_new_set_count, 204 &check_new_set_count,
204 NULL); 205 NULL);
205} 206}
206 207
207 208
208static void 209static void
209test_copy(void *cls) 210test_copy (void *cls)
210{ 211{
211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
212 "about to copy\n"); 213 "about to copy\n");
213 GNUNET_SET_copy_lazy(set1, 214 GNUNET_SET_copy_lazy (set1,
214 &copy_done, 215 &copy_done,
215 NULL); 216 NULL);
216} 217}
217 218
218 219
@@ -222,23 +223,23 @@ test_copy(void *cls)
222 * @param cls closure 223 * @param cls closure
223 */ 224 */
224static void 225static void
225do_shutdown(void *cls) 226do_shutdown (void *cls)
226{ 227{
227 if (NULL != tt) 228 if (NULL != tt)
228 { 229 {
229 GNUNET_SCHEDULER_cancel(tt); 230 GNUNET_SCHEDULER_cancel (tt);
230 tt = NULL; 231 tt = NULL;
231 } 232 }
232 if (NULL != set1) 233 if (NULL != set1)
233 { 234 {
234 GNUNET_SET_destroy(set1); 235 GNUNET_SET_destroy (set1);
235 set1 = NULL; 236 set1 = NULL;
236 } 237 }
237 if (NULL != set2) 238 if (NULL != set2)
238 { 239 {
239 GNUNET_SET_destroy(set2); 240 GNUNET_SET_destroy (set2);
240 set2 = NULL; 241 set2 = NULL;
241 } 242 }
242} 243}
243 244
244 245
@@ -251,59 +252,60 @@ do_shutdown(void *cls)
251 * @param peer identity of the peer that was created 252 * @param peer identity of the peer that was created
252 */ 253 */
253static void 254static void
254run(void *cls, 255run (void *cls,
255 const struct GNUNET_CONFIGURATION_Handle *cfg, 256 const struct GNUNET_CONFIGURATION_Handle *cfg,
256 struct GNUNET_TESTING_Peer *peer) 257 struct GNUNET_TESTING_Peer *peer)
257{ 258{
258 tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 259 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
259 &timeout_fail, 260 GNUNET_TIME_UNIT_SECONDS, 5),
260 NULL); 261 &timeout_fail,
261 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, 262 NULL);
262 NULL); 263 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
264 NULL);
263 config = cfg; 265 config = cfg;
264 GNUNET_TESTING_peer_get_identity(peer, 266 GNUNET_TESTING_peer_get_identity (peer,
265 &local_id); 267 &local_id);
266 268
267 set1 = GNUNET_SET_create(cfg, 269 set1 = GNUNET_SET_create (cfg,
268 GNUNET_SET_OPERATION_UNION); 270 GNUNET_SET_OPERATION_UNION);
269 add_element_str(set1, 271 add_element_str (set1,
270 "333"); 272 "333");
271 add_element_str(set1, 273 add_element_str (set1,
272 "k444"); 274 "k444");
273 /* duplicate -- ignored */ 275 /* duplicate -- ignored */
274 add_element_str(set1, 276 add_element_str (set1,
275 "k444"); 277 "k444");
276 remove_element_str(set1, 278 remove_element_str (set1,
277 "333"); 279 "333");
278 /* non-existent -- ignored */ 280 /* non-existent -- ignored */
279 remove_element_str(set1, 281 remove_element_str (set1,
280 "999999999"); 282 "999999999");
281 add_element_str(set1, 283 add_element_str (set1,
282 "k5555"); 284 "k5555");
283 /* duplicate -- ignored */ 285 /* duplicate -- ignored */
284 remove_element_str(set1, 286 remove_element_str (set1,
285 "333"); 287 "333");
286 add_element_str(set1, 288 add_element_str (set1,
287 "k2"); 289 "k2");
288 290
289 check_count(set1, 291 check_count (set1,
290 "initial test", 292 "initial test",
291 3, 293 3,
292 &test_copy, 294 &test_copy,
293 NULL); 295 NULL);
294} 296}
295 297
296 298
297int 299int
298main(int argc, char **argv) 300main (int argc, char **argv)
299{ 301{
300 if (0 != GNUNET_TESTING_peer_run("test_set_union_copy", 302 if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy",
301 "test_set.conf", 303 "test_set.conf",
302 &run, NULL)) 304 &run, NULL))
303 { 305 {
304 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 "failed to start testing peer\n"); 307 "failed to start testing peer\n");
306 return 1; 308 return 1;
307 } 309 }
308 return ret; 310 return ret;
309} 311}