diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-07-18 15:51:29 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-15 12:03:36 -0400 |
commit | c342ea98791ccbeb67b1255816ca2e92167cefb0 (patch) | |
tree | 81a9f7a8ff193bfc4b4bfe863179057882d558e6 /src/test | |
parent | 7da59721a9963862b7b19dbba4e55d010c296d34 (diff) | |
download | tor-c342ea98791ccbeb67b1255816ca2e92167cefb0.tar.gz tor-c342ea98791ccbeb67b1255816ca2e92167cefb0.zip |
Unit tests for ext_or_id_map.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/include.am | 1 | ||||
-rw-r--r-- | src/test/test.c | 2 | ||||
-rw-r--r-- | src/test/test_extorport.c | 65 | ||||
-rw-r--r-- | src/test/test_options.c | 3 |
4 files changed, 70 insertions, 1 deletions
diff --git a/src/test/include.am b/src/test/include.am index 8718ce7c91..74311ac199 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -26,6 +26,7 @@ src_test_test_SOURCES = \ src/test/test_cell_queue.c \ src/test/test_data.c \ src/test/test_dir.c \ + src/test/test_extorport.c \ src/test/test_introduce.c \ src/test/test_microdesc.c \ src/test/test_options.c \ diff --git a/src/test/test.c b/src/test/test.c index a436688c57..851ddf026a 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1569,6 +1569,7 @@ extern struct testcase_t circuitlist_tests[]; extern struct testcase_t cell_queue_tests[]; extern struct testcase_t options_tests[]; extern struct testcase_t socks_tests[]; +extern struct testcase_t extorport_tests[]; static struct testgroup_t testgroups[] = { { "", test_array }, @@ -1588,6 +1589,7 @@ static struct testgroup_t testgroups[] = { { "introduce/", introduce_tests }, { "circuitlist/", circuitlist_tests }, { "options/", options_tests }, + { "extorport/", extorport_tests }, END_OF_GROUPS }; diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c new file mode 100644 index 0000000000..cfe810ef0b --- /dev/null +++ b/src/test/test_extorport.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2013, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#define CONNECTION_PRIVATE +#include "or.h" +#include "connection.h" +#include "ext_orport.h" +#include "test.h" + +/* Test connection_or_remove_from_ext_or_id_map and + * connection_or_set_ext_or_identifier */ +static void +test_ext_or_id_map(void *arg) +{ + or_connection_t *c1 = NULL, *c2 = NULL, *c3 = NULL; + char *idp = NULL, *idp2 = NULL; + (void)arg; + + /* pre-initialization */ + tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id("xxxxxxxxxxxxxxxxxxxx")); + + c1 = or_connection_new(CONN_TYPE_EXT_OR, AF_INET); + c2 = or_connection_new(CONN_TYPE_EXT_OR, AF_INET); + c3 = or_connection_new(CONN_TYPE_OR, AF_INET); + + tt_ptr_op(c1->ext_or_conn_id, !=, NULL); + tt_ptr_op(c2->ext_or_conn_id, !=, NULL); + tt_ptr_op(c3->ext_or_conn_id, ==, NULL); + + tt_ptr_op(c1, ==, connection_or_get_by_ext_or_id(c1->ext_or_conn_id)); + tt_ptr_op(c2, ==, connection_or_get_by_ext_or_id(c2->ext_or_conn_id)); + tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id("xxxxxxxxxxxxxxxxxxxx")); + + idp = tor_memdup(c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN); + + /* Give c2 a new ID. */ + connection_or_set_ext_or_identifier(c2); + test_mem_op(idp, !=, c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN); + idp2 = tor_memdup(c2->ext_or_conn_id, EXT_OR_CONN_ID_LEN); + tt_assert(!tor_digest_is_zero(idp2)); + + tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp)); + tt_ptr_op(c2, ==, connection_or_get_by_ext_or_id(idp2)); + + /* Now remove it. */ + connection_or_remove_from_ext_or_id_map(c2); + tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp)); + tt_ptr_op(NULL, ==, connection_or_get_by_ext_or_id(idp2)); + + done: + if (c1) + connection_free_(TO_CONN(c1)); + if (c2) + connection_free_(TO_CONN(c2)); + if (c3) + connection_free_(TO_CONN(c3)); + tor_free(idp); + tor_free(idp2); + connection_or_clear_ext_or_id_map(); +} + +struct testcase_t extorport_tests[] = { + { "id_map", test_ext_or_id_map, TT_FORK, NULL, NULL }, + END_OF_TESTCASES +}; diff --git a/src/test/test_options.c b/src/test/test_options.c index 6beff2567e..737f658e2c 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -148,6 +148,8 @@ test_options_validate(void *arg) (void)arg; setup_log_callback(); + WANT_ERR("ExtORPort 500000", "Invalid ExtORPort"); + WANT_ERR_LOG("ServerTransportOptions trebuchet", "ServerTransportOptions did not parse", LOG_WARN, "Too few arguments"); @@ -157,7 +159,6 @@ test_options_validate(void *arg) "ServerTransportOptions did not parse", LOG_WARN, "\"slingsnappy\" is not a k=v"); -// done: clear_log_messages(); return; } |