Skip to content
Permalink
Browse files

tests: socket: misc: Add tests for inet_pton()

Basic testcases for accepting correct input and rejecting invalid.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
  • Loading branch information...
pfalcon authored and jukkar committed May 6, 2019
1 parent 909f5a8 commit b2bfcc27b970dd369cc2346fa2d07618d42e8445
Showing with 26 additions and 1 deletion.
  1. +26 −1 tests/net/socket/misc/src/main.c
@@ -25,12 +25,37 @@ void test_gethostname(void)
zassert_equal(strcmp(buf, "ztest_hostname"), 0, "");
}

void test_inet_pton(void)
{
int res;
u8_t buf[32];

res = inet_pton(AF_INET, "127.0.0.1", buf);
zassert_equal(res, 1, "");

res = inet_pton(AF_INET, "127.0.0.1a", buf);
zassert_equal(res, 0, "");

res = inet_pton(AF_INET6, "a:b:c:d:0:1:2:3", buf);
zassert_equal(res, 1, "");

res = inet_pton(AF_INET6, "::1", buf);
zassert_equal(res, 1, "");

res = inet_pton(AF_INET6, "1::", buf);
zassert_equal(res, 1, "");

res = inet_pton(AF_INET6, "a:b:c:d:0:1:2:3z", buf);
zassert_equal(res, 0, "");
}

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

ztest_test_suite(socket_misc,
ztest_user_unit_test(test_gethostname));
ztest_user_unit_test(test_gethostname),
ztest_user_unit_test(test_inet_pton));

ztest_run_test_suite(socket_misc);
}

0 comments on commit b2bfcc2

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