Skip to content
Snippets Groups Projects
Commit acb45b9c authored by Soeren Peters's avatar Soeren Peters
Browse files

Added unittest functionality.

parent 38a843b3
No related branches found
No related tags found
No related merge requests found
if(BUILD_SHARED_LIBS)
add_definitions(-DGTEST_LINKED_AS_SHARED_LIBRARY)
endif()
target_include_directories(${targetName} PRIVATE ${GMOCK_ROOT}/googlemock/include)
target_include_directories(${targetName} PRIVATE ${GMOCK_ROOT}/googletest/include)
target_link_directories(${targetName} PRIVATE ${GMOCK_ROOT}/build/lib)
target_link_libraries(${targetName} PRIVATE gtest gmock gmock_main)
......@@ -28,11 +28,21 @@ endmacro(includeTestFiles)
macro(includeFiles targetName file_path)
foreach(file ${file_path})
message("File: " ${file})
get_filename_component(package_dir ${file} DIRECTORY)
message("package_dir: " ${package_dir})
collectFilesFrom(${file})
if (package_dir)
setSourceGroupForFilesIn(${package_dir} ${targetName})
#setSourceGroupForFilesIn(${package_dir} ${targetName})
buildSourceGroup(${targetName} ${package_dir})
if(isAllTestSuite)
source_group(${targetName}\\${SOURCE_GROUP} FILES ${MY_SRCS})
else()
source_group(${SOURCE_GROUP} FILES ${file})
endif()
endif()
endforeach()
endmacro(includeFiles)
......@@ -95,6 +105,8 @@ macro(buildSourceGroup targetName path)
endif()
endforeach()
message("SOURCE_GROUP: " ${SOURCE_GROUP})
if(NOT SOURCE_GROUP)
set(SOURCE_GROUP "general")
endif()
......
......@@ -50,6 +50,10 @@ function(vf_add_library)
set(sourceFiles ${sourceFiles} ${all_files})
endif()
foreach(X IN LISTS sourceFiles)
message(STATUS "${X}")
endforeach()
if (ARG_EXCLUDE)
foreach(file_path ${sourceFiles})
foreach(file_exclude ${ARG_EXCLUDE})
......@@ -175,3 +179,27 @@ function(vf_add_library)
endfunction(vf_add_library)
function(vf_add_tests)
vf_get_library_name (folder_name)
set (targetName ${folder_name}Tests)
message(Add Test binary: ${targetName})
file ( GLOB_RECURSE all_files ${VIRTUAL_FLUIDS_GLOB_FILES} )
set(sourceFiles ${sourceFiles} ${all_files})
includeTestFiles (${folder_name} "${sourceFiles}")
message(${MY_SRCS})
ADD_EXECUTABLE(${targetName} ${MY_SRCS})
target_link_libraries(${targetName} PRIVATE ${folder_name})
target_include_directories(${targetName} PRIVATE ${CMAKE_BINARY_DIR})
target_include_directories(${targetName} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(${targetName} PRIVATE ${CMAKE_SOURCE_DIR}/src)
include(${CMAKE_PATH}/3rd/gmock.cmake)
#add_compile_options (-std=c++11)
add_definitions("-std=c++11")
endfunction(vf_add_tests)
\ No newline at end of file
......@@ -39,4 +39,6 @@ IF(${USE_METIS})
SET(METIS_DEBUG_LIBRARY "/usr/local/lib/libmetis.a")
SET(METIS_RELEASE_LIBRARY "/usr/local/lib/libmetis.a")
ENDIF()
#set(SOURCE_ROOT "/host/Projects/pFluid/source")
\ No newline at end of file
#set(SOURCE_ROOT "/host/Projects/pFluid/source")
SET(GMOCK_ROOT "~/Libraries/googletest-release-1.10.0" CACHE PATH "GMOCK ROOT")
\ No newline at end of file
......@@ -19,6 +19,10 @@ include(Core/buildInfo.cmake)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/VirtualFluidsCore)
INCLUDE_DIRECTORIES(${MPI_INCLUDE_PATH})
IF(MSVC)
add_compile_definitions(NOMINMAX) # Disable Min/Max-Macros
ENDIF(MSVC)
vf_add_library(BUILDTYPE static
FOLDER
${CMAKE_CURRENT_LIST_DIR}/numerics/geometry3d
......@@ -43,8 +47,13 @@ vf_add_library(BUILDTYPE static
EXCLUDE buildInfo.in.cpp
)
vf_get_library_name (library_name)
target_include_directories(${library_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Core)
target_include_directories(${library_name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
include (${CMAKE_PATH}/3rd/mpi.cmake)
\ No newline at end of file
include (${CMAKE_PATH}/3rd/mpi.cmake)
include (${CMAKE_PATH}/3rd/boost.cmake)
linkBoost ("")
vf_add_tests()
\ No newline at end of file
......@@ -5,7 +5,7 @@
#include "../Logger.h"
TEST(LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStream)
TEST(DISABLED_LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStream)
{
std::ostringstream stream;
logging::Logger::setStream(&stream);
......@@ -15,7 +15,7 @@ TEST(LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStrea
EXPECT_THAT(stream.str(), "[LOW] Hello World\n");
}
TEST(LoggerTest, logStringWithHighDebugLevel_logOnlyHighLevelMessages)
TEST(DISABLED_LoggerTest, logStringWithHighDebugLevel_logOnlyHighLevelMessages)
{
std::ostringstream stream;
logging::Logger::setStream(&stream);
......@@ -26,7 +26,7 @@ TEST(LoggerTest, logStringWithHighDebugLevel_logOnlyHighLevelMessages)
EXPECT_THAT(stream.str(), "[HIGH] HIGH Debug Message\n");
}
TEST(LoggerTest, addTwoStreams_shouldWriteToBoth)
TEST(DISABLED_LoggerTest, addTwoStreams_shouldWriteToBoth)
{
logging::Logger::resetStreams();
......@@ -41,7 +41,7 @@ TEST(LoggerTest, addTwoStreams_shouldWriteToBoth)
EXPECT_THAT(stream2.str(), "[LOW] Hello World\n");
}
TEST(LoggerTest, splittetOutputShouldHaveDebugInformationOnce)
TEST(DISABLED_LoggerTest, splittetOutputShouldHaveDebugInformationOnce)
{
std::ostringstream stream;
logging::Logger::setStream(&stream);
......@@ -51,7 +51,7 @@ TEST(LoggerTest, splittetOutputShouldHaveDebugInformationOnce)
EXPECT_THAT(stream.str(), "[LOW] Hello World\n");
}
TEST(LoggerTest, enableTimeStampInOutput)
TEST(DISABLED_LoggerTest, enableTimeStampInOutput)
{
std::ostringstream stream;
logging::Logger::setStream(&stream);
......
......@@ -88,6 +88,17 @@ bool StringUtil::toBool(bool &t, const std::string &input, std::ios_base &(*f)(s
return !(iss >> f >> t).fail();
}
std::vector<std::string> split(const std::string& str, char delim = ' ')
{
std::stringstream ss(str);
std::string token;
std::vector<std::string> list;
while (std::getline(ss, token, delim)) {
list.push_back(token);
}
return list;
}
std::vector<int> StringUtil::toIntVector(const std::string& input)
{
std::vector<int> v;
......@@ -160,5 +171,10 @@ template BASICS_EXPORT std::string StringUtil::toString<int>(const int& t);
bool StringUtil::endsWith(const std::string &input, const std::string &end)
{
return boost::algorithm::ends_with(input, end);
if (input.length() >= end.length()) {
return (0 == input.compare (input.length() - end.length(), end.length(), end));
} else {
return false;
}
//return boost::algorithm::ends_with(input, end);
}
\ No newline at end of file
//
// Created by Soeren Peters on 24.07.20.
//
#include <gmock/gmock.h>
TEST(TestTest, failing)
{
ASSERT_TRUE(false);
}
\ No newline at end of file
#include "gmock/gmock.h"
#include "Vector3D.h"
#include <cmath>
using namespace testing;
class Vector3DTest : public Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment