aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_nodelist.c
diff options
context:
space:
mode:
authorQingping Hou <dave2008713@gmail.com>2014-02-04 19:54:09 -0500
committerQingping Hou <dave2008713@gmail.com>2014-02-06 16:13:55 -0500
commit39ff3b00cf965bab7ac82aa052ea3ea941d30a2c (patch)
treee236b76697d63046cb918cc566639b0ace539f64 /src/test/test_nodelist.c
parent0fbe7f31883787df9c6fe91a3869e5f3f6a2befe (diff)
downloadtor-39ff3b00cf965bab7ac82aa052ea3ea941d30a2c.tar
tor-39ff3b00cf965bab7ac82aa052ea3ea941d30a2c.tar.gz
add test for node_get_verbose_nickname_by_id
Diffstat (limited to 'src/test/test_nodelist.c')
-rw-r--r--src/test/test_nodelist.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/test_nodelist.c b/src/test/test_nodelist.c
new file mode 100644
index 000000000..b01ceed77
--- /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
+};
+