mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Add unit test for tor_addr_is_loopback
This commit is contained in:
parent
b528aaef03
commit
165b2c0123
@ -623,12 +623,48 @@ test_addr_ip6_helpers(void)
|
||||
;
|
||||
}
|
||||
|
||||
static void
|
||||
test_addr_is_loopback(void *data)
|
||||
{
|
||||
static const struct loopback_item {
|
||||
const char *name;
|
||||
int is_loopback;
|
||||
} loopback_items[] = {
|
||||
{ "::1", 1 },
|
||||
{ "127.0.0.1", 1 },
|
||||
{ "127.99.100.101", 1 },
|
||||
{ "128.99.100.101", 0 },
|
||||
{ "8.8.8.8", 0 },
|
||||
{ "0.0.0.0", 0 },
|
||||
{ "::2", 0 },
|
||||
{ "::", 0 },
|
||||
{ "::1.0.0.0", 0 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
int i;
|
||||
tor_addr_t addr;
|
||||
(void)data;
|
||||
|
||||
for (i=0; loopback_items[i].name; ++i) {
|
||||
tt_int_op(tor_addr_parse(&addr, loopback_items[i].name), >=, 0);
|
||||
tt_int_op(tor_addr_is_loopback(&addr), ==, loopback_items[i].is_loopback);
|
||||
}
|
||||
|
||||
tor_addr_make_unspec(&addr);
|
||||
tt_int_op(tor_addr_is_loopback(&addr), ==, 0);
|
||||
|
||||
done:
|
||||
;
|
||||
}
|
||||
|
||||
#define ADDR_LEGACY(name) \
|
||||
{ #name, legacy_test_helper, 0, &legacy_setup, test_addr_ ## name }
|
||||
|
||||
struct testcase_t addr_tests[] = {
|
||||
ADDR_LEGACY(basic),
|
||||
ADDR_LEGACY(ip6_helpers),
|
||||
{ "is_loopback", test_addr_is_loopback, 0, NULL, NULL },
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user