libgnunetchat

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

commit d4a77ef011918a8e8c4567085ca9169afcf14745
parent c96bea2fa3698b0d3383c635e48348214d884b4e
Author: Jacki <jacki@thejackimonster.de>
Date:   Wed, 21 Aug 2024 00:49:44 +0200

Restructure test cases so they don't interfere each other

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

Diffstat:
Atests/attribute/meson.build | 37+++++++++++++++++++++++++++++++++++++
Atests/attribute/test_gnunet_chat_attribute_check.c | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/attribute/test_gnunet_chat_attribute_share.c | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/discourse/meson.build | 37+++++++++++++++++++++++++++++++++++++
Atests/discourse/test_gnunet_chat_discourse_open.c | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/discourse/test_gnunet_chat_discourse_write.c | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/file/meson.build | 28++++++++++++++++++++++++++++
Atests/file/test_gnunet_chat_file_send.c | 226+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/meson.build | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/test_gnunet_chat_handle_accounts.c | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/test_gnunet_chat_handle_connection.c | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/test_gnunet_chat_handle_init.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/test_gnunet_chat_handle_rename.c | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/handle/test_gnunet_chat_handle_update.c | 176+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/lobby/meson.build | 37+++++++++++++++++++++++++++++++++++++
Atests/lobby/test_gnunet_chat_lobby_join.c | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atests/lobby/test_gnunet_chat_lobby_open.c | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/meson.build | 75+++++++++++++++++++++------------------------------------------------------
Atests/message/meson.build | 28++++++++++++++++++++++++++++
Atests/message/test_gnunet_chat_message_text.c | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtests/test_gnunet_chat_attribute.c | 354-------------------------------------------------------------------------------
Dtests/test_gnunet_chat_discourse.c | 306-------------------------------------------------------------------------------
Dtests/test_gnunet_chat_file.c | 226-------------------------------------------------------------------------------
Dtests/test_gnunet_chat_handle.c | 504-------------------------------------------------------------------------------
Dtests/test_gnunet_chat_lobby.c | 233-------------------------------------------------------------------------------
Dtests/test_gnunet_chat_message.c | 141-------------------------------------------------------------------------------
26 files changed, 2229 insertions(+), 1818 deletions(-)

