mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
Tests: Add tests for gethostbyname_r()
This commit is contained in:
parent
1a7e262752
commit
5c4b71ac67
2 changed files with 53 additions and 0 deletions
|
@ -8,6 +8,7 @@ set(TEST_SOURCES
|
||||||
TestLibCDirEnt.cpp
|
TestLibCDirEnt.cpp
|
||||||
TestLibCInodeWatcher.cpp
|
TestLibCInodeWatcher.cpp
|
||||||
TestLibCMkTemp.cpp
|
TestLibCMkTemp.cpp
|
||||||
|
TestLibCNetdb.cpp
|
||||||
TestLibCSetjmp.cpp
|
TestLibCSetjmp.cpp
|
||||||
TestLibCString.cpp
|
TestLibCString.cpp
|
||||||
TestLibCTime.cpp
|
TestLibCTime.cpp
|
||||||
|
|
52
Tests/LibC/TestLibCNetdb.cpp
Normal file
52
Tests/LibC/TestLibCNetdb.cpp
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Marcus Nilsson <marcus.nilsson@genarp.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibTest/TestCase.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
TEST_CASE(gethostbyname_r_should_return_erange_when_buffer_is_to_small)
|
||||||
|
{
|
||||||
|
constexpr size_t buffer_size = 2;
|
||||||
|
char buffer[buffer_size] = { 0 };
|
||||||
|
int h_errnop;
|
||||||
|
struct hostent ret;
|
||||||
|
struct hostent* result;
|
||||||
|
|
||||||
|
int rc = gethostbyname_r("127.0.0.1", &ret, buffer, buffer_size, &result, &h_errnop);
|
||||||
|
EXPECT_EQ(rc, ERANGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(gethostbyname_r_should_return_host_not_found)
|
||||||
|
{
|
||||||
|
constexpr size_t buffer_size = 1024;
|
||||||
|
char buffer[buffer_size] = { 0 };
|
||||||
|
int h_errnop;
|
||||||
|
struct hostent ret;
|
||||||
|
struct hostent* result;
|
||||||
|
|
||||||
|
int rc = gethostbyname_r("unknownhostthatdoesntexistandhopefullyneverwill.com", &ret, buffer, buffer_size, &result, &h_errnop);
|
||||||
|
EXPECT(rc < 0);
|
||||||
|
EXPECT_EQ(h_errnop, HOST_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(gethostbyname_r)
|
||||||
|
{
|
||||||
|
constexpr size_t buffer_size = 1024;
|
||||||
|
char buffer[buffer_size] = { 0 };
|
||||||
|
int h_errnop;
|
||||||
|
struct hostent ret;
|
||||||
|
struct hostent* result;
|
||||||
|
|
||||||
|
int rc = gethostbyname_r("google.com", &ret, buffer, buffer_size, &result, &h_errnop);
|
||||||
|
EXPECT_EQ(rc, 0);
|
||||||
|
EXPECT_EQ(h_errnop, 0);
|
||||||
|
EXPECT_NE(result, nullptr);
|
||||||
|
EXPECT_EQ(result->h_aliases[0], nullptr);
|
||||||
|
EXPECT_EQ(result->h_addr_list[1], nullptr);
|
||||||
|
EXPECT_EQ(result->h_addrtype, AF_INET);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue