aboutsummaryrefslogtreecommitdiff
path: root/src/psycstore/test_plugin_psycstore.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-16 13:23:12 +0000
committerGabor X Toth <*@tg-x.net>2013-09-16 13:23:12 +0000
commit2a95ef75f9df9267eda0a2a6625082288bc9715b (patch)
tree15d8a291eb35c95ec80e1fa5f4bcef147beef40d /src/psycstore/test_plugin_psycstore.c
parent92d8421cb317d5f588ccf66f9b07aa1bdf438685 (diff)
downloadgnunet-2a95ef75f9df9267eda0a2a6625082288bc9715b.tar.gz
gnunet-2a95ef75f9df9267eda0a2a6625082288bc9715b.zip
psycstore: use GNUNET_assert()
Diffstat (limited to 'src/psycstore/test_plugin_psycstore.c')
-rw-r--r--src/psycstore/test_plugin_psycstore.c192
1 files changed, 94 insertions, 98 deletions
diff --git a/src/psycstore/test_plugin_psycstore.c b/src/psycstore/test_plugin_psycstore.c
index a59b18939..77a4186bf 100644
--- a/src/psycstore/test_plugin_psycstore.c
+++ b/src/psycstore/test_plugin_psycstore.c
@@ -43,15 +43,6 @@
43#define LOG(kind,...) \ 43#define LOG(kind,...) \
44 GNUNET_log_from (kind, "test-plugin-psycstore", __VA_ARGS__) 44 GNUNET_log_from (kind, "test-plugin-psycstore", __VA_ARGS__)
45 45
46#define ASSERT(x) \
47 do { \
48 if (! (x)) \
49 { \
50 LOG (GNUNET_ERROR_TYPE_ERROR, "Error at %s:%d\n", __FILE__, __LINE__); \
51 goto FAILURE; \
52 } \
53 } while (0)
54
55static int ok; 46static int ok;
56 47
57/** 48/**
@@ -186,28 +177,29 @@ run (void *cls, char *const *args, const char *cfgfile,
186 channel_key = GNUNET_CRYPTO_ecc_key_create (); 177 channel_key = GNUNET_CRYPTO_ecc_key_create ();
187 slave_key = GNUNET_CRYPTO_ecc_key_create (); 178 slave_key = GNUNET_CRYPTO_ecc_key_create ();
188 179
189 GNUNET_CRYPTO_ecc_key_get_public_for_signature (channel_key, &channel_pub_key); 180 GNUNET_CRYPTO_ecc_key_get_public_for_signature (channel_key,
181 &channel_pub_key);
190 GNUNET_CRYPTO_ecc_key_get_public_for_signature (slave_key, &slave_pub_key); 182 GNUNET_CRYPTO_ecc_key_get_public_for_signature (slave_key, &slave_pub_key);
191 183
192 ASSERT (GNUNET_OK == db->membership_store (db->cls, &channel_pub_key, 184 GNUNET_assert (GNUNET_OK == db->membership_store (db->cls, &channel_pub_key,
193 &slave_pub_key, GNUNET_YES, 185 &slave_pub_key, GNUNET_YES,
194 4, 2, 1)); 186 4, 2, 1));
195 187
196 ASSERT (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key, 188 GNUNET_assert (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key,
197 &slave_pub_key, 4)); 189 &slave_pub_key, 4));
198 190
199 ASSERT (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key, 191 GNUNET_assert (GNUNET_YES == db->membership_test (db->cls, &channel_pub_key,
200 &slave_pub_key, 2)); 192 &slave_pub_key, 2));
201 193
202 ASSERT (GNUNET_NO == db->membership_test (db->cls, &channel_pub_key, 194 GNUNET_assert (GNUNET_NO == db->membership_test (db->cls, &channel_pub_key,
203 &slave_pub_key, 1)); 195 &slave_pub_key, 1));
204 196
205 197
206 /* Store & get messages */ 198 /* Store & get messages */
207 199
208 struct GNUNET_MULTICAST_MessageHeader *msg 200 struct GNUNET_MULTICAST_MessageHeader *msg
209 = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key)); 201 = GNUNET_malloc (sizeof (*msg) + sizeof (channel_pub_key));
210 ASSERT (msg != NULL); 202 GNUNET_assert (msg != NULL);
211 203
212 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE); 204 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MULTICAST_MESSAGE);
213 msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key)); 205 msg->header.size = htons (sizeof (*msg) + sizeof (channel_pub_key));
@@ -233,33 +225,35 @@ run (void *cls, char *const *args, const char *cfgfile,
233 fcls.msg[0] = msg; 225 fcls.msg[0] = msg;
234 fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE; 226 fcls.flags[0] = GNUNET_PSYCSTORE_MESSAGE_STATE;
235 227
236 ASSERT (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg, 228 GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg,
237 fcls.flags[0])); 229 fcls.flags[0]));
238 230
239 ASSERT (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, 231 GNUNET_assert (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
240 GNUNET_ntohll (msg->fragment_id), 232 GNUNET_ntohll (msg->fragment_id),
241 fragment_cb, &fcls)); 233 fragment_cb, &fcls));
242 ASSERT (fcls.n == 1); 234 GNUNET_assert (fcls.n == 1);
243 235
244 fcls.n = 0; 236 fcls.n = 0;
245 237
246 ASSERT (GNUNET_OK == db->message_get_fragment (db->cls, &channel_pub_key, 238 GNUNET_assert (
247 GNUNET_ntohll (msg->message_id), 239 GNUNET_OK == db->message_get_fragment (db->cls, &channel_pub_key,
248 GNUNET_ntohll (msg->fragment_offset), 240 GNUNET_ntohll (msg->message_id),
249 fragment_cb, &fcls)); 241 GNUNET_ntohll (msg->fragment_offset),
250 ASSERT (fcls.n == 1); 242 fragment_cb, &fcls));
243 GNUNET_assert (fcls.n == 1);
251 244
252 ASSERT (GNUNET_OK == db->message_add_flags ( 245 GNUNET_assert (
253 db->cls, &channel_pub_key, GNUNET_ntohll (msg->message_id), 246 GNUNET_OK == db->message_add_flags (db->cls, &channel_pub_key,
254 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED)); 247 GNUNET_ntohll (msg->message_id),
248 GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED));
255 249
256 fcls.n = 0; 250 fcls.n = 0;
257 fcls.flags[0] |= GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED; 251 fcls.flags[0] |= GNUNET_PSYCSTORE_MESSAGE_STATE_APPLIED;
258 252
259 ASSERT (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key, 253 GNUNET_assert (GNUNET_OK == db->fragment_get (db->cls, &channel_pub_key,
260 GNUNET_ntohll (msg->fragment_id), 254 GNUNET_ntohll (msg->fragment_id),
261 fragment_cb, &fcls)); 255 fragment_cb, &fcls));
262 ASSERT (fcls.n == 1); 256 GNUNET_assert (fcls.n == 1);
263 257
264 struct GNUNET_MULTICAST_MessageHeader *msg1 258 struct GNUNET_MULTICAST_MessageHeader *msg1
265 = GNUNET_malloc (sizeof (*msg1) + sizeof (channel_pub_key)); 259 = GNUNET_malloc (sizeof (*msg1) + sizeof (channel_pub_key));
@@ -273,75 +267,77 @@ run (void *cls, char *const *args, const char *cfgfile,
273 fcls.msg[1] = msg1; 267 fcls.msg[1] = msg1;
274 fcls.flags[1] = GNUNET_PSYCSTORE_MESSAGE_STATE_HASH; 268 fcls.flags[1] = GNUNET_PSYCSTORE_MESSAGE_STATE_HASH;
275 269
276 ASSERT (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg1, 270 GNUNET_assert (GNUNET_OK == db->fragment_store (db->cls, &channel_pub_key, msg1,
277 fcls.flags[1])); 271 fcls.flags[1]));
278 272
279 uint64_t retfrags = 0; 273 uint64_t retfrags = 0;
280 ASSERT (GNUNET_OK == db->message_get (db->cls, &channel_pub_key, 274 GNUNET_assert (GNUNET_OK == db->message_get (db->cls, &channel_pub_key,
281 GNUNET_ntohll (msg->message_id), 275 GNUNET_ntohll (msg->message_id),
282 &retfrags, fragment_cb, &fcls)); 276 &retfrags, fragment_cb, &fcls));
283 ASSERT (fcls.n == 2 && retfrags == 2); 277 GNUNET_assert (fcls.n == 2 && retfrags == 2);
284 278
285 /* Master counters */ 279 /* Master counters */
286 280
287 uint64_t fragment_id = 0, message_id = 0, group_generation = 0; 281 uint64_t fragment_id = 0, message_id = 0, group_generation = 0;
288 ASSERT (GNUNET_OK == db->counters_get_master (db->cls, &channel_pub_key, 282 GNUNET_assert (
289 &fragment_id, &message_id, 283 GNUNET_OK == db->counters_get_master (db->cls, &channel_pub_key,
290 &group_generation) 284 &fragment_id, &message_id,
291 && fragment_id == GNUNET_ntohll (msg1->fragment_id) 285 &group_generation)
292 && message_id == GNUNET_ntohll (msg1->message_id) 286 && fragment_id == GNUNET_ntohll (msg1->fragment_id)
293 && group_generation == GNUNET_ntohll (msg1->group_generation)); 287 && message_id == GNUNET_ntohll (msg1->message_id)
294 288 && group_generation == GNUNET_ntohll (msg1->group_generation));
295 289
296 /* Modify state */ 290 /* Modify state */
297 291
298 message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 1; 292 message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 1;
299 ASSERT (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, 293 GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key,
300 message_id, 1)); 294 message_id, 1));
301 295
302 ASSERT (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key, "_foo", 296 GNUNET_assert (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key,
303 C2ARG("one two three"))); 297 "_foo",
298 C2ARG("one two three")));
304 299
305 ASSERT (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key, 300 GNUNET_assert (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key,
306 "_foo_bar", slave_key, 301 "_foo_bar", slave_key,
307 sizeof (*slave_key))); 302 sizeof (*slave_key)));
308 303
309 ASSERT (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key, 304 GNUNET_assert (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key,
310 message_id)); 305 message_id));
311 306
312 struct StateClosure scls = { 0 }; 307 struct StateClosure scls = { 0 };
313 scls.n = 0; 308 scls.n = 0;
314 scls.value[0] = "one two three"; 309 scls.value[0] = "one two three";
315 scls.value_size[0] = strlen ("one two three"); 310 scls.value_size[0] = strlen ("one two three");
316 311
317 ASSERT (GNUNET_OK == db->state_get (db->cls, &channel_pub_key, "_foo", 312 GNUNET_assert (GNUNET_OK == db->state_get (db->cls, &channel_pub_key, "_foo",
318 state_cb, &scls)); 313 state_cb, &scls));
319 ASSERT (scls.n == 1); 314 GNUNET_assert (scls.n == 1);
320 315
321 scls.n = 0; 316 scls.n = 0;
322 scls.value[1] = slave_key; 317 scls.value[1] = slave_key;
323 scls.value_size[1] = sizeof (*slave_key); 318 scls.value_size[1] = sizeof (*slave_key);
324 319
325 ASSERT (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key, "_foo", 320 GNUNET_assert (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key,
326 state_cb, &scls)); 321 "_foo", state_cb, &scls));
327 ASSERT (scls.n == 2); 322 GNUNET_assert (scls.n == 2);
328 323
329 scls.n = 0; 324 scls.n = 0;
330 ASSERT (GNUNET_NO == db->state_get_signed (db->cls, &channel_pub_key, 325 GNUNET_assert (GNUNET_NO == db->state_get_signed (db->cls, &channel_pub_key,
331 state_cb, &scls)); 326 state_cb, &scls));
332 ASSERT (scls.n == 0); 327 GNUNET_assert (scls.n == 0);
333 328
334 ASSERT (GNUNET_OK == db->state_update_signed (db->cls, &channel_pub_key)); 329 GNUNET_assert (GNUNET_OK == db->state_update_signed (db->cls,
330 &channel_pub_key));
335 331
336 scls.n = 0; 332 scls.n = 0;
337 ASSERT (GNUNET_YES == db->state_get_signed (db->cls, &channel_pub_key, 333 GNUNET_assert (GNUNET_YES == db->state_get_signed (db->cls, &channel_pub_key,
338 state_cb, &scls)); 334 state_cb, &scls));
339 ASSERT (scls.n == 2); 335 GNUNET_assert (scls.n == 2);
340 336
341 /* Slave counters */ 337 /* Slave counters */
342 338
343 uint64_t max_state_msg_id = 0; 339 uint64_t max_state_msg_id = 0;
344 ASSERT (GNUNET_OK == db->counters_get_slave (db->cls, &channel_pub_key, 340 GNUNET_assert (GNUNET_OK == db->counters_get_slave (db->cls, &channel_pub_key,
345 &max_state_msg_id) 341 &max_state_msg_id)
346 && max_state_msg_id == message_id); 342 && max_state_msg_id == message_id);
347 343
@@ -353,53 +349,53 @@ run (void *cls, char *const *args, const char *cfgfile,
353 scls.value[1] = "three two one"; 349 scls.value[1] = "three two one";
354 scls.value_size[1] = strlen ("three two one"); 350 scls.value_size[1] = strlen ("three two one");
355 351
356 ASSERT (GNUNET_OK == db->state_sync_begin (db->cls, &channel_pub_key)); 352 GNUNET_assert (GNUNET_OK == db->state_sync_begin (db->cls, &channel_pub_key));
357 353
358 ASSERT (GNUNET_OK == db->state_sync_set (db->cls, &channel_pub_key, 354 GNUNET_assert (GNUNET_OK == db->state_sync_set (db->cls, &channel_pub_key,
359 "_sync_bar", 355 "_sync_bar", scls.value[0],
360 scls.value[0], scls.value_size[0])); 356 scls.value_size[0]));
361 357
362 ASSERT (GNUNET_OK == db->state_sync_set (db->cls, &channel_pub_key, 358 GNUNET_assert (GNUNET_OK == db->state_sync_set (db->cls, &channel_pub_key,
363 "_sync_foo", 359 "_sync_foo", scls.value[1],
364 scls.value[1], scls.value_size[1])); 360 scls.value_size[1]));
365 361
366 ASSERT (GNUNET_OK == db->state_sync_end (db->cls, &channel_pub_key, INT64_MAX - 5)); 362 GNUNET_assert (GNUNET_OK == db->state_sync_end (db->cls, &channel_pub_key,
363 INT64_MAX - 5));
367 364
368 ASSERT (GNUNET_NO == db->state_get_prefix (db->cls, &channel_pub_key, "_foo", 365 GNUNET_assert (GNUNET_NO == db->state_get_prefix (db->cls, &channel_pub_key,
369 state_cb, &scls)); 366 "_foo", state_cb, &scls));
370 ASSERT (scls.n == 0); 367 GNUNET_assert (scls.n == 0);
371 368
372 ASSERT (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key, "_sync", 369 GNUNET_assert (GNUNET_OK == db->state_get_prefix (db->cls, &channel_pub_key,
373 state_cb, &scls)); 370 "_sync", state_cb, &scls));
374 ASSERT (scls.n == 2); 371 GNUNET_assert (scls.n == 2);
375 372
376 scls.n = 0; 373 scls.n = 0;
377 ASSERT (GNUNET_OK == db->state_get_signed (db->cls, &channel_pub_key, 374 GNUNET_assert (GNUNET_OK == db->state_get_signed (db->cls, &channel_pub_key,
378 state_cb, &scls)); 375 state_cb, &scls));
379 ASSERT (scls.n == 2); 376 GNUNET_assert (scls.n == 2);
380 377
381 /* Modify state after sync */ 378 /* Modify state after sync */
382 379
383 message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 6; 380 message_id = GNUNET_ntohll (fcls.msg[0]->message_id) + 6;
384 ASSERT (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key, 381 GNUNET_assert (GNUNET_OK == db->state_modify_begin (db->cls, &channel_pub_key,
385 message_id, 3)); 382 message_id, 3));
386 383
387 ASSERT (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key, "_sync_foo", 384 GNUNET_assert (GNUNET_OK == db->state_modify_set (db->cls, &channel_pub_key,
388 C2ARG("five six seven"))); 385 "_sync_foo",
386 C2ARG("five six seven")));
389 387
390 ASSERT (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key, 388 GNUNET_assert (GNUNET_OK == db->state_modify_end (db->cls, &channel_pub_key,
391 message_id)); 389 message_id));
392 390
393 /* Reset state */ 391 /* Reset state */
394 392
395 scls.n = 0; 393 scls.n = 0;
396 ASSERT (GNUNET_OK == db->state_reset (db->cls, &channel_pub_key)); 394 GNUNET_assert (GNUNET_OK == db->state_reset (db->cls, &channel_pub_key));
397 ASSERT (scls.n == 0); 395 GNUNET_assert (scls.n == 0);
398 396
399 ok = 0; 397 ok = 0;
400 398
401FAILURE:
402
403 if (NULL != channel_key) 399 if (NULL != channel_key)
404 { 400 {
405 GNUNET_free (channel_key); 401 GNUNET_free (channel_key);