Skip to content
Permalink
Browse files
[cmake] use single macro QGIS_ADD_TEST and modernize cmake code
all duplication of the macro have been removed
the test targets are now named test_[module]_[test-name] which helps to sort them in QGIS
  • Loading branch information
3nids committed Jun 21, 2021
1 parent 51c8cb8 commit 38d89fc16f4aa106ff0debb3ed267fe83ea1116d
@@ -15,13 +15,10 @@ PyQgsAuthManagerOgrPostgresTest
PyQgsDbManagerPostgis

# Needs an OpenCL device, the library is not enough
qgis_openclutilstest
test_core_openclutils

# Relies on a broken/unreliable 3rd party service
qgis_layerdefinition
test_core_layerdefinition

# MSSQL requires the MSSQL docker
PyQgsProviderConnectionMssql



@@ -1,8 +1,8 @@
# flaky
qgis_filedownloader
qgis_wcsprovidertest
test_gui_filedownloader
test_provider_wcsprovider
PyQgsWFSProviderGUI
qgis_ziplayertest
test_core_ziplayer

# Flaky, the ms odbc driver crashes a lot on the ubuntu docker image. Retest when
# the docker base image is upgraded
@@ -1,7 +1,6 @@
# Standard includes and utils to compile into all tests.
set (util_SRCS)


#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
@@ -18,48 +17,21 @@ include_directories(SYSTEM
${QT5_3DEXTRA_INCLUDE_DIR}
)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time
#############################################################
# Tests:

