[tor-commits] [tor/master] Unit test for namemap_fmt_name()

asn at torproject.org asn at torproject.org
Wed Mar 27 12:31:31 UTC 2019


commit f74301f8fdf168dbd9dbfe77362658656c70fe71
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Mar 13 15:48:45 2019 -0400

    Unit test for namemap_fmt_name()
---
 src/test/test_namemap.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/test/test_namemap.c b/src/test/test_namemap.c
index 5134e1451..df77d4e2d 100644
--- a/src/test/test_namemap.c
+++ b/src/test/test_namemap.c
@@ -142,6 +142,25 @@ test_namemap_internals(void *arg)
   namemap_clear(&m);
 }
 
+static void
+test_namemap_fmt(void *arg)
+{
+  (void)arg;
+  namemap_t m = NAMEMAP_INIT();
+
+  unsigned a = namemap_get_or_create_id(&m, "greetings");
+  unsigned b = namemap_get_or_create_id(&m, "earthlings");
+
+  tt_str_op(namemap_fmt_name(&m, a), OP_EQ, "greetings");
+  tt_str_op(namemap_fmt_name(&m, b), OP_EQ, "earthlings");
+  tt_int_op(a, OP_NE, 100);
+  tt_int_op(b, OP_NE, 100);
+  tt_str_op(namemap_fmt_name(&m, 100), OP_EQ, "{100}");
+
+ done:
+  namemap_clear(&m);
+}
+
 #define T(name) \
   { #name, test_namemap_ ## name , 0, NULL, NULL }
 
@@ -150,5 +169,6 @@ struct testcase_t namemap_tests[] = {
   T(toolong),
   T(blackbox),
   T(internals),
+  T(fmt),
   END_OF_TESTCASES
 };





More information about the tor-commits mailing list