diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-31 15:40:23 +0200 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2022-03-31 15:40:23 +0200 |
commit | 5b266a4c6e22ba210086b6d9759fd8aae01abaaf (patch) | |
tree | 272f926ef806aee3404b7d23b9945f32904b6b4d | |
parent | 2134dfccf8be89fa5e1e595d6ec65a56ac357d78 (diff) | |
download | libgnunetchat-5b266a4c6e22ba210086b6d9759fd8aae01abaaf.tar.gz libgnunetchat-5b266a4c6e22ba210086b6d9759fd8aae01abaaf.zip |
Added account deletion and adjusted automated tests
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | include/gnunet_chat_lib.h | 15 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 22 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 6 | ||||
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 8 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 74 | ||||
-rw-r--r-- | src/gnunet_chat_lib_intern.c | 54 | ||||
-rw-r--r-- | tests/test_gnunet_chat.h | 4 | ||||
-rw-r--r-- | tests/test_gnunet_chat_handle.c | 146 |
8 files changed, 253 insertions, 76 deletions
diff --git a/include/gnunet_chat_lib.h b/include/gnunet_chat_lib.h index 9e3fd04..135e82e 100644 --- a/include/gnunet_chat_lib.h +++ b/include/gnunet_chat_lib.h | |||
@@ -362,6 +362,21 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
362 | const char* name); | 362 | const char* name); |
363 | 363 | ||
364 | /** | 364 | /** |
365 | * Deletes an existing chat account of a given chat <i>handle</i> under a | ||
366 | * unique <i>name</i>. | ||
367 | * | ||
368 | * If there is no account known to this chat handle under the provided name, the | ||
369 | * function will fail and return #GNUNET_NO. | ||
370 | * | ||
371 | * @param[in,out] handle Chat handle | ||
372 | * @param[in] name Account name | ||
373 | * @return #GNUNET_OK on success, #GNUNET_NO on failure and otherwise #GNUNET_SYSERR | ||
374 | */ | ||
375 | int | ||
376 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | ||
377 | const char* name); | ||
378 | |||
379 | /** | ||
365 | * Iterates through the accounts of a given chat <i>handle</i> with a selected | 380 | * Iterates through the accounts of a given chat <i>handle</i> with a selected |
366 | * callback and custom closure. | 381 | * callback and custom closure. |
367 | * | 382 | * |
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index d23741b..cbbbcc7 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -40,6 +40,8 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
40 | on_handle_shutdown, handle | 40 | on_handle_shutdown, handle |
41 | ); | 41 | ); |
42 | 42 | ||
43 | handle->destruction = NULL; | ||
44 | |||
43 | handle->internal_head = NULL; | 45 | handle->internal_head = NULL; |
44 | handle->internal_tail = NULL; | 46 | handle->internal_tail = NULL; |
45 | 47 | ||
@@ -85,7 +87,6 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
85 | handle->accounts_tail = NULL; | 87 | handle->accounts_tail = NULL; |
86 | 88 | ||
87 | handle->current = NULL; | 89 | handle->current = NULL; |
88 | handle->creation_op = NULL; | ||
89 | handle->monitor = NULL; | 90 | handle->monitor = NULL; |
90 | 91 | ||
91 | handle->lobbies_head = NULL; | 92 | handle->lobbies_head = NULL; |
@@ -154,25 +155,36 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) | |||
154 | if (handle->shutdown_hook) | 155 | if (handle->shutdown_hook) |
155 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); | 156 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); |
156 | 157 | ||
158 | if (handle->destruction) | ||
159 | GNUNET_SCHEDULER_cancel(handle->destruction); | ||
160 | |||
157 | if (handle->monitor) | 161 | if (handle->monitor) |
158 | GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); | 162 | GNUNET_NAMESTORE_zone_monitor_stop(handle->monitor); |
159 | 163 | ||
160 | if (handle->creation_op) | ||
161 | GNUNET_IDENTITY_cancel(handle->creation_op); | ||
162 | |||
163 | if (handle->current) | 164 | if (handle->current) |
164 | handle_disconnect(handle); | 165 | handle_disconnect(handle); |
165 | 166 | ||
166 | if (handle->namestore) | 167 | if (handle->namestore) |
167 | GNUNET_NAMESTORE_disconnect(handle->namestore); | 168 | GNUNET_NAMESTORE_disconnect(handle->namestore); |
168 | 169 | ||
170 | struct GNUNET_CHAT_InternalAccounts *accounts; | ||
171 | accounts = handle->accounts_head; | ||
172 | |||
173 | while (accounts) | ||
174 | { | ||
175 | if (accounts->op) | ||
176 | GNUNET_IDENTITY_cancel(accounts->op); | ||
177 | |||
178 | accounts->op = NULL; | ||
179 | accounts = accounts->next; | ||
180 | } | ||
181 | |||
169 | if (handle->identity) | 182 | if (handle->identity) |
170 | GNUNET_IDENTITY_disconnect(handle->identity); | 183 | GNUNET_IDENTITY_disconnect(handle->identity); |
171 | 184 | ||
172 | if (handle->arm) | 185 | if (handle->arm) |
173 | GNUNET_ARM_disconnect(handle->arm); | 186 | GNUNET_ARM_disconnect(handle->arm); |
174 | 187 | ||
175 | struct GNUNET_CHAT_InternalAccounts *accounts; | ||
176 | while (handle->accounts_head) | 188 | while (handle->accounts_head) |
177 | { | 189 | { |
178 | accounts = handle->accounts_head; | 190 | accounts = handle->accounts_head; |
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h index 5702206..2cc6349 100644 --- a/src/gnunet_chat_handle.h +++ b/src/gnunet_chat_handle.h | |||
@@ -56,6 +56,10 @@ struct GNUNET_CHAT_InternalMessages | |||
56 | struct GNUNET_CHAT_InternalAccounts | 56 | struct GNUNET_CHAT_InternalAccounts |
57 | { | 57 | { |
58 | struct GNUNET_CHAT_Account *account; | 58 | struct GNUNET_CHAT_Account *account; |
59 | |||
60 | struct GNUNET_CHAT_Handle *handle; | ||
61 | struct GNUNET_IDENTITY_Operation *op; | ||
62 | |||
59 | struct GNUNET_CHAT_InternalAccounts *next; | 63 | struct GNUNET_CHAT_InternalAccounts *next; |
60 | struct GNUNET_CHAT_InternalAccounts *prev; | 64 | struct GNUNET_CHAT_InternalAccounts *prev; |
61 | }; | 65 | }; |
@@ -82,6 +86,7 @@ struct GNUNET_CHAT_Handle | |||
82 | { | 86 | { |
83 | const struct GNUNET_CONFIGURATION_Handle* cfg; | 87 | const struct GNUNET_CONFIGURATION_Handle* cfg; |
84 | struct GNUNET_SCHEDULER_Task *shutdown_hook; | 88 | struct GNUNET_SCHEDULER_Task *shutdown_hook; |
89 | struct GNUNET_SCHEDULER_Task *destruction; | ||
85 | 90 | ||
86 | struct GNUNET_CHAT_InternalMessages *internal_head; | 91 | struct GNUNET_CHAT_InternalMessages *internal_head; |
87 | struct GNUNET_CHAT_InternalMessages *internal_tail; | 92 | struct GNUNET_CHAT_InternalMessages *internal_tail; |
@@ -95,7 +100,6 @@ struct GNUNET_CHAT_Handle | |||
95 | struct GNUNET_CHAT_InternalAccounts *accounts_tail; | 100 | struct GNUNET_CHAT_InternalAccounts *accounts_tail; |
96 | 101 | ||
97 | const struct GNUNET_CHAT_Account *current; | 102 | const struct GNUNET_CHAT_Account *current; |
98 | struct GNUNET_IDENTITY_Operation *creation_op; | ||
99 | struct GNUNET_NAMESTORE_ZoneMonitor *monitor; | 103 | struct GNUNET_NAMESTORE_ZoneMonitor *monitor; |
100 | 104 | ||
101 | struct GNUNET_CHAT_InternalLobbies *lobbies_head; | 105 | struct GNUNET_CHAT_InternalLobbies *lobbies_head; |
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index cf8a3b3..63758a8 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -224,6 +224,9 @@ on_handle_gnunet_identity(void *cls, | |||
224 | { | 224 | { |
225 | struct GNUNET_CHAT_Handle* handle = cls; | 225 | struct GNUNET_CHAT_Handle* handle = cls; |
226 | 226 | ||
227 | if (!name) | ||
228 | return; | ||
229 | |||
227 | if (!ego) | 230 | if (!ego) |
228 | goto send_refresh; | 231 | goto send_refresh; |
229 | 232 | ||
@@ -248,6 +251,8 @@ on_handle_gnunet_identity(void *cls, | |||
248 | handle->accounts_tail, | 251 | handle->accounts_tail, |
249 | accounts | 252 | accounts |
250 | ); | 253 | ); |
254 | |||
255 | GNUNET_free(accounts); | ||
251 | } | 256 | } |
252 | 257 | ||
253 | goto send_refresh; | 258 | goto send_refresh; |
@@ -267,6 +272,9 @@ skip_account: | |||
267 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); | 272 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); |
268 | accounts->account = account_create_from_ego(ego, name); | 273 | accounts->account = account_create_from_ego(ego, name); |
269 | 274 | ||
275 | accounts->handle = handle; | ||
276 | accounts->op = NULL; | ||
277 | |||
270 | if (handle->directory) | 278 | if (handle->directory) |
271 | account_update_directory(accounts->account, handle->directory); | 279 | account_update_directory(accounts->account, handle->directory); |
272 | 280 | ||
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 72db7cd..6739d15 100644 --- a/src/gnunet_chat_lib.c +++ b/src/gnunet_chat_lib.c | |||
@@ -67,10 +67,12 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle) | |||
67 | { | 67 | { |
68 | GNUNET_CHAT_VERSION_ASSERT(); | 68 | GNUNET_CHAT_VERSION_ASSERT(); |
69 | 69 | ||
70 | if (!handle) | 70 | if ((!handle) || (handle->destruction)) |
71 | return; | 71 | return; |
72 | 72 | ||
73 | handle_destroy(handle); | 73 | handle->destruction = GNUNET_SCHEDULER_add_now( |
74 | task_handle_destruction, handle | ||
75 | ); | ||
74 | } | 76 | } |
75 | 77 | ||
76 | 78 | ||
@@ -93,23 +95,76 @@ GNUNET_CHAT_account_create (struct GNUNET_CHAT_Handle *handle, | |||
93 | (0 == strcmp(accounts->account->name, name))) | 95 | (0 == strcmp(accounts->account->name, name))) |
94 | return GNUNET_NO; | 96 | return GNUNET_NO; |
95 | 97 | ||
96 | skip_account: | 98 | skip_account: |
97 | accounts = accounts->next; | 99 | accounts = accounts->next; |
98 | } | 100 | } |
99 | 101 | ||
100 | if (handle->creation_op) | 102 | accounts = GNUNET_new(struct GNUNET_CHAT_InternalAccounts); |
101 | GNUNET_IDENTITY_cancel(handle->creation_op); | 103 | accounts->account = NULL; |
104 | accounts->handle = handle; | ||
102 | 105 | ||
103 | handle->creation_op = GNUNET_IDENTITY_create( | 106 | accounts->op = GNUNET_IDENTITY_create( |
104 | handle->identity, | 107 | handle->identity, |
105 | name, | 108 | name, |
106 | NULL, | 109 | NULL, |
107 | GNUNET_IDENTITY_TYPE_ECDSA, | 110 | GNUNET_IDENTITY_TYPE_ECDSA, |
108 | cb_account_creation, | 111 | cb_account_creation, |
109 | handle | 112 | accounts |
113 | ); | ||
114 | |||
115 | if (!(accounts->op)) | ||
116 | { | ||
117 | GNUNET_free(accounts); | ||
118 | return GNUNET_SYSERR; | ||
119 | } | ||
120 | |||
121 | GNUNET_CONTAINER_DLL_insert_tail( | ||
122 | handle->accounts_head, | ||
123 | handle->accounts_tail, | ||
124 | accounts | ||
125 | ); | ||
126 | |||
127 | return GNUNET_OK; | ||
128 | } | ||
129 | |||
130 | |||
131 | int | ||
132 | GNUNET_CHAT_account_delete(struct GNUNET_CHAT_Handle *handle, | ||
133 | const char* name) | ||
134 | { | ||
135 | GNUNET_CHAT_VERSION_ASSERT(); | ||
136 | |||
137 | if ((!handle) || (!name)) | ||
138 | return GNUNET_SYSERR; | ||
139 | |||
140 | struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head; | ||
141 | while (accounts) | ||
142 | { | ||
143 | if (!(accounts->account)) | ||
144 | goto skip_account; | ||
145 | |||
146 | if ((accounts->account->name) && | ||
147 | (0 == strcmp(accounts->account->name, name))) | ||
148 | break; | ||
149 | |||
150 | skip_account: | ||
151 | accounts = accounts->next; | ||
152 | } | ||
153 | |||
154 | if (!accounts) | ||
155 | return GNUNET_NO; | ||
156 | |||
157 | if (accounts->op) | ||
158 | GNUNET_IDENTITY_cancel(accounts->op); | ||
159 | |||
160 | accounts->op = GNUNET_IDENTITY_delete( | ||
161 | handle->identity, | ||
162 | name, | ||
163 | cb_account_deletion, | ||
164 | accounts | ||
110 | ); | 165 | ); |
111 | 166 | ||
112 | return (handle->creation_op? GNUNET_OK : GNUNET_SYSERR); | 167 | return (accounts->op? GNUNET_OK : GNUNET_SYSERR); |
113 | } | 168 | } |
114 | 169 | ||
115 | 170 | ||
@@ -129,13 +184,14 @@ GNUNET_CHAT_iterate_accounts (const struct GNUNET_CHAT_Handle *handle, | |||
129 | while (accounts) | 184 | while (accounts) |
130 | { | 185 | { |
131 | if (!(accounts->account)) | 186 | if (!(accounts->account)) |
132 | return GNUNET_SYSERR; | 187 | goto skip_account; |
133 | 188 | ||
134 | result++; | 189 | result++; |
135 | 190 | ||
136 | if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account))) | 191 | if ((callback) && (GNUNET_YES != callback(cls, handle, accounts->account))) |
137 | break; | 192 | break; |
138 | 193 | ||
194 | skip_account: | ||
139 | accounts = accounts->next; | 195 | accounts = accounts->next; |
140 | } | 196 | } |
141 | 197 | ||
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c index 444f3c0..a430fe5 100644 --- a/src/gnunet_chat_lib_intern.c +++ b/src/gnunet_chat_lib_intern.c | |||
@@ -25,15 +25,36 @@ | |||
25 | #define GNUNET_UNUSED __attribute__ ((unused)) | 25 | #define GNUNET_UNUSED __attribute__ ((unused)) |
26 | 26 | ||
27 | void | 27 | void |
28 | task_handle_destruction (void *cls) | ||
29 | { | ||
30 | GNUNET_assert(cls); | ||
31 | |||
32 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | ||
33 | |||
34 | handle->destruction = NULL; | ||
35 | handle_destroy(handle); | ||
36 | } | ||
37 | |||
38 | void | ||
28 | cb_account_creation (void *cls, | 39 | cb_account_creation (void *cls, |
29 | const struct GNUNET_IDENTITY_PrivateKey *key, | 40 | const struct GNUNET_IDENTITY_PrivateKey *key, |
30 | const char *emsg) | 41 | const char *emsg) |
31 | { | 42 | { |
32 | GNUNET_assert(cls); | 43 | GNUNET_assert(cls); |
33 | 44 | ||
34 | struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls; | 45 | struct GNUNET_CHAT_InternalAccounts *accounts = ( |
46 | (struct GNUNET_CHAT_InternalAccounts*) cls | ||
47 | ); | ||
35 | 48 | ||
36 | handle->creation_op = NULL; | 49 | struct GNUNET_CHAT_Handle *handle = accounts->handle; |
50 | |||
51 | GNUNET_CONTAINER_DLL_remove( | ||
52 | handle->accounts_head, | ||
53 | handle->accounts_tail, | ||
54 | accounts | ||
55 | ); | ||
56 | |||
57 | GNUNET_free(accounts); | ||
37 | 58 | ||
38 | if (emsg) | 59 | if (emsg) |
39 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | 60 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); |
@@ -42,6 +63,35 @@ cb_account_creation (void *cls, | |||
42 | } | 63 | } |
43 | 64 | ||
44 | void | 65 | void |
66 | cb_account_deletion (void *cls, | ||
67 | const char *emsg) | ||
68 | { | ||
69 | GNUNET_assert(cls); | ||
70 | |||
71 | struct GNUNET_CHAT_InternalAccounts *accounts = ( | ||
72 | (struct GNUNET_CHAT_InternalAccounts*) cls | ||
73 | ); | ||
74 | |||
75 | struct GNUNET_CHAT_Handle *handle = accounts->handle; | ||
76 | |||
77 | if (emsg) | ||
78 | { | ||
79 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_WARNING, emsg); | ||
80 | return; | ||
81 | } | ||
82 | |||
83 | GNUNET_CONTAINER_DLL_remove( | ||
84 | handle->accounts_head, | ||
85 | handle->accounts_tail, | ||
86 | accounts | ||
87 | ); | ||
88 | |||
89 | GNUNET_free(accounts); | ||
90 | |||
91 | handle_send_internal_message(handle, NULL, GNUNET_CHAT_FLAG_REFRESH, NULL); | ||
92 | } | ||
93 | |||
94 | void | ||
45 | cb_lobby_lookup (void *cls, | 95 | cb_lobby_lookup (void *cls, |
46 | uint32_t count, | 96 | uint32_t count, |
47 | const struct GNUNET_GNSRECORD_Data *data) | 97 | const struct GNUNET_GNSRECORD_Data *data) |
diff --git a/tests/test_gnunet_chat.h b/tests/test_gnunet_chat.h index 80803d3..2172611 100644 --- a/tests/test_gnunet_chat.h +++ b/tests/test_gnunet_chat.h | |||
@@ -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 |
@@ -32,6 +32,8 @@ | |||
32 | 32 | ||
33 | #include <gnunet/gnunet_chat_lib.h> | 33 | #include <gnunet/gnunet_chat_lib.h> |
34 | 34 | ||
35 | #define GNUNET_CHAT_TEST_ACCOUNT "check" | ||
36 | |||
35 | #define CREATE_GNUNET_TEST(test_name, test_call) \ | 37 | #define CREATE_GNUNET_TEST(test_name, test_call) \ |
36 | void \ | 38 | void \ |
37 | task_##test_call (__attribute__ ((unused)) void *cls, \ | 39 | task_##test_call (__attribute__ ((unused)) void *cls, \ |
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 | ||
38 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) | 38 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_init, call_gnunet_chat_handle_init) |
39 | 39 | ||
40 | struct GNUNET_CHAT_Handle *login_handle; | 40 | struct GNUNET_CHAT_Handle *accounts_handle; |
41 | int accounts_stage; | ||
41 | 42 | ||
42 | int | 43 | int |
43 | on_gnunet_chat_handle_login_msg(void *cls, | 44 | on_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 | |||
58 | int | ||
59 | on_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 | ||
57 | void | 100 | void |
58 | call_gnunet_chat_handle_login(const struct GNUNET_CONFIGURATION_Handle *cfg) | 101 | call_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 | ||
64 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_login, call_gnunet_chat_handle_login) | 109 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_accounts, call_gnunet_chat_handle_accounts) |
65 | 110 | ||
66 | struct GNUNET_CHAT_Handle *access_handle; | 111 | struct GNUNET_CHAT_Handle *connection_handle; |
67 | int access_logins; | ||
68 | 112 | ||
69 | int | 113 | int |
70 | on_gnunet_chat_handle_access_msg(void *cls, | 114 | on_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); | 128 | void |
101 | ck_assert_ptr_ne(key, NULL); | 129 | call_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"); | 135 | CREATE_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); | 137 | struct GNUNET_CHAT_Handle *update_handle; |
111 | 138 | ||
112 | name = GNUNET_CHAT_get_name(access_handle); | 139 | int |
113 | ck_assert_str_eq(name, "Bccess"); | 140 | on_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 | ||
122 | void | 153 | void |
123 | call_gnunet_chat_handle_access(const struct GNUNET_CONFIGURATION_Handle *cfg) | 154 | call_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 | ||
131 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_access, call_gnunet_chat_handle_access) | 160 | CREATE_GNUNET_TEST(test_gnunet_chat_handle_update, call_gnunet_chat_handle_update) |
132 | 161 | ||
133 | 162 | ||
134 | START_SUITE(handle_suite, "Handle") | 163 | START_SUITE(handle_suite, "Handle") |
135 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") | 164 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_init, "Start/Stop") |
136 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_login, "Login") | 165 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_accounts, "Accounts") |
137 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_access, "Get/Set") | 166 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_connection, "Connect/Disconnect") |
167 | ADD_TEST_TO_SUITE(test_gnunet_chat_handle_update, "Update") | ||
138 | END_SUITE | 168 | END_SUITE |
139 | 169 | ||
140 | MAIN_SUITE(handle_suite, CK_NORMAL) | 170 | MAIN_SUITE(handle_suite, CK_NORMAL) |