Files
PowerShell/src/libpsl-native/test/test-getfullyqualifiedname.cpp
T

37 lines
1.1 KiB
C++
Raw Normal View History

2015-10-28 16:42:15 -07:00
//! @file test-getfullyqualifiedname.cpp
//! @author George Fleming <v-geflem@microsoft.com>
//! @brief Unit tests for GetFullyQualifiedName
#include <gtest/gtest.h>
2016-07-13 12:32:18 -07:00
#include "getcomputername.h"
2015-10-28 16:42:15 -07:00
#include "getfullyqualifiedname.h"
2016-03-04 19:52:03 -08:00
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string>
2015-10-28 16:42:15 -07:00
2016-07-13 12:32:18 -07:00
TEST(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName)
2015-10-28 16:42:15 -07:00
{
2016-03-04 19:52:03 -08:00
std::string actual(GetFullyQualifiedName());
2015-10-28 16:42:15 -07:00
2016-07-13 12:32:18 -07:00
std::string hostname(GetComputerName());
2015-10-28 16:42:15 -07:00
2016-07-13 12:32:18 -07:00
// FQDN starts with hostname (which may be fully qualified)
EXPECT_LE(hostname, actual);
2015-10-28 16:42:15 -07:00
2016-07-13 12:32:18 -07:00
// hostname did not include domain name, so test it separately
if (hostname < actual)
{
struct addrinfo hints, *info;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
EXPECT_FALSE(getaddrinfo(hostname.c_str(), "http", &hints, &info));
2015-10-28 16:42:15 -07:00
2016-07-13 12:32:18 -07:00
// Compare canonical name to FQDN
EXPECT_STREQ(info->ai_canonname, actual.c_str());
2016-03-04 19:52:03 -08:00
2016-07-13 12:32:18 -07:00
freeaddrinfo(info);
}
2015-10-28 16:42:15 -07:00
}