diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-08-27 09:01:39 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-08-28 09:42:17 -0400 |
commit | aa3f0c4788c5cb07243a764589c912a8ed4a26cd (patch) | |
tree | f6fe755eb86e50dfc824b6db4e66f02da66c4582 /src/test/test_confparse.c | |
parent | 380d3ee1682ce5d202d754d442928710b477f59a (diff) | |
download | tor-aa3f0c4788c5cb07243a764589c912a8ed4a26cd.tar.gz tor-aa3f0c4788c5cb07243a764589c912a8ed4a26cd.zip |
Add tests for variable-listing functions.
This discovered a bug related to an extra & in
config_mgr_list_deprecated_vars(): fix that.
Diffstat (limited to 'src/test/test_confparse.c')
-rw-r--r-- | src/test/test_confparse.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/test_confparse.c b/src/test/test_confparse.c index eaa257aedd..1d2e31ab94 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 }; |