libgnunetchat

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

commit f55d5252c527d398226f46da1d408b06e83a096f
parent f7cd0c45711e242d4d54f1682cf5fbdfa0bb0f57
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu, 29 Aug 2024 01:02:17 +0200

Add new test case for group opening and leaving

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

Diffstat:
Atests/group/meson.build | 28++++++++++++++++++++++++++++
Atests/group/test_gnunet_chat_group_open.c | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtests/meson.build | 3+++
Mtests/test_gnunet_chat.h | 6++++--
4 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/tests/group/meson.build b/tests/group/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_group_open = executable( + 'test_gnunet_chat_group_open.test', + 'test_gnunet_chat_group_open.c', + dependencies: test_deps, + link_with: gnunetchat_lib, + include_directories: tests_include, + extra_files: test_header, +) diff --git a/tests/group/test_gnunet_chat_group_open.c b/tests/group/test_gnunet_chat_group_open.c @@ -0,0 +1,127 @@ +/* + 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_group_open.c + */ + +#include "test_gnunet_chat.h" + +#define TEST_OPEN_ID "gnunet_chat_group_open" +#define TEST_OPEN_GROUP "gnunet_chat_group_open_group" + +enum GNUNET_GenericReturnValue +on_gnunet_chat_group_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_CHAT_Group *group; + group = GNUNET_CHAT_context_get_group(context); + + 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); + + account = GNUNET_CHAT_find_account(handle, TEST_OPEN_ID); + + ck_assert_ptr_nonnull(account); + + GNUNET_CHAT_connect(handle, account); + 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); + ck_assert_ptr_null(group); + + group = GNUNET_CHAT_group_create(handle, TEST_OPEN_GROUP); + + ck_assert_ptr_nonnull(group); + break; + case GNUNET_CHAT_KIND_LOGOUT: + ck_assert_ptr_null(context); + ck_assert_ptr_nonnull(account); + ck_assert_ptr_null(group); + + 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_nonnull(group); + + ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK); + break; + case GNUNET_CHAT_KIND_LEAVE: + ck_assert_ptr_nonnull(context); + ck_assert_ptr_null(group); + + GNUNET_CHAT_disconnect(handle); + break; + case GNUNET_CHAT_KIND_CONTACT: + break; + default: + ck_abort_msg("%d\n", GNUNET_CHAT_message_get_kind(message)); + ck_abort(); + break; + } + + return GNUNET_YES; +} + +REQUIRE_GNUNET_CHAT_ACCOUNT(gnunet_chat_group_open, TEST_OPEN_ID) + +void +call_gnunet_chat_group_open(const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + static struct GNUNET_CHAT_Handle *handle = NULL; + handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_group_open_msg, &handle); + + ck_assert_ptr_nonnull(handle); +} + +CREATE_GNUNET_TEST(test_gnunet_chat_group_open, gnunet_chat_group_open) + +START_SUITE(handle_suite, "Group") +ADD_TEST_TO_SUITE(test_gnunet_chat_group_open, "Open/Close") +END_SUITE + +MAIN_SUITE(handle_suite, CK_NORMAL) diff --git a/tests/meson.build b/tests/meson.build @@ -28,6 +28,7 @@ test_header = '../test_gnunet_chat.h' subdir('attribute') subdir('discourse') subdir('file') +subdir('group') subdir('handle') subdir('lobby') subdir('message') @@ -38,6 +39,8 @@ test('test_gnunet_chat_handle_connection', test_gnunet_chat_handle_connection, d test('test_gnunet_chat_handle_update', test_gnunet_chat_handle_update, depends: gnunetchat_lib, is_parallel : false) test('test_gnunet_chat_handle_rename', test_gnunet_chat_handle_rename, depends: gnunetchat_lib, is_parallel : false) +test('test_gnunet_chat_group_open', test_gnunet_chat_group_open, depends: gnunetchat_lib, is_parallel : false) + test('test_gnunet_chat_message_text', test_gnunet_chat_message_text, depends: gnunetchat_lib, is_parallel : false) test('test_gnunet_chat_file_send', test_gnunet_chat_file_send, depends: gnunetchat_lib, is_parallel : false) diff --git a/tests/test_gnunet_chat.h b/tests/test_gnunet_chat.h @@ -25,6 +25,7 @@ #ifndef TEST_GNUNET_CHAT_H_ #define TEST_GNUNET_CHAT_H_ +#include <stdio.h> #include <stdlib.h> #include <check.h> @@ -170,8 +171,8 @@ task_##test_call (void *cls, \ { \ ck_assert_ptr_nonnull(cls); \ ck_assert_ptr_nonnull(cfg); \ - GNUNET_log( \ - GNUNET_ERROR_TYPE_INFO, \ + fprintf( \ + stdout, \ "Stage: %s\n", \ (const char*) cls \ ); \ @@ -188,6 +189,7 @@ task_##test_call (void *cls, \ char *binary = #test_call; \ char *const args [] = { binary }; \ \ + fprintf(stdout, "Running: %s\n", binary); \ result = GNUNET_PROGRAM_run( \ 1, \ args, \