aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacki <jacki@thejackimonster.de>2024-01-02 22:22:56 +0100
committerJacki <jacki@thejackimonster.de>2024-01-02 22:22:56 +0100
commit6ce67371c87dd8b3ed71195857d0e430a823fa80 (patch)
tree82bebb0f966491d3009888728884e6d71b0a2d5a
parent7d953503a71668ac0402a5151632dfc6ab7d4ca9 (diff)
downloadlibgnunetchat-6ce67371c87dd8b3ed71195857d0e430a823fa80.tar.gz
libgnunetchat-6ce67371c87dd8b3ed71195857d0e430a823fa80.zip
Implement test for simple messaging and update namestore usage
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r--src/gnunet_chat_context.c3
-rw-r--r--src/gnunet_chat_handle.c5
-rw-r--r--src/gnunet_chat_handle_intern.c8
-rw-r--r--src/gnunet_chat_lib.c2
-rw-r--r--src/gnunet_chat_lobby_intern.c2
-rw-r--r--tests/meson.build10
-rw-r--r--tests/test_gnunet_chat_message.c137
7 files changed, 158 insertions, 9 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index 57d23e6..c016fa3 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -28,6 +28,7 @@
28#include "gnunet_chat_util.h" 28#include "gnunet_chat_util.h"
29 29
30#include "gnunet_chat_context_intern.c" 30#include "gnunet_chat_context_intern.c"
31#include <gnunet/gnunet_namestore_service.h>
31 32
32static const unsigned int initial_map_size_of_room = 8; 33static const unsigned int initial_map_size_of_room = 8;
33static const unsigned int initial_map_size_of_contact = 4; 34static const unsigned int initial_map_size_of_contact = 4;
@@ -363,7 +364,7 @@ skip_record_data:
363 if (context->query) 364 if (context->query)
364 GNUNET_NAMESTORE_cancel(context->query); 365 GNUNET_NAMESTORE_cancel(context->query);
365 366
366 context->query = GNUNET_NAMESTORE_records_store( 367 context->query = GNUNET_NAMESTORE_record_set_store(
367 context->handle->namestore, 368 context->handle->namestore,
368 zone, 369 zone,
369 label, 370 label,
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index ed8686f..9e63756 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -318,7 +318,8 @@ handle_connect (struct GNUNET_CHAT_Handle *handle,
318 318
319 handle->messenger = GNUNET_MESSENGER_connect( 319 handle->messenger = GNUNET_MESSENGER_connect(
320 handle->cfg, name, key, 320 handle->cfg, name, key,
321 on_handle_message, handle 321 on_handle_message,
322 handle
322 ); 323 );
323 324
324 handle->current = account; 325 handle->current = account;
@@ -479,7 +480,7 @@ update_accounts_operation (struct GNUNET_CHAT_InternalAccounts **out_accounts,
479 accounts->handle = handle; 480 accounts->handle = handle;
480 481
481 GNUNET_CONTAINER_DLL_insert_tail( 482 GNUNET_CONTAINER_DLL_insert_tail(
482 handle->accounts_head, 483 handle->accounts_head,
483 handle->accounts_tail, 484 handle->accounts_tail,
484 accounts 485 accounts
485 ); 486 );
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index b334cea..da1f571 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -366,10 +366,10 @@ cb_account_creation (void *cls,
366 if (GNUNET_EC_NONE != ec) 366 if (GNUNET_EC_NONE != ec)
367 { 367 {
368 handle_send_internal_message( 368 handle_send_internal_message(
369 handle, 369 handle,
370 NULL, 370 NULL,
371 GNUNET_CHAT_FLAG_WARNING, 371 GNUNET_CHAT_FLAG_WARNING,
372 GNUNET_ErrorCode_get_hint(ec) 372 GNUNET_ErrorCode_get_hint(ec)
373 ); 373 );
374 374
375 return; 375 return;
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index d9c50a3..5eded0c 100644
--- 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,
151 151
152void 152void
153GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle, 153GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle,
154 const struct GNUNET_CHAT_Account *account) 154 const struct GNUNET_CHAT_Account *account)
155{ 155{
156 GNUNET_CHAT_VERSION_ASSERT(); 156 GNUNET_CHAT_VERSION_ASSERT();
157 157
diff --git a/src/gnunet_chat_lobby_intern.c b/src/gnunet_chat_lobby_intern.c
index 28c1b7a..664b2aa 100644
--- a/src/gnunet_chat_lobby_intern.c
+++ b/src/gnunet_chat_lobby_intern.c
@@ -118,7 +118,7 @@ cont_lobby_identity_create (void *cls,
118 lobby->uri = uri_create(&public_zone, label); 118 lobby->uri = uri_create(&public_zone, label);
119 GNUNET_free(label); 119 GNUNET_free(label);
120 120
121 lobby->query = GNUNET_NAMESTORE_records_store( 121 lobby->query = GNUNET_NAMESTORE_record_set_store(
122 lobby->handle->namestore, 122 lobby->handle->namestore,
123 zone, 123 zone,
124 lobby->uri->label, 124 lobby->uri->label,
diff --git a/tests/meson.build b/tests/meson.build
index e0cde5f..6f51afa 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -50,6 +50,16 @@ test_gnunet_chat_file = executable(
50 extra_files: 'test_gnunet_chat.h', 50 extra_files: 'test_gnunet_chat.h',
51) 51)
52 52
53test_gnunet_chat_message = executable(
54 'test_gnunet_chat_message.test',
55 'test_gnunet_chat_message.c',
56 dependencies: test_deps,
57 link_with: gnunetchat_lib,
58 include_directories: tests_include,
59 extra_files: 'test_gnunet_chat.h',
60)
61
53test('test_gnunet_chat_handle', test_gnunet_chat_handle, depends: gnunetchat_lib) 62test('test_gnunet_chat_handle', test_gnunet_chat_handle, depends: gnunetchat_lib)
54test('test_gnunet_chat_lobby', test_gnunet_chat_lobby, depends: gnunetchat_lib) 63test('test_gnunet_chat_lobby', test_gnunet_chat_lobby, depends: gnunetchat_lib)
55test('test_gnunet_chat_file', test_gnunet_chat_file, depends: gnunetchat_lib) 64test('test_gnunet_chat_file', test_gnunet_chat_file, depends: gnunetchat_lib)
65test('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
new file mode 100644
index 0000000..ea11383
--- /dev/null
+++ b/tests/test_gnunet_chat_message.c
@@ -0,0 +1,137 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2023--2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file test_gnunet_chat_message.c
23 */
24
25#include "test_gnunet_chat.h"
26#include <check.h>
27#include <stdio.h>
28
29int
30on_gnunet_chat_message_text_it(void *cls,
31 const struct GNUNET_CHAT_Handle *handle,
32 struct GNUNET_CHAT_Account *account)
33{
34 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
35
36 ck_assert_ptr_ne(chat, NULL);
37 ck_assert_ptr_eq(handle, chat);
38 ck_assert_ptr_ne(account, NULL);
39
40 const char *name = GNUNET_CHAT_account_get_name(account);
41
42 ck_assert_ptr_ne(name, NULL);
43 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
44
45 if (0 == strcmp(name, "gnunet_chat_message_text"))
46 {
47 GNUNET_CHAT_connect(chat, account);
48 return GNUNET_NO;
49 }
50
51 return GNUNET_YES;
52}
53
54int
55on_gnunet_chat_message_text_msg(void *cls,
56 struct GNUNET_CHAT_Context *context,
57 const struct GNUNET_CHAT_Message *message)
58{
59 struct GNUNET_CHAT_Handle *handle = *(
60 (struct GNUNET_CHAT_Handle**) cls
61 );
62
63 ck_assert_ptr_ne(handle, NULL);
64 ck_assert_ptr_ne(message, NULL);
65
66 if (GNUNET_CHAT_get_connected(handle))
67 goto skip_search_account;
68
69 GNUNET_CHAT_iterate_accounts(
70 handle,
71 on_gnunet_chat_message_text_it,
72 handle
73 );
74
75 if (!GNUNET_CHAT_get_connected(handle))
76 return GNUNET_YES;
77
78skip_search_account:
79 struct GNUNET_CHAT_Group *group = NULL;
80 const char *text = NULL;
81
82 switch (GNUNET_CHAT_message_get_kind(message))
83 {
84 case GNUNET_CHAT_KIND_LOGIN:
85 ck_assert_ptr_eq(context, NULL);
86
87 group = GNUNET_CHAT_group_create(handle, "gnunet_chat_message");
88 ck_assert_ptr_ne(group, NULL);
89
90 ck_assert_int_eq(GNUNET_CHAT_context_send_text(
91 GNUNET_CHAT_group_get_context(group), "test_text_message"
92 ), GNUNET_OK);
93 break;
94 case GNUNET_CHAT_KIND_TEXT:
95 ck_assert_ptr_ne(context, NULL);
96
97 group = GNUNET_CHAT_context_get_group(context);
98 ck_assert_ptr_ne(group, NULL);
99
100 text = GNUNET_CHAT_message_get_text(message);
101
102 ck_assert_int_eq(strcmp(text, "test_text_message"), 0);
103 ck_assert_int_eq(GNUNET_CHAT_group_leave(group), GNUNET_OK);
104 ck_assert_int_eq(GNUNET_CHAT_account_delete(
105 handle,
106 "gnunet_chat_message_text"
107 ), GNUNET_OK);
108
109 GNUNET_CHAT_stop(handle);
110 break;
111 default:
112 break;
113 }
114
115 return GNUNET_YES;
116}
117
118void
119call_gnunet_chat_message_text(const struct GNUNET_CONFIGURATION_Handle *cfg)
120{
121 static struct GNUNET_CHAT_Handle *handle = NULL;
122 handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_message_text_msg, &handle);
123
124 ck_assert_ptr_ne(handle, NULL);
125 ck_assert_int_eq(GNUNET_CHAT_account_create(
126 handle,
127 "gnunet_chat_message_text"
128 ), GNUNET_OK);
129}
130
131CREATE_GNUNET_TEST(test_gnunet_chat_message_text, call_gnunet_chat_message_text)
132
133START_SUITE(handle_suite, "Message")
134ADD_TEST_TO_SUITE(test_gnunet_chat_message_text, "Text")
135END_SUITE
136
137MAIN_SUITE(handle_suite, CK_NORMAL)