summaryrefslogtreecommitdiff
path: root/src/identity/test_identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/test_identity.c')
-rw-r--r--src/identity/test_identity.c230
1 files changed, 115 insertions, 115 deletions
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index 7f7371422..aaa435d4f 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -29,7 +29,7 @@
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31 31
32#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33 33
34 34
35/** 35/**
@@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task;
54 54
55#define CHECK(cond) \ 55#define CHECK(cond) \
56 do \ 56 do \
57 { \ 57 { \
58 if (!(cond)) \ 58 if (! (cond)) \
59 { \ 59 { \
60 GNUNET_break(0); \ 60 GNUNET_break (0); \
61 end(); \ 61 end (); \
62 return; \ 62 return; \
63 } \ 63 } \
64 } while (0) 64 } while (0)
65 65
66 66
67/** 67/**
68 * Clean up all resources used. 68 * Clean up all resources used.
69 */ 69 */
70static void 70static void
71cleanup(void *cls) 71cleanup (void *cls)
72{ 72{
73 (void)cls; 73 (void) cls;
74 if (NULL != op) 74 if (NULL != op)
75 { 75 {
76 GNUNET_IDENTITY_cancel(op); 76 GNUNET_IDENTITY_cancel (op);
77 op = NULL; 77 op = NULL;
78 } 78 }
79 if (NULL != h) 79 if (NULL != h)
80 { 80 {
81 GNUNET_IDENTITY_disconnect(h); 81 GNUNET_IDENTITY_disconnect (h);
82 h = NULL; 82 h = NULL;
83 } 83 }
84} 84}
85 85
86 86
@@ -90,9 +90,9 @@ cleanup(void *cls)
90 * @param cls NULL 90 * @param cls NULL
91 */ 91 */
92static void 92static void
93endbadly(void *cls) 93endbadly (void *cls)
94{ 94{
95 GNUNET_SCHEDULER_shutdown(); 95 GNUNET_SCHEDULER_shutdown ();
96} 96}
97 97
98 98
@@ -100,14 +100,14 @@ endbadly(void *cls)
100 * Finish the testcase (successfully). 100 * Finish the testcase (successfully).
101 */ 101 */
102static void 102static void
103end() 103end ()
104{ 104{
105 if (NULL != endbadly_task) 105 if (NULL != endbadly_task)
106 { 106 {
107 GNUNET_SCHEDULER_cancel(endbadly_task); 107 GNUNET_SCHEDULER_cancel (endbadly_task);
108 endbadly_task = NULL; 108 endbadly_task = NULL;
109 } 109 }
110 GNUNET_SCHEDULER_shutdown(); 110 GNUNET_SCHEDULER_shutdown ();
111} 111}
112 112
113 113
@@ -123,64 +123,64 @@ end()
123 * must thus no longer be used 123 * must thus no longer be used
124 */ 124 */
125static void 125static void
126notification_cb(void *cls, 126notification_cb (void *cls,
127 struct GNUNET_IDENTITY_Ego *ego, 127 struct GNUNET_IDENTITY_Ego *ego,
128 void **ctx, 128 void **ctx,
129 const char *identifier) 129 const char *identifier)
130{ 130{
131 static struct GNUNET_IDENTITY_Ego *my_ego; 131 static struct GNUNET_IDENTITY_Ego *my_ego;
132 static int round; 132 static int round;
133 133
134 switch (round) 134 switch (round)
135 { 135 {
136 case 0: /* end of initial iteration */ 136 case 0: /* end of initial iteration */
137 CHECK(NULL == ego); 137 CHECK (NULL == ego);
138 CHECK(NULL == identifier); 138 CHECK (NULL == identifier);
139 break; 139 break;
140 140
141 case 1: /* create */ 141 case 1: /* create */
142 CHECK(NULL != ego); 142 CHECK (NULL != ego);
143 CHECK(NULL != identifier); 143 CHECK (NULL != identifier);
144 CHECK(0 == strcmp(identifier, "test-id")); 144 CHECK (0 == strcmp (identifier, "test-id"));
145 my_ego = ego; 145 my_ego = ego;
146 *ctx = &round; 146 *ctx = &round;
147 break; 147 break;
148 148
149 case 2: /* rename */ 149 case 2: /* rename */
150 CHECK(my_ego == ego); 150 CHECK (my_ego == ego);
151 CHECK(NULL != identifier); 151 CHECK (NULL != identifier);
152 CHECK(0 == strcmp(identifier, "test")); 152 CHECK (0 == strcmp (identifier, "test"));
153 CHECK(*ctx == &round); 153 CHECK (*ctx == &round);
154 break; 154 break;
155 155
156 case 3: /* reconnect-down */ 156 case 3: /* reconnect-down */
157 CHECK(my_ego == ego); 157 CHECK (my_ego == ego);
158 CHECK(NULL == identifier); 158 CHECK (NULL == identifier);
159 CHECK(*ctx == &round); 159 CHECK (*ctx == &round);
160 *ctx = NULL; 160 *ctx = NULL;
161 break; 161 break;
162 162
163 case 4: /* reconnect-up */ 163 case 4: /* reconnect-up */
164 CHECK(NULL != identifier); 164 CHECK (NULL != identifier);
165 CHECK(0 == strcmp(identifier, "test")); 165 CHECK (0 == strcmp (identifier, "test"));
166 my_ego = ego; 166 my_ego = ego;
167 *ctx = &round; 167 *ctx = &round;
168 break; 168 break;
169 169
170 case 5: /* end of iteration after reconnect */ 170 case 5: /* end of iteration after reconnect */
171 CHECK(NULL == ego); 171 CHECK (NULL == ego);
172 CHECK(NULL == identifier); 172 CHECK (NULL == identifier);
173 break; 173 break;
174 174
175 case 6: /* delete */ 175 case 6: /* delete */
176 CHECK(my_ego == ego); 176 CHECK (my_ego == ego);
177 CHECK(*ctx == &round); 177 CHECK (*ctx == &round);
178 *ctx = NULL; 178 *ctx = NULL;
179 break; 179 break;
180 180
181 default: 181 default:
182 CHECK(0); 182 CHECK (0);
183 } 183 }
184 round++; 184 round++;
185} 185}
186 186
@@ -192,12 +192,12 @@ notification_cb(void *cls,
192 * @param emsg (should also be NULL) 192 * @param emsg (should also be NULL)
193 */ 193 */
194static void 194static void
195delete_cont(void *cls, const char *emsg) 195delete_cont (void *cls, const char *emsg)
196{ 196{
197 op = NULL; 197 op = NULL;
198 CHECK(NULL == emsg); 198 CHECK (NULL == emsg);
199 res = 0; 199 res = 0;
200 end(); 200 end ();
201} 201}
202 202
203 203
@@ -207,9 +207,9 @@ delete_cont(void *cls, const char *emsg)
207 * @param cls NULL 207 * @param cls NULL
208 */ 208 */
209static void 209static void
210finally_delete(void *cls) 210finally_delete (void *cls)
211{ 211{
212 op = GNUNET_IDENTITY_delete(h, "test", &delete_cont, NULL); 212 op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL);
213} 213}
214 214
215 215
@@ -220,13 +220,13 @@ finally_delete(void *cls)
220 * @param emsg (should also be NULL) 220 * @param emsg (should also be NULL)
221 */ 221 */
222static void 222static void
223fail_rename_cont(void *cls, const char *emsg) 223fail_rename_cont (void *cls, const char *emsg)
224{ 224{
225 CHECK(NULL != emsg); 225 CHECK (NULL != emsg);
226 op = NULL; 226 op = NULL;
227 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, 227 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
228 &finally_delete, 228 &finally_delete,
229 NULL); 229 NULL);
230} 230}
231 231
232 232
@@ -237,10 +237,10 @@ fail_rename_cont(void *cls, const char *emsg)
237 * @param emsg (should also be NULL) 237 * @param emsg (should also be NULL)
238 */ 238 */
239static void 239static void
240success_rename_cont(void *cls, const char *emsg) 240success_rename_cont (void *cls, const char *emsg)
241{ 241{
242 CHECK(NULL == emsg); 242 CHECK (NULL == emsg);
243 op = GNUNET_IDENTITY_rename(h, "test-id", "test", &fail_rename_cont, NULL); 243 op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL);
244} 244}
245 245
246 246
@@ -252,14 +252,14 @@ success_rename_cont(void *cls, const char *emsg)
252 * @param emsg error message 252 * @param emsg error message
253 */ 253 */
254static void 254static void
255create_cb(void *cls, 255create_cb (void *cls,
256 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 256 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
257 const char *emsg) 257 const char *emsg)
258{ 258{
259 CHECK(NULL != pk); 259 CHECK (NULL != pk);
260 CHECK(NULL == emsg); 260 CHECK (NULL == emsg);
261 op = 261 op =
262 GNUNET_IDENTITY_rename(h, "test-id", "test", &success_rename_cont, NULL); 262 GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL);
263} 263}
264 264
265 265
@@ -271,30 +271,30 @@ create_cb(void *cls,
271 * @param peer handle to access more of the peer (not used) 271 * @param peer handle to access more of the peer (not used)
272 */ 272 */
273static void 273static void
274run(void *cls, 274run (void *cls,
275 const struct GNUNET_CONFIGURATION_Handle *cfg, 275 const struct GNUNET_CONFIGURATION_Handle *cfg,
276 struct GNUNET_TESTING_Peer *peer) 276 struct GNUNET_TESTING_Peer *peer)
277{ 277{
278 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); 278 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL);
279 GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); 279 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL);
280 h = GNUNET_IDENTITY_connect(cfg, &notification_cb, NULL); 280 h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL);
281 CHECK(NULL != h); 281 CHECK (NULL != h);
282 op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL); 282 op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL);
283} 283}
284 284
285 285
286int 286int
287main(int argc, char *argv[]) 287main (int argc, char *argv[])
288{ 288{
289 GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); 289 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
290 res = 1; 290 res = 1;
291 if (0 != GNUNET_TESTING_service_run("test-identity", 291 if (0 != GNUNET_TESTING_service_run ("test-identity",
292 "identity", 292 "identity",
293 "test_identity.conf", 293 "test_identity.conf",
294 &run, 294 &run,
295 NULL)) 295 NULL))
296 return 1; 296 return 1;
297 GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); 297 GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service");
298 return res; 298 return res;
299} 299}
300 300