diff options
Diffstat (limited to 'src/set/test_set_union_copy.c')
-rw-r--r-- | src/set/test_set_union_copy.c | 285 |
1 files changed, 142 insertions, 143 deletions
diff --git a/src/set/test_set_union_copy.c b/src/set/test_set_union_copy.c index d129753e8..ab76668cc 100644 --- a/src/set/test_set_union_copy.c +++ b/src/set/test_set_union_copy.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/test_set_union_copy.c | 22 | * @file set/test_set_union_copy.c |
@@ -47,34 +47,34 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
47 | 47 | ||
48 | 48 | ||
49 | static void | 49 | static void |
50 | add_element_str (struct GNUNET_SET_Handle *set, | 50 | add_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 | ||
65 | static void | 65 | static void |
66 | remove_element_str (struct GNUNET_SET_Handle *set, | 66 | remove_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,16 +84,15 @@ remove_element_str (struct GNUNET_SET_Handle *set, | |||
84 | * @param cls closure | 84 | * @param cls closure |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | timeout_fail (void *cls) | 87 | timeout_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 | ||
95 | struct CountIterClosure | 95 | struct CountIterClosure { |
96 | { | ||
97 | unsigned int expected_count; | 96 | unsigned int expected_count; |
98 | unsigned int ongoing_count; | 97 | unsigned int ongoing_count; |
99 | GNUNET_SCHEDULER_TaskCallback cont; | 98 | GNUNET_SCHEDULER_TaskCallback cont; |
@@ -103,33 +102,33 @@ struct CountIterClosure | |||
103 | 102 | ||
104 | 103 | ||
105 | static int | 104 | static int |
106 | check_count_iter (void *cls, | 105 | check_count_iter(void *cls, |
107 | const struct GNUNET_SET_Element *element) | 106 | const struct GNUNET_SET_Element *element) |
108 | { | 107 | { |
109 | struct CountIterClosure *ci_cls = cls; | 108 | struct CountIterClosure *ci_cls = cls; |
110 | 109 | ||
111 | if (NULL == element) | 110 | if (NULL == element) |
112 | { | ||
113 | if (ci_cls->expected_count != ci_cls->ongoing_count) | ||
114 | { | 111 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 112 | if (ci_cls->expected_count != ci_cls->ongoing_count) |
116 | "Expected count (what: %s) to be %u, but it's actually %u\n", | 113 | { |
117 | ci_cls->what, | 114 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
118 | ci_cls->expected_count, | 115 | "Expected count (what: %s) to be %u, but it's actually %u\n", |
119 | ci_cls->ongoing_count); | 116 | ci_cls->what, |
120 | ret = 1; | 117 | ci_cls->expected_count, |
121 | GNUNET_SCHEDULER_shutdown (); | 118 | ci_cls->ongoing_count); |
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); | ||
122 | return GNUNET_NO; | 125 | return GNUNET_NO; |
123 | } | 126 | } |
124 | ci_cls->cont (ci_cls->cont_cls); | 127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
125 | GNUNET_free (ci_cls); | 128 | "Set `%s' has element %.*s\n", |
126 | return GNUNET_NO; | 129 | ci_cls->what, |
127 | } | 130 | (int)element->size, |
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | (const char *)element->data); |
129 | "Set `%s' has element %.*s\n", | ||
130 | ci_cls->what, | ||
131 | (int) element->size, | ||
132 | (const char *) element->data); | ||
133 | 132 | ||
134 | ci_cls->ongoing_count++; | 133 | ci_cls->ongoing_count++; |
135 | return GNUNET_YES; | 134 | return GNUNET_YES; |
@@ -137,17 +136,17 @@ check_count_iter (void *cls, | |||
137 | 136 | ||
138 | 137 | ||
139 | static void | 138 | static void |
140 | check_count (struct GNUNET_SET_Handle *set, | 139 | check_count(struct GNUNET_SET_Handle *set, |
141 | char *what, | 140 | char *what, |
142 | unsigned int expected_count, | 141 | unsigned int expected_count, |
143 | GNUNET_SCHEDULER_TaskCallback cont, | 142 | GNUNET_SCHEDULER_TaskCallback cont, |
144 | void *cont_cls) | 143 | void *cont_cls) |
145 | { | 144 | { |
146 | struct CountIterClosure *ci_cls = GNUNET_new (struct CountIterClosure); | 145 | struct CountIterClosure *ci_cls = GNUNET_new(struct CountIterClosure); |
147 | 146 | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
149 | "Checking count of %s\n", | 148 | "Checking count of %s\n", |
150 | what); | 149 | what); |
151 | 150 | ||
152 | ci_cls->expected_count = expected_count; | 151 | ci_cls->expected_count = expected_count; |
153 | ci_cls->ongoing_count = 0; | 152 | ci_cls->ongoing_count = 0; |
@@ -155,65 +154,65 @@ check_count (struct GNUNET_SET_Handle *set, | |||
155 | ci_cls->cont_cls = cont_cls; | 154 | ci_cls->cont_cls = cont_cls; |
156 | ci_cls->what = what; | 155 | ci_cls->what = what; |
157 | 156 | ||
158 | GNUNET_assert (GNUNET_YES == | 157 | GNUNET_assert(GNUNET_YES == |
159 | GNUNET_SET_iterate (set, | 158 | GNUNET_SET_iterate(set, |
160 | &check_count_iter, | 159 | &check_count_iter, |
161 | ci_cls)); | 160 | ci_cls)); |
162 | } | 161 | } |
163 | 162 | ||
164 | 163 | ||
165 | static void | 164 | static void |
166 | test_done (void *cls) | 165 | test_done(void *cls) |
167 | { | 166 | { |
168 | GNUNET_SCHEDULER_shutdown (); | 167 | GNUNET_SCHEDULER_shutdown(); |
169 | } | 168 | } |
170 | 169 | ||
171 | 170 | ||
172 | static void | 171 | static void |
173 | check_new_set_count (void *cls) | 172 | check_new_set_count(void *cls) |
174 | { | 173 | { |
175 | check_count (set2, | 174 | check_count(set2, |
176 | "new set", | 175 | "new set", |
177 | 3, | 176 | 3, |
178 | &test_done, | 177 | &test_done, |
179 | NULL); | 178 | NULL); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
183 | static void | 182 | static void |
184 | copy_done (void *cls, | 183 | copy_done(void *cls, |
185 | struct GNUNET_SET_Handle *new_set) | 184 | struct GNUNET_SET_Handle *new_set) |
186 | { | 185 | { |
187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 186 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
188 | "copy done\n"); | 187 | "copy done\n"); |
189 | set2 = new_set; | 188 | set2 = new_set; |
190 | remove_element_str (set2, | 189 | remove_element_str(set2, |
191 | "k5555"); | 190 | "k5555"); |
192 | add_element_str (set2, | 191 | add_element_str(set2, |
193 | "n66666"); | 192 | "n66666"); |
194 | add_element_str (set2, | 193 | add_element_str(set2, |
195 | "new2butremoved"); | 194 | "new2butremoved"); |
196 | remove_element_str (set2, | 195 | remove_element_str(set2, |
197 | "new2butremoved"); | 196 | "new2butremoved"); |
198 | remove_element_str (set2, | 197 | remove_element_str(set2, |
199 | "new3justremoved"); | 198 | "new3justremoved"); |
200 | // Check that set1 didn't change. | 199 | // Check that set1 didn't change. |
201 | check_count (set1, | 200 | check_count(set1, |
202 | "old set", | 201 | "old set", |
203 | 3, | 202 | 3, |
204 | &check_new_set_count, | 203 | &check_new_set_count, |
205 | NULL); | 204 | NULL); |
206 | } | 205 | } |
207 | 206 | ||
208 | 207 | ||
209 | static void | 208 | static void |
210 | test_copy (void *cls) | 209 | test_copy(void *cls) |
211 | { | 210 | { |
212 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 211 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
213 | "about to copy\n"); | 212 | "about to copy\n"); |
214 | GNUNET_SET_copy_lazy (set1, | 213 | GNUNET_SET_copy_lazy(set1, |
215 | ©_done, | 214 | ©_done, |
216 | NULL); | 215 | NULL); |
217 | } | 216 | } |
218 | 217 | ||
219 | 218 | ||
@@ -223,23 +222,23 @@ test_copy (void *cls) | |||
223 | * @param cls closure | 222 | * @param cls closure |
224 | */ | 223 | */ |
225 | static void | 224 | static void |
226 | do_shutdown (void *cls) | 225 | do_shutdown(void *cls) |
227 | { | 226 | { |
228 | if (NULL != tt) | 227 | if (NULL != tt) |
229 | { | 228 | { |
230 | GNUNET_SCHEDULER_cancel (tt); | 229 | GNUNET_SCHEDULER_cancel(tt); |
231 | tt = NULL; | 230 | tt = NULL; |
232 | } | 231 | } |
233 | if (NULL != set1) | 232 | if (NULL != set1) |
234 | { | 233 | { |
235 | GNUNET_SET_destroy (set1); | 234 | GNUNET_SET_destroy(set1); |
236 | set1 = NULL; | 235 | set1 = NULL; |
237 | } | 236 | } |
238 | if (NULL != set2) | 237 | if (NULL != set2) |
239 | { | 238 | { |
240 | GNUNET_SET_destroy (set2); | 239 | GNUNET_SET_destroy(set2); |
241 | set2 = NULL; | 240 | set2 = NULL; |
242 | } | 241 | } |
243 | } | 242 | } |
244 | 243 | ||
245 | 244 | ||
@@ -252,59 +251,59 @@ do_shutdown (void *cls) | |||
252 | * @param peer identity of the peer that was created | 251 | * @param peer identity of the peer that was created |
253 | */ | 252 | */ |
254 | static void | 253 | static void |
255 | run (void *cls, | 254 | run(void *cls, |
256 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 255 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
257 | struct GNUNET_TESTING_Peer *peer) | 256 | struct GNUNET_TESTING_Peer *peer) |
258 | { | 257 | { |
259 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | 258 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), |
260 | &timeout_fail, | 259 | &timeout_fail, |
261 | NULL); | 260 | NULL); |
262 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 261 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
263 | NULL); | 262 | NULL); |
264 | config = cfg; | 263 | config = cfg; |
265 | GNUNET_TESTING_peer_get_identity (peer, | 264 | GNUNET_TESTING_peer_get_identity(peer, |
266 | &local_id); | 265 | &local_id); |
267 | 266 | ||
268 | set1 = GNUNET_SET_create (cfg, | 267 | set1 = GNUNET_SET_create(cfg, |
269 | GNUNET_SET_OPERATION_UNION); | 268 | GNUNET_SET_OPERATION_UNION); |
270 | add_element_str (set1, | 269 | add_element_str(set1, |
271 | "333"); | 270 | "333"); |
272 | add_element_str (set1, | 271 | add_element_str(set1, |
273 | "k444"); | 272 | "k444"); |
274 | /* duplicate -- ignored */ | 273 | /* duplicate -- ignored */ |
275 | add_element_str (set1, | 274 | add_element_str(set1, |
276 | "k444"); | 275 | "k444"); |
277 | remove_element_str (set1, | 276 | remove_element_str(set1, |
278 | "333"); | 277 | "333"); |
279 | /* non-existent -- ignored */ | 278 | /* non-existent -- ignored */ |
280 | remove_element_str (set1, | 279 | remove_element_str(set1, |
281 | "999999999"); | 280 | "999999999"); |
282 | add_element_str (set1, | 281 | add_element_str(set1, |
283 | "k5555"); | 282 | "k5555"); |
284 | /* duplicate -- ignored */ | 283 | /* duplicate -- ignored */ |
285 | remove_element_str (set1, | 284 | remove_element_str(set1, |
286 | "333"); | 285 | "333"); |
287 | add_element_str (set1, | 286 | add_element_str(set1, |
288 | "k2"); | 287 | "k2"); |
289 | 288 | ||
290 | check_count (set1, | 289 | check_count(set1, |
291 | "initial test", | 290 | "initial test", |
292 | 3, | 291 | 3, |
293 | &test_copy, | 292 | &test_copy, |
294 | NULL); | 293 | NULL); |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
298 | int | 297 | int |
299 | main (int argc, char **argv) | 298 | main(int argc, char **argv) |
300 | { | 299 | { |
301 | if (0 != GNUNET_TESTING_peer_run ("test_set_union_copy", | 300 | if (0 != GNUNET_TESTING_peer_run("test_set_union_copy", |
302 | "test_set.conf", | 301 | "test_set.conf", |
303 | &run, NULL)) | 302 | &run, NULL)) |
304 | { | 303 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 304 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
306 | "failed to start testing peer\n"); | 305 | "failed to start testing peer\n"); |
307 | return 1; | 306 | return 1; |
308 | } | 307 | } |
309 | return ret; | 308 | return ret; |
310 | } | 309 | } |