- make sure -1LL is consistently used everywhere, document
[oweals/gnunet.git] / src / mesh / test_mesh_tree_api.c
index 77fd799bd56a2f1d1011a1fb827ad788abc7f94f..1d43135e4ff058b8eaa95785accd32778faad644 100644 (file)
@@ -78,16 +78,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 +100,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 +112,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);
   }
 }
 
@@ -170,7 +170,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 +181,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");
@@ -215,8 +215,38 @@ main (int argc, char *argv[])
   test_assert (2, MESH_PEER_RELAY, 1, 0);
   test_assert (1, MESH_PEER_ROOT, 1, 0);
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Calculating costs...\n");
+  for (i = 1; i < 5; i++)
+  {
+    path->length = i;
+    if (tree_get_path_cost (tree, path) != 0)
+    {
+      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)
+  {
+    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)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: length %u cost failed!\n", i);
+    failed++;
+  }
+  path->length--;
+  if (tree_get_path_cost (tree, path) != 1)
+  {
+    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);