libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 31060c1502ce34ebed3ceb0b8365ff58169d4db9
parent 242d75e5ceb10403e62abfb52c9381fc4351d9b5
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Tue, 12 Oct 2021 00:31:24 +0200

Added two more test cases and corrected some functions

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/gnunet_chat_handle_intern.c | 19+++++++++----------
Msrc/gnunet_chat_lib.c | 5++++-
Mtests/test_gnunet_chat.h | 2++
Mtests/test_gnunet_chat_handle.c | 104++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 115 insertions(+), 15 deletions(-)

diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -364,8 +364,16 @@ on_handle_identity(void *cls, (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) return; + GNUNET_MESSENGER_find_rooms( + handle->messenger, NULL, find_handle_rooms, handle + ); + + GNUNET_MESSENGER_find_rooms( + handle->messenger, NULL, scan_handle_rooms, handle + ); + if (!handle->msg_cb) - goto skip_login; + return; struct GNUNET_CHAT_Message *msg = message_create_internally( NULL, GNUNET_CHAT_FLAG_LOGIN, NULL @@ -373,15 +381,6 @@ on_handle_identity(void *cls, handle->msg_cb(handle->msg_cls, NULL, msg); message_destroy(msg); - -skip_login: - GNUNET_MESSENGER_find_rooms( - handle->messenger, NULL, find_handle_rooms, handle - ); - - GNUNET_MESSENGER_find_rooms( - handle->messenger, NULL, scan_handle_rooms, handle - ); } void diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -665,7 +665,7 @@ GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context, enum GNUNET_CHAT_MessageKind GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) { - if ((!message) || (!(message->msg))) + if (!message) return GNUNET_CHAT_KIND_UNKNOWN; switch (message->flag) @@ -678,6 +678,9 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) break; } + if (!(message->msg)) + return GNUNET_CHAT_KIND_UNKNOWN; + switch (message->msg->header.kind) { case GNUNET_MESSENGER_KIND_JOIN: diff --git a/tests/test_gnunet_chat.h b/tests/test_gnunet_chat.h @@ -28,6 +28,8 @@ #include <stdlib.h> #include <check.h> +#define CK_DEFAULT_TIMEOUT 5 + #include <gnunet/gnunet_chat_lib.h> #define CREATE_GNUNET_TEST(test_name, test_call) \ diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c @@ -25,20 +25,116 @@ #include "test_gnunet_chat.h" void -call_gnunet_chat_handle(const struct GNUNET_CONFIGURATION_Handle *cfg) +call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_CHAT_Handle *handle; - handle = GNUNET_CHAT_start(cfg, "", "Test", NULL, NULL, NULL, NULL); + handle = GNUNET_CHAT_start(cfg, "", "Init", NULL, NULL); ck_assert_ptr_ne(handle, NULL); GNUNET_CHAT_stop(handle); } -CREATE_GNUNET_TEST(test_gnunet_chat_handle, call_gnunet_chat_handle) +CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) + +struct GNUNET_CHAT_Handle *login_handle; + +int +on_gnunet_chat_handle_login_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); + + ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); + ck_assert_ptr_eq(cls, NULL); + ck_assert_ptr_eq(context, NULL); + + GNUNET_CHAT_stop(login_handle); + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + login_handle = GNUNET_CHAT_start(cfg, "", "Login", on_gnunet_chat_handle_login_msg, NULL); + ck_assert_ptr_ne(login_handle, NULL); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_login, call_gnunet_chat_handle_login) + +struct GNUNET_CHAT_Handle *access_handle; +int access_logins; + +int +on_gnunet_chat_handle_access_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); + + ck_assert_ptr_eq(cls, NULL); + ck_assert_ptr_eq(context, NULL); + + const struct GNUNET_IDENTITY_PublicKey *key; + const char *name; + int result; + + if (access_logins == 0) + { + ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); + + key = GNUNET_CHAT_get_key(access_handle); + ck_assert_ptr_eq(key, NULL); + + result = GNUNET_CHAT_update(access_handle); + ck_assert_int_eq(result, GNUNET_OK); + + name = GNUNET_CHAT_get_name(access_handle); + ck_assert_str_eq(name, "Access"); + } + else if (access_logins == 1) + { + ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); + + key = GNUNET_CHAT_get_key(access_handle); + ck_assert_ptr_ne(key, NULL); + + result = GNUNET_CHAT_set_name(access_handle, "Bccess"); + ck_assert_int_eq(result, GNUNET_YES); + } + else + { + ck_assert(kind == GNUNET_CHAT_KIND_CONTACT); + + ck_assert_int_eq(access_logins, 2); + + name = GNUNET_CHAT_get_name(access_handle); + ck_assert_str_eq(name, "Bccess"); + + GNUNET_CHAT_stop(access_handle); + } + + access_logins++; + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + access_logins = 0; + + access_handle = GNUNET_CHAT_start(cfg, "", "Access", on_gnunet_chat_handle_access_msg, NULL); + ck_assert_ptr_ne(access_handle, NULL); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_access, call_gnunet_chat_handle_access) + START_SUITE(handle_suite, "Handle") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle, "Start/Stop") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_login, "Login") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_access, "Get/Set") END_SUITE MAIN_SUITE(handle_suite, CK_NORMAL)