aboutsummaryrefslogtreecommitdiff
path: root/tests/test_gnunet_chat_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_gnunet_chat_handle.c')
-rw-r--r--tests/test_gnunet_chat_handle.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index f4d4ef8..6bc6fbf 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -287,12 +287,122 @@ call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg)
287 287
288CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) 288CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update)
289 289
290int
291on_gnunet_chat_handle_rename_it(void *cls,
292 const struct GNUNET_CHAT_Handle *handle,
293 struct GNUNET_CHAT_Account *account)
294{
295 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
296
297 ck_assert_ptr_ne(chat, NULL);
298 ck_assert_ptr_eq(handle, chat);
299 ck_assert_ptr_ne(account, NULL);
300
301 const char *name = GNUNET_CHAT_account_get_name(account);
302
303 ck_assert_ptr_ne(name, NULL);
304 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
305
306 if (0 == strcmp(name, "gnunet_chat_handle_rename_A"))
307 {
308 GNUNET_CHAT_connect(chat, account);
309 return GNUNET_NO;
310 }
311
312 return GNUNET_YES;
313}
314
315int
316on_gnunet_chat_handle_rename_msg(void *cls,
317 struct GNUNET_CHAT_Context *context,
318 const struct GNUNET_CHAT_Message *message)
319{
320 struct GNUNET_CHAT_Handle *handle = *(
321 (struct GNUNET_CHAT_Handle**) cls
322 );
323
324 ck_assert_ptr_ne(handle, NULL);
325 ck_assert_ptr_eq(context, NULL);
326 ck_assert_ptr_ne(message, NULL);
327
328 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
329
330 if (GNUNET_CHAT_get_connected(handle))
331 goto skip_search_account;
332
333 GNUNET_CHAT_iterate_accounts(
334 handle,
335 on_gnunet_chat_handle_rename_it,
336 handle
337 );
338
339 if (!GNUNET_CHAT_get_connected(handle))
340 return GNUNET_YES;
341
342skip_search_account:
343 if (GNUNET_CHAT_KIND_LOGIN != kind)
344 return GNUNET_YES;
345
346 const char *name = GNUNET_CHAT_get_name(handle);
347 ck_assert_ptr_ne(name, NULL);
348
349 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
350
351 if (!dup)
352 {
353 dup = GNUNET_strdup(name);
354
355 ck_assert_ptr_ne(dup, NULL);
356 ck_assert_str_eq(name, dup);
357
358 GNUNET_CHAT_set_user_pointer(handle, (void*) dup);
359
360 ck_assert_int_eq(GNUNET_CHAT_set_name(
361 handle,
362 "gnunet_chat_handle_rename_B"
363 ), GNUNET_YES);
364 }
365 else
366 {
367 ck_assert_ptr_ne(dup, NULL);
368 ck_assert_str_ne(name, dup);
369
370 GNUNET_free(dup);
371
372 GNUNET_CHAT_disconnect(handle);
373
374 ck_assert_int_eq(GNUNET_CHAT_account_delete(
375 handle,
376 "gnunet_chat_handle_rename_B"
377 ), GNUNET_OK);
378
379 GNUNET_CHAT_stop(handle);
380 }
381
382 return GNUNET_YES;
383}
384
385void
386call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg)
387{
388 static struct GNUNET_CHAT_Handle *handle = NULL;
389 handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_rename_msg, &handle);
390
391 ck_assert_ptr_ne(handle, NULL);
392 ck_assert_int_eq(GNUNET_CHAT_account_create(
393 handle,
394 "gnunet_chat_handle_rename_A"
395 ), GNUNET_OK);
396}
397
398CREATE_GNUNET_TEST(test_gnunet_chat_handle_rename, call_gnunet_chat_handle_rename)
290 399
291START_SUITE(handle_suite, "Handle") 400START_SUITE(handle_suite, "Handle")
292ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") 401ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop")
293ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts") 402ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts")
294ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect") 403ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect")
295ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update") 404ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update")
405ADD_TEST_TO_SUITE(test_gnunet_chat_handle_rename, "Rename")
296END_SUITE 406END_SUITE
297 407
298MAIN_SUITE(handle_suite, CK_NORMAL) 408MAIN_SUITE(handle_suite, CK_NORMAL)