aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_config.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2013-06-12 15:28:48 +0300
committerNick Mathewson <nickm@torproject.org>2013-07-18 08:45:02 -0400
commit6cfc2b5d73f6ec1b2ab4af1f209b6126a7d8cba9 (patch)
tree06b5177348ddccee0f81739442a68c231dbde904 /src/test/test_config.c
parent08d98071252995d586f0ac3cef82f6ec46fc9347 (diff)
downloadtor-6cfc2b5d73f6ec1b2ab4af1f209b6126a7d8cba9.tar
tor-6cfc2b5d73f6ec1b2ab4af1f209b6126a7d8cba9.tar.gz
Write unit tests for the ServerTransportOptions parsing function.
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r--src/test/test_config.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 4e9e13e47..7c43b5f61 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -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