From 8b279dfa719349fd865c576f91f2d863a12e6f02 Mon Sep 17 00:00:00 2001 From: Harald Scheirich <harald.scheirich@kitware.com> Date: Wed, 28 Jul 2021 12:16:26 -0400 Subject: [PATCH] ENH:Add a main to run the unittests --- CMake/Utilities/imstkAddTest.cmake | 5 +-- CMakeLists.txt | 1 + Source/Testing/CMakeLists.txt | 13 ++++++++ Source/Testing/imstkTestingMain.cpp | 51 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 Source/Testing/CMakeLists.txt create mode 100644 Source/Testing/imstkTestingMain.cpp diff --git a/CMake/Utilities/imstkAddTest.cmake b/CMake/Utilities/imstkAddTest.cmake index e82df3795..ff50656d7 100644 --- a/CMake/Utilities/imstkAddTest.cmake +++ b/CMake/Utilities/imstkAddTest.cmake @@ -50,10 +50,11 @@ function(imstk_add_test_internal target kind) # Link test driver against current target, gtest and pthread target_link_libraries(${test_driver_executable} ${target} + Testing + Threads::Threads GTest::gtest GTest::gmock - GTest::gtest_main - Threads::Threads + ) if (MSVC) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bdecc461..690bf97df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -377,6 +377,7 @@ add_subdirectory(Source/CollisionDetection) add_subdirectory(Source/CollisionHandling) add_subdirectory(Source/Scene) add_subdirectory(Source/SimulationManager) +add_subdirectory(Source/Testing) add_subdirectory(Source/Filtering) add_subdirectory(Source/FilteringCore) diff --git a/Source/Testing/CMakeLists.txt b/Source/Testing/CMakeLists.txt new file mode 100644 index 000000000..2b6f17a34 --- /dev/null +++ b/Source/Testing/CMakeLists.txt @@ -0,0 +1,13 @@ +#----------------------------------------------------------------------------- +# Create target +#----------------------------------------------------------------------------- +if( ${PROJECT_NAME}_BUILD_TESTING ) +include(imstkAddLibrary) +imstk_add_library( Testing + DEPENDS + Common + GTest::gtest + ${VTK_LIBRARIES} + ) + +endif() \ No newline at end of file diff --git a/Source/Testing/imstkTestingMain.cpp b/Source/Testing/imstkTestingMain.cpp new file mode 100644 index 000000000..0a9c20bdd --- /dev/null +++ b/Source/Testing/imstkTestingMain.cpp @@ -0,0 +1,51 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#include <vtksys/SystemTools.hxx> + +#include <gtest/gtest.h> + +#include "imstkLogger.h" + +int +main(int argc, char** argv) +{ + bool removeLog = true; + for (int i = 0; i < argc; ++i) + { + if (std::string(argv[i]) == "--imstk_keep_log") + { + removeLog = true; + } + } + + if (removeLog) + { + vtksys::SystemTools::RemoveADirectory("testlog"); + vtksys::SystemTools::MakeDirectory("testlog"); + } + + auto& logger = imstk::Logger::getInstance(); + logger.addFileSink("test", "testlog"); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file -- GitLab