Skip to content
Permalink
Browse files

tests: net: getaddrinfo: Add cases for numeric IPv4 addr

And also for AI_NUMERICHOST flag.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
  • Loading branch information...
pfalcon authored and jukkar committed May 28, 2019
1 parent 8b3db46 commit 4d8941a91da8725a01f0ef473fbe69bb776a797d
Showing with 51 additions and 3 deletions.
  1. +51 −3 tests/net/socket/getaddrinfo/src/main.c
@@ -255,15 +255,63 @@ void test_getaddrinfo_no_host(void)
freeaddrinfo(res);
}

void test_getaddrinfo_num_ipv4(void)
{
struct zsock_addrinfo *res = NULL;
struct sockaddr_in *saddr;
int ret;

ret = zsock_getaddrinfo("1.2.3.255", "65534", NULL, &res);

zassert_equal(ret, 0, "Invalid result");
zassert_not_null(res, "");
zassert_is_null(res->ai_next, "");

zassert_equal(res->ai_family, AF_INET, "");
zassert_equal(res->ai_socktype, SOCK_STREAM, "");
zassert_equal(res->ai_protocol, IPPROTO_TCP, "");

saddr = (struct sockaddr_in *)res->ai_addr;
zassert_equal(saddr->sin_family, AF_INET, "");
zassert_equal(saddr->sin_port, htons(65534), "");
zassert_equal(saddr->sin_addr.s4_addr[0], 1, "");
zassert_equal(saddr->sin_addr.s4_addr[1], 2, "");
zassert_equal(saddr->sin_addr.s4_addr[2], 3, "");
zassert_equal(saddr->sin_addr.s4_addr[3], 255, "");

zsock_freeaddrinfo(res);
}

void test_getaddrinfo_flags_numerichost(void)
{
int ret;
struct zsock_addrinfo *res = NULL;
struct zsock_addrinfo hints = {
.ai_flags = AI_NUMERICHOST,
};

ret = zsock_getaddrinfo("foo.bar", "65534", &hints, &res);
zassert_equal(ret, DNS_EAI_FAIL, "Invalid result");
zassert_is_null(res, "");

ret = zsock_getaddrinfo("1.2.3.4", "65534", &hints, &res);
zassert_equal(ret, 0, "Invalid result");
zassert_not_null(res, "");

zsock_freeaddrinfo(res);
}

void test_main(void)
{
k_thread_system_pool_assign(k_current_get());

ztest_test_suite(socket_getaddrinfo,
ztest_unit_test(test_getaddrinfo_setup),
ztest_user_unit_test(test_getaddrinfo_ok),
ztest_user_unit_test(test_getaddrinfo_cancelled),
ztest_user_unit_test(test_getaddrinfo_no_host));
ztest_unit_test(test_getaddrinfo_ok),
ztest_unit_test(test_getaddrinfo_cancelled),
ztest_unit_test(test_getaddrinfo_no_host),
ztest_unit_test(test_getaddrinfo_num_ipv4),
ztest_unit_test(test_getaddrinfo_flags_numerichost));

ztest_run_test_suite(socket_getaddrinfo);
}

0 comments on commit 4d8941a

Please sign in to comment.
You can’t perform that action at this time.