aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_entrynodes.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-11-23 15:08:07 -0500
committerNick Mathewson <nickm@torproject.org>2016-12-16 11:06:15 -0500
commita7bc73935b030100b0d7b9f39c5dec5ef6eb0a85 (patch)
tree13f36d25abad37405fc01449706f2e28b458da27 /src/test/test_entrynodes.c
parent526b0e2ce2c5d31c70eb3e48eda59b34e9eb681d (diff)
downloadtor-a7bc73935b030100b0d7b9f39c5dec5ef6eb0a85.tar.gz
tor-a7bc73935b030100b0d7b9f39c5dec5ef6eb0a85.zip
Test get_guard_selection_by_name
Diffstat (limited to 'src/test/test_entrynodes.c')
-rw-r--r--src/test/test_entrynodes.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index cdf8672f11..785503bd26 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -1236,6 +1236,52 @@ test_entry_guard_parse_from_state_partial_failure(void *arg)
}
static void
+test_entry_guard_get_guard_selection_by_name(void *arg)
+{
+ (void)arg;
+ guard_selection_t *gs1, *gs2, *gs3;
+
+ gs1 = get_guard_selection_by_name("unlikely", 0);
+ tt_assert(gs1 == NULL);
+ gs1 = get_guard_selection_by_name("unlikely", 1);
+ tt_assert(gs1 != NULL);
+ gs2 = get_guard_selection_by_name("unlikely", 1);
+ tt_assert(gs2 == gs1);
+ gs2 = get_guard_selection_by_name("unlikely", 0);
+ tt_assert(gs2 == gs1);
+
+ gs2 = get_guard_selection_by_name("implausible", 0);
+ tt_assert(gs2 == NULL);
+ gs2 = get_guard_selection_by_name("implausible", 1);
+ tt_assert(gs2 != NULL);
+ tt_assert(gs2 != gs1);
+ gs3 = get_guard_selection_by_name("implausible", 0);
+ tt_assert(gs3 == gs2);
+
+ gs3 = get_guard_selection_by_name("default", 0);
+ tt_assert(gs3 == NULL);
+ gs3 = get_guard_selection_by_name("default", 1);
+ tt_assert(gs3 != NULL);
+ tt_assert(gs3 != gs2);
+ tt_assert(gs3 != gs1);
+ tt_assert(gs3 == get_guard_selection_info());
+
+#if 0
+ or_options_t *options = get_options_mutable();
+ options->UseDeprecatedGuardAlgorithm = 1;
+ gs4 = get_guard_selection_info();
+ tt_assert(gs4 != gs3);
+ tt_assert(gs4 == get_guard_selection_by_name("legacy", 1));
+
+ options->UseDeprecatedGuardAlgorithm = 0;
+ tt_assert(gs3 == get_guard_selection_info());
+#endif
+
+ done:
+ entry_guards_free_all();
+}
+
+static void
test_entry_guard_add_single_guard(void *arg)
{
(void)arg;
@@ -2245,6 +2291,8 @@ struct testcase_t entrynodes_tests[] = {
test_entry_guard_parse_from_state_failure, 0, NULL, NULL },
{ "parse_from_state_partial_failure",
test_entry_guard_parse_from_state_partial_failure, 0, NULL, NULL },
+ { "get_guard_selection_by_name",
+ test_entry_guard_get_guard_selection_by_name, TT_FORK, NULL, NULL },
BFN_TEST(add_single_guard),
BFN_TEST(node_filter),
BFN_TEST(expand_sample),