CMake: Add BUILTIN_TESTDATA option to qt_internal_add_test

Multiple tests use qt_internal_add_resource that copies the
functionality that is already implemented inside the
qt_internal_add_test function. Simplify these test by replacing
the qt_internal_add_resource call with the new BUILTIN_TESTDATA
option.

Change-Id: I18475b817d6f87264f0de53817d6c26c5ccab4e2
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2022-02-09 16:24:24 +01:00
parent 52492ff720
commit fdf5d11ff6
22 changed files with 207 additions and 316 deletions

View File

@ -181,12 +181,39 @@ endfunction()
# You may avoid test wrapping by either passing NO_WRAPPER option or switching QT_NO_TEST_WRAPPERS
# to ON. This is helpful if you want to use internal CMake tools within tests, like memory or
# sanitizer checks. See https://cmake.org/cmake/help/v3.19/manual/ctest.1.html#ctest-memcheck-step
# Arguments:
# BUILTIN_TESTDATA the option forces adding the provded TESTDATA to resources.
function(qt_internal_add_test name)
# EXCEPTIONS is a noop as they are enabled by default.
set(optional_args
RUN_SERIAL
EXCEPTIONS
NO_EXCEPTIONS
GUI
QMLTEST
CATCH
LOWDPI
NO_WRAPPER
BUILTIN_TESTDATA
)
set(single_value_args
OUTPUT_DIRECTORY
WORKING_DIRECTORY
TIMEOUT
VERSION
)
set(multi_value_args
QML_IMPORTPATH
TESTDATA
QT_TEST_SERVER_LIST
${__default_private_args}
${__default_public_args}
)
qt_parse_all_arguments(arg "qt_add_test"
"RUN_SERIAL;EXCEPTIONS;NO_EXCEPTIONS;GUI;QMLTEST;CATCH;LOWDPI;NO_WRAPPER"
"OUTPUT_DIRECTORY;WORKING_DIRECTORY;TIMEOUT;VERSION"
"QML_IMPORTPATH;TESTDATA;QT_TEST_SERVER_LIST;${__default_private_args};${__default_public_args}" ${ARGN}
"${optional_args}"
"${single_value_args}"
"${multi_value_args}"
${ARGN}
)
if (NOT arg_OUTPUT_DIRECTORY)
@ -364,7 +391,7 @@ function(qt_internal_add_test name)
endif()
endif()
if(ANDROID OR IOS OR INTEGRITY)
if(ANDROID OR IOS OR INTEGRITY OR arg_BUILTIN_TESTDATA)
set(builtin_testdata TRUE)
endif()

View File

