From 9a05a04daddcae1e1f5481cff0bddb2ebc1c5bfa Mon Sep 17 00:00:00 2001 From: berniev Date: Tue, 3 Jan 2023 14:12:19 +1000 Subject: [PATCH] Improve unit testing directory structure Separate Qt tests and gtest tests Add a basic shadow of the project structure Add a few simple tests to demonstrate usage --- src/App/CMakeLists.txt | 1 - tests/CMakeLists.txt | 60 +------------------------- tests/src/App/Branding.cpp | 7 +++ tests/src/App/CMakeLists.txt | 5 +++ tests/src/Base/Builder3D.cpp | 8 ++++ tests/src/Base/CMakeLists.txt | 23 ++-------- tests/src/CMakeLists.txt | 4 ++ tests/src/Gui/Assistant.cpp | 7 +++ tests/src/Gui/CMakeLists.txt | 5 +++ tests/src/Misc/CMakeLists.txt | 6 +++ tests/src/{ => Misc}/test1.cpp | 0 tests/src/{ => Misc}/test2.cpp | 0 tests/src/Qt/CMakeLists.txt | 48 +++++++++++++++++++++ tests/src/{ => Qt}/InventorBuilder.cpp | 0 14 files changed, 96 insertions(+), 78 deletions(-) create mode 100644 tests/src/App/Branding.cpp create mode 100644 tests/src/App/CMakeLists.txt create mode 100644 tests/src/Base/Builder3D.cpp create mode 100644 tests/src/Gui/Assistant.cpp create mode 100644 tests/src/Gui/CMakeLists.txt create mode 100644 tests/src/Misc/CMakeLists.txt rename tests/src/{ => Misc}/test1.cpp (100%) rename tests/src/{ => Misc}/test2.cpp (100%) create mode 100644 tests/src/Qt/CMakeLists.txt rename tests/src/{ => Qt}/InventorBuilder.cpp (100%) diff --git a/src/App/CMakeLists.txt b/src/App/CMakeLists.txt index 4f46da8792..f014d2bf38 100644 --- a/src/App/CMakeLists.txt +++ b/src/App/CMakeLists.txt @@ -290,7 +290,6 @@ if(FREECAD_USE_PCH) endif(FREECAD_USE_PCH) add_library(FreeCADApp SHARED ${FreeCADApp_SRCS}) - target_link_libraries(FreeCADApp ${FreeCADApp_LIBS}) add_dependencies(FreeCADApp fc_version) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 986701cb29..bc50262481 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,3 @@ -# 'Google_test' is the subproject name -project(Google_tests) - -if(WIN32) - add_definitions(-DCOIN_DLL) -endif(WIN32) - if(MSVC) option( gtest_force_shared_crt @@ -32,56 +25,7 @@ if(MSVC) endif() endif() -# 'lib' is the folder with Google Test sources +add_executable(Tests_run) add_subdirectory(lib) -include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) - -# 'Google_Tests_run' is the target name - -# 'test1.cpp tests2.cpp' are source files with tests -add_executable( - Google_Tests_run - src/test1.cpp - src/test2.cpp -) - -target_link_libraries(Google_Tests_run gtest gtest_main ${Google_Tests_LIBS}) - -# ------------------------------------------------------ - -enable_testing() - -function(SETUP_TESTS) - foreach(_testname ${ARGN}) - add_executable(${_testname}_Tests_run src/${_testname}.cpp) - add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run) - if(NOT BUILD_DYNAMIC_LINK_PYTHON) - list(APPEND ${_testname}_LIBS - ${PYTHON_LIBRARIES} - ) - endif() - target_link_libraries(${_testname}_Tests_run ${QtTest_LIBRARIES} ${${_testname}_LIBS}) - endforeach() -endfunction() - -set(CMAKE_AUTOMOC ON) - -# Qt Test -include_directories( - ${QtGui_INCLUDE_DIRS} - ${QtTest_INCLUDE_DIRS} - ${COIN3D_INCLUDE_DIRS} -) - -# ------------------------------------------------------ - -set (InventorBuilder_LIBS - ${COIN3D_LIBRARIES} - FreeCADBase -) - -SETUP_TESTS( - InventorBuilder -) - add_subdirectory(src) +target_link_libraries(Tests_run gtest_main ${Google_Tests_LIBS} FreeCADApp) diff --git a/tests/src/App/Branding.cpp b/tests/src/App/Branding.cpp new file mode 100644 index 0000000000..1a71e9b72d --- /dev/null +++ b/tests/src/App/Branding.cpp @@ -0,0 +1,7 @@ +#include "gtest/gtest.h" + +#include "App/Branding.h" + +TEST(Branding, one){ + QString ss {}; +} diff --git a/tests/src/App/CMakeLists.txt b/tests/src/App/CMakeLists.txt new file mode 100644 index 0000000000..6cc3e36166 --- /dev/null +++ b/tests/src/App/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources( + Tests_run + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Branding.cpp +) diff --git a/tests/src/Base/Builder3D.cpp b/tests/src/Base/Builder3D.cpp new file mode 100644 index 0000000000..6be77031ae --- /dev/null +++ b/tests/src/Base/Builder3D.cpp @@ -0,0 +1,8 @@ +#include "gtest/gtest.h" + +#include +#include "Base/Builder3D.h" + +TEST(Builder, one){ + QString ss{}; +} diff --git a/tests/src/Base/CMakeLists.txt b/tests/src/Base/CMakeLists.txt index a3c5b116ff..3582ab3076 100644 --- a/tests/src/Base/CMakeLists.txt +++ b/tests/src/Base/CMakeLists.txt @@ -1,20 +1,5 @@ - -add_executable( - Tests_Tools_run - tst_Tools.cpp +target_sources( + Tests_run + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/tst_Tools.cpp ) - -set (Tests_Tools_LIBS - gtest - gtest_main - ${Google_Tests_LIBS} - FreeCADBase -) - -if(NOT BUILD_DYNAMIC_LINK_PYTHON) - list(APPEND Tests_Tools_LIBS - ${PYTHON_LIBRARIES} - ) -endif() - -target_link_libraries(Tests_Tools_run ${Tests_Tools_LIBS}) diff --git a/tests/src/CMakeLists.txt b/tests/src/CMakeLists.txt index aef5792491..2f5f8257e2 100644 --- a/tests/src/CMakeLists.txt +++ b/tests/src/CMakeLists.txt @@ -1 +1,5 @@ add_subdirectory(Base) +add_subdirectory(App) +add_subdirectory(Gui) +add_subdirectory(Misc) +add_subdirectory(Qt) diff --git a/tests/src/Gui/Assistant.cpp b/tests/src/Gui/Assistant.cpp new file mode 100644 index 0000000000..6dca9aa065 --- /dev/null +++ b/tests/src/Gui/Assistant.cpp @@ -0,0 +1,7 @@ +#include "gtest/gtest.h" + +#include "Gui/Assistant.h" + +TEST(Assistant, first){ + +} diff --git a/tests/src/Gui/CMakeLists.txt b/tests/src/Gui/CMakeLists.txt new file mode 100644 index 0000000000..53ec78d55a --- /dev/null +++ b/tests/src/Gui/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources( + Tests_run + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Assistant.cpp +) diff --git a/tests/src/Misc/CMakeLists.txt b/tests/src/Misc/CMakeLists.txt new file mode 100644 index 0000000000..42ad1d45fd --- /dev/null +++ b/tests/src/Misc/CMakeLists.txt @@ -0,0 +1,6 @@ +target_sources( + Tests_run + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/test1.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test2.cpp +) diff --git a/tests/src/test1.cpp b/tests/src/Misc/test1.cpp similarity index 100% rename from tests/src/test1.cpp rename to tests/src/Misc/test1.cpp diff --git a/tests/src/test2.cpp b/tests/src/Misc/test2.cpp similarity index 100% rename from tests/src/test2.cpp rename to tests/src/Misc/test2.cpp diff --git a/tests/src/Qt/CMakeLists.txt b/tests/src/Qt/CMakeLists.txt new file mode 100644 index 0000000000..a0d8f411bf --- /dev/null +++ b/tests/src/Qt/CMakeLists.txt @@ -0,0 +1,48 @@ +# 'Google_test' is the subproject name +project(Google_tests) + +if(WIN32) + add_definitions(-DCOIN_DLL) +endif(WIN32) + +# 'lib' is the folder with Google Test sources + +# 'Google_Tests_run' is the target name +#target_link_libraries(Google_Tests_run gtest gtest_main ${Google_Tests_LIBS}) + +# ------------------------------------------------------ + +enable_testing() + +function(SETUP_TESTS) + foreach(_testname ${ARGN}) + add_executable(${_testname}_Tests_run ${_testname}.cpp) + add_test(NAME ${_testname}_Tests_run COMMAND ${_testname}_Tests_run) + if(NOT BUILD_DYNAMIC_LINK_PYTHON) + list(APPEND ${_testname}_LIBS + ${PYTHON_LIBRARIES} + ) + endif() + target_link_libraries(${_testname}_Tests_run ${QtTest_LIBRARIES} ${${_testname}_LIBS}) + endforeach() +endfunction() + +set(CMAKE_AUTOMOC ON) + +# Qt Test +include_directories( + ${QtGui_INCLUDE_DIRS} + ${QtTest_INCLUDE_DIRS} + ${COIN3D_INCLUDE_DIRS} +) + +# ------------------------------------------------------ + +set (InventorBuilder_LIBS + ${COIN3D_LIBRARIES} + FreeCADBase +) + +SETUP_TESTS( + InventorBuilder +) diff --git a/tests/src/InventorBuilder.cpp b/tests/src/Qt/InventorBuilder.cpp similarity index 100% rename from tests/src/InventorBuilder.cpp rename to tests/src/Qt/InventorBuilder.cpp