From ad9322433829c2609909005208b9a2f195745f44 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Wed, 21 Sep 2011 11:39:40 +0000 Subject: [PATCH] Updated testcase --- src/mesh/test_mesh_path_api.c | 160 +++++++++++++++++++++++++++++++++- 1 file 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 @@ int failed; int cb_call; +struct GNUNET_PeerIdentity* pi[10]; +struct MeshTunnelTree *tree; void cb (const struct MeshTunnelTreeNode *n) @@ -49,6 +51,23 @@ cb (const struct MeshTunnelTreeNode *n) cb_call--; } + +void +finish(void) +{ + unsigned int i; + + for (i = 0; i < 10; i++) + { + GNUNET_free(pi[i]); + } + if (tree->root->nchildren > 0) + GNUNET_free(tree->root->children); + GNUNET_free(tree->root); + GNUNET_free(tree); + exit(0); +} + /** * Convert an integer int to a peer identity */ @@ -66,10 +85,8 @@ get_pi (uint32_t id) int main (int argc, char *argv[]) { - struct GNUNET_PeerIdentity* pi[10]; struct MeshTunnelTreeNode *node; struct MeshTunnelTreeNode *node2; - struct MeshTunnelTree *tree; struct MeshPeerPath *path[10]; unsigned int i; @@ -102,6 +119,7 @@ main (int argc, char *argv[]) path[0]->peers[3] = 3; path[0]->length = 4; + finish(); tunnel_add_path(tree, path[0], &cb); path[1] = tunnel_get_path_to_peer(tree, 3); if (path[0]->length != path[1]->length || @@ -122,6 +140,13 @@ main (int argc, char *argv[]) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); failed++; } + node->status = MESH_PEER_READY; + if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + return 0; node = tunnel_find_peer(tree->root, 2); if (node->peer != 2) @@ -139,6 +164,28 @@ main (int argc, char *argv[]) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); failed++; } + if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + + node = tunnel_find_peer(tree->root, 1); + if (node->peer != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_RELAY) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } path[0]->length--; tunnel_add_path(tree, path[0], &cb); @@ -159,8 +206,35 @@ main (int argc, char *argv[]) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); failed++; } + if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } - path[0]->length = 4; + node = tunnel_find_peer(tree->root, 1); + if (node->peer != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_RELAY) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } + + path[0]->length++; path[0]->peers[3] = 4; tunnel_add_path(tree, path[0], &cb); @@ -180,6 +254,33 @@ main (int argc, char *argv[]) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); failed++; } + if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + if (GNUNET_PEER_search(path_get_first_hop(tree, 4)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + + node = tunnel_find_peer(tree->root, 1); + if (node->peer != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_RELAY) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } node = tunnel_find_peer(tree->root, 4); if (node->peer != 4) @@ -218,6 +319,59 @@ main (int argc, char *argv[]) failed++; } + path[0]->length = 2; + path[0]->peers[1] = 3; + cb_call = 1; + tunnel_add_path(tree, path[0], cb); + if (cb_call != 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); + failed++; + } + node = tunnel_find_peer(tree->root, 2); + if (node->peer != 2) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } + node = tunnel_find_peer(tree->root, 3); + if (node->peer != 3) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); + failed++; + } + if (node->status != MESH_PEER_SEARCHING) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); + failed++; + } + if (node->nchildren != 0) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); + failed++; + } + if (GNUNET_PEER_search(path_get_first_hop(tree, 2)) != 1) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + if (GNUNET_PEER_search(path_get_first_hop(tree, 3)) != 3) + { + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Wrong first hop!\n"); + failed++; + } + + if (failed > 0) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); -- 2.25.1