libgnunetchat

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

commit 543421ccf16722141fea56e50c52e467f641c691
parent 6b24ccab0ffb551226477633943afbe76bc434c2
Author: Jacki <jacki@thejackimonster.de>
Date:   Tue, 13 Oct 2026 17:48:57 +0200

Remove side effects of test cases by closing rooms properly

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Minclude/gnunet/gnunet_chat_lib.h | 30+++++++++++++++++++++++++++++-
Msrc/gnunet_chat_handle.c | 36++++++++++++++++++------------------
Msrc/gnunet_chat_lib.c | 3++-
Msrc/gnunet_chat_lib_intern.c | 10+++++++++-
Msrc/gnunet_chat_lobby.c | 34++++++++++++++++++++++++++++++++--
Msrc/gnunet_chat_lobby.h | 2++
Mtests/attribute/test_gnunet_chat_attribute_share.c | 169++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Mtests/discourse/test_gnunet_chat_discourse_open.c | 31++++++++++++++++++++++++++-----
Mtests/discourse/test_gnunet_chat_discourse_write.c | 30+++++++++++++++++++++++++-----
Mtests/file/test_gnunet_chat_file_send.c | 24++++++++++++++++++++++--
Mtests/lobby/test_gnunet_chat_lobby_join.c | 26++++++++++++++++++++++++--
Mtests/lobby/test_gnunet_chat_lobby_open.c | 41+++++++++++++++++++++++++++++++++++------
Mtests/tag/test_gnunet_chat_tag_message.c | 2+-
13 files changed, 367 insertions(+), 71 deletions(-)

