aboutsummaryrefslogtreecommitdiff
path: root/src/identity/test_identity.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-01 00:52:06 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-01 00:52:13 +0200
commit47a7c12c47fa10728494623ea8f89beab8e5cd77 (patch)
tree2e37a6a55d169c96e9927c608a12f540e5cd0123 /src/identity/test_identity.c
parent09d0b535d3b5dc8798b18a4791d45b4a9c8ab529 (diff)
downloadgnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.tar.gz
gnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.zip
stash
Diffstat (limited to 'src/identity/test_identity.c')
-rw-r--r--src/identity/test_identity.c152
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 */
53static struct GNUNET_SCHEDULER_Task *endbadly_task; 53static 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 */
59static void 70static void
60cleanup () 71cleanup (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 ()
81static void 92static void
82endbadly (void *cls) 93endbadly (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 */
94static void
95end_normally (void *cls)
96{
97 cleanup ();
98 res = 0;
99} 96}
100 97
101 98
@@ -127,9 +124,9 @@ end ()
127 */ 124 */
128static void 125static void
129notification_cb (void *cls, 126notification_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 */
190static void 187static void
191delete_cont (void *cls, 188delete_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,
205static void 202static void
206finally_delete (void *cls) 203finally_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 */
221static void 215static void
222fail_rename_cont (void *cls, 216fail_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 */
239static void 232static void
240success_rename_cont (void *cls, 233success_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 */
259static void 247static void
260create_cb (void *cls, 248create_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, &notification_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 &notification_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
303int 279int
304main (int argc, char *argv[]) 280main (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