diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-04-04 16:01:55 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-04-04 16:01:55 +0200 |
commit | de5dccb421f01bb09764ae1da40cb226c30b8d45 (patch) | |
tree | 7c9085092c2d215a48eb4863c5aae3f421e589f0 | |
parent | 4e7fe777d6bb03b88ae3e0ac781f366f5296b23d (diff) | |
download | libgnunetchat-de5dccb421f01bb09764ae1da40cb226c30b8d45.tar.gz libgnunetchat-de5dccb421f01bb09764ae1da40cb226c30b8d45.zip |
Added test suite for lobbies
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | Makefile | 31 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 48 | ||||
-rw-r--r-- | tests/test_gnunet_chat_handle.c | 2 | ||||
-rw-r--r-- | tests/test_gnunet_chat_lobby.c | 252 |
4 files changed, 292 insertions, 41 deletions
@@ -7,26 +7,27 @@ INSTALL_DIR ?= /usr/local/ | |||
7 | 7 | ||
8 | LIBRARY = lib$(TARGET_NAME).so | 8 | LIBRARY = lib$(TARGET_NAME).so |
9 | SOURCES = gnunet_chat_lib.c\ | 9 | SOURCES = gnunet_chat_lib.c\ |
10 | gnunet_chat_account.c\ | 10 | gnunet_chat_account.c\ |
11 | gnunet_chat_contact.c\ | 11 | gnunet_chat_contact.c\ |
12 | gnunet_chat_context.c\ | 12 | gnunet_chat_context.c\ |
13 | gnunet_chat_file.c\ | 13 | gnunet_chat_file.c\ |
14 | gnunet_chat_group.c\ | 14 | gnunet_chat_group.c\ |
15 | gnunet_chat_handle.c\ | 15 | gnunet_chat_handle.c\ |
16 | gnunet_chat_invitation.c\ | 16 | gnunet_chat_invitation.c\ |
17 | gnunet_chat_lobby.c\ | 17 | gnunet_chat_lobby.c\ |
18 | gnunet_chat_message.c\ | 18 | gnunet_chat_message.c\ |
19 | gnunet_chat_uri.c\ | 19 | gnunet_chat_uri.c\ |
20 | gnunet_chat_util.c | 20 | gnunet_chat_util.c |
21 | 21 | ||
22 | HEADERS = gnunet_chat_lib.h | 22 | HEADERS = gnunet_chat_lib.h |
23 | 23 | ||
24 | TESTS = test_gnunet_chat_handle.c | 24 | TESTS = test_gnunet_chat_handle.c\ |
25 | test_gnunet_chat_lobby.c | ||
25 | 26 | ||
26 | LIBRARIES = gnunetarm\ | 27 | LIBRARIES = gnunetarm\ |
27 | gnunetfs\ | 28 | gnunetfs\ |
28 | gnunetidentity\ | 29 | gnunetidentity\ |
29 | gnunetgns\ | 30 | gnunetgns\ |
30 | gnunetmessenger\ | 31 | gnunetmessenger\ |
31 | gnunetnamestore\ | 32 | gnunetnamestore\ |
32 | gnunetregex\ | 33 | gnunetregex\ |
@@ -66,7 +67,7 @@ $(LIBRARY): $(OBJECT_FILES) | |||
66 | $(GNU_LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) | 67 | $(GNU_LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) |
67 | 68 | ||
68 | check: $(TEST_CASES) | 69 | check: $(TEST_CASES) |
69 | ./$(TEST_CASES) | 70 | $(foreach TEST_CASE,$(TEST_CASES),./$(TEST_CASE);) |
70 | 71 | ||
71 | %.test: %.c | 72 | %.test: %.c |
72 | $(GNU_CC) $(CFLAGS) $< -o $@ -I $(INCLUDE_DIR) $(TEST_FLAGS) | 73 | $(GNU_CC) $(CFLAGS) $< -o $@ -I $(INCLUDE_DIR) $(TEST_FLAGS) |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index b9b1d3e..c5d70a8 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -312,9 +312,33 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
312 | if (handle->messenger) | 312 | if (handle->messenger) |
313 | GNUNET_MESSENGER_disconnect(handle->messenger); | 313 | GNUNET_MESSENGER_disconnect(handle->messenger); |
314 | 314 | ||
315 | struct GNUNET_CHAT_UriLookups *lookups; | ||
316 | while (handle->lookups_head) | ||
317 | { | ||
318 | lookups = handle->lookups_head; | ||
319 | |||
320 | if (lookups->request) | ||
321 | GNUNET_GNS_lookup_cancel(lookups->request); | ||
322 | |||
323 | if (lookups->uri) | ||
324 | uri_destroy(lookups->uri); | ||
325 | |||
326 | GNUNET_CONTAINER_DLL_remove( | ||
327 | handle->lookups_head, | ||
328 | handle->lookups_tail, | ||
329 | lookups | ||
330 | ); | ||
331 | |||
332 | GNUNET_free(lookups); | ||
333 | } | ||
334 | |||
315 | if (handle->gns) | 335 | if (handle->gns) |
316 | GNUNET_GNS_disconnect(handle->gns); | 336 | GNUNET_GNS_disconnect(handle->gns); |
317 | 337 | ||
338 | GNUNET_CONTAINER_multihashmap_iterate( | ||
339 | handle->files, it_destroy_handle_files, NULL | ||
340 | ); | ||
341 | |||
318 | if (handle->fs) | 342 | if (handle->fs) |
319 | GNUNET_FS_stop(handle->fs); | 343 | GNUNET_FS_stop(handle->fs); |
320 | 344 | ||
@@ -322,10 +346,6 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
322 | handle->gns = NULL; | 346 | handle->gns = NULL; |
323 | handle->messenger = NULL; | 347 | handle->messenger = NULL; |
324 | 348 | ||
325 | GNUNET_CONTAINER_multihashmap_iterate( | ||
326 | handle->files, it_destroy_handle_files, NULL | ||
327 | ); | ||
328 | |||
329 | struct GNUNET_CHAT_InternalLobbies *lobbies; | 349 | struct GNUNET_CHAT_InternalLobbies *lobbies; |
330 | while (handle->lobbies_head) | 350 | while (handle->lobbies_head) |
331 | { | 351 | { |
@@ -343,26 +363,6 @@ handle_disconnect (struct GNUNET_CHAT_Handle *handle) | |||
343 | GNUNET_free(lobbies); | 363 | GNUNET_free(lobbies); |
344 | } | 364 | } |
345 | 365 | ||
346 | struct GNUNET_CHAT_UriLookups *lookups; | ||
347 | while (handle->lookups_head) | ||
348 | { | ||
349 | lookups = handle->lookups_head; | ||
350 | |||
351 | if (lookups->request) | ||
352 | GNUNET_GNS_lookup_cancel(lookups->request); | ||
353 | |||
354 | if (lookups->uri) | ||
355 | uri_destroy(lookups->uri); | ||
356 | |||
357 | GNUNET_CONTAINER_DLL_remove( | ||
358 | handle->lookups_head, | ||
359 | handle->lookups_tail, | ||
360 | lookups | ||
361 | ); | ||
362 | |||
363 | GNUNET_free(lookups); | ||
364 | } | ||
365 | |||
366 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); | 366 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); |
367 | GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); | 367 | GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); |
368 | GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); | 368 | GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); |
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c index c8a9e89..134448a 100644 --- a/tests/test_gnunet_chat_handle.c +++ b/tests/test_gnunet_chat_handle.c | |||
@@ -346,8 +346,6 @@ skip_search_account: | |||
346 | const char *name = GNUNET_CHAT_get_name(handle); | 346 | const char *name = GNUNET_CHAT_get_name(handle); |
347 | ck_assert_ptr_ne(name, NULL); | 347 | ck_assert_ptr_ne(name, NULL); |
348 | 348 | ||
349 | printf("login: %s\n", name); | ||
350 | |||
351 | char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); | 349 | char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle); |
352 | 350 | ||
353 | if (!dup) | 351 | if (!dup) |
diff --git a/tests/test_gnunet_chat_lobby.c b/tests/test_gnunet_chat_lobby.c new file mode 100644 index 0000000..8f079ed --- /dev/null +++ b/tests/test_gnunet_chat_lobby.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 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_lobby.c | ||
23 | */ | ||
24 | |||
25 | #include "test_gnunet_chat.h" | ||
26 | |||
27 | int | ||
28 | on_gnunet_chat_lobby_base_it(void *cls, | ||
29 | const struct GNUNET_CHAT_Handle *handle, | ||
30 | struct GNUNET_CHAT_Account *account) | ||
31 | { | ||
32 | struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; | ||
33 | |||
34 | ck_assert_ptr_ne(chat, NULL); | ||
35 | ck_assert_ptr_eq(handle, chat); | ||
36 | ck_assert_ptr_ne(account, NULL); | ||
37 | |||
38 | const char *name = GNUNET_CHAT_account_get_name(account); | ||
39 | |||
40 | ck_assert_ptr_ne(name, NULL); | ||
41 | ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL); | ||
42 | |||
43 | if (0 == strcmp(name, "gnunet_chat_lobby_base")) | ||
44 | { | ||
45 | GNUNET_CHAT_connect(chat, account); | ||
46 | return GNUNET_NO; | ||
47 | } | ||
48 | |||
49 | return GNUNET_YES; | ||
50 | } | ||
51 | |||
52 | int | ||
53 | on_gnunet_chat_lobby_base_msg(void *cls, | ||
54 | struct GNUNET_CHAT_Context *context, | ||
55 | const struct GNUNET_CHAT_Message *message) | ||
56 | { | ||
57 | struct GNUNET_CHAT_Handle *handle = *( | ||
58 | (struct GNUNET_CHAT_Handle**) cls | ||
59 | ); | ||
60 | |||
61 | ck_assert_ptr_ne(handle, NULL); | ||
62 | ck_assert_ptr_eq(context, NULL); | ||
63 | ck_assert_ptr_ne(message, NULL); | ||
64 | |||
65 | enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); | ||
66 | |||
67 | if ((kind != GNUNET_CHAT_KIND_REFRESH) || | ||
68 | (GNUNET_CHAT_get_connected(handle))) | ||
69 | goto skip_search_account; | ||
70 | |||
71 | ck_assert(kind == GNUNET_CHAT_KIND_REFRESH); | ||
72 | |||
73 | GNUNET_CHAT_iterate_accounts( | ||
74 | handle, | ||
75 | on_gnunet_chat_lobby_base_it, | ||
76 | handle | ||
77 | ); | ||
78 | |||
79 | if (!GNUNET_CHAT_get_connected(handle)) | ||
80 | return GNUNET_YES; | ||
81 | |||
82 | skip_search_account: | ||
83 | if (GNUNET_CHAT_KIND_LOGIN != kind) | ||
84 | return GNUNET_YES; | ||
85 | |||
86 | ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); | ||
87 | |||
88 | struct GNUNET_CHAT_Lobby *lobby = GNUNET_CHAT_lobby_open( | ||
89 | handle, | ||
90 | GNUNET_TIME_relative_get_second_(), | ||
91 | NULL, | ||
92 | NULL | ||
93 | ); | ||
94 | |||
95 | ck_assert_ptr_ne(lobby, NULL); | ||
96 | |||
97 | GNUNET_CHAT_lobby_close(lobby); | ||
98 | GNUNET_CHAT_disconnect(handle); | ||
99 | |||
100 | ck_assert_int_eq(GNUNET_CHAT_account_delete( | ||
101 | handle, | ||
102 | "gnunet_chat_lobby_base" | ||
103 | ), GNUNET_OK); | ||
104 | |||
105 | GNUNET_CHAT_stop(handle); | ||
106 | |||
107 | return GNUNET_YES; | ||
108 | } | ||
109 | |||
110 | void | ||
111 | call_gnunet_chat_lobby_base(const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
112 | { | ||
113 | static struct GNUNET_CHAT_Handle *handle = NULL; | ||
114 | handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_base_msg, &handle); | ||
115 | |||
116 | ck_assert_ptr_ne(handle, NULL); | ||
117 | ck_assert_int_eq(GNUNET_CHAT_account_create( | ||
118 | handle, | ||
119 | "gnunet_chat_lobby_base" | ||
120 | ), GNUNET_OK); | ||
121 | } | ||
122 | |||
123 | CREATE_GNUNET_TEST(test_gnunet_chat_lobby_base, call_gnunet_chat_lobby_base) | ||
124 | |||
125 | int | ||
126 | on_gnunet_chat_lobby_join_it(void *cls, | ||
127 | const struct GNUNET_CHAT_Handle *handle, | ||
128 | struct GNUNET_CHAT_Account *account) | ||
129 | { | ||
130 | struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; | ||
131 | |||
132 | ck_assert_ptr_ne(chat, NULL); | ||
133 | ck_assert_ptr_eq(handle, chat); | ||
134 | ck_assert_ptr_ne(account, NULL); | ||
135 | |||
136 | const char *name = GNUNET_CHAT_account_get_name(account); | ||
137 | |||
138 | ck_assert_ptr_ne(name, NULL); | ||
139 | ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL); | ||
140 | |||
141 | if (0 == strcmp(name, "gnunet_chat_lobby_join")) | ||
142 | { | ||
143 | GNUNET_CHAT_connect(chat, account); | ||
144 | return GNUNET_NO; | ||
145 | } | ||
146 | |||
147 | return GNUNET_YES; | ||
148 | } | ||
149 | |||
150 | void | ||
151 | on_gnunet_chat_lobby_join_task(void *cls) | ||
152 | { | ||
153 | struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; | ||
154 | |||
155 | ck_assert_ptr_ne(chat, NULL); | ||
156 | |||
157 | GNUNET_CHAT_disconnect(chat); | ||
158 | |||
159 | ck_assert_int_eq(GNUNET_CHAT_account_delete( | ||
160 | chat, | ||
161 | "gnunet_chat_lobby_join" | ||
162 | ), GNUNET_OK); | ||
163 | |||
164 | GNUNET_CHAT_stop(chat); | ||
165 | } | ||
166 | |||
167 | void | ||
168 | on_gnunet_chat_lobby_join_open(void *cls, | ||
169 | const struct GNUNET_CHAT_Uri *uri) | ||
170 | { | ||
171 | struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls; | ||
172 | |||
173 | ck_assert_ptr_ne(chat, NULL); | ||
174 | ck_assert_ptr_ne(uri, NULL); | ||
175 | |||
176 | GNUNET_CHAT_lobby_join(chat, uri); | ||
177 | |||
178 | GNUNET_SCHEDULER_add_now( | ||
179 | on_gnunet_chat_lobby_join_task, | ||
180 | chat | ||
181 | ); | ||
182 | } | ||
183 | |||
184 | int | ||
185 | on_gnunet_chat_lobby_join_msg(void *cls, | ||
186 | struct GNUNET_CHAT_Context *context, | ||
187 | const struct GNUNET_CHAT_Message *message) | ||
188 | { | ||
189 | struct GNUNET_CHAT_Handle *handle = *( | ||
190 | (struct GNUNET_CHAT_Handle**) cls | ||
191 | ); | ||
192 | |||
193 | ck_assert_ptr_ne(handle, NULL); | ||
194 | ck_assert_ptr_ne(message, NULL); | ||
195 | |||
196 | enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); | ||
197 | |||
198 | if ((kind != GNUNET_CHAT_KIND_REFRESH) || | ||
199 | (GNUNET_CHAT_get_connected(handle))) | ||
200 | goto skip_search_account; | ||
201 | |||
202 | ck_assert(kind == GNUNET_CHAT_KIND_REFRESH); | ||
203 | ck_assert_ptr_eq(context, NULL); | ||
204 | |||
205 | GNUNET_CHAT_iterate_accounts( | ||
206 | handle, | ||
207 | on_gnunet_chat_lobby_join_it, | ||
208 | handle | ||
209 | ); | ||
210 | |||
211 | if (!GNUNET_CHAT_get_connected(handle)) | ||
212 | return GNUNET_YES; | ||
213 | |||
214 | skip_search_account: | ||
215 | if (GNUNET_CHAT_KIND_LOGIN != kind) | ||
216 | return GNUNET_YES; | ||
217 | |||
218 | ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); | ||
219 | ck_assert_ptr_eq(context, NULL); | ||
220 | |||
221 | struct GNUNET_CHAT_Lobby *lobby = GNUNET_CHAT_lobby_open( | ||
222 | handle, | ||
223 | GNUNET_TIME_relative_get_second_(), | ||
224 | on_gnunet_chat_lobby_join_open, | ||
225 | handle | ||
226 | ); | ||
227 | |||
228 | ck_assert_ptr_ne(lobby, NULL); | ||
229 | return GNUNET_YES; | ||
230 | } | ||
231 | |||
232 | void | ||
233 | call_gnunet_chat_lobby_join(const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
234 | { | ||
235 | static struct GNUNET_CHAT_Handle *handle = NULL; | ||
236 | handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_lobby_join_msg, &handle); | ||
237 | |||
238 | ck_assert_ptr_ne(handle, NULL); | ||
239 | ck_assert_int_eq(GNUNET_CHAT_account_create( | ||
240 | handle, | ||
241 | "gnunet_chat_lobby_join" | ||
242 | ), GNUNET_OK); | ||
243 | } | ||
244 | |||
245 | CREATE_GNUNET_TEST(test_gnunet_chat_lobby_join, call_gnunet_chat_lobby_join) | ||
246 | |||
247 | START_SUITE(handle_suite, "Lobby") | ||
248 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_base, "Open/Close") | ||
249 | ADD_TEST_TO_SUITE(test_gnunet_chat_lobby_join, "Join") | ||
250 | END_SUITE | ||
251 | |||
252 | MAIN_SUITE(handle_suite, CK_NORMAL) | ||