From 70645d5bc1f8d039a240f3753b656a1cdfc7ca70 Mon Sep 17 00:00:00 2001 From: Peter Honeder Date: Fri, 3 Apr 2015 10:22:05 -0700 Subject: [PATCH] fetched changes from branch feature/GetComputerName --- CMakeLists.txt | 3 ++- impl/getcomputername.cpp | 8 ++++++++ impl/getcomputername.h | 9 +++++++++ tests/test-getcomputername.cpp | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 impl/getcomputername.cpp create mode 100644 impl/getcomputername.h create mode 100644 tests/test-getcomputername.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4355f98d04..868a006fa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/impl/getcomputername.cpp b/impl/getcomputername.cpp new file mode 100644 index 0000000000..f67adab0b5 --- /dev/null +++ b/impl/getcomputername.cpp @@ -0,0 +1,8 @@ +#include "getcomputername.h" +#include + +int GetComputerName(char *name, size_t len) +{ + int host = gethostname(name, len); + return host; +} diff --git a/impl/getcomputername.h b/impl/getcomputername.h new file mode 100644 index 0000000000..a1d6cefe21 --- /dev/null +++ b/impl/getcomputername.h @@ -0,0 +1,9 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + +int GetComputerName(char * name, size_t len); + +PAL_END_EXTERNC \ No newline at end of file diff --git a/tests/test-getcomputername.cpp b/tests/test-getcomputername.cpp new file mode 100644 index 0000000000..c2c152ed54 --- /dev/null +++ b/tests/test-getcomputername.cpp @@ -0,0 +1,23 @@ +#include +#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]); + } +} \ No newline at end of file