Skip to content
Snippets Groups Projects
Commit 634352a1 authored by Lars Bilke's avatar Lars Bilke
Browse files

Integrated googletest similar to OGS-5.

parent a9e22bc3
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,9 @@ INCLUDE_DIRECTORIES(
# Add logog subdirectory and group its targets in a Visual Studio folder
ADD_SUBDIRECTORY(logog)
SET_PROPERTY(TARGET Continuous PROPERTY FOLDER "logog")
IF(BUILD_TESTING)
SET_PROPERTY(TARGET Continuous PROPERTY FOLDER "logog")
ENDIF()
SET_PROPERTY(TARGET logog PROPERTY FOLDER "logog")
SET_PROPERTY(TARGET test-logog PROPERTY FOLDER "logog")
......
......@@ -96,6 +96,7 @@ IF( OGS_BUILD_CLI )
ADD_SUBDIRECTORY( OGS )
ENDIF() # OGS_BUILD_CLI
IF( OGS_BUILD_TESTS )
ADD_SUBDIRECTORY( Tests )
ADD_SUBDIRECTORY( SimpleTests/MatrixTests )
ADD_SUBDIRECTORY( SimpleTests/MeshTests )
IF(NOT MSVC AND BLAS_FOUND AND LAPACK_FOUND)
......
/**
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* \file TestSwap.cpp
*
* Created on 2010-04-29 by Lars Bilke
*/
// ** INCLUDES **
#include "gtest.h"
#include "swap.h"
TEST(BaseLib, SwapInt) {
int arg0 = 5;
int arg1 = 10;
BaseLib::swap(arg0, arg1);
ASSERT_EQ ( arg0, 10 );
ASSERT_EQ ( arg1, 5 );
}
TEST(BaseLib, SwapDouble) {
double arg0 = 5.0;
double arg1 = 10.0;
BaseLib::swap(arg0, arg1);
ASSERT_EQ ( arg0, 10.0 );
ASSERT_EQ ( arg1, 5.0 );
}
TEST(BaseLib, SwapString) {
std::string arg0 = "5";
std::string arg1 = "10";
BaseLib::swap(arg0, arg1);
ASSERT_EQ ( arg0, std::string("10") );
ASSERT_EQ ( arg1, std::string("5") );
}
ADD_SUBDIRECTORY( gtest )
GET_SOURCE_FILES(TEST_SOURCES)
GET_SOURCE_FILES(TEST_SOURCES BaseLib)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/Tests/gtest
${CMAKE_SOURCE_DIR}/BaseLib
)
ADD_EXECUTABLE (testrunner testrunner.cpp ${TEST_SOURCES})
TARGET_LINK_LIBRARIES(testrunner
GTest
BaseLib
)
# Creates one ctest entry for every googletest
ADD_GOOGLE_TESTS ( ${EXECUTABLE_OUTPUT_PATH}/${CMAKE_CFG_INTDIR}/testrunner ${TEST_SOURCES})
\ No newline at end of file
# This is Googletest 1.6 compressed to 2 source files
IF (HAVE_PTHREADS)
ADD_DEFINITIONS (-DGTEST_HAS_PTHREAD=1)
ELSE ()
ADD_DEFINITIONS (-DGTEST_HAS_PTHREAD=0)
ENDIF ()
ADD_LIBRARY (GTest gtest.h gtest-all.cc)
SET_TARGET_PROPERTIES(GTest PROPERTIES FOLDER Testing)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
/**
* Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*
* \file testrunner.cpp
* Created on 2012-04-29 by Lars Bilke
*
*/
// ** INCLUDES **
#include "gtest.h"
/// Implementation of the googletest testrunner
int main(int argc, char* argv[])
{
testing::InitGoogleTest ( &argc, argv );
return RUN_ALL_TESTS();
}
......@@ -7,13 +7,13 @@ ENDMACRO()
# Returns a list of source files (*.h and *.cpp) in SOURCE_FILES and creates a Visual
# Studio folder. A (relative) subdirectory can be passed as second parameter (optional).
MACRO(GET_SOURCE_FILES SOURCE_FILES)
IF(${ARGC} EQUAL 2)
SET(DIR "${ARGV1}")
ELSE()
SET(DIR ".")
ENDIF()
# Get all files in the directory
FILE(GLOB GET_SOURCE_FILES_HEADERS ${DIR}/*.h)
FILE(GLOB GET_SOURCE_FILES_SOURCES ${DIR}/*.cpp)
......@@ -27,10 +27,24 @@ MACRO(GET_SOURCE_FILES SOURCE_FILES)
ELSE()
SET(DIR "")
ENDIF()
GET_CURRENT_SOURCE_SUBDIRECTORY(DIRECTORY)
SOURCE_GROUP( "${DIRECTORY}${DIR}" FILES
${GET_SOURCE_FILES_HEADERS}
${GET_SOURCE_FILES_SOURCES})
ENDMACRO()
# Creates one ctest for each googletest found in source files passed as arguments
# number two onwards. Argument one specifies the testrunner executable.
MACRO(ADD_GOOGLE_TESTS executable)
FOREACH ( source ${ARGN} )
FILE(READ "${source}" contents)
STRING(REGEX MATCHALL "TEST_?F?\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
FOREACH(hit ${found_tests})
STRING(REGEX REPLACE ".*\\(([A-Za-z_0-9]+)[, ]*([A-Za-z_0-9]+)\\).*" "\\1.\\2" test_name ${hit})
ADD_TEST(${test_name} ${executable} --gtest_output=xml --gtest_filter=${test_name} ${MI3CTestingDir})
# message ("Adding test: ${test_name}")
ENDFOREACH(hit)
ENDFOREACH()
ENDMACRO()
\ No newline at end of file
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