diff --git a/tests/attribute/meson.build b/tests/attribute/meson.build @@ -0,0 +1,37 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_attribute_check = executable( + 'test_gnunet_chat_attribute_check.test', + 'test_gnunet_chat_attribute_check.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_attribute_share = executable( + 'test_gnunet_chat_attribute_share.test', + 'test_gnunet_chat_attribute_share.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/attribute/test_gnunet_chat_attribute_check.c b/tests/attribute/test_gnunet_chat_attribute_check.c @@ -0,0 +1,156 @@ +/* + This file is part of GNUnet. + Copyright (C) 2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_attribute_check.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_CHECK_ID "gnunet_chat_attribute_check" +#define TEST_CHECK_NAME "test_attribute_check_name" +#define TEST_CHECK_VALUE "test_attribute_check_value" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_attribute_check_attr(void *cls, + struct GNUNET_CHAT_Handle *handle, + const char *name, + const char *value) +{ + ck_assert_ptr_null(cls); + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_CHECK_NAME)) + { + ck_assert_ptr_nonnull(value); + ck_assert_str_eq(value, TEST_CHECK_VALUE); + + GNUNET_CHAT_delete_attribute(handle, TEST_CHECK_NAME); + return GNUNET_NO; + } + + return GNUNET_YES; +} + +enum GNUNET_GenericReturnValue +on_gnunet_chat_attribute_check_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + const struct GNUNET_CHAT_Account *account; + const char *text; + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + account = GNUNET_CHAT_message_get_account(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_set_attribute( + handle, + TEST_CHECK_NAME, + TEST_CHECK_VALUE, + GNUNET_TIME_relative_get_forever_() + ); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + TEST_CHECK_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + break; + case GNUNET_CHAT_KIND_ATTRIBUTES: + ck_assert_ptr_null(context); + + text = GNUNET_CHAT_message_get_text(message); + + if (text) + { + ck_assert_str_eq(text, TEST_CHECK_NAME); + + GNUNET_CHAT_get_attributes( + handle, + on_gnunet_chat_attribute_check_attr, + NULL + ); + } + else + GNUNET_CHAT_disconnect(handle); + + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_attribute_check(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_check_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, + TEST_CHECK_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_attribute_check, call_gnunet_chat_attribute_check) + +START_SUITE(handle_suite, "Attribute") +ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_check, "Check") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/attribute/test_gnunet_chat_attribute_share.c b/tests/attribute/test_gnunet_chat_attribute_share.c @@ -0,0 +1,230 @@ +/* + This file is part of GNUnet. + Copyright (C) 2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_attribute_share.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_SHARE_ID_A "gnunet_chat_attribute_share_a" +#define TEST_SHARE_ID_B "gnunet_chat_attribute_share_b" +#define TEST_SHARE_GROUP "test_attribute_share_group" +#define TEST_SHARE_NAME "test_attribute_share_name" +#define TEST_SHARE_VALUE "test_attribute_share_value" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_attribute_share_attr(void *cls, + struct GNUNET_CHAT_Contact *contact, + const char *name, + const char *value) +{ + ck_assert_ptr_nonnull(cls); + ck_assert_ptr_nonnull(contact); + ck_assert_ptr_nonnull(name); + ck_assert_ptr_nonnull(value); + + struct GNUNET_CHAT_Handle *handle = ( + (struct GNUNET_CHAT_Handle*) cls + ); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_get_connected(handle); + + const char *account_name = GNUNET_CHAT_account_get_name(account); + const char *contact_name = GNUNET_CHAT_contact_get_name(contact); + + ck_assert_ptr_nonnull(account); + ck_assert_str_eq(account_name, TEST_SHARE_ID_B); + ck_assert_str_eq(contact_name, TEST_SHARE_ID_A); + ck_assert_str_eq(name, TEST_SHARE_NAME); + ck_assert_str_eq(value, TEST_SHARE_VALUE); + + GNUNET_CHAT_unshare_attribute_from(handle, contact, name); + return GNUNET_NO; +} + +enum GNUNET_GenericReturnValue +on_gnunet_chat_attribute_share_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + const struct GNUNET_CHAT_Account *account; + struct GNUNET_CHAT_Contact *recipient; + struct GNUNET_CHAT_Contact *sender; + const char *name; + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + account = GNUNET_CHAT_message_get_account(message); + recipient = GNUNET_CHAT_message_get_recipient(message); + sender = GNUNET_CHAT_message_get_sender(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_SHARE_ID_B)) + GNUNET_CHAT_set_attribute( + handle, + TEST_SHARE_NAME, + TEST_SHARE_VALUE, + GNUNET_TIME_relative_get_forever_() + ); + + ck_assert_ptr_nonnull(GNUNET_CHAT_group_create( + handle, TEST_SHARE_GROUP + )); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + 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)) + break; + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_SHARE_ID_A + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(context); + 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_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_SHARE_ID_B + ), GNUNET_OK); + else + GNUNET_CHAT_stop(handle); + + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + ck_assert_ptr_nonnull(context); + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(sender); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_SHARE_ID_A)) + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, + TEST_SHARE_ID_B + ), GNUNET_OK); + else if (GNUNET_YES != GNUNET_CHAT_message_is_sent(message)) + GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME); + break; + case GNUNET_CHAT_KIND_CONTACT: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(sender); + break; + case GNUNET_CHAT_KIND_ATTRIBUTES: + ck_assert_ptr_null(context); + break; + case GNUNET_CHAT_KIND_SHARED_ATTRIBUTES: + if (!context) + { + ck_assert_ptr_null(account); + ck_assert_ptr_null(sender); + ck_assert_ptr_null(recipient); + + GNUNET_CHAT_disconnect(handle); + } + else if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) + { + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(sender); + ck_assert_ptr_nonnull(recipient); + ck_assert_ptr_ne(sender, recipient); + + GNUNET_CHAT_get_shared_attributes( + handle, + recipient, + on_gnunet_chat_attribute_share_attr, + handle + ); + } + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_attribute_share(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_share_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, + TEST_SHARE_ID_A + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_attribute_share, call_gnunet_chat_attribute_share) + +START_SUITE(handle_suite, "Attribute") +ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_share, "Share") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/discourse/meson.build b/tests/discourse/meson.build @@ -0,0 +1,37 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_discourse_open = executable( + 'test_gnunet_chat_discourse_open.test', + 'test_gnunet_chat_discourse_open.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_discourse_write = executable( + 'test_gnunet_chat_discourse_write.test', + 'test_gnunet_chat_discourse_write.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/discourse/test_gnunet_chat_discourse_open.c b/tests/discourse/test_gnunet_chat_discourse_open.c @@ -0,0 +1,147 @@ +/* + This file is part of GNUnet. + Copyright (C) 2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_discourse_open.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_OPEN_ID "gnunet_chat_discourse_open" +#define TEST_OPEN_GROUP "gnunet_chat_discourse_open_group" +#define TEST_OPEN_DISCOURSE "gnunet_chat_discourse_open_discourse" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_discourse_open_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_message_get_account(message); + + const char *name = GNUNET_CHAT_get_name(handle); + struct GNUNET_ShortHashCode discourse_id; + + struct GNUNET_CHAT_Discourse *discourse; + discourse = GNUNET_CHAT_message_get_discourse(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_OPEN_ID); + + GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + TEST_OPEN_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_null(discourse); + + GNUNET_memcpy( + &discourse_id, + TEST_OPEN_DISCOURSE, + sizeof(discourse_id) + ); + + discourse = GNUNET_CHAT_context_open_discourse( + context, + &discourse_id + ); + + ck_assert_ptr_nonnull(discourse); + ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO); + 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)) + GNUNET_CHAT_discourse_close(discourse); + else + GNUNET_CHAT_disconnect(handle); + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_discourse_open(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_open_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_OPEN_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_discourse_open, call_gnunet_chat_discourse_open) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_open, "Open/Close") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/discourse/test_gnunet_chat_discourse_write.c b/tests/discourse/test_gnunet_chat_discourse_write.c @@ -0,0 +1,186 @@ +/* + This file is part of GNUnet. + Copyright (C) 2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_discourse_write.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_WRITE_ID "gnunet_chat_discourse_write" +#define TEST_WRITE_GROUP "gnunet_chat_discourse_write_group" +#define TEST_WRITE_DISCOURSE "gnunet_chat_discourse_write_discourse" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_discourse_write_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_message_get_account(message); + + const char *name = GNUNET_CHAT_get_name(handle); + struct GNUNET_ShortHashCode discourse_id; + + struct GNUNET_CHAT_Discourse *discourse; + discourse = GNUNET_CHAT_message_get_discourse(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_WRITE_ID); + + GNUNET_CHAT_group_create(handle, TEST_WRITE_GROUP); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + TEST_WRITE_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_null(discourse); + + GNUNET_memcpy( + &discourse_id, + TEST_WRITE_DISCOURSE, + sizeof(discourse_id) + ); + + discourse = GNUNET_CHAT_context_open_discourse( + context, + &discourse_id + ); + + ck_assert_ptr_nonnull(discourse); + ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO); + break; + case GNUNET_CHAT_KIND_CONTACT: + break; + case GNUNET_CHAT_KIND_DISCOURSE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(discourse); + + GNUNET_memcpy( + &discourse_id, + TEST_WRITE_DISCOURSE, + sizeof(discourse_id) + ); + + if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse)) + ck_assert_int_eq( + GNUNET_CHAT_discourse_write( + discourse, + (const char*) &discourse_id, + sizeof(discourse_id) + ), + GNUNET_OK + ); + else + GNUNET_CHAT_disconnect(handle); + break; + case GNUNET_CHAT_KIND_DATA: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(discourse); + + ck_assert_uint_eq( + GNUNET_CHAT_message_available(message), + sizeof(discourse_id) + ); + + ck_assert_int_eq( + GNUNET_CHAT_message_read( + message, + (char*) &discourse_id, + sizeof(discourse_id) + ), + GNUNET_OK + ); + + ck_assert_mem_eq( + &discourse_id, + TEST_WRITE_DISCOURSE, + sizeof(discourse_id) + ); + + GNUNET_CHAT_discourse_close(discourse); + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_discourse_write(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_write_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_WRITE_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_discourse_write, call_gnunet_chat_discourse_write) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_write, "Talk") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/file/meson.build b/tests/file/meson.build @@ -0,0 +1,28 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_file_send = executable( + 'test_gnunet_chat_file_send.test', + 'test_gnunet_chat_file_send.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/file/test_gnunet_chat_file_send.c b/tests/file/test_gnunet_chat_file_send.c @@ -0,0 +1,226 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_file_send.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_SEND_ID "gnunet_chat_file_send" +#define TEST_SEND_TEXT "gnunet_chat_file_deleted" +#define TEST_SEND_FILENAME "gnunet_chat_file_send_name" +#define TEST_SEND_GROUP "gnunet_chat_file_send_group" + +void +on_gnunet_chat_file_send_upload(void *cls, + struct GNUNET_CHAT_File *file, + uint64_t completed, + uint64_t size) +{ + struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(file); + ck_assert_uint_le(completed, size); + + uint64_t check_size = GNUNET_CHAT_file_get_size(file); + + ck_assert_uint_eq(size, check_size); + + if (completed > size) + return; + + ck_assert_uint_eq(completed, size); +} + +void +on_gnunet_chat_file_send_unindex(void *cls, + struct GNUNET_CHAT_File *file, + uint64_t completed, + uint64_t size) +{ + struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls; + + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(file); + ck_assert_uint_le(completed, size); + + if (completed > size) + return; + + ck_assert_uint_eq(completed, size); + + GNUNET_CHAT_context_send_text(context, TEST_SEND_TEXT); +} + +enum GNUNET_GenericReturnValue +on_gnunet_chat_file_send_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + static char *filename = NULL; + + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + const struct GNUNET_CHAT_Account *account; + struct GNUNET_CHAT_Group *group; + struct GNUNET_CHAT_File *file; + + const char *name; + const char *text; + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + ck_assert_ptr_null(context); + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + + group = GNUNET_CHAT_group_create( + handle, TEST_SEND_GROUP + ); + + ck_assert_ptr_nonnull(group); + + context = GNUNET_CHAT_group_get_context(group); + + ck_assert_ptr_nonnull(context); + ck_assert_ptr_null(filename); + + filename = GNUNET_DISK_mktemp(TEST_SEND_FILENAME); + + ck_assert_ptr_nonnull(filename); + + file = GNUNET_CHAT_context_send_file( + context, + filename, + on_gnunet_chat_file_send_upload, + handle + ); + + ck_assert_ptr_nonnull(file); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_null(filename); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(context); + + account = GNUNET_CHAT_message_get_account(message); + + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_SEND_ID); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(context); + + account = GNUNET_CHAT_message_get_account(message); + + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_SEND_ID); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_null(context); + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + case GNUNET_CHAT_KIND_JOIN: + case GNUNET_CHAT_KIND_CONTACT: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(filename); + break; + case GNUNET_CHAT_KIND_TEXT: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(filename); + + remove(filename); + GNUNET_free(filename); + filename = NULL; + + text = GNUNET_CHAT_message_get_text(message); + + ck_assert_ptr_nonnull(text); + ck_assert_str_eq(text, TEST_SEND_TEXT); + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_SEND_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_FILE: + ck_assert_ptr_nonnull(context); + + file = GNUNET_CHAT_message_get_file(message); + + ck_assert_ptr_nonnull(file); + ck_assert_int_eq(GNUNET_CHAT_file_unindex( + file, + on_gnunet_chat_file_send_unindex, + context + ), GNUNET_OK); + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_file_send(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_file_send_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, + TEST_SEND_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_file_send, call_gnunet_chat_file_send) + +START_SUITE(handle_suite, "File") +ADD_TEST_TO_SUITE(test_gnunet_chat_file_send, "Send") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/handle/meson.build b/tests/handle/meson.build @@ -0,0 +1,64 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_handle_accounts = executable( + 'test_gnunet_chat_handle_accounts.test', + 'test_gnunet_chat_handle_accounts.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_handle_connection = executable( + 'test_gnunet_chat_handle_connection.test', + 'test_gnunet_chat_handle_connection.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_handle_init = executable( + 'test_gnunet_chat_handle_init.test', + 'test_gnunet_chat_handle_init.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_handle_rename = executable( + 'test_gnunet_chat_handle_rename.test', + 'test_gnunet_chat_handle_rename.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_handle_update = executable( + 'test_gnunet_chat_handle_update.test', + 'test_gnunet_chat_handle_update.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/handle/test_gnunet_chat_handle_accounts.c b/tests/handle/test_gnunet_chat_handle_accounts.c @@ -0,0 +1,147 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_handle_accounts.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_ACCOUNTS_ID "gnunet_chat_handle_accounts" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_handle_accounts_it(void *cls, + const struct GNUNET_CHAT_Handle *handle, + struct GNUNET_CHAT_Account *account) +{ + unsigned int *accounts_stage = cls; + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(account); + ck_assert_int_eq(*accounts_stage, 2); + + const char *name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_ACCOUNTS_ID)) + { + *accounts_stage = 3; + return GNUNET_NO; + } + + return GNUNET_YES; +} + +enum GNUNET_GenericReturnValue +on_gnunet_chat_handle_accounts_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + static unsigned int accounts_stage = 0; + + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_null(context); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_message_get_account(message); + + const char *name; + name = GNUNET_CHAT_account_get_name(account); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + if (0 == accounts_stage) + { + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, + TEST_ACCOUNTS_ID + ), GNUNET_OK); + + accounts_stage = 1; + } else + if (2 == accounts_stage) + { + ck_assert_int_ge(GNUNET_CHAT_iterate_accounts( + handle, + on_gnunet_chat_handle_accounts_it, + &accounts_stage + ), 1); + } + + if (3 == accounts_stage) + { + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + TEST_ACCOUNTS_ID + ), GNUNET_OK); + + accounts_stage = 4; + } + + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_ACCOUNTS_ID)) + accounts_stage = 2; + + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_int_eq(accounts_stage, 4); + ck_assert_ptr_nonnull(name); + + if (0 == strcmp(name, TEST_ACCOUNTS_ID)) + GNUNET_CHAT_stop(handle); + + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_accounts(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_accounts_msg, &handle); + + ck_assert_ptr_nonnull(handle); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/handle/test_gnunet_chat_handle_connection.c b/tests/handle/test_gnunet_chat_handle_connection.c @@ -0,0 +1,130 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_handle_connection.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_CONNECTION_ID "gnunet_chat_handle_connection" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_handle_connection_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + 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); + + const struct GNUNET_CHAT_Account *connected; + const struct GNUNET_CHAT_Account *account; + const char *name; + + connected = GNUNET_CHAT_get_connected(handle); + account = GNUNET_CHAT_message_get_account(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_nonnull(connected); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_eq(connected, account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_CONNECTION_ID); + + GNUNET_CHAT_disconnect(handle); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_nonnull(connected); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_eq(connected, account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_CONNECTION_ID); + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_CONNECTION_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(connected); + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_CONNECTION_ID); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(connected); + ck_assert_ptr_nonnull(account); + + name = GNUNET_CHAT_account_get_name(account); + + ck_assert_ptr_nonnull(name); + ck_assert_str_eq(name, TEST_CONNECTION_ID); + + GNUNET_CHAT_stop(handle); + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_connection_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_CONNECTION_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/handle/test_gnunet_chat_handle_init.c b/tests/handle/test_gnunet_chat_handle_init.c @@ -0,0 +1,45 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_handle_init.c + */ + +#include "test_gnunet_chat.h" + +void +call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_CHAT_Handle *handle; + + handle = GNUNET_CHAT_start(cfg, NULL, NULL); + + ck_assert_ptr_nonnull(handle); + + GNUNET_CHAT_stop(handle); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/handle/test_gnunet_chat_handle_rename.c b/tests/handle/test_gnunet_chat_handle_rename.c @@ -0,0 +1,129 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_handle_rename.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_RENAME_ID_A "gnunet_chat_handle_rename_a" +#define TEST_RENAME_ID_B "gnunet_chat_handle_rename_b" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_handle_rename_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + 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); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_message_get_account(message); + + const char *name = GNUNET_CHAT_get_name(handle); + char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); + ck_assert_ptr_null(dup); + ck_assert_str_eq(name, TEST_RENAME_ID_A); + + dup = GNUNET_strdup(name); + + ck_assert_ptr_nonnull(dup); + ck_assert_str_eq(name, dup); + + GNUNET_CHAT_set_user_pointer(handle, (void*) dup); + + ck_assert_int_eq(GNUNET_CHAT_set_name( + handle, + TEST_RENAME_ID_B + ), GNUNET_YES); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_nonnull(account); + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, + TEST_RENAME_ID_B + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(name); + ck_assert_ptr_nonnull(dup); + ck_assert_str_ne(name, dup); + ck_assert_str_eq(name, TEST_RENAME_ID_B); + ck_assert_str_eq(dup, TEST_RENAME_ID_A); + + GNUNET_free(dup); + + GNUNET_CHAT_disconnect(handle); + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_rename_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_RENAME_ID_A + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_rename, call_gnunet_chat_handle_rename) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_rename, "Rename") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/handle/test_gnunet_chat_handle_update.c b/tests/handle/test_gnunet_chat_handle_update.c @@ -0,0 +1,176 @@ +/* + This file is part of GNUnet. + Copyright (C) 2021--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_handle_update.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_UPDATE_ID "gnunet_chat_handle_update" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_handle_update_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + static unsigned int update_stage = 0; + + 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); + + const struct GNUNET_CHAT_Account *account; + account = GNUNET_CHAT_message_get_account(message); + + const char *key; + char *dup; + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + account = GNUNET_CHAT_get_connected(handle); + + ck_assert_ptr_nonnull(account); + ck_assert_str_eq( + GNUNET_CHAT_account_get_name(account), + TEST_UPDATE_ID + ); + + key = GNUNET_CHAT_get_key(handle); + ck_assert_ptr_nonnull(key); + + dup = (char*) GNUNET_CHAT_get_user_pointer(handle); + + ck_assert_int_eq(update_stage, 1); + + dup = GNUNET_strdup(key); + + ck_assert_ptr_nonnull(dup); + ck_assert_str_eq(key, dup); + + GNUNET_CHAT_set_user_pointer(handle, (void*) dup); + GNUNET_CHAT_update(handle); + + update_stage = 2; + break; + case GNUNET_CHAT_KIND_LOGOUT: + account = GNUNET_CHAT_get_connected(handle); + + ck_assert_int_ge(update_stage, 2); + ck_assert_int_le(update_stage, 3); + + ck_assert_ptr_nonnull(account); + ck_assert_str_eq( + GNUNET_CHAT_account_get_name(account), + TEST_UPDATE_ID + ); + + if (update_stage == 3) + { + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_UPDATE_ID + ), GNUNET_OK); + + update_stage = 4; + } + + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), + TEST_UPDATE_ID))) + break; + + ck_assert_int_eq(update_stage, 0); + + update_stage = 1; + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), + TEST_UPDATE_ID))) + break; + + ck_assert_int_eq(update_stage, 4); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + + if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), + TEST_UPDATE_ID))) + break; + + key = GNUNET_CHAT_get_key(handle); + ck_assert_ptr_nonnull(key); + + dup = (char*) GNUNET_CHAT_get_user_pointer(handle); + + ck_assert_int_eq(update_stage, 2); + ck_assert_ptr_nonnull(dup); + ck_assert_str_ne(key, dup); + + GNUNET_free(dup); + + GNUNET_CHAT_disconnect(handle); + + update_stage = 3; + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_update_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_UPDATE_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) + +START_SUITE(handle_suite, "Handle") +ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/lobby/meson.build b/tests/lobby/meson.build @@ -0,0 +1,37 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_lobby_join = executable( + 'test_gnunet_chat_lobby_join.test', + 'test_gnunet_chat_lobby_join.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) + +test_gnunet_chat_lobby_open = executable( + 'test_gnunet_chat_lobby_open.test', + 'test_gnunet_chat_lobby_open.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/lobby/test_gnunet_chat_lobby_join.c b/tests/lobby/test_gnunet_chat_lobby_join.c @@ -0,0 +1,148 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_lobby_join.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_JOIN_ID "gnunet_chat_lobby_join" + +void +on_gnunet_chat_lobby_join_open(void *cls, + const struct GNUNET_CHAT_Uri *uri) +{ + struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; + + ck_assert_ptr_nonnull(chat); + ck_assert_ptr_nonnull(uri); + + GNUNET_CHAT_lobby_join(chat, uri); +} + +enum GNUNET_GenericReturnValue +on_gnunet_chat_lobby_join_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + 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_nonnull(message); + + const struct GNUNET_CHAT_Account *account; + + account = GNUNET_CHAT_message_get_account(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + ck_assert_ptr_null(context); + ck_assert_ptr_null(account); + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); + + lobby = GNUNET_CHAT_lobby_open( + handle, + GNUNET_TIME_relative_get_second_(), + on_gnunet_chat_lobby_join_open, + handle + ); + + ck_assert_ptr_nonnull(lobby); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_JOIN_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(lobby); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + ck_assert_ptr_nonnull(context); + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_nonnull(lobby); + + GNUNET_CHAT_lobby_close(lobby); + lobby = NULL; + + GNUNET_CHAT_disconnect(handle); + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_lobby_join(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_join_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_JOIN_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_lobby_join, call_gnunet_chat_lobby_join) + +START_SUITE(lobby_suite, "Lobby") +ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_join, "Join") +END_SUITE + +MAIN_SUITE(lobby_suite, CK_NORMAL) diff --git a/tests/lobby/test_gnunet_chat_lobby_open.c b/tests/lobby/test_gnunet_chat_lobby_open.c @@ -0,0 +1,116 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_lobby_open.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_OPEN_ID "gnunet_chat_lobby_open" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_lobby_open_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + 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); + + const struct GNUNET_CHAT_Account *account; + struct GNUNET_CHAT_Lobby *lobby; + + account = GNUNET_CHAT_message_get_account(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + ck_assert_ptr_null(account); + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_nonnull(account); + + lobby = GNUNET_CHAT_lobby_open( + handle, + GNUNET_TIME_relative_get_second_(), + NULL, + NULL + ); + + ck_assert_ptr_nonnull(lobby); + + GNUNET_CHAT_lobby_close(lobby); + GNUNET_CHAT_disconnect(handle); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_nonnull(account); + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_OPEN_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + break; + default: + ck_abort(); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_lobby_open(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_open_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_OPEN_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_lobby_open, call_gnunet_chat_lobby_open) + +START_SUITE(lobby_suite, "Lobby") +ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_open, "Open/Close") +END_SUITE + +MAIN_SUITE(lobby_suite, CK_NORMAL) diff --git a/tests/meson.build b/tests/meson.build @@ -23,63 +23,30 @@ test_deps = [ dependency('gnunetutil'), ] -test_gnunet_chat_handle = executable( - 'test_gnunet_chat_handle.test', - 'test_gnunet_chat_handle.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +test_header = '../test_gnunet_chat.h' -test_gnunet_chat_lobby = executable( - 'test_gnunet_chat_lobby.test', - 'test_gnunet_chat_lobby.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +subdir('attribute') +subdir('discourse') +subdir('file') +subdir('handle') +subdir('lobby') +subdir('message') -test_gnunet_chat_file = executable( - 'test_gnunet_chat_file.test', - 'test_gnunet_chat_file.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +test('test_gnunet_chat_handle_init', test_gnunet_chat_handle_init, depends: gnunetchat_lib) +test('test_gnunet_chat_handle_accounts', test_gnunet_chat_handle_accounts, depends: gnunetchat_lib) +test('test_gnunet_chat_handle_connection', test_gnunet_chat_handle_connection, depends: gnunetchat_lib) +test('test_gnunet_chat_handle_update', test_gnunet_chat_handle_update, depends: gnunetchat_lib) +test('test_gnunet_chat_handle_rename', test_gnunet_chat_handle_rename, depends: gnunetchat_lib) -test_gnunet_chat_message = executable( - 'test_gnunet_chat_message.test', - 'test_gnunet_chat_message.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +test('test_gnunet_chat_message_text', test_gnunet_chat_message_text, depends: gnunetchat_lib) -test_gnunet_chat_attribute = executable( - 'test_gnunet_chat_attribute.test', - 'test_gnunet_chat_attribute.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +test('test_gnunet_chat_file_send', test_gnunet_chat_file_send, depends: gnunetchat_lib) -test_gnunet_chat_discourse = executable( - 'test_gnunet_chat_discourse.test', - 'test_gnunet_chat_discourse.c', - dependencies: test_deps, - link_with: gnunetchat_lib, - include_directories: tests_include, - extra_files: 'test_gnunet_chat.h', -) +test('test_gnunet_chat_lobby_open', test_gnunet_chat_lobby_open, depends: gnunetchat_lib) +test('test_gnunet_chat_lobby_join', test_gnunet_chat_lobby_join, depends: gnunetchat_lib) -test('test_gnunet_chat_handle', test_gnunet_chat_handle, depends: gnunetchat_lib) -test('test_gnunet_chat_lobby', test_gnunet_chat_lobby, depends: gnunetchat_lib) -test('test_gnunet_chat_file', test_gnunet_chat_file, depends: gnunetchat_lib) -test('test_gnunet_chat_message', test_gnunet_chat_message, depends: gnunetchat_lib) -test('test_gnunet_chat_attribute', test_gnunet_chat_attribute, depends: gnunetchat_lib) -test('test_gnunet_chat_discourse', test_gnunet_chat_discourse, depends: gnunetchat_lib) +test('test_gnunet_chat_attribute_check', test_gnunet_chat_attribute_check, depends: gnunetchat_lib) +test('test_gnunet_chat_attribute_share', test_gnunet_chat_attribute_check, depends: gnunetchat_lib) + +test('test_gnunet_chat_discourse_open', test_gnunet_chat_discourse_open, depends: gnunetchat_lib) +test('test_gnunet_chat_discourse_write', test_gnunet_chat_discourse_write, depends: gnunetchat_lib) diff --git a/tests/message/meson.build b/tests/message/meson.build @@ -0,0 +1,28 @@ +# +# This file is part of GNUnet. +# Copyright (C) 2024 GNUnet e.V. +# +# GNUnet is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, +# or (at your option) any later version. +# +# GNUnet is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# SPDX-License-Identifier: AGPL3.0-or-later +# + +test_gnunet_chat_message_text = executable( + 'test_gnunet_chat_message_text.test', + 'test_gnunet_chat_message_text.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/message/test_gnunet_chat_message_text.c b/tests/message/test_gnunet_chat_message_text.c @@ -0,0 +1,141 @@ +/* + This file is part of GNUnet. + Copyright (C) 2023--2024 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file test_gnunet_chat_message_text.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_TEXT_ID "gnunet_chat_message_text" +#define TEST_TEXT_GROUP "gnunet_chat_message_text_group" +#define TEST_TEXT_MSG "test_text_message" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_message_text_msg(void *cls, + struct GNUNET_CHAT_Context *context, + const struct GNUNET_CHAT_Message *message) +{ + struct GNUNET_CHAT_Handle *handle = *( + (struct GNUNET_CHAT_Handle**) cls + ); + + const struct GNUNET_CHAT_Account *account; + struct GNUNET_CHAT_Group *group; + const char *text; + + ck_assert_ptr_nonnull(handle); + ck_assert_ptr_nonnull(message); + + account = GNUNET_CHAT_message_get_account(message); + + switch (GNUNET_CHAT_message_get_kind(message)) + { + case GNUNET_CHAT_KIND_WARNING: + ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); + break; + case GNUNET_CHAT_KIND_REFRESH: + break; + case GNUNET_CHAT_KIND_LOGIN: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + group = GNUNET_CHAT_group_create(handle, TEST_TEXT_GROUP); + + ck_assert_ptr_nonnull(group); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + + ck_assert_int_eq(GNUNET_CHAT_account_delete( + handle, TEST_TEXT_ID + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_CREATED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + break; + case GNUNET_CHAT_KIND_DELETED_ACCOUNT: + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_stop(handle); + break; + case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: + ck_assert_ptr_nonnull(account); + break; + case GNUNET_CHAT_KIND_UPDATE_CONTEXT: + ck_assert_ptr_nonnull(context); + break; + case GNUNET_CHAT_KIND_JOIN: + ck_assert_ptr_nonnull(context); + + ck_assert_int_eq(GNUNET_CHAT_context_send_text( + context, TEST_TEXT_MSG + ), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + + GNUNET_CHAT_disconnect(handle); + break; + case GNUNET_CHAT_KIND_CONTACT: + ck_assert_ptr_nonnull(context); + break; + case GNUNET_CHAT_KIND_TEXT: + ck_assert_ptr_nonnull(context); + + group = GNUNET_CHAT_context_get_group(context); + + ck_assert_ptr_nonnull(group); + + text = GNUNET_CHAT_message_get_text(message); + + ck_assert_str_eq(text, TEST_TEXT_MSG); + ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK); + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + break; + } + + return GNUNET_YES; +} + +void +call_gnunet_chat_message_text(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_message_text_msg, &handle); + + ck_assert_ptr_nonnull(handle); + ck_assert_int_eq(GNUNET_CHAT_account_create( + handle, TEST_TEXT_ID + ), GNUNET_OK); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_message_text, call_gnunet_chat_message_text) + +START_SUITE(handle_suite, "Message") +ADD_TEST_TO_SUITE(test_gnunet_chat_message_text, "Text") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_attribute.c b/tests/test_gnunet_chat_attribute.c @@ -1,354 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_attribute.c - */ - -#include "test_gnunet_chat.h" - -#define TEST_CHECK_ID "gnunet_chat_attribute_check" -#define TEST_CHECK_NAME "test_attribute_check_name" -#define TEST_CHECK_VALUE "test_attribute_check_value" -#define TEST_SHARE_ID_A "gnunet_chat_attribute_share_a" -#define TEST_SHARE_ID_B "gnunet_chat_attribute_share_b" -#define TEST_SHARE_GROUP "test_attribute_share_group" -#define TEST_SHARE_NAME "test_attribute_share_name" -#define TEST_SHARE_VALUE "test_attribute_share_value" - -enum GNUNET_GenericReturnValue -on_gnunet_chat_attribute_check_attr(void *cls, - struct GNUNET_CHAT_Handle *handle, - const char *name, - const char *value) -{ - ck_assert_ptr_null(cls); - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_CHECK_NAME)) - { - ck_assert_ptr_nonnull(value); - ck_assert_str_eq(value, TEST_CHECK_VALUE); - - GNUNET_CHAT_delete_attribute(handle, TEST_CHECK_NAME); - return GNUNET_NO; - } - - return GNUNET_YES; -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_attribute_check_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - const struct GNUNET_CHAT_Account *account; - const char *text; - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - account = GNUNET_CHAT_message_get_account(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_set_attribute( - handle, - TEST_CHECK_NAME, - TEST_CHECK_VALUE, - GNUNET_TIME_relative_get_forever_() - ); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - TEST_CHECK_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - break; - case GNUNET_CHAT_KIND_ATTRIBUTES: - ck_assert_ptr_null(context); - - text = GNUNET_CHAT_message_get_text(message); - - if (text) - { - ck_assert_str_eq(text, TEST_CHECK_NAME); - - GNUNET_CHAT_get_attributes( - handle, - on_gnunet_chat_attribute_check_attr, - NULL - ); - } - else - GNUNET_CHAT_disconnect(handle); - - break; - default: - ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_attribute_check(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_check_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - TEST_CHECK_ID - ), GNUNET_OK); -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_attribute_share_attr(void *cls, - struct GNUNET_CHAT_Contact *contact, - const char *name, - const char *value) -{ - ck_assert_ptr_nonnull(cls); - ck_assert_ptr_nonnull(contact); - ck_assert_ptr_nonnull(name); - ck_assert_ptr_nonnull(value); - - struct GNUNET_CHAT_Handle *handle = ( - (struct GNUNET_CHAT_Handle*) cls - ); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_get_connected(handle); - - const char *account_name = GNUNET_CHAT_account_get_name(account); - const char *contact_name = GNUNET_CHAT_contact_get_name(contact); - - ck_assert_ptr_nonnull(account); - ck_assert_str_eq(account_name, TEST_SHARE_ID_B); - ck_assert_str_eq(contact_name, TEST_SHARE_ID_A); - ck_assert_str_eq(name, TEST_SHARE_NAME); - ck_assert_str_eq(value, TEST_SHARE_VALUE); - - GNUNET_CHAT_unshare_attribute_from(handle, contact, name); - return GNUNET_NO; -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_attribute_share_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - const struct GNUNET_CHAT_Account *account; - struct GNUNET_CHAT_Contact *recipient; - struct GNUNET_CHAT_Contact *sender; - const char *name; - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - account = GNUNET_CHAT_message_get_account(message); - recipient = GNUNET_CHAT_message_get_recipient(message); - sender = GNUNET_CHAT_message_get_sender(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_SHARE_ID_B)) - GNUNET_CHAT_set_attribute( - handle, - TEST_SHARE_NAME, - TEST_SHARE_VALUE, - GNUNET_TIME_relative_get_forever_() - ); - - ck_assert_ptr_nonnull(GNUNET_CHAT_group_create( - handle, TEST_SHARE_GROUP - )); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - 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)) - break; - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_SHARE_ID_A - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(context); - 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_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_SHARE_ID_B - ), GNUNET_OK); - else - GNUNET_CHAT_stop(handle); - - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - ck_assert_ptr_nonnull(context); - break; - case GNUNET_CHAT_KIND_JOIN: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(sender); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_SHARE_ID_A)) - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - TEST_SHARE_ID_B - ), GNUNET_OK); - else if (GNUNET_YES != GNUNET_CHAT_message_is_sent(message)) - GNUNET_CHAT_share_attribute_with(handle, sender, TEST_SHARE_NAME); - break; - case GNUNET_CHAT_KIND_CONTACT: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(sender); - break; - case GNUNET_CHAT_KIND_ATTRIBUTES: - ck_assert_ptr_null(context); - break; - case GNUNET_CHAT_KIND_SHARED_ATTRIBUTES: - if (!context) - { - ck_assert_ptr_null(account); - ck_assert_ptr_null(sender); - ck_assert_ptr_null(recipient); - - GNUNET_CHAT_disconnect(handle); - } - else if (GNUNET_YES == GNUNET_CHAT_message_is_sent(message)) - { - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(sender); - ck_assert_ptr_nonnull(recipient); - ck_assert_ptr_ne(sender, recipient); - - GNUNET_CHAT_get_shared_attributes( - handle, - recipient, - on_gnunet_chat_attribute_share_attr, - handle - ); - } - break; - default: - ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_attribute_share(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_attribute_share_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - TEST_SHARE_ID_A - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_attribute_check, call_gnunet_chat_attribute_check) -CREATE_GNUNET_TEST(test_gnunet_chat_attribute_share, call_gnunet_chat_attribute_share) - -START_SUITE(handle_suite, "Attribute") -ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_check, "Check") -ADD_TEST_TO_SUITE(test_gnunet_chat_attribute_share, "Share") -END_SUITE - -MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_discourse.c b/tests/test_gnunet_chat_discourse.c @@ -1,306 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_discourse.c - */ - -#include "test_gnunet_chat.h" -#include <check.h> -#include <gnunet/gnunet_chat_lib.h> -#include <gnunet/gnunet_common.h> -#include <gnunet/gnunet_messenger_service.h> - -#define TEST_OPEN_ID "gnunet_chat_discourse_open" -#define TEST_OPEN_GROUP "gnunet_chat_discourse_open_group" -#define TEST_OPEN_DISCOURSE "gnunet_chat_discourse_open_discourse" -#define TEST_WRITE_ID "gnunet_chat_discourse_write" -#define TEST_WRITE_GROUP "gnunet_chat_discourse_write_group" -#define TEST_WRITE_DISCOURSE "gnunet_chat_discourse_write_discourse" - -enum GNUNET_GenericReturnValue -on_gnunet_chat_discourse_open_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_message_get_account(message); - - const char *name = GNUNET_CHAT_get_name(handle); - struct GNUNET_ShortHashCode discourse_id; - - struct GNUNET_CHAT_Discourse *discourse; - discourse = GNUNET_CHAT_message_get_discourse(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_OPEN_ID); - - GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - TEST_OPEN_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - break; - case GNUNET_CHAT_KIND_JOIN: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_null(discourse); - - GNUNET_memcpy( - &discourse_id, - TEST_OPEN_DISCOURSE, - sizeof(discourse_id) - ); - - discourse = GNUNET_CHAT_context_open_discourse( - context, - &discourse_id - ); - - ck_assert_ptr_nonnull(discourse); - ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO); - 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)) - GNUNET_CHAT_discourse_close(discourse); - else - GNUNET_CHAT_disconnect(handle); - break; - default: - ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_discourse_open(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_open_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_OPEN_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_discourse_open, call_gnunet_chat_discourse_open) - -enum GNUNET_GenericReturnValue -on_gnunet_chat_discourse_write_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_message_get_account(message); - - const char *name = GNUNET_CHAT_get_name(handle); - struct GNUNET_ShortHashCode discourse_id; - - struct GNUNET_CHAT_Discourse *discourse; - discourse = GNUNET_CHAT_message_get_discourse(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_WRITE_ID); - - GNUNET_CHAT_group_create(handle, TEST_WRITE_GROUP); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - TEST_WRITE_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - break; - case GNUNET_CHAT_KIND_JOIN: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_null(discourse); - - GNUNET_memcpy( - &discourse_id, - TEST_WRITE_DISCOURSE, - sizeof(discourse_id) - ); - - discourse = GNUNET_CHAT_context_open_discourse( - context, - &discourse_id - ); - - ck_assert_ptr_nonnull(discourse); - ck_assert_int_eq(GNUNET_CHAT_discourse_is_open(discourse), GNUNET_NO); - break; - case GNUNET_CHAT_KIND_CONTACT: - break; - case GNUNET_CHAT_KIND_DISCOURSE: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(discourse); - - GNUNET_memcpy( - &discourse_id, - TEST_WRITE_DISCOURSE, - sizeof(discourse_id) - ); - - if (GNUNET_YES == GNUNET_CHAT_discourse_is_open(discourse)) - ck_assert_int_eq( - GNUNET_CHAT_discourse_write( - discourse, - (const char*) &discourse_id, - sizeof(discourse_id) - ), - GNUNET_OK - ); - else - GNUNET_CHAT_disconnect(handle); - break; - case GNUNET_CHAT_KIND_DATA: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(discourse); - - ck_assert_uint_eq( - GNUNET_CHAT_message_available(message), - sizeof(discourse_id) - ); - - ck_assert_int_eq( - GNUNET_CHAT_message_read( - message, - (char*) &discourse_id, - sizeof(discourse_id) - ), - GNUNET_OK - ); - - ck_assert_mem_eq( - &discourse_id, - TEST_WRITE_DISCOURSE, - sizeof(discourse_id) - ); - - GNUNET_CHAT_discourse_close(discourse); - break; - default: - ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_discourse_write(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_discourse_write_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_WRITE_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_discourse_write, call_gnunet_chat_discourse_write) - -START_SUITE(handle_suite, "Handle") -ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_open, "Open/Close") -ADD_TEST_TO_SUITE(test_gnunet_chat_discourse_write, "Talk") -END_SUITE - -MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_file.c b/tests/test_gnunet_chat_file.c @@ -1,226 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_file.c - */ - -#include "test_gnunet_chat.h" - -#define TEST_SEND_ID "gnunet_chat_file_send" -#define TEST_SEND_TEXT "gnunet_chat_file_deleted" -#define TEST_SEND_FILENAME "gnunet_chat_file_send_name" -#define TEST_SEND_GROUP "gnunet_chat_file_send_group" - -void -on_gnunet_chat_file_send_upload(void *cls, - struct GNUNET_CHAT_File *file, - uint64_t completed, - uint64_t size) -{ - struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(file); - ck_assert_uint_le(completed, size); - - uint64_t check_size = GNUNET_CHAT_file_get_size(file); - - ck_assert_uint_eq(size, check_size); - - if (completed > size) - return; - - ck_assert_uint_eq(completed, size); -} - -void -on_gnunet_chat_file_send_unindex(void *cls, - struct GNUNET_CHAT_File *file, - uint64_t completed, - uint64_t size) -{ - struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) cls; - - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(file); - ck_assert_uint_le(completed, size); - - if (completed > size) - return; - - ck_assert_uint_eq(completed, size); - - GNUNET_CHAT_context_send_text(context, TEST_SEND_TEXT); -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_file_send_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - static char *filename = NULL; - - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - const struct GNUNET_CHAT_Account *account; - struct GNUNET_CHAT_Group *group; - struct GNUNET_CHAT_File *file; - - const char *name; - const char *text; - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - ck_assert_ptr_null(context); - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - - group = GNUNET_CHAT_group_create( - handle, TEST_SEND_GROUP - ); - - ck_assert_ptr_nonnull(group); - - context = GNUNET_CHAT_group_get_context(group); - - ck_assert_ptr_nonnull(context); - ck_assert_ptr_null(filename); - - filename = GNUNET_DISK_mktemp(TEST_SEND_FILENAME); - - ck_assert_ptr_nonnull(filename); - - file = GNUNET_CHAT_context_send_file( - context, - filename, - on_gnunet_chat_file_send_upload, - handle - ); - - ck_assert_ptr_nonnull(file); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_null(filename); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(context); - - account = GNUNET_CHAT_message_get_account(message); - - ck_assert_ptr_nonnull(account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_SEND_ID); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(context); - - account = GNUNET_CHAT_message_get_account(message); - - ck_assert_ptr_nonnull(account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_SEND_ID); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_null(context); - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - case GNUNET_CHAT_KIND_JOIN: - case GNUNET_CHAT_KIND_CONTACT: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(filename); - break; - case GNUNET_CHAT_KIND_TEXT: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(filename); - - remove(filename); - GNUNET_free(filename); - filename = NULL; - - text = GNUNET_CHAT_message_get_text(message); - - ck_assert_ptr_nonnull(text); - ck_assert_str_eq(text, TEST_SEND_TEXT); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_SEND_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_FILE: - ck_assert_ptr_nonnull(context); - - file = GNUNET_CHAT_message_get_file(message); - - ck_assert_ptr_nonnull(file); - ck_assert_int_eq(GNUNET_CHAT_file_unindex( - file, - on_gnunet_chat_file_send_unindex, - context - ), GNUNET_OK); - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_file_send(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_file_send_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - TEST_SEND_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_file_send, call_gnunet_chat_file_send) - -START_SUITE(handle_suite, "File") -ADD_TEST_TO_SUITE(test_gnunet_chat_file_send, "Send") -END_SUITE - -MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c @@ -1,504 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2021--2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_handle.c - */ - -#include "test_gnunet_chat.h" - -#define TEST_ACCOUNTS_ID "gnunet_chat_handle_accounts" -#define TEST_CONNECTION_ID "gnunet_chat_handle_connection" -#define TEST_UPDATE_ID "gnunet_chat_handle_update" -#define TEST_RENAME_ID_A "gnunet_chat_handle_rename_a" -#define TEST_RENAME_ID_B "gnunet_chat_handle_rename_b" - -void -call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - struct GNUNET_CHAT_Handle *handle; - - handle = GNUNET_CHAT_start(cfg, NULL, NULL); - - ck_assert_ptr_nonnull(handle); - - GNUNET_CHAT_stop(handle); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) - -enum GNUNET_GenericReturnValue -on_gnunet_chat_handle_accounts_it(void *cls, - const struct GNUNET_CHAT_Handle *handle, - struct GNUNET_CHAT_Account *account) -{ - unsigned int *accounts_stage = cls; - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(account); - ck_assert_int_eq(*accounts_stage, 2); - - const char *name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_ACCOUNTS_ID)) - { - *accounts_stage = 3; - return GNUNET_NO; - } - - return GNUNET_YES; -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_handle_accounts_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - static unsigned int accounts_stage = 0; - - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_null(context); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_message_get_account(message); - - const char *name; - name = GNUNET_CHAT_account_get_name(account); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - if (0 == accounts_stage) - { - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, - TEST_ACCOUNTS_ID - ), GNUNET_OK); - - accounts_stage = 1; - } else - if (2 == accounts_stage) - { - ck_assert_int_ge(GNUNET_CHAT_iterate_accounts( - handle, - on_gnunet_chat_handle_accounts_it, - &accounts_stage - ), 1); - } - - if (3 == accounts_stage) - { - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - TEST_ACCOUNTS_ID - ), GNUNET_OK); - - accounts_stage = 4; - } - - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_ACCOUNTS_ID)) - accounts_stage = 2; - - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_int_eq(accounts_stage, 4); - ck_assert_ptr_nonnull(name); - - if (0 == strcmp(name, TEST_ACCOUNTS_ID)) - GNUNET_CHAT_stop(handle); - - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_handle_accounts(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_accounts_msg, &handle); - - ck_assert_ptr_nonnull(handle); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts) - -enum GNUNET_GenericReturnValue -on_gnunet_chat_handle_connection_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - 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); - - const struct GNUNET_CHAT_Account *connected; - const struct GNUNET_CHAT_Account *account; - const char *name; - - connected = GNUNET_CHAT_get_connected(handle); - account = GNUNET_CHAT_message_get_account(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_nonnull(connected); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_eq(connected, account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_CONNECTION_ID); - - GNUNET_CHAT_disconnect(handle); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_nonnull(connected); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_eq(connected, account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_CONNECTION_ID); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_CONNECTION_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(connected); - ck_assert_ptr_nonnull(account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_CONNECTION_ID); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(connected); - ck_assert_ptr_nonnull(account); - - name = GNUNET_CHAT_account_get_name(account); - - ck_assert_ptr_nonnull(name); - ck_assert_str_eq(name, TEST_CONNECTION_ID); - - GNUNET_CHAT_stop(handle); - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_connection_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_CONNECTION_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection) - -enum GNUNET_GenericReturnValue -on_gnunet_chat_handle_update_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - static unsigned int update_stage = 0; - - 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); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_message_get_account(message); - - const char *key; - char *dup; - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - account = GNUNET_CHAT_get_connected(handle); - - ck_assert_ptr_nonnull(account); - ck_assert_str_eq( - GNUNET_CHAT_account_get_name(account), - TEST_UPDATE_ID - ); - - key = GNUNET_CHAT_get_key(handle); - ck_assert_ptr_nonnull(key); - - dup = (char*) GNUNET_CHAT_get_user_pointer(handle); - - ck_assert_int_eq(update_stage, 1); - - dup = GNUNET_strdup(key); - - ck_assert_ptr_nonnull(dup); - ck_assert_str_eq(key, dup); - - GNUNET_CHAT_set_user_pointer(handle, (void*) dup); - GNUNET_CHAT_update(handle); - - update_stage = 2; - break; - case GNUNET_CHAT_KIND_LOGOUT: - account = GNUNET_CHAT_get_connected(handle); - - ck_assert_int_ge(update_stage, 2); - ck_assert_int_le(update_stage, 3); - - ck_assert_ptr_nonnull(account); - ck_assert_str_eq( - GNUNET_CHAT_account_get_name(account), - TEST_UPDATE_ID - ); - - if (update_stage == 3) - { - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_UPDATE_ID - ), GNUNET_OK); - - update_stage = 4; - } - - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), - TEST_UPDATE_ID))) - break; - - ck_assert_int_eq(update_stage, 0); - - update_stage = 1; - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), - TEST_UPDATE_ID))) - break; - - ck_assert_int_eq(update_stage, 4); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - - if ((0 != strcmp(GNUNET_CHAT_account_get_name(account), - TEST_UPDATE_ID))) - break; - - key = GNUNET_CHAT_get_key(handle); - ck_assert_ptr_nonnull(key); - - dup = (char*) GNUNET_CHAT_get_user_pointer(handle); - - ck_assert_int_eq(update_stage, 2); - ck_assert_ptr_nonnull(dup); - ck_assert_str_ne(key, dup); - - GNUNET_free(dup); - - GNUNET_CHAT_disconnect(handle); - - update_stage = 3; - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_update_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_UPDATE_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) - -enum GNUNET_GenericReturnValue -on_gnunet_chat_handle_rename_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - 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); - - const struct GNUNET_CHAT_Account *account; - account = GNUNET_CHAT_message_get_account(message); - - const char *name = GNUNET_CHAT_get_name(handle); - char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(name); - ck_assert_ptr_null(dup); - ck_assert_str_eq(name, TEST_RENAME_ID_A); - - dup = GNUNET_strdup(name); - - ck_assert_ptr_nonnull(dup); - ck_assert_str_eq(name, dup); - - GNUNET_CHAT_set_user_pointer(handle, (void*) dup); - - ck_assert_int_eq(GNUNET_CHAT_set_name( - handle, - TEST_RENAME_ID_B - ), GNUNET_YES); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_nonnull(account); - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, - TEST_RENAME_ID_B - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(name); - ck_assert_ptr_nonnull(dup); - ck_assert_str_ne(name, dup); - ck_assert_str_eq(name, TEST_RENAME_ID_B); - ck_assert_str_eq(dup, TEST_RENAME_ID_A); - - GNUNET_free(dup); - - GNUNET_CHAT_disconnect(handle); - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_handle_rename(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_rename_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_RENAME_ID_A - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_handle_rename, call_gnunet_chat_handle_rename) - -START_SUITE(handle_suite, "Handle") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update") -ADD_TEST_TO_SUITE(test_gnunet_chat_handle_rename, "Rename") -END_SUITE - -MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_lobby.c b/tests/test_gnunet_chat_lobby.c @@ -1,233 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_lobby.c - */ - -#include "test_gnunet_chat.h" - -#define TEST_BASE_ID "gnunet_chat_lobby_base" -#define TEST_JOIN_ID "gnunet_chat_lobby_join" - -enum GNUNET_GenericReturnValue -on_gnunet_chat_lobby_base_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - 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); - - const struct GNUNET_CHAT_Account *account; - struct GNUNET_CHAT_Lobby *lobby; - - account = GNUNET_CHAT_message_get_account(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - ck_assert_ptr_null(account); - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_nonnull(account); - - lobby = GNUNET_CHAT_lobby_open( - handle, - GNUNET_TIME_relative_get_second_(), - NULL, - NULL - ); - - ck_assert_ptr_nonnull(lobby); - - GNUNET_CHAT_lobby_close(lobby); - GNUNET_CHAT_disconnect(handle); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_nonnull(account); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_BASE_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_lobby_base(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_base_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_BASE_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_lobby_base, call_gnunet_chat_lobby_base) - -void -on_gnunet_chat_lobby_join_open(void *cls, - const struct GNUNET_CHAT_Uri *uri) -{ - struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; - - ck_assert_ptr_nonnull(chat); - ck_assert_ptr_nonnull(uri); - - GNUNET_CHAT_lobby_join(chat, uri); -} - -enum GNUNET_GenericReturnValue -on_gnunet_chat_lobby_join_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - 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_nonnull(message); - - const struct GNUNET_CHAT_Account *account; - - account = GNUNET_CHAT_message_get_account(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - ck_assert_ptr_null(context); - ck_assert_ptr_null(account); - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_null(lobby); - - lobby = GNUNET_CHAT_lobby_open( - handle, - GNUNET_TIME_relative_get_second_(), - on_gnunet_chat_lobby_join_open, - handle - ); - - ck_assert_ptr_nonnull(lobby); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_null(lobby); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_JOIN_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_null(lobby); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_null(lobby); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - ck_assert_ptr_nonnull(context); - break; - case GNUNET_CHAT_KIND_JOIN: - ck_assert_ptr_nonnull(context); - ck_assert_ptr_nonnull(account); - ck_assert_ptr_nonnull(lobby); - - GNUNET_CHAT_lobby_close(lobby); - lobby = NULL; - - GNUNET_CHAT_disconnect(handle); - break; - default: - ck_abort(); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_lobby_join(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_join_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_JOIN_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_lobby_join, call_gnunet_chat_lobby_join) - -START_SUITE(lobby_suite, "Lobby") -ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_base, "Open/Close") -ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_join, "Join") -END_SUITE - -MAIN_SUITE(lobby_suite, CK_NORMAL) diff --git a/tests/test_gnunet_chat_message.c b/tests/test_gnunet_chat_message.c @@ -1,141 +0,0 @@ -/* - This file is part of GNUnet. - Copyright (C) 2023--2024 GNUnet e.V. - - GNUnet is free software: you can redistribute it and/or modify it - under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, - or (at your option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. - - SPDX-License-Identifier: AGPL3.0-or-later - */ -/* - * @author Tobias Frisch - * @file test_gnunet_chat_message.c - */ - -#include "test_gnunet_chat.h" - -#define TEST_TEXT_ID "gnunet_chat_message_text" -#define TEST_TEXT_GROUP "gnunet_chat_message_text_group" -#define TEST_TEXT_MSG "test_text_message" - -enum GNUNET_GenericReturnValue -on_gnunet_chat_message_text_msg(void *cls, - struct GNUNET_CHAT_Context *context, - const struct GNUNET_CHAT_Message *message) -{ - struct GNUNET_CHAT_Handle *handle = *( - (struct GNUNET_CHAT_Handle**) cls - ); - - const struct GNUNET_CHAT_Account *account; - struct GNUNET_CHAT_Group *group; - const char *text; - - ck_assert_ptr_nonnull(handle); - ck_assert_ptr_nonnull(message); - - account = GNUNET_CHAT_message_get_account(message); - - switch (GNUNET_CHAT_message_get_kind(message)) - { - case GNUNET_CHAT_KIND_WARNING: - ck_abort_msg("%s\n", GNUNET_CHAT_message_get_text(message)); - break; - case GNUNET_CHAT_KIND_REFRESH: - break; - case GNUNET_CHAT_KIND_LOGIN: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - group = GNUNET_CHAT_group_create(handle, TEST_TEXT_GROUP); - - ck_assert_ptr_nonnull(group); - break; - case GNUNET_CHAT_KIND_LOGOUT: - ck_assert_ptr_null(context); - ck_assert_ptr_nonnull(account); - - ck_assert_int_eq(GNUNET_CHAT_account_delete( - handle, TEST_TEXT_ID - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_CREATED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_connect(handle, account); - break; - case GNUNET_CHAT_KIND_DELETED_ACCOUNT: - ck_assert_ptr_nonnull(account); - - GNUNET_CHAT_stop(handle); - break; - case GNUNET_CHAT_KIND_UPDATE_ACCOUNT: - ck_assert_ptr_nonnull(account); - break; - case GNUNET_CHAT_KIND_UPDATE_CONTEXT: - ck_assert_ptr_nonnull(context); - break; - case GNUNET_CHAT_KIND_JOIN: - ck_assert_ptr_nonnull(context); - - ck_assert_int_eq(GNUNET_CHAT_context_send_text( - context, TEST_TEXT_MSG - ), GNUNET_OK); - break; - case GNUNET_CHAT_KIND_LEAVE: - ck_assert_ptr_nonnull(context); - - GNUNET_CHAT_disconnect(handle); - break; - case GNUNET_CHAT_KIND_CONTACT: - ck_assert_ptr_nonnull(context); - break; - case GNUNET_CHAT_KIND_TEXT: - ck_assert_ptr_nonnull(context); - - group = GNUNET_CHAT_context_get_group(context); - - ck_assert_ptr_nonnull(group); - - text = GNUNET_CHAT_message_get_text(message); - - ck_assert_str_eq(text, TEST_TEXT_MSG); - ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK); - break; - default: - ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); - break; - } - - return GNUNET_YES; -} - -void -call_gnunet_chat_message_text(const struct GNUNET_CONFIGURATION_Handle *cfg) -{ - static struct GNUNET_CHAT_Handle *handle = NULL; - handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_message_text_msg, &handle); - - ck_assert_ptr_nonnull(handle); - ck_assert_int_eq(GNUNET_CHAT_account_create( - handle, TEST_TEXT_ID - ), GNUNET_OK); -} - -CREATE_GNUNET_TEST(test_gnunet_chat_message_text, call_gnunet_chat_message_text) - -START_SUITE(handle_suite, "Message") -ADD_TEST_TO_SUITE(test_gnunet_chat_message_text, "Text") -END_SUITE - -MAIN_SUITE(handle_suite, CK_NORMAL)