diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c9630dda1..3dfb4fdd4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,7 @@ add_executable(psnative-test test-getusername.cpp test-getcomputername.cpp test-getlinkcount.cpp + test-getfullyqualifiedname.cpp main.cpp) # manually include gtest headers diff --git a/tests/test-getfullyqualifiedname.cpp b/tests/test-getfullyqualifiedname.cpp new file mode 100644 index 000000000..484fd8d65 --- /dev/null +++ b/tests/test-getfullyqualifiedname.cpp @@ -0,0 +1,35 @@ +//! @file test-getfullyqualifiedname.cpp +//! @author George Fleming +//! @brief Unit tests for GetFullyQualifiedName + +#include +#include +#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("/bin/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); +}