diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-01 00:52:06 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-01 00:52:13 +0200 |
commit | 47a7c12c47fa10728494623ea8f89beab8e5cd77 (patch) | |
tree | 2e37a6a55d169c96e9927c608a12f540e5cd0123 /src/identity/test_identity.c | |
parent | 09d0b535d3b5dc8798b18a4791d45b4a9c8ab529 (diff) | |
download | gnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.tar.gz gnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.zip |
stash
Diffstat (limited to 'src/identity/test_identity.c')
-rw-r--r-- | src/identity/test_identity.c | 152 |
1 files changed, 64 insertions, 88 deletions
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index 163394801..74c052917 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -52,13 +52,25 @@ static struct GNUNET_IDENTITY_Operation *op; | |||
52 | */ | 52 | */ |
53 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 53 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
54 | 54 | ||
55 | #define CHECK(cond) \ | ||
56 | do \ | ||
57 | { \ | ||
58 | if (! (cond)) \ | ||
59 | { \ | ||
60 | GNUNET_break (0); \ | ||
61 | end (); \ | ||
62 | return; \ | ||
63 | } \ | ||
64 | } while (0) | ||
65 | |||
55 | 66 | ||
56 | /** | 67 | /** |
57 | * Clean up all resources used. | 68 | * Clean up all resources used. |
58 | */ | 69 | */ |
59 | static void | 70 | static void |
60 | cleanup () | 71 | cleanup (void *cls) |
61 | { | 72 | { |
73 | (void) cls; | ||
62 | if (NULL != op) | 74 | if (NULL != op) |
63 | { | 75 | { |
64 | GNUNET_IDENTITY_cancel (op); | 76 | GNUNET_IDENTITY_cancel (op); |
@@ -69,7 +81,6 @@ cleanup () | |||
69 | GNUNET_IDENTITY_disconnect (h); | 81 | GNUNET_IDENTITY_disconnect (h); |
70 | h = NULL; | 82 | h = NULL; |
71 | } | 83 | } |
72 | GNUNET_SCHEDULER_shutdown (); | ||
73 | } | 84 | } |
74 | 85 | ||
75 | 86 | ||
@@ -81,21 +92,7 @@ cleanup () | |||
81 | static void | 92 | static void |
82 | endbadly (void *cls) | 93 | endbadly (void *cls) |
83 | { | 94 | { |
84 | cleanup (); | 95 | GNUNET_SCHEDULER_shutdown (); |
85 | res = 1; | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Termiante the testcase (success). | ||
91 | * | ||
92 | * @param cls NULL | ||
93 | */ | ||
94 | static void | ||
95 | end_normally (void *cls) | ||
96 | { | ||
97 | cleanup (); | ||
98 | res = 0; | ||
99 | } | 96 | } |
100 | 97 | ||
101 | 98 | ||
@@ -127,9 +124,9 @@ end () | |||
127 | */ | 124 | */ |
128 | static void | 125 | static void |
129 | notification_cb (void *cls, | 126 | notification_cb (void *cls, |
130 | struct GNUNET_IDENTITY_Ego *ego, | 127 | struct GNUNET_IDENTITY_Ego *ego, |
131 | void **ctx, | 128 | void **ctx, |
132 | const char *identifier) | 129 | const char *identifier) |
133 | { | 130 | { |
134 | static struct GNUNET_IDENTITY_Ego *my_ego; | 131 | static struct GNUNET_IDENTITY_Ego *my_ego; |
135 | static int round; | 132 | static int round; |
@@ -137,45 +134,45 @@ notification_cb (void *cls, | |||
137 | switch (round) | 134 | switch (round) |
138 | { | 135 | { |
139 | case 0: /* end of initial iteration */ | 136 | case 0: /* end of initial iteration */ |
140 | GNUNET_assert (NULL == ego); | 137 | CHECK (NULL == ego); |
141 | GNUNET_assert (NULL == identifier); | 138 | CHECK (NULL == identifier); |
142 | break; | 139 | break; |
143 | case 1: /* create */ | 140 | case 1: /* create */ |
144 | GNUNET_assert (NULL != ego); | 141 | CHECK (NULL != ego); |
145 | GNUNET_assert (0 == strcmp (identifier, | 142 | CHECK (NULL != identifier); |
146 | "test-id")); | 143 | CHECK (0 == strcmp (identifier, "test-id")); |
147 | my_ego = ego; | 144 | my_ego = ego; |
148 | *ctx = &round; | 145 | *ctx = &round; |
149 | break; | 146 | break; |
150 | case 2: /* rename */ | 147 | case 2: /* rename */ |
151 | GNUNET_assert (my_ego == ego); | 148 | CHECK (my_ego == ego); |
152 | GNUNET_assert (0 == strcmp (identifier, | 149 | CHECK (NULL != identifier); |
153 | "test")); | 150 | CHECK (0 == strcmp (identifier, "test")); |
154 | GNUNET_assert (*ctx == &round); | 151 | CHECK (*ctx == &round); |
155 | break; | 152 | break; |
156 | case 3: /* reconnect-down */ | 153 | case 3: /* reconnect-down */ |
157 | GNUNET_assert (my_ego == ego); | 154 | CHECK (my_ego == ego); |
158 | GNUNET_assert (NULL == identifier); | 155 | CHECK (NULL == identifier); |
159 | GNUNET_assert (*ctx == &round); | 156 | CHECK (*ctx == &round); |
160 | *ctx = NULL; | 157 | *ctx = NULL; |
161 | break; | 158 | break; |
162 | case 4: /* reconnect-up */ | 159 | case 4: /* reconnect-up */ |
163 | GNUNET_assert (0 == strcmp (identifier, | 160 | CHECK (NULL != identifier); |
164 | "test")); | 161 | CHECK (0 == strcmp (identifier, "test")); |
165 | my_ego = ego; | 162 | my_ego = ego; |
166 | *ctx = &round; | 163 | *ctx = &round; |
167 | break; | 164 | break; |
168 | case 5: /* end of iteration after reconnect */ | 165 | case 5: /* end of iteration after reconnect */ |
169 | GNUNET_assert (NULL == ego); | 166 | CHECK (NULL == ego); |
170 | GNUNET_assert (NULL == identifier); | 167 | CHECK (NULL == identifier); |
171 | break; | 168 | break; |
172 | case 6: /* delete */ | 169 | case 6: /* delete */ |
173 | GNUNET_assert (my_ego == ego); | 170 | CHECK (my_ego == ego); |
174 | GNUNET_assert (*ctx == &round); | 171 | CHECK (*ctx == &round); |
175 | *ctx = NULL; | 172 | *ctx = NULL; |
176 | break; | 173 | break; |
177 | default: | 174 | default: |
178 | GNUNET_break (0); | 175 | CHECK (0); |
179 | } | 176 | } |
180 | round++; | 177 | round++; |
181 | } | 178 | } |
@@ -188,11 +185,11 @@ notification_cb (void *cls, | |||
188 | * @param emsg (should also be NULL) | 185 | * @param emsg (should also be NULL) |
189 | */ | 186 | */ |
190 | static void | 187 | static void |
191 | delete_cont (void *cls, | 188 | delete_cont (void *cls, const char *emsg) |
192 | const char *emsg) | ||
193 | { | 189 | { |
194 | op = NULL; | 190 | op = NULL; |
195 | GNUNET_assert (NULL == emsg); | 191 | CHECK (NULL == emsg); |
192 | res = 0; | ||
196 | end (); | 193 | end (); |
197 | } | 194 | } |
198 | 195 | ||
@@ -205,10 +202,7 @@ delete_cont (void *cls, | |||
205 | static void | 202 | static void |
206 | finally_delete (void *cls) | 203 | finally_delete (void *cls) |
207 | { | 204 | { |
208 | op = GNUNET_IDENTITY_delete (h, | 205 | op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL); |
209 | "test", | ||
210 | &delete_cont, | ||
211 | NULL); | ||
212 | } | 206 | } |
213 | 207 | ||
214 | 208 | ||
@@ -219,10 +213,9 @@ finally_delete (void *cls) | |||
219 | * @param emsg (should also be NULL) | 213 | * @param emsg (should also be NULL) |
220 | */ | 214 | */ |
221 | static void | 215 | static void |
222 | fail_rename_cont (void *cls, | 216 | fail_rename_cont (void *cls, const char *emsg) |
223 | const char *emsg) | ||
224 | { | 217 | { |
225 | GNUNET_assert (NULL != emsg); | 218 | CHECK (NULL != emsg); |
226 | op = NULL; | 219 | op = NULL; |
227 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 220 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
228 | &finally_delete, | 221 | &finally_delete, |
@@ -237,15 +230,10 @@ fail_rename_cont (void *cls, | |||
237 | * @param emsg (should also be NULL) | 230 | * @param emsg (should also be NULL) |
238 | */ | 231 | */ |
239 | static void | 232 | static void |
240 | success_rename_cont (void *cls, | 233 | success_rename_cont (void *cls, const char *emsg) |
241 | const char *emsg) | ||
242 | { | 234 | { |
243 | GNUNET_assert (NULL == emsg); | 235 | CHECK (NULL == emsg); |
244 | op = GNUNET_IDENTITY_rename (h, | 236 | op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); |
245 | "test-id", | ||
246 | "test", | ||
247 | &fail_rename_cont, | ||
248 | NULL); | ||
249 | } | 237 | } |
250 | 238 | ||
251 | 239 | ||
@@ -258,16 +246,13 @@ success_rename_cont (void *cls, | |||
258 | */ | 246 | */ |
259 | static void | 247 | static void |
260 | create_cb (void *cls, | 248 | create_cb (void *cls, |
261 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 249 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
262 | const char *emsg) | 250 | const char *emsg) |
263 | { | 251 | { |
264 | GNUNET_assert (NULL != pk); | 252 | CHECK (NULL != pk); |
265 | GNUNET_assert (NULL == emsg); | 253 | CHECK (NULL == emsg); |
266 | op = GNUNET_IDENTITY_rename (h, | 254 | op = |
267 | "test-id", | 255 | GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); |
268 | "test", | ||
269 | &success_rename_cont, | ||
270 | NULL); | ||
271 | } | 256 | } |
272 | 257 | ||
273 | 258 | ||
@@ -283,35 +268,26 @@ run (void *cls, | |||
283 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 268 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
284 | struct GNUNET_TESTING_Peer *peer) | 269 | struct GNUNET_TESTING_Peer *peer) |
285 | { | 270 | { |
286 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 271 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); |
287 | &endbadly, | 272 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
288 | NULL); | 273 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
289 | GNUNET_SCHEDULER_add_shutdown (&end_normally, | 274 | CHECK (NULL != h); |
290 | NULL); | 275 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); |
291 | h = GNUNET_IDENTITY_connect (cfg, | ||
292 | ¬ification_cb, | ||
293 | NULL); | ||
294 | GNUNET_assert (NULL != h); | ||
295 | op = GNUNET_IDENTITY_create (h, | ||
296 | "test-id", | ||
297 | &create_cb, | ||
298 | NULL); | ||
299 | |||
300 | } | 276 | } |
301 | 277 | ||
302 | 278 | ||
303 | int | 279 | int |
304 | main (int argc, char *argv[]) | 280 | main (int argc, char *argv[]) |
305 | { | 281 | { |
306 | GNUNET_DISK_directory_remove ("/tmp/test-identity-service"); | 282 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); |
307 | res = 1; | 283 | res = 1; |
308 | if (0 != | 284 | if (0 != GNUNET_TESTING_service_run ("test-identity", |
309 | GNUNET_TESTING_service_run ("test-identity", | 285 | "identity", |
310 | "identity", | 286 | "test_identity.conf", |
311 | "test_identity.conf", | 287 | &run, |
312 | &run, | 288 | NULL)) |
313 | NULL)) | ||
314 | return 1; | 289 | return 1; |
290 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); | ||
315 | return res; | 291 | return res; |
316 | } | 292 | } |
317 | 293 | ||