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_defaults.c | |
parent | 09d0b535d3b5dc8798b18a4791d45b4a9c8ab529 (diff) | |
download | gnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.tar.gz gnunet-47a7c12c47fa10728494623ea8f89beab8e5cd77.zip |
stash
Diffstat (limited to 'src/identity/test_identity_defaults.c')
-rw-r--r-- | src/identity/test_identity_defaults.c | 149 |
1 files changed, 65 insertions, 84 deletions
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index bcd75e84c..ecda31c4c 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.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 | ||
@@ -50,15 +50,27 @@ static struct GNUNET_IDENTITY_Operation *op; | |||
50 | /** | 50 | /** |
51 | * Handle for task for timeout termination. | 51 | * Handle for task for timeout termination. |
52 | */ | 52 | */ |
53 | static struct GNUNET_SCHEDULER_Task * endbadly_task; | 53 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
54 | |||
55 | #define CHECK(cond) \ | ||
56 | do \ | ||
57 | { \ | ||
58 | if (! (cond)) \ | ||
59 | { \ | ||
60 | GNUNET_break (0); \ | ||
61 | end (); \ | ||
62 | return; \ | ||
63 | } \ | ||
64 | } while (0) | ||
54 | 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,37 +92,23 @@ 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; | 96 | res = 1; |
86 | } | 97 | } |
87 | 98 | ||
88 | 99 | ||
89 | /** | 100 | /** |
90 | * Termiante the testcase (success). | 101 | * Termiante the testcase. |
91 | * | ||
92 | * @param cls NULL | ||
93 | */ | ||
94 | static void | ||
95 | end_normally (void *cls) | ||
96 | { | ||
97 | cleanup (); | ||
98 | res = 0; | ||
99 | } | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Finish the testcase (successfully). | ||
104 | */ | 102 | */ |
105 | static void | 103 | static void |
106 | end () | 104 | end () |
107 | { | 105 | { |
108 | if (endbadly_task != NULL) | 106 | if (NULL != endbadly_task) |
109 | { | 107 | { |
110 | GNUNET_SCHEDULER_cancel (endbadly_task); | 108 | GNUNET_SCHEDULER_cancel (endbadly_task); |
111 | endbadly_task = NULL; | 109 | endbadly_task = NULL; |
112 | } | 110 | } |
113 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MILLISECONDS, | 111 | GNUNET_SCHEDULER_shutdown (); |
114 | &end_normally, NULL); | ||
115 | } | 112 | } |
116 | 113 | ||
117 | 114 | ||
@@ -122,11 +119,11 @@ end () | |||
122 | * @param emsg (should also be NULL) | 119 | * @param emsg (should also be NULL) |
123 | */ | 120 | */ |
124 | static void | 121 | static void |
125 | delete_cont (void *cls, | 122 | delete_cont (void *cls, const char *emsg) |
126 | const char *emsg) | ||
127 | { | 123 | { |
128 | op = NULL; | 124 | op = NULL; |
129 | GNUNET_assert (NULL == emsg); | 125 | CHECK (NULL == emsg); |
126 | res = 0; | ||
130 | end (); | 127 | end (); |
131 | } | 128 | } |
132 | 129 | ||
@@ -139,17 +136,15 @@ delete_cont (void *cls, | |||
139 | */ | 136 | */ |
140 | static void | 137 | static void |
141 | get_cb (void *cls, | 138 | get_cb (void *cls, |
142 | struct GNUNET_IDENTITY_Ego *ego, | 139 | struct GNUNET_IDENTITY_Ego *ego, |
143 | void **ctx, | 140 | void **ctx, |
144 | const char *identifier) | 141 | const char *identifier) |
145 | { | 142 | { |
146 | GNUNET_assert (NULL != ego); | 143 | op = NULL; |
147 | GNUNET_assert (NULL != identifier); | 144 | CHECK (NULL != ego); |
148 | GNUNET_assert (0 == strcmp (identifier, "test-id")); | 145 | CHECK (NULL != identifier); |
149 | op = GNUNET_IDENTITY_delete (h, | 146 | CHECK (0 == strcmp (identifier, "test-id")); |
150 | "test-id", | 147 | op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL); |
151 | &delete_cont, | ||
152 | NULL); | ||
153 | } | 148 | } |
154 | 149 | ||
155 | 150 | ||
@@ -162,17 +157,14 @@ get_cb (void *cls, | |||
162 | */ | 157 | */ |
163 | static void | 158 | static void |
164 | run_get (void *cls, | 159 | run_get (void *cls, |
165 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 160 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
166 | struct GNUNET_TESTING_Peer *peer) | 161 | struct GNUNET_TESTING_Peer *peer) |
167 | { | 162 | { |
168 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 163 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); |
169 | &endbadly, NULL); | 164 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
170 | h = GNUNET_IDENTITY_connect (cfg, NULL, NULL); | 165 | h = GNUNET_IDENTITY_connect (cfg, NULL, NULL); |
171 | GNUNET_assert (NULL != h); | 166 | CHECK (NULL != h); |
172 | op = GNUNET_IDENTITY_get (h, | 167 | op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL); |
173 | "test-service", | ||
174 | &get_cb, | ||
175 | NULL); | ||
176 | } | 168 | } |
177 | 169 | ||
178 | 170 | ||
@@ -183,11 +175,10 @@ run_get (void *cls, | |||
183 | * @param emsg (should also be NULL) | 175 | * @param emsg (should also be NULL) |
184 | */ | 176 | */ |
185 | static void | 177 | static void |
186 | success_set_cont (void *cls, | 178 | success_set_cont (void *cls, const char *emsg) |
187 | const char *emsg) | ||
188 | { | 179 | { |
189 | op = NULL; | 180 | op = NULL; |
190 | GNUNET_assert (NULL == emsg); | 181 | CHECK (NULL == emsg); |
191 | end (); | 182 | end (); |
192 | } | 183 | } |
193 | 184 | ||
@@ -205,19 +196,15 @@ success_set_cont (void *cls, | |||
205 | */ | 196 | */ |
206 | static void | 197 | static void |
207 | notification_cb (void *cls, | 198 | notification_cb (void *cls, |
208 | struct GNUNET_IDENTITY_Ego *ego, | 199 | struct GNUNET_IDENTITY_Ego *ego, |
209 | void **ctx, | 200 | void **ctx, |
210 | const char *identifier) | 201 | const char *identifier) |
211 | { | 202 | { |
212 | if (NULL == ego) | 203 | if (NULL == ego) |
213 | return; /* skip first call */ | 204 | return; /* skip first call */ |
214 | if (NULL == identifier) | 205 | if (NULL == identifier) |
215 | return; /* deletion / shutdown */ | 206 | return; /* deletion / shutdown */ |
216 | op = GNUNET_IDENTITY_set (h, | 207 | op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL); |
217 | "test-service", | ||
218 | ego, | ||
219 | &success_set_cont, | ||
220 | NULL); | ||
221 | } | 208 | } |
222 | 209 | ||
223 | 210 | ||
@@ -230,11 +217,11 @@ notification_cb (void *cls, | |||
230 | */ | 217 | */ |
231 | static void | 218 | static void |
232 | create_cb (void *cls, | 219 | create_cb (void *cls, |
233 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 220 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
234 | const char *emsg) | 221 | const char *emsg) |
235 | { | 222 | { |
236 | GNUNET_assert (NULL == emsg); | 223 | CHECK (NULL == emsg); |
237 | GNUNET_assert (NULL != pk); | 224 | CHECK (NULL != pk); |
238 | op = NULL; | 225 | op = NULL; |
239 | } | 226 | } |
240 | 227 | ||
@@ -248,43 +235,37 @@ create_cb (void *cls, | |||
248 | */ | 235 | */ |
249 | static void | 236 | static void |
250 | run_set (void *cls, | 237 | run_set (void *cls, |
251 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 238 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
252 | struct GNUNET_TESTING_Peer *peer) | 239 | struct GNUNET_TESTING_Peer *peer) |
253 | { | 240 | { |
254 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 241 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); |
255 | &endbadly, NULL); | 242 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); |
256 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 243 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); |
257 | GNUNET_assert (NULL != h); | 244 | CHECK (NULL != h); |
258 | op = GNUNET_IDENTITY_create (h, | 245 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); |
259 | "test-id", | ||
260 | &create_cb, | ||
261 | NULL); | ||
262 | |||
263 | } | 246 | } |
264 | 247 | ||
265 | 248 | ||
266 | int | 249 | int |
267 | main (int argc, char *argv[]) | 250 | main (int argc, char *argv[]) |
268 | { | 251 | { |
269 | GNUNET_DISK_directory_remove ("/tmp/test-identity-service"); | 252 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); |
270 | res = 1; | 253 | res = 1; |
271 | if (0 != | 254 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", |
272 | GNUNET_TESTING_service_run ("test-identity-defaults", | 255 | "identity", |
273 | "identity", | 256 | "test_identity.conf", |
274 | "test_identity.conf", | 257 | &run_set, |
275 | &run_set, | 258 | NULL)) |
276 | NULL)) | ||
277 | return 1; | 259 | return 1; |
278 | if (0 != | 260 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", |
279 | GNUNET_TESTING_service_run ("test-identity-defaults", | 261 | "identity", |
280 | "identity", | 262 | "test_identity.conf", |
281 | "test_identity.conf", | 263 | &run_get, |
282 | &run_get, | 264 | NULL)) |
283 | NULL)) | ||
284 | return 1; | 265 | return 1; |
285 | GNUNET_DISK_directory_remove ("/tmp/test-identity-service"); | 266 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); |
286 | return res; | 267 | return res; |
287 | } | 268 | } |
288 | 269 | ||
289 | 270 | ||
290 | /* end of test_identity.c */ | 271 | /* end of test_identity_defaults.c */ |