-fix fix
[oweals/gnunet.git] / src / mesh / test_mesh_tree_api.c
index 6ad5e918954946c9a688e733dcef5ebbc1d42532..60b88239ceb8915630b3828feabc1dad42bf68f3 100644 (file)
 #define MESH_TUNNEL_TREE_C
 #endif
 
-#define VERBOSE 1
-
-int failed;
-int cb_call;
-struct GNUNET_PeerIdentity *pi[10];
-struct MeshTunnelTree *tree;
+static int failed;
+static int cb_call;
+static struct GNUNET_PeerIdentity *pi[10];
+static struct MeshTunnelTree *tree;
 
 static void
 cb (void *cls, GNUNET_PEER_Id peer_id)
@@ -78,16 +76,15 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
   if (n->peer != peer_id)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Retrieved peer has wrong ID! (Got %u, expected %u)\n",
-                n->peer, peer_id);
+                "Retrieved peer has wrong ID! (Got %u, expected %u)\n", n->peer,
+                peer_id);
     failed++;
   }
   if (n->status != status)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 "Retrieved peer has wrong status! (Got %u, expected %u)\n",
-                n->status,
-                status);
+                n->status, status);
     failed++;
   }
   for (c = n->children_head, i = 0; NULL != c; c = c->next, i++) ;
@@ -101,7 +98,8 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
   if (0 != first_hop &&
       GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)) != first_hop)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Wrong first hop! (Got %u, expected %u)\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Wrong first hop! (Got %u, expected %u)\n",
                 GNUNET_PEER_search (tree_get_first_hop (tree, peer_id)),
                 first_hop);
     failed++;
@@ -112,8 +110,8 @@ test_assert (GNUNET_PEER_Id peer_id, enum MeshPeerState status,
 
     GNUNET_PEER_resolve (peer_id, &id);
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "*** Peer %s (%u) has failed %d checks!\n",
-                GNUNET_i2s (&id), peer_id, failed - pre_failed);
+                "*** Peer %s (%u) has failed %d checks!\n", GNUNET_i2s (&id),
+                peer_id, failed - pre_failed);
   }
 }
 
@@ -155,11 +153,7 @@ main (int argc, char *argv[])
   failed = 0;
   cb_call = 0;
   GNUNET_log_setup ("test_mesh_api_tree",
-#if VERBOSE
-                    "DEBUG",
-#else
                     "WARNING",
-#endif
                     NULL);
   for (i = 0; i < 10; i++)
   {
@@ -170,7 +164,7 @@ main (int argc, char *argv[])
   }
   tree = tree_new (1);
   tree->me = tree->root;
-  path = path_new (4);
+  path = path_new (5);
   path->peers[0] = 1;
   path->peers[1] = 2;
   path->peers[2] = 3;
@@ -181,7 +175,7 @@ main (int argc, char *argv[])
   tree_add_path (tree, path, &cb, NULL);
   tree_debug (tree);
   path1 = tree_get_path_to_peer (tree, 4);
-  if (path->length != path1->length ||
+  if (NULL == path1 || path->length != path1->length ||
       memcmp (path->peers, path1->peers, path->length) != 0)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Retrieved path != original\n");
@@ -219,41 +213,34 @@ main (int argc, char *argv[])
   for (i = 1; i < 5; i++)
   {
     path->length = i;
-    if (tree_get_path_cost(tree, path) != 0)
+    if (tree_get_path_cost (tree, path) != 0)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "test: length %u cost failed!\n",
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: length %u cost failed!\n",
                   i);
       failed++;
     }
   }
   path->length++;
   path->peers[4] = 6;
-  if (tree_get_path_cost(tree, path) != 1)
+  if (tree_get_path_cost (tree, path) != 1)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "test: length %u cost failed!\n",
-                i);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: length %u cost failed!\n", i);
     failed++;
   }
   path->peers[3] = 7;
-  if (tree_get_path_cost(tree, path) != 2)
+  if (tree_get_path_cost (tree, path) != 2)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "test: length %u cost failed!\n",
-                i);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: length %u cost failed!\n", i);
     failed++;
   }
   path->length--;
-  if (tree_get_path_cost(tree, path) != 1)
+  if (tree_get_path_cost (tree, path) != 1)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "test: length %u cost failed!\n",
-                i);
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: length %u cost failed!\n", i);
     failed++;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Deleting third path (5)\n");
-  tree_set_status(tree, 5, MESH_PEER_READY);
+  tree_set_status (tree, 5, MESH_PEER_READY);
   cb_call = 1;
   node = tree_del_path (tree, 5, &cb, NULL);
   tree_debug (tree);