diff --git a/include/gnunet/gnunet_chat_lib.h b/include/gnunet/gnunet_chat_lib.h @@ -55,7 +55,7 @@ struct GNUNET_CONFIGURATION_Handle; * the #GNUNET_MESSENGER_VERSION of the GNUnet Messenger * service while the patch version is independent. */ -#define GNUNET_CHAT_VERSION 0x000000080000L +#define GNUNET_CHAT_VERSION 0x000000080001L #define GNUNET_CHAT_VERSION_MAJOR ((GNUNET_CHAT_VERSION >> 32L) & 0xFFFFL) #define GNUNET_CHAT_VERSION_MINOR ((GNUNET_CHAT_VERSION >> 16L) & 0xFFFFL) @@ -92,6 +92,32 @@ enum GNUNET_CHAT_UriType }; /** + * Enum for the different types of lobbies. + */ +enum GNUNET_CHAT_LobbyType +{ + /** + * The type to open a private chat with a specific contact. + */ + GNUNET_CHAT_LOBBY_TYPE_CONTACT = 1, /**< GNUNET_CHAT_LOBBY_TYPE_CONTACT */ + + /** + * The type to open a private group chat with multiple contacts. + */ + GNUNET_CHAT_LOBBY_TYPE_GROUP = 2, /**< GNUNET_CHAT_LOBBY_TYPE_GROUP */ + + /** + * The type to open a feed chat. + */ + GNUNET_CHAT_LOBBY_TYPE_FEED = 3, /**< GNUNET_CHAT_LOBBY_TYPE_FEED */ + + /** + * An unknown type of lobby. + */ + GNUNET_CHAT_LOBBY_TYPE_UNKNOWN = 0 /**< GNUNET_CHAT_LOBBY_TYPE_UNKNOWN */ +}; + +/** * Enum for the different kinds of messages. */ enum GNUNET_CHAT_MessageKind @@ -795,6 +821,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri); * Opens an empty chat lobby which will expire after a custom <i>delay</i>. * * @param[in,out] handle Chat handle + * @param[in] type Type of lobby * @param[in] delay Expiration delay * @param[in] callback Callback for the lobby opening * @param[in,out] cls Closure for the lobby opening (optional) @@ -802,6 +829,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri); */ struct GNUNET_CHAT_Lobby* GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, + enum GNUNET_CHAT_LobbyType type, unsigned int delay, GNUNET_CHAT_LobbyCallback callback, void *cls); diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -117,7 +117,7 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->files = GNUNET_CONTAINER_multihashmap_create( initial_map_size_of_handle, GNUNET_NO); - + handle->contexts = NULL; handle->contacts = NULL; handle->groups = NULL; @@ -125,7 +125,7 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->arm = GNUNET_ARM_connect( handle->cfg, - on_handle_arm_connection, + on_handle_arm_connection, handle ); @@ -629,9 +629,9 @@ handle_create_account (struct GNUNET_CHAT_Handle *handle, enum GNUNET_GenericReturnValue result; result = update_accounts_operation( - &accounts, - handle, - name, + &accounts, + handle, + name, GNUNET_CHAT_ACCOUNT_CREATION ); @@ -673,9 +673,9 @@ handle_delete_account (struct GNUNET_CHAT_Handle *handle, enum GNUNET_GenericReturnValue result; result = update_accounts_operation( - &accounts, - handle, - NULL, + &accounts, + handle, + NULL, GNUNET_CHAT_ACCOUNT_DELETION ); @@ -726,9 +726,9 @@ handle_rename_account (struct GNUNET_CHAT_Handle *handle, enum GNUNET_GenericReturnValue result; result = update_accounts_operation( - &accounts, - handle, - NULL, + &accounts, + handle, + NULL, GNUNET_CHAT_ACCOUNT_RENAMING ); @@ -768,9 +768,9 @@ handle_delete_lobby (struct GNUNET_CHAT_Handle *handle, struct GNUNET_CHAT_InternalAccounts *accounts = NULL; enum GNUNET_GenericReturnValue result; result = update_accounts_operation( - &accounts, - handle, - NULL, + &accounts, + handle, + NULL, GNUNET_CHAT_ACCOUNT_DELETION ); @@ -843,9 +843,9 @@ handle_update (struct GNUNET_CHAT_Handle *handle) enum GNUNET_GenericReturnValue result; result = update_accounts_operation( - &accounts, - handle, - name, + &accounts, + handle, + name, GNUNET_CHAT_ACCOUNT_UPDATING ); @@ -980,7 +980,7 @@ handle_request_context_by_room (struct GNUNET_CHAT_Handle *handle, if ((GNUNET_CHAT_CONTEXT_TYPE_UNKNOWN == context->type) && (GNUNET_YES != context->deleted)) goto check_type; - + return GNUNET_OK; new_context: diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c @@ -642,6 +642,7 @@ GNUNET_CHAT_uri_destroy (struct GNUNET_CHAT_Uri *uri) struct GNUNET_CHAT_Lobby* GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, + enum GNUNET_CHAT_LobbyType type, unsigned int delay, GNUNET_CHAT_LobbyCallback callback, void *cls) @@ -667,7 +668,7 @@ GNUNET_CHAT_lobby_open (struct GNUNET_CHAT_Handle *handle, lobbies ); - lobby_open(lobbies->lobby, rel, callback, cls); + lobby_open(lobbies->lobby, type, rel, callback, cls); return lobbies->lobby; } diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c @@ -27,6 +27,7 @@ #include "gnunet_chat_context.h" #include "gnunet_chat_group.h" #include "gnunet_chat_handle.h" +#include "gnunet_chat_lib.h" #include <gnunet/gnunet_common.h> #include <gnunet/gnunet_messenger_service.h> @@ -353,9 +354,16 @@ task_lobby_destruction (void *cls) lobbies = lobbies->next; } - lobby->destruction = NULL; + struct GNUNET_CHAT_Context *context = lobby->context; + lobby->destruction = NULL; lobby_destroy(lobby); + + if ((! context) || + (GNUNET_OK == GNUNET_CHAT_context_get_status(context))) + return; + + context_delete(context, GNUNET_YES); } void diff --git a/src/gnunet_chat_lobby.c b/src/gnunet_chat_lobby.c @@ -24,9 +24,13 @@ #include "gnunet_chat_lobby.h" +#include "gnunet_chat_group.h" #include "gnunet_chat_handle.h" +#include "gnunet_chat_lib.h" #include "gnunet_chat_lobby_intern.c" +#include "gnunet_chat_util.h" #include <gnunet/gnunet_messenger_service.h> +#include <gnunet/gnunet_util_lib.h> struct GNUNET_CHAT_Lobby* lobby_create (struct GNUNET_CHAT_Handle *handle) @@ -78,6 +82,7 @@ skip_deletion: void lobby_open (struct GNUNET_CHAT_Lobby *lobby, + enum GNUNET_CHAT_LobbyType type, struct GNUNET_TIME_Relative delay, GNUNET_CHAT_LobbyCallback callback, void *cls) @@ -101,8 +106,8 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, &key, NULL, GNUNET_NO, - GNUNET_NO, - GNUNET_NO + GNUNET_CHAT_LOBBY_TYPE_GROUP == type? GNUNET_YES : GNUNET_NO, + GNUNET_CHAT_LOBBY_TYPE_FEED == type? GNUNET_YES : GNUNET_NO ); struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( @@ -126,6 +131,31 @@ lobby_open (struct GNUNET_CHAT_Lobby *lobby, return; } + if (GNUNET_CHAT_CONTEXT_TYPE_GROUP == lobby->context->type) + { + struct GNUNET_CHAT_Group *group; + group = group_create_from_context(lobby->handle, lobby->context); + + if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( + lobby->handle->groups, &(key.hash), group, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) + { + group_destroy(group); + + if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove( + lobby->handle->contexts, &(key.hash), lobby->context)) + { + context_destroy(lobby->context); + lobby->context = NULL; + } + + GNUNET_MESSENGER_close_room(room); + return; + } + } + + context_write_records(lobby->context); + open_zone: util_lobby_name(&(key.hash), &name); diff --git a/src/gnunet_chat_lobby.h b/src/gnunet_chat_lobby.h @@ -75,12 +75,14 @@ lobby_destroy (struct GNUNET_CHAT_Lobby *lobby); * closure. * * @param[in,out] lobby Chat lobby + * @param[in] type Type of lobby to open * @param[in] delay Delay to close down the lobby again * @param[in] callback Lobby opening callback * @param[in,out] cls Closure */ void lobby_open (struct GNUNET_CHAT_Lobby *lobby, + enum GNUNET_CHAT_LobbyType type, struct GNUNET_TIME_Relative delay, GNUNET_CHAT_LobbyCallback callback, void *cls); diff --git a/tests/attribute/test_gnunet_chat_attribute_share.c b/tests/attribute/test_gnunet_chat_attribute_share.c @@ -80,6 +80,7 @@ on_gnunet_chat_attribute_share_msg(void *cls, struct GNUNET_CHAT_Account *account; struct GNUNET_CHAT_Contact *recipient; struct GNUNET_CHAT_Contact *sender; + struct GNUNET_CHAT_Group *group; const char *name; ck_assert_ptr_nonnull(handle); @@ -115,7 +116,7 @@ on_gnunet_chat_attribute_share_msg(void *cls, } break; - case GNUNET_CHAT_KIND_LOGIN: + case GNUNET_CHAT_KIND_LOGIN: ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); @@ -126,21 +127,41 @@ on_gnunet_chat_attribute_share_msg(void *cls, if (0 == strcmp(name, TEST_SHARE_ID_B)) { - ck_assert_uint_eq(share_stage, 4); - - GNUNET_CHAT_set_attribute( - handle, - TEST_SHARE_NAME, - TEST_SHARE_VALUE - ); - - share_stage = 5; + ck_assert_uint_ge(share_stage, 4); + + if (share_stage > 4) + { + ck_assert_uint_eq(share_stage, 12); + + share_stage = 13; + } + else + { + ck_assert_uint_eq(share_stage, 4); + + GNUNET_CHAT_set_attribute( + handle, + TEST_SHARE_NAME, + TEST_SHARE_VALUE + ); + + share_stage = 5; + } } else { - ck_assert_uint_eq(share_stage, 1); - - share_stage = 2; + if (share_stage > 1) + { + ck_assert_uint_eq(share_stage, 8); + + share_stage = 9; + } + else + { + ck_assert_uint_eq(share_stage, 1); + + share_stage = 2; + } } ck_assert_ptr_nonnull(GNUNET_CHAT_group_create( @@ -158,15 +179,35 @@ on_gnunet_chat_attribute_share_msg(void *cls, if (0 == strcmp(name, TEST_SHARE_ID_A)) { - ck_assert_uint_eq(share_stage, 3); - - share_stage = 4; + if (share_stage > 3) + { + ck_assert_uint_eq(share_stage, 11); + + share_stage = 12; + } + else + { + ck_assert_uint_eq(share_stage, 3); + + share_stage = 4; + } } else if (0 == strcmp(name, TEST_SHARE_ID_B)) { - ck_assert_uint_eq(share_stage, 7); + ck_assert_uint_ge(share_stage, 7); + + if (share_stage > 7) + { + ck_assert_uint_eq(share_stage, 15); + + GNUNET_CHAT_stop(handle); + } + else + { + ck_assert_uint_eq(share_stage, 7); - GNUNET_CHAT_stop(handle); + share_stage = 8; + } } break; @@ -188,24 +229,92 @@ on_gnunet_chat_attribute_share_msg(void *cls, if ((0 == strcmp(name, TEST_SHARE_ID_A)) && (GNUNET_YES == GNUNET_CHAT_message_is_sent(message))) { - ck_assert_uint_eq(share_stage, 2); + ck_assert_uint_ge(share_stage, 2); + + if (share_stage > 2) + { + ck_assert_uint_eq(share_stage, 9); + + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); + + share_stage = 10; + } + else + { + ck_assert_uint_eq(share_stage, 2); + + GNUNET_CHAT_connect( + handle, + GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_B), + TEST_SHARE_SECRET_B, + strlen(TEST_SHARE_SECRET_B) + ); + + share_stage = 3; + } + } + else if ((GNUNET_YES != GNUNET_CHAT_message_is_sent(message)) && + (share_stage == 5)) + { + GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME); + + share_stage = 6; + } + else if ((0 == strcmp(name, TEST_SHARE_ID_B)) && + (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) && + (share_stage > 6)) + { + ck_assert_uint_eq(share_stage, 13); + + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); + + share_stage = 14; + } + + break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_SHARE_ID_A)) + { + ck_assert_uint_eq(share_stage, 10); GNUNET_CHAT_connect( - handle, + handle, GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_B), TEST_SHARE_SECRET_B, strlen(TEST_SHARE_SECRET_B) ); - share_stage = 3; + share_stage = 11; } - else if ((GNUNET_YES != GNUNET_CHAT_message_is_sent(message)) && - (share_stage == 5)) + else if (0 == strcmp(name, TEST_SHARE_ID_B)) { - GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME); - share_stage = 6; + ck_assert_uint_eq(share_stage, 14); + + GNUNET_CHAT_disconnect(handle); + + share_stage = 15; } - + break; case GNUNET_CHAT_KIND_CONTACT: ck_assert_ptr_nonnull(context); @@ -224,7 +333,13 @@ on_gnunet_chat_attribute_share_msg(void *cls, ck_assert_ptr_null(sender); ck_assert_ptr_null(recipient); - GNUNET_CHAT_disconnect(handle); + GNUNET_CHAT_connect( + handle, + GNUNET_CHAT_find_account(handle, TEST_SHARE_ID_A), + TEST_SHARE_SECRET_A, + strlen(TEST_SHARE_SECRET_A) + ); + share_stage = 7; } else if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) diff --git a/tests/discourse/test_gnunet_chat_discourse_open.c b/tests/discourse/test_gnunet_chat_discourse_open.c @@ -49,6 +49,7 @@ on_gnunet_chat_discourse_open_msg(void *cls, const char *name = GNUNET_CHAT_get_name(handle); struct GNUNET_CHAT_DiscourseId discourse_id; + struct GNUNET_CHAT_Group *group; struct GNUNET_CHAT_Discourse *discourse; discourse = GNUNET_CHAT_message_get_discourse(message); @@ -85,14 +86,17 @@ on_gnunet_chat_discourse_open_msg(void *cls, ck_assert_str_eq(name, TEST_OPEN_ID); ck_assert_uint_eq(discourse_stage, 1); - GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP); + group = GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP); + + ck_assert_ptr_nonnull(group); + discourse_stage = 2; break; case GNUNET_CHAT_KIND_LOGOUT: ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); - ck_assert_uint_eq(discourse_stage, 5); - + ck_assert_uint_eq(discourse_stage, 6); + GNUNET_CHAT_stop(handle); break; case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: @@ -120,12 +124,21 @@ on_gnunet_chat_discourse_open_msg(void *cls, discourse_stage = 3; break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_uint_eq(discourse_stage, 5); + + GNUNET_CHAT_disconnect(handle); + + discourse_stage = 6; + break; case GNUNET_CHAT_KIND_CONTACT: break; case GNUNET_CHAT_KIND_DISCOURSE: ck_assert_ptr_nonnull(context); ck_assert_ptr_nonnull(discourse); - + if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse)) { ck_assert_uint_eq(discourse_stage, 3); @@ -137,7 +150,15 @@ on_gnunet_chat_discourse_open_msg(void *cls, { ck_assert_uint_eq(discourse_stage, 4); - GNUNET_CHAT_disconnect(handle); + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); + discourse_stage = 5; } diff --git a/tests/discourse/test_gnunet_chat_discourse_write.c b/tests/discourse/test_gnunet_chat_discourse_write.c @@ -49,6 +49,7 @@ on_gnunet_chat_discourse_write_msg(void *cls, const char *name = GNUNET_CHAT_get_name(handle); struct GNUNET_CHAT_DiscourseId discourse_id; + struct GNUNET_CHAT_Group *group; struct GNUNET_CHAT_Discourse *discourse; discourse = GNUNET_CHAT_message_get_discourse(message); @@ -85,14 +86,17 @@ on_gnunet_chat_discourse_write_msg(void *cls, ck_assert_str_eq(name, TEST_WRITE_ID); ck_assert_uint_eq(discourse_stage, 1); - GNUNET_CHAT_group_create(handle, TEST_WRITE_GROUP); + group = GNUNET_CHAT_group_create(handle, TEST_WRITE_GROUP); + + ck_assert_ptr_nonnull(group); + discourse_stage = 2; break; case GNUNET_CHAT_KIND_LOGOUT: ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); - ck_assert_uint_eq(discourse_stage, 6); - + ck_assert_uint_eq(discourse_stage, 7); + GNUNET_CHAT_stop(handle); break; case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: @@ -120,6 +124,15 @@ on_gnunet_chat_discourse_write_msg(void *cls, discourse_stage = 3; break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_uint_eq(discourse_stage, 6); + + GNUNET_CHAT_disconnect(handle); + + discourse_stage = 7; + break; case GNUNET_CHAT_KIND_CONTACT: break; case GNUNET_CHAT_KIND_DISCOURSE: @@ -131,7 +144,7 @@ on_gnunet_chat_discourse_write_msg(void *cls, TEST_WRITE_DISCOURSE, sizeof(discourse_id) ); - + if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse)) { ck_assert_uint_eq(discourse_stage, 3); @@ -151,7 +164,14 @@ on_gnunet_chat_discourse_write_msg(void *cls, { ck_assert_uint_eq(discourse_stage, 5); - GNUNET_CHAT_disconnect(handle); + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); discourse_stage = 6; } diff --git a/tests/file/test_gnunet_chat_file_send.c b/tests/file/test_gnunet_chat_file_send.c @@ -151,7 +151,7 @@ on_gnunet_chat_file_send_msg(void *cls, case GNUNET_CHAT_KIND_LOGOUT: ck_assert_ptr_null(context); ck_assert_ptr_null(filename); - ck_assert_uint_eq(file_stage, 4); + ck_assert_uint_eq(file_stage, 5); GNUNET_CHAT_stop(handle); break; @@ -160,6 +160,18 @@ on_gnunet_chat_file_send_msg(void *cls, break; case GNUNET_CHAT_KIND_UPDATE_CONTEXT: case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(filename); + break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_null(filename); + ck_assert_uint_eq(file_stage, 4); + + GNUNET_CHAT_disconnect(handle); + + file_stage = 5; + break; case GNUNET_CHAT_KIND_CONTACT: ck_assert_ptr_nonnull(context); ck_assert_ptr_nonnull(filename); @@ -178,7 +190,15 @@ on_gnunet_chat_file_send_msg(void *cls, ck_assert_ptr_nonnull(text); ck_assert_str_eq(text, TEST_SEND_TEXT); - GNUNET_CHAT_disconnect(handle); + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); + file_stage = 4; break; case GNUNET_CHAT_KIND_FILE: diff --git a/tests/lobby/test_gnunet_chat_lobby_join.c b/tests/lobby/test_gnunet_chat_lobby_join.c @@ -57,6 +57,8 @@ on_gnunet_chat_lobby_join_msg(void *cls, struct GNUNET_CHAT_Account *account; account = GNUNET_CHAT_message_get_account(message); + struct GNUNET_CHAT_Group *group; + switch (GNUNET_CHAT_message_get_kind(message)) { case GNUNET_CHAT_KIND_WARNING: @@ -91,6 +93,7 @@ on_gnunet_chat_lobby_join_msg(void *cls, lobby = GNUNET_CHAT_lobby_open( handle, + GNUNET_CHAT_LOBBY_TYPE_GROUP, 1, on_gnunet_chat_lobby_join_open, handle @@ -103,7 +106,7 @@ on_gnunet_chat_lobby_join_msg(void *cls, ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); ck_assert_ptr_null(lobby); - ck_assert_uint_eq(lobby_stage, 3); + ck_assert_uint_eq(lobby_stage, 4); GNUNET_CHAT_stop(handle); break; @@ -123,9 +126,28 @@ on_gnunet_chat_lobby_join_msg(void *cls, GNUNET_CHAT_lobby_close(lobby); lobby = NULL; - GNUNET_CHAT_disconnect(handle); + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + ck_assert_int_eq( + GNUNET_CHAT_group_leave(group), + GNUNET_OK + ); + lobby_stage = 3; break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_uint_eq(lobby_stage, 3); + + GNUNET_CHAT_disconnect(handle); + + lobby_stage = 4; + break; + case GNUNET_CHAT_KIND_CONTACT: + break; default: ck_abort(); break; diff --git a/tests/lobby/test_gnunet_chat_lobby_open.c b/tests/lobby/test_gnunet_chat_lobby_open.c @@ -33,17 +33,16 @@ on_gnunet_chat_lobby_open_msg(void *cls, struct GNUNET_CHAT_Message *message) { static unsigned int lobby_stage = 0; + static struct GNUNET_CHAT_Lobby *lobby = NULL; struct GNUNET_CHAT_Handle *handle = *( (struct GNUNET_CHAT_Handle**) cls ); ck_assert_ptr_nonnull(handle); - ck_assert_ptr_null(context); ck_assert_ptr_nonnull(message); struct GNUNET_CHAT_Account *account; - struct GNUNET_CHAT_Lobby *lobby; account = GNUNET_CHAT_message_get_account(message); @@ -71,15 +70,17 @@ on_gnunet_chat_lobby_open_msg(void *cls, lobby_stage = 1; } - + break; case GNUNET_CHAT_KIND_LOGIN: ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); ck_assert_uint_eq(lobby_stage, 1); lobby = GNUNET_CHAT_lobby_open( handle, + GNUNET_CHAT_LOBBY_TYPE_CONTACT, 1, NULL, NULL @@ -87,14 +88,13 @@ on_gnunet_chat_lobby_open_msg(void *cls, ck_assert_ptr_nonnull(lobby); - GNUNET_CHAT_lobby_close(lobby); - GNUNET_CHAT_disconnect(handle); lobby_stage = 2; break; case GNUNET_CHAT_KIND_LOGOUT: ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); - ck_assert_uint_eq(lobby_stage, 2); + ck_assert_ptr_null(lobby); + ck_assert_uint_eq(lobby_stage, 4); GNUNET_CHAT_stop(handle); break; @@ -102,6 +102,35 @@ on_gnunet_chat_lobby_open_msg(void *cls, ck_assert_ptr_null(context); ck_assert_ptr_nonnull(account); break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(lobby); + ck_assert_uint_eq(lobby_stage, 2); + + GNUNET_CHAT_lobby_close(lobby); + lobby = NULL; + + lobby_stage = 3; + break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); + ck_assert_uint_eq(lobby_stage, 3); + + GNUNET_CHAT_disconnect(handle); + + lobby_stage = 4; + break; + case GNUNET_CHAT_KIND_CONTACT: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + break; default: ck_abort(); break; diff --git a/tests/tag/test_gnunet_chat_tag_message.c b/tests/tag/test_gnunet_chat_tag_message.c @@ -114,7 +114,7 @@ on_gnunet_chat_tag_message_msg(void *cls, case GNUNET_CHAT_KIND_LEAVE: ck_assert_ptr_nonnull(context); ck_assert_uint_eq(tag_stage, 6); - + GNUNET_CHAT_disconnect(handle); tag_stage = 7; break;