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.c160
1 files changed, 144 insertions, 16 deletions
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
index f8a7b60..f4d4ef8 100644
--- a/tests/test_gnunet_chat_handle.c
+++ b/tests/test_gnunet_chat_handle.c
@@ -49,7 +49,7 @@ on_gnunet_chat_handle_accounts_it(__attribute__ ((unused)) void *cls,
49 49
50 ck_assert_ptr_ne(name, NULL); 50 ck_assert_ptr_ne(name, NULL);
51 51
52 if (0 == strcmp(name, GNUNET_CHAT_TEST_ACCOUNT)) 52 if (0 == strcmp(name, "gnunet_chat_handle_accounts"))
53 accounts_stage |= 2; 53 accounts_stage |= 2;
54 54
55 return GNUNET_YES; 55 return GNUNET_YES;
@@ -77,7 +77,7 @@ on_gnunet_chat_handle_accounts_msg(void *cls,
77 if (3 == accounts_stage) 77 if (3 == accounts_stage)
78 ck_assert_int_eq(GNUNET_CHAT_account_delete( 78 ck_assert_int_eq(GNUNET_CHAT_account_delete(
79 accounts_handle, 79 accounts_handle,
80 GNUNET_CHAT_TEST_ACCOUNT 80 "gnunet_chat_handle_accounts"
81 ), GNUNET_OK); 81 ), GNUNET_OK);
82 82
83 accounts_stage = 4; 83 accounts_stage = 4;
@@ -88,7 +88,7 @@ on_gnunet_chat_handle_accounts_msg(void *cls,
88 { 88 {
89 ck_assert_int_eq(GNUNET_CHAT_account_create( 89 ck_assert_int_eq(GNUNET_CHAT_account_create(
90 accounts_handle, 90 accounts_handle,
91 GNUNET_CHAT_TEST_ACCOUNT 91 "gnunet_chat_handle_accounts"
92 ), GNUNET_OK); 92 ), GNUNET_OK);
93 93
94 accounts_stage = 1; 94 accounts_stage = 1;
@@ -108,53 +108,181 @@ call_gnunet_chat_handle_accounts(const struct GNUNET_CONFIGURATION_Handle *cfg)
108 108
109CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts) 109CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts)
110 110
111struct GNUNET_CHAT_Handle *connection_handle; 111int
112on_gnunet_chat_handle_connection_it(void *cls,
113 const struct GNUNET_CHAT_Handle *handle,
114 struct GNUNET_CHAT_Account *account)
115{
116 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
117
118 ck_assert_ptr_ne(chat, NULL);
119 ck_assert_ptr_eq(handle, chat);
120 ck_assert_ptr_ne(account, NULL);
121
122 const char *name = GNUNET_CHAT_account_get_name(account);
123
124 ck_assert_ptr_ne(name, NULL);
125 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
126
127 if (0 == strcmp(name, "gnunet_chat_handle_connection"))
128 {
129 GNUNET_CHAT_connect(chat, account);
130 return GNUNET_NO;
131 }
132
133 return GNUNET_YES;
134}
112 135
113int 136int
114on_gnunet_chat_handle_connection_msg(void *cls, 137on_gnunet_chat_handle_connection_msg(void *cls,
115 struct GNUNET_CHAT_Context *context, 138 struct GNUNET_CHAT_Context *context,
116 const struct GNUNET_CHAT_Message *message) 139 const struct GNUNET_CHAT_Message *message)
117{ 140{
118 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 141 struct GNUNET_CHAT_Handle *handle = *(
142 (struct GNUNET_CHAT_Handle**) cls
143 );
119 144
120 ck_assert(kind == GNUNET_CHAT_KIND_LOGIN); 145 ck_assert_ptr_ne(handle, NULL);
121 ck_assert_ptr_eq(cls, NULL);
122 ck_assert_ptr_eq(context, NULL); 146 ck_assert_ptr_eq(context, NULL);
147 ck_assert_ptr_ne(message, NULL);
123 148
124 GNUNET_CHAT_stop(connection_handle); 149 GNUNET_CHAT_iterate_accounts(
150 handle,
151 on_gnunet_chat_handle_connection_it,
152 handle
153 );
154
155 if (!GNUNET_CHAT_get_connected(handle))
156 return GNUNET_YES;
157
158 GNUNET_CHAT_disconnect(handle);
159
160 ck_assert_int_eq(GNUNET_CHAT_account_delete(
161 handle,
162 "gnunet_chat_handle_connection"
163 ), GNUNET_OK);
164
165 GNUNET_CHAT_stop(handle);
125 return GNUNET_YES; 166 return GNUNET_YES;
126} 167}
127 168
128void 169void
129call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg) 170call_gnunet_chat_handle_connection(const struct GNUNET_CONFIGURATION_Handle *cfg)
130{ 171{
131 connection_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_connection_msg, NULL); 172 static struct GNUNET_CHAT_Handle *handle = NULL;
132 ck_assert_ptr_ne(connection_handle, NULL); 173 handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_connection_msg, &handle);
174
175 ck_assert_ptr_ne(handle, NULL);
176 ck_assert_int_eq(GNUNET_CHAT_account_create(
177 handle,
178 "gnunet_chat_handle_connection"
179 ), GNUNET_OK);
133} 180}
134 181
135CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection) 182CREATE_GNUNET_TEST(test_gnunet_chat_handle_connection, call_gnunet_chat_handle_connection)
136 183
137struct GNUNET_CHAT_Handle *update_handle; 184int
185on_gnunet_chat_handle_update_it(void *cls,
186 const struct GNUNET_CHAT_Handle *handle,
187 struct GNUNET_CHAT_Account *account)
188{
189 struct GNUNET_CHAT_Handle *chat = (struct GNUNET_CHAT_Handle*) cls;
190
191 ck_assert_ptr_ne(chat, NULL);
192 ck_assert_ptr_eq(handle, chat);
193 ck_assert_ptr_ne(account, NULL);
194
195 const char *name = GNUNET_CHAT_account_get_name(account);
196
197 ck_assert_ptr_ne(name, NULL);
198 ck_assert_ptr_eq(GNUNET_CHAT_get_connected(handle), NULL);
199
200 if (0 == strcmp(name, "gnunet_chat_handle_update"))
201 {
202 GNUNET_CHAT_connect(chat, account);
203 return GNUNET_NO;
204 }
205
206 return GNUNET_YES;
207}
138 208
139int 209int
140on_gnunet_chat_handle_update_msg(void *cls, 210on_gnunet_chat_handle_update_msg(void *cls,
141 struct GNUNET_CHAT_Context *context, 211 struct GNUNET_CHAT_Context *context,
142 const struct GNUNET_CHAT_Message *message) 212 const struct GNUNET_CHAT_Message *message)
143{ 213{
144 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 214 struct GNUNET_CHAT_Handle *handle = *(
215 (struct GNUNET_CHAT_Handle**) cls
216 );
145 217
146 ck_assert_ptr_eq(cls, NULL); 218 ck_assert_ptr_ne(handle, NULL);
147 ck_assert_ptr_eq(context, NULL); 219 ck_assert_ptr_eq(context, NULL);
220 ck_assert_ptr_ne(message, NULL);
221
222 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
223
224 if (GNUNET_CHAT_get_connected(handle))
225 goto skip_search_account;
226
227 GNUNET_CHAT_iterate_accounts(
228 handle,
229 on_gnunet_chat_handle_update_it,
230 handle
231 );
232
233 if (!GNUNET_CHAT_get_connected(handle))
234 return GNUNET_YES;
235
236skip_search_account:
237 if (GNUNET_CHAT_KIND_LOGIN != kind)
238 return GNUNET_YES;
239
240 const char *key = GNUNET_CHAT_get_key(handle);
241 ck_assert_ptr_ne(key, NULL);
242
243 char *dup = (char*) GNUNET_CHAT_get_user_pointer(handle);
244
245 if (!dup)
246 {
247 dup = GNUNET_strdup(key);
248
249 ck_assert_ptr_ne(dup, NULL);
250 ck_assert_str_eq(key, dup);
251
252 GNUNET_CHAT_set_user_pointer(handle, (void*) dup);
253 GNUNET_CHAT_update(handle);
254 }
255 else
256 {
257 ck_assert_ptr_ne(dup, NULL);
258 // ck_assert_str_ne(key, dup); // TODO: needs to be implemented in service!
259
260 GNUNET_free(dup);
261
262 GNUNET_CHAT_disconnect(handle);
263
264 ck_assert_int_eq(GNUNET_CHAT_account_delete(
265 handle,
266 "gnunet_chat_handle_update"
267 ), GNUNET_OK);
268
269 GNUNET_CHAT_stop(handle);
270 }
148 271
149 GNUNET_CHAT_stop(update_handle);
150 return GNUNET_YES; 272 return GNUNET_YES;
151} 273}
152 274
153void 275void
154call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg) 276call_gnunet_chat_handle_update(const struct GNUNET_CONFIGURATION_Handle *cfg)
155{ 277{
156 update_handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_update_msg, NULL); 278 static struct GNUNET_CHAT_Handle *handle = NULL;
157 ck_assert_ptr_ne(update_handle, NULL); 279 handle = GNUNET_CHAT_start(cfg, on_gnunet_chat_handle_update_msg, &handle);
280
281 ck_assert_ptr_ne(handle, NULL);
282 ck_assert_int_eq(GNUNET_CHAT_account_create(
283 handle,
284 "gnunet_chat_handle_update"
285 ), GNUNET_OK);
158} 286}
159 287
160CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) 288CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update)