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
This commit is contained in:
berniev
2023-01-03 14:12:19 +10:00
committed by Chris Hennes
parent 4eca103469
commit 9a05a04dad
14 changed files with 96 additions and 78 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -0,0 +1,7 @@
#include "gtest/gtest.h"
#include "App/Branding.h"
TEST(Branding, one){
QString ss {};
}

View File

@@ -0,0 +1,5 @@
target_sources(
Tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Branding.cpp
)

View File

@@ -0,0 +1,8 @@
#include "gtest/gtest.h"
#include <QString>
#include "Base/Builder3D.h"
TEST(Builder, one){
QString ss{};
}

View File

@@ -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})

View File

@@ -1 +1,5 @@
add_subdirectory(Base)
add_subdirectory(App)
add_subdirectory(Gui)
add_subdirectory(Misc)
add_subdirectory(Qt)

View File

@@ -0,0 +1,7 @@
#include "gtest/gtest.h"
#include "Gui/Assistant.h"
TEST(Assistant, first){
}

View File

@@ -0,0 +1,5 @@
target_sources(
Tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Assistant.cpp
)

View File

@@ -0,0 +1,6 @@
target_sources(
Tests_run
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/test1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test2.cpp
)

View File

@@ -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
)