Commit 3059ffbe authored by Harald Scheirich's avatar Harald Scheirich
Browse files

Merge branch 'feature/plain-gtest' into 'master'

ENH: Discard old google test wrapper in favor of plain google test

See merge request !586
parents 241f93e0 9def6eff
Pipeline #231785 passed with stage
in 0 seconds
......@@ -3,12 +3,13 @@
#-----------------------------------------------------------------------------
include(imstkAddExternalProject)
imstk_add_external_project( GTest
URL https://gitlab.kitware.com/iMSTK/googletest/-/archive/release-1.10.0/googletest-release-1.10.0.zip
URL_MD5 1878d0300f865cb54df06b220ded5168
URL https://github.com/google/googletest/archive/53495a2a7d6ba7e0691a7f3602e9a5324bba6e45.zip
URL_MD5 8349ef674d27b005a43ce3679cb04947
CMAKE_CACHE_ARGS
-DBUILD_GMOCK:BOOL=ON
-DBUILD_GTEST:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
-Dgtest_force_shared_crt:BOOL=ON
DEPENDENCIES ""
RELATIVE_INCLUDE_PATH ""
#VERBOSE
......
# gtest_add_tests
#
# Taken from https://github.com/Kitware/CMake/blob/master/Modules/FindGTest.cmake
#
# Only changed the 'add_test' line to add 'extra_args' before the 'gtest_filter' flag.
# Doing so allows to use gtest with a ctest driver created after create_test_sourcelist,
# by providing the test file name as the first argument to the driver.
#
# Changes should become a part of CMake. Better improvements could be made to bring
# ctest and gtest together.
#
function(GTEST_ADD_TESTS executable extra_args)
if(NOT ARGN)
message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS")
endif()
if(ARGN STREQUAL "AUTO")
# obtain sources used for building that executable
get_property(ARGN TARGET ${executable} PROPERTY SOURCES)
endif()
set(gtest_case_name_regex ".*\\( *([A-Za-z_0-9]+) *, *([A-Za-z_0-9]+) *\\).*")
set(gtest_test_type_regex "(TYPED_TEST|TEST_?[FP]?)")
foreach(source ${ARGN})
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${source})
file(READ "${source}" contents)
string(REGEX MATCHALL "${gtest_test_type_regex} *\\(([A-Za-z_0-9 ,]+)\\)" found_tests ${contents})
foreach(hit ${found_tests})
string(REGEX MATCH "${gtest_test_type_regex}" test_type ${hit})
# Parameterized tests have a different signature for the filter
if("x${test_type}" STREQUAL "xTEST_P")
string(REGEX REPLACE ${gtest_case_name_regex} "*/\\1.\\2/*" test_name ${hit})
elseif("x${test_type}" STREQUAL "xTEST_F" OR "x${test_type}" STREQUAL "xTEST")
string(REGEX REPLACE ${gtest_case_name_regex} "\\1.\\2" test_name ${hit})
elseif("x${test_type}" STREQUAL "xTYPED_TEST")
string(REGEX REPLACE ${gtest_case_name_regex} "\\1/*.\\2" test_name ${hit})
else()
message(WARNING "Could not parse GTest ${hit} for adding to CTest.")
continue()
endif()
add_test(NAME ${test_name} COMMAND ${executable} ${extra_args} --gtest_filter=${test_name} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin) # changed here
endforeach()
endforeach()
endfunction()
# imstk_add_test
#
# Description: Will create tests for the given iMSTK target.
......@@ -72,35 +26,16 @@ endfunction()
# # test body on m_objectToTest
# }
#
# int imstkMyClassTest(int argc, char* argv[])
# {
# // Init Google Test
# ::testing::InitGoogleTest(&argc, argv);
#
# // Run tests with gtest
# return RUN_ALL_TESTS();
# }
#
function(imstk_add_test target)
include(GoogleTest)
set(test_driver_name "imstk${target}TestDriver")
string(TOLOWER ${target} target_lowercase)
set(test_driver_executable "imstk_${target_lowercase}_test_driver")
message(STATUS "Configuring ${test_driver_executable}")
#-----------------------------------------------------------------------------
# Check that Testing repository exists
#-----------------------------------------------------------------------------
if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Testing")
message(WARNING "Can not create test driver for ${target} target: missing 'Testing' directory in ${CMAKE_CURRENT_SOURCE_DIR}.")
return()
endif()
#-----------------------------------------------------------------------------
# Create test driver
#-----------------------------------------------------------------------------
function(imstk_add_test_internal target kind)
set(test_driver_executable "${target}${kind}")
# Get all source files
file(GLOB test_files "${CMAKE_CURRENT_SOURCE_DIR}/Testing/*Test.cpp")
file(GLOB test_files "${CMAKE_CURRENT_SOURCE_DIR}/*Test.cpp")
# Get all source file names
set(test_file_names "")
......@@ -109,44 +44,31 @@ function(imstk_add_test target)
list(APPEND test_file_names ${test_file_name})
endforeach()
# Create test driver main source file
create_test_sourcelist(test_sourcelist ${test_driver_name}.cpp ${test_file_names})
# Create test driver executable
imstk_add_executable(${test_driver_executable} ${test_driver_name}.cpp ${test_files})
imstk_add_executable(${test_driver_executable} ${test_files})
# Link test driver against current target, gtest and pthread
target_link_libraries(${test_driver_executable}
${target}
GTest::gtest
GTest::gmock
GTest::gtest_main
Threads::Threads
)
gtest_discover_tests(${test_driver_executable} WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin" DISCOVERY_MODE PRE_TEST)
#-----------------------------------------------------------------------------
# Add the target to Testing folder
#-----------------------------------------------------------------------------
SET_TARGET_PROPERTIES (${test_driver_executable} PROPERTIES FOLDER Testing)
#-----------------------------------------------------------------------------
# Create tests
#-----------------------------------------------------------------------------
foreach(test_file ${test_files})
get_filename_component(test_name ${test_file} NAME_WE)
# A. Registers tests per gTests
# [aka] a lot of tests - Google Testing standards
gtest_add_tests(${test_driver_executable} ${test_name} ${test_file})
# ... or ...
# B. Registers tests per test files
# [aka] less tests - CTest standards
# include(ExternalData)
# ExternalData_add_test( ${PROJECT_NAME}Data
# NAME ${test_name}
# COMMAND $<TARGET_FILE:${test_driver_executable}> ${test_name} --gtest_filter=${test_name}.*
# )
endfunction()
endforeach()
function(imstk_add_test target)
imstk_add_test_internal(${target} Tests)
endfunction()
function(imstk_add_visual_test target)
imstk_add_test_internal(${target} VisualTests)
endfunction()
......@@ -15,9 +15,5 @@ imstk_add_library( CollisionDetection
# Testing
#-----------------------------------------------------------------------------
if( ${PROJECT_NAME}_BUILD_TESTING )
include(imstkAddTest)
imstk_add_test(CollisionDetection)
imstk_add_data(CollisionDetection ${FILE_LIST_COL_TEST})
add_subdirectory(Testing)
endif()
include(imstkAddTest)
imstk_add_test( CollisionDetection )
imstk_add_data(CollisionDetection ${FILE_LIST_COL_TEST})
\ No newline at end of file
......@@ -537,15 +537,3 @@ TEST_F(OctreeBasedCDTest, TestMeshMeshUsingSurfaceMeshToSurfaceMeshCD)
testMeshMeshUsingSurfaceMeshToSurfaceMeshCD();
}
}
///
/// \brief TODO
///
int
imstkOctreeBasedCDTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -37,9 +37,6 @@ protected:
TetraToTetraCD* m_CD;
};
///
/// \brief TODO
///
std::shared_ptr<TetrahedralMesh>
loadMesh(const std::string& externalDataSuffix)
{
......@@ -52,18 +49,12 @@ loadMesh(const std::string& externalDataSuffix)
return volMesh;
}
///
/// \brief TODO
///
std::shared_ptr<TetrahedralMesh>
duplicate(std::shared_ptr<TetrahedralMesh> mesh)
{
return std::make_shared<TetrahedralMesh>(*mesh.get());
}
///
/// \brief TODO
///
TEST_F(imstkTetraToTetraCDTest, DISABLED_NoSelfIntersection)
{
std::shared_ptr<TetrahedralMesh> a = loadMesh("/asianDragon/asianDragon.veg");
......@@ -80,9 +71,6 @@ TEST_F(imstkTetraToTetraCDTest, DISABLED_NoSelfIntersection)
EXPECT_EQ(cd->PTColData.getSize(), 0);
}
///
/// \brief TODO
///
TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionThenNoIntersection1T)
{
std::shared_ptr<TetrahedralMesh> a = loadMesh("/oneTet/oneTet.veg");
......@@ -117,9 +105,6 @@ TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionThenNoIntersection1T)
EXPECT_EQ(cd->PTColData.getSize(), 0);
}
///
/// \brief TODO
///
TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionThenNoIntersectionHuman)
{
std::shared_ptr<TetrahedralMesh> a = loadMesh("/human/human.veg");
......@@ -161,9 +146,6 @@ TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionThenNoIntersectionHuman)
EXPECT_EQ(cd->PTColData.getSize(), 0);
}
///
/// \brief TODO
///
TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionOfDifferentMeshes)
{
std::shared_ptr<TetrahedralMesh> a = loadMesh("/asianDragon/asianDragon.veg");
......@@ -174,16 +156,3 @@ TEST_F(imstkTetraToTetraCDTest, DISABLED_IntersectionOfDifferentMeshes)
m_CD->computeCollisionData();
EXPECT_EQ(cd->PTColData.getSize(), 595);
}
///
/// \brief TODO
///
int
imstkTetraToTetraCDTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -14,7 +14,6 @@ imstk_add_library( Common
# Testing
#-----------------------------------------------------------------------------
if( ${PROJECT_NAME}_BUILD_TESTING )
include(imstkAddTest)
imstk_add_test( Common )
add_subdirectory(Testing)
endif()
include(imstkAddTest)
imstk_add_test( Common )
\ No newline at end of file
......@@ -145,6 +145,7 @@ TEST(imstkDataArrayTest, Iterators)
for (const auto& val : a)
{
GTEST_FAIL() << "Should not enter here";
int i = val;
}
auto itBegin = a.begin();
......@@ -203,13 +204,3 @@ TEST(imstkDataArrayTest, ParameterCast)
EXPECT_DOUBLE_EQ(static_cast<double>(a[i]), (*actualB)[i]);
}
}
int
imstkDataArrayTest(int argc, char* argv[])
{
// Init Google Test
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
\ No newline at end of file
......@@ -96,16 +96,3 @@ TEST_F(imstkModuleTest, UnInitialize)
m_moduleObject.uninit();
EXPECT_EQ(m_moduleObject.getInit(), false);
}
///
/// \brief TODO
///
int
imstkModuleTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -236,14 +236,4 @@ TEST(imstkVecDataArrayTest, ParameterCast)
{
EXPECT_TRUE(a[i].cast<double>().isApprox((*actualB)[i]));
}
}
int
imstkVecDataArrayTest(int argc, char* argv[])
{
// Init Google Test
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
\ No newline at end of file
......@@ -12,6 +12,5 @@ imstk_add_library( DataStructures
# Testing
#-----------------------------------------------------------------------------
if( ${PROJECT_NAME}_BUILD_TESTING )
include(imstkAddTest)
imstk_add_test( DataStructures )
add_subdirectory(Testing)
endif()
include(imstkAddTest)
imstk_add_test( DataStructures )
\ No newline at end of file
......@@ -139,25 +139,16 @@ randomizePositions(const std::shared_ptr<SurfaceMesh>& mesh)
namespace imstk
{
///
/// \brief TODO
///
class LooseOctreeTest : public ::testing::Test
{
public:
LooseOctreeTest() {}
///
/// \brief TODO
///
void reset()
{
m_Octree.reset(new LooseOctree(Vec3d(0, 0, 0), 100.0, 0.1, 4));
}
///
/// \brief TODO
///
void buildExample()
{
reset();
......@@ -177,9 +168,6 @@ public:
m_Octree->build();
}
///
/// \brief TODO
///
void testOctree()
{
m_Octree->update();
......@@ -265,9 +253,6 @@ public:
}
}
///
/// \brief TODO
///
void testDummyPrimitives(bool bRebuild)
{
// Test points
......@@ -379,24 +364,3 @@ TEST_F(LooseOctreeTest, TestTeleportingPrimitives)
randomizePositions(m_Mesh);
}
}
///
/// \brief Test octree update while primitives moving around randomly
///
TEST_F(LooseOctreeTest, TestDummyPrimitives)
{
testDummyPrimitives(true);
testDummyPrimitives(false);
}
///
/// \brief TODO
///
int
imstkLooseOctreeTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -198,14 +198,10 @@ verify(std::vector<std::vector<size_t>>& neighbors1, std::vector<std::vector<siz
return true;
}
class dummyClass : public ::testing::Test
{
};
///
/// \brief Generate a sphere-shape particles and search neighbors for each particle
///
TEST_F(dummyClass, CompareGridSearchAndSpatialHashing)
TEST(imstkNeighborSearchTest, CompareGridSearchAndSpatialHashing)
{
const Vec3r sphereCenter = SPHERE_CENTER;
const auto sphereRadiusSqr = SPHERE_RADIUS * SPHERE_RADIUS;
......@@ -251,7 +247,7 @@ TEST_F(dummyClass, CompareGridSearchAndSpatialHashing)
///
/// \brief Generate a sphere-shape particles and divide them into two point sets, then for each point in setA search neighbors in setB
///
TEST_F(dummyClass, TestGridSearchFromDifferentPointSet)
TEST(imstkNeighborSearchTest, TestGridSearchFromDifferentPointSet)
{
const Vec3r sphereCenter = SPHERE_CENTER;
const auto sphereRadiusSqr = SPHERE_RADIUS * SPHERE_RADIUS;
......@@ -309,15 +305,3 @@ TEST_F(dummyClass, TestGridSearchFromDifferentPointSet)
EXPECT_EQ(verify(neighbors1, neighbors0), true);
}
}
///
/// \brief TODO
///
int
imstkNeighborSearchTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -11,6 +11,5 @@ imstk_add_library( Geometry
# Testing
#-----------------------------------------------------------------------------
if( ${PROJECT_NAME}_BUILD_TESTING )
include(imstkAddTest)
imstk_add_test( Geometry )
add_subdirectory(Testing)
endif()
include(imstkAddTest)
imstk_add_test( Geometry )
\ No newline at end of file
......@@ -25,18 +25,12 @@
using namespace imstk;
///
/// \brief TODO
///
class imstkGeometryTest : public ::testing::Test
{
protected:
Plane m_geometry; // Can't use imstk::Geometry since pure virtual. Should use google mock class.
};
///
/// \brief TODO
///
TEST_F(imstkGeometryTest, GetSetScaling)
{
m_geometry.setScaling(Vec3d(2.0, 2.0, 2.0));
......@@ -49,9 +43,6 @@ TEST_F(imstkGeometryTest, GetSetScaling)
EXPECT_EQ(m_geometry.getScaling(), Vec3d(400000000.0, 400000000.0, 400000000.0));
}
///
/// \brief TODO
///
TEST_F(imstkGeometryTest, GetSetTranslation)
{
auto p1 = Vec3d(12.0, 0.0005, -400000.0);
......@@ -70,9 +61,6 @@ TEST_F(imstkGeometryTest, GetSetTranslation)
EXPECT_EQ(m_geometry.getTranslation(), p2);
}
///
/// \brief TODO
///
TEST_F(imstkGeometryTest, GetSetRotation1)
{
// NOTE: '==' not defined for Eigen::Quaternion, using 'isApprox'.
......@@ -85,9 +73,6 @@ TEST_F(imstkGeometryTest, GetSetRotation1)
EXPECT_TRUE(Quatd(m_geometry.getRotation()).isApprox(q1));
}
///
/// \brief TODO
///
TEST_F(imstkGeometryTest, GetSetRotation2)
{
// NOTE: '==' not defined for Eigen::Quaternion, using 'isApprox'.
......@@ -100,9 +85,6 @@ TEST_F(imstkGeometryTest, GetSetRotation2)
EXPECT_TRUE(m_geometry.getRotation().isApprox(mat2));
}
///
/// \brief TODO
///
TEST_F(imstkGeometryTest, GetSetRotation3)
{
// NOTE: '==' not defined for Eigen::Quaternion, using 'isApprox'.
......@@ -116,16 +98,3 @@ TEST_F(imstkGeometryTest, GetSetRotation3)
m_geometry.setRotation(axes, angle);
EXPECT_TRUE(m_geometry.getRotation().isApprox(mat3));
}
///
/// \brief TODO
///
int
imstkGeometryTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -66,13 +66,3 @@ TEST(imstkImageDataTest, Cast)
EXPECT_DOUBLE_EQ(static_cast<double>(intScalars[i]), (*actualScalars)[i]);
}
}
int
imstkImageDataTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}
......@@ -31,9 +31,6 @@ protected:
OrientedBox m_box;
};
///
/// \brief TODO
///
TEST_F(imstkOrientedBoxTest, SetGetWidth)
{
m_box.setExtents(1.0, 1.0, 1.0);
......@@ -43,18 +40,12 @@ TEST_F(imstkOrientedBoxTest, SetGetWidth)
EXPECT_DOUBLE_EQ(1.0, extents[2]);
}
///
/// \brief TODO
///
TEST_F(imstkOrientedBoxTest, GetVolume)
{
m_box.setExtents(1.0, 1.0, 1.0);
EXPECT_DOUBLE_EQ(8, m_box.getVolume());
}
///
/// \brief test the cube SDF evaluator
///
TEST_F(imstkOrientedBoxTest, GetFunctionValue)
{
m_box.setExtents(1.0, 1.0, 2.0);
......@@ -72,16 +63,3 @@ TEST_F(imstkOrientedBoxTest, GetFunctionValue)
EXPECT_DOUBLE_EQ(-0.5, m_box.getFunctionValue(Vec3d(0.5, 0.0, 0.0)));
EXPECT_DOUBLE_EQ(-0.5, m_box.getFunctionValue(Vec3d(0.0, -1.5, 0.0)));
}
///
/// \brief TODO
///
int
imstkOrientedBoxTest(int argc, char* argv[])
{
// Init Google Test & Mock
::testing::InitGoogleTest(&argc, argv);
// Run tests with gtest
return RUN_ALL_TESTS();
}