[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] add test for node_get_verbose_nickname_by_id



commit 39ff3b00cf965bab7ac82aa052ea3ea941d30a2c
Author: Qingping Hou <dave2008713@xxxxxxxxx>
Date:   Tue Feb 4 19:54:09 2014 -0500

    add test for node_get_verbose_nickname_by_id
---
 src/test/include.am      |    1 +
 src/test/test.c          |    2 ++
 src/test/test_nodelist.c |   40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/src/test/include.am b/src/test/include.am
index aa6a872..5f978b5 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -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_nodelist.c \
 	src/ext/tinytest.c
 
 src_test_test_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
diff --git a/src/test/test.c b/src/test/test.c
index 3f8e9c6..522f2af 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -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 nodelist_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 },
+  { "nodelist/", nodelist_tests },
   END_OF_GROUPS
 };
 
diff --git a/src/test/test_nodelist.c b/src/test/test_nodelist.c
new file mode 100644
index 0000000..b01ceed
--- /dev/null
+++ b/src/test/test_nodelist.c
@@ -0,0 +1,40 @@
+/* Copyright (c) 2007-2013, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file test_nodelist.c
+ * \brief Unit tests for nodelist related functions.
+ **/
+
+#include "or.h"
+#include "nodelist.h"
+#include "test.h"
+
+/** Tese the case when node_get_by_id() returns NULL,
+ * node_get_verbose_nickname_by_id should return the base 16 encoding
+ * of the id.
+ */
+static void
+test_nodelist_node_get_verbose_nickname_by_id_null_node(void *arg)
+{
+  char vname[MAX_VERBOSE_NICKNAME_LEN+1];
+  const char ID[] = "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA"
+                    "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
+  (void) arg;
+
+  /* make sure node_get_by_id returns NULL */
+  test_assert(!node_get_by_id(ID));
+  node_get_verbose_nickname_by_id(ID, vname);
+  test_streq(vname, "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+ done:
+  return;
+}
+
+#define NODE(name, flags) \
+  { #name, test_nodelist_##name, (flags), NULL, NULL }
+
+struct testcase_t nodelist_tests[] = {
+  NODE(node_get_verbose_nickname_by_id_null_node, TT_FORK),
+  END_OF_TESTCASES
+};
+



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits