mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 20:56:02 +00:00
We can't use `hostname --fqdn` or any other shell tool because there is no POSIX compatible way to do this short of system calls. Unfortunately this means the test practically reimplements the original code, but oh well.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
//! @file test-getfullyqualifiedname.cpp
|
|
//! @author George Fleming <v-geflem@microsoft.com>
|
|
//! @brief Unit tests for GetFullyQualifiedName
|
|
|
|
#include <gtest/gtest.h>
|
|
#include "getfullyqualifiedname.h"
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
#include <string>
|
|
|
|
//! Test fixture for GetComputerNameTest
|
|
class GetFullyQualifiedNameTest : public ::testing::Test
|
|
{
|
|
};
|
|
|
|
TEST_F(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName)
|
|
{
|
|
std::string actual(GetFullyQualifiedName());
|
|
|
|
std::string hostname(_POSIX_HOST_NAME_MAX, 0);
|
|
ASSERT_FALSE(gethostname(&hostname[0], hostname.length()));
|
|
// trim null characters from string
|
|
hostname = std::string(hostname.c_str());
|
|
|
|
struct addrinfo hints, *info;
|
|
memset(&hints, 0, sizeof(hints));
|
|
hints.ai_family = AF_UNSPEC;
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
hints.ai_flags = AI_CANONNAME;
|
|
ASSERT_FALSE(getaddrinfo(hostname.c_str(), "http", &hints, &info));
|
|
|
|
// Compare hostname part of FQDN
|
|
ASSERT_EQ(hostname, actual.substr(0, hostname.length()));
|
|
|
|
// Compare canonical name to FQDN
|
|
ASSERT_EQ(info->ai_canonname, actual);
|
|
|
|
freeaddrinfo(info);
|
|
}
|