commit 6ce67371c87dd8b3ed71195857d0e430a823fa80
parent 7d953503a71668ac0402a5151632dfc6ab7d4ca9
Author: Jacki <jacki@thejackimonster.de>
Date: Tue, 2 Jan 2024 22:22:56 +0100
Implement test for simple messaging and update namestore usage
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
7 files changed, 158 insertions(+), 9 deletions(-)
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
@@ -28,6 +28,7 @@
#include "gnunet_chat_util.h"
#include "gnunet_chat_context_intern.c"
+#include <gnunet/gnunet_namestore_service.h>
static const unsigned int initial_map_size_of_room = 8;
static const unsigned int initial_map_size_of_contact = 4;
@@ -363,7 +364,7 @@ skip_record_data:
if (context->query)
GNUNET_NAMESTORE_cancel(context->query);
- context->query = GNUNET_NAMESTORE_records_store(
+ context->query = GNUNET_NAMESTORE_record_set_store(
context->handle->namestore,
zone,
label,
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
@@ -318,7 +318,8 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
handle->messenger = GNUNET_MESSENGER_connect(
handle->cfg, name, key,
- on_handle_message, handle
+ on_handle_message,
+ handle
);
handle->current = account;
@@ -479,7 +480,7 @@ update_accounts_operation (struct GNUNET_CHAT_InternalAccounts **out_accounts,
accounts->handle = handle;
GNUNET_CONTAINER_DLL_insert_tail(
- handle->accounts_head,
+ handle->accounts_head,
handle->accounts_tail,
accounts
);
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
@@ -366,10 +366,10 @@ cb_account_creation (void *cls,
if (GNUNET_EC_NONE != ec)
{
handle_send_internal_message(
- handle,
- NULL,
- GNUNET_CHAT_FLAG_WARNING,
- GNUNET_ErrorCode_get_hint(ec)
+ handle,
+ NULL,
+ GNUNET_CHAT_FLAG_WARNING,
+ GNUNET_ErrorCode_get_hint(ec)
);
return;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -151,7 +151,7 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle,
void
GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle,
- const struct GNUNET_CHAT_Account *account)
+ const struct GNUNET_CHAT_Account *account)
{
GNUNET_CHAT_VERSION_ASSERT();
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c
@@ -118,7 +118,7 @@ cont_lobby_identity_create (void *cls,
lobby->uri = uri_create(&public_zone, label);
GNUNET_free(label);
- lobby->query = GNUNET_NAMESTORE_records_store(
+ lobby->query = GNUNET_NAMESTORE_record_set_store(
lobby->handle->namestore,
zone,
lobby->uri->label,
diff --git a/tests/meson.build b/tests/meson.build
@@ -50,6 +50,16 @@ test_gnunet_chat_file = executable(
extra_files: 'test_gnunet_chat.h',
)
+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_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)
diff --git a/tests/test_gnunet_chat_message.c b/tests/test_gnunet_chat_message.c
@@ -0,0 +1,137 @@
+/*
+ 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"
+#include <check.h>
+#include <stdio.h>
+
+int
+on_gnunet_chat_message_text_it(void *cls,
+ const struct GNUNET_CHAT_Handle *handle,
+ struct GNUNET_CHAT_Account *account)
+{
+ struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
+
+ ck_assert_ptr_ne(chat, NULL);
+ ck_assert_ptr_eq(handle, chat);
+ ck_assert_ptr_ne(account, NULL);
+
+ const char *name = GNUNET_CHAT_account_get_name(account);
+
+ ck_assert_ptr_ne(name, NULL);
+ ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
+
+ if (0 == strcmp(name, "gnunet_chat_message_text"))
+ {
+ GNUNET_CHAT_connect(chat, account);
+ return GNUNET_NO;
+ }
+
+ return GNUNET_YES;
+}
+
+int
+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
+ );
+
+ ck_assert_ptr_ne(handle, NULL);
+ ck_assert_ptr_ne(message, NULL);
+
+ if (GNUNET_CHAT_get_connected(handle))
+ goto skip_search_account;
+
+ GNUNET_CHAT_iterate_accounts(
+ handle,
+ on_gnunet_chat_message_text_it,
+ handle
+ );
+
+ if (!GNUNET_CHAT_get_connected(handle))
+ return GNUNET_YES;
+
+skip_search_account:
+ struct GNUNET_CHAT_Group *group = NULL;
+ const char *text = NULL;
+
+ switch (GNUNET_CHAT_message_get_kind(message))
+ {
+ case GNUNET_CHAT_KIND_LOGIN:
+ ck_assert_ptr_eq(context, NULL);
+
+ group = GNUNET_CHAT_group_create(handle, "gnunet_chat_message");
+ ck_assert_ptr_ne(group, NULL);
+
+ ck_assert_int_eq(GNUNET_CHAT_context_send_text(
+ GNUNET_CHAT_group_get_context(group), "test_text_message"
+ ), GNUNET_OK);
+ break;
+ case GNUNET_CHAT_KIND_TEXT:
+ ck_assert_ptr_ne(context, NULL);
+
+ group = GNUNET_CHAT_context_get_group(context);
+ ck_assert_ptr_ne(group, NULL);
+
+ text = GNUNET_CHAT_message_get_text(message);
+
+ ck_assert_int_eq(strcmp(text, "test_text_message"), 0);
+ ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK);
+ ck_assert_int_eq(GNUNET_CHAT_account_delete(
+ handle,
+ "gnunet_chat_message_text"
+ ), GNUNET_OK);
+
+ GNUNET_CHAT_stop(handle);
+ break;
+ default:
+ 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_ne(handle, NULL);
+ ck_assert_int_eq(GNUNET_CHAT_account_create(
+ handle,
+ "gnunet_chat_message_text"
+ ), 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)