Add tests for variable-listing functions.

This discovered a bug related to an extra & in
config_mgr_list_deprecated_vars(): fix that.
This commit is contained in:
Nick Mathewson
2019-08-27 09:01:39 -04:00
parent 380d3ee168
commit aa3f0c4788
2 changed files with 71 additions and 1 deletions
+1 -1
View File
@@ -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;
}
+70
View File
@@ -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
};