Files
PowerShell/tests/test-getfullyqualifiedname.cpp
T
Andrew Schwartzmeyer 3bdcf50465 Use HOST_NAME_MAX as specified in gethostname(2)
NAME_MAX is the "maximum number of bytes in a filename," which is
irrelevant to the gethostname libc function.
2015-11-09 09:46:53 -08:00

35 lines
1022 B
C++

//! @file test-getfullyqualifiedname.cpp
//! @author George Fleming <v-geflem@microsoft.com>
//! @brief Unit tests for GetFullyQualifiedName
#include <gtest/gtest.h>
#include "getfullyqualifiedname.h"
//! Test fixture for GetComputerNameTest
class GetFullyQualifiedNameTest : public ::testing::Test
{
};
TEST_F(GetFullyQualifiedNameTest, ValidateLinuxGetFullyQualifiedDomainName)
{
char expectedComputerName[HOST_NAME_MAX];
//Get expected result from using linux command
FILE *fPtr = popen("hostname --fqdn", "r");
ASSERT_TRUE(fPtr != NULL);
char *linePtr = fgets(expectedComputerName, sizeof(expectedComputerName), fPtr);
ASSERT_TRUE(linePtr != NULL);
// There's a tendency to have \n at end of fgets string, so remove it before compare
size_t sz = strlen(expectedComputerName);
if (sz > 0 && expectedComputerName[sz - 1] == '\n')
{
expectedComputerName[sz - 1] = '\0';
}
pclose(fPtr);
ASSERT_STREQ(GetFullyQualifiedName(), expectedComputerName);
}