mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Tests: Add tests for gethostbyname_r()
This commit is contained in:
parent
1a7e262752
commit
5c4b71ac67
Notes:
sideshowbarker
2024-07-16 23:17:55 +09:00
Author: https://github.com/mkanilsson Commit: https://github.com/SerenityOS/serenity/commit/5c4b71ac67 Pull-request: https://github.com/SerenityOS/serenity/pull/20536 Reviewed-by: https://github.com/ADKaster ✅
@ -8,6 +8,7 @@ set(TEST_SOURCES
|
||||
TestLibCDirEnt.cpp
|
||||
TestLibCInodeWatcher.cpp
|
||||
TestLibCMkTemp.cpp
|
||||
TestLibCNetdb.cpp
|
||||
TestLibCSetjmp.cpp
|
||||
TestLibCString.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…
Reference in New Issue
Block a user