Skip to content

Commit

Permalink
tests/common: add test for get_addr errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andcscott committed Oct 26, 2024
1 parent e6aa924 commit 5574b77
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,28 @@ START_TEST(test_parse_format_ipv4_mapped_ipv6)
}
END_TEST

START_TEST(test_get_addr_err)
{
char *host = "192.168.2.10";
struct sockaddr_storage addr;
int addr_len;
int flags = AI_PASSIVE;

/* Invalid host */
addr_len = get_addr(NULL, -1, flags, 0, &addr);
ck_assert(addr_len == -1);
/* Invalid port */
addr_len = get_addr(host, -1, flags, 0, &addr);
ck_assert(addr_len == -1);
/* Invalid flag */
addr_len = get_addr(host, 53, flags | 0xFFF, 0, &addr);
ck_assert(addr_len == -1);
/* Invalid addr */
addr_len = get_addr(host, 53, flags, 0, (struct sockaddr_storage *)NULL);
ck_assert(addr_len == -1);
}
END_TEST

TCase *
test_common_create_tests(void)
{
Expand All @@ -295,6 +317,7 @@ test_common_create_tests(void)
tcase_add_test(tc, test_query_datalen_wild);
tcase_add_test(tc, test_parse_format_ipv4);
tcase_add_test(tc, test_parse_format_ipv4_listen_all);
tcase_add_test(tc, test_get_addr_err);

/* Tests require IPv6 support */
sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
Expand Down

0 comments on commit 5574b77

Please sign in to comment.