diff --git a/CMakeLists.txt b/CMakeLists.txt index b61395b0c..e0e4a7ab9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.8.4) project(MONAD_NATIVE) -add_compile_options(-std=c++11 -Wall) +add_compile_options(-std=c++11 -Wall -Werror) # test in BUILD_DIR enable_testing() diff --git a/native/getcomputername.cpp b/native/getcomputername.cpp index 3d4e7eda3..9feecf01c 100644 --- a/native/getcomputername.cpp +++ b/native/getcomputername.cpp @@ -33,7 +33,8 @@ char* GetComputerName() return NULL; } - // Get computername from system in a thread-safe manner + // Get computername from system, note that gethostname(2) gets the + // nodename from uname std::string computername(HOST_NAME_MAX, 0); int err = gethostname(&computername[0], computername.length()); // Map errno to Win32 Error Codes diff --git a/tests/test-getcomputername.cpp b/tests/test-getcomputername.cpp index 1a170c67d..e0e9ca17f 100644 --- a/tests/test-getcomputername.cpp +++ b/tests/test-getcomputername.cpp @@ -10,13 +10,12 @@ class GetComputerNameTest : public ::testing::Test { }; -TEST_F(GetComputerNameTest, ValidateLinuxGetHostnameSystemCall) +TEST_F(GetComputerNameTest, Success) { char expectedComputerName[HOST_NAME_MAX]; - //Get expected result from using linux command - - FILE *fPtr = popen("hostname -s", "r"); + // the gethostname system call gets the nodename from uname + FILE *fPtr = popen("uname -n", "r"); ASSERT_TRUE(fPtr != NULL); char *linePtr = fgets(expectedComputerName, sizeof(expectedComputerName), fPtr); diff --git a/tests/test-getusername.cpp b/tests/test-getusername.cpp index 50c2d1fea..cab8cb98b 100644 --- a/tests/test-getusername.cpp +++ b/tests/test-getusername.cpp @@ -10,18 +10,9 @@ #include #include "getusername.h" -//! Test fixture for GetUserName -class GetUserNameTest : public ::testing::Test +TEST(GetUserName, Success) { -protected: - std::string UserName; - - GetUserNameTest(): UserName(std::string(getpwuid(geteuid())->pw_name)) - { - } -}; - -TEST_F(GetUserNameTest, Success) -{ - ASSERT_EQ(GetUserName(), UserName); + char* expected = getpwuid(geteuid())->pw_name; + ASSERT_TRUE(expected != NULL); + ASSERT_EQ(GetUserName(), std::string(expected)); }