@ -4,13 +4,6 @@
## tst_qfileselectors Test:
#####################################################################
qt_internal_add_test(tst_qfileselectors
SOURCES
tst_qfileselector.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
)
# Resources:
set(qfileselector_resource_files
"extras/+custom1/test"
@ -62,10 +55,12 @@ set(qfileselector_resource_files
"platforms/test5"
)
qt_internal_add_resource(tst_qfileselectors "qfileselector"
PREFIX
"/"
FILES
${qfileselector_resource_files}
qt_internal_add_test(tst_qfileselectors
SOURCES
tst_qfileselector.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
TESTDATA ${qfileselector_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,19 +4,7 @@
## tst_qsettings Test:
#####################################################################
qt_internal_add_test(tst_qsettings
SOURCES
tst_qsettings.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES
../../kernel/qmetatype
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
)
# Resources:
# Test:
set(qsettings_resource_files
"bom.ini"
"resourcefile.ini"
@ -29,11 +17,18 @@ set(qsettings_resource_files
"float.ini"
)
qt_internal_add_resource(tst_qsettings "qsettings"
PREFIX
"/"
FILES
${qsettings_resource_files}
qt_internal_add_test(tst_qsettings
SOURCES
tst_qsettings.cpp
DEFINES
QT_DISABLE_DEPRECATED_BEFORE=0
INCLUDE_DIRECTORIES
../../kernel/qmetatype
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
TESTDATA ${qsettings_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,6 +4,12 @@
## tst_qvariant Test:
#####################################################################
# Resources:
set(qvariant_resource_files
"stream/qt4.9/"
"stream/qt5.0/"
)
qt_internal_add_test(tst_qvariant
SOURCES
tst_qvariant.cpp
@ -14,22 +20,10 @@ qt_internal_add_test(tst_qvariant
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
TESTDATA ${qvariant_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qvariant_resource_files
"stream/qt4.9/"
"stream/qt5.0/"
)
qt_internal_add_resource(tst_qvariant "qvariant"
PREFIX
"/"
FILES
${qvariant_resource_files}
)
## Scopes:
#####################################################################

View File

@ -22,7 +22,9 @@ add_subdirectory(qpalette)
add_subdirectory(qscreen)
add_subdirectory(qsurfaceformat)
add_subdirectory(qwindow)
add_subdirectory(qguiapplication)
if(QT_FEATURE_private_tests)
add_subdirectory(qguiapplication)
endif()
add_subdirectory(qpixelformat)
add_subdirectory(qrasterwindow)
add_subdirectory(qaddpostroutine)

View File

@ -1,9 +1,5 @@
# Generated from qguiapplication.pro.
if(NOT QT_FEATURE_private_tests)
return()
endif()
#####################################################################
## tst_qguiapplication Test:
#####################################################################
@ -16,6 +12,12 @@ else()
endif()
# special case end
# Resources:
set(tst_qguiapplication_resource_files
"icons/appicon.png"
"icons/usericon.png"
)
qt_internal_add_test(tst_qguiapplication
VERSION ${target_version} # special case
SOURCES
@ -28,19 +30,8 @@ qt_internal_add_test(tst_qguiapplication
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::GuiPrivate
)
# Resources:
set(tst_qguiapplication_resource_files
"icons/appicon.png"
"icons/usericon.png"
)
qt_internal_add_resource(tst_qguiapplication "tst_qguiapplication"
PREFIX
"/"
FILES
${tst_qguiapplication_resource_files}
TESTDATA ${tst_qguiapplication_resource_files}
BUILTIN_TESTDATA
)
# special case begin
@ -49,12 +40,3 @@ if (APPLE)
set_property(TARGET tst_qguiapplication PROPERTY PROPERTY MACOSX_BUNDLE TRUE)
endif()
# special case end
## Scopes:
#####################################################################
#### Keys ignored in scope 3:.:../../../corelib/kernel/qcoreapplication:../../../corelib/kernel/qcoreapplication/qcoreapplication.pro:WIN32:
# VERSION = "1.2.3.4"
#### Keys ignored in scope 4:.:../../../corelib/kernel/qcoreapplication:../../../corelib/kernel/qcoreapplication/qcoreapplication.pro:else:
# VERSION = "1.2.3"

View File

@ -4,6 +4,12 @@
## tst_qguivariant Test:
#####################################################################
# Resources:
file(GLOB_RECURSE qguivariant_resource_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"data/*"
)
qt_internal_add_test(tst_qguivariant
SOURCES
tst_qguivariant.cpp
@ -11,17 +17,6 @@ qt_internal_add_test(tst_qguivariant
../../../../other/qvariant_common
PUBLIC_LIBRARIES
Qt::Gui
TESTDATA ${qguivariant_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qguivariant_resource_files
"data"
)
qt_internal_add_resource(tst_qguivariant "qguivariant"
PREFIX
"/"
FILES
${qguivariant_resource_files}
)

View File

@ -4,6 +4,12 @@
## tst_qkeysequence Test:
#####################################################################
# Resources:
set(qkeysequence_resource_files
"keys_de.qm"
"qt_de.qm"
)
qt_internal_add_test(tst_qkeysequence
SOURCES
tst_qkeysequence.cpp
@ -11,18 +17,6 @@ qt_internal_add_test(tst_qkeysequence
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
TESTDATA ${qkeysequence_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qkeysequence_resource_files
"keys_de.qm"
"qt_de.qm"
)
qt_internal_add_resource(tst_qkeysequence "qkeysequence"
PREFIX
"/"
FILES
${qkeysequence_resource_files}
)

View File

@ -5,10 +5,14 @@
#####################################################################
# Collect test data
file(GLOB_RECURSE test_data_glob
file(GLOB_RECURSE test_data
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
resources/*)
list(APPEND test_data ${test_data_glob})
resources/*
)
foreach(file IN LISTS test_data)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}")
endforeach()
qt_internal_add_test(tst_qcolorspace
SOURCES
@ -18,22 +22,5 @@ qt_internal_add_test(tst_qcolorspace
Qt::Gui
Qt::GuiPrivate
TESTDATA ${test_data}
BUILTIN_TESTDATA
)
file(GLOB resource_glob_0 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "resources/*")
foreach(file IN LISTS resource_glob_0)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}")
endforeach()
# Resources:
set(qmake_immediate_resource_files
${resource_glob_0}
)
qt_internal_add_resource(tst_qcolorspace "qmake_immediate"
PREFIX
"/"
FILES
${qmake_immediate_resource_files}
)

View File

@ -4,23 +4,18 @@
## tst_qrhi Test:
#####################################################################
# Resources:
file(GLOB_RECURSE qrhi_resource_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
data/*
)
qt_internal_add_test(tst_qrhi
SOURCES
tst_qrhi.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::GuiPrivate
TESTDATA ${qrhi_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qrhi_resource_files
"data"
)
qt_internal_add_resource(tst_qrhi "qrhi"
PREFIX
"/"
FILES
${qrhi_resource_files}
)

View File

@ -4,23 +4,18 @@
## tst_qshader Test:
#####################################################################
# Resources:
file(GLOB_RECURSE qshader_resource_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
"data/*"
)
qt_internal_add_test(tst_qshader
SOURCES
tst_qshader.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::GuiPrivate
TESTDATA ${qshader_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qshader_resource_files
"data"
)
qt_internal_add_resource(tst_qshader "qshader"
PREFIX
"/"
FILES
${qshader_resource_files}
)

View File

@ -4,6 +4,12 @@
## tst_qfont Test:
#####################################################################
# Resources:
set(testfont_resource_files
"datastream.515"
"weirdfont.otf"
)
qt_internal_add_test(tst_qfont
SOURCES
tst_qfont.cpp
@ -12,22 +18,10 @@ qt_internal_add_test(tst_qfont
Qt::Gui
Qt::GuiPrivate
Qt::TestPrivate
TESTDATA ${testfont_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(testfont_resource_files
"datastream.515"
"weirdfont.otf"
)
qt_internal_add_resource(tst_qfont "testfont"
PREFIX
"/"
FILES
${testfont_resource_files}
)
## Scopes:
#####################################################################

View File

@ -4,13 +4,6 @@
## tst_qglyphrun Test:
#####################################################################
qt_internal_add_test(tst_qglyphrun
SOURCES
tst_qglyphrun.cpp
PUBLIC_LIBRARIES
Qt::Gui
)
# Resources:
set_source_files_properties("../../../shared/resources/test.ttf"
PROPERTIES QT_RESOURCE_ALIAS "test.ttf"
@ -19,10 +12,12 @@ set(testdata_resource_files
"../../../shared/resources/test.ttf"
)
qt_internal_add_resource(tst_qglyphrun "testdata"
PREFIX
"/"
FILES
${testdata_resource_files}
qt_internal_add_test(tst_qglyphrun
SOURCES
tst_qglyphrun.cpp
PUBLIC_LIBRARIES
Qt::Gui
TESTDATA ${testdata_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,15 +4,6 @@
## tst_qrawfont Test:
#####################################################################
qt_internal_add_test(tst_qrawfont
SOURCES
tst_qrawfont.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
)
# Resources:
set_source_files_properties("../../../shared/resources/testfont.ttf"
PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf"
@ -23,10 +14,14 @@ set(testdata_resource_files
"testfont_os2_v1.ttf"
)
qt_internal_add_resource(tst_qrawfont "testdata"
PREFIX
"/"
FILES
${testdata_resource_files}
qt_internal_add_test(tst_qrawfont
SOURCES
tst_qrawfont.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
TESTDATA ${testdata_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,14 +4,6 @@
## tst_qtexturefilereader Test:
#####################################################################
qt_internal_add_test(tst_qtexturefilereader
SOURCES
tst_qtexturefilereader.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
# Resources:
set(qtexturefilereader_resource_files
"texturefiles/car.ktx"
@ -23,10 +15,13 @@ set(qtexturefilereader_resource_files
"texturefiles/pattern.pkm"
)
qt_internal_add_resource(tst_qtexturefilereader "qtexturefilereader"
PREFIX
"/"
FILES
${qtexturefilereader_resource_files}
qt_internal_add_test(tst_qtexturefilereader
SOURCES
tst_qtexturefilereader.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::GuiPrivate
TESTDATA ${qtexturefilereader_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,6 +4,13 @@ include(../../../../src/testlib/selfcover.cmake)
# ------------- Test runner -------------
# Resources:
file(GLOB qmake_expected_files_resource_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "expected_*")
foreach(file IN LISTS qmake_expected_files_resource_files)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}")
endforeach()
qt_internal_add_test(tst_selftests
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
EXCEPTIONS
@ -13,6 +20,8 @@ qt_internal_add_test(tst_selftests
catch.cpp
PUBLIC_LIBRARIES
Qt::TestPrivate
TESTDATA ${qmake_expected_files_resource_files}
BUILTIN_TESTDATA
# These lines need to be commented out as they need to be enabled
# COMPILE_OPTIONS
# conditionally
@ -24,25 +33,6 @@ qt_internal_add_test(tst_selftests
# "$$COVERAGE_OPTIONS"
)
file(GLOB resource_glob_0 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "expected_*")
foreach(file IN LISTS resource_glob_0)
set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${file}" PROPERTIES QT_RESOURCE_ALIAS "${file}")
endforeach()
# Resources:
set(qmake_expected_files_resource_files
${resource_glob_0}
)
qt_internal_add_resource(tst_selftests "qmake_expected_files"
PREFIX
"/"
BASE
"${CMAKE_CURRENT_SOURCE_DIR}"
FILES
${qmake_expected_files_resource_files}
)
qt_internal_apply_testlib_coverage_options(tst_selftests)
# ------------- Sub tests -------------

View File

@ -4,17 +4,6 @@
## tst_qfontdialog Test:
#####################################################################
qt_internal_add_test(tst_qfontdialog
SOURCES
tst_qfontdialog.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
Qt::WidgetsPrivate
)
# Resources:
set_source_files_properties("../../../shared/resources/test.ttf"
PROPERTIES QT_RESOURCE_ALIAS "test.ttf"
@ -27,13 +16,18 @@ set(testfonts_resource_files
"../../../shared/resources/testfont.ttf"
)
qt_internal_add_resource(tst_qfontdialog "testfonts"
PREFIX
"/"
FILES
${testfonts_resource_files}
qt_internal_add_test(tst_qfontdialog
SOURCES
tst_qfontdialog.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
Qt::WidgetsPrivate
TESTDATA ${testfonts_resource_files}
BUILTIN_TESTDATA
)
## Scopes:
#####################################################################

View File

@ -4,15 +4,6 @@
## tst_qwizard Test:
#####################################################################
qt_internal_add_test(tst_qwizard
SOURCES
tst_qwizard.cpp
tst_qwizard_2.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::Widgets
)
# Resources:
set(qwizard_resource_files
"images/background.png"
@ -21,10 +12,14 @@ set(qwizard_resource_files
"images/watermark.png"
)
qt_internal_add_resource(tst_qwizard "qwizard"
PREFIX
"/"
FILES
${qwizard_resource_files}
qt_internal_add_test(tst_qwizard
SOURCES
tst_qwizard.cpp
tst_qwizard_2.cpp
PUBLIC_LIBRARIES
Qt::Gui
Qt::Widgets
TESTDATA ${qwizard_resource_files}
BUILTIN_TESTDATA
)

View File

@ -4,32 +4,10 @@
## tst_qgraphicsscene Test:
#####################################################################
qt_internal_add_test(tst_qgraphicsscene
LOWDPI # special case
SOURCES
tst_qgraphicsscene.cpp
DEFINES
QT_NO_CAST_TO_ASCII
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
Qt::WidgetsPrivate
)
# Resources:
set(images_resource_files
"Ash_European.jpg"
)
qt_internal_add_resource(tst_qgraphicsscene "images"
PREFIX
"/"
FILES
${images_resource_files}
)
set(testdata_resource_files
"Ash_European.jpg"
"testData/render/all-all-45-deg-left.png"
"testData/render/all-all-45-deg-right.png"
"testData/render/all-all-scale-2x.png"
@ -60,14 +38,22 @@ set(testdata_resource_files
"testData/render/topright-topleft-untransformed.png"
)
qt_internal_add_resource(tst_qgraphicsscene "testdata"
PREFIX
"/"
FILES
${testdata_resource_files}
qt_internal_add_test(tst_qgraphicsscene
LOWDPI # special case
SOURCES
tst_qgraphicsscene.cpp
DEFINES
QT_NO_CAST_TO_ASCII
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
Qt::WidgetsPrivate
TESTDATA ${testdata_resource_files}
BUILTIN_TESTDATA
)
## Scopes:
#####################################################################

View File

@ -4,6 +4,14 @@
## tst_qwidget Test:
#####################################################################
# Resources:
set(qwidget_resource_files
"geometry-fullscreen.dat"
"geometry-maximized.dat"
"geometry.dat"
"hellotr_la.qm"
)
qt_internal_add_test(tst_qwidget
SOURCES
tst_qwidget.cpp
@ -14,24 +22,10 @@ qt_internal_add_test(tst_qwidget
Qt::TestPrivate
Qt::Widgets
Qt::WidgetsPrivate
TESTDATA ${qwidget_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(qwidget_resource_files
"geometry-fullscreen.dat"
"geometry-maximized.dat"
"geometry.dat"
"hellotr_la.qm"
)
qt_internal_add_resource(tst_qwidget "qwidget"
PREFIX
"/"
FILES
${qwidget_resource_files}
)
#### Keys ignored in scope 1:.:.:qwidget.pro:<TRUE>:
# testcase.timeout = "600"

View File

@ -3,7 +3,9 @@
if(APPLE)
add_subdirectory(qmacstyle)
endif()
add_subdirectory(qstyle)
if(QT_FEATURE_private_tests)
add_subdirectory(qstyle)
endif()
add_subdirectory(qstyleoption)
if(QT_FEATURE_private_tests AND NOT ANDROID AND NOT QNX AND NOT UIKIT)
add_subdirectory(qstylesheetstyle)

View File

@ -1,13 +1,15 @@
# Generated from qstylesheetstyle.pro.
if(NOT QT_FEATURE_private_tests)
return()
endif()
#####################################################################
## tst_qstylesheetstyle Test:
#####################################################################
# Resources:
set(resources_resource_files
"images/testimage.png"
"images/testimage@2x.png"
)
qt_internal_add_test(tst_qstylesheetstyle
SOURCES
tst_qstylesheetstyle.cpp
@ -17,21 +19,9 @@ qt_internal_add_test(tst_qstylesheetstyle
Qt::TestPrivate
Qt::Widgets
Qt::WidgetsPrivate
TESTDATA ${resources_resource_files}
BUILTIN_TESTDATA
)
# Resources:
set(resources_resource_files
"images/testimage.png"
"images/testimage@2x.png"
)
qt_internal_add_resource(tst_qstylesheetstyle "resources"
PREFIX
"/"
FILES
${resources_resource_files}
)
#### Keys ignored in scope 1:.:.:qstylesheetstyle.pro:<TRUE>:
# _REQUIREMENTS = "qtConfig(private_tests)"