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

41 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-09-09 11:44:51 -07:00
char *hostname = GetComputerName();
ASSERT_STRNE(NULL, hostname);
// this might be fail
errno = 0;
char *actual = GetFullyQualifiedName();
int fqdnErrno = errno;
2015-10-28 16:42:15 -07:00
2016-08-18 15:25:47 -07:00
struct addrinfo hints, *info;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_CANONNAME;
2016-09-09 11:44:51 -07:00
errno = 0;
if (getaddrinfo(hostname, "http", &hints, &info) != 0)
{
// test that getaddrinfo failed the same way
EXPECT_EQ(fqdnErrno, errno);
goto exit;
}
2015-10-28 16:42:15 -07:00
2016-08-18 15:25:47 -07:00
// Compare canonical name to FQDN
2016-09-09 11:44:51 -07:00
EXPECT_STREQ(info->ai_canonname, actual);
2016-08-18 15:25:47 -07:00
freeaddrinfo(info);
2016-09-09 11:44:51 -07:00
exit:
free(hostname);
2015-10-28 16:42:15 -07:00
}