1 #define ROUTERSET_PRIVATE
6 #include "routerparse.h"
11 #define NS_MODULE routerset
13 #define NS_SUBMODULE routerset_new
16 * Functional (blackbox) test to determine that each member of the routerset
21 NS(test_main
)(void *arg
)
28 tt_ptr_op(rs
, OP_NE
, NULL
);
29 tt_ptr_op(rs
->list
, OP_NE
, NULL
);
30 tt_ptr_op(rs
->names
, OP_NE
, NULL
);
31 tt_ptr_op(rs
->digests
, OP_NE
, NULL
);
32 tt_ptr_op(rs
->policies
, OP_NE
, NULL
);
33 tt_ptr_op(rs
->country_names
, OP_NE
, NULL
);
40 #define NS_SUBMODULE routerset_get_countryname
43 * Functional test to strip the braces from a "{xx}" country code string.
47 NS(test_main
)(void *arg
)
55 name
= routerset_get_countryname(input
);
56 tt_ptr_op(name
, OP_EQ
, NULL
);
61 name
= routerset_get_countryname(input
);
62 tt_ptr_op(name
, OP_EQ
, NULL
);
67 name
= routerset_get_countryname(input
);
68 tt_ptr_op(name
, OP_EQ
, NULL
);
73 name
= routerset_get_countryname(input
);
74 tt_str_op(name
, OP_EQ
, "xx");
78 name
= routerset_get_countryname(input
);
79 tt_str_op(name
, OP_EQ
, "xx");
85 #define NS_SUBMODULE ASPECT(routerset_refresh_counties, geoip_not_loaded)
88 * Structural (whitebox) test for routerset_refresh_counties, when the GeoIP DB
92 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
93 NS_DECL(int, geoip_get_n_countries
, (void));
96 NS(test_main
)(void *arg
)
98 routerset_t
*set
= routerset_new();
101 NS_MOCK(geoip_is_loaded
);
102 NS_MOCK(geoip_get_n_countries
);
104 routerset_refresh_countries(set
);
106 tt_ptr_op(set
->countries
, OP_EQ
, NULL
);
107 tt_int_op(set
->n_countries
, OP_EQ
, 0);
108 tt_int_op(CALLED(geoip_is_loaded
), OP_EQ
, 1);
109 tt_int_op(CALLED(geoip_get_n_countries
), OP_EQ
, 0);
112 NS_UNMOCK(geoip_is_loaded
);
113 NS_UNMOCK(geoip_get_n_countries
);
118 NS(geoip_is_loaded
)(sa_family_t family
)
121 CALLED(geoip_is_loaded
)++;
127 NS(geoip_get_n_countries
)(void)
129 CALLED(geoip_get_n_countries
)++;
135 #define NS_SUBMODULE ASPECT(routerset_refresh_counties, no_countries)
138 * Structural test for routerset_refresh_counties, when there are no countries.
141 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
142 NS_DECL(int, geoip_get_n_countries
, (void));
143 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
146 NS(test_main
)(void *arg
)
148 routerset_t
*set
= routerset_new();
151 NS_MOCK(geoip_is_loaded
);
152 NS_MOCK(geoip_get_n_countries
);
153 NS_MOCK(geoip_get_country
);
155 routerset_refresh_countries(set
);
157 tt_ptr_op(set
->countries
, OP_NE
, NULL
);
158 tt_int_op(set
->n_countries
, OP_EQ
, 1);
159 tt_int_op((unsigned int)(*set
->countries
), OP_EQ
, 0);
160 tt_int_op(CALLED(geoip_is_loaded
), OP_EQ
, 1);
161 tt_int_op(CALLED(geoip_get_n_countries
), OP_EQ
, 1);
162 tt_int_op(CALLED(geoip_get_country
), OP_EQ
, 0);
165 NS_UNMOCK(geoip_is_loaded
);
166 NS_UNMOCK(geoip_get_n_countries
);
167 NS_UNMOCK(geoip_get_country
);
172 NS(geoip_is_loaded
)(sa_family_t family
)
175 CALLED(geoip_is_loaded
)++;
181 NS(geoip_get_n_countries
)(void)
183 CALLED(geoip_get_n_countries
)++;
189 NS(geoip_get_country
)(const char *countrycode
)
192 CALLED(geoip_get_country
)++;
198 #define NS_SUBMODULE ASPECT(routerset_refresh_counties, one_valid_country)
201 * Structural test for routerset_refresh_counties, with one valid country.
204 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
205 NS_DECL(int, geoip_get_n_countries
, (void));
206 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
209 NS(test_main
)(void *arg
)
211 routerset_t
*set
= routerset_new();
214 NS_MOCK(geoip_is_loaded
);
215 NS_MOCK(geoip_get_n_countries
);
216 NS_MOCK(geoip_get_country
);
217 smartlist_add(set
->country_names
, tor_strndup("foo", 3));
219 routerset_refresh_countries(set
);
221 tt_ptr_op(set
->countries
, OP_NE
, NULL
);
222 tt_int_op(set
->n_countries
, OP_EQ
, 2);
223 tt_int_op(CALLED(geoip_is_loaded
), OP_EQ
, 1);
224 tt_int_op(CALLED(geoip_get_n_countries
), OP_EQ
, 1);
225 tt_int_op(CALLED(geoip_get_country
), OP_EQ
, 1);
226 tt_int_op((unsigned int)(*set
->countries
), OP_NE
, 0);
229 NS_UNMOCK(geoip_is_loaded
);
230 NS_UNMOCK(geoip_get_n_countries
);
231 NS_UNMOCK(geoip_get_country
);
236 NS(geoip_is_loaded
)(sa_family_t family
)
239 CALLED(geoip_is_loaded
)++;
245 NS(geoip_get_n_countries
)(void)
247 CALLED(geoip_get_n_countries
)++;
253 NS(geoip_get_country
)(const char *countrycode
)
256 CALLED(geoip_get_country
)++;
262 #define NS_SUBMODULE ASPECT(routerset_refresh_counties, one_invalid_country)
265 * Structural test for routerset_refresh_counties, with one invalid
269 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
270 NS_DECL(int, geoip_get_n_countries
, (void));
271 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
274 NS(test_main
)(void *arg
)
276 routerset_t
*set
= routerset_new();
279 NS_MOCK(geoip_is_loaded
);
280 NS_MOCK(geoip_get_n_countries
);
281 NS_MOCK(geoip_get_country
);
282 smartlist_add(set
->country_names
, tor_strndup("foo", 3));
284 routerset_refresh_countries(set
);
286 tt_ptr_op(set
->countries
, OP_NE
, NULL
);
287 tt_int_op(set
->n_countries
, OP_EQ
, 2);
288 tt_int_op(CALLED(geoip_is_loaded
), OP_EQ
, 1);
289 tt_int_op(CALLED(geoip_get_n_countries
), OP_EQ
, 1);
290 tt_int_op(CALLED(geoip_get_country
), OP_EQ
, 1);
291 tt_int_op((unsigned int)(*set
->countries
), OP_EQ
, 0);
294 NS_UNMOCK(geoip_is_loaded
);
295 NS_UNMOCK(geoip_get_n_countries
);
296 NS_UNMOCK(geoip_get_country
);
301 NS(geoip_is_loaded
)(sa_family_t family
)
304 CALLED(geoip_is_loaded
)++;
310 NS(geoip_get_n_countries
)(void)
312 CALLED(geoip_get_n_countries
)++;
318 NS(geoip_get_country
)(const char *countrycode
)
321 CALLED(geoip_get_country
)++;
327 #define NS_SUBMODULE ASPECT(routerset_parse, malformed)
330 * Functional test, with a malformed string to parse.
334 NS(test_main
)(void *arg
)
336 routerset_t
*set
= routerset_new();
341 r
= routerset_parse(set
, s
, "");
343 tt_int_op(r
, OP_EQ
, -1);
350 #define NS_SUBMODULE ASPECT(routerset_parse, valid_hexdigest)
353 * Functional test for routerset_parse, that routerset_parse returns 0
354 * on a valid hexdigest entry.
358 NS(test_main
)(void *arg
)
365 set
= routerset_new();
366 s
= "$0000000000000000000000000000000000000000";
367 r
= routerset_parse(set
, s
, "");
368 tt_int_op(r
, OP_EQ
, 0);
369 tt_int_op(digestmap_isempty(set
->digests
), OP_NE
, 1);
376 #define NS_SUBMODULE ASPECT(routerset_parse, valid_nickname)
379 * Functional test for routerset_parse, when given a valid nickname as input.
383 NS(test_main
)(void *arg
)
390 set
= routerset_new();
392 r
= routerset_parse(set
, s
, "");
393 tt_int_op(r
, OP_EQ
, 0);
394 tt_int_op(strmap_isempty(set
->names
), OP_NE
, 1);
401 #define NS_SUBMODULE ASPECT(routerset_parse, get_countryname)
404 * Functional test for routerset_parse, when given a valid countryname.
408 NS(test_main
)(void *arg
)
415 set
= routerset_new();
417 r
= routerset_parse(set
, s
, "");
418 tt_int_op(r
, OP_EQ
, 0);
419 tt_int_op(smartlist_len(set
->country_names
), OP_NE
, 0);
426 #define NS_SUBMODULE ASPECT(routerset_parse, policy)
429 * Structural test for routerset_parse, when given a valid policy.
432 NS_DECL(addr_policy_t
*, router_parse_addr_policy_item_from_string
,
433 (const char *s
, int assume_action
));
435 addr_policy_t
*NS(mock_addr_policy
);
438 NS(test_main
)(void *arg
)
445 NS_MOCK(router_parse_addr_policy_item_from_string
);
446 NS(mock_addr_policy
) = tor_malloc_zero(sizeof(addr_policy_t
));
448 set
= routerset_new();
450 r
= routerset_parse(set
, s
, "");
451 tt_int_op(r
, OP_EQ
, 0);
452 tt_int_op(smartlist_len(set
->policies
), OP_NE
, 0);
453 tt_int_op(CALLED(router_parse_addr_policy_item_from_string
), OP_EQ
, 1);
460 NS(router_parse_addr_policy_item_from_string
)(const char *s
, int assume_action
)
464 CALLED(router_parse_addr_policy_item_from_string
)++;
466 return NS(mock_addr_policy
);
470 #define NS_SUBMODULE ASPECT(routerset_union, source_bad)
473 * Structural test for routerset_union, when given a bad source argument.
476 NS_DECL(smartlist_t
*, smartlist_new
, (void));
479 NS(test_main
)(void *arg
)
481 routerset_t
*set
, *bad_set
;
484 set
= routerset_new();
485 bad_set
= routerset_new();
486 smartlist_free(bad_set
->list
);
487 bad_set
->list
= NULL
;
489 NS_MOCK(smartlist_new
);
491 routerset_union(set
, NULL
);
492 tt_int_op(CALLED(smartlist_new
), OP_EQ
, 0);
494 routerset_union(set
, bad_set
);
495 tt_int_op(CALLED(smartlist_new
), OP_EQ
, 0);
498 NS_UNMOCK(smartlist_new
);
501 /* Just recreate list, so we can simply use routerset_free. */
502 bad_set
->list
= smartlist_new();
503 routerset_free(bad_set
);
507 NS(smartlist_new
)(void)
509 CALLED(smartlist_new
)++;
515 #define NS_SUBMODULE ASPECT(routerset_union, one)
518 * Functional test for routerset_union.
522 NS(test_main
)(void *arg
)
524 routerset_t
*src
= routerset_new();
528 tgt
= routerset_new();
529 smartlist_add(src
->list
, tor_strdup("{xx}"));
530 routerset_union(tgt
, src
);
532 tt_int_op(smartlist_len(tgt
->list
), OP_NE
, 0);
540 #define NS_SUBMODULE routerset_is_list
543 * Functional tests for routerset_is_list.
547 NS(test_main
)(void *arg
)
550 addr_policy_t
*policy
;
554 /* len(set->country_names) == 0, len(set->policies) == 0 */
555 set
= routerset_new();
556 is_list
= routerset_is_list(set
);
559 tt_int_op(is_list
, OP_NE
, 0);
561 /* len(set->country_names) != 0, len(set->policies) == 0 */
562 set
= routerset_new();
563 smartlist_add(set
->country_names
, tor_strndup("foo", 3));
564 is_list
= routerset_is_list(set
);
567 tt_int_op(is_list
, OP_EQ
, 0);
569 /* len(set->country_names) == 0, len(set->policies) != 0 */
570 set
= routerset_new();
571 policy
= tor_malloc_zero(sizeof(addr_policy_t
));
572 smartlist_add(set
->policies
, (void *)policy
);
573 is_list
= routerset_is_list(set
);
576 tt_int_op(is_list
, OP_EQ
, 0);
578 /* len(set->country_names) != 0, len(set->policies) != 0 */
579 set
= routerset_new();
580 smartlist_add(set
->country_names
, tor_strndup("foo", 3));
581 policy
= tor_malloc_zero(sizeof(addr_policy_t
));
582 smartlist_add(set
->policies
, (void *)policy
);
583 is_list
= routerset_is_list(set
);
586 tt_int_op(is_list
, OP_EQ
, 0);
593 #define NS_SUBMODULE routerset_needs_geoip
596 * Functional tests for routerset_needs_geoip.
600 NS(test_main
)(void *arg
)
602 const routerset_t
*set
;
607 needs_geoip
= routerset_needs_geoip(set
);
608 tt_int_op(needs_geoip
, OP_EQ
, 0);
610 set
= routerset_new();
611 needs_geoip
= routerset_needs_geoip(set
);
612 routerset_free((routerset_t
*)set
);
613 tt_int_op(needs_geoip
, OP_EQ
, 0);
616 set
= routerset_new();
617 smartlist_add(set
->country_names
, tor_strndup("xx", 2));
618 needs_geoip
= routerset_needs_geoip(set
);
619 routerset_free((routerset_t
*)set
);
621 tt_int_op(needs_geoip
, OP_NE
, 0);
628 #define NS_SUBMODULE routerset_is_empty
631 * Functional tests for routerset_is_empty.
635 NS(test_main
)(void *arg
)
637 routerset_t
*set
= NULL
;
641 is_empty
= routerset_is_empty(set
);
642 tt_int_op(is_empty
, OP_NE
, 0);
644 set
= routerset_new();
645 is_empty
= routerset_is_empty(set
);
648 tt_int_op(is_empty
, OP_NE
, 0);
650 set
= routerset_new();
651 smartlist_add(set
->list
, tor_strdup("{xx}"));
652 is_empty
= routerset_is_empty(set
);
655 tt_int_op(is_empty
, OP_EQ
, 0);
662 #define NS_SUBMODULE ASPECT(routerset_contains, null_set_or_null_set_list)
665 * Functional test for routerset_contains, when given a NULL set or the
666 * set has a NULL list.
670 NS(test_main
)(void *arg
)
672 routerset_t
*set
= NULL
;
676 contains
= routerset_contains(set
, NULL
, 0, NULL
, NULL
, 0);
678 tt_int_op(contains
, OP_EQ
, 0);
680 set
= tor_malloc_zero(sizeof(routerset_t
));
682 contains
= routerset_contains(set
, NULL
, 0, NULL
, NULL
, 0);
684 tt_int_op(contains
, OP_EQ
, 0);
691 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_nickname)
694 * Functional test for routerset_contains, when given a valid routerset but a
699 NS(test_main
)(void *arg
)
701 routerset_t
*set
= routerset_new();
702 char *nickname
= NULL
;
706 contains
= routerset_contains(set
, NULL
, 0, nickname
, NULL
, 0);
709 tt_int_op(contains
, OP_EQ
, 0);
716 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_nickname)
719 * Functional test for routerset_contains, when given a valid routerset
720 * and the nickname is in the routerset.
724 NS(test_main
)(void *arg
)
726 routerset_t
*set
= routerset_new();
727 const char *nickname
;
731 nickname
= "Foo"; /* This tests the lowercase comparison as well. */
732 strmap_set_lc(set
->names
, nickname
, (void *)1);
733 contains
= routerset_contains(set
, NULL
, 0, nickname
, NULL
, 0);
736 tt_int_op(contains
, OP_EQ
, 4);
742 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_nickname)
745 * Functional test for routerset_contains, when given a valid routerset
746 * and the nickname is not in the routerset.
750 NS(test_main
)(void *arg
)
752 routerset_t
*set
= routerset_new();
756 strmap_set_lc(set
->names
, "bar", (void *)1);
757 contains
= routerset_contains(set
, NULL
, 0, "foo", NULL
, 0);
760 tt_int_op(contains
, OP_EQ
, 0);
766 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_digest)
769 * Functional test for routerset_contains, when given a valid routerset
770 * and the digest is contained in the routerset.
774 NS(test_main
)(void *arg
)
776 routerset_t
*set
= routerset_new();
778 uint8_t foo
[20] = { 2, 3, 4 };
781 digestmap_set(set
->digests
, (const char*)foo
, (void *)1);
782 contains
= routerset_contains(set
, NULL
, 0, NULL
, (const char*)foo
, 0);
785 tt_int_op(contains
, OP_EQ
, 4);
791 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_digest)
794 * Functional test for routerset_contains, when given a valid routerset
795 * and the digest is not contained in the routerset.
799 NS(test_main
)(void *arg
)
801 routerset_t
*set
= routerset_new();
803 uint8_t bar
[20] = { 9, 10, 11, 55 };
804 uint8_t foo
[20] = { 1, 2, 3, 4};
807 digestmap_set(set
->digests
, (const char*)bar
, (void *)1);
808 contains
= routerset_contains(set
, NULL
, 0, NULL
, (const char*)foo
, 0);
811 tt_int_op(contains
, OP_EQ
, 0);
817 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_digest)
820 * Functional test for routerset_contains, when given a valid routerset
821 * and the digest is NULL.
825 NS(test_main
)(void *arg
)
827 routerset_t
*set
= routerset_new();
829 uint8_t bar
[20] = { 9, 10, 11, 55 };
832 digestmap_set(set
->digests
, (const char*)bar
, (void *)1);
833 contains
= routerset_contains(set
, NULL
, 0, NULL
, NULL
, 0);
836 tt_int_op(contains
, OP_EQ
, 0);
842 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_addr)
845 * Structural test for routerset_contains, when given a valid routerset
846 * and the address is rejected by policy.
849 NS_DECL(addr_policy_result_t
, compare_tor_addr_to_addr_policy
,
850 (const tor_addr_t
*addr
, uint16_t port
, const smartlist_t
*policy
));
852 static tor_addr_t MOCK_TOR_ADDR
;
853 #define MOCK_TOR_ADDR_PTR (&MOCK_TOR_ADDR)
856 NS(test_main
)(void *arg
)
858 routerset_t
*set
= routerset_new();
859 tor_addr_t
*addr
= MOCK_TOR_ADDR_PTR
;
863 NS_MOCK(compare_tor_addr_to_addr_policy
);
865 contains
= routerset_contains(set
, addr
, 0, NULL
, NULL
, 0);
868 tt_int_op(CALLED(compare_tor_addr_to_addr_policy
), OP_EQ
, 1);
869 tt_int_op(contains
, OP_EQ
, 3);
876 NS(compare_tor_addr_to_addr_policy
)(const tor_addr_t
*addr
, uint16_t port
,
877 const smartlist_t
*policy
)
881 CALLED(compare_tor_addr_to_addr_policy
)++;
882 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
883 return ADDR_POLICY_REJECTED
;
890 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_no_addr)
893 * Structural test for routerset_contains, when given a valid routerset
894 * and the address is not rejected by policy.
897 NS_DECL(addr_policy_result_t
, compare_tor_addr_to_addr_policy
,
898 (const tor_addr_t
*addr
, uint16_t port
, const smartlist_t
*policy
));
901 NS(test_main
)(void *arg
)
903 routerset_t
*set
= routerset_new();
904 tor_addr_t
*addr
= MOCK_TOR_ADDR_PTR
;
908 NS_MOCK(compare_tor_addr_to_addr_policy
);
910 contains
= routerset_contains(set
, addr
, 0, NULL
, NULL
, 0);
913 tt_int_op(CALLED(compare_tor_addr_to_addr_policy
), OP_EQ
, 1);
914 tt_int_op(contains
, OP_EQ
, 0);
921 NS(compare_tor_addr_to_addr_policy
)(const tor_addr_t
*addr
, uint16_t port
,
922 const smartlist_t
*policy
)
926 CALLED(compare_tor_addr_to_addr_policy
)++;
927 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
929 return ADDR_POLICY_ACCEPTED
;
936 #define NS_SUBMODULE ASPECT(routerset_contains, set_and_null_addr)
939 * Structural test for routerset_contains, when given a valid routerset
940 * and the address is NULL.
943 NS_DECL(addr_policy_result_t
, compare_tor_addr_to_addr_policy
,
944 (const tor_addr_t
*addr
, uint16_t port
, const smartlist_t
*policy
));
947 NS(test_main
)(void *arg
)
949 routerset_t
*set
= routerset_new();
953 NS_MOCK(compare_tor_addr_to_addr_policy
);
955 contains
= routerset_contains(set
, NULL
, 0, NULL
, NULL
, 0);
958 tt_int_op(contains
, OP_EQ
, 0);
965 NS(compare_tor_addr_to_addr_policy
)(const tor_addr_t
*addr
, uint16_t port
,
966 const smartlist_t
*policy
)
970 CALLED(compare_tor_addr_to_addr_policy
)++;
971 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
973 return ADDR_POLICY_ACCEPTED
;
980 #define NS_SUBMODULE ASPECT(routerset_contains, countries_no_geoip)
983 * Structural test for routerset_contains, when there is no matching country
987 NS_DECL(addr_policy_result_t
, compare_tor_addr_to_addr_policy
,
988 (const tor_addr_t
*addr
, uint16_t port
, const smartlist_t
*policy
));
989 NS_DECL(int, geoip_get_country_by_addr
, (const tor_addr_t
*addr
));
992 NS(test_main
)(void *arg
)
994 routerset_t
*set
= routerset_new();
998 NS_MOCK(compare_tor_addr_to_addr_policy
);
999 NS_MOCK(geoip_get_country_by_addr
);
1001 set
->countries
= bitarray_init_zero(1);
1002 bitarray_set(set
->countries
, 1);
1003 contains
= routerset_contains(set
, MOCK_TOR_ADDR_PTR
, 0, NULL
, NULL
, -1);
1004 routerset_free(set
);
1006 tt_int_op(contains
, OP_EQ
, 0);
1007 tt_int_op(CALLED(compare_tor_addr_to_addr_policy
), OP_EQ
, 1);
1008 tt_int_op(CALLED(geoip_get_country_by_addr
), OP_EQ
, 1);
1014 addr_policy_result_t
1015 NS(compare_tor_addr_to_addr_policy
)(const tor_addr_t
*addr
, uint16_t port
,
1016 const smartlist_t
*policy
)
1020 CALLED(compare_tor_addr_to_addr_policy
)++;
1021 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
1024 return ADDR_POLICY_ACCEPTED
;
1028 NS(geoip_get_country_by_addr
)(const tor_addr_t
*addr
)
1030 CALLED(geoip_get_country_by_addr
)++;
1031 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
1038 #define NS_SUBMODULE ASPECT(routerset_contains, countries_geoip)
1041 * Structural test for routerset_contains, when there a matching country
1045 NS_DECL(addr_policy_result_t
, compare_tor_addr_to_addr_policy
,
1046 (const tor_addr_t
*addr
, uint16_t port
, const smartlist_t
*policy
));
1047 NS_DECL(int, geoip_get_country_by_addr
, (const tor_addr_t
*addr
));
1050 NS(test_main
)(void *arg
)
1052 routerset_t
*set
= routerset_new();
1056 NS_MOCK(compare_tor_addr_to_addr_policy
);
1057 NS_MOCK(geoip_get_country_by_addr
);
1059 set
->n_countries
= 2;
1060 set
->countries
= bitarray_init_zero(1);
1061 bitarray_set(set
->countries
, 1);
1062 contains
= routerset_contains(set
, MOCK_TOR_ADDR_PTR
, 0, NULL
, NULL
, -1);
1063 routerset_free(set
);
1065 tt_int_op(contains
, OP_EQ
, 2);
1066 tt_int_op(CALLED(compare_tor_addr_to_addr_policy
), OP_EQ
, 1);
1067 tt_int_op(CALLED(geoip_get_country_by_addr
), OP_EQ
, 1);
1073 addr_policy_result_t
1074 NS(compare_tor_addr_to_addr_policy
)(const tor_addr_t
*addr
, uint16_t port
,
1075 const smartlist_t
*policy
)
1079 CALLED(compare_tor_addr_to_addr_policy
)++;
1080 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
1083 return ADDR_POLICY_ACCEPTED
;
1087 NS(geoip_get_country_by_addr
)(const tor_addr_t
*addr
)
1089 CALLED(geoip_get_country_by_addr
)++;
1090 tt_ptr_op(addr
, OP_EQ
, MOCK_TOR_ADDR_PTR
);
1097 #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, only_flag_and_no_ccs)
1100 * Functional test for routerset_add_unknown_ccs, where only_if_some_cc_set
1101 * is set and there are no country names.
1105 NS(test_main
)(void *arg
)
1107 routerset_t
*set
= routerset_new();
1108 routerset_t
**setp
= &set
;
1112 r
= routerset_add_unknown_ccs(setp
, 1);
1114 tt_int_op(r
, OP_EQ
, 0);
1117 routerset_free(set
);
1121 #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, creates_set)
1124 * Functional test for routerset_add_unknown_ccs, where the set argument
1125 * is created if passed in as NULL.
1128 /* The mock is only used to stop the test from asserting erroneously. */
1129 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
1132 NS(test_main
)(void *arg
)
1134 routerset_t
*set
= NULL
;
1135 routerset_t
**setp
= &set
;
1139 NS_MOCK(geoip_get_country
);
1141 r
= routerset_add_unknown_ccs(setp
, 0);
1143 tt_ptr_op(*setp
, OP_NE
, NULL
);
1144 tt_int_op(r
, OP_EQ
, 0);
1148 routerset_free(set
);
1152 NS(geoip_get_country
)(const char *country
)
1155 CALLED(geoip_get_country
)++;
1161 #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, add_unknown)
1164 * Structural test for routerset_add_unknown_ccs, that the "{??}"
1165 * country code is added to the list.
1168 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
1169 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
1172 NS(test_main
)(void *arg
)
1174 routerset_t
*set
= routerset_new();
1175 routerset_t
**setp
= &set
;
1179 NS_MOCK(geoip_get_country
);
1180 NS_MOCK(geoip_is_loaded
);
1182 r
= routerset_add_unknown_ccs(setp
, 0);
1184 tt_int_op(r
, OP_EQ
, 1);
1185 tt_int_op(smartlist_contains_string(set
->country_names
, "??"), OP_EQ
, 1);
1186 tt_int_op(smartlist_contains_string(set
->list
, "{??}"), OP_EQ
, 1);
1190 routerset_free(set
);
1194 NS(geoip_get_country
)(const char *country
)
1196 int arg_is_qq
, arg_is_a1
;
1198 CALLED(geoip_get_country
)++;
1200 arg_is_qq
= !strcmp(country
, "??");
1201 arg_is_a1
= !strcmp(country
, "A1");
1203 tt_int_op(arg_is_qq
|| arg_is_a1
, OP_EQ
, 1);
1213 NS(geoip_is_loaded
)(sa_family_t family
)
1215 CALLED(geoip_is_loaded
)++;
1217 tt_int_op(family
, OP_EQ
, AF_INET
);
1224 #define NS_SUBMODULE ASPECT(routerset_add_unknown_ccs, add_a1)
1227 * Structural test for routerset_add_unknown_ccs, that the "{a1}"
1228 * country code is added to the list.
1231 NS_DECL(country_t
, geoip_get_country
, (const char *country
));
1232 NS_DECL(int, geoip_is_loaded
, (sa_family_t family
));
1235 NS(test_main
)(void *arg
)
1237 routerset_t
*set
= routerset_new();
1238 routerset_t
**setp
= &set
;
1242 NS_MOCK(geoip_get_country
);
1243 NS_MOCK(geoip_is_loaded
);
1245 r
= routerset_add_unknown_ccs(setp
, 0);
1247 tt_int_op(r
, OP_EQ
, 1);
1248 tt_int_op(smartlist_contains_string(set
->country_names
, "a1"), OP_EQ
, 1);
1249 tt_int_op(smartlist_contains_string(set
->list
, "{a1}"), OP_EQ
, 1);
1253 routerset_free(set
);
1257 NS(geoip_get_country
)(const char *country
)
1259 int arg_is_qq
, arg_is_a1
;
1261 CALLED(geoip_get_country
)++;
1263 arg_is_qq
= !strcmp(country
, "??");
1264 arg_is_a1
= !strcmp(country
, "A1");
1266 tt_int_op(arg_is_qq
|| arg_is_a1
, OP_EQ
, 1);
1276 NS(geoip_is_loaded
)(sa_family_t family
)
1278 CALLED(geoip_is_loaded
)++;
1280 tt_int_op(family
, OP_EQ
, AF_INET
);
1287 #define NS_SUBMODULE routerset_contains_extendinfo
1290 * Functional test for routerset_contains_extendinfo.
1294 NS(test_main
)(void *arg
)
1296 routerset_t
*set
= routerset_new();
1299 const char *nickname
= "foo";
1302 memset(&ei
, 0, sizeof(ei
));
1303 strmap_set_lc(set
->names
, nickname
, (void *)1);
1304 strncpy(ei
.nickname
, nickname
, sizeof(ei
.nickname
) - 1);
1305 ei
.nickname
[sizeof(ei
.nickname
) - 1] = '\0';
1307 r
= routerset_contains_extendinfo(set
, &ei
);
1309 tt_int_op(r
, OP_EQ
, 4);
1311 routerset_free(set
);
1315 #define NS_SUBMODULE routerset_contains_router
1318 * Functional test for routerset_contains_router.
1322 NS(test_main
)(void *arg
)
1324 routerset_t
*set
= routerset_new();
1326 country_t country
= 1;
1328 const char *nickname
= "foo";
1331 memset(&ri
, 0, sizeof(ri
));
1332 strmap_set_lc(set
->names
, nickname
, (void *)1);
1333 ri
.nickname
= (char *)nickname
;
1335 r
= routerset_contains_router(set
, &ri
, country
);
1337 tt_int_op(r
, OP_EQ
, 4);
1339 routerset_free(set
);
1343 #define NS_SUBMODULE routerset_contains_routerstatus
1346 * Functional test for routerset_contains_routerstatus.
1349 // XXX: This is a bit brief. It only populates and tests the nickname fields
1350 // ie., enough to make the containment check succeed. Perhaps it should do
1351 // a bit more or test a bit more.
1354 NS(test_main
)(void *arg
)
1356 routerset_t
*set
= routerset_new();
1358 country_t country
= 1;
1360 const char *nickname
= "foo";
1363 memset(&rs
, 0, sizeof(rs
));
1364 strmap_set_lc(set
->names
, nickname
, (void *)1);
1365 strncpy(rs
.nickname
, nickname
, sizeof(rs
.nickname
) - 1);
1366 rs
.nickname
[sizeof(rs
.nickname
) - 1] = '\0';
1368 r
= routerset_contains_routerstatus(set
, &rs
, country
);
1370 tt_int_op(r
, OP_EQ
, 4);
1372 routerset_free(set
);
1376 #define NS_SUBMODULE ASPECT(routerset_contains_node, none)
1379 * Functional test for routerset_contains_node, when the node has no
1380 * routerset or routerinfo.
1383 node_t
NS(mock_node
);
1386 NS(test_main
)(void *arg
)
1388 routerset_t
*set
= routerset_new();
1392 NS(mock_node
).ri
= NULL
;
1393 NS(mock_node
).rs
= NULL
;
1395 r
= routerset_contains_node(set
, &NS(mock_node
));
1396 tt_int_op(r
, OP_EQ
, 0);
1399 routerset_free(set
);
1403 #define NS_SUBMODULE ASPECT(routerset_contains_node, routerstatus)
1406 * Functional test for routerset_contains_node, when the node has a
1407 * routerset and no routerinfo.
1410 node_t
NS(mock_node
);
1413 NS(test_main
)(void *arg
)
1415 routerset_t
*set
= routerset_new();
1417 const char *nickname
= "foo";
1421 strmap_set_lc(set
->names
, nickname
, (void *)1);
1423 strncpy(rs
.nickname
, nickname
, sizeof(rs
.nickname
) - 1);
1424 rs
.nickname
[sizeof(rs
.nickname
) - 1] = '\0';
1425 NS(mock_node
).ri
= NULL
;
1426 NS(mock_node
).rs
= &rs
;
1428 r
= routerset_contains_node(set
, &NS(mock_node
));
1430 tt_int_op(r
, OP_EQ
, 4);
1432 routerset_free(set
);
1436 #define NS_SUBMODULE ASPECT(routerset_contains_node, routerinfo)
1439 * Functional test for routerset_contains_node, when the node has no
1440 * routerset and a routerinfo.
1444 NS(test_main
)(void *arg
)
1446 routerset_t
*set
= routerset_new();
1448 const char *nickname
= "foo";
1453 strmap_set_lc(set
->names
, nickname
, (void *)1);
1455 ri
.nickname
= (char *)nickname
;
1457 mock_node
.rs
= NULL
;
1459 r
= routerset_contains_node(set
, &mock_node
);
1461 tt_int_op(r
, OP_EQ
, 4);
1463 routerset_free(set
);
1467 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, no_routerset)
1470 * Functional test for routerset_get_all_nodes, when routerset is NULL or
1471 * the routerset list is NULL.
1475 NS(test_main
)(void *arg
)
1477 smartlist_t
*out
= smartlist_new();
1478 routerset_t
*set
= NULL
;
1481 tt_int_op(smartlist_len(out
), OP_EQ
, 0);
1482 routerset_get_all_nodes(out
, NULL
, NULL
, 0);
1484 tt_int_op(smartlist_len(out
), OP_EQ
, 0);
1486 set
= routerset_new();
1487 smartlist_free(set
->list
);
1488 routerset_get_all_nodes(out
, NULL
, NULL
, 0);
1489 tt_int_op(smartlist_len(out
), OP_EQ
, 0);
1491 /* Just recreate list, so we can simply use routerset_free. */
1492 set
->list
= smartlist_new();
1495 routerset_free(set
);
1496 smartlist_free(out
);
1500 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list_with_no_nodes)
1503 * Structural test for routerset_get_all_nodes, when the routerset list
1507 NS_DECL(const node_t
*, node_get_by_nickname
,
1508 (const char *nickname
, int warn_if_unused
));
1509 const char *NS(mock_nickname
);
1512 NS(test_main
)(void *arg
)
1514 smartlist_t
*out
= smartlist_new();
1515 routerset_t
*set
= routerset_new();
1519 NS_MOCK(node_get_by_nickname
);
1521 NS(mock_nickname
) = "foo";
1522 smartlist_add(set
->list
, tor_strdup(NS(mock_nickname
)));
1524 routerset_get_all_nodes(out
, set
, NULL
, 0);
1525 out_len
= smartlist_len(out
);
1527 smartlist_free(out
);
1528 routerset_free(set
);
1530 tt_int_op(out_len
, OP_EQ
, 0);
1531 tt_int_op(CALLED(node_get_by_nickname
), OP_EQ
, 1);
1538 NS(node_get_by_nickname
)(const char *nickname
, int warn_if_unused
)
1540 CALLED(node_get_by_nickname
)++;
1541 tt_str_op(nickname
, OP_EQ
, NS(mock_nickname
));
1542 tt_int_op(warn_if_unused
, OP_EQ
, 1);
1549 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list_flag_not_running)
1552 * Structural test for routerset_get_all_nodes, with the running_only flag
1553 * is set but the nodes are not running.
1556 NS_DECL(const node_t
*, node_get_by_nickname
,
1557 (const char *nickname
, int warn_if_unused
));
1558 const char *NS(mock_nickname
);
1559 node_t
NS(mock_node
);
1562 NS(test_main
)(void *arg
)
1564 smartlist_t
*out
= smartlist_new();
1565 routerset_t
*set
= routerset_new();
1569 NS_MOCK(node_get_by_nickname
);
1571 NS(mock_node
).is_running
= 0;
1572 NS(mock_nickname
) = "foo";
1573 smartlist_add(set
->list
, tor_strdup(NS(mock_nickname
)));
1575 routerset_get_all_nodes(out
, set
, NULL
, 1);
1576 out_len
= smartlist_len(out
);
1578 smartlist_free(out
);
1579 routerset_free(set
);
1581 tt_int_op(out_len
, OP_EQ
, 0);
1582 tt_int_op(CALLED(node_get_by_nickname
), OP_EQ
, 1);
1589 NS(node_get_by_nickname
)(const char *nickname
, int warn_if_unused
)
1591 CALLED(node_get_by_nickname
)++;
1592 tt_str_op(nickname
, OP_EQ
, NS(mock_nickname
));
1593 tt_int_op(warn_if_unused
, OP_EQ
, 1);
1596 return &NS(mock_node
);
1600 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, list)
1603 * Structural test for routerset_get_all_nodes.
1606 NS_DECL(const node_t
*, node_get_by_nickname
,
1607 (const char *nickname
, int warn_if_unused
));
1608 char *NS(mock_nickname
);
1609 node_t
NS(mock_node
);
1612 NS(test_main
)(void *arg
)
1614 smartlist_t
*out
= smartlist_new();
1615 routerset_t
*set
= routerset_new();
1620 NS_MOCK(node_get_by_nickname
);
1622 NS(mock_nickname
) = tor_strdup("foo");
1623 smartlist_add(set
->list
, NS(mock_nickname
));
1625 routerset_get_all_nodes(out
, set
, NULL
, 0);
1626 out_len
= smartlist_len(out
);
1627 ent
= (node_t
*)smartlist_get(out
, 0);
1629 smartlist_free(out
);
1630 routerset_free(set
);
1632 tt_int_op(out_len
, OP_EQ
, 1);
1633 tt_ptr_op(ent
, OP_EQ
, &NS(mock_node
));
1634 tt_int_op(CALLED(node_get_by_nickname
), OP_EQ
, 1);
1641 NS(node_get_by_nickname
)(const char *nickname
, int warn_if_unused
)
1643 CALLED(node_get_by_nickname
)++;
1644 tt_str_op(nickname
, OP_EQ
, NS(mock_nickname
));
1645 tt_int_op(warn_if_unused
, OP_EQ
, 1);
1648 return &NS(mock_node
);
1652 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, nodelist_with_no_nodes)
1655 * Structural test for routerset_get_all_nodes, when the nodelist has no nodes.
1658 NS_DECL(smartlist_t
*, nodelist_get_list
, (void));
1660 smartlist_t
*NS(mock_smartlist
);
1663 NS(test_main
)(void *arg
)
1665 routerset_t
*set
= routerset_new();
1666 smartlist_t
*out
= smartlist_new();
1670 NS_MOCK(nodelist_get_list
);
1672 smartlist_add(set
->country_names
, tor_strdup("{xx}"));
1673 NS(mock_smartlist
) = smartlist_new();
1675 routerset_get_all_nodes(out
, set
, NULL
, 1);
1676 r
= smartlist_len(out
);
1677 routerset_free(set
);
1678 smartlist_free(out
);
1679 smartlist_free(NS(mock_smartlist
));
1681 tt_int_op(r
, OP_EQ
, 0);
1682 tt_int_op(CALLED(nodelist_get_list
), OP_EQ
, 1);
1689 NS(nodelist_get_list
)(void)
1691 CALLED(nodelist_get_list
)++;
1693 return NS(mock_smartlist
);
1697 #define NS_SUBMODULE ASPECT(routerset_get_all_nodes, nodelist_flag_not_running)
1700 * Structural test for routerset_get_all_nodes, with a non-list routerset
1701 * the running_only flag is set, but the nodes are not running.
1704 NS_DECL(smartlist_t
*, nodelist_get_list
, (void));
1706 smartlist_t
*NS(mock_smartlist
);
1707 node_t
NS(mock_node
);
1710 NS(test_main
)(void *arg
)
1712 routerset_t
*set
= routerset_new();
1713 smartlist_t
*out
= smartlist_new();
1717 NS_MOCK(nodelist_get_list
);
1719 smartlist_add(set
->country_names
, tor_strdup("{xx}"));
1720 NS(mock_smartlist
) = smartlist_new();
1721 NS(mock_node
).is_running
= 0;
1722 smartlist_add(NS(mock_smartlist
), (void *)&NS(mock_node
));
1724 routerset_get_all_nodes(out
, set
, NULL
, 1);
1725 r
= smartlist_len(out
);
1726 routerset_free(set
);
1727 smartlist_free(out
);
1728 smartlist_free(NS(mock_smartlist
));
1730 tt_int_op(r
, OP_EQ
, 0);
1731 tt_int_op(CALLED(nodelist_get_list
), OP_EQ
, 1);
1738 NS(nodelist_get_list
)(void)
1740 CALLED(nodelist_get_list
)++;
1742 return NS(mock_smartlist
);
1746 #define NS_SUBMODULE routerset_subtract_nodes
1749 * Functional test for routerset_subtract_nodes.
1753 NS(test_main
)(void *arg
)
1755 routerset_t
*set
= routerset_new();
1756 smartlist_t
*list
= smartlist_new();
1757 const char *nickname
= "foo";
1762 strmap_set_lc(set
->names
, nickname
, (void *)1);
1764 ri
.nickname
= (char *)nickname
;
1765 mock_node
.rs
= NULL
;
1767 smartlist_add(list
, (void *)&mock_node
);
1769 tt_int_op(smartlist_len(list
), OP_NE
, 0);
1770 routerset_subtract_nodes(list
, set
);
1772 tt_int_op(smartlist_len(list
), OP_EQ
, 0);
1774 routerset_free(set
);
1775 smartlist_free(list
);
1779 #define NS_SUBMODULE ASPECT(routerset_subtract_nodes, null_routerset)
1782 * Functional test for routerset_subtract_nodes, with a NULL routerset.
1786 NS(test_main
)(void *arg
)
1788 routerset_t
*set
= NULL
;
1789 smartlist_t
*list
= smartlist_new();
1790 const char *nickname
= "foo";
1795 ri
.nickname
= (char *)nickname
;
1797 smartlist_add(list
, (void *)&mock_node
);
1799 tt_int_op(smartlist_len(list
), OP_NE
, 0);
1800 routerset_subtract_nodes(list
, set
);
1802 tt_int_op(smartlist_len(list
), OP_NE
, 0);
1804 routerset_free(set
);
1805 smartlist_free(list
);
1809 #define NS_SUBMODULE routerset_to_string
1812 * Functional test for routerset_to_string.
1816 NS(test_main
)(void *arg
)
1818 routerset_t
*set
= NULL
;
1823 s
= routerset_to_string(set
);
1824 tt_str_op(s
, OP_EQ
, "");
1827 set
= routerset_new();
1828 s
= routerset_to_string(set
);
1829 tt_str_op(s
, OP_EQ
, "");
1831 routerset_free(set
); set
= NULL
;
1833 set
= routerset_new();
1834 smartlist_add(set
->list
, tor_strndup("a", 1));
1835 s
= routerset_to_string(set
);
1836 tt_str_op(s
, OP_EQ
, "a");
1838 routerset_free(set
); set
= NULL
;
1840 set
= routerset_new();
1841 smartlist_add(set
->list
, tor_strndup("a", 1));
1842 smartlist_add(set
->list
, tor_strndup("b", 1));
1843 s
= routerset_to_string(set
);
1844 tt_str_op(s
, OP_EQ
, "a,b");
1846 routerset_free(set
); set
= NULL
;
1850 routerset_free((routerset_t
*)set
);
1854 #define NS_SUBMODULE ASPECT(routerset_equal, empty_empty)
1857 * Functional test for routerset_equal, with both routersets empty.
1861 NS(test_main
)(void *arg
)
1863 routerset_t
*a
= routerset_new(), *b
= routerset_new();
1867 r
= routerset_equal(a
, b
);
1871 tt_int_op(r
, OP_EQ
, 1);
1878 #define NS_SUBMODULE ASPECT(routerset_equal, empty_not_empty)
1881 * Functional test for routerset_equal, with one routersets empty.
1885 NS(test_main
)(void *arg
)
1887 routerset_t
*a
= routerset_new(), *b
= routerset_new();
1891 smartlist_add(b
->list
, tor_strdup("{xx}"));
1892 r
= routerset_equal(a
, b
);
1896 tt_int_op(r
, OP_EQ
, 0);
1902 #define NS_SUBMODULE ASPECT(routerset_equal, differing_lengths)
1905 * Functional test for routerset_equal, with the routersets having
1906 * differing lengths.
1910 NS(test_main
)(void *arg
)
1912 routerset_t
*a
= routerset_new(), *b
= routerset_new();
1916 smartlist_add(a
->list
, tor_strdup("{aa}"));
1917 smartlist_add(b
->list
, tor_strdup("{b1}"));
1918 smartlist_add(b
->list
, tor_strdup("{b2}"));
1919 r
= routerset_equal(a
, b
);
1923 tt_int_op(r
, OP_EQ
, 0);
1929 #define NS_SUBMODULE ASPECT(routerset_equal, unequal)
1932 * Functional test for routerset_equal, with the routersets being
1937 NS(test_main
)(void *arg
)
1939 routerset_t
*a
= routerset_new(), *b
= routerset_new();
1943 smartlist_add(a
->list
, tor_strdup("foo"));
1944 smartlist_add(b
->list
, tor_strdup("bar"));
1945 r
= routerset_equal(a
, b
);
1949 tt_int_op(r
, OP_EQ
, 0);
1955 #define NS_SUBMODULE ASPECT(routerset_equal, equal)
1958 * Functional test for routerset_equal, with the routersets being
1963 NS(test_main
)(void *arg
)
1965 routerset_t
*a
= routerset_new(), *b
= routerset_new();
1969 smartlist_add(a
->list
, tor_strdup("foo"));
1970 smartlist_add(b
->list
, tor_strdup("foo"));
1971 r
= routerset_equal(a
, b
);
1975 tt_int_op(r
, OP_EQ
, 1);
1981 #define NS_SUBMODULE ASPECT(routerset_free, null_routerset)
1984 * Structural test for routerset_free, where the routerset is NULL.
1987 NS_DECL(void, smartlist_free
, (smartlist_t
*sl
));
1990 NS(test_main
)(void *arg
)
1994 NS_MOCK(smartlist_free
);
1996 routerset_free(NULL
);
1998 tt_int_op(CALLED(smartlist_free
), OP_EQ
, 0);
2005 NS(smartlist_free
)(smartlist_t
*s
)
2008 CALLED(smartlist_free
)++;
2012 #define NS_SUBMODULE routerset_free
2015 * Structural test for routerset_free.
2018 NS_DECL(void, smartlist_free
, (smartlist_t
*sl
));
2019 NS_DECL(void, strmap_free
,(strmap_t
*map
, void (*free_val
)(void*)));
2020 NS_DECL(void, digestmap_free
, (digestmap_t
*map
, void (*free_val
)(void*)));
2023 NS(test_main
)(void *arg
)
2025 routerset_t
*routerset
= routerset_new();
2028 NS_MOCK(smartlist_free
);
2029 NS_MOCK(strmap_free
);
2030 NS_MOCK(digestmap_free
);
2032 routerset_free(routerset
);
2034 tt_int_op(CALLED(smartlist_free
), OP_NE
, 0);
2035 tt_int_op(CALLED(strmap_free
), OP_NE
, 0);
2036 tt_int_op(CALLED(digestmap_free
), OP_NE
, 0);
2043 NS(smartlist_free
)(smartlist_t
*s
)
2045 CALLED(smartlist_free
)++;
2046 smartlist_free__real(s
);
2050 NS(strmap_free
)(strmap_t
*map
, void (*free_val
)(void*))
2052 CALLED(strmap_free
)++;
2053 strmap_free__real(map
, free_val
);
2057 NS(digestmap_free
)(digestmap_t
*map
, void (*free_val
)(void*))
2059 CALLED(digestmap_free
)++;
2060 digestmap_free__real(map
, free_val
);
2065 struct testcase_t routerset_tests
[] = {
2066 TEST_CASE(routerset_new
),
2067 TEST_CASE(routerset_get_countryname
),
2068 TEST_CASE(routerset_is_list
),
2069 TEST_CASE(routerset_needs_geoip
),
2070 TEST_CASE(routerset_is_empty
),
2071 TEST_CASE_ASPECT(routerset_contains
, null_set_or_null_set_list
),
2072 TEST_CASE_ASPECT(routerset_contains
, set_and_nickname
),
2073 TEST_CASE_ASPECT(routerset_contains
, set_and_null_nickname
),
2074 TEST_CASE_ASPECT(routerset_contains
, set_and_no_nickname
),
2075 TEST_CASE_ASPECT(routerset_contains
, set_and_digest
),
2076 TEST_CASE_ASPECT(routerset_contains
, set_and_no_digest
),
2077 TEST_CASE_ASPECT(routerset_contains
, set_and_null_digest
),
2078 TEST_CASE_ASPECT(routerset_contains
, set_and_addr
),
2079 TEST_CASE_ASPECT(routerset_contains
, set_and_no_addr
),
2080 TEST_CASE_ASPECT(routerset_contains
, set_and_null_addr
),
2081 TEST_CASE_ASPECT(routerset_contains
, countries_no_geoip
),
2082 TEST_CASE_ASPECT(routerset_contains
, countries_geoip
),
2083 TEST_CASE_ASPECT(routerset_add_unknown_ccs
, only_flag_and_no_ccs
),
2084 TEST_CASE_ASPECT(routerset_add_unknown_ccs
, creates_set
),
2085 TEST_CASE_ASPECT(routerset_add_unknown_ccs
, add_unknown
),
2086 TEST_CASE_ASPECT(routerset_add_unknown_ccs
, add_a1
),
2087 TEST_CASE(routerset_contains_extendinfo
),
2088 TEST_CASE(routerset_contains_router
),
2089 TEST_CASE(routerset_contains_routerstatus
),
2090 TEST_CASE_ASPECT(routerset_contains_node
, none
),
2091 TEST_CASE_ASPECT(routerset_contains_node
, routerinfo
),
2092 TEST_CASE_ASPECT(routerset_contains_node
, routerstatus
),
2093 TEST_CASE_ASPECT(routerset_get_all_nodes
, no_routerset
),
2094 TEST_CASE_ASPECT(routerset_get_all_nodes
, list_with_no_nodes
),
2095 TEST_CASE_ASPECT(routerset_get_all_nodes
, list_flag_not_running
),
2096 TEST_CASE_ASPECT(routerset_get_all_nodes
, list
),
2097 TEST_CASE_ASPECT(routerset_get_all_nodes
, nodelist_with_no_nodes
),
2098 TEST_CASE_ASPECT(routerset_get_all_nodes
, nodelist_flag_not_running
),
2099 TEST_CASE_ASPECT(routerset_refresh_counties
, geoip_not_loaded
),
2100 TEST_CASE_ASPECT(routerset_refresh_counties
, no_countries
),
2101 TEST_CASE_ASPECT(routerset_refresh_counties
, one_valid_country
),
2102 TEST_CASE_ASPECT(routerset_refresh_counties
, one_invalid_country
),
2103 TEST_CASE_ASPECT(routerset_union
, source_bad
),
2104 TEST_CASE_ASPECT(routerset_union
, one
),
2105 TEST_CASE_ASPECT(routerset_parse
, malformed
),
2106 TEST_CASE_ASPECT(routerset_parse
, valid_hexdigest
),
2107 TEST_CASE_ASPECT(routerset_parse
, valid_nickname
),
2108 TEST_CASE_ASPECT(routerset_parse
, get_countryname
),
2109 TEST_CASE_ASPECT(routerset_parse
, policy
),
2110 TEST_CASE(routerset_subtract_nodes
),
2111 TEST_CASE_ASPECT(routerset_subtract_nodes
, null_routerset
),
2112 TEST_CASE(routerset_to_string
),
2113 TEST_CASE_ASPECT(routerset_equal
, empty_empty
),
2114 TEST_CASE_ASPECT(routerset_equal
, empty_not_empty
),
2115 TEST_CASE_ASPECT(routerset_equal
, differing_lengths
),
2116 TEST_CASE_ASPECT(routerset_equal
, unequal
),
2117 TEST_CASE_ASPECT(routerset_equal
, equal
),
2118 TEST_CASE_ASPECT(routerset_free
, null_routerset
),
2119 TEST_CASE(routerset_free
),