]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
add test case for node_describe_by_id
authorQingping Hou <dave2008713@gmail.com>
Sun, 26 Jan 2014 05:18:55 +0000 (00:18 -0500)
committerQingping Hou <dave2008713@gmail.com>
Thu, 30 Jan 2014 03:47:05 +0000 (22:47 -0500)
src/test/include.am
src/test/test.c
src/test/test_router.c [new file with mode: 0644]

index fe30fa4d3be75bc2406222c095a3042f3d6f5d71..b338cbe3e6772f1ad0f53232ca1d09e986df7980 100644 (file)
@@ -39,6 +39,7 @@ src_test_test_SOURCES = \
        src/test/test_util.c \
        src/test/test_config.c \
        src/test/test_hs.c \
+       src/test/test_router.c \
        src/ext/tinytest.c
 
 src_test_test_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
index 3f8e9c64f1a1b059778dcbb436fd36acff43a351..8b2a5ad67d14ffe84ce4c45ec1914bfb1f5f0321 100644 (file)
@@ -1626,6 +1626,7 @@ extern struct testcase_t controller_event_tests[];
 extern struct testcase_t logging_tests[];
 extern struct testcase_t backtrace_tests[];
 extern struct testcase_t hs_tests[];
+extern struct testcase_t router_tests[];
 
 static struct testgroup_t testgroups[] = {
   { "", test_array },
@@ -1650,6 +1651,7 @@ static struct testgroup_t testgroups[] = {
   { "extorport/", extorport_tests },
   { "control/", controller_event_tests },
   { "hs/", hs_tests },
+  { "router/", router_tests },
   END_OF_GROUPS
 };
 
diff --git a/src/test/test_router.c b/src/test/test_router.c
new file mode 100644 (file)
index 0000000..c13ccc6
--- /dev/null
@@ -0,0 +1,38 @@
+/* Copyright (c) 2007-2013, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file test_router.c
+ * \brief Unit tests for router related functions.
+ **/
+
+#include "or.h"
+#include "nodelist.h"
+#include "router.h"
+#include "test.h"
+
+
+/** Tese the case when node_get_by_id() returns NULL, node_describe_by_id
+ * should return the base 16 encoding of the id.
+ */
+static void
+test_node_describe_by_id_null_node(void *arg)
+{
+  (void) arg;
+
+  #define ID "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
+
+  /* make sure node_get_by_id returns NULL */
+  test_assert(!node_get_by_id(ID));
+  test_streq(node_describe_by_id(ID),
+              "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+done:
+  return;
+}
+
+struct testcase_t router_tests[] = {
+  { "node_get_by_id_null_node", test_node_describe_by_id_null_node, TT_FORK,
+    NULL, NULL },
+  END_OF_TESTCASES
+};
+