aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_pt.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-16 11:53:36 -0400
committerNick Mathewson <nickm@torproject.org>2013-07-18 08:43:53 -0400
commite02b6b99f243566e1e652068af0d0b712b37914e (patch)
tree28e4031380d11b8addd2130c8c6c370a07126e72 /src/test/test_pt.c
parentdd18789a9cb5ab5d39c85e3aa4106c020265e6ce (diff)
downloadtor-e02b6b99f243566e1e652068af0d0b712b37914e.tar
tor-e02b6b99f243566e1e652068af0d0b712b37914e.tar.gz
Add a basic unit test for pt_get_extra_info_descriptor_string.
Diffstat (limited to 'src/test/test_pt.c')
-rw-r--r--src/test/test_pt.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index 6a09807e7..cc2b0a965 100644
--- a/src/test/test_pt.c
+++ b/src/test/test_pt.c
@@ -169,12 +169,59 @@ test_pt_protocol(void)
tor_free(mp);
}
+static void
+test_pt_get_extrainfo_string(void *arg)
+{
+ managed_proxy_t *mp1 = NULL, *mp2 = NULL;
+ char **argv1, **argv2;
+ smartlist_t *t1 = smartlist_new(), *t2 = smartlist_new();
+ int r;
+ char *s = NULL;
+ (void) arg;
+
+ argv1 = tor_malloc_zero(sizeof(char*)*3);
+ argv1[0] = tor_strdup("ewige");
+ argv1[1] = tor_strdup("Blumenkraft");
+ argv1[2] = NULL;
+ argv2 = tor_malloc_zero(sizeof(char*)*4);
+ argv2[0] = tor_strdup("und");
+ argv2[1] = tor_strdup("ewige");
+ argv2[2] = tor_strdup("Schlangenkraft");
+ argv2[3] = NULL;
+
+ mp1 = managed_proxy_create(t1, argv1, 1);
+ mp2 = managed_proxy_create(t2, argv2, 1);
+
+ r = parse_smethod_line("SMETHOD hagbard 127.0.0.1:5555", mp1);
+ tt_int_op(r, ==, 0);
+ r = parse_smethod_line("SMETHOD celine 127.0.0.1:1723 ARGS:card=no-enemy",
+ mp2);
+ tt_int_op(r, ==, 0);
+
+ /* Force these proxies to look "completed" or they won't generate output. */
+ mp1->conf_state = mp2->conf_state = PT_PROTO_COMPLETED;
+
+ s = pt_get_extra_info_descriptor_string();
+ tt_assert(s);
+ tt_str_op(s, ==,
+ "transport hagbard 127.0.0.1:5555\n"
+ "transport celine 127.0.0.1:1723 card=no-enemy\n");
+
+ done:
+ /* XXXX clean up better */
+ smartlist_free(t1);
+ smartlist_free(t2);
+ tor_free(s);
+}
+
#define PT_LEGACY(name) \
{ #name, legacy_test_helper, 0, &legacy_setup, test_pt_ ## name }
struct testcase_t pt_tests[] = {
PT_LEGACY(parsing),
PT_LEGACY(protocol),
+ { "get_extrainfo_string", test_pt_get_extrainfo_string, TT_FORK,
+ NULL, NULL },
END_OF_TESTCASES
};