macro (ADD_QGIS_TEST testname testsrc)
set(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
set(qgis_${testname}_MOC_CPPS ${testsrc})
add_executable(qgis_${testname} ${qgis_${testname}_SRCS})
# require c++17
target_compile_features(qgis_${testname} PRIVATE cxx_std_17)
set_target_properties(qgis_${testname} PROPERTIES AUTORCC TRUE)
target_link_libraries(qgis_${testname}
${Qt5Xml_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Svg_LIBRARIES}
${Qt5Network_LIBRARIES}
${Qt5Test_LIBRARIES}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
qgis_core
qgis_3d
qgis_native)
add_test(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
target_link_libraries(qgis_${testname} qgis_native)
add_test(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

add_subdirectory(sandbox)

ADD_QGIS_TEST(3dutilstest testqgs3dutils.cpp)
ADD_QGIS_TEST(3drenderingtest testqgs3drendering.cpp)
ADD_QGIS_TEST(layout3dmaptest testqgslayout3dmap.cpp)
ADD_QGIS_TEST(materialregistrytest testqgsmaterialregistry.cpp)
ADD_QGIS_TEST(3dmaterialtest testqgs3dmaterial.cpp)
ADD_QGIS_TEST(tessellatortest testqgstessellator.cpp)
ADD_QGIS_TEST(3dsymbolregistrytest testqgs3dsymbolregistry.cpp)
set(TESTS
testqgs3dutils.cpp
testqgs3drendering.cpp
testqgslayout3dmap.cpp
testqgsmaterialregistry.cpp
testqgs3dmaterial.cpp
testqgstessellator.cpp
testqgs3dsymbolregistry.cpp
)


foreach(TESTSRC ${TESTS})
add_qgis_test(${TESTSRC} MODULE 3d LINKEDLIBRARIES qgis_3d)
endforeach(TESTSRC)

@@ -1,4 +1,34 @@
if (ENABLE_TESTS)


macro (add_qgis_test TESTSRC)
set(options OPTIONAL)
set(oneValueArgs MODULE LABELS)
set(multiValueArgs LINKEDLIBRARIES DEPENDENCIES)
cmake_parse_arguments(ARG_QGIS_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
set (TESTNAME "test_${ARG_QGIS_TEST_MODULE}_${TESTNAME}")
add_executable(${TESTNAME} ${TESTSRC} ${util_SRCS})
# add_custom_target(${TESTNAME}moc ALL DEPENDS ${${TESTNAME}_MOC_SRCS})
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
set_target_properties(${TESTNAME} PROPERTIES AUTORCC TRUE)
target_link_libraries(${TESTNAME} ${ARG_QGIS_TEST_LINKEDLIBRARIES})
target_link_libraries(${TESTNAME} ${Qt5Test_LIBRARIES})
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
if (DEFINED ARG_QGIS_TEST_DEPENDENCIES)
add_dependencies(${TESTNAME} ${ARG_QGIS_TEST_DEPENDENCIES})
endif()
if (DEFINED ARG_QGIS_TEST_LABELS)
set_tests_properties(${TESTNAME} PROPERTIES LABELS ${ARG_QGIS_TEST_LABELS})
endif()
endmacro()



#############################################################
# Compiler defines

@@ -5,7 +5,8 @@ set (util_SRCS)
#####################################################
# Don't forget to include output directory, otherwise
# the UI file won't be wrapped!
include_directories(${CMAKE_CURRENT_SOURCE_DIR}
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/src/test
)
@@ -14,43 +15,11 @@ if(HAVE_OPENCL)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
endif()

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

macro (ADD_QGIS_TEST TESTSRC)
set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
set (TESTNAME "qgis_${TESTNAME}test")

set(${TESTNAME}_SRCS ${TESTSRC} ${util_SRCS})
set(${TESTNAME}_MOC_CPPS ${TESTSRC})
add_executable(${TESTNAME} ${${TESTNAME}_SRCS})
# require c++17
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
target_link_libraries(${TESTNAME}
${Qt5Core_LIBRARIES}
${Qt5Test_LIBRARIES}
qgis_analysis)
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

#############################################################
# Tests:
set(TESTS
testqgsgeometrysnapper.cpp
testqgsinterpolator.cpp
testqgsprocessing.cpp
testqgsprocessingalgs.cpp
testqgszonalstatistics.cpp
testqgsrastercalculator.cpp
@@ -62,17 +31,11 @@ set(TESTS
testqgsmeshcontours.cpp
testqgstriangulation.cpp
)

if(HAVE_GSL)
set(TESTS
${TESTS}
testqgsgcptransformer.cpp
)
set(TESTS ${TESTS} testqgsgcptransformer.cpp)
endif()

foreach(TESTSRC ${TESTS})
ADD_QGIS_TEST(${TESTSRC})
add_qgis_test(${TESTSRC} MODULE analysis LINKEDLIBRARIES qgis_analysis)
endforeach(TESTSRC)

SET_TESTS_PROPERTIES(qgis_processingtest
PROPERTIES LABELS "POSTGRES")
add_qgis_test(testqgsprocessing.cpp MODULE analysis LINKEDLIBRARIES qgis_analysis LABELS "POSTGRES")
@@ -6,89 +6,50 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

macro (ADD_QGIS_TEST testname testsrc)
set(qgis_${testname}_SRCS ${testsrc} ${util_SRCS})
add_custom_target(qgis_${testname}moc ALL DEPENDS ${qgis_${testname}_MOC_SRCS})
add_executable(qgis_${testname} ${qgis_${testname}_SRCS})
target_compile_features(qgis_${testname} PRIVATE cxx_std_17)
target_link_libraries(qgis_${testname}
${Qt5Core_LIBRARIES}
${Qt5Xml_LIBRARIES}
${Qt5Sql_LIBRARIES}
${Qt5Svg_LIBRARIES}
${Qt5Test_LIBRARIES}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
${QWT_LIBRARY}
qgis_core
qgis_gui
qgis_analysis
qgis_app)
if(WITH_QWTPOLAR AND NOT WITH_INTERNAL_QWTPOLAR)
target_link_libraries(qgis_${testname} ${QWTPOLAR_LIBRARY})
endif()
if(WIN32)
add_definitions(-DQWT_DLL)
target_link_libraries(qgis_${testname} dbghelp)
endif()
if (APPLE)
target_link_libraries(qgis_${testname} ${APP_SERVICES_LIBRARY} )
endif()
add_test(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname} -maxwarnings 10000)
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

#############################################################
# Tests:

set(TESTS
testqgisapp.cpp
testqgsappbrowserproviders.cpp
testqgisappclipboard.cpp
testqgisappdockwidgets.cpp
testqgsattributetable.cpp
testqgsapplocatorfilters.cpp
testqgsdecorationscalebar.cpp
testqgsfieldcalculator.cpp
testqgsmaptoolidentifyaction.cpp
testqgsmaptoollabel.cpp
testqgsmaptoolselect.cpp
testqgsmaptoolreshape.cpp
testqgsmaptoolrotatefeature.cpp
testqgsmaptoolscalefeature.cpp
testqgsmaptoolcircularstring.cpp
testqgsmaptoolcircle.cpp
testqgsmaptoolmovefeature.cpp
testqgsmaptoolellipse.cpp
testqgsmaptoolrectangle.cpp
testqgsmaptoolregularpolygon.cpp
testqgsmaptoolsplitparts.cpp
testqgsmaptoolsplitfeatures.cpp
testqgsmeasuretool.cpp
testqgsmeasurebearingtool.cpp
testqgsvertextool.cpp
testqgsvectorlayersaveasdialog.cpp
testqgsmaptoolreverseline.cpp
testqgsmaptooltrimextendfeature.cpp
testqgsprojectproperties.cpp
testqgsapplayoutvaliditychecks.cpp
testqgsmeshcalculatordialog.cpp
testqgsgpsinformationwidget.cpp
testqgslabelpropertydialog.cpp
)
if (WITH_BINDINGS)
ADD_QGIS_TEST(apppythontest testqgisapppython.cpp)
set(TESTS ${TESTS} testqgisapppython.cpp)
endif()
ADD_QGIS_TEST(qgisapp testqgisapp.cpp)
ADD_QGIS_TEST(appbrowserproviders testqgsappbrowserproviders.cpp)
ADD_QGIS_TEST(qgisappclipboard testqgisappclipboard.cpp)
ADD_QGIS_TEST(appdockwidgets testqgisappdockwidgets.cpp)
ADD_QGIS_TEST(attributetabletest testqgsattributetable.cpp)
ADD_QGIS_TEST(applocatorfilters testqgsapplocatorfilters.cpp)
ADD_QGIS_TEST(decorationscalebar testqgsdecorationscalebar.cpp)
ADD_QGIS_TEST(fieldcalculatortest testqgsfieldcalculator.cpp)
ADD_QGIS_TEST(maptoolidentifyaction testqgsmaptoolidentifyaction.cpp)
ADD_QGIS_TEST(maptoollabel testqgsmaptoollabel.cpp)
ADD_QGIS_TEST(maptoolselect testqgsmaptoolselect.cpp)
ADD_QGIS_TEST(maptoolreshape testqgsmaptoolreshape.cpp)
ADD_QGIS_TEST(maptoolrotatefeature testqgsmaptoolrotatefeature.cpp)
ADD_QGIS_TEST(maptoolscalefeature testqgsmaptoolscalefeature.cpp)
ADD_QGIS_TEST(maptoolcircularstringtest testqgsmaptoolcircularstring.cpp)
ADD_QGIS_TEST(maptoolcircletest testqgsmaptoolcircle.cpp)
ADD_QGIS_TEST(maptoolmovefeaturetest testqgsmaptoolmovefeature.cpp)
ADD_QGIS_TEST(maptoolellipsetest testqgsmaptoolellipse.cpp)
ADD_QGIS_TEST(maptoolrectangletest testqgsmaptoolrectangle.cpp)
ADD_QGIS_TEST(maptoolregularpolygontest testqgsmaptoolregularpolygon.cpp)
ADD_QGIS_TEST(maptoolsplitpartstest testqgsmaptoolsplitparts.cpp)
ADD_QGIS_TEST(maptoolsplitfeaturestest testqgsmaptoolsplitfeatures.cpp)
ADD_QGIS_TEST(measuretool testqgsmeasuretool.cpp)
ADD_QGIS_TEST(measurebearingtool testqgsmeasurebearingtool.cpp)
ADD_QGIS_TEST(vertextool testqgsvertextool.cpp)
ADD_QGIS_TEST(vectorlayersaveasdialogtest testqgsvectorlayersaveasdialog.cpp)
ADD_QGIS_TEST(maptoolreverselinetest testqgsmaptoolreverseline.cpp)
ADD_QGIS_TEST(maptooltrimextendfeaturetest testqgsmaptooltrimextendfeature.cpp)
ADD_QGIS_TEST(projectproperties testqgsprojectproperties.cpp)
ADD_QGIS_TEST(layoutvaliditychecks testqgsapplayoutvaliditychecks.cpp)
ADD_QGIS_TEST(meshcalculator testqgsmeshcalculatordialog.cpp)
ADD_QGIS_TEST(gpsinformationwidget testqgsgpsinformationwidget.cpp)
ADD_QGIS_TEST(labelpropertydialog testqgslabelpropertydialog.cpp)

foreach(TESTSRC ${TESTS})
add_qgis_test(${TESTSRC} MODULE app LINKEDLIBRARIES qgis_app)
endforeach(TESTSRC)

add_subdirectory(maptooladdfeaturepoint)
add_subdirectory(maptooladdfeatureline)
@@ -10,42 +10,6 @@ include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)

#note for tests we should not include the moc of our
#qtests in the executable file list as the moc is
#directly included in the sources
#and should not be compiled twice. Trying to include
#them in will cause an error at build time

#No relinking and full RPATH for the install tree
#See: http://www.cmake.org/Wiki/CMake_RPATH_handling#No_relinking_and_full_RPATH_for_the_install_tree

macro (ADD_QGIS_TEST TESTSRC)
set (TESTNAME ${TESTSRC})
string(REPLACE "test" "" TESTNAME ${TESTNAME})
string(REPLACE "qgs" "qgis_" TESTNAME ${TESTNAME})
string(REPLACE ".cpp" "" TESTNAME ${TESTNAME})
add_executable(${TESTNAME} ${TESTSRC} ${util_SRCS})
target_compile_features(${TESTNAME} PRIVATE cxx_std_17)
target_link_libraries(${TESTNAME}
${Qt5Core_LIBRARIES}
${Qt5Xml_LIBRARIES}
${Qt5Sql_LIBRARIES}
${Qt5Svg_LIBRARIES}
${Qt5Test_LIBRARIES}
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
${QWT_LIBRARY}
qgis_core
qgis_gui
qgis_analysis
qgis_app)
add_test(${TESTNAME} ${CMAKE_BINARY_DIR}/output/bin/${TESTNAME} -maxwarnings 10000)
#set_target_properties(qgis_${testname} PROPERTIES
# INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${QGIS_LIB_DIR}
# INSTALL_RPATH_USE_LINK_PATH true )
endmacro (ADD_QGIS_TEST)

#############################################################
# Tests:

@@ -57,5 +21,5 @@ set(TESTS
)

foreach(TESTSRC ${TESTS})
ADD_QGIS_TEST(${TESTSRC})
add_qgis_test(${TESTSRC} MODULE app LINKEDLIBRARIES qgis_app)
endforeach(TESTSRC)
Loading

0 comments on commit 38d89fc

Please sign in to comment.