aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-10-12 00:31:24 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-10-12 00:31:24 +0200
commit31060c1502ce34ebed3ceb0b8365ff58169d4db9 (patch)
treef9201f3ee358ded23d29f5c70d2a5780faa89e90
parent242d75e5ceb10403e62abfb52c9381fc4351d9b5 (diff)
downloadlibgnunetchat-31060c1502ce34ebed3ceb0b8365ff58169d4db9.tar.gz
libgnunetchat-31060c1502ce34ebed3ceb0b8365ff58169d4db9.zip
Added two more test cases and corrected some functions
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_handle_intern.c19
-rw-r--r--src/gnunet_chat_lib.c5
-rw-r--r--tests/test_gnunet_chat.h2
-rw-r--r--tests/test_gnunet_chat_handle.c104
4 files changed, 115 insertions, 15 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index 10bea17..beb65d3 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -364,8 +364,16 @@ on_handle_identity(void *cls,
364 (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts))) 364 (0 < GNUNET_CONTAINER_multishortmap_size(handle->contacts)))
365 return; 365 return;
366 366
367 GNUNET_MESSENGER_find_rooms(
368 handle->messenger, NULL, find_handle_rooms, handle
369 );
370
371 GNUNET_MESSENGER_find_rooms(
372 handle->messenger, NULL, scan_handle_rooms, handle
373 );
374
367 if (!handle->msg_cb) 375 if (!handle->msg_cb)
368 goto skip_login; 376 return;
369 377
370 struct GNUNET_CHAT_Message *msg = message_create_internally( 378 struct GNUNET_CHAT_Message *msg = message_create_internally(
371 NULL, GNUNET_CHAT_FLAG_LOGIN, NULL 379 NULL, GNUNET_CHAT_FLAG_LOGIN, NULL
@@ -373,15 +381,6 @@ on_handle_identity(void *cls,
373 381
374 handle->msg_cb(handle->msg_cls, NULL, msg); 382 handle->msg_cb(handle->msg_cls, NULL, msg);
375 message_destroy(msg); 383 message_destroy(msg);
376
377skip_login:
378 GNUNET_MESSENGER_find_rooms(
379 handle->messenger, NULL, find_handle_rooms, handle
380 );
381
382 GNUNET_MESSENGER_find_rooms(
383 handle->messenger, NULL, scan_handle_rooms, handle
384 );
385} 384}
386 385
387void 386void
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index f985854..fb86885 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -665,7 +665,7 @@ GNUNET_CHAT_context_iterate_files (struct GNUNET_CHAT_Context *context,
665enum GNUNET_CHAT_MessageKind 665enum GNUNET_CHAT_MessageKind
666GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) 666GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
667{ 667{
668 if ((!message) || (!(message->msg))) 668 if (!message)
669 return GNUNET_CHAT_KIND_UNKNOWN; 669 return GNUNET_CHAT_KIND_UNKNOWN;
670 670
671 switch (message->flag) 671 switch (message->flag)
@@ -678,6 +678,9 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
678 break; 678 break;
679 } 679 }
680 680
681 if (!(message->msg))
682 return GNUNET_CHAT_KIND_UNKNOWN;
683
681 switch (message->msg->header.kind) 684 switch (message->msg->header.kind)
682 { 685 {
683 case GNUNET_MESSENGER_KIND_JOIN: 686 case GNUNET_MESSENGER_KIND_JOIN:
diff --git a/tests/test_gnunet_chat.h b/tests/test_gnunet_chat.h
index ba3c37e..80803d3 100644
--- a/tests/test_gnunet_chat.h
+++ b/tests/test_gnunet_chat.h
@@ -28,6 +28,8 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <check.h> 29#include <check.h>
30 30
31#define CK_DEFAULT_TIMEOUT 5
32
31#include <gnunet/gnunet_chat_lib.h> 33#include <gnunet/gnunet_chat_lib.h>
32 34
33#define CREATE_GNUNET_TEST(test_name, test_call) \ 35#define CREATE_GNUNET_TEST(test_name, test_call) \
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index ab0e44e..b1854cf 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -25,20 +25,116 @@
25#include "test_gnunet_chat.h" 25#include "test_gnunet_chat.h"
26 26
27void 27void
28call_gnunet_chat_handle(const struct GNUNET_CONFIGURATION_Handle *cfg) 28call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
29{ 29{
30 struct GNUNET_CHAT_Handle *handle; 30 struct GNUNET_CHAT_Handle *handle;
31 31
32 handle = GNUNET_CHAT_start(cfg, "", "Test", NULL, NULL, NULL, NULL); 32 handle = GNUNET_CHAT_start(cfg, "", "Init", NULL, NULL);
33 ck_assert_ptr_ne(handle, NULL); 33 ck_assert_ptr_ne(handle, NULL);
34 34
35 GNUNET_CHAT_stop(handle); 35 GNUNET_CHAT_stop(handle);
36} 36}
37 37
38CREATE_GNUNET_TEST(test_gnunet_chat_handle, call_gnunet_chat_handle) 38CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init)
39
40struct GNUNET_CHAT_Handle *login_handle;
41
42int
43on_gnunet_chat_handle_login_msg(void *cls,
44 struct GNUNET_CHAT_Context *context,
45 const struct GNUNET_CHAT_Message *message)
46{
47 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
48
49 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN);
50 ck_assert_ptr_eq(cls, NULL);
51 ck_assert_ptr_eq(context, NULL);
52
53 GNUNET_CHAT_stop(login_handle);
54 return GNUNET_YES;
55}
56
57void
58call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg)
59{
60 login_handle = GNUNET_CHAT_start(cfg, "", "Login", on_gnunet_chat_handle_login_msg, NULL);
61 ck_assert_ptr_ne(login_handle, NULL);
62}
63
64CREATE_GNUNET_TEST(test_gnunet_chat_handle_login, call_gnunet_chat_handle_login)
65
66struct GNUNET_CHAT_Handle *access_handle;
67int access_logins;
68
69int
70on_gnunet_chat_handle_access_msg(void *cls,
71 struct GNUNET_CHAT_Context *context,
72 const struct GNUNET_CHAT_Message *message)
73{
74 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
75
76 ck_assert_ptr_eq(cls, NULL);
77 ck_assert_ptr_eq(context, NULL);
78
79 const struct GNUNET_IDENTITY_PublicKey *key;
80 const char *name;
81 int result;
82
83 if (access_logins == 0)
84 {
85 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN);
86
87 key = GNUNET_CHAT_get_key(access_handle);
88 ck_assert_ptr_eq(key, NULL);
89
90 result = GNUNET_CHAT_update(access_handle);
91 ck_assert_int_eq(result, GNUNET_OK);
92
93 name = GNUNET_CHAT_get_name(access_handle);
94 ck_assert_str_eq(name, "Access");
95 }
96 else if (access_logins == 1)
97 {
98 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN);
99
100 key = GNUNET_CHAT_get_key(access_handle);
101 ck_assert_ptr_ne(key, NULL);
102
103 result = GNUNET_CHAT_set_name(access_handle, "Bccess");
104 ck_assert_int_eq(result, GNUNET_YES);
105 }
106 else
107 {
108 ck_assert(kind == GNUNET_CHAT_KIND_CONTACT);
109
110 ck_assert_int_eq(access_logins, 2);
111
112 name = GNUNET_CHAT_get_name(access_handle);
113 ck_assert_str_eq(name, "Bccess");
114
115 GNUNET_CHAT_stop(access_handle);
116 }
117
118 access_logins++;
119 return GNUNET_YES;
120}
121
122void
123call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg)
124{
125 access_logins = 0;
126
127 access_handle = GNUNET_CHAT_start(cfg, "", "Access", on_gnunet_chat_handle_access_msg, NULL);
128 ck_assert_ptr_ne(access_handle, NULL);
129}
130
131CREATE_GNUNET_TEST(test_gnunet_chat_handle_access, call_gnunet_chat_handle_access)
132
39 133
40START_SUITE(handle_suite, "Handle") 134START_SUITE(handle_suite, "Handle")
41ADD_TEST_TO_SUITE(test_gnunet_chat_handle, "Start/Stop") 135ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop")
136ADD_TEST_TO_SUITE(test_gnunet_chat_handle_login, "Login")
137ADD_TEST_TO_SUITE(test_gnunet_chat_handle_access, "Get/Set")
42END_SUITE 138END_SUITE
43 139
44MAIN_SUITE(handle_suite, CK_NORMAL) 140MAIN_SUITE(handle_suite, CK_NORMAL)