aboutsummaryrefslogtreecommitdiff
path: root/tests/test_gnunet_chat_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_gnunet_chat_handle.c')
-rw-r--r--tests/test_gnunet_chat_handle.c146
1 files changed, 88 insertions, 58 deletions
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index efa2ba9..f8a7b60 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -37,104 +37,134 @@ call_gnunet_chat_handle_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
37 37
38CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) 38CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init)
39 39
40struct GNUNET_CHAT_Handle *login_handle; 40struct GNUNET_CHAT_Handle *accounts_handle;
41int accounts_stage;
41 42
42int 43int
43on_gnunet_chat_handle_login_msg(void *cls, 44on_gnunet_chat_handle_accounts_it(__attribute__ ((unused)) void *cls,
44 struct GNUNET_CHAT_Context *context, 45 __attribute__ ((unused)) const struct GNUNET_CHAT_Handle *handle,
45 const struct GNUNET_CHAT_Message *message) 46 struct GNUNET_CHAT_Account *account)
47{
48 const char *name = GNUNET_CHAT_account_get_name(account);
49
50 ck_assert_ptr_ne(name, NULL);
51
52 if (0 == strcmp(name, GNUNET_CHAT_TEST_ACCOUNT))
53 accounts_stage |= 2;
54
55 return GNUNET_YES;
56}
57
58int
59on_gnunet_chat_handle_accounts_msg(void *cls,
60 struct GNUNET_CHAT_Context *context,
61 const struct GNUNET_CHAT_Message *message)
46{ 62{
47 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 63 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
48 64
49 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); 65 ck_assert(kind == GNUNET_CHAT_KIND_REFRESH);
50 ck_assert_ptr_eq(cls, NULL); 66 ck_assert_ptr_eq(cls, NULL);
51 ck_assert_ptr_eq(context, NULL); 67 ck_assert_ptr_eq(context, NULL);
52 68
53 GNUNET_CHAT_stop(login_handle); 69 GNUNET_CHAT_iterate_accounts(
70 accounts_handle,
71 on_gnunet_chat_handle_accounts_it,
72 NULL
73 );
74
75 if (2 & accounts_stage)
76 {
77 if (3 == accounts_stage)
78 ck_assert_int_eq(GNUNET_CHAT_account_delete(
79 accounts_handle,
80 GNUNET_CHAT_TEST_ACCOUNT
81 ), GNUNET_OK);
82
83 accounts_stage = 4;
84 }
85 else if (4 == accounts_stage)
86 GNUNET_CHAT_stop(accounts_handle);
87 else if (0 == accounts_stage)
88 {
89 ck_assert_int_eq(GNUNET_CHAT_account_create(
90 accounts_handle,
91 GNUNET_CHAT_TEST_ACCOUNT
92 ), GNUNET_OK);
93
94 accounts_stage = 1;
95 }
96
54 return GNUNET_YES; 97 return GNUNET_YES;
55} 98}
56 99
57void 100void
58call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg) 101call_gnunet_chat_handle_accounts(const struct GNUNET_CONFIGURATION_Handle *cfg)
59{ 102{
60 login_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_login_msg, NULL); 103 accounts_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_accounts_msg, NULL);
61 ck_assert_ptr_ne(login_handle, NULL); 104 accounts_stage = 0;
105
106 ck_assert_ptr_ne(accounts_handle, NULL);
62} 107}
63 108
64CREATE_GNUNET_TEST(test_gnunet_chat_handle_login, call_gnunet_chat_handle_login) 109CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts)
65 110
66struct GNUNET_CHAT_Handle *access_handle; 111struct GNUNET_CHAT_Handle *connection_handle;
67int access_logins;
68 112
69int 113int
70on_gnunet_chat_handle_access_msg(void *cls, 114on_gnunet_chat_handle_connection_msg(void *cls,
71 struct GNUNET_CHAT_Context *context, 115 struct GNUNET_CHAT_Context *context,
72 const struct GNUNET_CHAT_Message *message) 116 const struct GNUNET_CHAT_Message *message)
73{ 117{
74 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 118 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
75 119
120 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN);
76 ck_assert_ptr_eq(cls, NULL); 121 ck_assert_ptr_eq(cls, NULL);
77 ck_assert_ptr_eq(context, NULL); 122 ck_assert_ptr_eq(context, NULL);
78 123
79 const char *key; 124 GNUNET_CHAT_stop(connection_handle);
80 const char *name; 125 return GNUNET_YES;
81 int result; 126}
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 127
100 key = GNUNET_CHAT_get_key(access_handle); 128void
101 ck_assert_ptr_ne(key, NULL); 129call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg)
130{
131 connection_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_connection_msg, NULL);
132 ck_assert_ptr_ne(connection_handle, NULL);
133}
102 134
103 result = GNUNET_CHAT_set_name(access_handle, "Bccess"); 135CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection)
104 ck_assert_int_eq(result, GNUNET_YES);
105 }
106 else
107 {
108 ck_assert(kind == GNUNET_CHAT_KIND_CONTACT);
109 136
110 ck_assert_int_eq(access_logins, 2); 137struct GNUNET_CHAT_Handle *update_handle;
111 138
112 name = GNUNET_CHAT_get_name(access_handle); 139int
113 ck_assert_str_eq(name, "Bccess"); 140on_gnunet_chat_handle_update_msg(void *cls,
141 struct GNUNET_CHAT_Context *context,
142 const struct GNUNET_CHAT_Message *message)
143{
144 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
114 145
115 GNUNET_CHAT_stop(access_handle); 146 ck_assert_ptr_eq(cls, NULL);
116 } 147 ck_assert_ptr_eq(context, NULL);
117 148
118 access_logins++; 149 GNUNET_CHAT_stop(update_handle);
119 return GNUNET_YES; 150 return GNUNET_YES;
120} 151}
121 152
122void 153void
123call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg) 154call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg)
124{ 155{
125 access_logins = 0; 156 update_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_update_msg, NULL);
126 157 ck_assert_ptr_ne(update_handle, NULL);
127 access_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_access_msg, NULL);
128 ck_assert_ptr_ne(access_handle, NULL);
129} 158}
130 159
131CREATE_GNUNET_TEST(test_gnunet_chat_handle_access, call_gnunet_chat_handle_access) 160CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update)
132 161
133 162
134START_SUITE(handle_suite, "Handle") 163START_SUITE(handle_suite, "Handle")
135ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") 164ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop")
136ADD_TEST_TO_SUITE(test_gnunet_chat_handle_login, "Login") 165ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts")
137ADD_TEST_TO_SUITE(test_gnunet_chat_handle_access, "Get/Set") 166ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect")
167ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update")
138END_SUITE 168END_SUITE
139 169
140MAIN_SUITE(handle_suite, CK_NORMAL) 170MAIN_SUITE(handle_suite, CK_NORMAL)