diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-21 11:39:40 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-21 11:39:40 +0000 |
commit | ad9322433829c2609909005208b9a2f195745f44 (patch) | |
tree | 6c145e67180d8800f3e49830b8ba0f6c137cd388 /src/mesh/test_mesh_path_api.c | |
parent | e78e6833d9851df6538752cd5fc98097188e8cde (diff) | |
download | gnunet-ad9322433829c2609909005208b9a2f195745f44.tar.gz gnunet-ad9322433829c2609909005208b9a2f195745f44.zip |
Updated testcase
Diffstat (limited to 'src/mesh/test_mesh_path_api.c')
-rw-r--r-- | src/mesh/test_mesh_path_api.c | 160 |
1 files changed, 157 insertions, 3 deletions
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c index 9bff42686..e1d62bce3 100644 --- a/src/mesh/test_mesh_path_api.c +++ b/src/mesh/test_mesh_path_api.c | |||
@@ -36,6 +36,8 @@ | |||
36 | 36 | ||
37 | int failed; | 37 | int failed; |
38 | int cb_call; | 38 | int cb_call; |
39 | struct GNUNET_PeerIdentity* pi[10]; | ||
40 | struct MeshTunnelTree *tree; | ||
39 | 41 | ||
40 | void | 42 | void |
41 | cb (const struct MeshTunnelTreeNode *n) | 43 | cb (const struct MeshTunnelTreeNode *n) |
@@ -49,6 +51,23 @@ cb (const struct MeshTunnelTreeNode *n) | |||
49 | cb_call--; | 51 | cb_call--; |
50 | } | 52 | } |
51 | 53 | ||
54 | |||
55 | void | ||
56 | finish(void) | ||
57 | { | ||
58 | unsigned int i; | ||
59 | |||
60 | for (i = 0; i < 10; i++) | ||
61 | { | ||
62 | GNUNET_free(pi[i]); | ||
63 | } | ||
64 | if (tree->root->nchildren > 0) | ||
65 | GNUNET_free(tree->root->children); | ||
66 | GNUNET_free(tree->root); | ||
67 | GNUNET_free(tree); | ||
68 | exit(0); | ||
69 | } | ||
70 | |||
52 | /** | 71 | /** |
53 | * Convert an integer int to a peer identity | 72 | * Convert an integer int to a peer identity |
54 | */ | 73 | */ |
@@ -66,10 +85,8 @@ get_pi (uint32_t id) | |||
66 | int | 85 | int |
67 | main (int argc, char *argv[]) | 86 | main (int argc, char *argv[]) |
68 | { | 87 | { |
69 | struct GNUNET_PeerIdentity* pi[10]; | ||
70 | struct MeshTunnelTreeNode *node; | 88 | struct MeshTunnelTreeNode *node; |
71 | struct MeshTunnelTreeNode *node2; | 89 | struct MeshTunnelTreeNode *node2; |
72 | struct MeshTunnelTree *tree; | ||
73 | struct MeshPeerPath *path[10]; | 90 | struct MeshPeerPath *path[10]; |
74 | unsigned int i; | 91 | unsigned int i; |
75 | 92 | ||
@@ -102,6 +119,7 @@ main (int argc, char *argv[]) | |||
102 | path[0]->peers[3] = 3; | 119 | path[0]->peers[3] = 3; |
103 | path[0]->length = 4; | 120 | path[0]->length = 4; |
104 | 121 | ||
122 | finish(); | ||
105 | tunnel_add_path(tree, path[0], &cb); | 123 | tunnel_add_path(tree, path[0], &cb); |
106 | path[1] = tunnel_get_path_to_peer(tree, 3); | 124 | path[1] = tunnel_get_path_to_peer(tree, 3); |
107 | if (path[0]->length != path[1]->length || | 125 | if (path[0]->length != path[1]->length || |
@@ -122,6 +140,13 @@ main (int argc, char *argv[]) | |||
122 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | 140 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); |
123 | failed++; | 141 | failed++; |
124 | } | 142 | } |
143 | node->status = MESH_PEER_READY; | ||
144 | if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) | ||
145 | { | ||
146 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
147 | failed++; | ||
148 | } | ||
149 | return 0; | ||
125 | 150 | ||
126 | node = tunnel_find_peer(tree->root, 2); | 151 | node = tunnel_find_peer(tree->root, 2); |
127 | if (node->peer != 2) | 152 | if (node->peer != 2) |
@@ -139,6 +164,28 @@ main (int argc, char *argv[]) | |||
139 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | 164 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); |
140 | failed++; | 165 | failed++; |
141 | } | 166 | } |
167 | if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) | ||
168 | { | ||
169 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
170 | failed++; | ||
171 | } | ||
172 | |||
173 | node = tunnel_find_peer(tree->root, 1); | ||
174 | if (node->peer != 1) | ||
175 | { | ||
176 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
177 | failed++; | ||
178 | } | ||
179 | if (node->status != MESH_PEER_RELAY) | ||
180 | { | ||
181 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
182 | failed++; | ||
183 | } | ||
184 | if (node->nchildren != 1) | ||
185 | { | ||
186 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
187 | failed++; | ||
188 | } | ||
142 | 189 | ||
143 | path[0]->length--; | 190 | path[0]->length--; |
144 | tunnel_add_path(tree, path[0], &cb); | 191 | tunnel_add_path(tree, path[0], &cb); |
@@ -159,8 +206,35 @@ main (int argc, char *argv[]) | |||
159 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | 206 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); |
160 | failed++; | 207 | failed++; |
161 | } | 208 | } |
209 | if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) | ||
210 | { | ||
211 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
212 | failed++; | ||
213 | } | ||
214 | if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1) | ||
215 | { | ||
216 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
217 | failed++; | ||
218 | } | ||
162 | 219 | ||
163 | path[0]->length = 4; | 220 | node = tunnel_find_peer(tree->root, 1); |
221 | if (node->peer != 1) | ||
222 | { | ||
223 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
224 | failed++; | ||
225 | } | ||
226 | if (node->status != MESH_PEER_RELAY) | ||
227 | { | ||
228 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
229 | failed++; | ||
230 | } | ||
231 | if (node->nchildren != 1) | ||
232 | { | ||
233 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
234 | failed++; | ||
235 | } | ||
236 | |||
237 | path[0]->length++; | ||
164 | path[0]->peers[3] = 4; | 238 | path[0]->peers[3] = 4; |
165 | tunnel_add_path(tree, path[0], &cb); | 239 | tunnel_add_path(tree, path[0], &cb); |
166 | 240 | ||
@@ -180,6 +254,33 @@ main (int argc, char *argv[]) | |||
180 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | 254 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); |
181 | failed++; | 255 | failed++; |
182 | } | 256 | } |
257 | if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) | ||
258 | { | ||
259 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
260 | failed++; | ||
261 | } | ||
262 | if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 1) | ||
263 | { | ||
264 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
265 | failed++; | ||
266 | } | ||
267 | |||
268 | node = tunnel_find_peer(tree->root, 1); | ||
269 | if (node->peer != 1) | ||
270 | { | ||
271 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
272 | failed++; | ||
273 | } | ||
274 | if (node->status != MESH_PEER_RELAY) | ||
275 | { | ||
276 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
277 | failed++; | ||
278 | } | ||
279 | if (node->nchildren != 1) | ||
280 | { | ||
281 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
282 | failed++; | ||
283 | } | ||
183 | 284 | ||
184 | node = tunnel_find_peer(tree->root, 4); | 285 | node = tunnel_find_peer(tree->root, 4); |
185 | if (node->peer != 4) | 286 | if (node->peer != 4) |
@@ -218,6 +319,59 @@ main (int argc, char *argv[]) | |||
218 | failed++; | 319 | failed++; |
219 | } | 320 | } |
220 | 321 | ||
322 | path[0]->length = 2; | ||
323 | path[0]->peers[1] = 3; | ||
324 | cb_call = 1; | ||
325 | tunnel_add_path(tree, path[0], cb); | ||
326 | if (cb_call != 0) | ||
327 | { | ||
328 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); | ||
329 | failed++; | ||
330 | } | ||
331 | node = tunnel_find_peer(tree->root, 2); | ||
332 | if (node->peer != 2) | ||
333 | { | ||
334 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
335 | failed++; | ||
336 | } | ||
337 | if (node->status != MESH_PEER_SEARCHING) | ||
338 | { | ||
339 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
340 | failed++; | ||
341 | } | ||
342 | if (node->nchildren != 0) | ||
343 | { | ||
344 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
345 | failed++; | ||
346 | } | ||
347 | node = tunnel_find_peer(tree->root, 3); | ||
348 | if (node->peer != 3) | ||
349 | { | ||
350 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
351 | failed++; | ||
352 | } | ||
353 | if (node->status != MESH_PEER_SEARCHING) | ||
354 | { | ||
355 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
356 | failed++; | ||
357 | } | ||
358 | if (node->nchildren != 0) | ||
359 | { | ||
360 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
361 | failed++; | ||
362 | } | ||
363 | if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1) | ||
364 | { | ||
365 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
366 | failed++; | ||
367 | } | ||
368 | if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 3) | ||
369 | { | ||
370 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); | ||
371 | failed++; | ||
372 | } | ||
373 | |||
374 | |||
221 | if (failed > 0) | 375 | if (failed > 0) |
222 | { | 376 | { |
223 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); | 377 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); |