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

[tor-commits] [tor/master] Add tests for variable-listing functions.



commit aa3f0c4788c5cb07243a764589c912a8ed4a26cd
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Aug 27 09:01:39 2019 -0400

    Add tests for variable-listing functions.
    
    This discovered a bug related to an extra & in
    config_mgr_list_deprecated_vars(): fix that.
---
 src/app/config/confparse.c |  2 +-
 src/test/test_confparse.c  | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/src/app/config/confparse.c b/src/app/config/confparse.c
index cf1710733..8b2b53003 100644
--- a/src/app/config/confparse.c
+++ b/src/app/config/confparse.c
@@ -327,7 +327,7 @@ config_mgr_list_deprecated_vars(const config_mgr_t *mgr)
   smartlist_t *result = smartlist_new();
   tor_assert(mgr);
   SMARTLIST_FOREACH(mgr->all_deprecations, config_deprecation_t *, d,
-                    smartlist_add(result, &d->name));
+                    smartlist_add(result, (char*)d->name));
   return result;
 }
 
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c
index eaa257aed..1d2e31ab9 100644
--- a/src/test/test_confparse.c
+++ b/src/test/test_confparse.c
@@ -932,6 +932,74 @@ test_confparse_check_ok_fail(void *arg)
   config_mgr_free(mgr);
 }
 
+static void
+test_confparse_list_vars(void *arg)
+{
+  (void)arg;
+  config_mgr_t *mgr = config_mgr_new(&test_fmt);
+  smartlist_t *vars = config_mgr_list_vars(mgr);
+  smartlist_t *varnames = smartlist_new();
+  char *joined = NULL;
+
+  tt_assert(vars);
+  SMARTLIST_FOREACH(vars, config_var_t *, cv,
+                    smartlist_add(varnames, (void*)cv->member.name));
+  smartlist_sort_strings(varnames);
+  joined = smartlist_join_strings(varnames, "::", 0, NULL);
+  tt_str_op(joined, OP_EQ,
+            "LineTypeA::"
+            "LineTypeB::"
+            "MixedHiddenLines::"
+            "MixedLines::"
+            "VisibleLineB::"
+            "__HiddenInt::"
+            "__HiddenLineA::"
+            "autobool::"
+            "boolean::"
+            "csv::"
+            "csv_interval::"
+            "dbl::"
+            "deprecated_int::"
+            "fn::"
+            "i::"
+            "interval::"
+            "lines::"
+            "mem::"
+            "msec_interval::"
+            "obsolete::"
+            "pos::"
+            "routerset::"
+            "s::"
+            "time::"
+            "u64");
+
+ done:
+  tor_free(joined);
+  smartlist_free(varnames);
+  smartlist_free(vars);
+  config_mgr_free(mgr);
+}
+
+static void
+test_confparse_list_deprecated(void *arg)
+{
+  (void)arg;
+  config_mgr_t *mgr = config_mgr_new(&test_fmt);
+  smartlist_t *vars = config_mgr_list_deprecated_vars(mgr);
+  char *joined = NULL;
+
+  tt_assert(vars);
+  smartlist_sort_strings(vars);
+  joined = smartlist_join_strings(vars, "::", 0, NULL);
+
+  tt_str_op(joined, OP_EQ, "deprecated_int");
+
+ done:
+  tor_free(joined);
+  smartlist_free(vars);
+  config_mgr_free(mgr);
+}
+
 #define CONFPARSE_TEST(name, flags)                          \
   { #name, test_confparse_ ## name, flags, NULL, NULL }
 
@@ -968,5 +1036,7 @@ struct testcase_t confparse_tests[] = {
   CONFPARSE_TEST(extra_lines, 0),
   CONFPARSE_TEST(unitparse, 0),
   CONFPARSE_TEST(check_ok_fail, 0),
+  CONFPARSE_TEST(list_vars, 0),
+  CONFPARSE_TEST(list_deprecated, 0),
   END_OF_TESTCASES
 };



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