mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Write unit tests for the ServerTransportOptions parsing function.
This commit is contained in:
parent
08d9807125
commit
6cfc2b5d73
@ -438,12 +438,74 @@ test_config_parse_bridge_line(void *arg)
|
||||
"aa=b");
|
||||
}
|
||||
|
||||
static void
|
||||
test_config_parse_transport_options_line(void *arg)
|
||||
{
|
||||
smartlist_t *options_sl = NULL;
|
||||
|
||||
(void) arg;
|
||||
|
||||
{ /* too small line */
|
||||
options_sl = get_options_from_transport_options_line("valley", NULL);
|
||||
test_assert(!options_sl);
|
||||
}
|
||||
|
||||
{ /* no k=v values */
|
||||
options_sl = get_options_from_transport_options_line("hit it!", NULL);
|
||||
test_assert(!options_sl);
|
||||
}
|
||||
|
||||
{ /* correct line, but wrong transport specified */
|
||||
options_sl =
|
||||
get_options_from_transport_options_line("trebuchet k=v", "rook");
|
||||
test_assert(!options_sl);
|
||||
}
|
||||
|
||||
{ /* correct -- no transport specified */
|
||||
smartlist_t *sl_tmp = smartlist_new();
|
||||
smartlist_add_asprintf(sl_tmp, "ladi=dadi");
|
||||
smartlist_add_asprintf(sl_tmp, "weliketo=party");
|
||||
|
||||
options_sl =
|
||||
get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
|
||||
NULL);
|
||||
test_assert(options_sl);
|
||||
test_assert(smartlist_strings_eq(options_sl, sl_tmp));
|
||||
|
||||
SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
|
||||
smartlist_free(sl_tmp);
|
||||
SMARTLIST_FOREACH(options_sl, char *, s, tor_free(s));
|
||||
smartlist_free(options_sl);
|
||||
}
|
||||
|
||||
{ /* correct -- correct transport specified */
|
||||
smartlist_t *sl_tmp = smartlist_new();
|
||||
smartlist_add_asprintf(sl_tmp, "ladi=dadi");
|
||||
smartlist_add_asprintf(sl_tmp, "weliketo=party");
|
||||
|
||||
options_sl =
|
||||
get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
|
||||
"rook");
|
||||
test_assert(options_sl);
|
||||
test_assert(smartlist_strings_eq(options_sl, sl_tmp));
|
||||
|
||||
SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
|
||||
smartlist_free(sl_tmp);
|
||||
SMARTLIST_FOREACH(options_sl, char *, s, tor_free(s));
|
||||
smartlist_free(options_sl);
|
||||
}
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
#define CONFIG_TEST(name, flags) \
|
||||
{ #name, test_config_ ## name, flags, NULL, NULL }
|
||||
|
||||
struct testcase_t config_tests[] = {
|
||||
CONFIG_TEST(addressmap, 0),
|
||||
CONFIG_TEST(parse_bridge_line, 0),
|
||||
CONFIG_TEST(parse_transport_options_line, 0),
|
||||
CONFIG_TEST(check_or_create_data_subdir, TT_FORK),
|
||||
CONFIG_TEST(write_to_data_subdir, TT_FORK),
|
||||
END_OF_TESTCASES
|
||||
|
Loading…
Reference in New Issue
Block a user