diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-21 01:35:02 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-21 01:35:02 +0000 |
commit | f591bfdc7b28e93b9412c2d9e031c8848ce90f55 (patch) | |
tree | 45fd7f067088a8b797eaca0ff95c8c1181ee3be1 /src/mesh/test_mesh_path_api.c | |
parent | fe84bb63919dc9353d963234264f91a455f3f679 (diff) | |
download | gnunet-f591bfdc7b28e93b9412c2d9e031c8848ce90f55.tar.gz gnunet-f591bfdc7b28e93b9412c2d9e031c8848ce90f55.zip |
Added testcase code, fixed minor bugs
Diffstat (limited to 'src/mesh/test_mesh_path_api.c')
-rw-r--r-- | src/mesh/test_mesh_path_api.c | 168 |
1 files changed, 160 insertions, 8 deletions
diff --git a/src/mesh/test_mesh_path_api.c b/src/mesh/test_mesh_path_api.c index cc0cbc558..9bff42686 100644 --- a/src/mesh/test_mesh_path_api.c +++ b/src/mesh/test_mesh_path_api.c | |||
@@ -34,8 +34,23 @@ | |||
34 | 34 | ||
35 | #define VERBOSE 1 | 35 | #define VERBOSE 1 |
36 | 36 | ||
37 | int failed; | ||
38 | int cb_call; | ||
39 | |||
40 | void | ||
41 | cb (const struct MeshTunnelTreeNode *n) | ||
42 | { | ||
43 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: Desconnected %u\n", n->peer); | ||
44 | if(0 == cb_call) | ||
45 | { | ||
46 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "test: and it shouldn't!\n"); | ||
47 | failed++; | ||
48 | } | ||
49 | cb_call--; | ||
50 | } | ||
51 | |||
37 | /** | 52 | /** |
38 | * Convert an integer int oa peer identity | 53 | * Convert an integer int to a peer identity |
39 | */ | 54 | */ |
40 | static struct GNUNET_PeerIdentity * | 55 | static struct GNUNET_PeerIdentity * |
41 | get_pi (uint32_t id) | 56 | get_pi (uint32_t id) |
@@ -47,12 +62,19 @@ get_pi (uint32_t id) | |||
47 | return pi; | 62 | return pi; |
48 | } | 63 | } |
49 | 64 | ||
65 | |||
50 | int | 66 | int |
51 | main (int argc, char *argv[]) | 67 | main (int argc, char *argv[]) |
52 | { | 68 | { |
53 | struct GNUNET_PeerIdentity* pi; | 69 | struct GNUNET_PeerIdentity* pi[10]; |
54 | int result; | 70 | struct MeshTunnelTreeNode *node; |
71 | struct MeshTunnelTreeNode *node2; | ||
72 | struct MeshTunnelTree *tree; | ||
73 | struct MeshPeerPath *path[10]; | ||
74 | unsigned int i; | ||
55 | 75 | ||
76 | failed = 0; | ||
77 | cb_call = 0; | ||
56 | GNUNET_log_setup ("test_mesh_api_path", | 78 | GNUNET_log_setup ("test_mesh_api_path", |
57 | #if VERBOSE | 79 | #if VERBOSE |
58 | "DEBUG", | 80 | "DEBUG", |
@@ -60,15 +82,145 @@ main (int argc, char *argv[]) | |||
60 | "WARNING", | 82 | "WARNING", |
61 | #endif | 83 | #endif |
62 | NULL); | 84 | NULL); |
85 | for (i = 0; i < 10; i++) | ||
86 | { | ||
87 | pi[i] = get_pi(i); | ||
88 | GNUNET_break (i != GNUNET_PEER_intern(pi[i])); | ||
89 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer %u: %s\n", i, | ||
90 | GNUNET_h2s(&pi[i]->hashPubKey)); | ||
91 | } | ||
92 | tree = GNUNET_malloc(sizeof(struct MeshTunnelTree)); | ||
93 | tree->first_hops = GNUNET_CONTAINER_multihashmap_create(32); | ||
94 | tree->root = GNUNET_malloc(sizeof(struct MeshTunnelTreeNode)); | ||
95 | tree->root->peer = 0; | ||
96 | tree->me = tree->root; | ||
97 | path[0] = GNUNET_malloc(sizeof(struct MeshPeerPath)); | ||
98 | path[0]->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 4); | ||
99 | path[0]->peers[0] = 0; | ||
100 | path[0]->peers[1] = 1; | ||
101 | path[0]->peers[2] = 2; | ||
102 | path[0]->peers[3] = 3; | ||
103 | path[0]->length = 4; | ||
104 | |||
105 | tunnel_add_path(tree, path[0], &cb); | ||
106 | path[1] = tunnel_get_path_to_peer(tree, 3); | ||
107 | if (path[0]->length != path[1]->length || | ||
108 | memcmp(path[0]->peers, path[1]->peers, path[0]->length) != 0) | ||
109 | { | ||
110 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n"); | ||
111 | failed++; | ||
112 | } | ||
113 | path_destroy(path[1]); | ||
114 | node = tunnel_find_peer(tree->root, 3); | ||
115 | if (node->peer != 3) | ||
116 | { | ||
117 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
118 | failed++; | ||
119 | } | ||
120 | if (node->status != MESH_PEER_SEARCHING) | ||
121 | { | ||
122 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
123 | failed++; | ||
124 | } | ||
125 | |||
126 | node = tunnel_find_peer(tree->root, 2); | ||
127 | if (node->peer != 2) | ||
128 | { | ||
129 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
130 | failed++; | ||
131 | } | ||
132 | if (node->status != MESH_PEER_RELAY) | ||
133 | { | ||
134 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
135 | failed++; | ||
136 | } | ||
137 | if (node->nchildren != 1) | ||
138 | { | ||
139 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
140 | failed++; | ||
141 | } | ||
142 | |||
143 | path[0]->length--; | ||
144 | tunnel_add_path(tree, path[0], &cb); | ||
145 | |||
146 | node = tunnel_find_peer(tree->root, 2); | ||
147 | if (node->peer != 2) | ||
148 | { | ||
149 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
150 | failed++; | ||
151 | } | ||
152 | if (node->status != MESH_PEER_SEARCHING) | ||
153 | { | ||
154 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
155 | failed++; | ||
156 | } | ||
157 | if (node->nchildren != 1) | ||
158 | { | ||
159 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
160 | failed++; | ||
161 | } | ||
162 | |||
163 | path[0]->length = 4; | ||
164 | path[0]->peers[3] = 4; | ||
165 | tunnel_add_path(tree, path[0], &cb); | ||
63 | 166 | ||
64 | pi = get_pi(1); | 167 | node = tunnel_find_peer(tree->root, 2); |
65 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peer 1: %s\n", GNUNET_h2s(&pi->hashPubKey)); | 168 | if (node->peer != 2) |
169 | { | ||
170 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
171 | failed++; | ||
172 | } | ||
173 | if (node->status != MESH_PEER_SEARCHING) | ||
174 | { | ||
175 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
176 | failed++; | ||
177 | } | ||
178 | if (node->nchildren != 2) | ||
179 | { | ||
180 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
181 | failed++; | ||
182 | } | ||
66 | 183 | ||
67 | result = GNUNET_OK; | 184 | node = tunnel_find_peer(tree->root, 4); |
185 | if (node->peer != 4) | ||
186 | { | ||
187 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
188 | failed++; | ||
189 | } | ||
190 | node->status = MESH_PEER_READY; | ||
191 | cb_call = 1; | ||
192 | node2 = tunnel_del_path(tree, 4, &cb); | ||
193 | if (cb_call != 0) | ||
194 | { | ||
195 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%u callbacks missed!\n", cb_call); | ||
196 | failed++; | ||
197 | } | ||
198 | if (node2->peer != 4) | ||
199 | { | ||
200 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
201 | failed++; | ||
202 | } | ||
203 | // GNUNET_free(node2); FIXME destroy | ||
204 | node = tunnel_find_peer(tree->root, 2); | ||
205 | if (node->peer != 2) | ||
206 | { | ||
207 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer != original\n"); | ||
208 | failed++; | ||
209 | } | ||
210 | if (node->status != MESH_PEER_SEARCHING) | ||
211 | { | ||
212 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong status!\n"); | ||
213 | failed++; | ||
214 | } | ||
215 | if (node->nchildren != 1) | ||
216 | { | ||
217 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Retrieved peer wrong nchildren!\n"); | ||
218 | failed++; | ||
219 | } | ||
68 | 220 | ||
69 | if (GNUNET_SYSERR == result) | 221 | if (failed > 0) |
70 | { | 222 | { |
71 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test failed\n"); | 223 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%u tests failed\n", failed); |
72 | return 1; | 224 | return 1; |
73 | } | 225 | } |
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n"); | 226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test ok\n"); |