Files
PowerShell/tests/test-getcomputername.cpp
T

34 lines
967 B
C++
Raw Normal View History

//! @file test-getcomputername.cpp
2015-10-27 15:33:25 -07:00
//! @author George Fleming <v-geflem@microsoft.com>
//! @brief Unit tests for GetComputerName
#include <gtest/gtest.h>
#include "getcomputername.h"
//! Test fixture for GetComputerNameTest
2015-08-13 10:53:09 -07:00
class GetComputerNameTest : public ::testing::Test
{
};
2015-10-27 15:33:25 -07:00
TEST_F(GetComputerNameTest, ValidateLinuxGetHostnameSystemCall)
2015-08-13 10:53:09 -07:00
{
2015-11-02 16:40:28 -08:00
char expectedComputerName[NAME_MAX];
//Get expected result from using linux command
FILE *fPtr = popen("hostname -s", "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);
2015-10-27 10:48:31 -07:00
ASSERT_STREQ(GetComputerName(), expectedComputerName);
2015-07-30 12:47:10 -07:00
}