fetched changes from branch feature/GetComputerName

This commit is contained in:
Peter Honeder 2015-04-03 10:22:05 -07:00
parent beb5be9ffa
commit 70645d5bc1
4 changed files with 42 additions and 1 deletions

View File

@ -6,7 +6,8 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#include gtest
include_directories(../ext-src/gtest/fused-src impl)
set(SOURCE_FILES main.cpp tests/test-getcurrentprocessid.cpp impl/getcurrentprocessorid.cpp ../ext-src/gtest/fused-src/gtest/gtest-all.cc)
set(SOURCE_FILES main.cpp tests/test-getcurrentprocessid.cpp impl/getcurrentprocessorid.cpp tests/test-getcomputername.cpp impl/getcomputername.cpp
../ext-src/gtest/fused-src/gtest/gtest-all.cc)
add_executable(monad_native ${SOURCE_FILES})
# add pthread

8
impl/getcomputername.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "getcomputername.h"
#include <unistd.h>
int GetComputerName(char *name, size_t len)
{
int host = gethostname(name, len);
return host;
}

9
impl/getcomputername.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include "pal.h"
PAL_BEGIN_EXTERNC
int GetComputerName(char * name, size_t len);
PAL_END_EXTERNC

View File

@ -0,0 +1,23 @@
#include <gtest/gtest.h>
#include "getcomputername.h"
TEST(GetComputerName,simple)
{
char hostname[128];
char hostnameFunctionTest[128];
int getComputerName = GetComputerName(hostnameFunctionTest, sizeof hostnameFunctionTest);
int host = gethostname(hostname, sizeof hostname);
// first make sure that on this platform those types are of the same size
ASSERT_TRUE(getComputerName == 0);
ASSERT_TRUE(host == 0);
// now compare the actual values
for(int i =0; hostname[i] != '\0'; i++)
{
ASSERT_EQ(hostnameFunctionTest[i],hostname[i]);
}
}