summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/CMakeLists.txt3
-rw-r--r--tests/auto/gui/image/CMakeLists.txt12
-rw-r--r--tests/auto/gui/image/qicoimageformat/CMakeLists.txt40
-rw-r--r--tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.icobin0 -> 12862 bytes
-rw-r--r--tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.pngbin0 -> 3911 bytes
-rw-r--r--tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.icobin0 -> 16958 bytes
-rw-r--r--tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.pngbin0 -> 5536 bytes
-rw-r--r--tests/auto/gui/image/qicoimageformat/qicoimageformat.qrc18
-rw-r--r--tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp58
-rw-r--r--tests/auto/gui/image/qicon/CMakeLists.txt17
-rw-r--r--tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.pngbin0 -> 267 bytes
-rw-r--r--tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme8
-rw-r--r--tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.pngbin0 -> 267 bytes
-rw-r--r--tests/auto/gui/image/qicon/icons/hicolor/index.theme11
-rw-r--r--tests/auto/gui/image/qicon/icons/testtheme/index.theme2
-rw-r--r--tests/auto/gui/image/qicon/icons/themeparent/index.theme1
-rw-r--r--tests/auto/gui/image/qicon/tst_qicon.cpp84
-rw-r--r--tests/auto/gui/image/qicon/tst_qicon.qrc31
-rw-r--r--tests/auto/gui/image/qiconhighdpi/CMakeLists.txt11
-rw-r--r--tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp47
-rw-r--r--tests/auto/gui/image/qimage/CMakeLists.txt49
-rw-r--r--tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.iccbin0 -> 8464 bytes
-rw-r--r--tests/auto/gui/image/qimage/qimage.qrc22
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp313
-rw-r--r--tests/auto/gui/image/qimageiohandler/CMakeLists.txt11
-rw-r--r--tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp29
-rw-r--r--tests/auto/gui/image/qimagereader/BLACKLIST8
-rw-r--r--tests/auto/gui/image/qimagereader/CMakeLists.txt32
-rw-r--r--tests/auto/gui/image/qimagereader/images/image.pbm10
-rw-r--r--tests/auto/gui/image/qimagereader/tst_qimagereader.cpp352
-rw-r--r--tests/auto/gui/image/qimagewriter/CMakeLists.txt41
-rw-r--r--tests/auto/gui/image/qimagewriter/qimagewriter.qrc16
-rw-r--r--tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp33
-rw-r--r--tests/auto/gui/image/qmovie/CMakeLists.txt22
-rw-r--r--tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.icobin0 -> 25214 bytes
-rw-r--r--tests/auto/gui/image/qmovie/tst_qmovie.cpp113
-rw-r--r--tests/auto/gui/image/qpicture/CMakeLists.txt11
-rw-r--r--tests/auto/gui/image/qpicture/tst_qpicture.cpp29
-rw-r--r--tests/auto/gui/image/qpixmap/CMakeLists.txt15
-rw-r--r--tests/auto/gui/image/qpixmap/qpixmap.qrc51
-rw-r--r--tests/auto/gui/image/qpixmap/tst_qpixmap.cpp33
-rw-r--r--tests/auto/gui/image/qpixmapcache/CMakeLists.txt11
-rw-r--r--tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp192
-rw-r--r--tests/auto/gui/itemmodels/CMakeLists.txt3
-rw-r--r--tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST3
-rw-r--r--tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt20
-rw-r--r--tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp221
-rw-r--r--tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt11
-rw-r--r--tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp79
-rw-r--r--tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt12
-rw-r--r--tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp268
-rw-r--r--tests/auto/gui/kernel/CMakeLists.txt17
-rw-r--r--tests/auto/gui/kernel/noqteventloop/CMakeLists.txt13
-rw-r--r--tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp32
-rw-r--r--tests/auto/gui/kernel/qaction/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qaction/tst_qaction.cpp91
-rw-r--r--tests/auto/gui/kernel/qactiongroup/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp29
-rw-r--r--tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp29
-rw-r--r--tests/auto/gui/kernel/qbackingstore/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp323
-rw-r--r--tests/auto/gui/kernel/qclipboard/CMakeLists.txt9
-rw-r--r--tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt15
-rw-r--r--tests/auto/gui/kernel/qclipboard/copier/main.cpp29
-rw-r--r--tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt15
-rw-r--r--tests/auto/gui/kernel/qclipboard/paster/main.cpp29
-rw-r--r--tests/auto/gui/kernel/qclipboard/test/BLACKLIST5
-rw-r--r--tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt8
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp111
-rw-r--r--tests/auto/gui/kernel/qcursor/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qcursor/tst_qcursor.cpp29
-rw-r--r--tests/auto/gui/kernel/qdrag/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qdrag/tst_qdrag.cpp29
-rw-r--r--tests/auto/gui/kernel/qevent/CMakeLists.txt12
-rw-r--r--tests/auto/gui/kernel/qevent/tst_qevent.cpp107
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt9
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt8
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp33
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt5
-rw-r--r--tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp49
-rw-r--r--tests/auto/gui/kernel/qguiapplication/BLACKLIST5
-rw-r--r--tests/auto/gui/kernel/qguiapplication/CMakeLists.txt58
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp216
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc6
-rw-r--r--tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt38
-rw-r--r--tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt40
-rw-r--r--tests/auto/gui/kernel/qguieventloop/CMakeLists.txt13
-rw-r--r--tests/auto/gui/kernel/qguimetatype/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp103
-rw-r--r--tests/auto/gui/kernel/qguitimer/CMakeLists.txt39
-rw-r--r--tests/auto/gui/kernel/qguivariant/CMakeLists.txt3
-rw-r--r--tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt13
-rw-r--r--tests/auto/gui/kernel/qguivariant/no_application/main.cpp29
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt32
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc5
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp31
-rw-r--r--tests/auto/gui/kernel/qhighdpi/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp268
-rw-r--r--tests/auto/gui/kernel/qinputdevice/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp81
-rw-r--r--tests/auto/gui/kernel/qinputmethod/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp43
-rw-r--r--tests/auto/gui/kernel/qkeyevent/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp31
-rw-r--r--tests/auto/gui/kernel/qkeysequence/CMakeLists.txt31
-rw-r--r--tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc6
-rw-r--r--tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp38
-rw-r--r--tests/auto/gui/kernel/qmouseevent/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp55
-rw-r--r--tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp29
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp32
-rw-r--r--tests/auto/gui/kernel/qpalette/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qpalette/tst_qpalette.cpp183
-rw-r--r--tests/auto/gui/kernel/qpixelformat/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp29
-rw-r--r--tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp31
-rw-r--r--tests/auto/gui/kernel/qscreen/BLACKLIST4
-rw-r--r--tests/auto/gui/kernel/qscreen/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qscreen/tst_qscreen.cpp74
-rw-r--r--tests/auto/gui/kernel/qshortcut/CMakeLists.txt12
-rw-r--r--tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp92
-rw-r--r--tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp29
-rw-r--r--tests/auto/gui/kernel/qtouchevent/BLACKLIST6
-rw-r--r--tests/auto/gui/kernel/qtouchevent/CMakeLists.txt11
-rw-r--r--tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp465
-rw-r--r--tests/auto/gui/kernel/qwindow/BLACKLIST14
-rw-r--r--tests/auto/gui/kernel/qwindow/CMakeLists.txt35
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp142
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp671
-rw-r--r--tests/auto/gui/math3d/CMakeLists.txt3
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt13
-rw-r--r--tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp204
-rw-r--r--tests/auto/gui/math3d/qquaternion/CMakeLists.txt11
-rw-r--r--tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp94
-rw-r--r--tests/auto/gui/math3d/qvectornd/CMakeLists.txt11
-rw-r--r--tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp62
-rw-r--r--tests/auto/gui/painting/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qbrush/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qbrush/tst_qbrush.cpp29
-rw-r--r--tests/auto/gui/painting/qcolor/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qcolor/tst_qcolor.cpp106
-rw-r--r--tests/auto/gui/painting/qcolorspace/CMakeLists.txt40
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.iccbin0 -> 8464 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/VideoHD.iccbin0 -> 786 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.iccbin0 -> 360 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.iccbin0 -> 63868 bytes
-rw-r--r--tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp388
-rw-r--r--tests/auto/gui/painting/qcolortransform/CMakeLists.txt20
-rw-r--r--tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp380
-rw-r--r--tests/auto/gui/painting/qpagelayout/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp151
-rw-r--r--tests/auto/gui/painting/qpageranges/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp33
-rw-r--r--tests/auto/gui/painting/qpagesize/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp31
-rw-r--r--tests/auto/gui/painting/qpaintengine/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp29
-rw-r--r--tests/auto/gui/painting/qpainter/CMakeLists.txt208
-rw-r--r--tests/auto/gui/painting/qpainter/testdata.qrc186
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp298
-rw-r--r--tests/auto/gui/painting/qpainter/utils/createImages/main.cpp29
-rw-r--r--tests/auto/gui/painting/qpainterpath/BLACKLIST2
-rw-r--r--tests/auto/gui/painting/qpainterpath/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp127
-rw-r--r--tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp29
-rw-r--r--tests/auto/gui/painting/qpathclipper/CMakeLists.txt16
-rw-r--r--tests/auto/gui/painting/qpathclipper/pathcompare.h29
-rw-r--r--tests/auto/gui/painting/qpathclipper/paths.cpp29
-rw-r--r--tests/auto/gui/painting/qpathclipper/paths.h29
-rw-r--r--tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp57
-rw-r--r--tests/auto/gui/painting/qpdfwriter/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp29
-rw-r--r--tests/auto/gui/painting/qpen/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qpen/tst_qpen.cpp29
-rw-r--r--tests/auto/gui/painting/qpolygon/CMakeLists.txt13
-rw-r--r--tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp45
-rw-r--r--tests/auto/gui/painting/qregion/CMakeLists.txt11
-rw-r--r--tests/auto/gui/painting/qregion/tst_qregion.cpp29
-rw-r--r--tests/auto/gui/painting/qtransform/CMakeLists.txt13
-rw-r--r--tests/auto/gui/painting/qtransform/tst_qtransform.cpp29
-rw-r--r--tests/auto/gui/platform/CMakeLists.txt3
-rw-r--r--tests/auto/gui/platform/qx11info/CMakeLists.txt11
-rw-r--r--tests/auto/gui/platform/qx11info/tst_qx11info.cpp41
-rw-r--r--tests/auto/gui/qopengl/CMakeLists.txt11
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp54
-rw-r--r--tests/auto/gui/qopenglconfig/CMakeLists.txt11
-rw-r--r--tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp29
-rw-r--r--tests/auto/gui/qvulkan/CMakeLists.txt11
-rw-r--r--tests/auto/gui/qvulkan/tst_qvulkan.cpp58
-rw-r--r--tests/auto/gui/rhi/CMakeLists.txt3
-rw-r--r--tests/auto/gui/rhi/qrhi/BLACKLIST12
-rw-r--r--tests/auto/gui/rhi/qrhi/CMakeLists.txt32
-rw-r--r--tests/auto/gui/rhi/qrhi/data/buildshaders.bat56
-rw-r--r--tests/auto/gui/rhi/qrhi/data/half.vert10
-rw-r--r--tests/auto/gui/rhi/qrhi/data/half.vert.qsbbin0 -> 815 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/multiview.frag10
-rw-r--r--tests/auto/gui/rhi/qrhi/data/multiview.frag.qsbbin0 -> 2425 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/multiview.vert18
-rw-r--r--tests/auto/gui/rhi/qrhi/data/multiview.vert.qsbbin0 -> 3644 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.frag10
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsbbin0 -> 591 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.tesc22
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsbbin0 -> 1402 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.tese17
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsbbin0 -> 1401 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.vert12
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsbbin0 -> 936 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag14
-rw-r--r--tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag.qsbbin0 -> 1258 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer.comp28
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsbbin0 -> 1262 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp25
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsbbin0 -> 1415 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag33
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsbbin0 -> 1259 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc42
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsbbin0 -> 2024 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese39
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsbbin0 -> 1854 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert48
-rw-r--r--tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsbbin0 -> 2047 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsbbin0 -> 590 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc56
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsbbin0 -> 2873 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese96
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsbbin0 -> 4526 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert20
-rw-r--r--tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsbbin0 -> 1306 bytes
-rw-r--r--tests/auto/gui/rhi/qrhi/qrhi.qrc5
-rw-r--r--tests/auto/gui/rhi/qrhi/tst_qrhi.cpp3258
-rw-r--r--tests/auto/gui/rhi/qshader/CMakeLists.txt32
-rw-r--r--tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsbbin0 -> 729 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsbbin0 -> 1749 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsbbin0 -> 2390 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsbbin0 -> 1106 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsbbin0 -> 902 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data/texture_sep_v6.frag.qsbbin0 -> 1265 bytes
-rw-r--r--tests/auto/gui/rhi/qshader/data_src/color.vert (renamed from tests/auto/gui/rhi/qshader/data/color.vert)0
-rw-r--r--tests/auto/gui/rhi/qshader/data_src/texture.frag (renamed from tests/auto/gui/rhi/qshader/data/texture.frag)0
-rw-r--r--tests/auto/gui/rhi/qshader/data_src/texture_sep.frag17
-rw-r--r--tests/auto/gui/rhi/qshader/qshader.qrc5
-rw-r--r--tests/auto/gui/rhi/qshader/tst_qshader.cpp300
-rw-r--r--tests/auto/gui/text/CMakeLists.txt10
-rw-r--r--tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp35
-rw-r--r--tests/auto/gui/text/qcssparser/CMakeLists.txt53
-rw-r--r--tests/auto/gui/text/qcssparser/testdata.qrc18
-rw-r--r--tests/auto/gui/text/qcssparser/tst_qcssparser.cpp187
-rw-r--r--tests/auto/gui/text/qfont/BLACKLIST2
-rw-r--r--tests/auto/gui/text/qfont/CMakeLists.txt34
-rw-r--r--tests/auto/gui/text/qfont/datastream.515bin0 -> 121 bytes
-rw-r--r--tests/auto/gui/text/qfont/testfont.qrc5
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp172
-rw-r--r--tests/auto/gui/text/qfontcache/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qfontcache/tst_qfontcache.cpp29
-rw-r--r--tests/auto/gui/text/qfontdatabase/BLACKLIST7
-rw-r--r--tests/auto/gui/text/qfontdatabase/CMakeLists.txt15
-rw-r--r--tests/auto/gui/text/qfontdatabase/testdata.qrc9
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp139
-rw-r--r--tests/auto/gui/text/qfontmetrics/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qfontmetrics/testfont.qrc6
-rw-r--r--tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp70
-rw-r--r--tests/auto/gui/text/qglyphrun/BLACKLIST3
-rw-r--r--tests/auto/gui/text/qglyphrun/CMakeLists.txt27
-rw-r--r--tests/auto/gui/text/qglyphrun/Ligatures.otfbin0 -> 24624 bytes
-rw-r--r--tests/auto/gui/text/qglyphrun/testdata.qrc5
-rw-r--r--tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp405
-rw-r--r--tests/auto/gui/text/qinputcontrol/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp29
-rw-r--r--tests/auto/gui/text/qrawfont/BLACKLIST2
-rw-r--r--tests/auto/gui/text/qrawfont/CMakeLists.txt30
-rw-r--r--tests/auto/gui/text/qrawfont/testdata.qrc7
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp53
-rw-r--r--tests/auto/gui/text/qstatictext/CMakeLists.txt15
-rw-r--r--tests/auto/gui/text/qstatictext/tst_qstatictext.cpp93
-rw-r--r--tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt13
-rw-r--r--tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp37
-rw-r--r--tests/auto/gui/text/qtextblock/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextblock/tst_qtextblock.cpp29
-rw-r--r--tests/auto/gui/text/qtextcursor/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp280
-rw-r--r--tests/auto/gui/text/qtextdocument/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextdocument/common.h29
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp496
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp89
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/BLACKLIST3
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt13
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp66
-rw-r--r--tests/auto/gui/text/qtextformat/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextformat/tst_qtextformat.cpp59
-rw-r--r--tests/auto/gui/text/qtextimagehandler/CMakeLists.txt29
-rw-r--r--tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp60
-rw-r--r--tests/auto/gui/text/qtextlayout/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp200
-rw-r--r--tests/auto/gui/text/qtextlist/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextlist/tst_qtextlist.cpp87
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST3
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt19
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md9
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md1
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md6
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md11
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp395
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST2
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt17
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md10
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md14
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/example.md2
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/links.md3
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md6
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md9
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md11
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp658
-rw-r--r--tests/auto/gui/text/qtextobject/CMakeLists.txt13
-rw-r--r--tests/auto/gui/text/qtextobject/tst_qtextobject.cpp29
-rw-r--r--tests/auto/gui/text/qtextodfwriter/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp33
-rw-r--r--tests/auto/gui/text/qtextpiecetable/CMakeLists.txt14
-rw-r--r--tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp185
-rw-r--r--tests/auto/gui/text/qtextscriptengine/CMakeLists.txt11
-rw-r--r--tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt6
-rw-r--r--tests/auto/gui/text/qtextscriptengine/generate/main.cpp29
-rw-r--r--tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp38
-rw-r--r--tests/auto/gui/text/qtexttable/CMakeLists.txt13
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp146
-rw-r--r--tests/auto/gui/text/qzip/.gitignore1
-rw-r--r--tests/auto/gui/text/qzip/CMakeLists.txt35
-rw-r--r--tests/auto/gui/text/qzip/testdata.qrc6
-rw-r--r--tests/auto/gui/text/qzip/testdata/symlink.zipbin289 -> 0 bytes
-rw-r--r--tests/auto/gui/text/qzip/testdata/test.zipbin286 -> 0 bytes
-rw-r--r--tests/auto/gui/text/qzip/tst_qzip.cpp141
-rw-r--r--tests/auto/gui/util/CMakeLists.txt3
-rw-r--r--tests/auto/gui/util/qdesktopservices/CMakeLists.txt13
-rw-r--r--tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp50
-rw-r--r--tests/auto/gui/util/qdoublevalidator/CMakeLists.txt11
-rw-r--r--tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp120
-rw-r--r--tests/auto/gui/util/qintvalidator/CMakeLists.txt11
-rw-r--r--tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp75
-rw-r--r--tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt11
-rw-r--r--tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp37
-rw-r--r--tests/auto/gui/util/qtexturefilereader/CMakeLists.txt29
-rw-r--r--tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc11
-rw-r--r--tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktxbin0 -> 69 bytes
-rw-r--r--tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp42
-rw-r--r--tests/auto/gui/util/qundogroup/CMakeLists.txt11
-rw-r--r--tests/auto/gui/util/qundogroup/tst_qundogroup.cpp49
-rw-r--r--tests/auto/gui/util/qundostack/CMakeLists.txt11
-rw-r--r--tests/auto/gui/util/qundostack/tst_qundostack.cpp73
355 files changed, 13194 insertions, 6374 deletions
diff --git a/tests/auto/gui/CMakeLists.txt b/tests/auto/gui/CMakeLists.txt
index 7ba124952d..b0fb8891f5 100644
--- a/tests/auto/gui/CMakeLists.txt
+++ b/tests/auto/gui/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from gui.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(kernel)
if(NOT UIKIT)
diff --git a/tests/auto/gui/image/CMakeLists.txt b/tests/auto/gui/image/CMakeLists.txt
index 14930536c9..9cc6d4d2bf 100644
--- a/tests/auto/gui/image/CMakeLists.txt
+++ b/tests/auto/gui/image/CMakeLists.txt
@@ -1,10 +1,13 @@
-# Generated from image.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
-# QTBUG-87669 # special case
+# QTBUG-87669
if(TARGET Qt::Network AND NOT ANDROID)
add_subdirectory(qimagereader)
endif()
-add_subdirectory(qicoimageformat)
+if(QT_FEATURE_ico)
+ add_subdirectory(qicoimageformat)
+endif()
add_subdirectory(qpixmap)
add_subdirectory(qimage)
add_subdirectory(qimageiohandler)
@@ -15,7 +18,8 @@ add_subdirectory(qiconhighdpi)
if(QT_FEATURE_private_tests)
add_subdirectory(qpixmapcache)
endif()
-# QTBUG-87669 # special case
+
+# QTBUG-87669
if(NOT ANDROID)
add_subdirectory(qicon)
endif()
diff --git a/tests/auto/gui/image/qicoimageformat/CMakeLists.txt b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt
index 704c51a6be..17ec68df4e 100644
--- a/tests/auto/gui/image/qicoimageformat/CMakeLists.txt
+++ b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qicoimageformat.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qicoimageformat Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qicoimageformat LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -13,37 +20,8 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qicoimageformat
SOURCES
tst_qicoimageformat.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
TESTDATA ${test_data}
)
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(qicoimageformat_resource_files
- "icons/invalid/35floppy.ico"
- "icons/valid/35FLOPPY.ICO"
- "icons/valid/AddPerfMon.ico"
- "icons/valid/App.ico"
- "icons/valid/Obj_N2_Internal_Mem.ico"
- "icons/valid/Qt.ico"
- "icons/valid/Status_Play.ico"
- "icons/valid/TIMER01.ICO"
- "icons/valid/WORLD.ico"
- "icons/valid/WORLDH.ico"
- "icons/valid/abcardWindow.ico"
- "icons/valid/semitransparent.ico"
- "icons/valid/trolltechlogo_tiny.ico"
- "icons/valid/yellow.cur"
- )
-
- qt_internal_add_resource(tst_qicoimageformat "qicoimageformat"
- PREFIX
- "/"
- FILES
- ${qicoimageformat_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico
new file mode 100644
index 0000000000..7e9cfa2414
--- /dev/null
+++ b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.ico
Binary files differ
diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png
new file mode 100644
index 0000000000..f0a19c05e3
--- /dev/null
+++ b/tests/auto/gui/image/qicoimageformat/icons/masked/24bpp.png
Binary files differ
diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico
new file mode 100644
index 0000000000..a22248d76a
--- /dev/null
+++ b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.ico
Binary files differ
diff --git a/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png
new file mode 100644
index 0000000000..a6ceac73fa
--- /dev/null
+++ b/tests/auto/gui/image/qicoimageformat/icons/masked/32bpp.png
Binary files differ
diff --git a/tests/auto/gui/image/qicoimageformat/qicoimageformat.qrc b/tests/auto/gui/image/qicoimageformat/qicoimageformat.qrc
deleted file mode 100644
index 1e0ee8aa8c..0000000000
--- a/tests/auto/gui/image/qicoimageformat/qicoimageformat.qrc
+++ /dev/null
@@ -1,18 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>icons/invalid/35floppy.ico</file>
- <file>icons/valid/35FLOPPY.ICO</file>
- <file>icons/valid/abcardWindow.ico</file>
- <file>icons/valid/AddPerfMon.ico</file>
- <file>icons/valid/App.ico</file>
- <file>icons/valid/Obj_N2_Internal_Mem.ico</file>
- <file>icons/valid/Qt.ico</file>
- <file>icons/valid/semitransparent.ico</file>
- <file>icons/valid/Status_Play.ico</file>
- <file>icons/valid/TIMER01.ICO</file>
- <file>icons/valid/trolltechlogo_tiny.ico</file>
- <file>icons/valid/WORLD.ico</file>
- <file>icons/valid/WORLDH.ico</file>
- <file>icons/valid/yellow.cur</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
index 37d5f4998c..136f56facf 100644
--- a/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
+++ b/tests/auto/gui/image/qicoimageformat/tst_qicoimageformat.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui>
#include <QtCore>
@@ -52,6 +27,8 @@ private slots:
void pngCompression();
void write_data();
void write();
+ void icoMask_data();
+ void icoMask();
private:
QString m_IconPath;
@@ -344,6 +321,33 @@ void tst_QIcoImageFormat::write()
}
}
+void tst_QIcoImageFormat::icoMask_data()
+{
+ QTest::addColumn<QString>("inFile");
+ QTest::addColumn<QString>("outFile");
+
+ QTest::newRow("24bpp") << "masked/24bpp.ico" << "masked/24bpp.png";
+ QTest::newRow("32bpp") << "masked/32bpp.ico" << "masked/32bpp.png";
+}
+
+void tst_QIcoImageFormat::icoMask()
+{
+ QFETCH(QString, inFile);
+ QFETCH(QString, outFile);
+
+ QImage inImage;
+ QImageReader inReader(m_IconPath + QLatin1Char('/') + inFile);
+ inReader.read(&inImage);
+
+ QImage outImage;
+ QImageReader outReader(m_IconPath + QLatin1Char('/') + outFile);
+ outReader.read(&outImage);
+ outImage.setColorSpace(inImage.colorSpace());
+ outImage = outImage.convertToFormat(inImage.format());
+
+ QCOMPARE(inImage, outImage);
+}
+
QTEST_MAIN(tst_QIcoImageFormat)
#include "tst_qicoimageformat.moc"
diff --git a/tests/auto/gui/image/qicon/CMakeLists.txt b/tests/auto/gui/image/qicon/CMakeLists.txt
index 5f6b139205..c693c559cc 100644
--- a/tests/auto/gui/image/qicon/CMakeLists.txt
+++ b/tests/auto/gui/image/qicon/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qicon.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qicon Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qicon LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -33,7 +40,7 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qicon
SOURCES
tst_qicon.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
TESTDATA ${test_data}
)
@@ -55,6 +62,10 @@ set(tst_qicon_resource_files
"./icons/themeparent/index.theme"
"./icons/themeparent/scalable/actions/address-book-new.svg"
"./icons/themeparent/scalable/actions/appointment-new.svg"
+ "./icons/fallbacktheme/index.theme"
+ "./icons/fallbacktheme/16x16/edit-cut.png"
+ "./icons/hicolor/index.theme"
+ "./icons/hicolor/16x16/hicolor-icon.png"
"./second_icons/testtheme/32x32/actions/appointment-new.png"
"./styles/commonstyle/images/standardbutton-open-128.png"
"./styles/commonstyle/images/standardbutton-open-16.png"
@@ -91,6 +102,6 @@ qt_internal_add_resource(tst_qicon "qmake_immediate"
#####################################################################
qt_internal_extend_target(tst_qicon CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png b/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png
new file mode 100644
index 0000000000..661ef1ad03
--- /dev/null
+++ b/tests/auto/gui/image/qicon/icons/fallbacktheme/16x16/edit-cut.png
Binary files differ
diff --git a/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme b/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme
new file mode 100644
index 0000000000..809d296669
--- /dev/null
+++ b/tests/auto/gui/image/qicon/icons/fallbacktheme/index.theme
@@ -0,0 +1,8 @@
+[Icon Theme]
+Name=fallbacktheme
+
+Directories=16x16
+
+[16x16]
+Size=16
+Type=Fixed
diff --git a/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png
new file mode 100644
index 0000000000..661ef1ad03
--- /dev/null
+++ b/tests/auto/gui/image/qicon/icons/hicolor/16x16/hicolor-icon.png
Binary files differ
diff --git a/tests/auto/gui/image/qicon/icons/hicolor/index.theme b/tests/auto/gui/image/qicon/icons/hicolor/index.theme
new file mode 100644
index 0000000000..e5e5cef9b1
--- /dev/null
+++ b/tests/auto/gui/image/qicon/icons/hicolor/index.theme
@@ -0,0 +1,11 @@
+[Icon Theme]
+Name=hicolor
+
+# Provide a minimal hicolor theme, so that our hicolor fallback
+# lookup during testing will find that theme on all systems.
+
+Directories=16x16
+
+[16x16]
+Size=16
+Type=Fixed
diff --git a/tests/auto/gui/image/qicon/icons/testtheme/index.theme b/tests/auto/gui/image/qicon/icons/testtheme/index.theme
index e18736ab43..53664b14b2 100644
--- a/tests/auto/gui/image/qicon/icons/testtheme/index.theme
+++ b/tests/auto/gui/image/qicon/icons/testtheme/index.theme
@@ -1,7 +1,7 @@
[Icon Theme]
_Name=Test
_Comment=Test Theme
-Inherits=crystalsvg, themeparent
+Inherits=themeparent
Example=x-directory-normal
# KDE Specific Stuff
diff --git a/tests/auto/gui/image/qicon/icons/themeparent/index.theme b/tests/auto/gui/image/qicon/icons/themeparent/index.theme
index e536a0bf2f..96267addd6 100644
--- a/tests/auto/gui/image/qicon/icons/themeparent/index.theme
+++ b/tests/auto/gui/image/qicon/icons/themeparent/index.theme
@@ -1,7 +1,6 @@
[Icon Theme]
_Name=Test
_Comment=Test Theme
-Inherits=gnome,crystalsvg
Example=x-directory-normal
# KDE Specific Stuff
diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp
index 3363f86809..99b4a0589e 100644
--- a/tests/auto/gui/image/qicon/tst_qicon.cpp
+++ b/tests/auto/gui/image/qicon/tst_qicon.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QImageReader>
@@ -66,6 +41,7 @@ private slots:
void streamAvailableSizes();
void fromTheme();
void fromThemeCache();
+ void fromThemeConstant();
#ifndef QT_NO_WIDGETS
void task184901_badCache();
@@ -216,21 +192,21 @@ void tst_QIcon::isNull() {
// test string constructor with empty string
QIcon iconEmptyString = QIcon(QString());
QVERIFY(iconEmptyString.isNull());
- QVERIFY(!iconEmptyString.actualSize(QSize(32, 32)).isValid());;
+ QVERIFY(!iconEmptyString.actualSize(QSize(32, 32)).isValid());
// test string constructor with non-existing file
QIcon iconNoFile = QIcon("imagedoesnotexist");
- QVERIFY(!iconNoFile.isNull());
+ QVERIFY(iconNoFile.isNull());
QVERIFY(!iconNoFile.actualSize(QSize(32, 32)).isValid());
// test string constructor with non-existing file with suffix
QIcon iconNoFileSuffix = QIcon("imagedoesnotexist.png");
- QVERIFY(!iconNoFileSuffix.isNull());
+ QVERIFY(iconNoFileSuffix.isNull());
QVERIFY(!iconNoFileSuffix.actualSize(QSize(32, 32)).isValid());
// test string constructor with existing file but unsupported format
QIcon iconUnsupportedFormat = QIcon(m_sourceFileName);
- QVERIFY(!iconUnsupportedFormat.isNull());
+ QVERIFY(iconUnsupportedFormat.isNull());
QVERIFY(!iconUnsupportedFormat.actualSize(QSize(32, 32)).isValid());
// test string constructor with existing file and supported format
@@ -577,6 +553,10 @@ void tst_QIcon::availableSizes()
void tst_QIcon::name()
{
+ const auto reset = qScopeGuard([]{
+ QIcon::setThemeName({});
+ QIcon::setThemeSearchPaths({});
+ });
{
// No name if icon does not come from a theme
QIcon icon(":/image.png");
@@ -654,6 +634,7 @@ void tst_QIcon::task184901_badCache()
void tst_QIcon::fromTheme()
{
+ const bool abIconFromPlatform = !QIcon::fromTheme("address-book-new").isNull();
QString firstSearchPath = QLatin1String(":/icons");
QString secondSearchPath = QLatin1String(":/second_icons");
QIcon::setThemeSearchPaths(QStringList() << firstSearchPath << secondSearchPath);
@@ -742,14 +723,44 @@ void tst_QIcon::fromTheme()
QCOMPARE(i.availableSizes(), abIcon.availableSizes());
}
+ // Setting or changing the fallback theme should invalidate earlier lookups.
+ // We can only test this if the system doesn't provide an icon, because once
+ // we got a valid icon, it will be cached, and even if we proxy to a different
+ // engine when a fallback theme is set, the cacheKey of the icon will be the
+ // same.
+ const QIcon editCut = QIcon::fromTheme("edit-cut");
+ if (editCut.isNull()) {
+ QIcon::setFallbackThemeName("fallbacktheme");
+ QVERIFY(!QIcon::fromTheme("edit-cut").isNull());
+ }
+
// Make sure setting the theme name clears the state
QIcon::setThemeName("");
abIcon = QIcon::fromTheme("address-book-new");
- QVERIFY(abIcon.isNull());
+ QCOMPARE_NE(abIcon.isNull(), abIconFromPlatform);
+
+ // Test fallback icon behavior for empty theme names.
+ // Can only reliably test this on systems that don't have a
+ // named system icon theme.
+ QIcon::setThemeName(""); // Reset user-theme
+ if (QIcon::themeName().isEmpty()) {
+ // Test icon from fallback theme even when theme name is empty
+ QIcon::setFallbackThemeName("fallbacktheme");
+ QVERIFY(!QIcon::fromTheme("edit-cut").isNull());
+
+ // Test icon from fallback path even when theme name is empty
+ fallbackIcon = QIcon::fromTheme("red");
+ QVERIFY(!fallbackIcon.isNull());
+ QVERIFY(QIcon::hasThemeIcon("red"));
+ QCOMPARE(fallbackIcon.availableSizes().size(), 1);
+ }
// Passing a full path to fromTheme is not very useful, but should work anyway
QIcon fullPathIcon = QIcon::fromTheme(m_pngImageFileName);
QVERIFY(!fullPathIcon.isNull());
+
+ // Restore to system fallback theme
+ QIcon::setFallbackThemeName("");
}
static inline QString findGtkUpdateIconCache()
@@ -810,7 +821,7 @@ void tst_QIcon::fromThemeCache()
QTest::qWait(1000); // wait enough to have a different modification time in seconds
QVERIFY(QFile(QStringLiteral(":/styles/commonstyle/images/standardbutton-save-16.png"))
.copy(dir.path() + QLatin1String("/testcache/16x16/actions/button-save.png")));
- QVERIFY(QFileInfo(cacheName).lastModified() < QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified());
+ QVERIFY(QFileInfo(cacheName).lastModified(QTimeZone::UTC) < QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified(QTimeZone::UTC));
QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes
QVERIFY(!QIcon::fromTheme("button-open").isNull());
@@ -831,13 +842,18 @@ void tst_QIcon::fromThemeCache()
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
QCOMPARE(process.exitCode(), 0);
#endif // QT_CONFIG(process)
- QVERIFY(QFileInfo(cacheName).lastModified() >= QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified());
+ QVERIFY(QFileInfo(cacheName).lastModified(QTimeZone::UTC) >= QFileInfo(dir.path() + QLatin1String("/testcache/16x16/actions")).lastModified(QTimeZone::UTC));
QIcon::setThemeSearchPaths(QStringList() << dir.path()); // reload themes
QVERIFY(!QIcon::fromTheme("button-open").isNull());
QVERIFY(!QIcon::fromTheme("button-open-fallback").isNull());
QVERIFY(QIcon::fromTheme("notexist-fallback").isNull());
}
+void tst_QIcon::fromThemeConstant()
+{
+ const QIcon icon = QIcon::fromTheme(QIcon::ThemeIcon::EditCut);
+}
+
void tst_QIcon::task223279_inconsistentAddFile()
{
QIcon icon1;
diff --git a/tests/auto/gui/image/qicon/tst_qicon.qrc b/tests/auto/gui/image/qicon/tst_qicon.qrc
deleted file mode 100644
index 23a6801e38..0000000000
--- a/tests/auto/gui/image/qicon/tst_qicon.qrc
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
-<file>tst_qicon.cpp</file>
-<file>image.png</file>
-<file>rect.png</file>
-<file>./icons/testtheme/16x16/actions/appointment-new.png</file>
-<file>./icons/testtheme/22x22/actions/appointment-new.png</file>
-<file>./second_icons/testtheme/32x32/actions/appointment-new.png</file>
-<file>./fallback_icons/red.png</file>
-<file>./icons/testtheme/index.theme</file>
-<file>./icons/testtheme/scalable/actions/svg-only.svg</file>
-<file>./icons/themeparent/16x16/actions/address-book-new.png</file>
-<file>./icons/themeparent/16x16/actions/appointment-new.png</file>
-<file>./icons/themeparent/22x22/actions/address-book-new.png</file>
-<file>./icons/themeparent/22x22/actions/appointment-new.png</file>
-<file>./icons/themeparent/32x32/actions/address-book-new.png</file>
-<file>./icons/themeparent/32x32/actions/appointment-new.png</file>
-<file>./icons/themeparent/index.theme</file>
-<file>./icons/themeparent/icon-theme.cache</file>
-<file>./icons/themeparent/scalable/actions/address-book-new.svg</file>
-<file>./icons/themeparent/scalable/actions/appointment-new.svg</file>
-<file>./styles/commonstyle/images/standardbutton-open-16.png</file>
-<file>./styles/commonstyle/images/standardbutton-open-32.png</file>
-<file>./styles/commonstyle/images/standardbutton-open-64.png</file>
-<file>./styles/commonstyle/images/standardbutton-open-128.png</file>
-<file>./styles/commonstyle/images/standardbutton-save-16.png</file>
-<file>./styles/commonstyle/images/standardbutton-save-32.png</file>
-<file>./styles/commonstyle/images/standardbutton-save-64.png</file>
-<file>./styles/commonstyle/images/standardbutton-save-128.png</file>
-</qresource>
-</RCC>
diff --git a/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt
index 989cf1f44d..f0ccb97c8a 100644
--- a/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt
+++ b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qiconhighdpi.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qiconhighdpi Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qiconhighdpi LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -13,7 +20,7 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qiconhighdpi
SOURCES
tst_qiconhighdpi.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
TESTDATA ${test_data}
)
diff --git a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
index 3282776ee6..34f0132865 100644
--- a/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
+++ b/tests/auto/gui/image/qiconhighdpi/tst_qiconhighdpi.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qicon.h>
@@ -42,6 +17,7 @@ private slots:
void addPixmap_data();
void addPixmap();
void ninePatch();
+ void preferUpscale();
};
tst_QIconHighDpi::tst_QIconHighDpi()
@@ -236,6 +212,23 @@ void tst_QIconHighDpi::ninePatch()
}
}
+void tst_QIconHighDpi::preferUpscale()
+{
+ QIcon icon;
+
+ // manual pixmap adder for full control of devicePixelRatio
+ auto addPixmapWithDpr = [&icon](const QString &path, qreal dpr) {
+ QImage image(path);
+ image.setDevicePixelRatio(dpr);
+ icon.addPixmap(QPixmap::fromImage(image));
+ };
+
+ addPixmapWithDpr(":/icons/testtheme/22x22/actions/appointment-new.png", 1);
+ addPixmapWithDpr(":/icons/testtheme/22x22@2/actions/appointment-new.png", 2);
+
+ QCOMPARE(icon.pixmap(QSize(22, 22), 1.25f).devicePixelRatio(), 1.25f);
+}
+
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
diff --git a/tests/auto/gui/image/qimage/CMakeLists.txt b/tests/auto/gui/image/qimage/CMakeLists.txt
index 4c95b32e48..8d0842026d 100644
--- a/tests/auto/gui/image/qimage/CMakeLists.txt
+++ b/tests/auto/gui/image/qimage/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qimage.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qimage Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qimage LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -13,54 +20,20 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qimage
SOURCES
tst_qimage.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
TESTDATA ${test_data}
)
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(qimage_resource_files
- "images/image.bmp"
- "images/image.gif"
- "images/image.ico"
- "images/image.jpg"
- "images/image.pbm"
- "images/image.pgm"
- "images/image.png"
- "images/image.ppm"
- "images/image.xbm"
- "images/image.xpm"
- "images/jpeg_exif_orientation_value_1.jpg"
- "images/jpeg_exif_orientation_value_2.jpg"
- "images/jpeg_exif_orientation_value_3.jpg"
- "images/jpeg_exif_orientation_value_4.jpg"
- "images/jpeg_exif_orientation_value_5.jpg"
- "images/jpeg_exif_orientation_value_6.jpg"
- "images/jpeg_exif_orientation_value_7.jpg"
- "images/jpeg_exif_orientation_value_8.jpg"
- )
-
- qt_internal_add_resource(tst_qimage "qimage"
- PREFIX
- "/"
- FILES
- ${qimage_resource_files}
- )
-endif()
-
qt_internal_extend_target(tst_qimage CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
gdi32
user32
)
qt_internal_extend_target(tst_qimage CONDITION APPLE
- PUBLIC_LIBRARIES
+ LIBRARIES
${FWCoreGraphics}
)
diff --git a/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc b/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc
new file mode 100644
index 0000000000..b5a73495bf
--- /dev/null
+++ b/tests/auto/gui/image/qimage/images/CGATS001Compat-v2-micro.icc
Binary files differ
diff --git a/tests/auto/gui/image/qimage/qimage.qrc b/tests/auto/gui/image/qimage/qimage.qrc
deleted file mode 100644
index e5de27faf8..0000000000
--- a/tests/auto/gui/image/qimage/qimage.qrc
+++ /dev/null
@@ -1,22 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>images/image.bmp</file>
- <file>images/image.gif</file>
- <file>images/image.ico</file>
- <file>images/image.jpg</file>
- <file>images/image.pbm</file>
- <file>images/image.pgm</file>
- <file>images/image.png</file>
- <file>images/image.ppm</file>
- <file>images/image.xbm</file>
- <file>images/image.xpm</file>
- <file>images/jpeg_exif_orientation_value_1.jpg</file>
- <file>images/jpeg_exif_orientation_value_2.jpg</file>
- <file>images/jpeg_exif_orientation_value_3.jpg</file>
- <file>images/jpeg_exif_orientation_value_4.jpg</file>
- <file>images/jpeg_exif_orientation_value_5.jpg</file>
- <file>images/jpeg_exif_orientation_value_6.jpg</file>
- <file>images/jpeg_exif_orientation_value_7.jpg</file>
- <file>images/jpeg_exif_orientation_value_8.jpg</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 6f9e0641ac..1d0cdfcc4e 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -1,38 +1,15 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QBuffer>
+#include <QMatrix4x4>
#include <qimage.h>
#include <qimagereader.h>
#include <qlist.h>
+#include <qset.h>
#include <qtransform.h>
#include <qrandom.h>
#include <stdio.h>
@@ -91,6 +68,7 @@ private slots:
void rotate_data();
void rotate();
+ void rotateBigImage();
void copy();
@@ -130,6 +108,8 @@ private slots:
void smoothScaleAlpha();
void smoothScaleFormats_data();
void smoothScaleFormats();
+ void smoothScaleNoConversion_data();
+ void smoothScaleNoConversion();
void transformed_data();
void transformed();
@@ -189,6 +169,11 @@ private slots:
void largeInplaceRgbConversion_data();
void largeInplaceRgbConversion();
+ void colorSpaceRgbConversion_data();
+ void colorSpaceRgbConversion();
+ void colorSpaceCmykConversion_data();
+ void colorSpaceCmykConversion();
+
void deepCopyWhenPaintingActive();
void scaled_QTBUG19157();
@@ -250,12 +235,18 @@ private slots:
void largeFillScale();
void largeRasterScale();
+ void metadataChangeWithReadOnlyPixels();
+ void scaleIndexed();
+
#if defined(Q_OS_WIN)
void toWinHBITMAP_data();
void toWinHBITMAP();
void fromMonoHBITMAP();
#endif // Q_OS_WIN
+ void tofromPremultipliedFormat_data();
+ void tofromPremultipliedFormat();
+
private:
const QString m_prefix;
};
@@ -335,7 +326,9 @@ static QLatin1String formatToString(QImage::Format format)
return QLatin1String("RGBA32FPx4");
case QImage::Format_RGBA32FPx4_Premultiplied:
return QLatin1String("RGBA32FPx4pm");
- default:
+ case QImage::Format_CMYK8888:
+ return QLatin1String("CMYK8888");
+ case QImage::NImageFormats:
break;
};
Q_UNREACHABLE();
@@ -1153,10 +1146,9 @@ void tst_QImage::rotate_data()
QTest::addColumn<QImage::Format>("format");
QTest::addColumn<int>("degrees");
- QList<int> degrees;
- degrees << 0 << 90 << 180 << 270;
+ constexpr int degrees[] = {0, 90, 180, 270};
- foreach (int d, degrees) {
+ for (int d : degrees) {
const QString dB = QString::number(d);
for (int i = QImage::Format_Indexed8; i < QImage::NImageFormats; i++) {
QImage::Format format = static_cast<QImage::Format>(i);
@@ -1234,6 +1226,23 @@ void tst_QImage::rotate()
QCOMPARE(original, dest);
}
+void tst_QImage::rotateBigImage()
+{
+ // QTBUG-105088
+ QImage big_image(3840, 2160, QImage::Format_ARGB32_Premultiplied);
+ QTransform t;
+ t.translate(big_image.width() / 2.0, big_image.height() / 2.0);
+ t.rotate(-89, Qt::YAxis, big_image.width());
+ t.translate(-big_image.width() / 2.0, -big_image.height() / 2.0);
+ QVERIFY(!big_image.transformed(t).isNull());
+
+ QMatrix4x4 m;
+ m.translate(big_image.width() / 2.0, big_image.height() / 2.0);
+ m.projectedRotate(89, 0, 1, 0, big_image.width());
+ m.translate(-big_image.width() / 2.0, -big_image.height() / 2.0);
+ QVERIFY(!big_image.transformed(m.toTransform()).isNull());
+}
+
void tst_QImage::copy()
{
// Task 99250
@@ -1505,6 +1514,8 @@ void tst_QImage::setPixelWithAlpha_data()
continue;
if (c == QImage::Format_Alpha8)
continue;
+ if (c == QImage::Format_CMYK8888)
+ continue;
QTest::newRow(qPrintable(formatToString(QImage::Format(c)))) << QImage::Format(c);
}
}
@@ -2062,6 +2073,24 @@ void tst_QImage::smoothScaleFormats()
QVERIFY(rotated.hasAlphaChannel());
}
+void tst_QImage::smoothScaleNoConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addRow("Mono") << QImage::Format_Mono;
+ QTest::addRow("MonoLSB") << QImage::Format_MonoLSB;
+ QTest::addRow("Indexed8") << QImage::Format_Indexed8;
+}
+
+void tst_QImage::smoothScaleNoConversion()
+{
+ QFETCH(QImage::Format, format);
+ QImage img(128, 128, format);
+ img.fill(1);
+ img.setColorTable(QList<QRgb>() << qRgba(255,0,0,255) << qRgba(0,0,0,0));
+ img = img.scaled(QSize(48, 48), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+ QVERIFY(img.hasAlphaChannel());
+}
+
static int count(const QImage &img, int x, int y, int dx, int dy, QRgb pixel)
{
int i = 0;
@@ -2548,7 +2577,8 @@ void tst_QImage::rgbSwapped_data()
for (int i = QImage::Format_Indexed8; i < QImage::NImageFormats; ++i) {
if (i == QImage::Format_Alpha8
|| i == QImage::Format_Grayscale8
- || i == QImage::Format_Grayscale16) {
+ || i == QImage::Format_Grayscale16
+ || i == QImage::Format_CMYK8888) {
continue;
}
QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i);
@@ -2642,20 +2672,20 @@ void tst_QImage::mirrored_data()
QTest::newRow("Format_Mono, horizontal+vertical") << QImage::Format_Mono << true << true << 16 << 16;
QTest::newRow("Format_MonoLSB, horizontal+vertical") << QImage::Format_MonoLSB << true << true << 16 << 16;
- QTest::newRow("Format_RGB32, vertical") << QImage::Format_RGB32 << true << false << 8 << 16;
- QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false << 16 << 8;
+ QTest::newRow("Format_RGB32, vertical, narrow") << QImage::Format_RGB32 << true << false << 8 << 16;
+ QTest::newRow("Format_ARGB32, vertical, short") << QImage::Format_ARGB32 << true << false << 16 << 8;
QTest::newRow("Format_Mono, vertical, non-aligned") << QImage::Format_Mono << true << false << 19 << 25;
QTest::newRow("Format_MonoLSB, vertical, non-aligned") << QImage::Format_MonoLSB << true << false << 19 << 25;
// Non-aligned horizontal 1-bit needs special handling so test this.
QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 13 << 17;
- QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 19 << 25;
- QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 25 << 47;
+ QTest::newRow("Format_Mono, horizontal, non-aligned, big") << QImage::Format_Mono << false << true << 19 << 25;
+ QTest::newRow("Format_Mono, horizontal+vertical, non-aligned, big") << QImage::Format_Mono << true << true << 25 << 47;
QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 21 << 16;
QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 13 << 17;
- QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 19 << 25;
- QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 25 << 47;
+ QTest::newRow("Format_MonoLSB, horizontal, non-aligned, big") << QImage::Format_MonoLSB << false << true << 19 << 25;
+ QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned, big") << QImage::Format_MonoLSB << true << true << 25 << 47;
QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 21 << 16;
}
@@ -3030,13 +3060,15 @@ void tst_QImage::inplaceRgbConversion_data()
for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) {
if (i == QImage::Format_Alpha8
|| i == QImage::Format_Grayscale8
- || i == QImage::Format_Grayscale16) {
+ || i == QImage::Format_Grayscale16
+ || i == QImage::Format_CMYK8888) {
continue;
}
for (int j = QImage::Format_RGB32; j < QImage::NImageFormats; ++j) {
if (j == QImage::Format_Alpha8
|| j == QImage::Format_Grayscale8
- || j == QImage::Format_Grayscale16) {
+ || j == QImage::Format_Grayscale16
+ || j == QImage::Format_CMYK8888) {
continue;
}
if (i == j)
@@ -3217,6 +3249,144 @@ void tst_QImage::largeInplaceRgbConversion()
}
}
+void tst_QImage::colorSpaceRgbConversion_data()
+{
+ QTest::addColumn<QImage::Format>("fromFormat");
+ QTest::addColumn<QImage::Format>("toFormat");
+
+ // The various possible code paths for color space conversions compatible with RGB color spaces:
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGBX64,
+ QImage::Format_RGBA64,
+ QImage::Format_RGBA64_Premultiplied,
+ QImage::Format_RGBX32FPx4,
+ QImage::Format_RGBA32FPx4,
+ QImage::Format_RGBA32FPx4_Premultiplied,
+ QImage::Format_Grayscale8,
+ QImage::Format_Grayscale16,
+ };
+
+ for (auto fromFormat : formats) {
+ const QLatin1String formatI = formatToString(fromFormat);
+ for (auto toFormat : formats) {
+ QTest::addRow("%s -> %s", formatI.data(), formatToString(toFormat).data())
+ << fromFormat << toFormat;
+ }
+ }
+}
+
+void tst_QImage::colorSpaceRgbConversion()
+{
+ // Test that all color space conversions work
+ QFETCH(QImage::Format, fromFormat);
+ QFETCH(QImage::Format, toFormat);
+
+ bool srcGrayscale = fromFormat == QImage::Format_Grayscale8 || fromFormat == QImage::Format_Grayscale16;
+ bool dstGrayscale = toFormat == QImage::Format_Grayscale8 || toFormat == QImage::Format_Grayscale16;
+
+ QImage image(16, 16, fromFormat);
+ image.setColorSpace(QColorSpace::SRgb);
+
+ for (int i = 0; i < image.height(); ++i) {
+ for (int j = 0; j < image.width(); ++j) {
+ if (srcGrayscale || dstGrayscale)
+ image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8));
+ else
+ image.setPixel(j, i, qRgb(j * 16, i * 16, (i + j) * 8));
+ }
+ }
+
+ QImage imageConverted = image.convertedToColorSpace(QColorSpace::DisplayP3, toFormat);
+ QCOMPARE(imageConverted.format(), toFormat);
+ QCOMPARE(imageConverted.size(), image.size());
+ if (dstGrayscale) {
+ int gray = 0;
+ for (int x = 0; x < image.width(); ++x) {
+ int newGray = qGray(imageConverted.pixel(x, 6));
+ QCOMPARE_GE(newGray, gray);
+ gray = newGray;
+ }
+ } else {
+ int red = 0;
+ int blue = 0;
+ for (int x = 0; x < image.width(); ++x) {
+ int newRed = qRed(imageConverted.pixel(x, 5));
+ int newBlue = qBlue(imageConverted.pixel(x, 7));
+ QCOMPARE_GE(newBlue, blue);
+ QCOMPARE_GE(newRed, red);
+ blue = newBlue;
+ red = newRed;
+ }
+ }
+}
+
+
+void tst_QImage::colorSpaceCmykConversion_data()
+{
+ QTest::addColumn<QImage::Format>("toFormat");
+
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGBX64,
+ QImage::Format_RGBA64,
+ QImage::Format_RGBA64_Premultiplied,
+ QImage::Format_RGBX32FPx4,
+ QImage::Format_RGBA32FPx4,
+ QImage::Format_RGBA32FPx4_Premultiplied,
+ QImage::Format_Grayscale8,
+ QImage::Format_Grayscale16,
+ };
+
+ for (auto toFormat : formats)
+ QTest::addRow("CMYK8888 -> %s", formatToString(toFormat).data()) << toFormat;
+}
+
+void tst_QImage::colorSpaceCmykConversion()
+{
+ QFETCH(QImage::Format, toFormat);
+
+ bool dstGrayscale = toFormat == QImage::Format_Grayscale8 || toFormat == QImage::Format_Grayscale16;
+
+ QImage image(16, 16, QImage::Format_CMYK8888);
+ QFile iccProfile(m_prefix +"CGATS001Compat-v2-micro.icc");
+ iccProfile.open(QIODevice::ReadOnly);
+ image.setColorSpace(QColorSpace::fromIccProfile(iccProfile.readAll()));
+ QVERIFY(image.colorSpace().isValid());
+
+ for (int i = 0; i < image.height(); ++i) {
+ for (int j = 0; j < image.width(); ++j) {
+ if (dstGrayscale)
+ image.setPixel(j, i, qRgb((i + j) * 8, (i + j) * 8, (i + j) * 8));
+ else
+ image.setPixel(j, i, qRgb(j * 16, i * 16, (i + j) * 8));
+ }
+ }
+
+ QImage imageConverted = image.convertedToColorSpace(QColorSpace::SRgb, toFormat);
+ QCOMPARE(imageConverted.format(), toFormat);
+ QCOMPARE(imageConverted.size(), image.size());
+ if (dstGrayscale) {
+ int gray = 0;
+ for (int x = 0; x < image.width(); ++x) {
+ int newGray = qGray(imageConverted.pixel(x, 6));
+ QCOMPARE_GE(newGray, gray);
+ gray = newGray;
+ }
+ } else {
+ int red = 0;
+ for (int x = 0; x < image.width(); ++x) {
+ int newRed = qRed(imageConverted.pixel(x, 5));
+ QCOMPARE_GE(newRed, red);
+ red = newRed;
+ }
+ }
+}
+
void tst_QImage::deepCopyWhenPaintingActive()
{
QImage image(64, 64, QImage::Format_ARGB32_Premultiplied);
@@ -3325,7 +3495,8 @@ void tst_QImage::invertPixelsRGB_data()
for (int i = QImage::Format_RGB32; i < QImage::NImageFormats; ++i) {
if (i == QImage::Format_Alpha8
|| i == QImage::Format_Grayscale8
- || i == QImage::Format_Grayscale16) {
+ || i == QImage::Format_Grayscale16
+ || i == QImage::Format_CMYK8888) {
continue;
}
QTest::addRow("%s", formatToString(QImage::Format(i)).data()) << QImage::Format(i);
@@ -3457,6 +3628,9 @@ void tst_QImage::exifInvalidData()
void tst_QImage::exifReadComments()
{
+#ifdef QT_NO_IMAGEIO_TEXT_LOADING
+ QSKIP("Reading text from image file is configured off");
+#endif
QImage image;
QVERIFY(image.load(m_prefix + "jpeg_exif_utf8_comment.jpg"));
QVERIFY(!image.isNull());
@@ -3850,7 +4024,7 @@ void tst_QImage::reinterpretAsFormat_data()
QTest::newRow("rgb32 -> argb32") << QImage::Format_RGB32 << QImage::Format_ARGB32 << QColor(Qt::cyan) << QColor(Qt::cyan);
QTest::newRow("argb32pm -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(Qt::transparent) << QColor(Qt::black);
QTest::newRow("argb32 -> rgb32") << QImage::Format_ARGB32 << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(255, 0, 0);
- QTest::newRow("argb32pm -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(127, 0, 0);
+ QTest::newRow("argb32pm (red) -> rgb32") << QImage::Format_ARGB32_Premultiplied << QImage::Format_RGB32 << QColor(255, 0, 0, 127) << QColor(127, 0, 0);
}
void tst_QImage::reinterpretAsFormat()
@@ -3945,7 +4119,10 @@ void tst_QImage::hugeQImage()
#if Q_PROCESSOR_WORDSIZE < 8
QSKIP("Test only makes sense on 64-bit machines");
#else
- QImage image(25000, 25000, QImage::Format_RGB32);
+ std::unique_ptr<char[]> enough(new (std::nothrow) char[qsizetype(25000)*25000*4]);
+ if (!enough)
+ QSKIP("Could not allocate enough memory");
+ QImage image((uchar*)enough.get(), 25000, 25000, QImage::Format_RGB32);
QVERIFY(!image.isNull());
QCOMPARE(image.height(), 25000);
@@ -4059,6 +4236,34 @@ void tst_QImage::largeRasterScale()
// image.save("largeRasterScale.png", "PNG");
}
+void tst_QImage::metadataChangeWithReadOnlyPixels()
+{
+ const QRgb data[3] = { qRgb(255, 0, 0), qRgb(0, 255, 0), qRgb(0, 0, 255) };
+ QImage image((const uchar *)data, 3, 1, QImage::Format_RGB32);
+
+ QCOMPARE(image.constBits(), (const uchar *)data);
+ image.setDotsPerMeterX(100);
+ QCOMPARE(image.constBits(), (const uchar *)data);
+
+ QImage image2 = image;
+ QCOMPARE(image2.constBits(), (const uchar *)data);
+ image2.setDotsPerMeterX(200);
+ // Pixels and metadata has the same sharing mechanism, so a change of a shared
+ // image metadata forces pixel detach (remove this sub-test if that ever changes).
+ QVERIFY(image2.constBits() != (const uchar *)data);
+ QCOMPARE(image.constBits(), (const uchar *)data);
+}
+
+void tst_QImage::scaleIndexed()
+{
+ QImage image(10, 10, QImage::Format_Indexed8);
+ image.setColor(0, qRgb(0,0,0));
+ image.setColor(1, qRgb(1,1,1));
+ image.fill(1);
+ image.setDevicePixelRatio(2);
+ QImage image2 = image.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation); // do not crash
+}
+
#if defined(Q_OS_WIN)
static inline QColor COLORREFToQColor(COLORREF cr)
@@ -4171,5 +4376,27 @@ void tst_QImage::fromMonoHBITMAP() // QTBUG-72343, corruption for mono bitmaps
#endif // Q_OS_WIN
+void tst_QImage::tofromPremultipliedFormat_data()
+{
+ QTest::addColumn<QImage::Format>("unpremul");
+ QTest::addColumn<QImage::Format>("premul");
+
+ // Test all available formats with both premultiplied and unpremultiplied versions
+ QTest::newRow("argb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32_Premultiplied;
+ QTest::newRow("rgba8888") << QImage::Format_RGBA8888 << QImage::Format_RGBA8888_Premultiplied;
+ QTest::newRow("rgba64") << QImage::Format_RGBA64 << QImage::Format_RGBA64_Premultiplied;
+ QTest::newRow("rgba16fpx4") << QImage::Format_RGBA16FPx4 << QImage::Format_RGBA16FPx4_Premultiplied;
+ QTest::newRow("rgba32fpx4") << QImage::Format_RGBA32FPx4 << QImage::Format_RGBA32FPx4_Premultiplied;
+}
+
+void tst_QImage::tofromPremultipliedFormat()
+{
+ QFETCH(QImage::Format, unpremul);
+ QFETCH(QImage::Format, premul);
+
+ QCOMPARE(qt_toPremultipliedFormat(unpremul), premul);
+ QCOMPARE(qt_toUnpremultipliedFormat(premul), unpremul);
+}
+
QTEST_GUILESS_MAIN(tst_QImage)
#include "tst_qimage.moc"
diff --git a/tests/auto/gui/image/qimageiohandler/CMakeLists.txt b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt
index 4bbf2f5b01..9fbd9c9b9f 100644
--- a/tests/auto/gui/image/qimageiohandler/CMakeLists.txt
+++ b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qimageiohandler.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qimageiohandler Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qimageiohandler LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qimageiohandler
SOURCES
tst_qimageiohandler.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp b/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp
index 9fa0e37cad..bd325e185c 100644
--- a/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp
+++ b/tests/auto/gui/image/qimageiohandler/tst_qimageiohandler.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/image/qimagereader/BLACKLIST b/tests/auto/gui/image/qimagereader/BLACKLIST
new file mode 100644
index 0000000000..6422ff1dac
--- /dev/null
+++ b/tests/auto/gui/image/qimagereader/BLACKLIST
@@ -0,0 +1,8 @@
+[setClipRect:SVG: rect]
+wayland
+[setClipRect:SVGZ: rect]
+wayland
+[setScaledClipRect:SVG: rect]
+wayland
+[setScaledClipRect:SVGZ: rect]
+wayland
diff --git a/tests/auto/gui/image/qimagereader/CMakeLists.txt b/tests/auto/gui/image/qimagereader/CMakeLists.txt
index a0cda3bb73..2a14ca3c9c 100644
--- a/tests/auto/gui/image/qimagereader/CMakeLists.txt
+++ b/tests/auto/gui/image/qimagereader/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qimagereader.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qimagereader Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qimagereader LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -17,7 +24,7 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qimagereader
SOURCES
tst_qimagereader.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
@@ -42,24 +49,3 @@ qt_internal_add_resource(tst_qimagereader "qmake_immediate"
${qmake_immediate_resource_files}
)
-
-#### Keys ignored in scope 1:.:.:qimagereader.pro:<TRUE>:
-# MOC_DIR = "tmp"
-
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(android_testdata_resource_files
- "images/kollada-noext"
- "images/trans.gif"
- )
-
- qt_internal_add_resource(tst_qimagereader "android_testdata"
- PREFIX
- "/"
- FILES
- ${android_testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/image/qimagereader/images/image.pbm b/tests/auto/gui/image/qimagereader/images/image.pbm
index 67e5efa3e9..e529536ca4 100644
--- a/tests/auto/gui/image/qimagereader/images/image.pbm
+++ b/tests/auto/gui/image/qimagereader/images/image.pbm
@@ -1,8 +1,8 @@
P1
16 6
1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
-1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
+10 00 00 00 01 00 00 01
+1000 0000 0100 0001
+100000000 1000001
+1000000001000001
+10 000 0000 10000 01
diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
index 1019def466..96af8b4e9b 100644
--- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
+++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp
@@ -1,31 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -36,7 +10,7 @@
#include <QImageReader>
#include <QImageWriter>
#include <QPixmap>
-#include <QSet>
+#include <QScopeGuard>
#include <QTcpSocket>
#include <QTcpServer>
#include <QTimer>
@@ -88,12 +62,17 @@ private slots:
void setScaledSize_data();
void setScaledSize();
+ void setScaledSizeOneDimension_data();
+ void setScaledSizeOneDimension();
+
void setClipRect_data();
void setClipRect();
void setScaledClipRect_data();
void setScaledClipRect();
+ void setFormat();
+
void imageFormat_data();
void imageFormat();
@@ -324,25 +303,52 @@ void tst_QImageReader::jpegRgbCmyk()
QImage image1(prefix + QLatin1String("YCbCr_cmyk.jpg"));
QImage image2(prefix + QLatin1String("YCbCr_cmyk.png"));
- if (image1 != image2) {
- // first, do some obvious tests
- QCOMPARE(image1.height(), image2.height());
- QCOMPARE(image1.width(), image2.width());
- QCOMPARE(image1.format(), image2.format());
- QCOMPARE(image1.format(), QImage::Format_RGB32);
-
- // compare all the pixels with a slack of 3. This ignores rounding errors
- // in libjpeg/libpng, where some versions sacrifice accuracy for speed.
- for (int h = 0; h < image1.height(); ++h) {
- const uchar *s1 = image1.constScanLine(h);
- const uchar *s2 = image2.constScanLine(h);
- for (int w = 0; w < image1.width() * 4; ++w) {
- if (*s1 != *s2) {
- QVERIFY2(qAbs(*s1 - *s2) <= 3, qPrintable(QString("images differ in line %1, col %2 (image1: %3, image2: %4)").arg(h).arg(w).arg(*s1, 0, 16).arg(*s2, 0, 16)));
- }
- s1++;
- s2++;
- }
+ QVERIFY(!image1.isNull());
+ QVERIFY(!image2.isNull());
+
+ QCOMPARE(image1.height(), image2.height());
+ QCOMPARE(image1.width(), image2.width());
+
+ QCOMPARE(image1.format(), QImage::Format_CMYK8888);
+ QCOMPARE(image2.format(), QImage::Format_RGB32);
+
+ // compare all the pixels with a slack of 3. This ignores rounding errors
+ // in libjpeg/libpng, where some versions sacrifice accuracy for speed.
+ const auto fuzzyCompareColors = [](const QColor &c1, const QColor &c2) {
+ int c1rgba[4];
+ int c2rgba[4];
+
+ c1.getRgb(c1rgba + 0,
+ c1rgba + 1,
+ c1rgba + 2,
+ c1rgba + 3);
+
+ c2.getRgb(c2rgba + 0,
+ c2rgba + 1,
+ c2rgba + 2,
+ c2rgba + 3);
+
+ const auto fuzzyCompare = [](int a, int b) {
+ return qAbs(a - b) <= 3;
+ };
+
+ return fuzzyCompare(c1rgba[0], c2rgba[0]) &&
+ fuzzyCompare(c1rgba[1], c2rgba[1]) &&
+ fuzzyCompare(c1rgba[2], c2rgba[2]) &&
+ fuzzyCompare(c1rgba[3], c2rgba[3]);
+ };
+
+ for (int h = 0; h < image1.height(); ++h) {
+ const uchar *sl1 = image1.constScanLine(h);
+ const uchar *sl2 = image2.constScanLine(h);
+ for (int w = 0; w < image1.width(); ++w) {
+ const uchar *s1 = sl1 + w * 4;
+ const uchar *s2 = sl2 + w * 4;
+
+ QColor c1 = QColor::fromCmyk(s1[0], s1[1], s1[2], s1[3]);
+ QColor c2 = QColor::fromRgb(s2[2], s2[1], s2[0]);
+ QVERIFY2(fuzzyCompareColors(c1, c2),
+ qPrintable(QString("images differ in line %1, col %2").arg(h).arg(w)));
}
}
}
@@ -395,6 +401,60 @@ void tst_QImageReader::setScaledSize()
QCOMPARE(image.size(), newSize);
}
+void tst_QImageReader::setScaledSizeOneDimension_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QByteArray>("format");
+
+ QTest::newRow("PNG: kollada") << QString("kollada") << QByteArray("png");
+ QTest::newRow("JPEG: beavis") << QString("beavis") << QByteArray("jpeg");
+ QTest::newRow("GIF: earth") << QString("earth") << QByteArray("gif");
+ QTest::newRow("SVG: rect") << QString("rect") << QByteArray("svg");
+ QTest::newRow("BMP: colorful") << QString("colorful") << QByteArray("bmp");
+ QTest::newRow("XPM: marble") << QString("marble") << QByteArray("xpm");
+ QTest::newRow("PPM: teapot") << QString("teapot") << QByteArray("ppm");
+ QTest::newRow("XBM: gnus") << QString("gnus") << QByteArray("xbm");
+}
+
+void tst_QImageReader::setScaledSizeOneDimension()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QByteArray, format);
+
+ SKIP_IF_UNSUPPORTED(format);
+
+ const QSize originalSize = QImageReader(prefix + fileName).size();
+ QVERIFY(!originalSize.isEmpty());
+
+ auto testScaledSize = [&] (const QSize &scaledSize) {
+ QSize expectedSize = scaledSize;
+ if (scaledSize.width() <= 0)
+ expectedSize.setWidth(qRound(originalSize.width() *
+ (qreal(scaledSize.height()) / originalSize.height())));
+ else if (scaledSize.height() <= 0)
+ expectedSize.setHeight(qRound(originalSize.height() *
+ (qreal(scaledSize.width()) / originalSize.width())));
+
+ QImageReader reader(prefix + fileName);
+ reader.setScaledSize(scaledSize);
+ QImage image = reader.read();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.size(), expectedSize);
+ };
+
+ // downscale
+ testScaledSize(QSize(originalSize.width() / 2, 0));
+ testScaledSize(QSize(originalSize.width() / 2, -1));
+ testScaledSize(QSize(0, originalSize.height() / 2));
+ testScaledSize(QSize(-1, originalSize.height() / 2));
+
+ // upscale
+ testScaledSize(QSize(originalSize.width() * 2, 0));
+ testScaledSize(QSize(originalSize.width() * 2, -1));
+ testScaledSize(QSize(0, originalSize.height() * 2));
+ testScaledSize(QSize(-1, originalSize.height() * 2));
+}
+
void tst_QImageReader::task255627_setNullScaledSize_data()
{
setScaledSize_data();
@@ -510,9 +570,38 @@ void tst_QImageReader::setScaledClipRect()
QImageReader originalReader(prefix + fileName);
originalReader.setScaledSize(QSize(300, 300));
QImage originalImage = originalReader.read();
+ if (format.contains("svg")) {
+ // rendering of subrect may yield slight rounding differences, truncate them away
+ image.convertTo(QImage::Format_RGB444);
+ originalImage.convertTo(QImage::Format_RGB444);
+ }
QCOMPARE(originalImage.copy(newRect), image);
}
+void tst_QImageReader::setFormat()
+{
+ QByteArray ppmImage = "P1 2 2\n1 0\n0 1";
+ QBuffer buf(&ppmImage);
+ QImageReader reader(&buf);
+
+ // read image in autodetected format
+ QCOMPARE(reader.size(), QSize(2,2));
+ buf.close();
+
+ // try reading with non-matching format, must not succeed
+ reader.setDecideFormatFromContent(false);
+ reader.setFormat("bmp");
+ reader.setDevice(&buf);
+ QCOMPARE(reader.size(), QSize());
+ buf.close();
+
+ // read with manually set matching format
+ reader.setFormat("ppm");
+ reader.setDevice(&buf);
+ QCOMPARE(reader.size(), QSize(2,2));
+ buf.close();
+}
+
void tst_QImageReader::imageFormat_data()
{
QTest::addColumn<QString>("fileName");
@@ -527,7 +616,7 @@ void tst_QImageReader::imageFormat_data()
QTest::newRow("ppm-4") << QString("test.ppm") << QByteArray("ppm") << QImage::Format_RGB32;
QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Grayscale8;
- QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
+ QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_CMYK8888;
QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32;
QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif") << QImage::Format_Invalid;
@@ -588,41 +677,31 @@ void tst_QImageReader::multiWordNamedColorXPM()
QCOMPARE(image.pixel(0, 2), qRgb(255, 250, 205)); // lemon chiffon
}
-void tst_QImageReader::supportedFormats()
+namespace {
+template <typename ForwardIterator>
+bool is_sorted_unique(ForwardIterator first, ForwardIterator last)
{
- QList<QByteArray> formats = QImageReader::supportedImageFormats();
- QList<QByteArray> sortedFormats = formats;
- std::sort(sortedFormats.begin(), sortedFormats.end());
-
- // check that the list is sorted
- QCOMPARE(formats, sortedFormats);
-
- QSet<QByteArray> formatSet;
- foreach (QByteArray format, formats)
- formatSet << format;
+ // a range is sorted with no dups iff each *i < *(i+1), so check that none are >=:
+ return std::adjacent_find(first, last, std::greater_equal<>{}) == last;
+}
+}
- // check that the list does not contain duplicates
- QCOMPARE(formatSet.size(), formats.size());
+void tst_QImageReader::supportedFormats()
+{
+ const QList<QByteArray> formats = QImageReader::supportedImageFormats();
+ auto printOnFailure = qScopeGuard([&] { qDebug() << formats; });
+ QVERIFY(is_sorted_unique(formats.begin(), formats.end()));
+ printOnFailure.dismiss();
}
void tst_QImageReader::supportedMimeTypes()
{
- QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes();
- QList<QByteArray> sortedMimeTypes = mimeTypes;
- std::sort(sortedMimeTypes.begin(), sortedMimeTypes.end());
-
- // check that the list is sorted
- QCOMPARE(mimeTypes, sortedMimeTypes);
-
- QSet<QByteArray> mimeTypeSet;
- foreach (QByteArray mimeType, mimeTypes)
- mimeTypeSet << mimeType;
-
+ const QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes();
+ auto printOnFailure = qScopeGuard([&] { qDebug() << mimeTypes; });
+ QVERIFY(is_sorted_unique(mimeTypes.begin(), mimeTypes.end()));
// check the list as a minimum contains image/bmp
- QVERIFY(mimeTypeSet.contains("image/bmp"));
-
- // check that the list does not contain duplicates
- QCOMPARE(mimeTypeSet.size(), mimeTypes.size());
+ QVERIFY(mimeTypes.contains("image/bmp"));
+ printOnFailure.dismiss();
}
void tst_QImageReader::setBackgroundColor_data()
@@ -667,7 +746,7 @@ void tst_QImageReader::supportsAnimation_data()
QTest::newRow("BMP: colorful") << QString("colorful.bmp") << false;
QTest::newRow("BMP: font") << QString("font.bmp") << false;
QTest::newRow("BMP: signed char") << QString("crash-signed-char.bmp") << false;
- QTest::newRow("BMP: test32bfv4") << QString("test32bfv4.bmp") << false;;
+ QTest::newRow("BMP: test32bfv4") << QString("test32bfv4.bmp") << false;
QTest::newRow("BMP: test32v5") << QString("test32v5.bmp") << false;
QTest::newRow("XPM: marble") << QString("marble.xpm") << false;
QTest::newRow("PNG: kollada") << QString("kollada.png") << false;
@@ -1617,43 +1696,56 @@ void tst_QImageReader::supportsOption_data()
QTest::addColumn<QIntList>("options");
QTest::newRow("png") << QString("black.png")
- << (QIntList() << QImageIOHandler::Gamma
- << QImageIOHandler::Description
- << QImageIOHandler::Quality
- << QImageIOHandler::CompressionRatio
- << QImageIOHandler::Size
- << QImageIOHandler::ScaledSize);
+ << QIntList{
+ QImageIOHandler::Gamma,
+ QImageIOHandler::Description,
+ QImageIOHandler::Quality,
+ QImageIOHandler::CompressionRatio,
+ QImageIOHandler::Size,
+ QImageIOHandler::ScaledSize,
+ QImageIOHandler::ImageFormat,
+ };
}
void tst_QImageReader::supportsOption()
{
QFETCH(QString, fileName);
- QFETCH(QIntList, options);
-
- QSet<QImageIOHandler::ImageOption> allOptions;
- allOptions << QImageIOHandler::Size
- << QImageIOHandler::ClipRect
- << QImageIOHandler::Description
- << QImageIOHandler::ScaledClipRect
- << QImageIOHandler::ScaledSize
- << QImageIOHandler::CompressionRatio
- << QImageIOHandler::Gamma
- << QImageIOHandler::Quality
- << QImageIOHandler::Name
- << QImageIOHandler::SubType
- << QImageIOHandler::IncrementalReading
- << QImageIOHandler::Endianness
- << QImageIOHandler::Animation
- << QImageIOHandler::BackgroundColor;
+ QFETCH(const QIntList, options);
QImageReader reader(prefix + fileName);
- for (int i = 0; i < options.size(); ++i) {
- QVERIFY(reader.supportsOption(QImageIOHandler::ImageOption(options.at(i))));
- allOptions.remove(QImageIOHandler::ImageOption(options.at(i)));
- }
- foreach (QImageIOHandler::ImageOption option, allOptions)
- QVERIFY(!reader.supportsOption(option));
+ for (int i = 0; ; ++i) {
+ // this switch ensures the compiler warns when we miss an enumerator [-Wswitch]
+ // do _not_ add a default case!
+ switch (const auto o = QImageIOHandler::ImageOption(i)) {
+ case QImageIOHandler::Size:
+ case QImageIOHandler::ClipRect:
+ case QImageIOHandler::Description:
+ case QImageIOHandler::ScaledClipRect:
+ case QImageIOHandler::ScaledSize:
+ case QImageIOHandler::CompressionRatio:
+ case QImageIOHandler::Gamma:
+ case QImageIOHandler::Quality:
+ case QImageIOHandler::Name:
+ case QImageIOHandler::SubType:
+ case QImageIOHandler::IncrementalReading:
+ case QImageIOHandler::Endianness:
+ case QImageIOHandler::Animation:
+ case QImageIOHandler::BackgroundColor:
+ case QImageIOHandler::ImageFormat:
+ case QImageIOHandler::SupportedSubTypes:
+ case QImageIOHandler::OptimizedWrite:
+ case QImageIOHandler::ProgressiveScanWrite:
+ case QImageIOHandler::ImageTransformation:
+ {
+ auto printOnFailure = qScopeGuard([&] { qDebug("failed at %d", i); });
+ QCOMPARE(reader.supportsOption(o), options.contains(i));
+ printOnFailure.dismiss();
+ continue; // ... as long as `i` represents a valid ImageOption value
+ }
+ }
+ break; // ... once `i` no longer represents a valid ImageOption value
+ }
}
void tst_QImageReader::autoDetectImageFormat()
@@ -1822,13 +1914,13 @@ void tst_QImageReader::testIgnoresFormatAndExtension()
SKIP_IF_UNSUPPORTED(expected.toLatin1());
- QList<QByteArray> formats = QImageReader::supportedImageFormats();
+ const QList<QByteArray> formats = QImageReader::supportedImageFormats();
QString fileNameBase = prefix + name + QLatin1Char('.');
QString tempPath = m_temporaryDir.path();
if (!tempPath.endsWith(QLatin1Char('/')))
tempPath += QLatin1Char('/');
- foreach (const QByteArray &f, formats) {
+ for (const QByteArray &f : formats) {
if (f == extension.toLocal8Bit())
continue;
@@ -1953,6 +2045,10 @@ void tst_QImageReader::readText_data()
void tst_QImageReader::readText()
{
+#ifdef QT_NO_IMAGEIO_TEXT_LOADING
+ QSKIP("Reading text from image is configured away");
+#endif
+
QFETCH(QString, fileName);
QFETCH(QString, key);
QFETCH(QString, text);
@@ -1974,19 +2070,31 @@ void tst_QImageReader::preserveTexts_data()
for (int c = 0xa0; c <= 0xff; c++)
latin1set.append(QLatin1Char(c));
- QStringList fileNames;
- fileNames << QLatin1String(":/images/kollada.png")
- << QLatin1String(":/images/txts.jpg");
- foreach (const QString &fileName, fileNames) {
- QTest::newRow("Simple") << fileName << "simpletext";
- QTest::newRow("Whitespace") << fileName << " A text with whitespace ";
- QTest::newRow("Newline") << fileName << "A text\nwith newlines\n";
- QTest::newRow("Double newlines") << fileName << "A text\n\nwith double newlines\n\n";
- QTest::newRow("Long") << fileName << QString("A rather long text, at least after many repetitions. ").repeated(100);
- QTest::newRow("All Latin1 chars") << fileName << latin1set;
+ const QList<QLatin1StringView> fileNames{
+ QLatin1StringView(":/images/kollada.png"),
+ QLatin1StringView(":/images/txts.jpg")
+ // Common prefix of length 9 before file names: ":/images/", skipped below by + 9.
+ };
+ for (const auto &fileName : fileNames) {
+ QTest::addRow("Simple %s", fileName.data() + 9)
+ << QString(fileName) << "simpletext";
+ QTest::addRow("Whitespace %s", fileName.data() + 9)
+ << QString(fileName) << " A text with whitespace ";
+ QTest::addRow("Newline %s", fileName.data() + 9)
+ << QString(fileName) << "A text\nwith newlines\n";
+ QTest::addRow("Double newlines %s", fileName.data() + 9)
+ << QString(fileName) << "A text\n\nwith double newlines\n\n";
+ QTest::addRow("Long %s", fileName.data() + 9)
+ << QString(fileName)
+ << QString("A rather long text, at least after many repetitions. ").repeated(100);
+ QTest::addRow("All Latin1 chars %s", fileName.data() + 9)
+ << QString(fileName) << latin1set;
#if 0
// Depends on iTXt support in libpng
- QTest::newRow("Multibyte string") << fileName << QString::fromUtf8("\341\233\222\341\233\226\341\232\251\341\232\271\341\232\242\341\233\232\341\232\240");
+ QTest::addRow("Multibyte string %s", fileName.data() + 9)
+ << QString(fileName)
+ << QString::fromUtf8("\341\233\222\341\233\226\341\232\251\341\232"
+ "\271\341\232\242\341\233\232\341\232\240");
#endif
}
}
@@ -1994,6 +2102,10 @@ void tst_QImageReader::preserveTexts_data()
void tst_QImageReader::preserveTexts()
{
+#ifdef QT_NO_IMAGEIO_TEXT_LOADING
+ QSKIP("Reading text from image is configured away");
+#endif
+
QFETCH(QString, fileName);
QByteArray format = fileName.right(3).toLatin1();
QFETCH(QString, text);
diff --git a/tests/auto/gui/image/qimagewriter/CMakeLists.txt b/tests/auto/gui/image/qimagewriter/CMakeLists.txt
index e74321731f..06273ce7e4 100644
--- a/tests/auto/gui/image/qimagewriter/CMakeLists.txt
+++ b/tests/auto/gui/image/qimagewriter/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qimagewriter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qimagewriter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qimagewriter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -13,38 +20,8 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qimagewriter
SOURCES
tst_qimagewriter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
TESTDATA ${test_data}
)
-#### Keys ignored in scope 1:.:.:qimagewriter.pro:<TRUE>:
-# MOC_DIR = "tmp"
-
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(qimagewriter_resource_files
- "images/YCbCr_cmyk.jpg"
- "images/YCbCr_rgb.jpg"
- "images/beavis.jpg"
- "images/colorful.bmp"
- "images/earth.gif"
- "images/font.bmp"
- "images/gnus.xbm"
- "images/kollada.png"
- "images/marble.xpm"
- "images/ship63.pbm"
- "images/teapot.ppm"
- "images/trolltech.gif"
- )
-
- qt_internal_add_resource(tst_qimagewriter "qimagewriter"
- PREFIX
- "/"
- FILES
- ${qimagewriter_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/image/qimagewriter/qimagewriter.qrc b/tests/auto/gui/image/qimagewriter/qimagewriter.qrc
deleted file mode 100644
index 29b036e303..0000000000
--- a/tests/auto/gui/image/qimagewriter/qimagewriter.qrc
+++ /dev/null
@@ -1,16 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>images/beavis.jpg</file>
- <file>images/colorful.bmp</file>
- <file>images/earth.gif</file>
- <file>images/font.bmp</file>
- <file>images/gnus.xbm</file>
- <file>images/kollada.png</file>
- <file>images/marble.xpm</file>
- <file>images/ship63.pbm</file>
- <file>images/teapot.ppm</file>
- <file>images/trolltech.gif</file>
- <file>images/YCbCr_cmyk.jpg</file>
- <file>images/YCbCr_rgb.jpg</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
index 6ce8060306..1059cc48ab 100644
--- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
+++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QDebug>
@@ -127,7 +102,7 @@ void tst_QImageWriter::getSetCheck()
QCOMPARE((QIODevice *) var1, obj1.device());
// The class should possibly handle a 0-pointer as a device, since
- // there is a default contructor, so it's "handling" a 0 device by default.
+ // there is a default constructor, so it's "handling" a 0 device by default.
// For example: QMovie::setDevice(0) works just fine
obj1.setDevice((QIODevice *)0);
QCOMPARE((QIODevice *) 0, obj1.device());
@@ -281,6 +256,8 @@ void tst_QImageWriter::writeImage2()
QFETCH(QByteArray, format);
QFETCH(QImage, image);
+ SKIP_IF_UNSUPPORTED(format);
+
//we reduce the scope of writer so that it closes the associated file
// and QFile::remove can actually work
{
diff --git a/tests/auto/gui/image/qmovie/CMakeLists.txt b/tests/auto/gui/image/qmovie/CMakeLists.txt
index 545ee481d1..52e0a347c4 100644
--- a/tests/auto/gui/image/qmovie/CMakeLists.txt
+++ b/tests/auto/gui/image/qmovie/CMakeLists.txt
@@ -1,20 +1,28 @@
-# Generated from qmovie.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmovie Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmovie LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
- animations/*)
+ animations/* multiframe/*)
list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qmovie
SOURCES
tst_qmovie.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
+ Qt::TestPrivate
TESTDATA ${test_data}
)
@@ -23,6 +31,7 @@ set(resources_resource_files
"animations/comicsecard.gif"
"animations/corrupt.gif"
"animations/trolltech.gif"
+ "multiframe/Obj_N2_Internal_Mem.ico"
)
qt_internal_add_resource(tst_qmovie "resources"
@@ -32,16 +41,11 @@ qt_internal_add_resource(tst_qmovie "resources"
${resources_resource_files}
)
-
-#### Keys ignored in scope 1:.:.:qmovie.pro:<TRUE>:
-# MOC_DIR = "tmp"
-# QT_FOR_CONFIG = "gui-private"
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qmovie CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico
new file mode 100644
index 0000000000..8da119efdd
--- /dev/null
+++ b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico
Binary files differ
diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp
index c1abeccba5..c2171d4209 100644
--- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp
+++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp
@@ -1,41 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QTestEventLoop>
#include <QSignalSpy>
+#include <QtTest/private/qpropertytesthelper_p.h>
#include <QIODevice>
#ifndef QT_NO_WIDGETS
#include <QLabel>
#endif
#include <QMovie>
+#include <QProperty>
class tst_QMovie : public QObject
{
@@ -65,6 +42,13 @@ private slots:
#endif
void emptyMovie();
void bindings();
+ void automatedBindings();
+#ifndef QT_NO_ICO
+ void multiFrameImage();
+#endif
+
+ void setScaledSize_data();
+ void setScaledSize();
};
// Testing get/set functions
@@ -180,7 +164,7 @@ void tst_QMovie::playMovie()
movie.start();
QCOMPARE(movie.state(), QMovie::Running);
QTestEventLoop::instance().enterLoop(2);
- QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(finishedSpy.size(), 0);
QCOMPARE(movie.state(), QMovie::Running);
QCOMPARE(movie.currentFrameNumber(), 0);
}
@@ -263,5 +247,78 @@ void tst_QMovie::bindings()
QCOMPARE(cacheModeObserver, QMovie::CacheAll);
}
+void tst_QMovie::automatedBindings()
+{
+ QMovie movie;
+
+ QTestPrivate::testReadWritePropertyBasics(movie, 50, 100, "speed");
+ if (QTest::currentTestFailed()) {
+ qDebug("Failed property test for QMovie::speed");
+ return;
+ }
+
+ QTestPrivate::testReadWritePropertyBasics(movie, QMovie::CacheAll, QMovie::CacheNone,
+ "cacheMode");
+ if (QTest::currentTestFailed()) {
+ qDebug("Failed property test for QMovie::cacheMode");
+ return;
+ }
+}
+
+#ifndef QT_NO_ICO
+/*! \internal
+ Test behavior of QMovie with image formats that are multi-frame,
+ but not normally intended as animation formats (such as tiff and ico).
+*/
+void tst_QMovie::multiFrameImage()
+{
+ QMovie movie(QFINDTESTDATA("multiframe/Obj_N2_Internal_Mem.ico"));
+ const int expectedFrameCount = 9;
+
+ QCOMPARE(movie.frameCount(), expectedFrameCount);
+ QVERIFY(movie.isValid());
+ movie.setSpeed(1000); // speed up the test: play at 10 FPS (1000% of normal)
+ QElapsedTimer playTimer;
+ QSignalSpy frameChangedSpy(&movie, &QMovie::frameChanged);
+ QSignalSpy errorSpy(&movie, &QMovie::error);
+ QSignalSpy finishedSpy(&movie, &QMovie::finished);
+ playTimer.start();
+ movie.start();
+ QTRY_COMPARE(finishedSpy.size(), 1);
+ QCOMPARE_GE(playTimer.elapsed(), 100 * expectedFrameCount);
+ QCOMPARE(movie.nextFrameDelay(), 100);
+ QCOMPARE(errorSpy.size(), 0);
+ QCOMPARE(frameChangedSpy.size(), expectedFrameCount);
+}
+#endif
+
+void tst_QMovie::setScaledSize_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QSize>("scaledSize");
+ QTest::addColumn<QSize>("expectedSize");
+
+ QTest::newRow("trolltech (50, 50)") << QString("animations/trolltech.gif") << QSize(50, 50) << QSize(50, 50);
+ QTest::newRow("trolltech (400, 400)") << QString("animations/trolltech.gif") << QSize(400, 400) << QSize(400, 400);
+ QTest::newRow("trolltech (50, 0)") << QString("animations/trolltech.gif") << QSize(50, 0) << QSize(50, 25);
+ QTest::newRow("trolltech (50, -1)") << QString("animations/trolltech.gif") << QSize(50, -1) << QSize(50, 25);
+ QTest::newRow("trolltech (0, 50)") << QString("animations/trolltech.gif") << QSize(0, 50) << QSize(100, 50);
+ QTest::newRow("trolltech (-1, 50)") << QString("animations/trolltech.gif") << QSize(-1, 50) << QSize(100, 50);
+}
+
+void tst_QMovie::setScaledSize()
+{
+ QFETCH(QString, fileName);
+ QFETCH(QSize, scaledSize);
+ QFETCH(QSize, expectedSize);
+
+ QMovie movie(QFINDTESTDATA(fileName));
+ movie.setScaledSize(scaledSize);
+
+ movie.start();
+ QCOMPARE(movie.currentFrameNumber(), 0);
+ QCOMPARE(movie.currentImage().size(), expectedSize);
+}
+
QTEST_MAIN(tst_QMovie)
#include "tst_qmovie.moc"
diff --git a/tests/auto/gui/image/qpicture/CMakeLists.txt b/tests/auto/gui/image/qpicture/CMakeLists.txt
index 29bf68fa06..30b0aafd11 100644
--- a/tests/auto/gui/image/qpicture/CMakeLists.txt
+++ b/tests/auto/gui/image/qpicture/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpicture.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpicture Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpicture LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpicture
SOURCES
tst_qpicture.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
index 25e284a6ec..2fa4436154 100644
--- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp
+++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/image/qpixmap/CMakeLists.txt b/tests/auto/gui/image/qpixmap/CMakeLists.txt
index 1946715047..8531ef5b7b 100644
--- a/tests/auto/gui/image/qpixmap/CMakeLists.txt
+++ b/tests/auto/gui/image/qpixmap/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qpixmap.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpixmap Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpixmap LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -25,7 +32,7 @@ list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qpixmap
SOURCES
tst_qpixmap.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
@@ -95,13 +102,13 @@ qt_internal_add_resource(tst_qpixmap "qpixmap"
#####################################################################
qt_internal_extend_target(tst_qpixmap CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
Qt::WidgetsPrivate
)
qt_internal_extend_target(tst_qpixmap CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
gdi32
user32
)
diff --git a/tests/auto/gui/image/qpixmap/qpixmap.qrc b/tests/auto/gui/image/qpixmap/qpixmap.qrc
deleted file mode 100644
index 3965622dba..0000000000
--- a/tests/auto/gui/image/qpixmap/qpixmap.qrc
+++ /dev/null
@@ -1,51 +0,0 @@
-<RCC>
- <qresource>
- <file>loadFromData/designer_argb32.png</file>
- <file>loadFromData/designer_indexed8_no_alpha_animated.gif</file>
- <file>loadFromData/designer_indexed8_no_alpha.gif</file>
- <file>loadFromData/designer_indexed8_no_alpha.png</file>
- <file>loadFromData/designer_indexed8_with_alpha_animated.gif</file>
- <file>loadFromData/designer_indexed8_with_alpha.gif</file>
- <file>loadFromData/designer_indexed8_with_alpha.png</file>
- <file>loadFromData/designer_rgb32.jpg</file>
- <file>loadFromData/designer_rgb32.png</file>
- <file>convertFromImage/task31722_1/img1.png</file>
- <file>convertFromImage/task31722_1/img2.png</file>
- <file>convertFromToHICON/icon_8bpp_16x16.png</file>
- <file>convertFromToHICON/icon_8bpp_32x32.png</file>
- <file>convertFromToHICON/icon_8bpp_48x48.png</file>
- <file>convertFromToHICON/icon_8bpp.ico</file>
- <file>convertFromToHICON/icon_32bpp_16x16.png</file>
- <file>convertFromToHICON/icon_32bpp_32x32.png</file>
- <file>convertFromToHICON/icon_32bpp_48x48.png</file>
- <file>convertFromToHICON/icon_32bpp_256x256.png</file>
- <file>convertFromToHICON/icon_32bpp.ico</file>
- <file>convertFromImage/task31722_0/img1.png</file>
- <file>convertFromImage/task31722_0/img2.png</file>
- <file>images/designer.png</file>
- <file>images/dx_0_dy_0_50_50_100_100.png</file>
- <file>images/dx_0_dy_0_null.png</file>
- <file>images/dx_0_dy_0_x_y_w_h.png</file>
- <file>images/dx_0_dy_-10_50_50_100_100.png</file>
- <file>images/dx_0_dy_10_50_50_100_100.png</file>
- <file>images/dx_0_dy_-10_x_y_w_h.png</file>
- <file>images/dx_0_dy_10_x_y_w_h.png</file>
- <file>images/dx_0_dy_-128_x_y_w_h.png</file>
- <file>images/dx_0_dy_128_x_y_w_h.png</file>
- <file>images/dx_0_dy_1_null.png</file>
- <file>images/dx_-10_dy_0_50_50_100_100.png</file>
- <file>images/dx_10_dy_0_50_50_100_100.png</file>
- <file>images/dx_-10_dy_0_x_y_w_h.png</file>
- <file>images/dx_10_dy_0_x_y_w_h.png</file>
- <file>images/dx_-10_dy_-10_50_50_100_100.png</file>
- <file>images/dx_10_dy_10_50_50_100_100.png</file>
- <file>images/dx_-10_dy_-10_x_y_w_h.png</file>
- <file>images/dx_10_dy_10_x_y_w_h.png</file>
- <file>images/dx_-128_dy_0_x_y_w_h.png</file>
- <file>images/dx_128_dy_0_x_y_w_h.png</file>
- <file>images/dx_128_dy_128_64_64_128_128.png</file>
- <file>images/dx_-128_dy_-128_x_y_w_h.png</file>
- <file>images/dx_128_dy_128_x_y_w_h.png</file>
- <file>images/dx_1_dy_0_null.png</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
index 6c6c282af4..137439d98b 100644
--- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QSet>
#include <QTemporaryFile>
@@ -46,7 +21,7 @@
#include <private/qdrawhelper_p.h>
#ifdef Q_OS_WIN
-#include <windows.h>
+#include <qt_windows.h>
#endif
@@ -1448,7 +1423,7 @@ void tst_QPixmap::loadFromDataImage()
QPixmap pixmapWithCopy = QPixmap::fromImage(imageRef);
QFile file(imagePath);
- file.open(QIODevice::ReadOnly);
+ QVERIFY(file.open(QIODevice::ReadOnly));
QByteArray rawData = file.readAll();
QPixmap directLoadingPixmap;
diff --git a/tests/auto/gui/image/qpixmapcache/CMakeLists.txt b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt
index 9e99842e6e..444de9cb3e 100644
--- a/tests/auto/gui/image/qpixmapcache/CMakeLists.txt
+++ b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qpixmapcache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpixmapcache Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpixmapcache LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpixmapcache
SOURCES
tst_qpixmapcache.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
index a87ec5d025..8384a46491 100644
--- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
@@ -1,32 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#define Q_TEST_QPIXMAPCACHE
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -34,6 +7,16 @@
#include <qpixmapcache.h>
#include "private/qpixmapcache_p.h"
+#include <functional>
+
+QT_BEGIN_NAMESPACE // The test requires QT_BUILD_INTERNAL
+Q_AUTOTEST_EXPORT void qt_qpixmapcache_flush_detached_pixmaps();
+Q_AUTOTEST_EXPORT int qt_qpixmapcache_qpixmapcache_total_used();
+Q_AUTOTEST_EXPORT int q_QPixmapCache_keyHashSize();
+QT_END_NAMESPACE
+
+using namespace Qt::StringLiterals;
+
class tst_QPixmapCache : public QObject
{
Q_OBJECT
@@ -50,13 +33,22 @@ private slots:
void setCacheLimit();
void find();
void insert();
+ void failedInsertReturnsInvalidKey();
+#if QT_DEPRECATED_SINCE(6, 6)
void replace();
+#endif
void remove();
void clear();
void pixmapKey();
void noLeak();
+ void clearDoesNotLeakStringKeys();
+ void evictionDoesNotLeakStringKeys();
+ void reducingCacheLimitDoesNotLeakStringKeys();
void strictCacheLimit();
void noCrashOnLargeInsert();
+
+private:
+ void stringLeak_impl(std::function<void()> whenOp);
};
static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
@@ -123,28 +115,32 @@ void tst_QPixmapCache::setCacheLimit()
//The int part of the API
p1 = new QPixmap(2, 3);
QPixmapCache::Key key = QPixmapCache::insert(*p1);
- QVERIFY(QPixmapCache::find(key, p1) != 0);
+ QVERIFY(QPixmapCache::find(key, p1));
delete p1;
QPixmapCache::setCacheLimit(0);
- QVERIFY(QPixmapCache::find(key, p1) == 0);
+ QVERIFY(!QPixmapCache::find(key, p1));
- p1 = new QPixmap(2, 3);
QPixmapCache::setCacheLimit(1000);
- QPixmapCache::replace(key, *p1);
- QVERIFY(QPixmapCache::find(key, p1) == 0);
+#if QT_DEPRECATED_SINCE(6, 6)
+ QT_WARNING_PUSH
+ QT_WARNING_DISABLE_DEPRECATED
+ p1 = new QPixmap(2, 3);
+ QVERIFY(!QPixmapCache::replace(key, *p1));
+ QVERIFY(!QPixmapCache::find(key, p1));
delete p1;
+#endif // QT_DEPRECATED_SINCE(6, 6)
//Let check if keys are released when the pixmap cache is
//full or has been flushed.
QPixmapCache::clear();
p1 = new QPixmap(2, 3);
key = QPixmapCache::insert(*p1);
- QVERIFY(QPixmapCache::find(key, p1) != 0);
+ QVERIFY(QPixmapCache::find(key, p1));
p1->detach(); // dectach so that the cache thinks no-one is using it.
QPixmapCache::setCacheLimit(0);
- QVERIFY(QPixmapCache::find(key, p1) == 0);
+ QVERIFY(!QPixmapCache::find(key, p1));
QPixmapCache::setCacheLimit(1000);
key = QPixmapCache::insert(*p1);
QVERIFY(key.isValid());
@@ -158,7 +154,7 @@ void tst_QPixmapCache::setCacheLimit()
QPixmap p2;
p1 = new QPixmap(2, 3);
key = QPixmapCache::insert(*p1);
- QVERIFY(QPixmapCache::find(key, &p2) != 0);
+ QVERIFY(QPixmapCache::find(key, &p2));
//we flush the cache
p1->detach();
p2.detach();
@@ -166,8 +162,8 @@ void tst_QPixmapCache::setCacheLimit()
QPixmapCache::setCacheLimit(1000);
QPixmapCache::Key key2 = QPixmapCache::insert(*p1);
QCOMPARE(getPrivate(key2)->key, 1);
- QVERIFY(QPixmapCache::find(key, &p2) == 0);
- QVERIFY(QPixmapCache::find(key2, &p2) != 0);
+ QVERIFY(!QPixmapCache::find(key, &p2));
+ QVERIFY(QPixmapCache::find(key2, &p2));
QCOMPARE(p2, *p1);
delete p1;
@@ -185,12 +181,12 @@ void tst_QPixmapCache::setCacheLimit()
p1->detach();
QPixmapCache::Key key3 = QPixmapCache::insert(*p1);
p1->detach();
- QPixmapCache::flushDetachedPixmaps();
+ qt_qpixmapcache_flush_detached_pixmaps();
key2 = QPixmapCache::insert(*p1);
QCOMPARE(getPrivate(key2)->key, 1);
//This old key is not valid anymore after the flush
QVERIFY(!key.isValid());
- QVERIFY(QPixmapCache::find(key, &p2) == 0);
+ QVERIFY(!QPixmapCache::find(key, &p2));
delete p1;
}
@@ -228,7 +224,7 @@ void tst_QPixmapCache::find()
QPixmapCache::insert(p5);
//at that time the first key has been erase because no more place in the cache
- QVERIFY(QPixmapCache::find(key, &p1) == 0);
+ QVERIFY(!QPixmapCache::find(key, &p1));
QVERIFY(!key.isValid());
}
@@ -287,6 +283,7 @@ void tst_QPixmapCache::insert()
for (int i = 0; i < numberOfKeys; ++i) {
QPixmap p3(10,10);
keys.append(QPixmapCache::insert(p3));
+ QVERIFY(keys.back().isValid());
}
num = 0;
@@ -300,6 +297,35 @@ void tst_QPixmapCache::insert()
QVERIFY(num <= estimatedNum);
}
+void tst_QPixmapCache::failedInsertReturnsInvalidKey()
+{
+ //
+ // GIVEN: a pixmap whose memory footprint exceeds the cache's limit:
+ //
+ QPixmapCache::setCacheLimit(20);
+
+ QPixmap pm(256, 256);
+ pm.fill(Qt::transparent);
+ QCOMPARE_GT(pm.width() * pm.height() * pm.depth() / 8,
+ QPixmapCache::cacheLimit() * 1024);
+
+ //
+ // WHEN: trying to add this pixmap to the cache
+ //
+ const auto success = QPixmapCache::insert(u"foo"_s, pm); // QString API
+ { QPixmap r; QVERIFY(!QPixmapCache::find(u"foo"_s, &r)); }
+ const auto key = QPixmapCache::insert(pm); // "int" API
+
+ //
+ // THEN: failure is reported to the user
+ //
+ QVERIFY(!key.isValid()); // "int" API
+ QVERIFY(!success); // QString API
+}
+
+#if QT_DEPRECATED_SINCE(6, 6)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
void tst_QPixmapCache::replace()
{
//The int part of the API
@@ -328,6 +354,8 @@ void tst_QPixmapCache::replace()
//Broken keys
QCOMPARE(QPixmapCache::replace(QPixmapCache::Key(), p2), false);
}
+QT_WARNING_POP
+#endif // QT_DEPRECATED_SINCE(6, 6)
void tst_QPixmapCache::remove()
{
@@ -361,11 +389,11 @@ void tst_QPixmapCache::remove()
QVERIFY(p1.toImage() == p1.toImage()); // sanity check
QPixmapCache::remove(key);
- QVERIFY(QPixmapCache::find(key, &p1) == 0);
+ QVERIFY(!QPixmapCache::find(key, &p1));
//Broken key
QPixmapCache::remove(QPixmapCache::Key());
- QVERIFY(QPixmapCache::find(QPixmapCache::Key(), &p1) == 0);
+ QVERIFY(!QPixmapCache::find(QPixmapCache::Key(), &p1));
//Test if keys are release
QPixmapCache::clear();
@@ -379,7 +407,7 @@ void tst_QPixmapCache::remove()
QPixmapCache::clear();
key = QPixmapCache::insert(p1);
QCOMPARE(getPrivate(key)->key, 1);
- QVERIFY(QPixmapCache::find(key, &p1) != 0);
+ QVERIFY(QPixmapCache::find(key, &p1));
QPixmapCache::remove(key);
QCOMPARE(p1.isDetached(), true);
@@ -389,8 +417,8 @@ void tst_QPixmapCache::remove()
QPixmapCache::insert("red", p1);
key = QPixmapCache::insert(p1);
QPixmapCache::remove(key);
- QVERIFY(QPixmapCache::find(key, &p1) == 0);
- QVERIFY(QPixmapCache::find("red", &p1) != 0);
+ QVERIFY(!QPixmapCache::find(key, &p1));
+ QVERIFY(QPixmapCache::find("red", &p1));
}
void tst_QPixmapCache::clear()
@@ -434,7 +462,7 @@ void tst_QPixmapCache::clear()
QPixmapCache::clear();
for (int k = 0; k < numberOfKeys; ++k) {
- QVERIFY(QPixmapCache::find(keys.at(k), &p1) == 0);
+ QVERIFY(!QPixmapCache::find(keys.at(k), &p1));
QVERIFY(!keys[k].isValid());
}
}
@@ -483,10 +511,6 @@ void tst_QPixmapCache::pixmapKey()
QVERIFY(!getPrivate(key8));
}
-QT_BEGIN_NAMESPACE
-extern int q_QPixmapCache_keyHashSize();
-QT_END_NAMESPACE
-
void tst_QPixmapCache::noLeak()
{
QPixmapCache::Key key;
@@ -503,6 +527,68 @@ void tst_QPixmapCache::noLeak()
QCOMPARE(oldSize, newSize);
}
+void tst_QPixmapCache::clearDoesNotLeakStringKeys()
+{
+ stringLeak_impl([] { QPixmapCache::clear(); });
+}
+
+void tst_QPixmapCache::evictionDoesNotLeakStringKeys()
+{
+ stringLeak_impl([] {
+ // fill the cache with other pixmaps to force eviction of "our" pixmap:
+ constexpr int Iterations = 10;
+ for (int i = 0; i < Iterations; ++i) {
+ QPixmap pm(64, 64);
+ pm.fill(Qt::transparent);
+ [[maybe_unused]] auto r = QPixmapCache::insert(pm);
+ }
+ });
+}
+
+void tst_QPixmapCache::reducingCacheLimitDoesNotLeakStringKeys()
+{
+ stringLeak_impl([] {
+ QPixmapCache::setCacheLimit(0);
+ });
+}
+
+void tst_QPixmapCache::stringLeak_impl(std::function<void()> whenOp)
+{
+ QVERIFY(whenOp);
+
+ QPixmapCache::setCacheLimit(20); // 20KiB
+ //
+ // GIVEN: a QPixmap with QString key `key` in QPixmapCache
+ //
+ QString key;
+ {
+ QPixmap pm(64, 64);
+ QCOMPARE_LT(pm.width() * pm.height() * std::ceil(pm.depth() / 8.0),
+ QPixmapCache::cacheLimit() * 1024);
+ pm.fill(Qt::transparent);
+ key = u"theKey"_s.repeated(20); // avoid eventual QString SSO
+ QVERIFY(key.isDetached());
+ QPixmapCache::insert(key, pm);
+ }
+ QVERIFY(!key.isDetached()); // was saved inside QPixmapCache
+
+ //
+ // WHEN: performing the given operation
+ //
+ whenOp();
+ if (QTest::currentTestFailed())
+ return;
+
+ //
+ // THEN: `key` is no longer referenced by QPixmapCache:
+ //
+ QVERIFY(key.isDetached());
+ // verify that the pixmap is really gone from the cache
+ // (do it after the key check, because QPixmapCache cleans up `key` on a failed lookup)
+ QPixmap r;
+ QVERIFY(!QPixmapCache::find(key, &r));
+}
+
void tst_QPixmapCache::strictCacheLimit()
{
@@ -524,7 +610,7 @@ void tst_QPixmapCache::strictCacheLimit()
QPixmapCache::insert(id + "-b", pixmap);
}
- QVERIFY(QPixmapCache::totalUsed() <= limit);
+ QVERIFY(qt_qpixmapcache_qpixmapcache_total_used() <= limit);
}
void tst_QPixmapCache::noCrashOnLargeInsert()
diff --git a/tests/auto/gui/itemmodels/CMakeLists.txt b/tests/auto/gui/itemmodels/CMakeLists.txt
index 69b6cb0e22..4c25418ef1 100644
--- a/tests/auto/gui/itemmodels/CMakeLists.txt
+++ b/tests/auto/gui/itemmodels/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from itemmodels.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qstandarditem)
if(TARGET Qt::Widgets)
diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST b/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST
index ae8a64dc1f..4119afce84 100644
--- a/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST
+++ b/tests/auto/gui/itemmodels/qfilesystemmodel/BLACKLIST
@@ -3,6 +3,3 @@ ubuntu
b2qt
[specialFiles]
b2qt
-# QTBUG-87427
-[specialFiles]
-android
diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt
index 31fd8ca32d..85fb4fe2e1 100644
--- a/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt
+++ b/tests/auto/gui/itemmodels/qfilesystemmodel/CMakeLists.txt
@@ -1,25 +1,23 @@
-# Generated from qfilesystemmodel.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfilesystemmodel Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfilesystemmodel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qfilesystemmodel
SOURCES
tst_qfilesystemmodel.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::Widgets
Qt::WidgetsPrivate
Qt::TestPrivate
)
-
-## Scopes:
-#####################################################################
-
-#### Keys ignored in scope 2:.:.:qfilesystemmodel.pro:WIN32:
-# testcase.timeout = "900"
-
-#### Keys ignored in scope 3:.:.:qfilesystemmodel.pro:MACOS:
-# testcase.timeout = "900"
diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
index b6f6328acd..8ef0b6272a 100644
--- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -45,6 +20,7 @@
#include <QStyle>
#include <QtGlobal>
#include <QTemporaryDir>
+#include <QAbstractItemModelTester>
#if defined(Q_OS_WIN)
# include <qt_windows.h> // for SetFileAttributes
#endif
@@ -52,6 +28,9 @@
#include <algorithm>
+using namespace Qt::StringLiterals;
+using namespace std::chrono;
+
#define WAITTIME 1000
// Will try to wait for the condition while allowing event processing
@@ -86,6 +65,7 @@ private slots:
void rootPath();
void readOnly();
void iconProvider();
+ void nullIconProvider();
void rowCount();
@@ -101,6 +81,8 @@ private slots:
void filters_data();
void filters();
+ void showFilesOnly();
+
void nameFilters();
void setData_data();
@@ -172,6 +154,8 @@ void tst_QFileSystemModel::indexPath()
{
#if !defined(Q_OS_WIN)
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
int depth = QDir::currentPath().count('/');
model->setRootPath(QDir::currentPath());
QString backPath;
@@ -186,12 +170,14 @@ void tst_QFileSystemModel::indexPath()
void tst_QFileSystemModel::rootPath()
{
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QCOMPARE(model->rootPath(), QString(QDir().path()));
QSignalSpy rootChanged(model.data(), &QFileSystemModel::rootPathChanged);
QModelIndex root = model->setRootPath(model->rootPath());
root = model->setRootPath("this directory shouldn't exist");
- QCOMPARE(rootChanged.count(), 0);
+ QCOMPARE(rootChanged.size(), 0);
QString oldRootPath = model->rootPath();
const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
@@ -208,48 +194,50 @@ void tst_QFileSystemModel::rootPath()
QTRY_VERIFY(model->rowCount(root) >= 0);
QCOMPARE(model->rootPath(), QString(documentPath));
- QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1);
+ QCOMPARE(rootChanged.size(), oldRootPath == model->rootPath() ? 0 : 1);
QCOMPARE(model->rootDirectory().absolutePath(), documentPath);
model->setRootPath(QDir::rootPath());
- int oldCount = rootChanged.count();
+ int oldCount = rootChanged.size();
oldRootPath = model->rootPath();
root = model->setRootPath(documentPath + QLatin1String("/."));
QTRY_VERIFY(model->rowCount(root) >= 0);
QCOMPARE(model->rootPath(), documentPath);
- QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1);
+ QCOMPARE(rootChanged.size(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1);
QCOMPARE(model->rootDirectory().absolutePath(), documentPath);
QDir newdir = documentPath;
if (newdir.cdUp()) {
- oldCount = rootChanged.count();
+ oldCount = rootChanged.size();
oldRootPath = model->rootPath();
root = model->setRootPath(documentPath + QLatin1String("/.."));
QTRY_VERIFY(model->rowCount(root) >= 0);
QCOMPARE(model->rootPath(), newdir.path());
- QCOMPARE(rootChanged.count(), oldCount + 1);
+ QCOMPARE(rootChanged.size(), oldCount + 1);
QCOMPARE(model->rootDirectory().absolutePath(), newdir.path());
}
#ifdef Q_OS_WIN
// check case insensitive root node on windows, tests QTBUG-71701
- QModelIndex index = model->setRootPath(uR"(\\localhost\c$)"_qs);
+ QModelIndex index = model->setRootPath(uR"(\\localhost\c$)"_s);
QVERIFY(index.isValid());
- QCOMPARE(model->rootPath(), u"//localhost/c$"_qs);
+ QCOMPARE(model->rootPath(), u"//localhost/c$"_s);
- index = model->setRootPath(uR"(\\localhost\C$)"_qs);
+ index = model->setRootPath(uR"(\\localhost\C$)"_s);
QVERIFY(index.isValid());
- QCOMPARE(model->rootPath(), u"//localhost/C$"_qs);
+ QCOMPARE(model->rootPath(), u"//localhost/C$"_s);
- index = model->setRootPath(uR"(\\LOCALHOST\C$)"_qs);
+ index = model->setRootPath(uR"(\\LOCALHOST\C$)"_s);
QVERIFY(index.isValid());
- QCOMPARE(model->rootPath(), u"//LOCALHOST/C$"_qs);
+ QCOMPARE(model->rootPath(), u"//LOCALHOST/C$"_s);
#endif
}
void tst_QFileSystemModel::readOnly()
{
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QCOMPARE(model->isReadOnly(), true);
QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat"));
QVERIFY2(file.open(), qPrintable(file.errorString()));
@@ -261,10 +249,14 @@ void tst_QFileSystemModel::readOnly()
QModelIndex root = model->setRootPath(flatDirTestPath);
QTRY_VERIFY(model->rowCount(root) > 0);
+
+ // ItemIsEditable should change, ItemNeverHasChildren should not change
QVERIFY(!(model->flags(model->index(fileName)) & Qt::ItemIsEditable));
+ QVERIFY(model->flags(model->index(fileName)) & Qt::ItemNeverHasChildren);
model->setReadOnly(false);
QCOMPARE(model->isReadOnly(), false);
QVERIFY(model->flags(model->index(fileName)) & Qt::ItemIsEditable);
+ QVERIFY(model->flags(model->index(fileName)) & Qt::ItemNeverHasChildren);
}
class CustomFileIconProvider : public QFileIconProvider
@@ -299,6 +291,8 @@ private:
void tst_QFileSystemModel::iconProvider()
{
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QVERIFY(model->iconProvider());
QScopedPointer<QFileIconProvider> provider(new QFileIconProvider);
model->setIconProvider(provider.data());
@@ -318,6 +312,19 @@ void tst_QFileSystemModel::iconProvider()
QCOMPARE(myModel->fileIcon(myModel->index(QDir::homePath())).pixmap(50, 50), mb);
}
+void tst_QFileSystemModel::nullIconProvider()
+{
+ QFileSystemModel model;
+ QAbstractItemModelTester tester(&model);
+ tester.setUseFetchMore(false);
+ QVERIFY(model.iconProvider());
+ // No crash when setIconProvider(nullptr) is used
+ model.setIconProvider(nullptr);
+ const auto documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
+ QVERIFY(!documentPaths.isEmpty());
+ model.setRootPath(documentPaths.constFirst());
+}
+
bool tst_QFileSystemModel::createFiles(QFileSystemModel *model, const QString &test_path,
const QStringList &initial_files, int existingFileCount,
const QStringList &initial_dirs)
@@ -408,11 +415,13 @@ void tst_QFileSystemModel::rowCount()
QSignalSpy *spy2 = nullptr;
QSignalSpy *spy3 = nullptr;
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = prepareTestModelRoot(model.data(), flatDirTestPath, &spy2, &spy3);
QVERIFY(root.isValid());
- QVERIFY(spy2 && spy2->count() > 0);
- QVERIFY(spy3 && spy3->count() > 0);
+ QVERIFY(spy2 && spy2->size() > 0);
+ QVERIFY(spy3 && spy3->size() > 0);
}
void tst_QFileSystemModel::rowsInserted_data()
@@ -436,6 +445,8 @@ void tst_QFileSystemModel::rowsInserted()
{
const QString tmp = flatDirTestPath;
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
QVERIFY(root.isValid());
@@ -452,7 +463,7 @@ void tst_QFileSystemModel::rowsInserted()
QVERIFY(createFiles(model.data(), tmp, files, 5));
QTRY_COMPARE(model->rowCount(root), oldCount + count);
int totalRowsInserted = 0;
- for (int i = 0; i < spy0.count(); ++i) {
+ for (int i = 0; i < spy0.size(); ++i) {
int start = spy0[i].value(1).toInt();
int end = spy0[i].value(2).toInt();
totalRowsInserted += end - start + 1;
@@ -461,24 +472,24 @@ void tst_QFileSystemModel::rowsInserted()
const QString expected = ascending == Qt::AscendingOrder ? QStringLiteral("j") : QStringLiteral("b");
QTRY_COMPARE(lastEntry(root), expected);
- if (spy0.count() > 0) {
+ if (spy0.size() > 0) {
if (count == 0)
- QCOMPARE(spy0.count(), 0);
+ QCOMPARE(spy0.size(), 0);
else
- QVERIFY(spy0.count() >= 1);
+ QVERIFY(spy0.size() >= 1);
}
- if (count == 0) QCOMPARE(spy1.count(), 0); else QVERIFY(spy1.count() >= 1);
+ if (count == 0) QCOMPARE(spy1.size(), 0); else QVERIFY(spy1.size() >= 1);
QVERIFY(createFiles(model.data(), tmp, QStringList(".hidden_file"), 5 + count));
if (count != 0)
- QTRY_VERIFY(spy0.count() >= 1);
+ QTRY_VERIFY(spy0.size() >= 1);
else
- QTRY_COMPARE(spy0.count(), 0);
+ QTRY_COMPARE(spy0.size(), 0);
if (count != 0)
- QTRY_VERIFY(spy1.count() >= 1);
+ QTRY_VERIFY(spy1.size() >= 1);
else
- QTRY_COMPARE(spy1.count(), 0);
+ QTRY_COMPARE(spy1.size(), 0);
}
void tst_QFileSystemModel::rowsRemoved_data()
@@ -490,6 +501,8 @@ void tst_QFileSystemModel::rowsRemoved()
{
const QString tmp = flatDirTestPath;
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
QVERIFY(root.isValid());
@@ -507,14 +520,14 @@ void tst_QFileSystemModel::rowsRemoved()
}
for (int i = 0 ; i < 10; ++i) {
if (count != 0) {
- if (i == 10 || spy0.count() != 0) {
- QVERIFY(spy0.count() >= 1);
- QVERIFY(spy1.count() >= 1);
+ if (i == 10 || spy0.size() != 0) {
+ QVERIFY(spy0.size() >= 1);
+ QVERIFY(spy1.size() >= 1);
}
} else {
- if (i == 10 || spy0.count() == 0) {
- QCOMPARE(spy0.count(), 0);
- QCOMPARE(spy1.count(), 0);
+ if (i == 10 || spy0.size() == 0) {
+ QCOMPARE(spy0.size(), 0);
+ QCOMPARE(spy1.size(), 0);
}
}
QStringList lst;
@@ -533,11 +546,11 @@ void tst_QFileSystemModel::rowsRemoved()
QVERIFY(QFile::remove(tmp + QLatin1String("/.c")));
if (count != 0) {
- QVERIFY(spy0.count() >= 1);
- QVERIFY(spy1.count() >= 1);
+ QVERIFY(spy0.size() >= 1);
+ QVERIFY(spy1.size() >= 1);
} else {
- QCOMPARE(spy0.count(), 0);
- QCOMPARE(spy1.count(), 0);
+ QCOMPARE(spy0.size(), 0);
+ QCOMPARE(spy1.size(), 0);
}
}
@@ -552,6 +565,8 @@ void tst_QFileSystemModel::dataChanged()
const QString tmp = flatDirTestPath;
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = prepareTestModelRoot(model.data(), tmp);
QVERIFY(root.isValid());
@@ -567,7 +582,7 @@ void tst_QFileSystemModel::dataChanged()
QTest::qWait(WAITTIME);
- if (count != 0) QVERIFY(spy.count() >= 1); else QCOMPARE(spy.count(), 0);
+ if (count != 0) QVERIFY(spy.size() >= 1); else QCOMPARE(spy.size(), 0);
}
void tst_QFileSystemModel::filters_data()
@@ -612,6 +627,8 @@ void tst_QFileSystemModel::filters()
{
QString tmp = flatDirTestPath;
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QVERIFY(createFiles(model.data(), tmp, QStringList()));
QModelIndex root = model->setRootPath(tmp);
QFETCH(QStringList, files);
@@ -620,7 +637,7 @@ void tst_QFileSystemModel::filters()
QFETCH(QStringList, nameFilters);
QFETCH(int, rowCount);
- if (nameFilters.count() > 0)
+ if (nameFilters.size() > 0)
model->setNameFilters(nameFilters);
model->setNameFilterDisables(false);
model->setFilter(dirFilters);
@@ -632,12 +649,12 @@ void tst_QFileSystemModel::filters()
QDir xFactor(tmp);
QStringList dirEntries;
- if (nameFilters.count() > 0)
+ if (nameFilters.size() > 0)
dirEntries = xFactor.entryList(nameFilters, dirFilters);
else
dirEntries = xFactor.entryList(dirFilters);
- QCOMPARE(dirEntries.count(), rowCount);
+ QCOMPARE(dirEntries.size(), rowCount);
QStringList modelEntries;
@@ -649,7 +666,7 @@ void tst_QFileSystemModel::filters()
QCOMPARE(dirEntries, modelEntries);
#ifdef Q_OS_LINUX
- if (files.count() >= 3 && rowCount >= 3 && rowCount != 5) {
+ if (files.size() >= 3 && rowCount >= 3 && rowCount != 5) {
QString fileName1 = (tmp + '/' + files.at(0));
QString fileName2 = (tmp + '/' + files.at(1));
QString fileName3 = (tmp + '/' + files.at(2));
@@ -675,11 +692,46 @@ void tst_QFileSystemModel::filters()
#endif
}
+void tst_QFileSystemModel::showFilesOnly()
+{
+ QString tmp = flatDirTestPath;
+ QFileSystemModel model;
+ QAbstractItemModelTester tester(&model);
+ tester.setUseFetchMore(false);
+ QVERIFY(createFiles(&model, tmp, QStringList()));
+ const QStringList files{u"a"_s, u"b"_s, u"c"_s};
+ const auto subdir = u"sub_directory"_s;
+ QVERIFY(createFiles(&model, tmp, files, 0, {subdir}));
+
+ // The model changes asynchronously when we run the event loop in the QTRY_...
+ // macros, so the root index returned by an earlier call to setRootPath might
+ // become invalid. Make sure we use a fresh one for each iteration.
+
+ // QTBUG-74471
+ // WHAT: setting the root path of the model to a dir with some files and a subdir
+ QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size() + 1);
+
+ // Change the model to only show files
+ model.setFilter(QDir::Files);
+ QTRY_COMPARE(model.rowCount(model.setRootPath(tmp)), files.size());
+
+ // WHEN: setting the root path to a subdir
+ QModelIndex subIndex = model.setRootPath(tmp + u'/' + subdir);
+ QTRY_COMPARE(model.rowCount(subIndex), 0);
+
+ // THEN: setting the root path to the previous (parent) dir, the model should
+ // still only show files.
+ // Doubling the default timeout (5s) as this test to fails on macos on the CI
+ QTRY_COMPARE_WITH_TIMEOUT(model.rowCount(model.setRootPath(tmp)), files.size(), 10s);
+}
+
void tst_QFileSystemModel::nameFilters()
{
QStringList list;
list << "a" << "b" << "c";
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
model->setNameFilters(list);
model->setNameFilterDisables(false);
QCOMPARE(model->nameFilters(), list);
@@ -725,6 +777,8 @@ void tst_QFileSystemModel::setData_data()
void tst_QFileSystemModel::setData()
{
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QSignalSpy spy(model.data(), &QFileSystemModel::fileRenamed);
QFETCH(QString, subdirName);
QFETCH(QStringList, files);
@@ -744,7 +798,7 @@ void tst_QFileSystemModel::setData()
tmpIdx = model->index(tmp);
model->fetchMore(tmpIdx);
}
- QTRY_COMPARE(model->rowCount(tmpIdx), files.count());
+ QTRY_COMPARE(model->rowCount(tmpIdx), files.size());
QModelIndex idx = model->index(tmp + '/' + oldFileName);
QCOMPARE(idx.isValid(), true);
@@ -754,16 +808,17 @@ void tst_QFileSystemModel::setData()
QCOMPARE(model->setData(idx, newFileName), success);
model->setReadOnly(true);
if (success) {
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QList<QVariant> arguments = spy.takeFirst();
QCOMPARE(model->data(idx, QFileSystemModel::FileNameRole).toString(), newFileName);
+ QCOMPARE(model->data(idx, QFileSystemModel::FileInfoRole).value<QFileInfo>().fileName(), newFileName);
QCOMPARE(model->fileInfo(idx).filePath(), tmp + '/' + newFileName);
QCOMPARE(model->index(arguments.at(0).toString()), model->index(tmp));
QCOMPARE(arguments.at(1).toString(), oldFileName);
QCOMPARE(arguments.at(2).toString(), newFileName);
QCOMPARE(QFile::rename(tmp + '/' + newFileName, tmp + '/' + oldFileName), true);
}
- QTRY_COMPARE(model->rowCount(tmpIdx), files.count());
+ QTRY_COMPARE(model->rowCount(tmpIdx), files.size());
// cleanup
if (!subdirName.isEmpty())
QVERIFY(QDir(tmp).removeRecursively());
@@ -777,6 +832,8 @@ void tst_QFileSystemModel::sortPersistentIndex()
file.close();
QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo));
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = model->setRootPath(flatDirTestPath);
QTRY_VERIFY(model->rowCount(root) > 0);
@@ -821,13 +878,13 @@ void tst_QFileSystemModel::sort()
//Create a file that will be at the end when sorting by name (For Mac, the default)
//but if we sort by size descending it will be the first
QFile tempFile(dirPath + "/plop2.txt");
- tempFile.open(QIODevice::WriteOnly | QIODevice::Text);
+ QVERIFY(tempFile.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream out(&tempFile);
out << "The magic number is: " << 49 << "\n";
tempFile.close();
QFile tempFile2(dirPath + "/plop.txt");
- tempFile2.open(QIODevice::WriteOnly | QIODevice::Text);
+ QVERIFY(tempFile2.open(QIODevice::WriteOnly | QIODevice::Text));
QTextStream out2(&tempFile2);
out2 << "The magic number is : " << 49 << " but i write some stuff in the file \n";
tempFile2.close();
@@ -856,7 +913,7 @@ void tst_QFileSystemModel::sort()
expectedOrder << tempFile2.fileName() << tempFile.fileName() << dirPath + QChar('/') + ".." << dirPath + QChar('/') + ".";
if (fileDialogMode) {
- QTRY_COMPARE(myModel->rowCount(parent), expectedOrder.count());
+ QTRY_COMPARE(myModel->rowCount(parent), expectedOrder.size());
// File dialog Mode means sub trees are not sorted, only the current root.
// There's no way we can check that the sub tree is "not sorted"; just check if it
// has the same contents of the expected list
@@ -883,6 +940,8 @@ void tst_QFileSystemModel::mkdir()
QString tmp = flatDirTestPath;
QString newFolderPath = QDir::toNativeSeparators(tmp + '/' + "NewFoldermkdirtest4");
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex tmpDir = model->index(tmp);
QVERIFY(tmpDir.isValid());
QDir bestatic(newFolderPath);
@@ -918,6 +977,8 @@ void tst_QFileSystemModel::deleteFile()
}
newFile.close();
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex idx = model->index(newFilePath);
QVERIFY(idx.isValid());
QVERIFY(model->remove(idx));
@@ -980,12 +1041,14 @@ void tst_QFileSystemModel::caseSensitivity()
QStringList files;
files << "a" << "c" << "C";
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QVERIFY(createFiles(model.data(), tmp, files));
QModelIndex root = model->index(tmp);
QStringList paths;
QModelIndexList indexes;
QCOMPARE(model->rowCount(root), 0);
- for (int i = 0; i < files.count(); ++i) {
+ for (int i = 0; i < files.size(); ++i) {
const QString path = tmp + '/' + files.at(i);
const QModelIndex index = model->index(path);
QVERIFY(index.isValid());
@@ -995,7 +1058,7 @@ void tst_QFileSystemModel::caseSensitivity()
if (!QFileSystemEngine::isCaseSensitive()) {
// QTBUG-31103, QTBUG-64147: Verify that files can be accessed by paths with fLipPeD case.
- for (int i = 0; i < paths.count(); ++i) {
+ for (int i = 0; i < paths.size(); ++i) {
const QModelIndex flippedCaseIndex = model->index(flipCase(paths.at(i)));
QCOMPARE(indexes.at(i), flippedCaseIndex);
}
@@ -1016,11 +1079,12 @@ void tst_QFileSystemModel::drives()
QFileSystemModel model;
model.setRootPath(path);
model.fetchMore(QModelIndex());
- QFileInfoList drives = QDir::drives();
+ const QFileInfoList drives = QDir::drives();
int driveCount = 0;
- foreach(const QFileInfo& driveRoot, drives)
+ for (const QFileInfo& driveRoot : drives) {
if (driveRoot.exists())
driveCount++;
+ }
QTRY_COMPARE(model.rowCount(), driveCount);
}
@@ -1045,6 +1109,8 @@ void tst_QFileSystemModel::dirsBeforeFiles()
}
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QModelIndex root = model->setRootPath(dir.absolutePath());
// Wait for model to be notified by the file system watcher
QTRY_COMPARE(model->rowCount(root), 2 * itemCount);
@@ -1119,6 +1185,8 @@ void tst_QFileSystemModel::permissions() // checks QTBUG-20503
const QString tmp = flatDirTestPath;
const QString file = tmp + QLatin1String("/f");
QScopedPointer<QFileSystemModel> model(new QFileSystemModel);
+ QAbstractItemModelTester tester(model.get());
+ tester.setUseFetchMore(false);
QVERIFY(createFiles(model.data(), tmp, QStringList{QLatin1String("f")}));
QVERIFY(QFile::setPermissions(file, permissions));
@@ -1183,6 +1251,9 @@ void tst_QFileSystemModel::specialFiles()
#ifndef Q_OS_UNIX
QSKIP("Not implemented");
#endif
+#ifdef Q_OS_ANDROID
+ QSKIP("Android does not allow access to root filesystem");
+#endif
QFileSystemModel model;
diff --git a/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt
index e5446d596a..db29eaaf94 100644
--- a/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt
+++ b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qstandarditem.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstandarditem Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstandarditem LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstandarditem
SOURCES
tst_qstandarditem.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
index 61683b20a6..70fb2b39d3 100644
--- a/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
+++ b/tests/auto/gui/itemmodels/qstandarditem/tst_qstandarditem.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -782,10 +757,10 @@ void tst_QStandardItem::takeColumn()
QList<QStandardItem *> taken = item.takeColumn(column);
if (expectSuccess) {
- QCOMPARE(taken.count(), item.rowCount());
+ QCOMPARE(taken.size(), item.rowCount());
QCOMPARE(item.columnCount(), columns - 1);
int index = column;
- for (int i = 0; i < taken.count(); ++i) {
+ for (int i = 0; i < taken.size(); ++i) {
QCOMPARE(taken.at(i), originalChildren.takeAt(index));
index += item.columnCount();
}
@@ -843,10 +818,10 @@ void tst_QStandardItem::takeRow()
QList<QStandardItem *> taken = item.takeRow(row);
if (expectSuccess) {
- QCOMPARE(taken.count(), item.columnCount());
+ QCOMPARE(taken.size(), item.columnCount());
QCOMPARE(item.rowCount(), rows - 1);
int index = row * columns;
- for (int i = 0; i < taken.count(); ++i) {
+ for (int i = 0; i < taken.size(); ++i) {
QCOMPARE(taken.at(i), originalChildren.takeAt(index));
}
index = 0;
@@ -1009,8 +984,8 @@ void tst_QStandardItem::sortChildren()
QCOMPARE(two->child(1)->text(), QLatin1String("e"));
QCOMPARE(two->child(2)->text(), QLatin1String("f"));
- QCOMPARE(layoutAboutToBeChangedSpy.count(), (x == 0) ? 0 : 3);
- QCOMPARE(layoutChangedSpy.count(), (x == 0) ? 0 : 3);
+ QCOMPARE(layoutAboutToBeChangedSpy.size(), (x == 0) ? 0 : 3);
+ QCOMPARE(layoutChangedSpy.size(), (x == 0) ? 0 : 3);
if (x == 0)
delete item;
@@ -1026,11 +1001,37 @@ public:
int type() const override { return QStandardItem::UserType + 1; }
bool operator<(const QStandardItem &other) const override {
- return text().length() < other.text().length();
+ return text().size() < other.text().size();
}
using QStandardItem::clone;
using QStandardItem::emitDataChanged;
+
+ void setData(const QVariant &value, int role) override
+ {
+ switch (role) {
+ case Qt::DisplayRole:
+ QStandardItem::setData(value, role);
+ break;
+ default:
+ // setFlags() uses "UserRole - 1" to store the flags, which is an
+ // implementation detail not exposed in the docs.
+ QStandardItem::setData(value, role);
+ break;
+ }
+ }
+
+ QVariant data(int role) const override
+ {
+ switch (role) {
+ case Qt::DisplayRole:
+ return QStandardItem::data(role);
+ default:
+ // flags() uses "UserRole - 1" to get the flags, which is an implementation
+ // detail not exposed in the docs.
+ return QStandardItem::data(role);
+ }
+ }
};
Q_DECLARE_METATYPE(QStandardItem*)
@@ -1052,8 +1053,8 @@ void tst_QStandardItem::subclassing()
QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged);
item->emitDataChanged();
- QCOMPARE(itemChangedSpy.count(), 1);
- QCOMPARE(itemChangedSpy.at(0).count(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
+ QCOMPARE(itemChangedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QStandardItem*>(itemChangedSpy.at(0).at(0)), item);
CustomItem *child0 = new CustomItem("cc");
@@ -1066,6 +1067,12 @@ void tst_QStandardItem::subclassing()
QCOMPARE(item->child(0), child2);
QCOMPARE(item->child(1), child0);
QCOMPARE(item->child(2), child1);
+
+ item->setFlags(Qt::ItemFlags{0});
+ QCOMPARE(item->flags(), Qt::ItemFlags{0});
+
+ item->setFlags(Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable});
+ QCOMPARE(item->flags(), Qt::ItemFlags{Qt::ItemIsEditable | Qt::ItemIsSelectable});
}
void tst_QStandardItem::lessThan()
diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt b/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt
index 49cbcbfa88..31ae25d008 100644
--- a/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt
+++ b/tests/auto/gui/itemmodels/qstandarditemmodel/CMakeLists.txt
@@ -1,16 +1,24 @@
-# Generated from qstandarditemmodel.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstandarditemmodel Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstandarditemmodel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstandarditemmodel
SOURCES
tst_qstandarditemmodel.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
Qt::WidgetsPrivate
+ Qt::TestPrivate
)
diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
index 7758a5d5cc..ef2fd83d4c 100644
--- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
+++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
@@ -1,41 +1,22 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QStandardItemModel>
#include <QTreeView>
+#include <QMap>
#include <QSignalSpy>
#include <QAbstractItemModelTester>
#include <private/qabstractitemmodel_p.h>
+#include <private/qpropertytesthelper_p.h>
#include <private/qtreeview_p.h>
+#include <algorithm>
+
+using namespace Qt::StringLiterals;
+
class tst_QStandardItemModel : public QObject
{
Q_OBJECT
@@ -112,6 +93,7 @@ private slots:
void indexFromItem();
void itemFromIndex();
void getSetItemPrototype();
+ void getSetItemData_data();
void getSetItemData();
void setHeaderLabels_data();
void setHeaderLabels();
@@ -138,6 +120,7 @@ private slots:
void taskQTBUG_45114_setItemData();
void setItemPersistentIndex();
void signalsOnTakeItem();
+ void takeChild();
void createPersistentOnLayoutAboutToBeChanged();
private:
QStandardItemModel *m_model = nullptr;
@@ -473,16 +456,16 @@ void tst_QStandardItemModel::setHeaderData()
for (int i = 0; i < count; ++i) {
QString customString = QString("custom") + QString::number(i);
QCOMPARE(m_model->setHeaderData(i, orient, customString), true);
- QCOMPARE(headerDataChangedSpy.count(), 1);
- QCOMPARE(dataChangedSpy.count(), 0);
+ QCOMPARE(headerDataChangedSpy.size(), 1);
+ QCOMPARE(dataChangedSpy.size(), 0);
QVariantList args = headerDataChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<Qt::Orientation>(args.at(0)), orient);
QCOMPARE(args.at(1).toInt(), i);
QCOMPARE(args.at(2).toInt(), i);
QCOMPARE(m_model->headerData(i, orient).toString(), customString);
QCOMPARE(m_model->setHeaderData(i, orient, customString), true);
- QCOMPARE(headerDataChangedSpy.count(), 0);
- QCOMPARE(dataChangedSpy.count(), 0);
+ QCOMPARE(headerDataChangedSpy.size(), 0);
+ QCOMPARE(dataChangedSpy.size(), 0);
}
//check read from invalid sections
@@ -745,7 +728,7 @@ void tst_QStandardItemModel::data()
const QMap<int, QVariant> itmData = m_model->itemData(m_model->index(0, 0));
QCOMPARE(itmData.value(Qt::DisplayRole), QLatin1String("initialitem"));
QCOMPARE(itmData.value(Qt::ToolTipRole), QLatin1String("tooltip"));
- QVERIFY(!itmData.contains(Qt::UserRole - 1));
+ QVERIFY(!itmData.contains(Qt::UserRole - 1)); // Qt::UserRole - 1 is used to store flags
QVERIFY(m_model->itemData(QModelIndex()).isEmpty());
}
@@ -786,9 +769,9 @@ void tst_QStandardItemModel::clear()
model.clear();
- QCOMPARE(modelResetSpy.count(), 1);
- QCOMPARE(layoutChangedSpy.count(), 0);
- QCOMPARE(rowsRemovedSpy.count(), 0);
+ QCOMPARE(modelResetSpy.size(), 1);
+ QCOMPARE(layoutChangedSpy.size(), 0);
+ QCOMPARE(rowsRemovedSpy.size(), 0);
QCOMPARE(model.index(0, 0), QModelIndex());
QCOMPARE(model.columnCount(), 0);
QCOMPARE(model.rowCount(), 0);
@@ -830,8 +813,8 @@ void tst_QStandardItemModel::sort()
QFETCH(QStringList, expected);
// prepare model
QStandardItemModel model;
- QVERIFY(model.insertRows(0, initial.count(), QModelIndex()));
- QCOMPARE(model.rowCount(QModelIndex()), initial.count());
+ QVERIFY(model.insertRows(0, initial.size(), QModelIndex()));
+ QCOMPARE(model.rowCount(QModelIndex()), initial.size());
model.insertColumns(0, 1, QModelIndex());
QCOMPARE(model.columnCount(QModelIndex()), 1);
for (int row = 0; row < model.rowCount(QModelIndex()); ++row) {
@@ -847,8 +830,8 @@ void tst_QStandardItemModel::sort()
// sort
model.sort(0, sortOrder);
- QCOMPARE(layoutAboutToBeChangedSpy.count(), 1);
- QCOMPARE(layoutChangedSpy.count(), 1);
+ QCOMPARE(layoutAboutToBeChangedSpy.size(), 1);
+ QCOMPARE(layoutChangedSpy.size(), 1);
// make sure the model is sorted
for (int row = 0; row < model.rowCount(QModelIndex()); ++row) {
@@ -892,7 +875,7 @@ void tst_QStandardItemModel::sortRole()
QFETCH(QVariantList, expectedData);
QStandardItemModel model;
- for (int i = 0; i < initialText.count(); ++i) {
+ for (int i = 0; i < initialText.size(); ++i) {
QStandardItem *item = new QStandardItem;
item->setText(initialText.at(i));
item->setData(initialData.at(i), Qt::UserRole);
@@ -900,7 +883,7 @@ void tst_QStandardItemModel::sortRole()
}
model.setSortRole(sortRole);
model.sort(0, sortOrder);
- for (int i = 0; i < expectedText.count(); ++i) {
+ for (int i = 0; i < expectedText.size(); ++i) {
QStandardItem *item = model.item(i);
QCOMPARE(item->text(), expectedText.at(i));
QCOMPARE(item->data(Qt::UserRole), expectedData.at(i));
@@ -921,6 +904,9 @@ void tst_QStandardItemModel::sortRoleBindings()
sortRoleObserver.setBinding([&] { return model.sortRole(); });
model.setSortRole(Qt::EditRole);
QCOMPARE(sortRoleObserver, Qt::EditRole);
+
+ QTestPrivate::testReadWritePropertyBasics(model, static_cast<int>(Qt::DisplayRole),
+ static_cast<int>(Qt::EditRole), "sortRole");
}
void tst_QStandardItemModel::findItems()
@@ -931,15 +917,15 @@ void tst_QStandardItemModel::findItems()
model.item(1)->appendRow(new QStandardItem(QLatin1String("foo")));
QList<QStandardItem*> matches;
matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, 0);
- QCOMPARE(matches.count(), 2);
+ QCOMPARE(matches.size(), 2);
matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly, 0);
- QCOMPARE(matches.count(), 1);
+ QCOMPARE(matches.size(), 1);
matches = model.findItems(QLatin1String("food"), Qt::MatchExactly|Qt::MatchRecursive, 0);
- QCOMPARE(matches.count(), 0);
+ QCOMPARE(matches.size(), 0);
matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, -1);
- QCOMPARE(matches.count(), 0);
+ QCOMPARE(matches.size(), 0);
matches = model.findItems(QLatin1String("foo"), Qt::MatchExactly|Qt::MatchRecursive, 1);
- QCOMPARE(matches.count(), 0);
+ QCOMPARE(matches.size(), 0);
}
void tst_QStandardItemModel::getSetHeaderItem()
@@ -1050,33 +1036,49 @@ void tst_QStandardItemModel::getSetItemPrototype()
QCOMPARE(model.itemPrototype(), nullptr);
}
+using RoleMap = QMap<int, QVariant>;
+using RoleList = QList<int>;
+
+static RoleMap getSetItemDataRoleMap(int textRole)
+{
+ return {{textRole, "text"_L1},
+ {Qt::StatusTipRole, "statusTip"_L1},
+ {Qt::ToolTipRole, "toolTip"_L1},
+ {Qt::WhatsThisRole, "whatsThis"_L1},
+ {Qt::SizeHintRole, QSize{64, 48}},
+ {Qt::FontRole, QFont{}},
+ {Qt::TextAlignmentRole, int(Qt::AlignLeft|Qt::AlignVCenter)},
+ {Qt::BackgroundRole, QColor(Qt::blue)},
+ {Qt::ForegroundRole, QColor(Qt::green)},
+ {Qt::CheckStateRole, int(Qt::PartiallyChecked)},
+ {Qt::AccessibleTextRole, "accessibleText"_L1},
+ {Qt::AccessibleDescriptionRole, "accessibleDescription"_L1}};
+}
+
+void tst_QStandardItemModel::getSetItemData_data()
+{
+ QTest::addColumn<RoleMap>("itemData");
+ QTest::addColumn<RoleMap>("expectedItemData");
+ QTest::addColumn<RoleList>("expectedRoles");
+
+ // QTBUG-112326: verify that text data set using Qt::EditRole is mapped to
+ // Qt::DisplayRole and both roles are in the changed signal
+ const RoleMap expectedItemData = getSetItemDataRoleMap(Qt::DisplayRole);
+ RoleList expectedRoles = expectedItemData.keys() << Qt::EditRole;
+ std::sort(expectedRoles.begin(), expectedRoles.end());
+
+ QTest::newRow("DisplayRole") << expectedItemData
+ << expectedItemData << expectedRoles;
+
+ QTest::newRow("EditRole") << getSetItemDataRoleMap(Qt::EditRole)
+ << expectedItemData << expectedRoles;
+}
+
void tst_QStandardItemModel::getSetItemData()
{
- QMap<int, QVariant> roles;
- QLatin1String text("text");
- roles.insert(Qt::DisplayRole, text);
- QLatin1String statusTip("statusTip");
- roles.insert(Qt::StatusTipRole, statusTip);
- QLatin1String toolTip("toolTip");
- roles.insert(Qt::ToolTipRole, toolTip);
- QLatin1String whatsThis("whatsThis");
- roles.insert(Qt::WhatsThisRole, whatsThis);
- QSize sizeHint(64, 48);
- roles.insert(Qt::SizeHintRole, sizeHint);
- QFont font;
- roles.insert(Qt::FontRole, font);
- Qt::Alignment textAlignment(Qt::AlignLeft|Qt::AlignVCenter);
- roles.insert(Qt::TextAlignmentRole, int(textAlignment));
- QColor backgroundColor(Qt::blue);
- roles.insert(Qt::BackgroundRole, backgroundColor);
- QColor textColor(Qt::green);
- roles.insert(Qt::ForegroundRole, textColor);
- Qt::CheckState checkState(Qt::PartiallyChecked);
- roles.insert(Qt::CheckStateRole, int(checkState));
- QLatin1String accessibleText("accessibleText");
- roles.insert(Qt::AccessibleTextRole, accessibleText);
- QLatin1String accessibleDescription("accessibleDescription");
- roles.insert(Qt::AccessibleDescriptionRole, accessibleDescription);
+ QFETCH(RoleMap, itemData);
+ QFETCH(RoleMap, expectedItemData);
+ QFETCH(RoleList, expectedRoles);
QStandardItemModel model;
model.insertRows(0, 1);
@@ -1085,11 +1087,17 @@ void tst_QStandardItemModel::getSetItemData()
QSignalSpy modelDataChangedSpy(
&model, &QStandardItemModel::dataChanged);
- QVERIFY(model.setItemData(idx, roles));
- QCOMPARE(modelDataChangedSpy.count(), 1);
- QVERIFY(model.setItemData(idx, roles));
- QCOMPARE(modelDataChangedSpy.count(), 1); //it was already changed once
- QCOMPARE(model.itemData(idx), roles);
+ QVERIFY(model.setItemData(idx, itemData));
+ QCOMPARE(modelDataChangedSpy.size(), 1);
+ const QVariantList &args = modelDataChangedSpy.constFirst();
+ QCOMPARE(args.size(), 3);
+ auto roleList = args.at(2).value<QList<int> >();
+ std::sort(roleList.begin(), roleList.end());
+ QCOMPARE(roleList, expectedRoles);
+
+ QVERIFY(model.setItemData(idx, itemData));
+ QCOMPARE(modelDataChangedSpy.size(), 1); //it was already changed once
+ QCOMPARE(model.itemData(idx), expectedItemData);
}
void tst_QStandardItemModel::setHeaderLabels_data()
@@ -1152,12 +1160,12 @@ void tst_QStandardItemModel::setHeaderLabels()
model.setHorizontalHeaderLabels(labels);
else
model.setVerticalHeaderLabels(labels);
- for (int i = 0; i < expectedLabels.count(); ++i)
+ for (int i = 0; i < expectedLabels.size(); ++i)
QCOMPARE(model.headerData(i, orientation).toString(), expectedLabels.at(i));
- QCOMPARE(columnsInsertedSpy.count(),
- (orientation == Qt::Vertical) ? 0 : labels.count() > columns);
- QCOMPARE(rowsInsertedSpy.count(),
- (orientation == Qt::Horizontal) ? 0 : labels.count() > rows);
+ QCOMPARE(columnsInsertedSpy.size(),
+ (orientation == Qt::Vertical) ? 0 : labels.size() > columns);
+ QCOMPARE(rowsInsertedSpy.size(),
+ (orientation == Qt::Horizontal) ? 0 : labels.size() > rows);
}
void tst_QStandardItemModel::itemDataChanged()
@@ -1168,8 +1176,8 @@ void tst_QStandardItemModel::itemDataChanged()
QSignalSpy itemChangedSpy(&model, &QStandardItemModel::itemChanged);
model.setItem(0, &item);
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
QModelIndex index = model.indexFromItem(&item);
QList<QVariant> args;
args = dataChangedSpy.takeFirst();
@@ -1179,8 +1187,8 @@ void tst_QStandardItemModel::itemDataChanged()
QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item);
item.setData(QLatin1String("foo"), Qt::DisplayRole);
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = dataChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), index);
QCOMPARE(qvariant_cast<QModelIndex>(args.at(1)), index);
@@ -1188,12 +1196,12 @@ void tst_QStandardItemModel::itemDataChanged()
QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item);
item.setData(item.data(Qt::DisplayRole), Qt::DisplayRole);
- QCOMPARE(dataChangedSpy.count(), 0);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(dataChangedSpy.size(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
item.setFlags(Qt::ItemIsEnabled);
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(itemChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(itemChangedSpy.size(), 1);
args = dataChangedSpy.takeFirst();
QCOMPARE(qvariant_cast<QModelIndex>(args.at(0)), index);
QCOMPARE(qvariant_cast<QModelIndex>(args.at(1)), index);
@@ -1201,8 +1209,8 @@ void tst_QStandardItemModel::itemDataChanged()
QCOMPARE(qvariant_cast<QStandardItem*>(args.at(0)), &item);
item.setFlags(item.flags());
- QCOMPARE(dataChangedSpy.count(), 0);
- QCOMPARE(itemChangedSpy.count(), 0);
+ QCOMPARE(dataChangedSpy.size(), 0);
+ QCOMPARE(itemChangedSpy.size(), 0);
}
void tst_QStandardItemModel::takeHeaderItem()
@@ -1330,7 +1338,7 @@ void tst_QStandardItemModel::setNullChild()
QSignalSpy spy(&model, &QAbstractItemModel::dataChanged);
item->setChild(0, nullptr);
QCOMPARE(item->child(0), nullptr);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QStandardItemModel::deleteChild()
@@ -1342,7 +1350,7 @@ void tst_QStandardItemModel::deleteChild()
QSignalSpy spy(&model, &QAbstractItemModel::dataChanged);
delete item->child(0);
QCOMPARE(item->child(0), nullptr);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QStandardItemModel::rootItemFlags()
@@ -1583,8 +1591,8 @@ void tst_QStandardItemModel::removeRowsAndColumns()
QStringList row_list = QString("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20").split(',');
QStringList col_list = row_list;
QStandardItemModel model;
- for (int c = 0; c < col_list.count(); c++)
- for (int r = 0; r < row_list.count(); r++)
+ for (int c = 0; c < col_list.size(); c++)
+ for (int r = 0; r < row_list.size(); r++)
model.setItem(r, c, new QStandardItem(row_list[r] + QLatin1Char('x') + col_list[c]));
VERIFY_MODEL
@@ -1605,16 +1613,22 @@ void tst_QStandardItemModel::removeRowsAndColumns()
VERIFY_MODEL
QList<QStandardItem *> row_taken = model.takeRow(6);
- QCOMPARE(row_taken.count(), col_list.count());
- for (int c = 0; c < col_list.count(); c++)
- QCOMPARE(row_taken[c]->text() , row_list[6] + QLatin1Char('x') + col_list[c]);
+ QCOMPARE(row_taken.size(), col_list.size());
+ for (qsizetype c = 0; c < row_taken.size(); c++) {
+ auto item = row_taken.at(c);
+ QCOMPARE(item->text() , row_list[6] + QLatin1Char('x') + col_list[c]);
+ delete item;
+ }
row_list.remove(6);
VERIFY_MODEL
QList<QStandardItem *> col_taken = model.takeColumn(10);
- QCOMPARE(col_taken.count(), row_list.count());
- for (int r = 0; r < row_list.count(); r++)
- QCOMPARE(col_taken[r]->text() , row_list[r] + QLatin1Char('x') + col_list[10]);
+ QCOMPARE(col_taken.size(), row_list.size());
+ for (qsizetype r = 0; r < col_taken.size(); r++) {
+ auto item = col_taken.at(r);
+ QCOMPARE(item->text() , row_list[r] + QLatin1Char('x') + col_list[10]);
+ delete item;
+ }
col_list.remove(10);
VERIFY_MODEL
}
@@ -1630,8 +1644,8 @@ void tst_QStandardItemModel::itemRoleNames()
QStringList row_list = QString("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20").split(',');
QStringList col_list = row_list;
QStandardItemModel model;
- for (int c = 0; c < col_list.count(); c++)
- for (int r = 0; r < row_list.count(); r++)
+ for (int c = 0; c < col_list.size(); c++)
+ for (int r = 0; r < row_list.size(); r++)
model.setItem(r, c, new QStandardItem(row_list[r] + QLatin1Char('x') + col_list[c]));
VERIFY_MODEL
@@ -1671,7 +1685,7 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData()
QModelIndex index = item->index();
QCOMPARE(model.itemData(index).size(), 3);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QMap<int, QVariant> roles;
@@ -1679,21 +1693,21 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData()
roles.insert(Qt::UserRole + 2, 2);
model.setItemData(index, roles);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
roles.insert(Qt::UserRole + 1, 1);
roles.insert(Qt::UserRole + 2, 2);
roles.insert(Qt::UserRole + 3, QVariant());
model.setItemData(index, roles);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
roles.clear();
roles.insert(Qt::UserRole + 1, 10);
roles.insert(Qt::UserRole + 3, 12);
model.setItemData(index, roles);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QMap<int, QVariant> itemRoles = model.itemData(index);
QCOMPARE(itemRoles.size(), 4);
@@ -1705,13 +1719,13 @@ void tst_QStandardItemModel::taskQTBUG_45114_setItemData()
roles.insert(Qt::UserRole + 3, 1);
model.setItemData(index, roles);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
roles.clear();
roles.insert(Qt::UserRole + 3, QVariant());
model.setItemData(index, roles);
- QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.size(), 3);
itemRoles = model.itemData(index);
QCOMPARE(itemRoles.size(), 3);
@@ -1764,13 +1778,13 @@ void tst_QStandardItemModel::signalsOnTakeItem() // QTBUG-89145
QSignalSpy dataChangedSpy(&m, &QAbstractItemModel::dataChanged);
QStandardItem *const takenItem = m.takeItem(1, 0);
for (auto &&spy : removeSpies) {
- QCOMPARE(spy->count(), 1);
+ QCOMPARE(spy->size(), 1);
const auto spyArgs = spy->takeFirst();
QCOMPARE(spyArgs.at(0).value<QModelIndex>(), parentIndex);
QCOMPARE(spyArgs.at(1).toInt(), 0);
QCOMPARE(spyArgs.at(2).toInt(), 1);
}
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
const auto dataChangedSpyArgs = dataChangedSpy.takeFirst();
QCOMPARE(dataChangedSpyArgs.at(0).value<QModelIndex>(), m.index(1, 0));
QCOMPARE(dataChangedSpyArgs.at(1).value<QModelIndex>(), m.index(1, 0));
@@ -1784,6 +1798,7 @@ void tst_QStandardItemModel::signalsOnTakeItem() // QTBUG-89145
QCOMPARE(takenItem->model(), nullptr);
QCOMPARE(takenItem->child(0, 0)->model(), nullptr);
QCOMPARE(m.index(1, 0).data(), QVariant());
+ delete takenItem;
}
void tst_QStandardItemModel::createPersistentOnLayoutAboutToBeChanged() // QTBUG-93466
@@ -1821,5 +1836,36 @@ void tst_QStandardItemModel::createPersistentOnLayoutAboutToBeChanged() // QTBUG
QCOMPARE(layoutChangedSpy.size(), 1);
}
+void tst_QStandardItemModel::takeChild() // QTBUG-117900
+{
+ {
+ // with model
+ QStandardItemModel model1;
+ QStandardItemModel model2;
+ QStandardItem base1("base1");
+ model1.setItem(0, 0, &base1);
+ QStandardItem base2("base2");
+ model2.setItem(0, 0, &base2);
+ auto item = new QStandardItem("item1");
+ item->appendRow(new QStandardItem("child"));
+ base1.appendRow(item);
+ base2.appendRow(base1.takeChild(0, 0));
+ QCOMPARE(base1.child(0, 0), nullptr);
+ QCOMPARE(base2.child(0, 0), item);
+ }
+ {
+ // without model
+ QStandardItem base1("base1");
+ QStandardItem base2("base2");
+ auto item = new QStandardItem("item1");
+ item->appendRow(new QStandardItem("child"));
+ base1.appendRow(item);
+ base2.appendRow(base1.takeChild(0, 0));
+ QCOMPARE(base1.child(0, 0), nullptr);
+ QCOMPARE(base2.child(0, 0), item);
+ }
+}
+
+
QTEST_MAIN(tst_QStandardItemModel)
#include "tst_qstandarditemmodel.moc"
diff --git a/tests/auto/gui/kernel/CMakeLists.txt b/tests/auto/gui/kernel/CMakeLists.txt
index 7ff4e40280..9acd817610 100644
--- a/tests/auto/gui/kernel/CMakeLists.txt
+++ b/tests/auto/gui/kernel/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from kernel.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
if(QT_FEATURE_action)
add_subdirectory(qaction)
@@ -9,6 +10,7 @@ add_subdirectory(qcursor)
add_subdirectory(qdrag)
add_subdirectory(qevent)
add_subdirectory(qfileopenevent)
+add_subdirectory(qguichronotimer)
add_subdirectory(qguieventdispatcher)
add_subdirectory(qguitimer)
if(NOT ANDROID AND NOT WASM)
@@ -22,11 +24,13 @@ 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)
-if(NOT ANDROID AND NOT UIKIT)
+if(NOT UIKIT)
add_subdirectory(qclipboard)
endif()
if(TARGET Qt::Network)
@@ -43,12 +47,7 @@ if(TARGET Qt::Widgets)
add_subdirectory(qtouchevent)
endif()
if(QT_FEATURE_opengl)
- # special case begin
- # QTBUG-85364
- if(NOT LINUX)
- add_subdirectory(qopenglwindow)
- endif()
- # special case end
+ add_subdirectory(qopenglwindow)
endif()
if(TARGET Qt::Network AND WIN32)
add_subdirectory(noqteventloop)
diff --git a/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt
index 9e47156add..e9d3d96af9 100644
--- a/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt
+++ b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from noqteventloop.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_noqteventloop Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_noqteventloop LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_noqteventloop
SOURCES
tst_noqteventloop.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
@@ -18,6 +25,6 @@ qt_internal_add_test(tst_noqteventloop
#####################################################################
qt_internal_extend_target(tst_noqteventloop CONDITION QT_FEATURE_dynamicgl AND WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
user32
)
diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp
index 65f2329e3d..65fe4a83ed 100644
--- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp
+++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -156,7 +131,8 @@ public:
}
- void run() {
+ void run() override
+ {
struct ScopedCleanup
{
/* This is in order to ensure that the window is hidden when returning from run(),
diff --git a/tests/auto/gui/kernel/qaction/CMakeLists.txt b/tests/auto/gui/kernel/qaction/CMakeLists.txt
index ed0a0a8a5b..8f70a36c61 100644
--- a/tests/auto/gui/kernel/qaction/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qaction/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qaction.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qaction_kernel Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qaction_kernel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qaction_kernel
SOURCES
tst_qaction.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qaction/tst_qaction.cpp b/tests/auto/gui/kernel/qaction/tst_qaction.cpp
index 7f817a5c98..4a4d1a75c8 100644
--- a/tests/auto/gui/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/gui/kernel/qaction/tst_qaction.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -234,11 +209,11 @@ void tst_QAction::setToolTip()
QFETCH(QStringList, values);
QFETCH(QStringList, expectedToolTips);
- QCOMPARE(properties.count(), values.count());
- QCOMPARE(properties.count(), expectedToolTips.count());
+ QCOMPARE(properties.size(), values.size());
+ QCOMPARE(properties.size(), expectedToolTips.size());
QAction action(nullptr);
- for (int i = 0; i < properties.count(); ++i) {
+ for (int i = 0; i < properties.size(); ++i) {
const auto property = properties.at(i);
const auto value = values.at(i);
const auto expectedToolTip = expectedToolTips.at(i);
@@ -297,19 +272,19 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
// test without a group
const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr));
QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered));
- QCOMPARE(spyWithoutGroup.count(), 0);
+ QCOMPARE(spyWithoutGroup.size(), 0);
actionWithoutGroup->trigger();
// signal should be emitted
- QCOMPARE(spyWithoutGroup.count(), 1);
+ QCOMPARE(spyWithoutGroup.size(), 1);
// it is now a checkable checked action
actionWithoutGroup->setCheckable(true);
actionWithoutGroup->setChecked(true);
spyWithoutGroup.clear();
- QCOMPARE(spyWithoutGroup.count(), 0);
+ QCOMPARE(spyWithoutGroup.size(), 0);
actionWithoutGroup->trigger();
// signal should be emitted
- QCOMPARE(spyWithoutGroup.count(), 1);
+ QCOMPARE(spyWithoutGroup.size(), 1);
}
void tst_QAction::setData() // QTBUG-62006
@@ -317,14 +292,14 @@ void tst_QAction::setData() // QTBUG-62006
QAction act(nullptr);
QSignalSpy spy(&act, &QAction::changed);
QCOMPARE(act.data(), QVariant());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
act.setData(QVariant());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
act.setData(-1);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
act.setData(-1);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QAction::setEnabledSetVisible()
@@ -333,22 +308,22 @@ void tst_QAction::setEnabledSetVisible()
QSignalSpy spy(&action, &QAction::enabledChanged);
QVERIFY(action.isEnabled());
QVERIFY(action.isVisible());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
action.setVisible(false);
QVERIFY(!action.isEnabled());
QVERIFY(!action.isVisible());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
action.setEnabled(false);
QVERIFY(!action.isEnabled());
QVERIFY(!action.isVisible());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
action.setVisible(true);
QVERIFY(!action.isEnabled());
QVERIFY(action.isVisible());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
action.resetEnabled();
QVERIFY(action.isEnabled());
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
}
void tst_QAction::setCheckabledSetChecked()
@@ -359,37 +334,37 @@ void tst_QAction::setCheckabledSetChecked()
QSignalSpy checkableSpy(&action, &QAction::checkableChanged);
QVERIFY(!action.isCheckable());
QVERIFY(!action.isChecked());
- QCOMPARE(changedSpy.count(), 0);
- QCOMPARE(checkedSpy.count(), 0);
- QCOMPARE(checkableSpy.count(), 0);
+ QCOMPARE(changedSpy.size(), 0);
+ QCOMPARE(checkedSpy.size(), 0);
+ QCOMPARE(checkableSpy.size(), 0);
action.setCheckable(true);
QVERIFY(action.isCheckable());
QVERIFY(!action.isChecked());
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(checkedSpy.count(), 0);
- QCOMPARE(checkableSpy.count(), 1);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(checkedSpy.size(), 0);
+ QCOMPARE(checkableSpy.size(), 1);
action.setChecked(true);
QVERIFY(action.isCheckable());
QVERIFY(action.isChecked());
- QCOMPARE(changedSpy.count(), 2);
- QCOMPARE(checkedSpy.count(), 1);
- QCOMPARE(checkableSpy.count(), 1);
+ QCOMPARE(changedSpy.size(), 2);
+ QCOMPARE(checkedSpy.size(), 1);
+ QCOMPARE(checkableSpy.size(), 1);
action.setCheckable(false);
QVERIFY(!action.isCheckable());
QVERIFY(!action.isChecked());
- QCOMPARE(changedSpy.count(), 3);
- QCOMPARE(checkedSpy.count(), 2);
- QCOMPARE(checkableSpy.count(), 2);
+ QCOMPARE(changedSpy.size(), 3);
+ QCOMPARE(checkedSpy.size(), 2);
+ QCOMPARE(checkableSpy.size(), 2);
action.setCheckable(true);
QVERIFY(action.isCheckable());
QVERIFY(action.isChecked());
- QCOMPARE(changedSpy.count(), 4);
- QCOMPARE(checkedSpy.count(), 3);
- QCOMPARE(checkableSpy.count(), 3);
+ QCOMPARE(changedSpy.size(), 4);
+ QCOMPARE(checkedSpy.size(), 3);
+ QCOMPARE(checkableSpy.size(), 3);
}
QTEST_MAIN(tst_QAction)
diff --git a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt
index 10354f865c..360a20cc95 100644
--- a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qactiongroup.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qactiongroup_kernel Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qactiongroup_kernel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qactiongroup_kernel
SOURCES
tst_qactiongroup.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp
index 8ac3a0b4c7..a9e331e111 100644
--- a/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp
+++ b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt
index 454196ce1b..46a0475521 100644
--- a/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qaddpostroutine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qaddpostroutine Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qaddpostroutine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qaddpostroutine
SOURCES
tst_qaddpostroutine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp b/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp
index 731547f681..c5cc0a9b20 100644
--- a/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp
+++ b/tests/auto/gui/kernel/qaddpostroutine/tst_qaddpostroutine.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt
index 64ef31a0b5..811da8bb53 100644
--- a/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qbackingstore.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qbackingstore Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qbackingstore LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qbackingstore
SOURCES
tst_qbackingstore.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
index 5349119b6d..a830d14be8 100644
--- a/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
+++ b/tests/auto/gui/kernel/qbackingstore/tst_qbackingstore.cpp
@@ -1,33 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qwindow.h>
#include <qbackingstore.h>
+#include <qpa/qplatformbackingstore.h>
+#include <qpa/qplatformintegration.h>
+#include <private/qguiapplication_p.h>
#include <qpainter.h>
#include <QTest>
@@ -42,9 +20,221 @@ class tst_QBackingStore : public QObject
Q_OBJECT
private slots:
+
+ void initTestCase_data();
+ void init();
+
+ void resize();
+ void paint();
+
+ void scrollRectInImage_data();
+ void scrollRectInImage();
+
+ void scroll();
void flush();
+
+ void staticContents();
};
+void tst_QBackingStore::initTestCase_data()
+{
+ QTest::addColumn<QSurfaceFormat::SwapBehavior>("swapBehavior");
+
+ QTest::newRow("single-buffer") << QSurfaceFormat::SingleBuffer;
+ QTest::newRow("double-buffer") << QSurfaceFormat::DoubleBuffer;
+}
+
+void tst_QBackingStore::init()
+{
+ QFETCH_GLOBAL(QSurfaceFormat::SwapBehavior, swapBehavior);
+
+ QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat();
+ defaultFormat.setSwapBehavior(swapBehavior);
+ QSurfaceFormat::setDefaultFormat(defaultFormat);
+}
+
+void tst_QBackingStore::resize()
+{
+ QWindow window;
+ window.create();
+
+ QBackingStore backingStore(&window);
+
+ QRect rect(0, 0, 100, 100);
+ backingStore.resize(rect.size());
+ QCOMPARE(backingStore.size(), rect.size());
+
+ // The paint device should reflect the requested
+ // size, taking the window's DPR into account.
+ backingStore.beginPaint(rect);
+ auto paintDevice = backingStore.paintDevice();
+ QCOMPARE(paintDevice->devicePixelRatio(), window.devicePixelRatio());
+ QCOMPARE(QSize(paintDevice->width(), paintDevice->height()),
+ rect.size() * window.devicePixelRatio());
+ backingStore.endPaint();
+
+ // So should the platform backingstore when accessed as an QImage
+ QImage image = backingStore.handle()->toImage();
+ if (!image.isNull()) // toImage might not be implemented
+ QCOMPARE(image.size(), rect.size() * window.devicePixelRatio());
+}
+
+void tst_QBackingStore::paint()
+{
+ QWindow window;
+ window.create();
+
+ // The resize() test verifies that the backingstore image
+ // has a size that takes the window's DPR into account.
+ auto dpr = window.devicePixelRatio();
+
+ QBackingStore backingStore(&window);
+
+ QRect rect(0, 0, 100, 100);
+ backingStore.resize(rect.size());
+
+ // Partial fill of a fresh backingstore should not crash
+ backingStore.beginPaint(QRect(0, 0, 50, 50));
+ backingStore.endPaint();
+ backingStore.flush(rect);
+
+ // Two rounds, with flush in between
+ for (int i = 0; i < 2; ++i) {
+ backingStore.beginPaint(rect);
+ QPainter p(backingStore.paintDevice());
+ QColor bgColor = i ? Qt::red : Qt::blue;
+ QColor fgColor = i ? Qt::green : Qt::yellow;
+ p.fillRect(rect, bgColor);
+ p.fillRect(QRect(50, 50, 10, 10), fgColor);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(50 * dpr, 50 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(49 * dpr, 50 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(50 * dpr, 49 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(59 * dpr, 59 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(60 * dpr, 59 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(59 * dpr, 60 * dpr), bgColor);
+
+ backingStore.flush(rect);
+ }
+}
+
+void tst_QBackingStore::scrollRectInImage_data()
+{
+ QTest::addColumn<QRect>("rect");
+ QTest::addColumn<QPoint>("offset");
+
+ QTest::newRow("empty rect") << QRect() << QPoint();
+ QTest::newRow("rect outside image") << QRect(-100, -100, 1000, 1000) << QPoint(10, 10);
+ QTest::newRow("scroll outside positive") << QRect(10, 10, 10, 10) << QPoint(1000, 1000);
+ QTest::newRow("scroll outside negative") << QRect(10, 10, 10, 10) << QPoint(-1000, -1000);
+
+ QTest::newRow("sub-rect positive scroll") << QRect(100, 100, 50, 50) << QPoint(10, 10);
+ QTest::newRow("sub-rect negative scroll") << QRect(100, 100, 50, 50) << QPoint(-10, -10);
+
+ QTest::newRow("positive vertical only") << QRect(100, 100, 50, 50) << QPoint(0, 10);
+ QTest::newRow("negative vertical only") << QRect(100, 100, 50, 50) << QPoint(0, -10);
+ QTest::newRow("positive horizontal only") << QRect(100, 100, 50, 50) << QPoint(10, 0);
+ QTest::newRow("negative horizontal only") << QRect(100, 100, 50, 50) << QPoint(-10, 0);
+
+ QTest::newRow("whole rect positive") << QRect(0, 0, 250, 250) << QPoint(10, 10);
+ QTest::newRow("whole rect negative") << QRect(0, 0, 250, 250) << QPoint(-10, -10);
+}
+
+QT_BEGIN_NAMESPACE
+Q_GUI_EXPORT void qt_scrollRectInImage(QImage &, const QRect &, const QPoint &);
+QT_END_NAMESPACE
+
+void tst_QBackingStore::scrollRectInImage()
+{
+ QImage test(250, 250, QImage::Format_ARGB32_Premultiplied);
+
+ QFETCH(QRect, rect);
+ QFETCH(QPoint, offset);
+
+ qt_scrollRectInImage(test, rect, offset);
+}
+
+void tst_QBackingStore::scroll()
+{
+ QWindow window;
+ window.create();
+
+ // The resize() test verifies that the backingstore image
+ // has a size that takes the window's DPR into account.
+ auto dpr = window.devicePixelRatio();
+
+ QBackingStore backingStore(&window);
+ QRect rect(0, 0, 100, 100);
+
+ // Scrolling a backingstore without a size shouldn't crash
+ backingStore.scroll(rect, 10, 10);
+ backingStore.scroll(rect, -10, -10);
+
+ backingStore.resize(rect.size());
+
+ // Scrolling a backingstore without painting to it shouldn't crash
+ backingStore.scroll(rect, 10, 10);
+ backingStore.scroll(rect, -10, -10);
+
+ // Two rounds, with flush in between
+ for (int i = 0; i < 2; ++i) {
+
+ backingStore.beginPaint(rect);
+ QPainter p(backingStore.paintDevice());
+ QColor bgColor = i ? Qt::red : Qt::blue;
+ QColor fgColor = i ? Qt::green : Qt::yellow;
+ p.fillRect(rect, bgColor);
+ p.fillRect(QRect(50, 50, 10, 10), fgColor);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(50 * dpr, 50 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(49 * dpr, 50 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(50 * dpr, 49 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(59 * dpr, 59 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(60 * dpr, 59 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(59 * dpr, 60 * dpr), bgColor);
+ image = {};
+
+ bool supportsScroll = backingStore.scroll(QRect(52, 52, 6, 6), -12, -12);
+ if (!supportsScroll)
+ QSKIP("Platform backingstore does not support scrolling");
+
+ image = backingStore.handle()->toImage();
+ QCOMPARE(image.pixelColor(40 * dpr, 40 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(39 * dpr, 40 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(40 * dpr, 39 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(45 * dpr, 45 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(46 * dpr, 45 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(45 * dpr, 46 * dpr), bgColor);
+ image = {};
+
+ backingStore.flush(rect);
+
+ // Scroll again after flush, but before new round of painting
+ backingStore.scroll(QRect(52, 52, 6, 6), 12, 12);
+
+ image = backingStore.handle()->toImage();
+ QCOMPARE(image.pixelColor(64 * dpr, 64 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(63 * dpr, 64 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(64 * dpr, 63 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(69 * dpr, 69 * dpr), fgColor);
+ QCOMPARE(image.pixelColor(70 * dpr, 69 * dpr), bgColor);
+ QCOMPARE(image.pixelColor(69 * dpr, 70 * dpr), bgColor);
+ image = {};
+ }
+}
+
class Window : public QWindow
{
public:
@@ -58,7 +248,7 @@ public:
backingStore.resize(size());
}
- void exposeEvent(QExposeEvent *event) override
+ void paintEvent(QPaintEvent *event) override
{
QRect rect(QPoint(), size());
@@ -70,10 +260,7 @@ public:
backingStore.endPaint();
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
backingStore.flush(event->region().boundingRect());
-QT_WARNING_POP
}
private:
@@ -89,5 +276,79 @@ void tst_QBackingStore::flush()
QTRY_VERIFY(window.isExposed());
}
+void tst_QBackingStore::staticContents()
+{
+ const auto *integration = QGuiApplicationPrivate::platformIntegration();
+ if (!integration->hasCapability(QPlatformIntegration::BackingStoreStaticContents))
+ QSKIP("Platform does not support static backingstore content");
+
+ QWindow window;
+ window.create();
+
+ const auto dpr = window.devicePixelRatio();
+
+ QBackingStore backingStore(&window);
+
+ QRect initialRect(0, 0, 100, 100);
+
+ // Static contents without paint first should not crash
+ backingStore.setStaticContents(initialRect);
+ backingStore.resize(initialRect.size());
+ QCOMPARE(backingStore.size(), initialRect.size());
+ backingStore.beginPaint(QRect(0, 0, 50, 50));
+ backingStore.endPaint();
+ backingStore.handle()->toImage();
+
+ {
+ backingStore.setStaticContents(QRect());
+ backingStore.beginPaint(initialRect);
+ QPainter p(backingStore.paintDevice());
+ p.fillRect(initialRect, Qt::green);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green);
+ }
+
+ {
+ backingStore.setStaticContents(initialRect);
+
+ QRect resizedRect(0, 0, 200, 200);
+ backingStore.resize(resizedRect.size());
+
+ QRegion repaintRegion = QRegion(resizedRect) - QRegion(initialRect);
+
+ backingStore.beginPaint(repaintRegion);
+ QPainter p(backingStore.paintDevice());
+ for (auto repaintRect : repaintRegion)
+ p.fillRect(repaintRect, Qt::red);
+ p.end();
+ backingStore.endPaint();
+
+ QImage image = backingStore.handle()->toImage();
+ if (image.isNull())
+ QSKIP("Platform backingstore does not implement toImage");
+
+ QCOMPARE(image.pixelColor(initialRect.topLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomLeft() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.topRight() * dpr), Qt::green);
+ QCOMPARE(image.pixelColor(initialRect.bottomRight() * dpr), Qt::green);
+
+ for (auto repaintRect : repaintRegion) {
+ QCOMPARE(image.pixelColor(repaintRect.topLeft() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.bottomLeft() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.topRight() * dpr), Qt::red);
+ QCOMPARE(image.pixelColor(repaintRect.bottomRight() * dpr), Qt::red);
+ }
+ }
+}
+
#include <tst_qbackingstore.moc>
QTEST_MAIN(tst_QBackingStore);
diff --git a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt
index 05eba972d6..b7a0467758 100644
--- a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qclipboard.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qclipboard LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(copier)
add_subdirectory(paster)
diff --git a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt
index ef599b121e..ea7def8c0d 100644
--- a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt
@@ -1,23 +1,16 @@
-# Generated from copier.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## copier Binary:
#####################################################################
-# special case begin
set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
-# special case end
qt_internal_add_executable(copier
- ${args} # special case
+ ${args}
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
-
-## Scopes:
-#####################################################################
-
-#### Keys ignored in scope 2:.:.:copier.pro:WIN32:
-# DESTDIR = "../copier"
diff --git a/tests/auto/gui/kernel/qclipboard/copier/main.cpp b/tests/auto/gui/kernel/qclipboard/copier/main.cpp
index 32e91a9939..362ede38b7 100644
--- a/tests/auto/gui/kernel/qclipboard/copier/main.cpp
+++ b/tests/auto/gui/kernel/qclipboard/copier/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
#include <QtCore/QStringList>
diff --git a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt
index 571ae4944e..9bc1985ee4 100644
--- a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt
@@ -1,23 +1,16 @@
-# Generated from paster.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## paster Binary:
#####################################################################
-# special case begin
set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
-# special case end
qt_internal_add_executable(paster
- ${args} # special case
+ ${args}
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
-
-## Scopes:
-#####################################################################
-
-#### Keys ignored in scope 2:.:.:paster.pro:WIN32:
-# DESTDIR = "../paster"
diff --git a/tests/auto/gui/kernel/qclipboard/paster/main.cpp b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
index 7fca8af1cb..bf47b10ba6 100644
--- a/tests/auto/gui/kernel/qclipboard/paster/main.cpp
+++ b/tests/auto/gui/kernel/qclipboard/paster/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QGuiApplication>
#include <QtGui/QClipboard>
#include <QtGui/QImage>
diff --git a/tests/auto/gui/kernel/qclipboard/test/BLACKLIST b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST
new file mode 100644
index 0000000000..3ca7791b37
--- /dev/null
+++ b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST
@@ -0,0 +1,5 @@
+# QTBUG-87429
+[testSignals]
+android
+[setMimeData]
+android
diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt
index 0e9fa8f40d..fad30c16fd 100644
--- a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qclipboard Test:
@@ -8,7 +9,7 @@ qt_internal_add_test(tst_qclipboard
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
../tst_qclipboard.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
@@ -17,9 +18,8 @@ qt_internal_add_test(tst_qclipboard
#####################################################################
qt_internal_extend_target(tst_qclipboard CONDITION MACOS
- PUBLIC_LIBRARIES
+ LIBRARIES
${FWAppKit}
)
-#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID:
# TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster"
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
index 42af0dea2c..30366c6aa1 100644
--- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
+++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -46,8 +21,9 @@
#ifdef Q_OS_WIN
# include <QtGui/private/qguiapplication_p.h>
-# include <QtGui/private/qwindowsmime_p.h>
+# include <QtGui/qwindowsmimeconverter.h>
# include <QtGui/qpa/qplatformintegration.h>
+# include <QtCore/qt_windows.h>
#endif
class tst_QClipboard : public QObject
@@ -66,6 +42,7 @@ private slots:
void testSignals();
void setMimeData();
void clearBeforeSetText();
+ void getTextFromHTMLMimeType();
# ifdef Q_OS_WIN
void testWindowsMimeRegisterType();
void testWindowsMime_data();
@@ -86,7 +63,7 @@ void tst_QClipboard::initTestCase()
#if QT_CONFIG(clipboard)
void tst_QClipboard::init()
{
-#if QT_CONFIG(process)
+#if QT_CONFIG(process) && !defined(Q_OS_ANDROID)
const QString testdataDir = QFileInfo(QFINDTESTDATA("copier")).absolutePath();
QVERIFY2(QDir::setCurrent(testdataDir), qPrintable("Could not chdir to " + testdataDir));
#endif
@@ -149,7 +126,7 @@ public:
operator bool() const
{
- if (m_timer.elapsed() && !m_spy.count())
+ if (m_timer.elapsed() && !m_spy.size())
return true;
m_spy.clear();
return false;
@@ -191,11 +168,11 @@ void tst_QClipboard::testSignals()
// Test the default mode signal.
clipboard->setText(text);
- QTRY_COMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(searchChangedSpy.count(), 0);
- QCOMPARE(selectionChangedSpy.count(), 0);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QTRY_COMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(searchChangedSpy.size(), 0);
+ QCOMPARE(selectionChangedSpy.size(), 0);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Clipboard);
changedSpy.clear();
@@ -203,29 +180,29 @@ void tst_QClipboard::testSignals()
// Test the selection mode signal.
if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
- QCOMPARE(selectionChangedSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(selectionChangedSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Selection);
} else {
- QCOMPARE(selectionChangedSpy.count(), 0);
+ QCOMPARE(selectionChangedSpy.size(), 0);
}
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(searchChangedSpy.count(), 0);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(searchChangedSpy.size(), 0);
changedSpy.clear();
// Test the search mode signal.
if (clipboard->supportsFindBuffer()) {
clipboard->setText(text, QClipboard::FindBuffer);
- QCOMPARE(searchChangedSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(searchChangedSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::FindBuffer);
} else {
- QCOMPARE(searchChangedSpy.count(), 0);
+ QCOMPARE(searchChangedSpy.size(), 0);
}
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
}
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_QNX)
@@ -365,16 +342,16 @@ void tst_QClipboard::setMimeData()
QGuiApplication::clipboard()->clear(QClipboard::FindBuffer);
if (QGuiApplication::clipboard()->supportsSelection())
- QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spySelection.size(), 1);
else
- QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spySelection.size(), 0);
if (QGuiApplication::clipboard()->supportsFindBuffer())
- QCOMPARE(spyFindBuffer.count(), 1);
+ QCOMPARE(spyFindBuffer.size(), 1);
else
- QCOMPARE(spyFindBuffer.count(), 0);
+ QCOMPARE(spyFindBuffer.size(), 0);
- QTRY_COMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.size(), 1);
// an other crash test
data = new QMimeData;
@@ -401,16 +378,16 @@ void tst_QClipboard::setMimeData()
QGuiApplication::clipboard()->setMimeData(newData, QClipboard::FindBuffer);
if (QGuiApplication::clipboard()->supportsSelection())
- QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spySelection.size(), 1);
else
- QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spySelection.size(), 0);
if (QGuiApplication::clipboard()->supportsFindBuffer())
- QCOMPARE(spyFindBuffer.count(), 1);
+ QCOMPARE(spyFindBuffer.size(), 1);
else
- QCOMPARE(spyFindBuffer.count(), 0);
+ QCOMPARE(spyFindBuffer.size(), 0);
- QTRY_COMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.size(), 1);
}
void tst_QClipboard::clearBeforeSetText()
@@ -449,12 +426,30 @@ void tst_QClipboard::clearBeforeSetText()
QCOMPARE(QGuiApplication::clipboard()->text(), text);
}
+void tst_QClipboard::getTextFromHTMLMimeType()
+{
+ QClipboard * clipboard = QGuiApplication::clipboard();
+ QMimeData * mimeData = new QMimeData();
+ const QString testString("TEST");
+ const QString htmlString(QLatin1String("<html><body>") + testString + QLatin1String("</body></html>"));
+
+ mimeData->setText(testString);
+ mimeData->setHtml(htmlString);
+ clipboard->setMimeData(mimeData);
+
+ QCOMPARE(clipboard->text(), testString);
+ QVERIFY(clipboard->mimeData()->hasText());
+ QVERIFY(clipboard->mimeData()->hasHtml());
+ QCOMPARE(clipboard->mimeData()->text(), testString);
+ QCOMPARE(clipboard->mimeData()->html(), htmlString);
+}
+
# ifdef Q_OS_WIN
-using QWindowsMime = QNativeInterface::Private::QWindowsMime;
+using QWindowsMimeConverter = QWindowsMimeConverter;
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
-class TestMime : public QWindowsMime
+class TestMime : public QWindowsMimeConverter
{
public:
bool canConvertFromMime(const FORMATETC &, const QMimeData *) const override
diff --git a/tests/auto/gui/kernel/qcursor/CMakeLists.txt b/tests/auto/gui/kernel/qcursor/CMakeLists.txt
index 1304dd2ba2..52c88fc231 100644
--- a/tests/auto/gui/kernel/qcursor/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qcursor/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qcursor.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcursor Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcursor LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcursor
SOURCES
tst_qcursor.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp
index eb33cce95b..edc44b9ea6 100644
--- a/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp
+++ b/tests/auto/gui/kernel/qcursor/tst_qcursor.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
#include <qcursor.h>
diff --git a/tests/auto/gui/kernel/qdrag/CMakeLists.txt b/tests/auto/gui/kernel/qdrag/CMakeLists.txt
index b03f82da39..015cfe70d0 100644
--- a/tests/auto/gui/kernel/qdrag/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qdrag/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qdrag.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qdrag Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qdrag LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qdrag
SOURCES
tst_qdrag.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp
index 5c243df6d0..9e0d5ad0f4 100644
--- a/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp
+++ b/tests/auto/gui/kernel/qdrag/tst_qdrag.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/kernel/qevent/CMakeLists.txt b/tests/auto/gui/kernel/qevent/CMakeLists.txt
index 2bb22eb469..c6ad861f25 100644
--- a/tests/auto/gui/kernel/qevent/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qevent/CMakeLists.txt
@@ -1,10 +1,20 @@
-# Generated from qevent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qevent Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qevent LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qevent
SOURCES
tst_qevent.cpp
+ LIBRARIES
+ Qt::Gui
+ Qt::CorePrivate
)
diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp
index 6542ed5ad3..6960f99af2 100644
--- a/tests/auto/gui/kernel/qevent/tst_qevent.cpp
+++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp
@@ -1,36 +1,72 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
-#include <QtCore/qcoreapplication.h>
-#include <QtCore/qcoreevent.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qevent.h>
+#include <QtCore/private/qfutureinterface_p.h>
+
+#define FOR_EACH_CORE_EVENT(X) \
+ /* qcoreevent.h */ \
+ X(QEvent, (QEvent::None)) \
+ X(QTimerEvent, (42)) \
+ X(QChildEvent, (QEvent::ChildAdded, nullptr)) \
+ X(QDynamicPropertyChangeEvent, ("size")) \
+ /* qfutureinterface_p.h */ \
+ X(QFutureCallOutEvent, ()) \
+ /* end */
+
+#define FOR_EACH_GUI_EVENT(X) \
+ /* qevent.h */ \
+ X(QInputEvent, (QEvent::None, nullptr)) \
+ X(QPointerEvent, (QEvent::None, nullptr)) \
+ /* doesn't work with nullptr: */ \
+ X(QSinglePointEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {})) \
+ X(QEnterEvent, ({}, {}, {})) \
+ X(QMouseEvent, (QEvent::None, {}, {}, {}, {}, {}, {}, {}, QPointingDevice::primaryPointingDevice())) \
+ X(QHoverEvent, (QEvent::None, {}, {}, QPointF{})) \
+ X(QWheelEvent, ({}, {}, {}, {}, {}, {}, {}, {})) \
+ X(QTabletEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})) \
+ X(QNativeGestureEvent, ({}, QPointingDevice::primaryPointingDevice(), 0, {}, {}, {}, {}, {})) \
+ X(QKeyEvent, (QEvent::None, 0, {})) \
+ X(QFocusEvent, (QEvent::None)) \
+ X(QPaintEvent, (QRect{0, 0, 100, 100})) \
+ X(QMoveEvent, ({}, {})) \
+ X(QExposeEvent, ({})) \
+ X(QPlatformSurfaceEvent, ({})) \
+ X(QResizeEvent, ({}, {})) \
+ X(QCloseEvent, ()) \
+ X(QIconDragEvent, ()) \
+ X(QShowEvent, ()) \
+ X(QHideEvent, ()) \
+ X(QContextMenuEvent, (QContextMenuEvent::Reason::Keyboard, {}, {})) \
+ X(QInputMethodEvent, ()) \
+ X(QInputMethodQueryEvent, ({})) \
+ X(QDropEvent, ({}, {}, {}, {}, {})) \
+ X(QDragMoveEvent, ({}, {}, {}, {}, {})) \
+ X(QDragEnterEvent, ({}, {}, {}, {}, {})) \
+ X(QDragLeaveEvent, ()) \
+ X(QHelpEvent, ({}, {}, {})) \
+ X(QStatusTipEvent, ({})) \
+ X(QWhatsThisClickedEvent, ({})) \
+ X(QActionEvent, (0, nullptr)) \
+ X(QFileOpenEvent, (QString{})) \
+ X(QToolBarChangeEvent, (false)) \
+ X(QShortcutEvent, ({}, 0)) \
+ X(QWindowStateChangeEvent, ({})) \
+ X(QTouchEvent, (QEvent::None)) \
+ X(QScrollPrepareEvent, ({})) \
+ X(QScrollEvent, ({}, {}, {})) \
+ X(QScreenOrientationChangeEvent, (nullptr, {})) \
+ X(QApplicationStateChangeEvent, ({})) \
+ /* end */
+
+#define FOR_EACH_EVENT(X) \
+ FOR_EACH_CORE_EVENT(X) \
+ FOR_EACH_GUI_EVENT(X) \
+ /* end */
class tst_QEvent : public QObject
{
@@ -40,6 +76,7 @@ public:
~tst_QEvent();
private slots:
+ void clone() const;
void registerEventType_data();
void registerEventType();
void exhaustEventTypeRegistration(); // keep behind registerEventType() test
@@ -55,6 +92,18 @@ tst_QEvent::tst_QEvent()
tst_QEvent::~tst_QEvent()
{ }
+void tst_QEvent::clone() const
+{
+#define ACTION(Type, Init) do { \
+ const std::unique_ptr<const Type> e(new Type Init); \
+ auto c = e->clone(); \
+ static_assert(std::is_same_v<decltype(c), Type *>); \
+ delete c; \
+ } while (0);
+
+ FOR_EACH_EVENT(ACTION)
+}
+
void tst_QEvent::registerEventType_data()
{
QTest::addColumn<int>("hint");
diff --git a/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt
index 2404833737..9906400a66 100644
--- a/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qfileopenevent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfileopenevent LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
add_subdirectory(test)
add_subdirectory(qfileopeneventexternal)
diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt
index 658a70619f..7a39bc111c 100644
--- a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qfileopeneventexternal.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## qfileopeneventexternal Binary:
@@ -8,9 +9,6 @@ qt_internal_add_executable(qfileopeneventexternal
GUI
SOURCES
qfileopeneventexternal.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
-
-#### Keys ignored in scope 1:.:.:qfileopeneventexternal.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
index f21b0680bc..bd74e7497f 100644
--- a/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
+++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui>
#include <QEvent>
@@ -39,8 +14,8 @@ struct MyApplication : public QGuiApplication
{
if (event->type() == QEvent::FileOpen) {
QFileOpenEvent* ev = static_cast<QFileOpenEvent *>(event);
- QFile file;
- bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered);
+ QFile file(ev->file());
+ bool ok = file.open(QFile::Append | QFile::Unbuffered);
if (ok)
file.write(QByteArray("+external"));
return true;
diff --git a/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt
index faa5e5acfc..d7f4e32f70 100644
--- a/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfileopenevent Test:
@@ -7,6 +8,6 @@
qt_internal_add_test(tst_qfileopenevent
SOURCES
tst_qfileopenevent.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp
index 31cb036515..4b9a23ffcf 100644
--- a/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp
+++ b/tests/auto/gui/kernel/qfileopenevent/test/tst_qfileopenevent.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QTemporaryDir>
#include <QTest>
@@ -79,7 +54,7 @@ void tst_qfileopenevent::cleanupTestCase()
void tst_qfileopenevent::createFile(const QString &filename, const QByteArray &content)
{
QFile file(filename);
- file.open(QFile::WriteOnly);
+ QVERIFY(file.open(QFile::WriteOnly));
file.write(content);
file.close();
}
@@ -103,8 +78,9 @@ void tst_qfileopenevent::constructor()
QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event)
{
- QFile file;
- event.openFile(file, QFile::ReadOnly);
+ QFile file(event.file());
+ if (!file.open(QFile::ReadOnly))
+ qFatal("Cannot open file %s", qPrintable(event.file()));
file.seek(0);
QByteArray data = file.readAll();
return data;
@@ -112,8 +88,8 @@ QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event)
bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent)
{
- QFile file;
- bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered);
+ QFile file(event.file());
+ bool ok = file.open(QFile::Append | QFile::Unbuffered);
if (ok)
ok = file.write(writeContent) == writeContent.size();
return ok;
@@ -152,8 +128,8 @@ void tst_qfileopenevent::handleLifetime()
QScopedPointer<QFileOpenEvent> event(createFileAndEvent(QLatin1String("testHandleLifetime"), QByteArray("test content")));
// open a QFile after the original RFile is closed
- QFile qFile;
- QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true);
+ QFile qFile(event->file());
+ QVERIFY(qFile.open(QFile::Append | QFile::Unbuffered));
event.reset(0);
// write to the QFile after the event is closed
@@ -163,7 +139,7 @@ void tst_qfileopenevent::handleLifetime()
// check the content
QFile checkContent("testHandleLifetime");
- checkContent.open(QFile::ReadOnly);
+ QVERIFY(checkContent.open(QFile::ReadOnly));
QString content(checkContent.readAll());
QCOMPARE(content, QLatin1String("test content+closed original handles"));
checkContent.close();
@@ -177,7 +153,8 @@ void tst_qfileopenevent::multiOpen()
QFile files[5];
for (int i=0; i<5; i++) {
- QCOMPARE(event->openFile(files[i], QFile::ReadOnly), true);
+ files[i].setFileName(event->file());
+ QVERIFY(files[i].open(QFile::ReadOnly));
}
for (int i=0; i<5; i++)
files[i].seek(i);
diff --git a/tests/auto/gui/kernel/qguiapplication/BLACKLIST b/tests/auto/gui/kernel/qguiapplication/BLACKLIST
index e6ffe78ae3..3fa6c4880b 100644
--- a/tests/auto/gui/kernel/qguiapplication/BLACKLIST
+++ b/tests/auto/gui/kernel/qguiapplication/BLACKLIST
@@ -1,3 +1,2 @@
-[focusObject]
-ubuntu-16.04
-opensuse-42.3
+[quitOnLastWindowClosedWithEventLoopLocker]
+b2qt
diff --git a/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt
index ffd07cad26..6f1f845edd 100644
--- a/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt
@@ -1,60 +1,48 @@
-# Generated from qguiapplication.pro.
-
-if(NOT QT_FEATURE_private_tests)
- return()
-endif()
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguiapplication Test:
#####################################################################
-# special case begin
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguiapplication LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
if (WIN32)
set(target_version "1.2.3.4")
else()
set(target_version "1.2.3")
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
+ VERSION ${target_version}
SOURCES
- ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.h # special case
+ ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.h
tst_qguiapplication.cpp
DEFINES
- QT_DISABLE_DEPRECATED_BEFORE=0x050E00
+ QT_QGUIAPPLICATIONTEST=1
INCLUDE_DIRECTORIES
../../../corelib/kernel/qcoreapplication
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::GuiPrivate
+ TESTDATA ${tst_qguiapplication_resource_files}
+ BUILTIN_TESTDATA
)
-# 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}
-)
-
-# special case begin
+if (ANDROID)
+ set_property(TARGET tst_qguiapplication PROPERTY QT_ANDROID_VERSION_NAME ${target_version})
+endif()
if (APPLE)
set_property(TARGET tst_qguiapplication PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
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"
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index 836419659b..6b8700f580 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -72,6 +47,7 @@ private slots:
void changeFocusWindow();
void keyboardModifiers();
void palette();
+ void paletteNoCrash();
void font();
void modalWindow();
void quitOnLastWindowClosed();
@@ -85,6 +61,8 @@ private slots:
void staticFunctions();
+ void topLevelAt();
+
void settableStyleHints_data();
void settableStyleHints(); // Needs to run last as it changes style hints.
};
@@ -123,20 +101,20 @@ void tst_QGuiApplication::displayName()
QGuiApplication::setApplicationName("The Core Application");
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application"));
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The Core Application"));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QGuiApplication::setApplicationDisplayName("The GUI Application");
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QGuiApplication::setApplicationName("The Core Application 2");
QCOMPARE(QGuiApplication::applicationName(), QString::fromLatin1("The Core Application 2"));
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application"));
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QGuiApplication::setApplicationDisplayName("The GUI Application 2");
QCOMPARE(QGuiApplication::applicationDisplayName(), QString::fromLatin1("The GUI Application 2"));
- QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.size(), 3);
}
void tst_QGuiApplication::desktopFileName()
@@ -147,8 +125,8 @@ void tst_QGuiApplication::desktopFileName()
QCOMPARE(QGuiApplication::desktopFileName(), QString());
- QGuiApplication::setDesktopFileName("io.qt.QGuiApplication.desktop");
- QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication.desktop"));
+ QGuiApplication::setDesktopFileName("io.qt.QGuiApplication");
+ QCOMPARE(QGuiApplication::desktopFileName(), QString::fromLatin1("io.qt.QGuiApplication"));
QGuiApplication::setDesktopFileName(QString());
QCOMPARE(QGuiApplication::desktopFileName(), QString());
@@ -247,12 +225,12 @@ void tst_QGuiApplication::focusObject()
window1.setFocusObject(&obj1);
QCOMPARE(app.focusObject(), &obj1);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
window1.setFocusObject(&obj2);
QCOMPARE(app.focusObject(), &obj2);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
window2.setFocusObject(&obj3);
@@ -261,12 +239,12 @@ void tst_QGuiApplication::focusObject()
QVERIFY(QTest::qWaitForWindowExposed(&window2));
QTRY_COMPARE(app.focusWindow(), &window2);
QCOMPARE(app.focusObject(), &obj3);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
// focus change on unfocused window does not show
spy.clear();
window1.setFocusObject(&obj1);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QCOMPARE(app.focusObject(), &obj3);
}
@@ -278,13 +256,13 @@ void tst_QGuiApplication::allWindows()
QWindow *window2 = new QWindow(window1);
QVERIFY(app.allWindows().contains(window1));
QVERIFY(app.allWindows().contains(window2));
- QCOMPARE(app.allWindows().count(), 2);
+ QCOMPARE(app.allWindows().size(), 2);
delete window1;
window1 = nullptr;
window2 = nullptr;
QVERIFY(!app.allWindows().contains(window2));
QVERIFY(!app.allWindows().contains(window1));
- QCOMPARE(app.allWindows().count(), 0);
+ QCOMPARE(app.allWindows().size(), 0);
}
void tst_QGuiApplication::topLevelWindows()
@@ -295,13 +273,13 @@ void tst_QGuiApplication::topLevelWindows()
QWindow *window2 = new QWindow(window1);
QVERIFY(app.topLevelWindows().contains(window1));
QVERIFY(!app.topLevelWindows().contains(window2));
- QCOMPARE(app.topLevelWindows().count(), 1);
+ QCOMPARE(app.topLevelWindows().size(), 1);
delete window1;
window1 = nullptr;
window2 = nullptr;
QVERIFY(!app.topLevelWindows().contains(window2));
QVERIFY(!app.topLevelWindows().contains(window1));
- QCOMPARE(app.topLevelWindows().count(), 0);
+ QCOMPARE(app.topLevelWindows().size(), 0);
}
class ShowCloseShowWindow : public QWindow
@@ -482,16 +460,12 @@ void tst_QGuiApplication::keyboardModifiers()
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
// wheel events
- QPoint global = window->mapToGlobal(center);
QPoint delta(0, 1);
- QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::NoModifier);
- QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
+ QTest::wheelEvent(window.data(), center, delta, delta, Qt::NoModifier);
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::NoModifier);
- QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::AltModifier);
- QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
+ QTest::wheelEvent(window.data(), center, delta, delta, Qt::AltModifier);
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::AltModifier);
- QWindowSystemInterface::handleWheelEvent(window.data(), center, global, delta, delta, Qt::ControlModifier);
- QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents);
+ QTest::wheelEvent(window.data(), center, delta, delta, Qt::ControlModifier);
QCOMPARE(QGuiApplication::keyboardModifiers(), Qt::ControlModifier);
// touch events
@@ -545,52 +519,78 @@ void tst_QGuiApplication::palette()
// The default application palette is not resolved
QVERIFY(!QGuiApplication::palette().resolveMask());
+ // TODO: add event processing instead of the signal
+#if QT_DEPRECATED_SINCE(6, 0)
QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette)));
+#endif
QPalette oldPalette = QGuiApplication::palette();
QPalette newPalette = QPalette(Qt::red);
QGuiApplication::setPalette(newPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), newPalette));
- QCOMPARE(signalSpy.count(), 1);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 1);
QVERIFY(palettesMatch(signalSpy.at(0).at(0).value<QPalette>(), newPalette));
+#endif
QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
- QCOMPARE(signalSpy.count(), 2);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 2);
QVERIFY(palettesMatch(signalSpy.at(1).at(0).value<QPalette>(), oldPalette));
+#endif
QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
- QCOMPARE(signalSpy.count(), 2);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 2);
+#endif
QCOMPARE(QGuiApplication::palette(), QPalette());
}
+void tst_QGuiApplication::paletteNoCrash()
+{
+ QGuiApplication::setDesktopSettingsAware(false);
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+ // this would crash on windows (QTBUG-111527)
+ QGuiApplication a(argc, argv);
+}
+
void tst_QGuiApplication::font()
{
int argc = 1;
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
QGuiApplication app(argc, argv);
+#if QT_DEPRECATED_SINCE(6, 0)
QSignalSpy signalSpy(&app, SIGNAL(fontChanged(QFont)));
+#endif
QFont oldFont = QGuiApplication::font();
QFont newFont = QFont("BogusFont", 33);
QGuiApplication::setFont(newFont);
QCOMPARE(QGuiApplication::font(), newFont);
- QCOMPARE(signalSpy.count(), 1);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 1);
QCOMPARE(signalSpy.at(0).at(0), QVariant(newFont));
+#endif
QGuiApplication::setFont(oldFont);
QCOMPARE(QGuiApplication::font(), oldFont);
- QCOMPARE(signalSpy.count(), 2);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 2);
QCOMPARE(signalSpy.at(1).at(0), QVariant(oldFont));
+#endif
QGuiApplication::setFont(oldFont);
QCOMPARE(QGuiApplication::font(), oldFont);
- QCOMPARE(signalSpy.count(), 2);
+#if QT_DEPRECATED_SINCE(6, 0)
+ QCOMPARE(signalSpy.size(), 2);
+#endif
}
class BlockableWindow : public QWindow
@@ -895,9 +895,9 @@ void tst_QGuiApplication::quitOnLastWindowClosed()
app.exec();
- QCOMPARE(spyAboutToQuit.count(), 1);
+ QCOMPARE(spyAboutToQuit.size(), 1);
// Should be around 10 if closing caused the quit
- QVERIFY2(spyTimeout.count() < 15, QByteArray::number(spyTimeout.count()).constData());
+ QVERIFY2(spyTimeout.size() < 15, QByteArray::number(spyTimeout.size()).constData());
}
void tst_QGuiApplication::quitOnLastWindowClosedMulti()
@@ -938,7 +938,7 @@ void tst_QGuiApplication::quitOnLastWindowClosedMulti()
app.exec();
QVERIFY(!prematureQuit);
- QCOMPARE(spyAboutToQuit.count(), 1); // fired only once
+ QCOMPARE(spyAboutToQuit.size(), 1); // fired only once
}
void tst_QGuiApplication::dontQuitOnLastWindowClosed()
@@ -966,8 +966,8 @@ void tst_QGuiApplication::dontQuitOnLastWindowClosed()
app.setQuitOnLastWindowClosed(true); // restore underlying static to default value
- QCOMPARE(spyTimeout.count(), 1); // quit timer fired
- QCOMPARE(spyLastWindowClosed.count(), 1); // lastWindowClosed emitted
+ QCOMPARE(spyTimeout.size(), 1); // quit timer fired
+ QCOMPARE(spyLastWindowClosed.size(), 1); // lastWindowClosed emitted
}
class QuitSpy : public QObject
@@ -1156,8 +1156,8 @@ void tst_QGuiApplication::layoutDirection()
{
qRegisterMetaType<Qt::LayoutDirection>();
- Qt::LayoutDirection oldDirection = QGuiApplication::layoutDirection();
- Qt::LayoutDirection newDirection = oldDirection == Qt::LeftToRight ? Qt::RightToLeft : Qt::LeftToRight;
+ const Qt::LayoutDirection oldDirection = QGuiApplication::layoutDirection();
+ const Qt::LayoutDirection newDirection = oldDirection == Qt::LeftToRight ? Qt::RightToLeft : Qt::LeftToRight;
QGuiApplication::setLayoutDirection(newDirection);
QCOMPARE(QGuiApplication::layoutDirection(), newDirection);
@@ -1169,14 +1169,70 @@ void tst_QGuiApplication::layoutDirection()
QGuiApplication::setLayoutDirection(oldDirection);
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
- QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.size(), 1);
QCOMPARE(signalSpy.at(0).at(0).toInt(), static_cast<int>(oldDirection));
QGuiApplication::setLayoutDirection(oldDirection);
QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
- QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.size(), 1);
+
+ // with QGuiApplication instantiated, install a translator that gives us control
+ class LayoutDirectionTranslator : public QTranslator
+ {
+ public:
+ LayoutDirectionTranslator(Qt::LayoutDirection direction)
+ : direction(direction)
+ {}
+
+ bool isEmpty() const override { return false; }
+ QString translate(const char *context, const char *sourceText, const char *disambiguation, int n) const override
+ {
+ if (QByteArrayView(sourceText) == "QT_LAYOUT_DIRECTION")
+ return direction == Qt::LeftToRight ? QLatin1String("LTR") : QLatin1String("RTL");
+ return QTranslator::translate(context, sourceText, disambiguation, n);
+ }
+
+ const Qt::LayoutDirection direction;
+ };
+
+ int layoutDirectionChangedCount = 0;
+ // reset to auto-detection, should be back to oldDirection now
+ QGuiApplication::setLayoutDirection(Qt::LayoutDirectionAuto);
+ QCOMPARE(QGuiApplication::layoutDirection(), oldDirection);
+ signalSpy.clear();
+ {
+ // this translator doesn't change the direction
+ LayoutDirectionTranslator translator(oldDirection);
+ QGuiApplication::installTranslator(&translator);
+ QCOMPARE(QGuiApplication::layoutDirection(), translator.direction);
+ QCOMPARE(signalSpy.size(), layoutDirectionChangedCount);
+ }
+ QCOMPARE(signalSpy.size(), layoutDirectionChangedCount); // ltrTranslator removed, no change
+
+ // install a new translator that changes the direction
+ {
+ LayoutDirectionTranslator translator(newDirection);
+ QGuiApplication::installTranslator(&translator);
+ QCOMPARE(QGuiApplication::layoutDirection(), translator.direction);
+ QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount);
+ }
+ // rtlTranslator removed
+ QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount);
+
+ // override translation
+ QGuiApplication::setLayoutDirection(newDirection);
+ QCOMPARE(signalSpy.size(), ++layoutDirectionChangedCount);
+ {
+ // this translator will be ignored
+ LayoutDirectionTranslator translator(oldDirection);
+ QGuiApplication::installTranslator(&translator);
+ QCOMPARE(QGuiApplication::layoutDirection(), newDirection);
+ QCOMPARE(signalSpy.size(), layoutDirectionChangedCount);
+ }
+ QCOMPARE(signalSpy.size(), layoutDirectionChangedCount);
}
+
void tst_QGuiApplication::globalShareContext()
{
#ifndef QT_NO_OPENGL
@@ -1267,6 +1323,40 @@ void tst_QGuiApplication::staticFunctions()
QPixmap::defaultDepth();
}
+void tst_QGuiApplication::topLevelAt()
+{
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qguiapplication") };
+ QGuiApplication app(argc, argv);
+
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("QGuiApplication::topLevelAt() is not Wayland compliant, see also QTBUG-121015");
+
+ QWindow bottom;
+ bottom.setObjectName("Bottom");
+ bottom.setFlag(Qt::FramelessWindowHint);
+ bottom.setGeometry(200, 200, 200, 200);
+ bottom.showNormal();
+ QVERIFY(QTest::qWaitForWindowExposed(&bottom));
+ QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &bottom);
+
+ QWindow top;
+ top.setObjectName("Top");
+ top.setFlag(Qt::FramelessWindowHint);
+ top.setGeometry(200, 200, 200, 200);
+ top.showNormal();
+ QVERIFY(QTest::qWaitForWindowExposed(&top));
+ top.raise();
+ QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &top);
+
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowMasks))
+ QSKIP("QWindow::setMask() is not supported.");
+
+ top.setMask(QRect(0, 0, 50, 50));
+ QTRY_COMPARE(app.topLevelAt(QPoint(300, 300)), &bottom);
+ QTRY_COMPARE(app.topLevelAt(QPoint(225, 225)), &top);
+}
+
void tst_QGuiApplication::settableStyleHints_data()
{
QTest::addColumn<bool>("appInstance");
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc
deleted file mode 100644
index b26fba37b9..0000000000
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource prefix="/">
- <file>icons/usericon.png</file>
- <file>icons/appicon.png</file>
-</qresource>
-</RCC>
diff --git a/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt b/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt
new file mode 100644
index 0000000000..37848d8cec
--- /dev/null
+++ b/tests/auto/gui/kernel/qguichronotimer/CMakeLists.txt
@@ -0,0 +1,38 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_qguichronotimer Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguichronotimer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+function(addGuiChronoTimerTest test)
+ qt_internal_add_test(${test}
+ SOURCES
+ ../../../corelib/kernel/qchronotimer/tst_qchronotimer.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::TestPrivate
+ )
+endfunction()
+
+addGuiChronoTimerTest(tst_qguichronotimer)
+qt_internal_extend_target(tst_qguichronotimer
+ DEFINES
+ tst_Qtimer=tst_QGuiChronoTimer
+)
+
+if(QT_FEATURE_glib AND UNIX)
+ addGuiChronoTimerTest(tst_qguichronotimer_no_glib)
+ qt_internal_extend_target(tst_qguichronotimer_no_glib
+ DEFINES
+ DISABLE_GLIB
+ tst_QTimer=tst_QGuiChronoTimer_no_glib # Class name in the unittest
+ )
+endif()
diff --git a/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt
index b1c0508198..62299f77df 100644
--- a/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt
@@ -1,12 +1,40 @@
-# Generated from qguieventdispatcher.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguieventdispatcher Test:
#####################################################################
-qt_internal_add_test(tst_qguieventdispatcher
- SOURCES
- ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
- PUBLIC_LIBRARIES
- Qt::Gui
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguieventdispatcher LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+set(test_names "tst_qguieventdispatcher")
+if(QT_FEATURE_glib AND UNIX)
+ list(APPEND test_names "tst_qguieventdispatcher_no_glib")
+endif()
+
+foreach(test ${test_names})
+ qt_internal_add_test(${test}
+ NO_BATCH
+ SOURCES
+ ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp
+ LIBRARIES
+ Qt::Gui
+ )
+endforeach()
+
+qt_internal_extend_target(tst_qguieventdispatcher
+ DEFINES
+ tst_QEventDispatcher=tst_qguieventdispatcher
)
+
+if (TARGET tst_qeventdispatcher_no_glib)
+ qt_internal_extend_target(tst_qguieventdispatcher_no_glib
+ DEFINES
+ DISABLE_GLIB
+ tst_QEventDispatcher=tst_qguieventdispatcher_no_glib
+ )
+endif()
diff --git a/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt
index ec9441a1dc..89c518be10 100644
--- a/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qguieventloop.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguieventloop Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguieventloop LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qguieventloop
SOURCES
../../../corelib/kernel/qeventloop/tst_qeventloop.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::Network
@@ -17,7 +24,7 @@ qt_internal_add_test(tst_qguieventloop
#####################################################################
qt_internal_extend_target(tst_qguieventloop CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
user32
)
diff --git a/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt
index 0887f05fc6..7c93e4b8a2 100644
--- a/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qguimetatype.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguimetatype Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguimetatype LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qguimetatype
SOURCES
tst_qguimetatype.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
index aac914bc68..54e95a2b38 100644
--- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
+++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore>
@@ -45,6 +20,8 @@ private slots:
void sizeOf();
void flags_data();
void flags();
+ void flags2_data();
+ void flags2();
void construct_data();
void construct();
void constructCopy_data();
@@ -318,14 +295,27 @@ struct TypeAlignment
enum { Value = alignof(T) };
};
+template <typename T> void addFlagsRow(const char *name, int id = qMetaTypeId<T>())
+{
+ QTest::newRow(name)
+ << id
+ << bool(QTypeInfo<T>::isRelocatable)
+ << bool(!std::is_trivially_default_constructible_v<T>)
+ << bool(!std::is_trivially_copy_constructible_v<T>)
+ << bool(!std::is_trivially_destructible_v<T>);
+}
+
+// tst_QGuiMetaType::flags is nearly identical to tst_QMetaType::flags
void tst_QGuiMetaType::flags_data()
{
QTest::addColumn<int>("type");
QTest::addColumn<bool>("isRelocatable");
- QTest::addColumn<bool>("isComplex");
+ QTest::addColumn<bool>("needsConstruction");
+ QTest::addColumn<bool>("needsCopyConstruction");
+ QTest::addColumn<bool>("needsDestruction");
#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
- QTest::newRow(#RealType) << MetaTypeId << bool(QTypeInfo<RealType>::isRelocatable) << bool(QTypeInfo<RealType>::isComplex);
+ addFlagsRow<RealType>(#RealType, MetaTypeId);
QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW)
#undef ADD_METATYPE_TEST_ROW
}
@@ -334,13 +324,62 @@ void tst_QGuiMetaType::flags()
{
QFETCH(int, type);
QFETCH(bool, isRelocatable);
- QFETCH(bool, isComplex);
+ QFETCH(bool, needsConstruction);
+ QFETCH(bool, needsCopyConstruction);
+ QFETCH(bool, needsDestruction);
- QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), isComplex);
- QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), isComplex);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), needsConstruction);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsCopyConstruction), needsCopyConstruction);
+ QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), needsDestruction);
QCOMPARE(bool(QMetaType(type).flags() & QMetaType::RelocatableType), isRelocatable);
}
+template <typename T> static void addFlags2Row(QMetaType metaType = QMetaType::fromType<T>())
+{
+ QTest::newRow(metaType.name() ? metaType.name() : "UnknownType")
+ << metaType
+ << std::is_default_constructible_v<T>
+ << std::is_copy_constructible_v<T>
+ << std::is_move_constructible_v<T>
+ << std::is_destructible_v<T>
+ << (QTypeTraits::has_operator_equal<T>::value || QTypeTraits::has_operator_less_than<T>::value)
+ << QTypeTraits::has_operator_less_than<T>::value;
+};
+
+// tst_QGuiMetaType::flags2 is nearly identical to tst_QMetaType::flags2
+void tst_QGuiMetaType::flags2_data()
+{
+ QTest::addColumn<QMetaType>("type");
+ QTest::addColumn<bool>("isDefaultConstructible");
+ QTest::addColumn<bool>("isCopyConstructible");
+ QTest::addColumn<bool>("isMoveConstructible");
+ QTest::addColumn<bool>("isDestructible");
+ QTest::addColumn<bool>("isEqualityComparable");
+ QTest::addColumn<bool>("isOrdered");
+
+#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \
+ addFlags2Row<RealType>();
+QT_FOR_EACH_STATIC_GUI_CLASS(ADD_METATYPE_TEST_ROW)
+#undef ADD_METATYPE_TEST_ROW
+}
+
+void tst_QGuiMetaType::flags2()
+{
+ QFETCH(QMetaType, type);
+ QFETCH(bool, isDefaultConstructible);
+ QFETCH(bool, isCopyConstructible);
+ QFETCH(bool, isMoveConstructible);
+ QFETCH(bool, isDestructible);
+ QFETCH(bool, isEqualityComparable);
+ QFETCH(bool, isOrdered);
+
+ QCOMPARE(type.isDefaultConstructible(), isDefaultConstructible);
+ QCOMPARE(type.isCopyConstructible(), isCopyConstructible);
+ QCOMPARE(type.isMoveConstructible(), isMoveConstructible);
+ QCOMPARE(type.isDestructible(), isDestructible);
+ QCOMPARE(type.isEqualityComparable(), isEqualityComparable);
+ QCOMPARE(type.isOrdered(), isOrdered);
+}
void tst_QGuiMetaType::construct_data()
{
diff --git a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
index 5375155a82..bc292e133b 100644
--- a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt
@@ -1,13 +1,38 @@
-# Generated from qguitimer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguitimer Test:
#####################################################################
-qt_internal_add_test(tst_qguitimer
- SOURCES
- ../../../corelib/kernel/qtimer/tst_qtimer.cpp
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::Gui
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguitimer LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+function(addGuiTimerTest test)
+ qt_internal_add_test(${test}
+ SOURCES
+ ../../../corelib/kernel/qtimer/tst_qtimer.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::TestPrivate
+ )
+endfunction()
+
+addGuiTimerTest(tst_qguitimer)
+qt_internal_extend_target(tst_qguitimer
+ DEFINES
+ tst_Qtimer=tst_QGuiTimer
)
+
+if(QT_FEATURE_glib AND UNIX)
+ addGuiTimerTest(tst_qguitimer_no_glib)
+ qt_internal_extend_target(tst_qguitimer_no_glib
+ DEFINES
+ DISABLE_GLIB
+ tst_QTimer=tst_QGuiTimer_no_glib # Class name in the unittest
+ )
+endif()
diff --git a/tests/auto/gui/kernel/qguivariant/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt
index 3a0adab6e3..eda22152ec 100644
--- a/tests/auto/gui/kernel/qguivariant/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qguivariant.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(test)
add_subdirectory(no_application)
diff --git a/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt
index 2e6f548f11..4470411a3b 100644
--- a/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from no_application.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## no_application Test:
#####################################################################
-qt_internal_add_test(no_application
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_gui_variant_no_application LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_gui_variant_no_application
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qguivariant/no_application/main.cpp b/tests/auto/gui/kernel/qguivariant/no_application/main.cpp
index 1ab0f63240..2b6ec7b870 100644
--- a/tests/auto/gui/kernel/qguivariant/no_application/main.cpp
+++ b/tests/auto/gui/kernel/qguivariant/no_application/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt
index a3292511bd..36b732e4ae 100644
--- a/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt
@@ -1,27 +1,29 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qguivariant Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qguivariant LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# Resources:
+file(GLOB_RECURSE qguivariant_resource_files
+ RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
+ "data/*"
+)
+
qt_internal_add_test(tst_qguivariant
SOURCES
tst_qguivariant.cpp
INCLUDE_DIRECTORIES
../../../../other/qvariant_common
- PUBLIC_LIBRARIES
+ 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}
-)
-
diff --git a/tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc b/tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc
deleted file mode 100644
index 576d9cda1c..0000000000
--- a/tests/auto/gui/kernel/qguivariant/test/qguivariant.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>data</file>
-</qresource>
-</RCC>
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index aea5cb3ac3..cb22024f76 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -245,7 +220,7 @@ void tst_QGuiVariant::toColor_data()
QTest::newRow("qstring(#ff0000)") << QVariant(QString::fromUtf8("#ff0000")) << c;
QTest::newRow("qbytearray(#ff0000)") << QVariant(QByteArray("#ff0000")) << c;
- c.setNamedColor("#88112233");
+ c = QColor::fromString("#88112233");
QTest::newRow("qstring(#88112233)") << QVariant(QString::fromUtf8("#88112233")) << c;
QTest::newRow("qbytearray(#88112233)") << QVariant(QByteArray("#88112233")) << c;
}
diff --git a/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt b/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt
index bdd9a5e17f..aa61bfbb0b 100644
--- a/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qhighdpi/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qhighdpi.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qhighdpi Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhighdpi LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qhighdpi
SOURCES
tst_qhighdpi.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
index b732954230..6fe4faec03 100644
--- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
+++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <private/qhighdpiscaling_p.h>
#include <qpa/qplatformscreen.h>
@@ -35,6 +10,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QStringView>
+#include <QSignalSpy>
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
@@ -60,10 +36,13 @@ private slots:
void screenDpiAndDpr_data();
void screenDpiAndDpr();
void screenDpiChange();
+ void screenDpiChangeWithWindow();
void environment_QT_SCALE_FACTOR();
void environment_QT_SCREEN_SCALE_FACTORS_data();
void environment_QT_SCREEN_SCALE_FACTORS();
void environment_QT_USE_PHYSICAL_DPI();
+ void environment_QT_SCALE_FACTOR_ROUNDING_POLICY();
+ void application_setScaleFactorRoundingPolicy();
void screenAt_data();
void screenAt();
void screenGeometry_data();
@@ -76,6 +55,10 @@ private slots:
void mouseEvents();
void mouseVelocity();
void mouseVelocity_data();
+ void setCursor();
+ void setCursor_data();
+ void setGlobalFactorEmits();
+ void setScreenFactorEmits();
};
/// Offscreen platform plugin test setup
@@ -86,7 +69,7 @@ const int standardScreenCount = 3;
QJsonArray tst_QHighDpi::createStandardScreens(const QList<qreal> &dpiValues)
{
- Q_ASSERT(dpiValues.count() == standardScreenCount);
+ Q_ASSERT(dpiValues.size() == standardScreenCount);
// Create row of three screens: screen#0 screen#1 screen#2
return QJsonArray {
@@ -203,65 +186,6 @@ QJsonObject tst_QHighDpi::offscreenConfiguration()
return getConfiguration(platformNativeInterface);
}
-// JsonValueRef implements support for mutating nested JSON structures, e.g.
-//
-// JsonValueRef::get(&config)["screens"][0]["logicalDpi"] = 192
-//
-class JsonValueRef {
-public:
- static JsonValueRef get(QJsonValue *value) {
- return JsonValueRef(value);
- }
-
- JsonValueRef(QJsonValue *value)
- : m_value(value) { }
-
- JsonValueRef(QJsonValue *value, JsonValueRef *parent, QString key)
- : m_value(value), m_parent(parent), m_key(key) { }
-
- JsonValueRef(QJsonValue *value, JsonValueRef *parent, int index)
- : m_value(value), m_parent(parent), m_index(index) { }
-
- ~JsonValueRef() {
- if (m_parent) {
- if (!m_key.isNull()) {
- QJsonObject parentObject = m_parent->m_value->toObject();
- parentObject[m_key] = *m_value;
- *m_parent->m_value = parentObject;
- } else if (m_index > -1) {
- QJsonArray parentArray = m_parent->m_value->toArray();
- parentArray[m_index] = *m_value;
- *m_parent->m_value = parentArray;
- }
- delete m_value; // owned if we have a parent, see operator[]
- }
- }
-
- JsonValueRef operator[](const char *str) {
- QString key = QString::fromUtf8(str);
- return JsonValueRef(new QJsonValue((*m_value)[key]), this, key);
- }
-
- JsonValueRef operator[](int index) {
- return JsonValueRef(new QJsonValue((*m_value)[index]), this, index);
- }
-
- void operator=(int value) {
- *m_value = QJsonValue(value);
- }
-
- void operator=(const char *str) {
- *m_value = QJsonValue(QString(str));
- }
-
-private:
- Q_DISABLE_COPY(JsonValueRef);
- QJsonValue *m_value = nullptr;
- JsonValueRef *m_parent = nullptr;
- QString m_key;
- int m_index = -1;
-};
-
void tst_QHighDpi::cleanup()
{
// Some test functions set environment variables. Unset them here,
@@ -269,6 +193,7 @@ void tst_QHighDpi::cleanup()
qunsetenv("QT_SCALE_FACTOR");
qunsetenv("QT_SCREEN_SCALE_FACTORS");
qunsetenv("QT_USE_PHYSICAL_DPI");
+ qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY");
}
void tst_QHighDpi::qhighdpiscaling_data()
@@ -314,6 +239,9 @@ void tst_QHighDpi::screenDpiAndDpr()
QWindow window(screen);
QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
+ window.setGeometry(QRect(screen->geometry().center(), QSize(10, 10)));
+ window.create();
+ QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
}
}
@@ -327,10 +255,12 @@ void tst_QHighDpi::screenDpiChange()
// Set new DPI
int newDpi = 192;
QJsonValue config = offscreenConfiguration();
- JsonValueRef::get(&config)["screens"][0]["logicalDpi"] = newDpi;
- JsonValueRef::get(&config)["screens"][1]["logicalDpi"] = newDpi;
- JsonValueRef::get(&config)["screens"][2]["logicalDpi"] = newDpi;
- setOffscreenConfiguration(config.toObject());
+ // API defect until Qt 7, so go indirectly via CBOR
+ QCborMap map = QCborMap::fromJsonObject(config.toObject());
+ map[QLatin1String("screens")][0][QLatin1String("logicalDpi")] = newDpi;
+ map[QLatin1String("screens")][1][QLatin1String("logicalDpi")] = newDpi;
+ map[QLatin1String("screens")][2][QLatin1String("logicalDpi")] = newDpi;
+ setOffscreenConfiguration(map.toJsonObject());
// TODO check events
@@ -338,16 +268,52 @@ void tst_QHighDpi::screenDpiChange()
for (QScreen *screen : app->screens()) {
QCOMPARE(screen->devicePixelRatio(), newDpi / standardBaseDpi);
QCOMPARE(screen->logicalDotsPerInch(), newDpi / screen->devicePixelRatio());
+
QWindow window(screen);
QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
+ window.create();
+ QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio());
}
QCOMPARE(app->devicePixelRatio(), newDpi / standardBaseDpi);
}
+void tst_QHighDpi::screenDpiChangeWithWindow()
+{
+ QList<qreal> dpiValues = { 96, 192, 288 };
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ // Create windows for screens
+ QList<QScreen *> screens = app->screens();
+ QList<QWindow *> windows;
+ for (int i = 0; i < screens.count(); ++i) {
+ QScreen *screen = screens[i];
+ QWindow *window = new QWindow();
+ windows.append(window);
+ window->setGeometry(QRect(screen->geometry().center(), QSize(10, 10)));
+ window->create();
+ QCOMPARE(window->devicePixelRatio(), dpiValues[i] / standardBaseDpi);
+ }
+
+ // Change screen DPI
+ QList<qreal> newDpiValues = { 288, 192, 96 };
+ QJsonValue config = offscreenConfiguration();
+ QCborMap map = QCborMap::fromJsonObject(config.toObject());
+ for (int i = 0; i < screens.count(); ++i) {
+ map[QLatin1String("screens")][i][QLatin1String("logicalDpi")] = newDpiValues[i];
+ }
+ setOffscreenConfiguration(map.toJsonObject());
+
+ // Verify that window DPR changes on Screen DPI change.
+ for (int i = 0; i < screens.count(); ++i) {
+ QWindow *window = windows[i];
+ QCOMPARE(window->devicePixelRatio(), newDpiValues[i] / standardBaseDpi);
+ }
+}
+
void tst_QHighDpi::environment_QT_SCALE_FACTOR()
{
qreal factor = 3.1415;
- qputenv("QT_SCALE_FACTOR", QByteArray::number(factor));
+ qputenv("QT_SCALE_FACTOR", std::to_string(factor));
QList<qreal> dpiValues { 96, 144, 192 };
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
@@ -390,9 +356,10 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS()
QFETCH(QByteArray, environment);
QFETCH(QList<qreal>, expectedDprValues);
+ qputenv("QT_SCREEN_SCALE_FACTORS", environment);
+
// Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR.
{
- qputenv("QT_SCREEN_SCALE_FACTORS", environment);
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi));
int i = 0;
for (QScreen *screen : app->screens()) {
@@ -404,6 +371,18 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS()
QCOMPARE(window.devicePixelRatio(), expextedDpr);
}
}
+
+ // Verify that setHighDpiScaleFactorRoundingPolicy applies to QT_SCREEN_SCALE_FACTORS as well
+ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi));
+ int i = 0;
+ for (QScreen *screen : app->screens()) {
+ qreal expectedRounderDpr = qRound(expectedDprValues[i++]);
+ qreal windowDpr = QWindow(screen).devicePixelRatio();
+ QCOMPARE(windowDpr, expectedRounderDpr);
+ }
+ }
}
void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI()
@@ -431,6 +410,59 @@ void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI()
}
}
+void tst_QHighDpi::environment_QT_SCALE_FACTOR_ROUNDING_POLICY()
+{
+ QList<qreal> dpiValues { 96, 144, 192 };
+
+ qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough");
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96));
+ }
+
+ qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "Round");
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96)));
+ }
+
+ qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY");
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96));
+ }
+}
+
+void tst_QHighDpi::application_setScaleFactorRoundingPolicy()
+{
+ QList<qreal> dpiValues { 96, 144, 192 };
+ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96)));
+ }
+
+ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96));
+ }
+
+ // Verify that environment overrides app setting
+ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
+ qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough");
+ {
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+ for (int i = 0; i < dpiValues.size(); ++i)
+ QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96));
+ }
+}
+
void tst_QHighDpi::minimumDpr()
{
QList<qreal> dpiValues { 40, 60, 95 };
@@ -474,7 +506,7 @@ void tst_QHighDpi::screenAt()
QFETCH(QList<qreal>, dpiValues);
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
- QCOMPARE(app->screens().count(), standardScreenCount); // standard setup
+ QCOMPARE(app->screens().size(), standardScreenCount); // standard setup
// Verify that screenAt() returns the correct or no screen for various points,
// for all screens.
@@ -483,7 +515,7 @@ void tst_QHighDpi::screenAt()
qreal dpi = dpiValues[i++];
// veryfy virtualSiblings and that AA_EnableHighDpiScaling is active
- QCOMPARE(screen->virtualSiblings().count(), standardScreenCount);
+ QCOMPARE(screen->virtualSiblings().size(), standardScreenCount);
QCOMPARE(screen->geometry().size(), QSize(standardScreenWidth, standardScreenHeight) * (96.0 / dpi));
// test points on screen
@@ -805,5 +837,51 @@ void tst_QHighDpi::mouseVelocity()
}
}
+void tst_QHighDpi::setCursor_data()
+{
+ standardScreenDpiTestData();
+}
+
+void tst_QHighDpi::setCursor()
+{
+ QFETCH(QList<qreal>, dpiValues);
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ for (QScreen *screen : app->screens()) {
+ QPoint center = screen->geometry().center();
+ QCursor::setPos(center.x(), center.y());
+ QCOMPARE(QCursor::pos(), center);
+ }
+}
+
+void tst_QHighDpi::setGlobalFactorEmits()
+{
+ QList<qreal> dpiValues { 96, 96, 96 };
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ std::vector<std::unique_ptr<QSignalSpy>> spies;
+ for (QScreen *screen : app->screens())
+ spies.push_back(std::make_unique<QSignalSpy>(screen, &QScreen::geometryChanged));
+
+ QHighDpiScaling::setGlobalFactor(2);
+
+ for (const auto &spy : spies)
+ QCOMPARE(spy->count(), 1);
+
+ QHighDpiScaling::setGlobalFactor(1);
+}
+
+void tst_QHighDpi::setScreenFactorEmits()
+{
+ QList<qreal> dpiValues { 96, 96, 96 };
+ std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
+
+ for (QScreen *screen : app->screens()) {
+ QSignalSpy spy(screen, &QScreen::geometryChanged);
+ QHighDpiScaling::setScreenFactor(screen, 2);
+ QCOMPARE(spy.count(), 1);
+ }
+}
+
#include "tst_qhighdpi.moc"
QTEST_APPLESS_MAIN(tst_QHighDpi);
diff --git a/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt b/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt
index aea72357dd..afbfd9bb37 100644
--- a/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qinputdevice/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qinputdevice.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qinputdevice Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qinputdevice LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qinputdevice
SOURCES
tst_qinputdevice.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
index 077a44b229..8587aebf2a 100644
--- a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
+++ b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qpa/qwindowsysteminterface.h>
@@ -43,12 +18,56 @@ private slots:
void multiSeatDevices();
private:
+ const QInputDevice *getPrimaryKeyboard(const QString& seatName = QString());
+ const QPointingDevice *getPrimaryPointingDevice(const QString& seatName = QString());
};
void tst_QInputDevice::initTestCase()
{
}
+const QInputDevice *tst_QInputDevice::getPrimaryKeyboard(const QString& seatName)
+{
+ QList<const QInputDevice *> devices = QInputDevice::devices();
+ const QInputDevice *ret = nullptr;
+ for (const QInputDevice *d : devices) {
+ if (d->type() != QInputDevice::DeviceType::Keyboard)
+ continue;
+ if (seatName.isNull() || d->seatName() == seatName) {
+ // the master keyboard's parent is not another input device
+ if (!d->parent() || !qobject_cast<const QInputDevice *>(d->parent()))
+ return d;
+ if (!ret)
+ ret = d;
+ }
+ }
+ return ret;
+}
+
+const QPointingDevice *tst_QInputDevice::getPrimaryPointingDevice(const QString& seatName)
+{
+ QList<const QInputDevice *> devices = QInputDevice::devices();
+ const QPointingDevice *mouse = nullptr;
+ const QPointingDevice *touchpad = nullptr;
+ for (const QInputDevice *dev : devices) {
+ if (!seatName.isNull() && dev->seatName() != seatName)
+ continue;
+ if (dev->type() == QInputDevice::DeviceType::Mouse) {
+ if (!mouse)
+ mouse = static_cast<const QPointingDevice *>(dev);
+ // the core pointer is likely a mouse, and its parent is not another input device
+ if (!mouse->parent() || !qobject_cast<const QInputDevice *>(mouse->parent()))
+ return mouse;
+ } else if (dev->type() == QInputDevice::DeviceType::TouchPad) {
+ if (!touchpad || !dev->parent() || dev->parent()->metaObject() != dev->metaObject())
+ touchpad = static_cast<const QPointingDevice *>(dev);
+ }
+ }
+ if (mouse)
+ return mouse;
+ return touchpad;
+}
+
void tst_QInputDevice::multiSeatDevices()
{
QWindowSystemInterface::registerInputDevice(new QInputDevice("seat 1 kbd", 1000, QInputDevice::DeviceType::Keyboard, "seat 1", this));
@@ -59,15 +78,17 @@ void tst_QInputDevice::multiSeatDevices()
QWindowSystemInterface::registerInputDevice(new QPointingDevice("seat 2 mouse", 2010, QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic,
QInputDevice::Capability::Position | QInputDevice::Capability::Hover,
1, 2, "seat 2", QPointingDeviceUniqueId(), this));
- QVERIFY(QInputDevice::devices().count() >= 4);
+ QVERIFY(QInputDevice::devices().size() >= 4);
QVERIFY(QInputDevicePrivate::fromId(1010));
QVERIFY(QInputDevicePrivate::fromId(1010)->hasCapability(QInputDevice::Capability::Scroll));
QVERIFY(QInputDevicePrivate::fromId(2010));
QVERIFY(!QInputDevicePrivate::fromId(2010)->hasCapability(QInputDevice::Capability::Scroll));
QVERIFY(QInputDevice::primaryKeyboard());
- QCOMPARE(QInputDevice::primaryKeyboard()->systemId(), qint64(1) << 33);
+ if (!getPrimaryKeyboard())
+ QCOMPARE(QInputDevice::primaryKeyboard()->systemId(), qint64(1) << 33);
QVERIFY(QPointingDevice::primaryPointingDevice());
- QCOMPARE(QPointingDevice::primaryPointingDevice()->systemId(), 1);
+ if (!getPrimaryPointingDevice())
+ QCOMPARE(QPointingDevice::primaryPointingDevice()->systemId(), 1);
QVERIFY(QInputDevice::primaryKeyboard("seat 1"));
QCOMPARE(QInputDevice::primaryKeyboard("seat 1")->systemId(), 1000);
QVERIFY(QPointingDevice::primaryPointingDevice("seat 1"));
diff --git a/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt
index bbe8652e99..e3ce0774bc 100644
--- a/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qinputmethod.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qinputmethod Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qinputmethod LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qinputmethod
SOURCES
tst_qinputmethod.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp
index 318309d959..619de7bed3 100644
--- a/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp
+++ b/tests/auto/gui/kernel/qinputmethod/tst_qinputmethod.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -150,7 +125,7 @@ void tst_qinputmethod::animating()
QSignalSpy spy(qApp->inputMethod(), SIGNAL(animatingChanged()));
m_platformInputContext.emitAnimatingChanged();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_qinputmethod::keyboarRectangle()
@@ -162,7 +137,7 @@ void tst_qinputmethod::keyboarRectangle()
QSignalSpy spy(qApp->inputMethod(), SIGNAL(keyboardRectangleChanged()));
m_platformInputContext.emitKeyboardRectChanged();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_qinputmethod::inputItemTransform()
@@ -177,7 +152,7 @@ void tst_qinputmethod::inputItemTransform()
qApp->inputMethod()->setInputItemTransform(transform);
QCOMPARE(qApp->inputMethod()->inputItemTransform(), transform);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
// reset
qApp->inputMethod()->setInputItemTransform(QTransform());
@@ -274,13 +249,13 @@ void tst_qinputmethod::query()
void tst_qinputmethod::inputDirection()
{
- QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, 0);
+ auto originalCount = m_platformInputContext.m_inputDirectionCallCount;
qApp->inputMethod()->inputDirection();
- QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, 1);
+ QCOMPARE(m_platformInputContext.m_inputDirectionCallCount, originalCount + 1);
- QCOMPARE(m_platformInputContext.m_localeCallCount, 0);
+ originalCount = m_platformInputContext.m_localeCallCount;
qApp->inputMethod()->locale();
- QCOMPARE(m_platformInputContext.m_localeCallCount, 1);
+ QCOMPARE(m_platformInputContext.m_localeCallCount, originalCount + 1);
}
void tst_qinputmethod::inputMethodAccepted()
diff --git a/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt
index bd9f602e56..c3c9892d14 100644
--- a/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qkeyevent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qkeyevent Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qkeyevent LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qkeyevent
SOURCES
tst_qkeyevent.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp
index 1873c190d5..7d8e0aa5dc 100644
--- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp
+++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp
@@ -1,30 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
diff --git a/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt
index 9d0e25d356..1676302d1b 100644
--- a/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt
@@ -1,17 +1,15 @@
-# Generated from qkeysequence.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qkeysequence Test:
#####################################################################
-qt_internal_add_test(tst_qkeysequence
- SOURCES
- tst_qkeysequence.cpp
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::Gui
- Qt::GuiPrivate
-)
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qkeysequence LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
# Resources:
set(qkeysequence_resource_files
@@ -19,10 +17,13 @@ set(qkeysequence_resource_files
"qt_de.qm"
)
-qt_internal_add_resource(tst_qkeysequence "qkeysequence"
- PREFIX
- "/"
- FILES
- ${qkeysequence_resource_files}
+qt_internal_add_test(tst_qkeysequence
+ SOURCES
+ tst_qkeysequence.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ TESTDATA ${qkeysequence_resource_files}
+ BUILTIN_TESTDATA
)
-
diff --git a/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc b/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc
deleted file mode 100644
index e224faaddd..0000000000
--- a/tests/auto/gui/kernel/qkeysequence/qkeysequence.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource>
- <file>keys_de.qm</file>
- <file>qt_de.qm</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
index fb7296f834..67fef3cf44 100644
--- a/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
+++ b/tests/auto/gui/kernel/qkeysequence/tst_qkeysequence.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -498,10 +473,15 @@ void tst_QKeySequence::toStringFromKeycode_data()
QTest::newRow("A") << QKeySequence(Qt::Key_A) << "A";
QTest::newRow("-1") << QKeySequence(-1) << "";
QTest::newRow("Unknown") << QKeySequence(Qt::Key_unknown) << "";
+ QTest::newRow("Ctrl+Unknown") << QKeySequence(Qt::ControlModifier | Qt::Key_unknown) << "";
QTest::newRow("Ctrl+Num+Ins") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Insert) << "Ctrl+Num+Ins";
QTest::newRow("Ctrl+Num+Del") << QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Num+Del";
QTest::newRow("Ctrl+Alt+Num+Del") << QKeySequence(Qt::ControlModifier | Qt::AltModifier | Qt::KeypadModifier | Qt::Key_Delete) << "Ctrl+Alt+Num+Del";
QTest::newRow("Ctrl+Ins") << QKeySequence(Qt::ControlModifier | Qt::Key_Insert) << "Ctrl+Ins";
+ QTest::newRow("Ctrl") << QKeySequence(Qt::Key_Control) << "Control";
+ QTest::newRow("Alt") << QKeySequence(Qt::Key_Alt) << "Alt";
+ QTest::newRow("Shift") << QKeySequence(Qt::Key_Shift) << "Shift";
+ QTest::newRow("Meta") << QKeySequence(Qt::Key_Meta) << "Meta";
}
void tst_QKeySequence::toStringFromKeycode()
@@ -579,10 +559,6 @@ void tst_QKeySequence::parseString_data()
//QTest::newRow("Ctrl") << "Ctrl" << QKeySequence(Qt::CTRL);
//QTest::newRow("Shift") << "Shift" << QKeySequence(Qt::SHIFT);
- // Only Keys
- QTest::newRow("a") << "a" << QKeySequence(Qt::Key_A);
- QTest::newRow("A") << "A" << QKeySequence(Qt::Key_A);
-
// Incomplete
QTest::newRow("Meta+Shift+") << "Meta+Shift+" << QKeySequence(Qt::Key_unknown);
}
diff --git a/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt
index baf9b83b55..ac2200792b 100644
--- a/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qmouseevent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmouseevent Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmouseevent LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmouseevent
SOURCES
tst_qmouseevent.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
index d5174e0942..f703111384 100644
--- a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
+++ b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -32,6 +7,8 @@
#include <qwindow.h>
#include <QtGui/private/qpointingdevice_p.h>
+#include <QtCore/qpointer.h>
+
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
class MouseEventWidget : public QWindow
@@ -122,6 +99,7 @@ private slots:
void grabbers_data();
void grabbers();
void velocity();
+ void clone();
private:
MouseEventWidget* testMouseWidget;
@@ -288,14 +266,14 @@ void tst_QMouseEvent::grabbers()
auto firstEPD = devPriv->pointById(0);
QCOMPARE(firstEPD->eventPoint.pressTimestamp(), testMouseWidget->pressTimestamp);
QCOMPARE(firstEPD->exclusiveGrabber, grabExclusive ? testMouseWidget : nullptr);
- QCOMPARE(firstEPD->passiveGrabbers.count(), grabPassive ? 1 : 0);
+ QCOMPARE(firstEPD->passiveGrabbers.size(), grabPassive ? 1 : 0);
if (grabPassive)
QCOMPARE(firstEPD->passiveGrabbers.first(), testMouseWidget);
// Ensure that grabbers are forgotten after release delivery
QTest::mouseRelease(testMouseWidget, Qt::LeftButton, Qt::KeyboardModifiers(), {10, 10});
QTRY_COMPARE(firstEPD->exclusiveGrabber, nullptr);
- QCOMPARE(firstEPD->passiveGrabbers.count(), 0);
+ QCOMPARE(firstEPD->passiveGrabbers.size(), 0);
}
void tst_QMouseEvent::velocity()
@@ -334,5 +312,24 @@ void tst_QMouseEvent::velocity()
QVERIFY(testMouseWidget->velocity.y() > 0);
}
+void tst_QMouseEvent::clone()
+{
+ const QPointF pos(10.0f, 10.0f);
+
+ QMouseEvent originalMe(QEvent::MouseButtonPress, pos, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+ QVERIFY(!originalMe.allPointsAccepted());
+ QVERIFY(!originalMe.points().first().isAccepted());
+
+ // create a clone of the original
+ std::unique_ptr<QMouseEvent> clonedMe(originalMe.clone());
+ QVERIFY(!clonedMe->allPointsAccepted());
+ QVERIFY(!clonedMe->points().first().isAccepted());
+
+ // now we alter originalMe, which should *not* change clonedMe
+ originalMe.setAccepted(true);
+ QVERIFY(!clonedMe->allPointsAccepted());
+ QVERIFY(!clonedMe->points().first().isAccepted());
+}
+
QTEST_MAIN(tst_QMouseEvent)
#include "tst_qmouseevent.moc"
diff --git a/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt
index 698327736e..034b9c794d 100644
--- a/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qmouseevent_modal.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmouseevent_modal Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmouseevent_modal LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmouseevent_modal
SOURCES
tst_qmouseevent_modal.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::Widgets
)
diff --git a/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp
index ec2a9729bb..0fe218d503 100644
--- a/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp
+++ b/tests/auto/gui/kernel/qmouseevent_modal/tst_qmouseevent_modal.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt
index d171716776..0f57b98bc3 100644
--- a/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qopenglwindow.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qopenglwindow Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qopenglwindow LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qopenglwindow
SOURCES
tst_qopenglwindow.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
index 379034a20e..06a1ffb296 100644
--- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
+++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtOpenGL/QOpenGLWindow>
#include <QTest>
@@ -144,6 +119,9 @@ void tst_QOpenGLWindow::resize()
if (isPlatformWayland())
QSKIP("Wayland: Crashes on Intel Mesa due to a driver bug (QTBUG-66848).");
+ if (QGuiApplication::platformName().startsWith(QLatin1String("eglfs"), Qt::CaseInsensitive))
+ QSKIP("EGLFS does not allow resizing on top level window");
+
Window w;
w.reset();
w.resize(640, 480);
diff --git a/tests/auto/gui/kernel/qpalette/CMakeLists.txt b/tests/auto/gui/kernel/qpalette/CMakeLists.txt
index f69ac75a41..7983b9ac25 100644
--- a/tests/auto/gui/kernel/qpalette/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qpalette/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpalette.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpalette Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpalette LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpalette
SOURCES
tst_qpalette.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
index 6524f73143..c21828bee2 100644
--- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
+++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -47,6 +22,8 @@ private Q_SLOTS:
void noBrushesSetForDefaultPalette();
void cannotCheckIfInvalidBrushSet();
void checkIfBrushForCurrentGroupSet();
+ void cacheKey();
+ void dataStream();
};
void tst_QPalette::roleValues_data()
@@ -75,9 +52,10 @@ void tst_QPalette::roleValues_data()
QTest::newRow("QPalette::ToolTipBase") << int(QPalette::ToolTipBase) << 18;
QTest::newRow("QPalette::ToolTipText") << int(QPalette::ToolTipText) << 19;
QTest::newRow("QPalette::PlaceholderText") << int(QPalette::PlaceholderText) << 20;
+ QTest::newRow("QPalette::Accent") << int(QPalette::Accent) << 21;
// Change this value as you add more roles.
- QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 21;
+ QTest::newRow("QPalette::NColorRoles") << int(QPalette::NColorRoles) << 22;
}
void tst_QPalette::roleValues()
@@ -122,6 +100,21 @@ void tst_QPalette::resolve()
QVERIFY(p2ResolvedTo1 != p1);
QVERIFY(p2ResolvedTo1 != p2);
+
+ QPalette p3;
+ // ensure the resolve mask is full
+ for (int r = 0; r < QPalette::NColorRoles; ++r)
+ p3.setBrush(QPalette::All, QPalette::ColorRole(r), Qt::red);
+ const QPalette::ResolveMask fullMask = p3.resolveMask();
+
+ QPalette p3ResolvedToP1 = p3.resolve(p1);
+ QVERIFY(p3ResolvedToP1.isCopyOf(p3));
+
+ QPalette p4;
+ QCOMPARE(p4.resolveMask(), QPalette::ResolveMask{});
+ // resolve must detach even if p4 has no mask
+ p4 = p4.resolve(p3);
+ QCOMPARE(p3.resolveMask(), fullMask);
}
@@ -207,9 +200,6 @@ void tst_QPalette::setBrush()
const QPalette pp = p;
QVERIFY(pp.isCopyOf(p));
- // Setting the same brush won't detach
- p.setBrush(QPalette::Disabled, QPalette::Button, Qt::green);
- QVERIFY(pp.isCopyOf(p));
}
void tst_QPalette::isBrushSet()
@@ -227,6 +217,14 @@ void tst_QPalette::isBrushSet()
QVERIFY(p.isBrushSet(QPalette::Active, QPalette::LinkVisited));
QVERIFY(p.isBrushSet(QPalette::Inactive, QPalette::LinkVisited));
QVERIFY(p.isBrushSet(QPalette::Disabled, QPalette::LinkVisited));
+
+ // Don't set flag when brush doesn't change (and also don't detach - QTBUG-98762)
+ QPalette p2;
+ QPalette p3;
+ QVERIFY(!p2.isBrushSet(QPalette::Active, QPalette::Dark));
+ p2.setBrush(QPalette::Active, QPalette::Dark, p2.brush(QPalette::Active, QPalette::Dark));
+ QVERIFY(!p3.isBrushSet(QPalette::Active, QPalette::Dark));
+ QVERIFY(p2.isBrushSet(QPalette::Active, QPalette::Dark));
}
void tst_QPalette::setAllPossibleBrushes()
@@ -240,8 +238,14 @@ void tst_QPalette::setAllPossibleBrushes()
}
for (int r = 0; r < QPalette::NColorRoles; ++r) {
+ const QPalette::ColorRole role = static_cast<QPalette::ColorRole>(r);
for (int g = 0; g < QPalette::NColorGroups; ++g) {
- QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r)));
+ const QPalette::ColorGroup group = static_cast<QPalette::ColorGroup>(g);
+ // NoRole has no resolve bit => isBrushSet returns false
+ if (role == QPalette::NoRole)
+ QVERIFY(!p.isBrushSet(group, role));
+ else
+ QVERIFY(p.isBrushSet(group, role));
}
}
}
@@ -269,5 +273,120 @@ void tst_QPalette::checkIfBrushForCurrentGroupSet()
QVERIFY(p.isBrushSet(QPalette::Current, QPalette::Link));
}
+void tst_QPalette::cacheKey()
+{
+ const QPalette defaultPalette;
+ // precondition: all palettes are expected to have contrasting text on base
+ QVERIFY(defaultPalette.base() != defaultPalette.text());
+ const auto defaultCacheKey = defaultPalette.cacheKey();
+ const auto defaultSerNo = defaultCacheKey >> 32;
+ const auto defaultDetachNo = defaultCacheKey & 0xffffffff;
+
+ QPalette changeTwicePalette(defaultPalette);
+ changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::red);
+ const auto firstChangeCacheKey = changeTwicePalette.cacheKey();
+ QCOMPARE_NE(firstChangeCacheKey, defaultCacheKey);
+ changeTwicePalette.setBrush(QPalette::All, QPalette::ButtonText, Qt::green);
+ const auto secondChangeCacheKey = changeTwicePalette.cacheKey();
+ QCOMPARE_NE(firstChangeCacheKey, secondChangeCacheKey);
+
+ QPalette copyDifferentData(defaultPalette);
+ QPalette copyDifferentMask(defaultPalette);
+ QPalette copyDifferentMaskAndData(defaultPalette);
+
+ QCOMPARE(defaultPalette.cacheKey(), copyDifferentData.cacheKey());
+
+ // deep detach of both private and data
+ copyDifferentData.setBrush(QPalette::Base, defaultPalette.text());
+ const auto differentDataKey = copyDifferentData.cacheKey();
+ const auto differentDataSerNo = differentDataKey >> 32;
+ const auto differentDataDetachNo = differentDataKey & 0xffffffff;
+ auto loggerDeepDetach = qScopeGuard([&](){
+ qDebug() << "Deep detach serial" << differentDataSerNo;
+ qDebug() << "Deep detach detach number" << differentDataDetachNo;
+ });
+
+ QCOMPARE_NE(copyDifferentData.cacheKey(), defaultCacheKey);
+ QCOMPARE(defaultPalette.cacheKey(), defaultCacheKey);
+
+ // shallow detach, both privates reference the same data
+ copyDifferentMask.setResolveMask(0xffffffffffffffff);
+ const auto differentMaskKey = copyDifferentMask.cacheKey();
+ const auto differentMaskSerNo = differentMaskKey >> 32;
+ const auto differentMaskDetachNo = differentMaskKey & 0xffffffff;
+ auto loggerShallowDetach = qScopeGuard([&](){
+ qDebug() << "Shallow detach serial" << differentMaskSerNo;
+ qDebug() << "Shallow detach detach number" << differentMaskDetachNo;
+ });
+
+ QCOMPARE(differentMaskSerNo, defaultSerNo);
+ QCOMPARE_NE(differentMaskSerNo, defaultDetachNo);
+ QCOMPARE_NE(differentMaskKey, defaultCacheKey);
+ QCOMPARE_NE(differentMaskKey, differentDataKey);
+
+ // shallow detach, both privates reference the same data
+ copyDifferentMaskAndData.setResolveMask(0xeeeeeeeeeeeeeeee);
+ const auto modifiedCacheKey = copyDifferentMaskAndData.cacheKey();
+ QCOMPARE_NE(modifiedCacheKey, copyDifferentMask.cacheKey());
+ QCOMPARE_NE(modifiedCacheKey, defaultCacheKey);
+ QCOMPARE_NE(modifiedCacheKey, copyDifferentData.cacheKey());
+ QCOMPARE_NE(copyDifferentMask.cacheKey(), defaultCacheKey);
+
+ // full detach - both key elements are different
+ copyDifferentMaskAndData.setBrush(QPalette::Base, defaultPalette.text());
+ const auto modifiedAllKey = copyDifferentMaskAndData.cacheKey();
+ const auto modifiedAllSerNo = modifiedAllKey >> 32;
+ const auto modifiedAllDetachNo = modifiedAllKey & 0xffffffff;
+ QCOMPARE_NE(modifiedAllSerNo, defaultSerNo);
+ QCOMPARE_NE(modifiedAllDetachNo, defaultDetachNo);
+
+ QCOMPARE_NE(modifiedAllKey, copyDifferentMask.cacheKey());
+ QCOMPARE_NE(modifiedAllKey, defaultCacheKey);
+ QCOMPARE_NE(modifiedAllKey, differentDataKey);
+ QCOMPARE_NE(modifiedAllKey, modifiedCacheKey);
+
+ loggerDeepDetach.dismiss();
+ loggerShallowDetach.dismiss();
+}
+
+void tst_QPalette::dataStream()
+{
+ const QColor highlight(42, 42, 42);
+ const QColor accent(13, 13, 13);
+ QPalette palette;
+ palette.setBrush(QPalette::Highlight, highlight);
+ palette.setBrush(QPalette::Accent, accent);
+
+ // When saved with Qt_6_5 or earlier, Accent defaults to Highlight
+ {
+ QByteArray b;
+ {
+ QDataStream stream(&b, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_6_5);
+ stream << palette;
+ }
+ QPalette test;
+ QDataStream stream (&b, QIODevice::ReadOnly);
+ stream.setVersion(QDataStream::Qt_6_5);
+ stream >> test;
+ QCOMPARE(test.accent().color(), highlight);
+ }
+
+ // When saved with Qt_6_6 or later, Accent is saved explicitly
+ {
+ QByteArray b;
+ {
+ QDataStream stream(&b, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_6_6);
+ stream << palette;
+ }
+ QPalette test;
+ QDataStream stream (&b, QIODevice::ReadOnly);
+ stream.setVersion(QDataStream::Qt_6_6);
+ stream >> test;
+ QCOMPARE(test.accent().color(), accent);
+ }
+}
+
QTEST_MAIN(tst_QPalette)
#include "tst_qpalette.moc"
diff --git a/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt b/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt
index e33600dd8c..c711ceeafa 100644
--- a/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpixelformat.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpixelformat Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpixelformat LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpixelformat
SOURCES
tst_qpixelformat.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
index 6372303290..d6d471bf6b 100644
--- a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
+++ b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/qpixelformat.h>
diff --git a/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt
index 82391cf18f..dc9d6a70c7 100644
--- a/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qrasterwindow.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qrasterwindow Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qrasterwindow LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qrasterwindow
SOURCES
tst_qrasterwindow.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp
index f0725bff2d..a06e360e35 100644
--- a/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp
+++ b/tests/auto/gui/kernel/qrasterwindow/tst_qrasterwindow.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QRasterWindow>
#include <QTest>
@@ -70,7 +45,7 @@ void tst_QRasterWindow::basic()
w.reset();
w.resize(400, 400);
w.show();
- QVERIFY(QTest::qWaitForWindowExposed(&w));;
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QVERIFY(w.paintCount >= 1);
diff --git a/tests/auto/gui/kernel/qscreen/BLACKLIST b/tests/auto/gui/kernel/qscreen/BLACKLIST
index 0395ea7b1d..ca3136fdb2 100644
--- a/tests/auto/gui/kernel/qscreen/BLACKLIST
+++ b/tests/auto/gui/kernel/qscreen/BLACKLIST
@@ -1,3 +1,3 @@
-# QTBUG-87390
[grabWindow]
-android
+# QTBUG-100412
+windows
diff --git a/tests/auto/gui/kernel/qscreen/CMakeLists.txt b/tests/auto/gui/kernel/qscreen/CMakeLists.txt
index 9bed97cfcb..8502176ca4 100644
--- a/tests/auto/gui/kernel/qscreen/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qscreen/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qscreen.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qscreen Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qscreen LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qscreen
SOURCES
tst_qscreen.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp
index 83d476e812..74a03ac851 100644
--- a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp
+++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp
@@ -1,35 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qpainter.h>
#include <qrasterwindow.h>
#include <qscreen.h>
#include <qpa/qwindowsysteminterface.h>
+#include <qpa/qplatformintegration.h>
+#include <private/qguiapplication_p.h>
+#include <private/qhighdpiscaling_p.h>
#include <QTest>
#include <QSignalSpy>
@@ -180,34 +158,34 @@ void tst_QScreen::orientationChange()
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
- QCOMPARE(spy.count(), ++expectedSignalCount);
+ QCOMPARE(spy.size(), ++expectedSignalCount);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::PortraitOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::PortraitOrientation);
- QCOMPARE(spy.count(), ++expectedSignalCount);
+ QCOMPARE(spy.size(), ++expectedSignalCount);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedLandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::InvertedLandscapeOrientation);
- QCOMPARE(spy.count(), ++expectedSignalCount);
+ QCOMPARE(spy.size(), ++expectedSignalCount);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::InvertedPortraitOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::InvertedPortraitOrientation);
- QCOMPARE(spy.count(), ++expectedSignalCount);
+ QCOMPARE(spy.size(), ++expectedSignalCount);
QWindowSystemInterface::handleScreenOrientationChange(screen, Qt::LandscapeOrientation);
QWindowSystemInterface::flushWindowSystemEvents();
QTRY_COMPARE(screen->orientation(), Qt::LandscapeOrientation);
- QCOMPARE(spy.count(), ++expectedSignalCount);
+ QCOMPARE(spy.size(), ++expectedSignalCount);
}
void tst_QScreen::grabWindow_data()
{
- if (QGuiApplication::platformName().startsWith(QLatin1String("offscreen"), Qt::CaseInsensitive))
- QSKIP("Offscreen: Screen grabbing not implemented.");
-
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
+ || (QGuiApplication::platformName().toLower() == QStringLiteral("xcb") && !qEnvironmentVariableIsEmpty("WAYLAND_DISPLAY")))
+ QSKIP("This platform does not support grabbing windows on screen.");
QTest::addColumn<int>("screenIndex");
QTest::addColumn<QByteArray>("screenName");
QTest::addColumn<bool>("grabWindow");
@@ -279,20 +257,30 @@ void tst_QScreen::grabWindow()
QCOMPARE(screen->name().toUtf8(), screenName);
const double screenDpr = screen->devicePixelRatio();
+ if (QHighDpiScaling::isActive()) {
+ const float rawFactor = QHighDpiScaling::factor(screen);
+ const float roundedFactor = qRound(rawFactor);
+ if (!qFuzzyCompare(roundedFactor, rawFactor))
+ QSKIP("HighDPI enabled with non-integer factor. Skip due to possible rounding errors.");
+ }
+
Window window(screen);
window.setGeometry(windowRect);
+#ifndef Q_OS_ANDROID
window.show();
+#else
+ window.showNormal();
+#endif
if (!QTest::qWaitForWindowExposed(&window))
QSKIP("Failed to expose window - aborting");
- if (QGuiApplication::platformName().startsWith(QLatin1String("xcb"), Qt::CaseInsensitive))
- QTest::qWait(1500); // this is ridiculously necessary because of effects combined with slowness of VMs
-#ifdef Q_OS_MACOS // wait for desktop on screen to scroll into place
- QTest::qWait(1000);
-#endif
+ // this is necessary because of scrolling effects combined with potential slowness of VMs
+ QTest::qWait(1500);
- QSize expectedGrabSize = grabRect.isValid() ? grabRect.size() : (grabWindow ? windowRect.size() : screen->size());
+ QSize expectedGrabSize = grabRect.isValid()
+ ? grabRect.size()
+ : (grabWindow ? windowRect.size() : screen->size());
// we ask for pixel coordinates, but will get a pixmap with device-specific DPR
expectedGrabSize *= screen->devicePixelRatio();
@@ -300,7 +288,9 @@ void tst_QScreen::grabWindow()
QImage paintedImage = window.image;
QCOMPARE(paintedImage.devicePixelRatio(), screenDpr);
- const QPixmap pixmap = screen->grabWindow(grabWindow ? window.winId() : 0, grabRect.x(), grabRect.y(), grabRect.width(), grabRect.height());
+ const QPixmap pixmap = screen->grabWindow(grabWindow
+ ? window.winId()
+ : 0, grabRect.x(), grabRect.y(), grabRect.width(), grabRect.height());
QImage grabbedImage = pixmap.toImage();
const QSize grabbedSize = grabbedImage.size();
diff --git a/tests/auto/gui/kernel/qshortcut/CMakeLists.txt b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt
index 469ab47769..517a4e8a1a 100644
--- a/tests/auto/gui/kernel/qshortcut/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt
@@ -1,12 +1,20 @@
-# Generated from qshortcut.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qshortcut_kernel Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qshortcut_kernel LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qshortcut_kernel
SOURCES
tst_qshortcut.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
+ Qt::GuiPrivate
)
diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
index 777f486263..cb6ebab800 100644
--- a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
+++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp
@@ -1,81 +1,59 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/qguiapplication.h>
#include <QtGui/qshortcut.h>
-#include <QtGui/qpainter.h>
-#include <QtGui/qrasterwindow.h>
-#include <QtGui/qscreen.h>
#include <QtGui/qwindow.h>
+#include <QtTest/qsignalspy.h>
+
+#include <QtGui/private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
class tst_QShortcut : public QObject
{
Q_OBJECT
-public:
private slots:
- void trigger();
-};
-
-class ColoredWindow : public QRasterWindow {
-public:
- ColoredWindow(QColor c) : m_color(c) {}
-
-protected:
- void paintEvent(QPaintEvent *event) override;
-
-private:
- const QColor m_color;
+ void applicationShortcut();
+ void windowShortcut();
};
-void ColoredWindow::paintEvent(QPaintEvent *)
+void tst_QShortcut::applicationShortcut()
{
- QPainter p(this);
- p.fillRect(QRect(QPoint(), size()), m_color);
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("Window activation is not supported");
+
+ auto *shortcut = new QShortcut(Qt::CTRL | Qt::Key_A, this);
+ shortcut->setContext(Qt::ApplicationShortcut);
+ QSignalSpy activatedSpy(shortcut, &QShortcut::activated);
+
+ // Need a window to send key event to, even if the shortcut is application
+ // global. The documentation for Qt::ApplicationShortcut also says that
+ // the shortcut "is active when one of the applications windows are active",
+ // but this is only honored for Qt Widgets, not for Qt Gui. For now we
+ // activate the window just in case.
+ QWindow window;
+ window.show();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+ QTRY_COMPARE(QGuiApplication::applicationState(), Qt::ApplicationActive);
+ QTest::sendKeyEvent(QTest::Shortcut, &window, Qt::Key_A, 'a', Qt::ControlModifier);
+
+ QVERIFY(activatedSpy.size() > 0);
}
-static void sendKey(QWindow *target, Qt::Key k, char c, Qt::KeyboardModifiers modifiers)
+void tst_QShortcut::windowShortcut()
{
- QTest::sendKeyEvent(QTest::Press, target, k, c, modifiers);
- QTest::sendKeyEvent(QTest::Release, target, k, c, modifiers);
-}
-
-void tst_QShortcut::trigger()
-{
- ColoredWindow w(Qt::yellow);
- w.setTitle(QTest::currentTestFunction());
- w.resize(QGuiApplication::primaryScreen()->size() / 4);
+ QWindow w;
new QShortcut(Qt::CTRL | Qt::Key_Q, &w, SLOT(close()));
w.show();
QVERIFY(QTest::qWaitForWindowExposed(&w));
+
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QEXPECT_FAIL("", "It failed on Wayland, QTBUG-120334", Abort);
+
QTRY_VERIFY(QGuiApplication::applicationState() == Qt::ApplicationActive);
- sendKey(&w, Qt::Key_Q, 'q', Qt::ControlModifier);
+ QTest::sendKeyEvent(QTest::Click, &w, Qt::Key_Q, 'q', Qt::ControlModifier);
QTRY_VERIFY(!w.isVisible());
}
diff --git a/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt
index f1fab57ebe..1303f48cf3 100644
--- a/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qsurfaceformat.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsurfaceformat Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsurfaceformat LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsurfaceformat
SOURCES
tst_qsurfaceformat.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp
index f4410b2dae..3f655bd905 100644
--- a/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp
+++ b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qsurfaceformat.h>
diff --git a/tests/auto/gui/kernel/qtouchevent/BLACKLIST b/tests/auto/gui/kernel/qtouchevent/BLACKLIST
index 2876c120fc..c4e4b2291d 100644
--- a/tests/auto/gui/kernel/qtouchevent/BLACKLIST
+++ b/tests/auto/gui/kernel/qtouchevent/BLACKLIST
@@ -1,8 +1,6 @@
-[multiPointRawEventTranslationOnTouchScreen]
-ubuntu-16.04
-[multiPointRawEventTranslationOnTouchScreen]
-android
[multiPointRawEventTranslationOnTouchPad]
+# QTBUG-101519
+windows-11
android
[touchBeginWithGraphicsWidget]
android
diff --git a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt
index e9a6271f58..160263ac66 100644
--- a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtouchevent.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtouchevent Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtouchevent LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtouchevent
SOURCES
tst_qtouchevent.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
diff --git a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
index 28c33e8226..37ddcb8962 100644
--- a/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
+++ b/tests/auto/gui/kernel/qtouchevent/tst_qtouchevent.cpp
@@ -1,31 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the $MODULE$ of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#include <QtGui/QCursor>
#include <QtGui/QScreen>
#include <QtWidgets/QGraphicsItem>
#include <QtWidgets/QGraphicsScene>
@@ -33,11 +9,18 @@
#include <QtWidgets/QGraphicsWidget>
#include <QtWidgets/QWidget>
#include <QTest>
+#include <QSet>
+#include <QVarLengthArray>
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qwindowsysteminterface_p.h>
#include <private/qevent_p.h>
+#include <QtGui/private/qeventpoint_p.h>
#include <private/qhighdpiscaling_p.h>
#include <private/qpointingdevice_p.h>
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+
+#include <QtCore/qpointer.h>
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
@@ -67,6 +50,24 @@ public:
deleteInTouchBegin = deleteInTouchUpdate = deleteInTouchEnd = false;
}
+ void paintEvent(QPaintEvent *) override
+ {
+ QPainter painter(this);
+ painter.drawRect(rect());
+ painter.setPen(Qt::darkGray);
+ painter.drawText(rect(), Qt::AlignHCenter | Qt::AlignCenter, objectName());
+ static const QString pointFormat = QString::fromUtf8("\360\237\226\227 %1, %2");
+ painter.setPen(Qt::darkGreen);
+ for (const auto &pt : std::as_const(touchBeginPoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ painter.setPen(Qt::darkYellow);
+ for (const auto &pt : std::as_const(touchUpdatePoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ painter.setPen(Qt::darkRed);
+ for (const auto &pt : std::as_const(touchEndPoints))
+ painter.drawText(pt.position(), pointFormat.arg(pt.position().toPoint().x()).arg(pt.position().toPoint().y()));
+ }
+
bool event(QEvent *event) override
{
lastNormalizedPositions.clear();
@@ -80,13 +81,15 @@ public:
auto touchEvent = static_cast<QTouchEvent *>(event);
touchBeginPoints = touchEvent->points();
Q_ASSERT(touchBeginPoints.first().device() == touchEvent->pointingDevice());
- for (const QEventPoint &pt : qAsConst(touchBeginPoints))
+ for (const QEventPoint &pt : std::as_const(touchBeginPoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchBegin);
if (deleteInTouchBegin)
delete this;
+ else
+ update();
break;
}
case QEvent::TouchUpdate: {
@@ -96,13 +99,15 @@ public:
seenTouchUpdate = seenTouchBegin && !seenTouchEnd;
auto touchEvent = static_cast<QTouchEvent *>(event);
touchUpdatePoints = touchEvent->points();
- for (const QEventPoint &pt : qAsConst(touchUpdatePoints))
+ for (const QEventPoint &pt : std::as_const(touchUpdatePoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchUpdate);
if (deleteInTouchUpdate)
delete this;
+ else
+ update();
break;
}
case QEvent::TouchEnd: {
@@ -112,13 +117,15 @@ public:
seenTouchEnd = seenTouchBegin && !seenTouchEnd;
auto touchEvent = static_cast<QTouchEvent *>(event);
touchEndPoints = touchEvent->points();
- for (const QEventPoint &pt : qAsConst(touchEndPoints))
+ for (const QEventPoint &pt : std::as_const(touchEndPoints))
lastNormalizedPositions << pt.normalizedPosition();
timestamp = touchEvent->timestamp();
deviceFromEvent = touchEvent->pointingDevice();
event->setAccepted(acceptTouchEnd);
if (deleteInTouchEnd)
delete this;
+ else
+ update();
break;
}
default:
@@ -364,9 +371,11 @@ void tst_QTouchEvent::state()
QVERIFY(!touchEvent3.isBeginEvent());
QVERIFY(!touchEvent3.isUpdateEvent());
QVERIFY(touchEvent3.isEndEvent());
+#if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED // test Qt 5 compatibility wrappers
QCOMPARE(touchEvent3.touchPoints(), touchEvent3.points());
QT_WARNING_POP
+#endif
}
void tst_QTouchEvent::touchDisabledByDefault()
@@ -402,11 +411,11 @@ void tst_QTouchEvent::touchDisabledByDefault()
QVERIFY(!item.acceptTouchEvents());
// compose an event to the scene that is over the item
- QMutableEventPoint touchPoint(0);
- touchPoint.setState(QEventPoint::State::Pressed);
- touchPoint.setPosition(view.mapFromScene(item.mapToScene(item.boundingRect().center())));
- touchPoint.setGlobalPosition(view.mapToGlobal(touchPoint.position().toPoint()));
- touchPoint.setScenePosition(view.mapToScene(touchPoint.position().toPoint()));
+ QEventPoint touchPoint(0);
+ QMutableEventPoint::setState(touchPoint, QEventPoint::State::Pressed);
+ QMutableEventPoint::setPosition(touchPoint, view.mapFromScene(item.mapToScene(item.boundingRect().center())));
+ QMutableEventPoint::setGlobalPosition(touchPoint, view.mapToGlobal(touchPoint.position().toPoint()));
+ QMutableEventPoint::setScenePosition(touchPoint, view.mapToScene(touchPoint.position().toPoint()));
QTouchEvent touchEvent(QEvent::TouchBegin,
touchScreenDevice,
@@ -462,10 +471,10 @@ void tst_QTouchEvent::touchEventAcceptedByDefault()
// compose an event to the scene that is over the item
QPointF pos = view.mapFromScene(item.mapToScene(item.boundingRect().center()));
- QMutableEventPoint touchPoint(0, QEventPoint::State::Pressed,
- view.mapToScene(pos.toPoint()),
- view.mapToGlobal(pos.toPoint()));
- touchPoint.setPosition(pos);
+ QEventPoint touchPoint(0, QEventPoint::State::Pressed,
+ view.mapToScene(pos.toPoint()),
+ view.mapToGlobal(pos.toPoint()));
+ QMutableEventPoint::setPosition(touchPoint, pos);
QTouchEvent touchEvent(QEvent::TouchBegin,
touchScreenDevice,
Qt::NoModifier,
@@ -574,10 +583,10 @@ void tst_QTouchEvent::touchBeginPropagatesWhenIgnored()
// compose an event to the scene that is over the grandchild
QPointF pos = view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center()));
- QMutableEventPoint touchPoint(0, QEventPoint::State::Pressed,
- view.mapToScene(pos.toPoint()),
- view.mapToGlobal(pos.toPoint()));
- touchPoint.setPosition(pos);
+ QEventPoint touchPoint(0, QEventPoint::State::Pressed,
+ view.mapToScene(pos.toPoint()),
+ view.mapToGlobal(pos.toPoint()));
+ QMutableEventPoint::setPosition(touchPoint, pos);
QTouchEvent touchEvent(QEvent::TouchBegin,
touchScreenDevice,
Qt::NoModifier,
@@ -657,10 +666,10 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate()
// compose an event to the scene that is over the child
QPointF pos = view.mapFromScene(grandchild.mapToScene(grandchild.boundingRect().center()));
- QMutableEventPoint touchPoint(0, QEventPoint::State::Pressed,
- view.mapToScene(pos.toPoint()),
- view.mapToGlobal(pos.toPoint()));
- touchPoint.setPosition(pos);
+ QEventPoint touchPoint(0, QEventPoint::State::Pressed,
+ view.mapToScene(pos.toPoint()),
+ view.mapToGlobal(pos.toPoint()));
+ QMutableEventPoint::setPosition(touchPoint, pos);
QTouchEvent touchBeginEvent(QEvent::TouchBegin,
touchScreenDevice,
Qt::NoModifier,
@@ -672,10 +681,10 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate()
QVERIFY(!root.seenTouchBegin);
// send the touch update to the child, but ignore it, it doesn't propagate
- touchPoint = QMutableEventPoint(0, QEventPoint::State::Updated,
- view.mapToScene(pos.toPoint()),
- view.mapToGlobal(pos.toPoint()));
- touchPoint.setPosition(pos);
+ touchPoint = QEventPoint(0, QEventPoint::State::Updated,
+ view.mapToScene(pos.toPoint()),
+ view.mapToGlobal(pos.toPoint()));
+ QMutableEventPoint::setPosition(touchPoint, pos);
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
touchScreenDevice,
Qt::NoModifier,
@@ -687,10 +696,10 @@ void tst_QTouchEvent::touchUpdateAndEndNeverPropagate()
QVERIFY(!root.seenTouchUpdate);
// send the touch end, same thing should happen as with touch update
- touchPoint = QMutableEventPoint(0, QEventPoint::State::Released,
- view.mapToScene(pos.toPoint()),
- view.mapToGlobal(pos.toPoint()));
- touchPoint.setPosition(pos);
+ touchPoint = QEventPoint(0, QEventPoint::State::Released,
+ view.mapToScene(pos.toPoint()),
+ view.mapToGlobal(pos.toPoint()));
+ QMutableEventPoint::setPosition(touchPoint, pos);
QTouchEvent touchEndEvent(QEvent::TouchEnd,
touchScreenDevice,
Qt::NoModifier,
@@ -727,7 +736,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
QCOMPARE(touchBeginPoint.id(), 0);
@@ -757,7 +766,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 1);
QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
QCOMPARE(touchUpdatePoint.id(), 0);
QCOMPARE(touchUpdatePoint.state(), rawTouchPoint.state());
@@ -785,7 +794,7 @@ void tst_QTouchEvent::basicRawEventTranslation()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
QEventPoint touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 0);
QCOMPARE(touchEndPoint.state(), rawTouchPoint.state());
@@ -808,9 +817,11 @@ void tst_QTouchEvent::basicRawEventTranslation()
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
{
tst_QTouchEventWidget touchWidget;
+ touchWidget.setObjectName("parent touch widget");
touchWidget.setWindowTitle(QTest::currentTestFunction());
touchWidget.setAttribute(Qt::WA_AcceptTouchEvents);
- touchWidget.setGeometry(100, 100, 400, 300);
+ const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft() + QPoint(100, 100);
+ touchWidget.setGeometry({topLeft, QSize(400, 300)});
tst_QTouchEventWidget leftWidget(&touchWidget);
leftWidget.setObjectName("leftWidget");
@@ -824,24 +835,25 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
touchWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&touchWidget));
+ if (touchWidget.geometry().topLeft() != topLeft) {
+ qCDebug(lcTests) << "tried to set position 100, 100 on screen; got geometry"
+ << touchWidget.geometry() << "frame" << touchWidget.frameGeometry();
+ QSKIP("failed to position the widget window on this platform");
+ }
- QPointF leftPos = leftWidget.rect().center();
- QPointF rightPos = rightWidget.rect().center();
- QPointF centerPos = touchWidget.rect().center();
- QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
- QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
- QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
+ QPoint leftPos = leftWidget.rect().center();
+ QPoint rightPos = rightWidget.rect().center();
+ QPoint centerPos = touchWidget.rect().center();
+ QPoint leftScenePos = leftWidget.mapToParent(leftPos);
+ QPoint rightScenePos = rightWidget.mapToParent(rightPos);
+ QPoint leftScreenPos = leftWidget.mapToGlobal(leftPos);
+ QPoint rightScreenPos = rightWidget.mapToGlobal(rightPos);
+ QPoint centerScreenPos = touchWidget.mapToGlobal(centerPos);
// generate TouchBegins on both leftWidget and rightWidget
- ulong timestamp = 0;
- auto rawTouchPoints = QList<QEventPoint>()
- << QEventPoint(0, QEventPoint::State::Pressed, QPointF(), leftScreenPos)
- << QEventPoint(1, QEventPoint::State::Pressed, QPointF(), rightScreenPos);
- QWindow *window = touchWidget.windowHandle();
- QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ auto touchSequence = QTest::touchEvent(touchWidget.windowHandle(), touchScreenDevice);
+ touchSequence.press(0, leftScenePos).press(1, rightScenePos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -851,14 +863,14 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchBeginPoints.count(), 1);
- QCOMPARE(rightWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(leftWidget.touchBeginPoints.size(), 1);
+ QCOMPARE(rightWidget.touchBeginPoints.size(), 1);
const int touchPointId0 = 0;
const int touchPointId1 = touchPointId0 + 1;
{
- QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchBeginPoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Pressed);
QCOMPARE(leftTouchPoint.position(), leftPos);
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
@@ -868,15 +880,12 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftPos);
- QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
- QEventPoint rightTouchPoint = rightWidget.touchBeginPoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchBeginPoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Pressed);
QCOMPARE(rightTouchPoint.position(), rightPos);
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
@@ -886,20 +895,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightPos);
- QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
}
- rawTouchPoints.clear();
- rawTouchPoints << QEventPoint(0, QEventPoint::State::Updated, QPointF(), centerScreenPos)
- << QEventPoint(1, QEventPoint::State::Updated, QPointF(), centerScreenPos);
- nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ // an unlikely event with the two touchpoints moving exactly on top of each other
+ touchSequence.move(0, centerPos).move(1, centerPos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -909,13 +911,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchUpdatePoints.count(), 1);
- QCOMPARE(rightWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(leftWidget.touchUpdatePoints.size(), 1);
+ QCOMPARE(rightWidget.touchUpdatePoints.size(), 1);
{
- QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchUpdatePoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
- QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Updated);
+ QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos)));
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
@@ -924,16 +926,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(1.));
- QEventPoint rightTouchPoint = rightWidget.touchUpdatePoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchUpdatePoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
- QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Updated);
+ QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos)));
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
@@ -942,21 +941,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(1.));
}
// generate TouchEnds on both leftWidget and rightWidget
- rawTouchPoints.clear();
- rawTouchPoints << QEventPoint(0, QEventPoint::State::Released, QPointF(), centerScreenPos)
- << QEventPoint(1, QEventPoint::State::Released, QPointF(), centerScreenPos);
- nativeTouchPoints =
- QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
- QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
- QCoreApplication::processEvents();
+ touchSequence.release(0, centerPos).release(1, centerPos);
+ QVERIFY(touchSequence.commit()); // verify acceptance
QVERIFY(!touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
@@ -966,13 +957,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QVERIFY(rightWidget.seenTouchBegin);
QVERIFY(rightWidget.seenTouchUpdate);
QVERIFY(rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchEndPoints.count(), 1);
- QCOMPARE(rightWidget.touchEndPoints.count(), 1);
+ QCOMPARE(leftWidget.touchEndPoints.size(), 1);
+ QCOMPARE(rightWidget.touchEndPoints.size(), 1);
{
- QEventPoint leftTouchPoint = leftWidget.touchEndPoints.first();
+ const QEventPoint &leftTouchPoint = leftWidget.touchEndPoints.first();
QCOMPARE(leftTouchPoint.id(), touchPointId0);
- QCOMPARE(leftTouchPoint.state(), rawTouchPoints[0].state());
- QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(leftTouchPoint.state(), QEventPoint::Released);
+ QCOMPARE(leftTouchPoint.position(), QPointF(leftWidget.mapFromParent(centerPos)));
QCOMPARE(leftTouchPoint.pressPosition(), leftPos);
QCOMPARE(leftTouchPoint.lastPosition(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
@@ -981,16 +972,13 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(leftTouchPoint.pressure(), qreal(0.));
- QEventPoint rightTouchPoint = rightWidget.touchEndPoints.first();
+ const QEventPoint &rightTouchPoint = rightWidget.touchEndPoints.first();
QCOMPARE(rightTouchPoint.id(), touchPointId1);
- QCOMPARE(rightTouchPoint.state(), rawTouchPoints[1].state());
- QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos.toPoint())));
+ QCOMPARE(rightTouchPoint.state(), QEventPoint::Released);
+ QCOMPARE(rightTouchPoint.position(), QPointF(rightWidget.mapFromParent(centerPos)));
QCOMPARE(rightTouchPoint.pressPosition(), rightPos);
QCOMPARE(rightTouchPoint.lastPosition(), rightPos);
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
@@ -999,9 +987,6 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchScreen()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QCOMPARE(rightTouchPoint.position(), rightWidget.mapFromParent(centerPos.toPoint()));
- QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
- QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
QCOMPARE(rightTouchPoint.pressure(), qreal(0.));
}
@@ -1025,13 +1010,13 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
// this should be translated to a TouchBegin
QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 1, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
+ QMutableEventPoint::withTimeStamp(1234, 1, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
QWindowSystemInterface::handleTouchEvent(window, timestamp, touchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.first();
QCOMPARE(touchBeginPoint.id(), 1);
@@ -1042,11 +1027,11 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
touchWidget.seenTouchBegin = false;
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 10, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
+ QMutableEventPoint::withTimeStamp(1234, 10, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
QCOMPARE(touchBeginPoint.id(), 10);
@@ -1057,11 +1042,11 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
touchWidget.seenTouchBegin = false;
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 11, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
+ QMutableEventPoint::withTimeStamp(1234, 11, QEventPoint::State::Pressed, screenPos, screenPos, screenPos), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 1);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 1);
QCOMPARE(touchWidget.timestamp, timestamp);
touchBeginPoint = touchWidget.touchBeginPoints[0];
QCOMPARE(touchBeginPoint.id(), 11);
@@ -1071,13 +1056,13 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
// moving the first point should translate to TouchUpdate
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 1, QEventPoint::State::Updated, screenPos + delta, screenPos + delta, screenPos + delta), window);
+ QMutableEventPoint::withTimeStamp(1234, 1, QEventPoint::State::Updated, screenPos + delta, screenPos + delta, screenPos + delta), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 1);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 1);
QEventPoint touchUpdatePoint = touchWidget.touchUpdatePoints.first();
QCOMPARE(touchUpdatePoint.id(), 1);
QCOMPARE(touchUpdatePoint.state(), QEventPoint::State::Updated);
@@ -1086,13 +1071,13 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
// releasing the first point translates to TouchEnd
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 1, QEventPoint::State::Released, screenPos + delta + delta, screenPos + delta + delta, screenPos + delta + delta), window);
+ QMutableEventPoint::withTimeStamp(1234, 1, QEventPoint::State::Released, screenPos + delta + delta, screenPos + delta + delta, screenPos + delta + delta), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
QEventPoint touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 1);
QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released);
@@ -1110,14 +1095,14 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
touchWidget.touchEndPoints.clear();
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 10, QEventPoint::State::Released, screenPos, screenPos, screenPos) <<
- QMutableEventPoint(1234, 11, QEventPoint::State::Stationary, screenPos, screenPos, screenPos), window);
+ QMutableEventPoint::withTimeStamp(1234, 10, QEventPoint::State::Released, screenPos, screenPos, screenPos) <<
+ QMutableEventPoint::withTimeStamp(1234, 11, QEventPoint::State::Stationary, screenPos, screenPos, screenPos), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 10);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 11);
@@ -1125,14 +1110,14 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
touchWidget.seenTouchEnd = false;
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(QList<QEventPoint>() <<
- QMutableEventPoint(1234, 11, QEventPoint::State::Released, screenPos + delta + delta,
+ QMutableEventPoint::withTimeStamp(1234, 11, QEventPoint::State::Released, screenPos + delta + delta,
screenPos + delta + delta, screenPos + delta + delta), window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, secondaryTouchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchEndPoints.count(), 1);
+ QCOMPARE(touchWidget.touchEndPoints.size(), 1);
touchEndPoint = touchWidget.touchEndPoints.first();
QCOMPARE(touchEndPoint.id(), 11);
QCOMPARE(touchEndPoint.state(), QEventPoint::State::Released);
@@ -1140,6 +1125,17 @@ void tst_QTouchEvent::touchOnMultipleTouchscreens()
void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
{
+#ifdef Q_OS_MACOS
+#if QT_CONFIG(cursor)
+ QCursor::setPos(0, 0); // move mouse out of the way
+ if (!QTest::qWaitFor([]{ return QCursor::pos() == QPoint(0, 0); }))
+#endif
+ QSKIP("The macOS mouse cursor interferes with this test can cannot be moved away");
+#endif
+
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
tst_QTouchEventWidget touchWidget;
touchWidget.setObjectName("touchWidget");
touchWidget.setWindowTitle(QTest::currentTestFunction());
@@ -1158,28 +1154,29 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
rightWidget.setGeometry(300, 100, 100, 100);
touchWidget.show();
- QVERIFY(QTest::qWaitForWindowExposed(&touchWidget));
+ QVERIFY(QTest::qWaitForWindowActive(&touchWidget));
- QPointF leftPos = leftWidget.rect().center();
- QPointF rightPos = rightWidget.rect().center();
- QPointF centerPos = touchWidget.rect().center();
- QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
- QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
- QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
+ const QPointF leftPos = leftWidget.rect().center();
+ const QPointF rightPos = rightWidget.rect().center();
+ const QPointF centerPos = touchWidget.rect().center();
+ const QPointF leftScreenPos = leftWidget.mapToGlobal(leftPos.toPoint());
+ const QPointF rightScreenPos = rightWidget.mapToGlobal(rightPos.toPoint());
+ const QPointF centerScreenPos = touchWidget.mapToGlobal(centerPos.toPoint());
ulong timestamp = 0;
- QList<QMutableEventPoint> rawTouchPoints;
- rawTouchPoints.append(QMutableEventPoint(0));
- rawTouchPoints.append(QMutableEventPoint(1));
+ QList<QEventPoint> rawTouchPoints = {
+ QEventPoint(0),
+ QEventPoint(1),
+ };
// generate TouchBegin on leftWidget only
{
- QMutableEventPoint &tp0 = QMutableEventPoint::from(rawTouchPoints[0]);
- tp0.setState(QEventPoint::State::Pressed);
- tp0.setGlobalPosition(leftScreenPos);
- QMutableEventPoint & tp1 = QMutableEventPoint::from(rawTouchPoints[1]);
- tp1.setState(QEventPoint::State::Pressed);
- tp1.setGlobalPosition(rightScreenPos);
+ QEventPoint &tp0 = rawTouchPoints[0];
+ QMutableEventPoint::setState(tp0, QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(tp0, leftScreenPos);
+ QEventPoint &tp1 = rawTouchPoints[1];
+ QMutableEventPoint::setState(tp1, QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(tp1, rightScreenPos);
}
QWindow *window = touchWidget.windowHandle();
QList<QWindowSystemInterface::TouchPoint> nativeTouchPoints =
@@ -1195,8 +1192,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchBeginPoints.count(), 2);
- QCOMPARE(rightWidget.touchBeginPoints.count(), 0);
+ QCOMPARE(leftWidget.touchBeginPoints.size(), 2);
+ QCOMPARE(rightWidget.touchBeginPoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchBeginPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after press" << leftWidget.lastNormalizedPositions;
@@ -1212,7 +1210,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2) < 0.05); // 0.198, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.2), 0.05); // 0.198, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftPos);
QCOMPARE(leftTouchPoint.scenePosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), leftScreenPos);
@@ -1232,7 +1230,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8) < 0.05); // 0.798, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.8), 0.05); // 0.798, might depend on window frame size
QCOMPARE(rightTouchPoint.scenePosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.ellipseDiameters(), QSizeF(0, 0));
@@ -1240,10 +1238,10 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
}
// generate TouchUpdate on leftWidget
- rawTouchPoints[0].setState(QEventPoint::State::Updated);
- rawTouchPoints[0].setGlobalPosition(centerScreenPos);
- rawTouchPoints[1].setState(QEventPoint::State::Updated);
- rawTouchPoints[1].setGlobalPosition(centerScreenPos);
+ QMutableEventPoint::setState(rawTouchPoints[0], QEventPoint::State::Updated);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoints[0], centerScreenPos);
+ QMutableEventPoint::setState(rawTouchPoints[1], QEventPoint::State::Updated);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoints[1], centerScreenPos);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchPadDevice, nativeTouchPoints);
@@ -1257,8 +1255,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchUpdatePoints.count(), 2);
- QCOMPARE(rightWidget.touchUpdatePoints.count(), 0);
+ QCOMPARE(leftWidget.touchUpdatePoints.size(), 2);
+ QCOMPARE(rightWidget.touchUpdatePoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchUpdatePoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after update" << leftWidget.lastNormalizedPositions;
@@ -1274,7 +1273,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
@@ -1294,7 +1293,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
@@ -1304,8 +1303,8 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
// generate TouchEnd on leftWidget
// both touchpoints are still at centerScreenPos
- rawTouchPoints[0].setState(QEventPoint::State::Released);
- rawTouchPoints[1].setState(QEventPoint::State::Released);
+ QMutableEventPoint::setState(rawTouchPoints[0], QEventPoint::State::Released);
+ QMutableEventPoint::setState(rawTouchPoints[1], QEventPoint::State::Released);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchPadDevice, nativeTouchPoints);
@@ -1319,8 +1318,9 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QVERIFY(!rightWidget.seenTouchBegin);
QVERIFY(!rightWidget.seenTouchUpdate);
QVERIFY(!rightWidget.seenTouchEnd);
- QCOMPARE(leftWidget.touchEndPoints.count(), 2);
- QCOMPARE(rightWidget.touchEndPoints.count(), 0);
+ QCOMPARE(leftWidget.touchEndPoints.size(), 2);
+ QCOMPARE(rightWidget.touchEndPoints.size(), 0);
+ QCOMPARE(leftWidget.lastNormalizedPositions.size(), 2);
{
QEventPoint leftTouchPoint = leftWidget.touchEndPoints.at(0);
qCDebug(lcTests) << "lastNormalizedPositions after release" << leftWidget.lastNormalizedPositions;
@@ -1337,7 +1337,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPressPosition(), leftScreenPos);
QCOMPARE(leftTouchPoint.globalLastPosition(), leftScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(0).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(leftTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(leftTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(leftTouchPoint.globalPosition(), centerScreenPos);
@@ -1357,7 +1357,7 @@ void tst_QTouchEvent::multiPointRawEventTranslationOnTouchPad()
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPressPosition(), rightScreenPos);
QCOMPARE(rightTouchPoint.globalLastPosition(), rightScreenPos);
- QVERIFY(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5) < 0.05); // 0.498, might depend on window frame size
+ QCOMPARE_LT(qAbs(leftWidget.lastNormalizedPositions.at(1).x() - 0.5), 0.05); // 0.498, might depend on window frame size
QCOMPARE(rightTouchPoint.position(), leftWidget.mapFromParent(centerPos.toPoint()));
QCOMPARE(rightTouchPoint.scenePosition(), centerScreenPos);
QCOMPARE(rightTouchPoint.globalPosition(), centerScreenPos);
@@ -1382,17 +1382,17 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
screenPos << touchWidget.mapToGlobal(pos[i].toPoint());
}
QPointF delta(10, 10);
- QList<QMutableEventPoint> rawTouchPoints;
+ QList<QEventPoint> rawTouchPoints;
// Press both points, this should be translated to a TouchBegin
for (int i = 0; i < 2; ++i) {
- QMutableEventPoint rawTouchPoint(i);
- rawTouchPoint.setState(QEventPoint::State::Pressed);
- rawTouchPoint.setGlobalPosition(screenPos[i]);
+ QEventPoint rawTouchPoint(i);
+ QMutableEventPoint::setState(rawTouchPoint, QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoint, screenPos[i]);
rawTouchPoints << rawTouchPoint;
}
- QMutableEventPoint &p0 = rawTouchPoints[0];
- QMutableEventPoint &p1 = rawTouchPoints[1];
+ QEventPoint &p0 = rawTouchPoints[0];
+ QEventPoint &p1 = rawTouchPoints[1];
ulong timestamp = 1234;
QWindow *window = touchWidget.windowHandle();
@@ -1403,19 +1403,19 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(!touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchBeginPoints.count(), 2);
+ QCOMPARE(touchWidget.touchBeginPoints.size(), 2);
- for (int i = 0; i < touchWidget.touchBeginPoints.count(); ++i) {
+ for (int i = 0; i < touchWidget.touchBeginPoints.size(); ++i) {
QEventPoint touchBeginPoint = touchWidget.touchBeginPoints.at(i);
QCOMPARE(touchBeginPoint.id(), i);
QCOMPARE(touchBeginPoint.state(), rawTouchPoints[i].state());
}
// moving the point should translate to TouchUpdate
- for (int i = 0; i < rawTouchPoints.count(); ++i) {
+ for (int i = 0; i < rawTouchPoints.size(); ++i) {
auto &p = rawTouchPoints[i];
- p.setState(QEventPoint::State::Updated);
- p.setGlobalPosition(p.globalPosition() + delta);
+ QMutableEventPoint::setState(p, QEventPoint::State::Updated);
+ QMutableEventPoint::setGlobalPosition(p, p.globalPosition() + delta);
}
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
@@ -1424,13 +1424,13 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints.at(0).id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints.at(1).id(), 1);
// release last point
- p0.setState(QEventPoint::State::Stationary);
- p1.setState(QEventPoint::State::Released);
+ QMutableEventPoint::setState(p0, QEventPoint::State::Stationary);
+ QMutableEventPoint::setState(p1, QEventPoint::State::Released);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
@@ -1439,13 +1439,13 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QCOMPARE(touchWidget.seenTouchEnd, false);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 1);
// Press last point again, id should increase
- p1.setState(QEventPoint::State::Pressed);
- p1.setId(42); // new id
+ QMutableEventPoint::setState(p1, QEventPoint::State::Pressed);
+ QMutableEventPoint::setId(p1, 42); // new id
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
@@ -1453,13 +1453,13 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(!touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
// release everything
- p0.setState(QEventPoint::State::Released);
- p1.setState(QEventPoint::State::Released);
+ QMutableEventPoint::setState(p0, QEventPoint::State::Released);
+ QMutableEventPoint::setState(p1, QEventPoint::State::Released);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
@@ -1467,7 +1467,7 @@ void tst_QTouchEvent::basicRawEventTranslationOfIds()
QVERIFY(touchWidget.seenTouchBegin);
QVERIFY(touchWidget.seenTouchUpdate);
QVERIFY(touchWidget.seenTouchEnd);
- QCOMPARE(touchWidget.touchUpdatePoints.count(), 2);
+ QCOMPARE(touchWidget.touchUpdatePoints.size(), 2);
QCOMPARE(touchWidget.touchUpdatePoints[0].id(), 0);
QCOMPARE(touchWidget.touchUpdatePoints[1].id(), 42);
}
@@ -1552,23 +1552,23 @@ void tst_QTouchEvent::deleteInEventHandler()
view.resize(200, 200);
view.fitInView(scene.sceneRect());
- QMutableEventPoint touchPoint(0);
- touchPoint.setState(QEventPoint::State::Pressed);
- touchPoint.setPosition(view.mapFromScene(child1->mapToScene(child1->boundingRect().center())));
- touchPoint.setGlobalPosition(view.mapToGlobal(touchPoint.position().toPoint()));
- touchPoint.setScenePosition(view.mapToScene(touchPoint.position().toPoint()));
+ QEventPoint touchPoint(0);
+ QMutableEventPoint::setState(touchPoint, QEventPoint::State::Pressed);
+ QMutableEventPoint::setPosition(touchPoint, view.mapFromScene(child1->mapToScene(child1->boundingRect().center())));
+ QMutableEventPoint::setGlobalPosition(touchPoint, view.mapToGlobal(touchPoint.position().toPoint()));
+ QMutableEventPoint::setScenePosition(touchPoint, view.mapToScene(touchPoint.position().toPoint()));
QTouchEvent touchBeginEvent(QEvent::TouchBegin,
touchScreenDevice,
Qt::NoModifier,
{touchPoint});
- touchPoint.detach();
- touchPoint.setState(QEventPoint::State::Updated);
+ QMutableEventPoint::detach(touchPoint);
+ QMutableEventPoint::setState(touchPoint, QEventPoint::State::Updated);
QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
touchScreenDevice,
Qt::NoModifier,
{touchPoint});
- touchPoint.detach();
- touchPoint.setState(QEventPoint::State::Released);
+ QMutableEventPoint::detach(touchPoint);
+ QMutableEventPoint::setState(touchPoint, QEventPoint::State::Released);
QTouchEvent touchEndEvent(QEvent::TouchEnd,
touchScreenDevice,
Qt::NoModifier,
@@ -1648,16 +1648,17 @@ void tst_QTouchEvent::deleteInRawEventTranslation()
QPointF rightScreenPos = rightWidget->mapToGlobal(rightPos.toPoint());
ulong timestamp = 0;
- QList<QMutableEventPoint> rawTouchPoints;
- rawTouchPoints.append(QMutableEventPoint(0));
- rawTouchPoints.append(QMutableEventPoint(1));
- rawTouchPoints.append(QMutableEventPoint(2));
- rawTouchPoints[0].setState(QEventPoint::State::Pressed);
- rawTouchPoints[0].setGlobalPosition(leftScreenPos);
- rawTouchPoints[1].setState(QEventPoint::State::Pressed);
- rawTouchPoints[1].setGlobalPosition(centerScreenPos);
- rawTouchPoints[2].setState(QEventPoint::State::Pressed);
- rawTouchPoints[2].setGlobalPosition(rightScreenPos);
+ QList<QEventPoint> rawTouchPoints = {
+ QEventPoint(0),
+ QEventPoint(1),
+ QEventPoint(2),
+ };
+ QMutableEventPoint::setState(rawTouchPoints[0], QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoints[0], leftScreenPos);
+ QMutableEventPoint::setState(rawTouchPoints[1], QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoints[1], centerScreenPos);
+ QMutableEventPoint::setState(rawTouchPoints[2], QEventPoint::State::Pressed);
+ QMutableEventPoint::setGlobalPosition(rawTouchPoints[2], rightScreenPos);
// generate begin events on all widgets, the left widget should die
QWindow *window = touchWidget.windowHandle();
@@ -1670,18 +1671,18 @@ void tst_QTouchEvent::deleteInRawEventTranslation()
QVERIFY(!rightWidget.isNull());
// generate update events on all widget, the center widget should die
- rawTouchPoints[0].setState(QEventPoint::State::Updated);
- rawTouchPoints[1].setState(QEventPoint::State::Updated);
- rawTouchPoints[2].setState(QEventPoint::State::Updated);
+ QMutableEventPoint::setState(rawTouchPoints[0], QEventPoint::State::Updated);
+ QMutableEventPoint::setState(rawTouchPoints[1], QEventPoint::State::Updated);
+ QMutableEventPoint::setState(rawTouchPoints[2], QEventPoint::State::Updated);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
QCoreApplication::processEvents();
// generate end events on all widget, the right widget should die
- rawTouchPoints[0].setState(QEventPoint::State::Released);
- rawTouchPoints[1].setState(QEventPoint::State::Released);
- rawTouchPoints[2].setState(QEventPoint::State::Released);
+ QMutableEventPoint::setState(rawTouchPoints[0], QEventPoint::State::Released);
+ QMutableEventPoint::setState(rawTouchPoints[1], QEventPoint::State::Released);
+ QMutableEventPoint::setState(rawTouchPoints[2], QEventPoint::State::Released);
nativeTouchPoints =
QWindowSystemInterfacePrivate::toNativeTouchPoints(rawTouchPoints, window);
QWindowSystemInterface::handleTouchEvent(window, ++timestamp, touchScreenDevice, nativeTouchPoints);
@@ -1830,25 +1831,25 @@ void tst_QTouchEvent::testQGuiAppDelivery()
// Now the real thing.
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchBegin
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin);
points[0].state = QEventPoint::State::Updated;
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchUpdate
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 2);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 2);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchUpdate);
points[0].state = QEventPoint::State::Released;
QWindowSystemInterface::handleTouchEvent(&w, touchScreenDevice, points); // TouchEnd
QCoreApplication::processEvents();
- QCOMPARE(filter.d.count(), 1);
+ QCOMPARE(filter.d.size(), 1);
QCOMPARE(filter.d.contains(touchScreenDevice), true);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 3);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 3);
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchEnd);
}
@@ -1891,8 +1892,8 @@ void tst_QTouchEvent::testMultiDevice()
QCOMPARE(filter.d.value(touchScreenDevice).lastSeenType, QEvent::TouchBegin);
QCOMPARE(filter.d.value(deviceTwo).lastSeenType, QEvent::TouchBegin);
- QCOMPARE(filter.d.value(touchScreenDevice).points.count(), 1);
- QCOMPARE(filter.d.value(deviceTwo).points.count(), 2);
+ QCOMPARE(filter.d.value(touchScreenDevice).points.size(), 1);
+ QCOMPARE(filter.d.value(deviceTwo).points.size(), 2);
QCOMPARE(filter.d.value(touchScreenDevice).points.at(0).globalPosition(), area0.center());
// This fails because QGuiApplicationPrivate::processTouchEvent() sends synth-mouse events
@@ -1947,7 +1948,7 @@ void tst_QTouchEvent::grabbers()
// Ensure that grabbers are persistent between events, within the stored touchpoints
QCOMPARE(devPriv->pointById(0)->exclusiveGrabber, grabExclusive ? &w : nullptr);
- QCOMPARE(devPriv->pointById(0)->passiveGrabbers.count(), grabPassive ? 1 : 0);
+ QCOMPARE(devPriv->pointById(0)->passiveGrabbers.size(), grabPassive ? 1 : 0);
if (grabPassive)
QCOMPARE(devPriv->pointById(0)->passiveGrabbers.first(), &w);
diff --git a/tests/auto/gui/kernel/qwindow/BLACKLIST b/tests/auto/gui/kernel/qwindow/BLACKLIST
index ee1d6563cb..69df8883c8 100644
--- a/tests/auto/gui/kernel/qwindow/BLACKLIST
+++ b/tests/auto/gui/kernel/qwindow/BLACKLIST
@@ -1,9 +1,4 @@
[positioning]
-opensuse-leap
-[positioning:default]
-linux
-macos ci
-[positioning:fake]
macos ci
[modalWithChildWindow]
# QTBUG-69160
@@ -11,13 +6,11 @@ android
[modalWindowEnterEventOnHide_QTBUG35109]
osx
android
-windows-10
+windows
[spuriousMouseMove]
# QTBUG-69162
windows-10
android
-[testInputEvents]
-rhel-7.4
[modalWindowPosition]
# QTBUG-69161
android
@@ -28,3 +21,8 @@ android
android
[modalWindowModallity]
android
+[enterLeaveOnWindowShowHide]
+windows-10
+windows-11
+android
+rhel
diff --git a/tests/auto/gui/kernel/qwindow/CMakeLists.txt b/tests/auto/gui/kernel/qwindow/CMakeLists.txt
index 23671cc385..5824989ac3 100644
--- a/tests/auto/gui/kernel/qwindow/CMakeLists.txt
+++ b/tests/auto/gui/kernel/qwindow/CMakeLists.txt
@@ -1,22 +1,51 @@
-# Generated from qwindow.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qwindow Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qwindow LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qwindow
SOURCES
tst_qwindow.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
)
+if(APPLE OR WIN32 OR QT_FEATURE_xcb)
+ qt_internal_add_test(tst_foreignwindow
+ LOWDPI
+ SOURCES
+ tst_foreignwindow.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ )
+
+ if(APPLE)
+ enable_language(OBJCXX)
+ set_source_files_properties(tst_foreignwindow.cpp PROPERTIES LANGUAGE OBJCXX)
+ set_property(TARGET tst_foreignwindow PROPERTY PROPERTY MACOSX_BUNDLE TRUE)
+ endif()
+
+ if(QT_FEATURE_xcb)
+ target_link_libraries(tst_foreignwindow PRIVATE XCB::XCB)
+ endif()
+endif()
+
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qwindow CONDITION QT_FEATURE_dynamicgl AND WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
user32
)
diff --git a/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
new file mode 100644
index 0000000000..e7b05e7037
--- /dev/null
+++ b/tests/auto/gui/kernel/qwindow/tst_foreignwindow.cpp
@@ -0,0 +1,142 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
+
+#include <QtCore/qloggingcategory.h>
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+
+#include "../../../../shared/nativewindow.h"
+
+class tst_ForeignWindow: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase()
+ {
+ auto *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ if (!platformIntegration->hasCapability(QPlatformIntegration::ForeignWindows))
+ QSKIP("This platform does not support foreign windows");
+ }
+
+ void fromWinId();
+ void initialState();
+
+ void embedForeignWindow();
+ void embedInForeignWindow();
+};
+
+void tst_ForeignWindow::fromWinId()
+{
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+ QVERIFY(foreignWindow);
+ QVERIFY(foreignWindow->flags().testFlag(Qt::ForeignWindow));
+ QVERIFY(foreignWindow->handle());
+
+ // fromWinId does not take (exclusive) ownership of the native window,
+ // so deleting the foreign window should not be a problem/cause crashes.
+ foreignWindow.reset();
+}
+
+void tst_ForeignWindow::initialState()
+{
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ // A foreign window can be used to embed a Qt UI in a foreign window hierarchy,
+ // in which case the foreign window merely acts as a parent and should not be
+ // modified, or to embed a foreign window in a Qt UI, in which case the foreign
+ // window must to be able to re-parent, move, resize, show, etc, so that the
+ // containing Qt UI can treat it as any other window.
+
+ // At the point of creation though, we don't know what the foreign window
+ // will be used for, so the platform should not assume it can modify the
+ // window. Any properties set on the native window should persist past
+ // creation of the foreign window.
+
+ const QRect initialGeometry(123, 456, 321, 654);
+ nativeWindow.setGeometry(initialGeometry);
+ QTRY_COMPARE(nativeWindow.geometry(), initialGeometry);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+ QCOMPARE(nativeWindow.geometry(), initialGeometry);
+
+ // For extra bonus points, the foreign window should actually
+ // reflect the state of the native window.
+ QCOMPARE(foreignWindow->geometry(), initialGeometry);
+}
+
+void tst_ForeignWindow::embedForeignWindow()
+{
+ // A foreign window embedded into a Qt UI requires that the rest of Qt
+ // is to be able to treat the foreign child window as any other window
+ // that it can show, hide, stack, and move around.
+
+ QWindow parentWindow;
+
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ // As a prerequisite to that, we must be able to reparent the foreign window
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+ foreignWindow->setParent(&parentWindow);
+ QTRY_COMPARE(nativeWindow.parentWinId(), parentWindow.winId());
+
+ // FIXME: This test is flakey on Linux. Figure out why
+#if !defined(Q_OS_LINUX)
+ foreignWindow->setParent(nullptr);
+ QTRY_VERIFY(nativeWindow.parentWinId() != parentWindow.winId());
+#endif
+}
+
+void tst_ForeignWindow::embedInForeignWindow()
+{
+ // When a foreign window is used as a container to embed a Qt UI
+ // in a foreign window hierarchy, the foreign window merely acts
+ // as a parent, and should not be modified.
+
+ {
+ // At a minimum, we must be able to reparent into the window
+ NativeWindow nativeWindow;
+ QVERIFY(nativeWindow);
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(nativeWindow));
+
+ QWindow embeddedWindow;
+ embeddedWindow.setParent(foreignWindow.get());
+ QTRY_VERIFY(nativeWindow.isParentOf(embeddedWindow.winId()));
+ }
+
+ {
+ // The foreign window's native window should not be reparent as a
+ // result of creating the foreign window, adding and removing children,
+ // or destroying the foreign window.
+
+ NativeWindow topLevelNativeWindow;
+ NativeWindow childNativeWindow;
+ childNativeWindow.setParent(topLevelNativeWindow);
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ std::unique_ptr<QWindow> foreignWindow(QWindow::fromWinId(childNativeWindow));
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ QWindow embeddedWindow;
+ embeddedWindow.setParent(foreignWindow.get());
+ QTRY_VERIFY(childNativeWindow.isParentOf(embeddedWindow.winId()));
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ embeddedWindow.setParent(nullptr);
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+
+ foreignWindow.reset();
+ QVERIFY(topLevelNativeWindow.isParentOf(childNativeWindow));
+ }
+}
+
+#include <tst_foreignwindow.moc>
+QTEST_MAIN(tst_ForeignWindow)
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 9e8e1eac11..a9e2c5f882 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qrasterwindow.h>
#include <qpa/qwindowsysteminterface.h>
@@ -32,6 +7,7 @@
#include <qpa/qplatformwindow.h>
#include <private/qguiapplication_p.h>
#include <private/qhighdpiscaling_p.h>
+#include <private/qwindow_p.h>
#include <QtGui/QPainter>
#include <QTest>
@@ -47,6 +23,12 @@
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
+static bool isPlatformEglFS()
+{
+ static const bool isEglFS = !QGuiApplication::platformName().compare(QLatin1String("eglfs"), Qt::CaseInsensitive);
+ return isEglFS;
+}
+
class tst_QWindow: public QObject
{
Q_OBJECT
@@ -55,6 +37,7 @@ private slots:
void create();
void setParent();
void setVisible();
+ void setVisibleThenCreate();
void setVisibleFalseDoesNotCreateWindow();
void eventOrderOnShow();
void paintEvent();
@@ -95,6 +78,7 @@ private slots:
void modalWithChildWindow();
void modalWindowModallity();
void modalWindowPosition();
+ void modalCloseWhileBlocked();
#ifndef QT_NO_CURSOR
void modalWindowEnterEventOnHide_QTBUG35109();
void spuriousMouseMove();
@@ -110,6 +94,16 @@ private slots:
void generatedMouseMove();
void keepPendingUpdateRequests();
void activateDeactivateEvent();
+ void qobject_castOnDestruction();
+ void touchToMouseTranslationByPopup();
+ void stateChangeSignal();
+#ifndef QT_NO_CURSOR
+ void enterLeaveOnWindowShowHide_data();
+ void enterLeaveOnWindowShowHide();
+#endif
+ void windowExposedAfterReparent();
+ void childEvents();
+ void parentEvents();
private:
QPoint m_availableTopLeft;
@@ -120,8 +114,17 @@ private:
QInputDevice::Capability::Position | QInputDevice::Capability::MouseEmulation);
};
+static bool isPlatformWayland()
+{
+ return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive);
+}
+
void tst_QWindow::initTestCase()
{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() == 33)
+ QSKIP("Is flaky on Android 13 / RHEL 8.6 and 8.8 (QTQAINFRA-5606)");
+#endif
// Size of reference window, 200 for < 2000, scale up for larger screens
// to avoid Windows warnings about minimum size for decorated windows.
int width = 200;
@@ -131,6 +134,10 @@ void tst_QWindow::initTestCase()
if (screenWidth > 2000)
width = 100 * ((screenWidth + 500) / 1000);
m_testWindowSize = QSize(width, width);
+
+ // Make sure test runs consistently on all compositors by force-disabling window decorations
+ if (isPlatformWayland())
+ qputenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1");
}
void tst_QWindow::cleanup()
@@ -243,6 +250,40 @@ void tst_QWindow::setVisible()
QVERIFY(QTest::qWaitForWindowExposed(&i));
}
+class SurfaceCreatedWindow : public QWindow
+{
+ Q_OBJECT
+public:
+ using QWindow::QWindow;
+
+ bool eventFilter(QObject *o, QEvent *e) override
+ {
+ if (e->type() == QEvent::PlatformSurface) {
+ auto type = static_cast<QPlatformSurfaceEvent*>(e)->surfaceEventType();
+ if (type == QPlatformSurfaceEvent::SurfaceCreated)
+ ++surfaceCreatedEvents;
+ }
+ return QWindow::eventFilter(o, e);
+ }
+
+ int surfaceCreatedEvents = 0;
+};
+
+void tst_QWindow::setVisibleThenCreate()
+{
+ QWindow parent;
+ parent.setObjectName("Parent");
+ SurfaceCreatedWindow child(&parent);
+ child.installEventFilter(&child);
+ child.setObjectName("Child");
+ child.setVisible(true);
+ child.create();
+ QCOMPARE(child.surfaceCreatedEvents, 1);
+ parent.setVisible(true);
+ QCOMPARE(child.surfaceCreatedEvents, 1);
+ QVERIFY(QTest::qWaitForWindowExposed(&child));
+}
+
void tst_QWindow::setVisibleFalseDoesNotCreateWindow()
{
QWindow w;
@@ -310,13 +351,6 @@ public:
m_received[event->type()]++;
m_order << event->type();
switch (event->type()) {
- case QEvent::Expose:
-QT_WARNING_PUSH
-QT_WARNING_DISABLE_DEPRECATED
- m_exposeRegion = static_cast<QExposeEvent *>(event)->region();
-QT_WARNING_POP
- break;
-
case QEvent::PlatformSurface:
m_surfaceventType = static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType();
break;
@@ -346,11 +380,6 @@ QT_WARNING_POP
return m_order.indexOf(type);
}
- QRegion exposeRegion() const
- {
- return m_exposeRegion;
- }
-
QPlatformSurfaceEvent::SurfaceEventType surfaceEventType() const
{
return m_surfaceventType;
@@ -362,7 +391,6 @@ QT_WARNING_POP
private:
QHash<QEvent::Type, int> m_received;
QList<QEvent::Type> m_order;
- QRegion m_exposeRegion;
QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType;
};
@@ -454,11 +482,16 @@ void tst_QWindow::resizeEventAfterResize()
// Make sure we get a resizeEvent after calling resize
window.resize(m_testWindowSize);
+ if (isPlatformEglFS())
+ QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue);
+
QTRY_COMPARE(window.received(QEvent::Resize), 2);
}
void tst_QWindow::exposeEventOnShrink_QTBUG54040()
{
+ if (isPlatformEglFS())
+ QSKIP("", "eglfs windows are fullscreen by default.", Continue);
Window window;
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
window.setTitle(QTest::currentTestFunction());
@@ -522,13 +555,11 @@ static QString msgRectMismatch(const QRect &r1, const QRect &r2)
return result;
}
-static bool isPlatformWayland()
-{
- return !QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive);
-}
-
void tst_QWindow::positioning()
{
+#ifdef Q_OS_ANDROID
+ QSKIP("Fails on Android. QTBUG-105201");
+#endif
if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(
QPlatformIntegration::NonFullScreenWindows)) {
QSKIP("This platform does not support non-fullscreen windows");
@@ -550,9 +581,8 @@ void tst_QWindow::positioning()
QCOMPARE(window.geometry(), geometry);
// explicitly use non-fullscreen show. show() can be fullscreen on some platforms
window.showNormal();
- QCoreApplication::processEvents();
- QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(QTest::qWaitForWindowActive(&window));
QMargins originalMargins = window.frameMargins();
@@ -644,9 +674,8 @@ void tst_QWindow::childWindowPositioning_data()
void tst_QWindow::childWindowPositioning()
{
- if (isPlatformWayland())
- QSKIP("Wayland: This is flaky (protocol errors for xdg-shell v6). See QTBUG-67648.");
-
+ if (isPlatformEglFS())
+ QSKIP("eglfs does not support child windows.");
const QPoint topLeftOrigin(0, 0);
ColoredWindow topLevelWindowFirst(Qt::green);
@@ -749,7 +778,7 @@ void tst_QWindow::stateChange()
// explicitly use non-fullscreen show. show() can be fullscreen on some platforms
window.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&window));
- for (Qt::WindowState state : qAsConst(stateSequence)) {
+ for (Qt::WindowState state : std::as_const(stateSequence)) {
window.setWindowState(state);
QCoreApplication::processEvents();
}
@@ -823,16 +852,6 @@ void tst_QWindow::isExposed()
QTRY_VERIFY(window.received(QEvent::Expose) > 0);
QTRY_VERIFY(window.isExposed());
-#ifndef Q_OS_WIN
- // This is a top-level window so assuming it is completely exposed, the
- // expose region must be (0, 0), (width, height). If this is not the case,
- // the platform plugin is sending expose events with a region in an
- // incorrect coordinate system.
- QRect r = window.exposeRegion().boundingRect();
- r = QRect(window.mapToGlobal(r.topLeft()), r.size());
- QCOMPARE(r, window.geometry());
-#endif
-
window.hide();
QCoreApplication::processEvents();
@@ -977,6 +996,9 @@ public:
if (spinLoopWhenPressed)
QCoreApplication::processEvents();
}
+ if (closeOnTap)
+ this->close();
+
}
void mouseReleaseEvent(QMouseEvent *event) override
{
@@ -1033,7 +1055,7 @@ public:
}
touchEventType = event->type();
QList<QTouchEvent::TouchPoint> points = event->points();
- for (int i = 0; i < points.count(); ++i) {
+ for (int i = 0; i < points.size(); ++i) {
const auto &point = points.at(i);
switch (point.state()) {
case QEventPoint::State::Pressed:
@@ -1044,6 +1066,8 @@ public:
touchPressLocalPos = point.position();
touchPressGlobalPos = point.globalPosition();
}
+ if (closeOnTap)
+ this->close();
break;
case QEventPoint::State::Released:
++touchReleasedCount;
@@ -1100,6 +1124,8 @@ public:
const QPointingDevice *mouseDevice = nullptr;
const QPointingDevice *touchDevice = nullptr;
+
+ bool closeOnTap = false;
};
static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global)
@@ -1323,6 +1349,8 @@ void tst_QWindow::mouseToTouchTranslation()
QTRY_COMPARE(window.touchPressedCount, 1);
QTRY_COMPARE(window.touchReleasedCount, 1);
QCOMPARE(window.mouseDevice, window.touchDevice);
+ if (isPlatformWayland())
+ QEXPECT_FAIL("", "Wayland: This fails. See QTBUG-100887.", Abort);
QCOMPARE(window.touchDevice->type(), QInputDevice::DeviceType::Mouse);
QCOMPARE(window.touchPressLocalPos.toPoint(), localPos);
QCOMPARE(window.touchPressGlobalPos.toPoint(), window.mapToGlobal(localPos));
@@ -1480,9 +1508,6 @@ void tst_QWindow::touchCancelWithTouchToMouse()
void tst_QWindow::touchInterruptedByPopup()
{
- if (isPlatformWayland())
- QSKIP("Wayland: This test crashes with xdg-shell unstable v6");
-
InputTestWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(80, 80), m_testWindowSize));
@@ -1547,7 +1572,7 @@ void tst_QWindow::orientation()
QSignalSpy spy(&window, SIGNAL(contentOrientationChanged(Qt::ScreenOrientation)));
window.reportContentOrientationChange(Qt::LandscapeOrientation);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QWindow::sizes()
@@ -1566,40 +1591,58 @@ void tst_QWindow::sizes()
QCOMPARE(window.minimumHeight(), 0);
QCOMPARE(window.minimumSize(), QSize(10, 0));
QCOMPARE(window.maximumSize(), oldMaximum);
- QCOMPARE(minimumWidthSpy.count(), 1);
- QCOMPARE(minimumHeightSpy.count(), 0);
- QCOMPARE(maximumWidthSpy.count(), 0);
- QCOMPARE(maximumHeightSpy.count(), 0);
+ QCOMPARE(minimumWidthSpy.size(), 1);
+ QCOMPARE(minimumHeightSpy.size(), 0);
+ QCOMPARE(maximumWidthSpy.size(), 0);
+ QCOMPARE(maximumHeightSpy.size(), 0);
window.setMinimumHeight(10);
QCOMPARE(window.minimumWidth(), 10);
QCOMPARE(window.minimumHeight(), 10);
QCOMPARE(window.minimumSize(), QSize(10, 10));
QCOMPARE(window.maximumSize(), oldMaximum);
- QCOMPARE(minimumWidthSpy.count(), 1);
- QCOMPARE(minimumHeightSpy.count(), 1);
- QCOMPARE(maximumWidthSpy.count(), 0);
- QCOMPARE(maximumHeightSpy.count(), 0);
+ QCOMPARE(minimumWidthSpy.size(), 1);
+ QCOMPARE(minimumHeightSpy.size(), 1);
+ QCOMPARE(maximumWidthSpy.size(), 0);
+ QCOMPARE(maximumHeightSpy.size(), 0);
window.setMaximumWidth(100);
QCOMPARE(window.maximumWidth(), 100);
QCOMPARE(window.maximumHeight(), oldMaximum.height());
QCOMPARE(window.minimumSize(), QSize(10, 10));
QCOMPARE(window.maximumSize(), QSize(100, oldMaximum.height()));
- QCOMPARE(minimumWidthSpy.count(), 1);
- QCOMPARE(minimumHeightSpy.count(), 1);
- QCOMPARE(maximumWidthSpy.count(), 1);
- QCOMPARE(maximumHeightSpy.count(), 0);
+ QCOMPARE(minimumWidthSpy.size(), 1);
+ QCOMPARE(minimumHeightSpy.size(), 1);
+ QCOMPARE(maximumWidthSpy.size(), 1);
+ QCOMPARE(maximumHeightSpy.size(), 0);
window.setMaximumHeight(100);
QCOMPARE(window.maximumWidth(), 100);
QCOMPARE(window.maximumHeight(), 100);
QCOMPARE(window.minimumSize(), QSize(10, 10));
QCOMPARE(window.maximumSize(), QSize(100, 100));
- QCOMPARE(minimumWidthSpy.count(), 1);
- QCOMPARE(minimumHeightSpy.count(), 1);
- QCOMPARE(maximumWidthSpy.count(), 1);
- QCOMPARE(maximumHeightSpy.count(), 1);
+ QCOMPARE(minimumWidthSpy.size(), 1);
+ QCOMPARE(minimumHeightSpy.size(), 1);
+ QCOMPARE(maximumWidthSpy.size(), 1);
+ QCOMPARE(maximumHeightSpy.size(), 1);
+
+ // test if min and max limits will change the size
+ QVERIFY(window.minimumWidth() < 50 && window.maximumWidth() > 80);
+ QVERIFY(window.minimumHeight() < 50 && window.maximumHeight() > 80);
+ window.resize(50, 50);
+ QCOMPARE(window.size(), QSize(50, 50));
+ window.setMinimumSize(QSize(60, 60));
+ QCOMPARE(window.size(), QSize(60, 60));
+ window.resize(80, 80);
+ window.setMaximumSize(QSize(70, 70));
+ QCOMPARE(window.size(), QSize(70, 70));
+
+ // QTBUG-113233
+ // test for an invalid min/max pair
+ window.setMinimumSize(QSize(80, 80)); // current maximumSize = QSize(70, 70)
+ QCOMPARE(window.size(), QSize(70, 70));
+ window.setMaximumSize(QSize(90, 90));
+ QCOMPARE(window.size(), QSize(80, 80));
}
class CloseOnCloseEventWindow : public QWindow
@@ -1831,25 +1874,25 @@ void tst_QWindow::windowModality()
QCOMPARE(window.modality(), Qt::NonModal);
window.setModality(Qt::NonModal);
QCOMPARE(window.modality(), Qt::NonModal);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
window.setModality(Qt::WindowModal);
QCOMPARE(window.modality(), Qt::WindowModal);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
window.setModality(Qt::WindowModal);
QCOMPARE(window.modality(), Qt::WindowModal);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
window.setModality(Qt::ApplicationModal);
QCOMPARE(window.modality(), Qt::ApplicationModal);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
window.setModality(Qt::ApplicationModal);
QCOMPARE(window.modality(), Qt::ApplicationModal);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
window.setModality(Qt::NonModal);
QCOMPARE(window.modality(), Qt::NonModal);
- QCOMPARE(spy.count(), 3);
+ QCOMPARE(spy.size(), 3);
}
void tst_QWindow::inputReentrancy()
@@ -2032,32 +2075,32 @@ void tst_QWindow::visibility()
QVERIFY(window.isVisible());
QVERIFY(window.visibility() != QWindow::Hidden);
QVERIFY(window.visibility() != QWindow::AutomaticVisibility);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
window.setVisibility(QWindow::Hidden);
QVERIFY(!window.isVisible());
QCOMPARE(window.visibility(), QWindow::Hidden);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
window.setVisibility(QWindow::FullScreen);
QVERIFY(window.isVisible());
QCOMPARE(window.windowState(), Qt::WindowFullScreen);
QCOMPARE(window.visibility(), QWindow::FullScreen);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowFullScreen);
spy.clear();
window.setWindowState(Qt::WindowNoState);
QCOMPARE(window.visibility(), QWindow::Windowed);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QTRY_COMPARE(window.lastReceivedWindowState, Qt::WindowNoState);
spy.clear();
window.setVisible(false);
QCOMPARE(window.visibility(), QWindow::Hidden);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
}
@@ -2090,9 +2133,6 @@ void tst_QWindow::mask()
void tst_QWindow::initialSize()
{
- if (isPlatformWayland())
- QSKIP("Wayland: This fails. See QTBUG-66818.");
-
QSize defaultSize(0,0);
{
Window w;
@@ -2107,6 +2147,10 @@ void tst_QWindow::initialSize()
w.setTitle(QLatin1String(QTest::currentTestFunction()));
w.setWidth(m_testWindowSize.width());
w.showNormal();
+
+ if (isPlatformEglFS())
+ QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue);
+
QTRY_COMPARE(w.width(), m_testWindowSize.width());
QTRY_VERIFY(w.height() > 0);
}
@@ -2118,6 +2162,8 @@ void tst_QWindow::initialSize()
w.showNormal();
const QSize expectedSize = testSize;
+ if (isPlatformEglFS())
+ QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue);
QTRY_COMPARE(w.size(), expectedSize);
}
}
@@ -2282,6 +2328,9 @@ void tst_QWindow::modalWindowModallity()
void tst_QWindow::modalWindowPosition()
{
+ if (isPlatformWayland())
+ QSKIP("Window position not queryable on Wayland");
+
QWindow window;
window.setTitle(QLatin1String(QTest::currentTestFunction()));
window.setGeometry(QRect(m_availableTopLeft + QPoint(100, 100), m_testWindowSize));
@@ -2290,9 +2339,29 @@ void tst_QWindow::modalWindowPosition()
window.setModality(Qt::WindowModal);
window.show();
QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ if (isPlatformEglFS())
+ QEXPECT_FAIL("", "eglfs windows are fullscreen by default.", Continue);
+
QCOMPARE(window.geometry(), origGeo);
}
+void tst_QWindow::modalCloseWhileBlocked()
+{
+ QWindow first;
+ first.setModality(Qt::ApplicationModal);
+ first.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&first));
+
+ QWindow second;
+ second.setModality(Qt::ApplicationModal);
+ second.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&first));
+
+ first.close();
+ QTRY_VERIFY(!first.isVisible());
+}
+
#ifndef QT_NO_CURSOR
void tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109()
{
@@ -2302,6 +2371,9 @@ void tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109()
if (isPlatformOffscreenOrMinimal())
QSKIP("Can't test window focusing on offscreen/minimal");
+ if (isPlatformEglFS())
+ QSKIP("QCursor::setPos() is not supported on this platform");
+
const QPoint center = QGuiApplication::primaryScreen()->availableGeometry().center();
const int childOffset = 16;
@@ -2482,6 +2554,8 @@ void tst_QWindow::spuriousMouseMove()
QSKIP("No enter events sent");
if (platformName == QLatin1String("wayland"))
QSKIP("Setting mouse cursor position is not possible on Wayland");
+ if (isPlatformEglFS())
+ QSKIP("QCursor::setPos() is not supported on this platform");
const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry();
const QPoint center = screenGeometry.center();
QCursor::setPos(center);
@@ -2701,6 +2775,9 @@ void tst_QWindow::keepPendingUpdateRequests()
void tst_QWindow::activateDeactivateEvent()
{
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation))
+ QSKIP("QWindow::requestActivate() is not supported.");
+
class Window : public QWindow
{
public:
@@ -2741,6 +2818,408 @@ void tst_QWindow::activateDeactivateEvent()
QCOMPARE(w2.activateCount, 1);
}
+// Test that in a slot connected to destroyed() the emitter is
+// is no longer a QWindow.
+void tst_QWindow::qobject_castOnDestruction()
+{
+ QWindow window;
+ QObject::connect(&window, &QObject::destroyed, [](QObject *object)
+ {
+ QVERIFY(!qobject_cast<QWindow *>(object));
+ QVERIFY(!dynamic_cast<QWindow *>(object));
+ QVERIFY(!object->isWindowType());
+ });
+}
+
+void tst_QWindow::touchToMouseTranslationByPopup()
+{
+ InputTestWindow window;
+ window.setTitle(QLatin1String(QTest::currentTestFunction()));
+ window.ignoreTouch = true;
+ window.setGeometry(QRect(m_availableTopLeft, m_testWindowSize));
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+
+ InputTestWindow popupWindow;
+ popupWindow.setGeometry(QRect(m_availableTopLeft + QPoint(20, 20),
+ QSize(m_testWindowSize.width(), m_testWindowSize.height() / 2)));
+ popupWindow.setFlag(Qt::Popup);
+ popupWindow.setTransientParent(&window);
+ popupWindow.ignoreTouch = true;
+ popupWindow.closeOnTap = true;
+ popupWindow.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&popupWindow));
+
+ QTest::touchEvent(&popupWindow, touchDevice).press(0, {1, 1}, &window);
+ QVERIFY(!popupWindow.isVisible());
+
+ // Omit touchpoint 0: because the popup was closed, touchpoint0.release is not sent.
+ const QPoint tp1(50, 1);
+ QTest::touchEvent(&window, touchDevice).press(1, tp1, &window);
+ QTRY_COMPARE(window.mousePressButton, int(Qt::LeftButton));
+ QTest::touchEvent(&window, touchDevice).release(1, tp1, &window);
+ QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
+}
+
+// Test that windowStateChanged is not emitted on noop change (QTBUG-102478)
+void tst_QWindow::stateChangeSignal()
+{
+ // Test only for Windows, Linux and macOS
+#if !defined(Q_OS_LINUX) && !defined(Q_OS_WINDOWS) && !defined(Q_OS_DARWIN)
+ QSKIP("Singular windowStateChanged signal emission is guaranteed for Linux, Windows and macOS only.\n"
+ "On other operating systems, the signal may be emitted twice.");
+#endif
+ QWindow w;
+ Q_ASSERT(connect (&w, &QWindow::windowStateChanged, [](Qt::WindowState s){qCDebug(lcTests) << "State change to" << s;}));
+ QSignalSpy spy(&w, SIGNAL(windowStateChanged(Qt::WindowState)));
+ unsigned short signalCount = 0;
+ QList<Qt::WindowState> effectiveStates;
+ Q_ASSERT(connect(&w, &QWindow::windowStateChanged, [&effectiveStates](Qt::WindowState state)
+ { effectiveStates.append(state); }));
+ // Part 1:
+ // => test signal emission on programmatic state changes
+ QCOMPARE(w.windowState(), Qt::WindowNoState);
+ // - wait for target state to be set
+ // - wait for signal spy to have reached target count
+ // - extract state from signal and compare to target
+#define CHECK_STATE(State)\
+ QTRY_VERIFY(QTest::qWaitFor([&w](){return (w.windowState() == State); }));\
+ CHECK_SIGNAL(State)
+#define CHECK_SIGNAL(State)\
+ QTRY_COMPARE(spy.count(), signalCount);\
+ if (signalCount > 0) {\
+ QVariantList list = spy.at(signalCount - 1).toList();\
+ QCOMPARE(list.count(), 1);\
+ bool ok;\
+ const int stateInt = list.at(0).toInt(&ok);\
+ QVERIFY(ok);\
+ const Qt::WindowState newState = static_cast<Qt::WindowState>(stateInt);\
+ QCOMPARE(newState, State);\
+ }
+ // Check initialization
+ CHECK_STATE(Qt::WindowNoState);
+ // showMaximized after init
+ // expected behavior: signal emitted once with state == WindowMaximized
+ ++signalCount;
+ w.showMaximized();
+ CHECK_STATE(Qt::WindowMaximized);
+ // setWindowState to normal
+ // expected behavior: signal emitted once with state == WindowNoState
+ ++signalCount;
+ w.setWindowState(Qt::WindowNoState);
+ CHECK_STATE(Qt::WindowNoState);
+ // redundant setWindowState to normal - except windows, where the no-op is counted
+ // expected behavior: No emits.
+ // On Windows, a no-op state change causes a no-op resize and repaint, leading to a
+ // no-op state change and singal emission.
+#ifdef Q_OS_WINDOWS
+ ++signalCount;
+ ++signalCount;
+#endif
+ w.setWindowState(Qt::WindowNoState);
+ CHECK_STATE(Qt::WindowNoState);
+ // setWindowState to minimized
+ // expected behavior: signal emitted once with state == WindowMinimized
+ ++signalCount;
+ w.showMinimized();
+ CHECK_STATE(Qt::WindowMinimized);
+ // setWindowState to Normal
+ // expected behavior: signal emitted once with state == WindowNoState
+ ++signalCount;
+ w.showNormal();
+ CHECK_STATE(Qt::WindowNoState);
+ /*
+ - Testcase showFullScreen is omitted: Depending on window manager,
+ WindowFullScreen can be mapped to WindowMaximized
+ - Transition from WindowMinimized to WindowMaximized is omitted:
+ WindowNoState to WindowMaximized
+ */
+ // Part 2:
+ // => test signal emission on simulated user interaction
+ // To test the code path, inject state change events into the QPA event queue.
+ // Test the signal emission only, not the window's actual visible state.
+
+ // Flush pending events and clear
+ QCoreApplication::processEvents();
+ spy.clear();
+ effectiveStates.clear();
+ signalCount = 0;
+ // Maximize window
+ QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowMaximized, w.windowState());
+ ++signalCount;
+ CHECK_SIGNAL(Qt::WindowMaximized);
+ // Normalize window
+ QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowNoState, w.windowState());
+ ++signalCount;
+ CHECK_SIGNAL(Qt::WindowNoState);
+ // Minimize window
+ QWindowSystemInterface::handleWindowStateChanged(&w, Qt::WindowMinimized, w.windowState());
+ ++signalCount;
+ CHECK_SIGNAL(Qt::WindowMinimized);
+}
+
+#ifndef QT_NO_CURSOR
+void tst_QWindow::enterLeaveOnWindowShowHide_data()
+{
+ QTest::addColumn<Qt::WindowType>("windowType");
+ QTest::addRow("dialog") << Qt::Dialog;
+ QTest::addRow("popup") << Qt::Popup;
+}
+
+/*!
+ Verify that we get enter and leave events if the window under the mouse
+ opens and closes a modal dialog or popup. QWindow might get multiple
+ events in a row, as the various QPA plugins need to use different techniques
+ to synthesize events if the native platform doesn't provide them for us.
+*/
+void tst_QWindow::enterLeaveOnWindowShowHide()
+{
+ if (isPlatformWayland())
+ QSKIP("Can't set cursor position and qWaitForWindowActive on Wayland");
+
+ if (isPlatformEglFS())
+ QSKIP("QCursor::setPos() is not supported on this platform");
+
+ QFETCH(Qt::WindowType, windowType);
+
+ class Window : public QWindow
+ {
+ public:
+ int numEnterEvents = 0;
+ int numLeaveEvents = 0;
+ QPoint enterPosition;
+ protected:
+ bool event(QEvent *e) override
+ {
+ switch (e->type()) {
+ case QEvent::Enter:
+ ++numEnterEvents;
+ enterPosition = static_cast<QEnterEvent*>(e)->position().toPoint();
+ break;
+ case QEvent::Leave:
+ ++numLeaveEvents;
+ break;
+ default:
+ break;
+ }
+ return QWindow::event(e);
+ }
+ };
+
+ int expectedEnter = 0;
+ int expectedLeave = 0;
+
+ Window window;
+ const QRect screenGeometry = window.screen()->availableGeometry();
+ const QPoint cursorPos = screenGeometry.topLeft() + QPoint(50, 50);
+ window.setGeometry(QRect(cursorPos - QPoint(50, 50), screenGeometry.size() / 4));
+ QCursor::setPos(cursorPos);
+
+ if (!QTest::qWaitFor([&]{ return window.geometry().contains(QCursor::pos()); }))
+ QSKIP("We can't move the cursor");
+
+ window.show();
+ window.requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(&window));
+
+ ++expectedEnter;
+ QTRY_COMPARE_WITH_TIMEOUT(window.numEnterEvents, expectedEnter, 250);
+ QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos()));
+
+ QWindow secondary;
+ secondary.setFlag(windowType);
+ secondary.setModality(Qt::WindowModal);
+ secondary.setTransientParent(&window);
+ secondary.setPosition(cursorPos + QPoint(50, 50));
+ secondary.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&secondary));
+ ++expectedLeave;
+ QTRY_VERIFY(window.numLeaveEvents >= expectedLeave);
+ secondary.close();
+ ++expectedEnter;
+ QTRY_VERIFY(window.numEnterEvents >= expectedEnter);
+ QCOMPARE(window.enterPosition, window.mapFromGlobal(QCursor::pos()));
+}
+#endif
+
+void tst_QWindow::windowExposedAfterReparent()
+{
+ QWindow parent;
+ QWindow child(&parent);
+ child.show();
+ parent.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
+ QVERIFY(QTest::qWaitForWindowExposed(&child));
+
+ child.setParent(nullptr);
+ QCoreApplication::processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&child));
+
+ child.setParent(&parent);
+ QCoreApplication::processEvents();
+ QVERIFY(QTest::qWaitForWindowExposed(&child));
+}
+
+struct ParentWindow : public QWindow
+{
+ bool event(QEvent *event) override
+ {
+ [&]() -> void {
+ if (event->type() == QEvent::ChildWindowAdded
+ || event->type() == QEvent::ChildWindowRemoved) {
+ // We should not receive child events after the window has been destructed
+ QVERIFY(this->isWindowType());
+
+ auto *parentWindow = this;
+ auto *childEvent = static_cast<QChildWindowEvent*>(event);
+ auto *childWindow = childEvent->child();
+
+ if (event->type() == QEvent::ChildWindowAdded) {
+ QVERIFY(childWindow->parent());
+ QVERIFY(parentWindow->isAncestorOf(childWindow));
+ if (childWindow->handle())
+ QVERIFY(childWindow->handle()->parent() == parentWindow->handle());
+
+ } else {
+ QVERIFY(!childWindow->parent());
+ QVERIFY(!parentWindow->isAncestorOf(childWindow));
+ if (childWindow->handle())
+ QVERIFY(childWindow->handle()->parent() != parentWindow->handle());
+ }
+ }
+ }();
+
+ return QWindow::event(event);
+ }
+};
+
+void tst_QWindow::childEvents()
+{
+ ParentWindow parent;
+
+ {
+ // ChildAdded via constructor
+ QWindow constructorChild(&parent);
+ if (QTest::currentTestFailed()) return;
+ // ChildRemoved via destructor
+ }
+
+ if (QTest::currentTestFailed()) return;
+
+ // ChildAdded and ChildRemoved via setParent
+ QWindow child;
+ child.setParent(&parent);
+ if (QTest::currentTestFailed()) return;
+ child.setParent(nullptr);
+ if (QTest::currentTestFailed()) return;
+
+ parent.create();
+ child.create();
+
+ // ChildAdded and ChildRemoved after creation
+ child.setParent(&parent);
+ if (QTest::currentTestFailed()) return;
+ child.setParent(nullptr);
+ if (QTest::currentTestFailed()) return;
+}
+
+struct ChildWindowPrivate;
+struct ChildWindow : public QWindow
+{
+ ChildWindow(QWindow *parent = nullptr);
+};
+
+struct ChildWindowPrivate : public QWindowPrivate
+{
+ ChildWindowPrivate() : QWindowPrivate()
+ {
+ receiveParentEvents = true;
+ }
+};
+
+ChildWindow::ChildWindow(QWindow *parent)
+ : QWindow(*new ChildWindowPrivate, parent)
+{}
+
+struct ParentEventTester : public QObject
+{
+ bool eventFilter(QObject *object, QEvent *event) override
+ {
+ [&]() -> void {
+ if (event->type() == QEvent::ParentWindowAboutToChange
+ || event->type() == QEvent::ParentWindowChange) {
+ // We should not receive parent events after the window has been destructed
+ QVERIFY(object->isWindowType());
+ auto *window = static_cast<QWindow*>(object);
+
+ if (event->type() == QEvent::ParentWindowAboutToChange) {
+ QVERIFY(window->parent() != nextExpectedParent);
+ if (window->handle()) {
+ QVERIFY(window->handle()->parent() !=
+ (nextExpectedParent ? nextExpectedParent->handle() : nullptr));
+ }
+ } else {
+ QVERIFY(window->parent() == nextExpectedParent);
+ if (window->handle()) {
+ QVERIFY(window->handle()->parent() ==
+ (nextExpectedParent ? nextExpectedParent->handle() : nullptr));
+ }
+ }
+ }
+ }();
+
+ return QObject::eventFilter(object, event);
+ }
+
+ QWindow *nextExpectedParent = nullptr;
+};
+
+
+
+void tst_QWindow::parentEvents()
+{
+ QWindow parent;
+
+ {
+ ParentEventTester tester;
+
+ {
+ // We can't hook in early enough to get the parent change during
+ // QObject construction.
+ ChildWindow child(&parent);
+
+ // But we can observe the one during destruction
+ child.installEventFilter(&tester);
+ tester.nextExpectedParent = nullptr;
+ }
+ }
+ if (QTest::currentTestFailed()) return;
+
+ ParentEventTester tester;
+ ChildWindow child;
+ child.installEventFilter(&tester);
+
+ tester.nextExpectedParent = &parent;
+ child.setParent(&parent);
+ if (QTest::currentTestFailed()) return;
+
+ tester.nextExpectedParent = nullptr;
+ child.setParent(nullptr);
+ if (QTest::currentTestFailed()) return;
+
+ parent.create();
+ child.create();
+
+ tester.nextExpectedParent = &parent;
+ child.setParent(&parent);
+ if (QTest::currentTestFailed()) return;
+
+ tester.nextExpectedParent = nullptr;
+ child.setParent(nullptr);
+ if (QTest::currentTestFailed()) return;
+}
+
#include <tst_qwindow.moc>
QTEST_MAIN(tst_QWindow)
diff --git a/tests/auto/gui/math3d/CMakeLists.txt b/tests/auto/gui/math3d/CMakeLists.txt
index 11c50163ad..a7f2a55aa1 100644
--- a/tests/auto/gui/math3d/CMakeLists.txt
+++ b/tests/auto/gui/math3d/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from math3d.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qquaternion)
add_subdirectory(qvectornd)
diff --git a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt
index 5c54bd6b95..22f581e9c8 100644
--- a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt
+++ b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt
@@ -1,14 +1,19 @@
-# Generated from qmatrixnxn.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qmatrixnxn Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qmatrixnxn LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qmatrixnxn
SOURCES
tst_qmatrixnxn.cpp
- DEFINES
- QT_DISABLE_DEPRECATED_BEFORE=0
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
index 972bbe2f1c..38ecaa7e44 100644
--- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
+++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtCore/qmath.h>
@@ -125,6 +100,7 @@ private slots:
void rotate4x4_data();
void rotate4x4();
+ void projectedRotate();
void normalMatrix_data();
void normalMatrix();
@@ -157,6 +133,11 @@ private slots:
void properties();
void metaTypes();
+ // Tests for deprecated APIs
+#if QT_DEPRECATED_SINCE(6, 1)
+ void deprecatedMultiplications();
+#endif
+
private:
static void setMatrix(QMatrix2x2& m, const float *values);
static void setMatrixDirect(QMatrix2x2& m, const float *values);
@@ -1994,12 +1975,7 @@ void tst_QMatrixNxN::scale4x4()
}
QVector3D v1(2.0f, 3.0f, -4.0f);
- QVector3D v2 = m1 * v1;
- QCOMPARE(v2.x(), (float)(2.0f * x));
- QCOMPARE(v2.y(), (float)(3.0f * y));
- QCOMPARE(v2.z(), (float)(-4.0f * z));
-
- v2 = v1 * m1;
+ QVector3D v2 = m1.map(v1);
QCOMPARE(v2.x(), (float)(2.0f * x));
QCOMPARE(v2.y(), (float)(3.0f * y));
QCOMPARE(v2.z(), (float)(-4.0f * z));
@@ -2018,7 +1994,7 @@ void tst_QMatrixNxN::scale4x4()
QCOMPARE(v4.w(), (float)34.0f);
QPoint p1(2, 3);
- QPoint p2 = m1 * p1;
+ QPoint p2 = m1.map(p1);
QCOMPARE(p2.x(), (int)(2.0f * x));
QCOMPARE(p2.y(), (int)(3.0f * y));
@@ -2027,7 +2003,7 @@ void tst_QMatrixNxN::scale4x4()
QCOMPARE(p2.y(), (int)(3.0f * y));
QPointF p3(2.0f, 3.0f);
- QPointF p4 = m1 * p3;
+ QPointF p4 = m1.map(p3);
QCOMPARE(p4.x(), (float)(2.0f * x));
QCOMPARE(p4.y(), (float)(3.0f * y));
@@ -2140,7 +2116,7 @@ void tst_QMatrixNxN::translate4x4()
}
QVector3D v1(2.0f, 3.0f, -4.0f);
- QVector3D v2 = m1 * v1;
+ QVector3D v2 = m1.map(v1);
QCOMPARE(v2.x(), (float)(2.0f + x));
QCOMPARE(v2.y(), (float)(3.0f + y));
QCOMPARE(v2.z(), (float)(-4.0f + z));
@@ -2160,12 +2136,12 @@ void tst_QMatrixNxN::translate4x4()
QCOMPARE(v6.w(), (float)34.0f);
QPoint p1(2, 3);
- QPoint p2 = m1 * p1;
+ QPoint p2 = m1.map(p1);
QCOMPARE(p2.x(), (int)(2.0f + x));
QCOMPARE(p2.y(), (int)(3.0f + y));
QPointF p3(2.0f, 3.0f);
- QPointF p4 = m1 * p3;
+ QPointF p4 = m1.map(p3);
QCOMPARE(p4.x(), (float)(2.0f + x));
QCOMPARE(p4.y(), (float)(3.0f + y));
@@ -2370,7 +2346,7 @@ void tst_QMatrixNxN::rotate4x4()
p1z /= p1w;
QVector3D v1(2.0f, 3.0f, -4.0f);
- QVector3D v2 = m1 * v1;
+ QVector3D v2 = m1.map(v1);
QVERIFY(qFuzzyCompare(v2.x(), v1x));
QVERIFY(qFuzzyCompare(v2.y(), v1y));
QVERIFY(qFuzzyCompare(v2.z(), v1z));
@@ -2390,12 +2366,12 @@ void tst_QMatrixNxN::rotate4x4()
QVERIFY(qFuzzyCompare(v6.w(), v5w));
QPoint p1(2, 3);
- QPoint p2 = m1 * p1;
+ QPoint p2 = m1.map(p1);
QCOMPARE(p2.x(), qRound(p1x));
QCOMPARE(p2.y(), qRound(p1y));
QPointF p3(2.0f, 3.0f);
- QPointF p4 = m1 * p3;
+ QPointF p4 = m1.map(p3);
QVERIFY(qFuzzyCompare(float(p4.x()), p1x));
QVERIFY(qFuzzyCompare(float(p4.y()), p1y));
@@ -2408,6 +2384,22 @@ void tst_QMatrixNxN::rotate4x4()
}
}
+void tst_QMatrixNxN::projectedRotate()
+{
+ QMatrix4x4 m1, m2;
+ const QPointF origin(1000, 1000);
+
+ m1.translate(origin.x(), origin.y());
+ m1.projectedRotate(60, 0, 1, 0, 0);
+ m1.translate(-origin.x(), -origin.y());
+
+ m2.translate(origin.x(), origin.y());
+ m2.rotate(60, 0, 1, 0);
+ m2.translate(-origin.x(), -origin.y());
+
+ QCOMPARE(m1.toTransform(), m2.toTransform());
+}
+
static bool isSame(const QMatrix3x3& m1, const Matrix3& m2)
{
for (int row = 0; row < 3; ++row) {
@@ -2629,11 +2621,11 @@ void tst_QMatrixNxN::ortho()
{
QMatrix4x4 m1;
m1.ortho(QRect(0, 0, 300, 150));
- QPointF p1 = m1 * QPointF(0, 0);
- QPointF p2 = m1 * QPointF(300, 0);
- QPointF p3 = m1 * QPointF(0, 150);
- QPointF p4 = m1 * QPointF(300, 150);
- QVector3D p5 = m1 * QVector3D(300, 150, 1);
+ QPointF p1 = m1.map(QPointF(0, 0));
+ QPointF p2 = m1.map(QPointF(300, 0));
+ QPointF p3 = m1.map(QPointF(0, 150));
+ QPointF p4 = m1.map(QPointF(300, 150));
+ QVector3D p5 = m1.map(QVector3D(300, 150, 1));
QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f));
QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f));
QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f));
@@ -2648,11 +2640,11 @@ void tst_QMatrixNxN::ortho()
QMatrix4x4 m2;
m2.ortho(QRectF(0, 0, 300, 150));
- p1 = m2 * QPointF(0, 0);
- p2 = m2 * QPointF(300, 0);
- p3 = m2 * QPointF(0, 150);
- p4 = m2 * QPointF(300, 150);
- p5 = m2 * QVector3D(300, 150, 1);
+ p1 = m2.map(QPointF(0, 0));
+ p2 = m2.map(QPointF(300, 0));
+ p3 = m2.map(QPointF(0, 150));
+ p4 = m2.map(QPointF(300, 150));
+ p5 = m2.map(QVector3D(300, 150, 1));
QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f));
QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f));
QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f));
@@ -2667,11 +2659,11 @@ void tst_QMatrixNxN::ortho()
QMatrix4x4 m3;
m3.ortho(0, 300, 150, 0, -1, 1);
- p1 = m3 * QPointF(0, 0);
- p2 = m3 * QPointF(300, 0);
- p3 = m3 * QPointF(0, 150);
- p4 = m3 * QPointF(300, 150);
- p5 = m3 * QVector3D(300, 150, 1);
+ p1 = m3.map(QPointF(0, 0));
+ p2 = m3.map(QPointF(300, 0));
+ p3 = m3.map(QPointF(0, 150));
+ p4 = m3.map(QPointF(300, 150));
+ p5 = m3.map(QVector3D(300, 150, 1));
QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f));
QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f));
QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f));
@@ -2686,11 +2678,11 @@ void tst_QMatrixNxN::ortho()
QMatrix4x4 m4;
m4.ortho(0, 300, 150, 0, -2, 3);
- p1 = m4 * QPointF(0, 0);
- p2 = m4 * QPointF(300, 0);
- p3 = m4 * QPointF(0, 150);
- p4 = m4 * QPointF(300, 150);
- p5 = m4 * QVector3D(300, 150, 1);
+ p1 = m4.map(QPointF(0, 0));
+ p2 = m4.map(QPointF(300, 0));
+ p3 = m4.map(QPointF(0, 150));
+ p4 = m4.map(QPointF(300, 150));
+ p5 = m4.map(QVector3D(300, 150, 1));
QVERIFY(qFuzzyCompare(float(p1.x()), -1.0f));
QVERIFY(qFuzzyCompare(float(p1.y()), 1.0f));
QVERIFY(qFuzzyCompare(float(p2.x()), 1.0f));
@@ -2718,11 +2710,11 @@ void tst_QMatrixNxN::frustum()
{
QMatrix4x4 m1;
m1.frustum(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
- QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f);
- QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f);
- QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f);
- QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f);
- QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f);
+ QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f));
+ QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f));
+ QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f));
+ QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f));
+ QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f));
QVERIFY(qFuzzyCompare(p1.x(), -1.0f));
QVERIFY(qFuzzyCompare(p1.y(), -1.0f));
QVERIFY(qFuzzyCompare(p1.z(), -1.0f));
@@ -2754,11 +2746,11 @@ void tst_QMatrixNxN::perspective()
{
QMatrix4x4 m1;
m1.perspective(45.0f, 1.0f, -1.0f, 1.0f);
- QVector3D p1 = m1 * QVector3D(-1.0f, -1.0f, 1.0f);
- QVector3D p2 = m1 * QVector3D(1.0f, -1.0f, 1.0f);
- QVector3D p3 = m1 * QVector3D(-1.0f, 1.0f, 1.0f);
- QVector3D p4 = m1 * QVector3D(1.0f, 1.0f, 1.0f);
- QVector3D p5 = m1 * QVector3D(0.0f, 0.0f, 2.0f);
+ QVector3D p1 = m1.map(QVector3D(-1.0f, -1.0f, 1.0f));
+ QVector3D p2 = m1.map(QVector3D(1.0f, -1.0f, 1.0f));
+ QVector3D p3 = m1.map(QVector3D(-1.0f, 1.0f, 1.0f));
+ QVector3D p4 = m1.map(QVector3D(1.0f, 1.0f, 1.0f));
+ QVector3D p5 = m1.map(QVector3D(0.0f, 0.0f, 2.0f));
QVERIFY(qFuzzyCompare(p1.x(), 2.41421f));
QVERIFY(qFuzzyCompare(p1.y(), 2.41421f));
QVERIFY(qFuzzyCompare(p1.z(), -1.0f));
@@ -2824,25 +2816,25 @@ void tst_QMatrixNxN::flipCoordinates()
{
QMatrix4x4 m1;
m1.flipCoordinates();
- QVector3D p1 = m1 * QVector3D(2, 3, 4);
+ QVector3D p1 = m1.map(QVector3D(2, 3, 4));
QVERIFY(p1 == QVector3D(2, -3, -4));
QMatrix4x4 m2;
m2.scale(2.0f, 3.0f, 1.0f);
m2.flipCoordinates();
- QVector3D p2 = m2 * QVector3D(2, 3, 4);
+ QVector3D p2 = m2.map(QVector3D(2, 3, 4));
QVERIFY(p2 == QVector3D(4, -9, -4));
QMatrix4x4 m3;
m3.translate(2.0f, 3.0f, 1.0f);
m3.flipCoordinates();
- QVector3D p3 = m3 * QVector3D(2, 3, 4);
+ QVector3D p3 = m3.map(QVector3D(2, 3, 4));
QVERIFY(p3 == QVector3D(4, 0, -3));
QMatrix4x4 m4;
m4.rotate(90.0f, 0.0f, 0.0f, 1.0f);
m4.flipCoordinates();
- QVector3D p4 = m4 * QVector3D(2, 3, 4);
+ QVector3D p4 = m4.map(QVector3D(2, 3, 4));
QVERIFY(p4 == QVector3D(3, 2, -4));
}
@@ -3044,7 +3036,7 @@ void tst_QMatrixNxN::convertQTransform()
QCOMPARE(p1.y(), 150.0 + 2.0);
QMatrix4x4 m2(m1);
- QPointF p2 = m2 * QPointF(100.0, 150.0);
+ QPointF p2 = m2.map(QPointF(100.0, 150.0));
QCOMPARE((double)p2.x(), 100.0 - 3.5);
QCOMPARE((double)p2.y(), 150.0 + 2.0);
QCOMPARE(m1, m2.toTransform());
@@ -3056,7 +3048,7 @@ void tst_QMatrixNxN::convertQTransform()
QCOMPARE(p3.y(), -2.0 * 150.0);
QMatrix4x4 m4(m3);
- QPointF p4 = m4 * QPointF(100.0, 150.0);
+ QPointF p4 = m4.map(QPointF(100.0, 150.0));
QCOMPARE((double)p4.x(), 1.5 * 100.0);
QCOMPARE((double)p4.y(), -2.0 * 150.0);
QCOMPARE(m3, m4.toTransform());
@@ -3066,7 +3058,7 @@ void tst_QMatrixNxN::convertQTransform()
QPointF p5 = m5.map(QPointF(100.0, 150.0));
QMatrix4x4 m6(m5);
- QPointF p6 = m6 * QPointF(100.0, 150.0);
+ QPointF p6 = m6.map(QPointF(100.0, 150.0));
QVERIFY(qFuzzyCompare(float(p5.x()), float(p6.x())));
QVERIFY(qFuzzyCompare(float(p5.y()), float(p6.y())));
@@ -3316,9 +3308,9 @@ void tst_QMatrixNxN::properties()
void tst_QMatrixNxN::metaTypes()
{
- QCOMPARE(QMetaType::type("QMatrix4x4"), int(QMetaType::QMatrix4x4));
+ QCOMPARE(QMetaType::fromName("QMatrix4x4").id(), int(QMetaType::QMatrix4x4));
- QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QMatrix4x4)),
+ QCOMPARE(QByteArray(QMetaType(QMetaType::QMatrix4x4).name()),
QByteArray("QMatrix4x4"));
QVERIFY(QMetaType::isRegistered(QMetaType::QMatrix4x4));
@@ -3326,6 +3318,58 @@ void tst_QMatrixNxN::metaTypes()
QCOMPARE(qMetaTypeId<QMatrix4x4>(), int(QMetaType::QMatrix4x4));
}
+#if QT_DEPRECATED_SINCE(6, 1)
+void tst_QMatrixNxN::deprecatedMultiplications()
+{
+ QMatrix4x4 m;
+ m.scale(1.0f, 2.0f, 3.0f);
+ // QMatrix4x4 and QVector3D
+ {
+ QVector3D v(4.0f, 5.0f, 6.0f);
+ {
+ // QMatrix4x4 * QVector3D
+ QT_IGNORE_DEPRECATIONS(const QVector3D v1 = m * v;)
+ const QVector3D v2 = m.map(v);
+
+ QCOMPARE(v1.x(), v2.x());
+ QCOMPARE(v1.y(), v2.y());
+ QCOMPARE(v1.z(), v2.z());
+ }
+ {
+ // QVector3D * QMatrix4x4
+ QT_IGNORE_DEPRECATIONS(const QVector3D v1 = v * m;)
+
+ QVector4D v4(v, 1.0);
+ const QVector4D v2 = v4 * m;
+
+ QCOMPARE(v1.x(), v2.x());
+ QCOMPARE(v1.y(), v2.y());
+ QCOMPARE(v1.z(), v2.z());
+ }
+ }
+ {
+ // QMatrix4x4 * QPoint
+ const QPoint p(4, 5);
+
+ QT_IGNORE_DEPRECATIONS(const QPoint p1 = m * p;)
+ const QPoint p2 = m.map(p);
+
+ QCOMPARE(p1.x(), p2.x());
+ QCOMPARE(p1.y(), p2.y());
+ }
+ {
+ // QMatrix4x4 * QPointF
+ const QPointF p(4.0f, 5.0f);
+
+ QT_IGNORE_DEPRECATIONS(const QPointF p1 = m * p;)
+ const QPointF p2 = m.map(p);
+
+ QCOMPARE(p1.x(), p2.x());
+ QCOMPARE(p1.y(), p2.y());
+ }
+}
+#endif // QT_DEPRECATED_SINCE(6, 1)
+
QTEST_APPLESS_MAIN(tst_QMatrixNxN)
#include "tst_qmatrixnxn.moc"
diff --git a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt
index fbeb76abdd..205865faba 100644
--- a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt
+++ b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qquaternion.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qquaternion Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qquaternion LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qquaternion
SOURCES
tst_qquaternion.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
index 4229fa1017..8cdc06354e 100644
--- a/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
+++ b/tests/auto/gui/math3d/qquaternion/tst_qquaternion.cpp
@@ -1,30 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QtCore/qmath.h>
@@ -600,7 +577,7 @@ void tst_QQuaternion::multiply_data()
for (float x = -1.0f; x <= 1.0f; x += 0.5f)
for (float y = -1.0f; y <= 1.0f; y += 0.5f)
for (float z = -1.0f; z <= 1.0f; z += 0.5f) {
- QTest::newRow("exhaustive")
+ QTest::addRow("exhaustive: (%.1f, %.1f, %.1f), %.1f", x, y, z, w)
<< x << y << z << w
<< z << w << y << x;
}
@@ -987,28 +964,6 @@ void tst_QQuaternion::rotationTo()
QVERIFY(myFuzzyCompare(vec2, from));
}
-static QByteArray testnameForAxis(const QVector3D &axis)
-{
- QByteArray testname;
- if (axis == QVector3D()) {
- testname = "null";
- } else {
- if (axis.x()) {
- testname += axis.x() < 0 ? '-' : '+';
- testname += 'X';
- }
- if (axis.y()) {
- testname += axis.y() < 0 ? '-' : '+';
- testname += 'Y';
- }
- if (axis.z()) {
- testname += axis.z() < 0 ? '-' : '+';
- testname += 'Z';
- }
- }
- return testname;
-}
-
// Test quaternion convertion to and from orthonormal axes.
void tst_QQuaternion::fromDirection_data()
{
@@ -1031,7 +986,10 @@ void tst_QQuaternion::fromDirection_data()
QVector3D xAxis, yAxis, zAxis;
q.getAxes(&xAxis, &yAxis, &zAxis);
- QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: " + testnameForAxis(yAxis))
+ QTest::addRow("ortho dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)",
+ xAxis.x(), xAxis.y(), xAxis.z(),
+ yAxis.x(), yAxis.y(), yAxis.z(),
+ zAxis.x(), zAxis.y(), zAxis.z())
<< zAxis * 10.0f << yAxis * 10.0f;
}
@@ -1050,7 +1008,10 @@ void tst_QQuaternion::fromDirection_data()
QVector3D xAxis, yAxis, zAxis;
q.getAxes(&xAxis, &yAxis, &zAxis);
- QTest::newRow("dir: " + testnameForAxis(zAxis) + ", up: null")
+ QTest::addRow("bad dirs: (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f), (%.1f,%.1f,%.1f)",
+ xAxis.x(), xAxis.y(), xAxis.z(),
+ yAxis.x(), yAxis.y(), yAxis.z(),
+ zAxis.x(), zAxis.y(), zAxis.z())
<< zAxis * 10.0f << QVector3D();
}
}
@@ -1110,6 +1071,35 @@ void tst_QQuaternion::fromEulerAngles_data()
QTest::newRow("complex")
<< 30.0f << 240.0f << -45.0f << QQuaternion(-0.531976f, -0.43968f, 0.723317f, -0.02226f);
+
+ // Three gimbal_lock cases are not unique for the conversions from quaternion
+ // to euler, Qt will use only XY rotations for these cases.
+ // For example, QQuaternion(0.5f, 0.5f, -0.5f, 0.5f) can be EulerXYZ(90.0f, 0.0f, 90.0f), too.
+ // But Qt will always convert it to EulerXYZ(90.0f, -90.0f, 0.0f) without Z-rotation.
+ QTest::newRow("gimbal_lock_1")
+ << 90.0f << -90.0f << 0.0f << QQuaternion(0.5f, 0.5f, -0.5f, 0.5f);
+
+ QTest::newRow("gimbal_lock_2")
+ << 90.0f << 40.0f << 0.0f << QQuaternion(0.664463f, 0.664463f, 0.241845f, -0.241845f);
+
+ QTest::newRow("gimbal_lock_3") << 90.0f << 170.0f << 0.0f
+ << QQuaternion(0.0616285f, 0.0616285f, 0.704416f, -0.704416f);
+
+ // These four examples have a fraction of errors that would bypass normalize() threshold
+ // and could make Gimbal lock detection fail.
+ QTest::newRow("gimbal_lock_fraction_1")
+ << -90.0f << 90.001152f << 0.0f << QQuaternion(0.499989986f, -0.5f, 0.5f, 0.5f);
+
+ QTest::newRow("gimbal_lock_fraction_2")
+ << -90.0f << -179.999985f << 0.0f
+ << QQuaternion(1.00000001e-07f, 1.00000001e-10f, -0.707106769f, -0.707105756f);
+
+ QTest::newRow("gimbal_lock_fraction_3")
+ << -90.0f << 90.0011597f << 0.0f << QQuaternion(0.499989986f, -0.49999994f, 0.5f, 0.5f);
+
+ QTest::newRow("gimbal_lock_fraction_4")
+ << -90.0f << -180.0f << 0.0f
+ << QQuaternion(9.99999996e-12f, 9.99999996e-12f, -0.707106769f, -0.707096756f);
}
void tst_QQuaternion::fromEulerAngles()
{
diff --git a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt
index c29550463a..5de1ff11e6 100644
--- a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt
+++ b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qvectornd.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qvectornd Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qvectornd LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qvectornd
SOURCES
tst_qvectornd.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
index c7bcb9d262..3272ffac0e 100644
--- a/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
+++ b/tests/auto/gui/math3d/qvectornd/tst_qvectornd.cpp
@@ -1,30 +1,38 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QVector2D>
+#include <QVector3D>
+#include <QVector4D>
+#ifdef QVARIANT_H
+# error "This test requires qvector{2,3,4}d.h to not include qvariant.h"
+#endif
+
+// don't assume <type_traits>
+template <typename T, typename U>
+constexpr inline bool my_is_same_v = false;
+template <typename T>
+constexpr inline bool my_is_same_v<T, T> = true;
+
+#define CHECK(cvref) \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector2D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector2D cvref >())), float cvref >); \
+ \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector3D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector3D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector3D cvref >())), float cvref >); \
+ \
+ static_assert(my_is_same_v<decltype(get<0>(std::declval<QVector4D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<1>(std::declval<QVector4D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<2>(std::declval<QVector4D cvref >())), float cvref >); \
+ static_assert(my_is_same_v<decltype(get<3>(std::declval<QVector4D cvref >())), float cvref >)
+
+CHECK(&);
+CHECK(const &);
+CHECK(&&);
+CHECK(const &&);
+
+#undef CHECK
#include <QTest>
#include <QtCore/qmath.h>
diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt
index 4f933139ca..b49a80b180 100644
--- a/tests/auto/gui/painting/CMakeLists.txt
+++ b/tests/auto/gui/painting/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from painting.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qpainterpath)
add_subdirectory(qpainterpathstroker)
@@ -9,14 +10,18 @@ add_subdirectory(qpagelayout)
add_subdirectory(qpageranges)
add_subdirectory(qpagesize)
add_subdirectory(qpainter)
-add_subdirectory(qpdfwriter)
+if (QT_FEATURE_pdf)
+ add_subdirectory(qpdfwriter)
+endif()
add_subdirectory(qpen)
add_subdirectory(qpaintengine)
add_subdirectory(qtransform)
add_subdirectory(qpolygon)
-# QTBUG-87669 # special case
+
+# QTBUG-87669
if(NOT ANDROID)
add_subdirectory(qcolorspace)
+ add_subdirectory(qcolortransform)
endif()
if(QT_FEATURE_private_tests)
add_subdirectory(qpathclipper)
diff --git a/tests/auto/gui/painting/qbrush/CMakeLists.txt b/tests/auto/gui/painting/qbrush/CMakeLists.txt
index c8dad25d94..313bce20a4 100644
--- a/tests/auto/gui/painting/qbrush/CMakeLists.txt
+++ b/tests/auto/gui/painting/qbrush/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qbrush.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qbrush Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qbrush LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qbrush
SOURCES
tst_qbrush.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
index ea380e3cc9..678c8d9b32 100644
--- a/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
+++ b/tests/auto/gui/painting/qbrush/tst_qbrush.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qcolor/CMakeLists.txt b/tests/auto/gui/painting/qcolor/CMakeLists.txt
index 87753803fb..52e551855c 100644
--- a/tests/auto/gui/painting/qcolor/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolor/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qcolor.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcolor Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcolor LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcolor
SOURCES
tst_qcolor.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
index 5c93a41b71..f592db5544 100644
--- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
+++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -38,6 +13,12 @@
#include <private/qdrawingprimitive_sse2_p.h>
#include <qrgba64.h>
+#if QT_DEPRECATED_SINCE(6, 6)
+# define DEPRECATED_IN_6_6(...) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED __VA_ARGS__ QT_WARNING_POP
+#else
+# define DEPRECATED_IN_6_6(...)
+#endif
+
class tst_QColor : public QObject
{
Q_OBJECT
@@ -54,8 +35,8 @@ private slots:
void name();
void namehex_data();
void namehex();
- void setNamedColor_data();
- void setNamedColor();
+ void fromString_data();
+ void fromString();
void constructNamedColorWithSpace();
@@ -92,7 +73,7 @@ private slots:
void toCmykNonDestructive();
void toHsl_data();
- void toHsl();;
+ void toHsl();
void toHslNonDestructive();
void convertTo();
@@ -243,13 +224,13 @@ void tst_QColor::isValid_data()
QTest::newRow("defaultConstructor") << QColor() << false;
QTest::newRow("rgbConstructor-valid") << QColor(2,5,7) << true;
QTest::newRow("rgbConstructor-invalid") << QColor(2,5,999) << false;
- QTest::newRow("nameQStringConstructor-valid") << QColor(QString("#ffffff")) << true;
- QTest::newRow("nameQStringConstructor-invalid") << QColor(QString("#ffffgg")) << false;
- QTest::newRow("nameQStringConstructor-empty") << QColor(QString("")) << false;
- QTest::newRow("nameQStringConstructor-named") << QColor(QString("red")) << true;
- QTest::newRow("nameCharConstructor-valid") << QColor("#ffffff") << true;
- QTest::newRow("nameCharConstructor-invalid") << QColor("#ffffgg") << false;
- QTest::newRow("nameCharConstructor-invalid-2") << QColor("#fffffg") << false;
+ QTest::newRow("nameQStringConstructor-valid") << QColor::fromString("#ffffff") << true;
+ QTest::newRow("nameQStringConstructor-invalid") << QColor::fromString("#ffffgg") << false;
+ QTest::newRow("nameQStringConstructor-empty") << QColor::fromString("") << false;
+ QTest::newRow("nameQStringConstructor-named") << QColor::fromString("red") << true;
+ QTest::newRow("nameCharConstructor-valid") << QColor::fromString("#ffffff") << true;
+ QTest::newRow("nameCharConstructor-invalid") << QColor::fromString("#ffffgg") << false;
+ QTest::newRow("nameCharConstructor-invalid-2") << QColor::fromString("#fffffg") << false;
}
void tst_QColor::isValid()
@@ -335,7 +316,10 @@ void tst_QColor::namehex()
{
QFETCH(QString, hexcolor);
QFETCH(QColor, color);
+ DEPRECATED_IN_6_6(
QCOMPARE(QColor(hexcolor), color);
+ )
+ QCOMPARE(QColor::fromString(hexcolor), color);
}
void tst_QColor::globalColors_data()
@@ -721,25 +705,36 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);
#undef rgb
-void tst_QColor::setNamedColor_data()
+void tst_QColor::fromString_data()
{
+#if QT_DEPRECATED_SINCE(6, 6)
QTest::addColumn<QColor>("byCtor");
QTest::addColumn<QColor>("bySetNamedColor");
+#endif
+ QTest::addColumn<QColor>("byFromString");
QTest::addColumn<QColor>("expected");
for (const auto e : rgbTbl) {
QColor expected;
expected.setRgba(e.value);
-#define ROW(expr) \
- do { \
- QColor bySetNamedColor; \
- bySetNamedColor.setNamedColor(expr); \
- auto byCtor = QColor(expr); \
- QTest::addRow("%s: %s", e.name, #expr) \
- << byCtor << bySetNamedColor << expected; \
- } while (0) \
- /*end*/
+#define ROW(expr) row(expr, #expr)
+ auto row = [&] (auto expr, const char *exprS) {
+ QT_WARNING_PUSH
+ #if QT_DEPRECATED_SINCE(6, 6)
+ QT_WARNING_DISABLE_DEPRECATED
+ QColor bySetNamedColor;
+ bySetNamedColor.setNamedColor(expr);
+ auto byCtor = QColor(expr);
+ #endif
+ QTest::addRow("%s: %s", e.name, exprS)
+ #if QT_DEPRECATED_SINCE(6, 6)
+ << byCtor << bySetNamedColor
+ #endif
+ << QColor::fromString(expr)
+ << expected;
+ QT_WARNING_POP
+ };
const auto l1 = QLatin1String(e.name);
const auto l1UpperBA = QByteArray(e.name).toUpper();
@@ -766,29 +761,42 @@ void tst_QColor::setNamedColor_data()
}
}
-void tst_QColor::setNamedColor()
+void tst_QColor::fromString()
{
+#if QT_DEPRECATED_SINCE(6, 6)
QFETCH(QColor, byCtor);
QFETCH(QColor, bySetNamedColor);
+#endif
+ QFETCH(QColor, byFromString);
QFETCH(QColor, expected);
+#if QT_DEPRECATED_SINCE(6, 6)
QCOMPARE(byCtor, expected);
QCOMPARE(bySetNamedColor, expected);
+#endif
+ QCOMPARE(byFromString, expected);
}
void tst_QColor::constructNamedColorWithSpace()
{
+ DEPRECATED_IN_6_6(
QColor whiteSmoke("white smoke");
QCOMPARE(whiteSmoke, QColor(245, 245, 245));
+ )
+ QCOMPARE(QColor::fromString("white smoke"), QColorConstants::Svg::whitesmoke);
}
void tst_QColor::colorNames()
{
- QStringList all = QColor::colorNames();
+ const QStringList all = QColor::colorNames();
QCOMPARE(all.size(), rgbTblSize);
for (int i = 0; i < all.size(); ++i)
QCOMPARE(all.at(i), QLatin1String(rgbTbl[i].name));
+ for (const QString &name : all)
+ QVERIFY(QColor::isValidColorName(name));
+ for (const auto &e : rgbTbl)
+ QVERIFY(QColor::isValidColorName(e.name));
}
void tst_QColor::spec()
diff --git a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
index 9e3460d363..383c1bb890 100644
--- a/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
+++ b/tests/auto/gui/painting/qcolorspace/CMakeLists.txt
@@ -1,39 +1,33 @@
-# Generated from qcolorspace.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcolorspace Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcolorspace LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# 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
tst_qcolorspace.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
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}
-)
-
diff --git a/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc
new file mode 100644
index 0000000000..b5a73495bf
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/CGATS001Compat-v2-micro.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc
new file mode 100644
index 0000000000..b96eb68136
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/VideoHD.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc
new file mode 100644
index 0000000000..2187b6786a
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/sGrey-v4.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc b/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc
new file mode 100644
index 0000000000..30da950907
--- /dev/null
+++ b/tests/auto/gui/painting/qcolorspace/resources/sRGB_ICC_v4_Appearance.icc
Binary files differ
diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
index 576885de34..4f366b02db 100644
--- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
+++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -65,7 +40,14 @@ private slots:
void imageConversion64PM();
void imageConversionOverLargerGamut_data();
void imageConversionOverLargerGamut();
-
+ void imageConversionOverLargerGamut2_data();
+ void imageConversionOverLargerGamut2();
+ void imageConversionOverAnyGamutFP_data();
+ void imageConversionOverAnyGamutFP();
+ void imageConversionOverAnyGamutFP2_data();
+ void imageConversionOverAnyGamutFP2();
+ void imageConversionOverNonThreeComponentMatrix_data();
+ void imageConversionOverNonThreeComponentMatrix();
void loadImage();
void primaries();
@@ -84,6 +66,11 @@ private slots:
void transferFunctionTable();
void description();
+ void whitePoint_data();
+ void whitePoint();
+ void setWhitePoint();
+ void grayColorSpace();
+ void grayColorSpaceEffectivelySRgb();
};
tst_QColorSpace::tst_QColorSpace()
@@ -201,15 +188,41 @@ void tst_QColorSpace::fromIccProfile_data()
QTest::addColumn<QString>("testProfile");
QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace");
QTest::addColumn<QColorSpace::TransferFunction>("transferFunction");
+ QTest::addColumn<QColorSpace::TransformModel>("transformModel");
+ QTest::addColumn<QColorSpace::ColorModel>("colorModel");
QTest::addColumn<QString>("description");
QString prefix = QFINDTESTDATA("resources/");
// Read the official sRGB ICCv2 profile:
QTest::newRow("sRGB2014 (ICCv2)") << prefix + "sRGB2014.icc" << QColorSpace::SRgb
- << QColorSpace::TransferFunction::SRgb << QString("sRGB2014");
+ << QColorSpace::TransferFunction::SRgb
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Rgb << QString("sRGB2014");
// My monitor's profile:
QTest::newRow("HP ZR30w (ICCv4)") << prefix + "HP_ZR30w.icc" << QColorSpace::NamedColorSpace(0)
- << QColorSpace::TransferFunction::Gamma << QString("HP Z30i");
+ << QColorSpace::TransferFunction::Gamma
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Rgb << QString("HP Z30i");
+ // A profile to HD TV
+ QTest::newRow("VideoHD") << prefix + "VideoHD.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Rgb << QString("HDTV (Rec. 709)");
+ // sRGB on PCSLab format
+ QTest::newRow("sRGB ICCv4 Appearance") << prefix + "sRGB_ICC_v4_Appearance.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Rgb << QString("sRGB_ICC_v4_Appearance.icc");
+ // Grayscale profile
+ QTest::newRow("sGrey-v4") << prefix + "sGrey-v4.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::SRgb
+ << QColorSpace::TransformModel::ThreeComponentMatrix
+ << QColorSpace::ColorModel::Gray << QString("sGry");
+ // CMYK profile
+ QTest::newRow("CGATS compat") << prefix + "CGATS001Compat-v2-micro.icc" << QColorSpace::NamedColorSpace(0)
+ << QColorSpace::TransferFunction::Custom
+ << QColorSpace::TransformModel::ElementListProcessing
+ << QColorSpace::ColorModel::Cmyk << QString("uCMY");
}
void tst_QColorSpace::fromIccProfile()
@@ -217,10 +230,12 @@ void tst_QColorSpace::fromIccProfile()
QFETCH(QString, testProfile);
QFETCH(QColorSpace::NamedColorSpace, namedColorSpace);
QFETCH(QColorSpace::TransferFunction, transferFunction);
+ QFETCH(QColorSpace::TransformModel, transformModel);
+ QFETCH(QColorSpace::ColorModel, colorModel);
QFETCH(QString, description);
QFile file(testProfile);
- file.open(QIODevice::ReadOnly);
+ QVERIFY(file.open(QIODevice::ReadOnly));
QByteArray iccProfile = file.readAll();
QColorSpace fileColorSpace = QColorSpace::fromIccProfile(iccProfile);
QVERIFY(fileColorSpace.isValid());
@@ -229,7 +244,14 @@ void tst_QColorSpace::fromIccProfile()
QCOMPARE(fileColorSpace, namedColorSpace);
QCOMPARE(fileColorSpace.transferFunction(), transferFunction);
+ QCOMPARE(fileColorSpace.transformModel(), transformModel);
+ QCOMPARE(fileColorSpace.colorModel(), colorModel);
QCOMPARE(fileColorSpace.description(), description);
+
+ QByteArray iccProfile2 = fileColorSpace.iccProfile();
+ QCOMPARE(iccProfile, iccProfile2);
+ QColorSpace fileColorSpace2 = QColorSpace::fromIccProfile(iccProfile2);
+ QCOMPARE(fileColorSpace2, fileColorSpace);
}
void tst_QColorSpace::imageConversion_data()
@@ -240,9 +262,10 @@ void tst_QColorSpace::imageConversion_data()
QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3 << 0;
QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb << 2;
- QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0;
QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb << 2;
+ QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3 << 2;
QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb << 2;
+ QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0;
QTest::newRow("sRGB -> sRGB Linear") << QColorSpace::SRgb << QColorSpace::SRgbLinear << 0;
QTest::newRow("sRGB Linear -> sRGB") << QColorSpace::SRgbLinear << QColorSpace::SRgb << 0;
}
@@ -284,8 +307,9 @@ void tst_QColorSpace::imageConversion()
QCOMPARE(testImage.colorSpace(), QColorSpace(fromColorSpace));
for (int i = 0; i < 256; ++i) {
QRgb p = testImage.pixel(i, 0);
- QVERIFY(qAbs(qRed(p) - qGreen(p)) <= tolerance);
QVERIFY(qAbs(qRed(p) - qBlue(p)) <= tolerance);
+ QVERIFY(qAbs(qRed(p) - qGreen(p)) <= tolerance);
+ QVERIFY(qAbs(qGreen(p) - qBlue(p)) <= tolerance);
QVERIFY((lastRed - qRed(p)) <= (tolerance / 2));
QVERIFY((lastGreen - qGreen(p)) <= (tolerance / 2));
QVERIFY((lastBlue - qBlue(p)) <= (tolerance / 2));
@@ -372,8 +396,10 @@ void tst_QColorSpace::imageConversion64PM()
for (int j = 0; j < 16; ++j) {
int a = j * 15;
- for (int i = 0; i < 256; ++i)
- testImage.setPixel(i, j, qPremultiply(qRgba(i, i, i, a)));
+ for (int i = 0; i < 256; ++i) {
+ QRgba64 color = QRgba64::fromRgba(i, i, i, a);
+ testImage.setPixelColor(i, j, QColor::fromRgba64(color));
+ }
}
testImage.setColorSpace(fromColorSpace);
@@ -412,8 +438,8 @@ void tst_QColorSpace::imageConversion64PM()
for (int i = 0; i < 256; ++i) {
QRgb expected = qPremultiply(qRgba(i, i, i, expectedAlpha));
QRgb p = testImage.pixel(i, j);
- QCOMPARE(qRed(p), qGreen(p));
- QCOMPARE(qRed(p), qBlue(p));
+ QVERIFY(qAbs(qRed(p) - qGreen(p)) <= 1);
+ QVERIFY(qAbs(qRed(p) - qBlue(p)) <= 1);
QCOMPARE(qAlpha(p), expectedAlpha);
QVERIFY((lastRed - qRed(p)) <= 0);
QVERIFY((lastGreen - qGreen(p)) <= 0);
@@ -460,7 +486,7 @@ void tst_QColorSpace::imageConversionOverLargerGamut()
testImage.setColorSpace(csfrom);
for (int y = 0; y < 256; ++y)
for (int x = 0; x < 256; ++x)
- testImage.setPixel(x, y, qRgb(x, y, 0));
+ testImage.setPixel(x, y, qRgb(x, y, qAbs(x - y)));
QImage resultImage = testImage.convertedToColorSpace(csto);
for (int y = 0; y < 256; ++y) {
@@ -489,6 +515,187 @@ void tst_QColorSpace::imageConversionOverLargerGamut()
}
}
+void tst_QColorSpace::imageConversionOverLargerGamut2_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+
+ QTest::newRow("rgbx16x4") << QImage::Format_RGBX16FPx4;
+ QTest::newRow("rgba16x4") << QImage::Format_RGBA16FPx4;
+ QTest::newRow("rgba16x4PM") << QImage::Format_RGBA16FPx4_Premultiplied;
+ QTest::newRow("rgbx32x4") << QImage::Format_RGBX32FPx4;
+ QTest::newRow("rgba32x4") << QImage::Format_RGBA32FPx4;
+ QTest::newRow("rgba32x4PM") << QImage::Format_RGBA32FPx4_Premultiplied;
+}
+
+void tst_QColorSpace::imageConversionOverLargerGamut2()
+{
+ QFETCH(QImage::Format, format);
+
+ QColorSpace csfrom = QColorSpace::DisplayP3;
+ QColorSpace csto = QColorSpace::SRgb;
+
+ QImage testImage(256, 256, format);
+ testImage.setColorSpace(csfrom);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgba(x, y, 16, 255));
+
+ QImage resultImage = testImage.convertedToColorSpace(csto);
+ for (int y = 0; y < 256; ++y) {
+ float lastRed = -256.0f;
+ for (int x = 0; x < 256; ++x) {
+ float pr = resultImage.pixelColor(x, y).redF();
+ QVERIFY(pr >= lastRed);
+ lastRed = pr;
+ }
+ }
+ for (int x = 0; x < 256; ++x) {
+ float lastGreen = -256.0f;
+ for (int y = 0; y < 256; ++y) {
+ float pg = resultImage.pixelColor(x, y).greenF();
+ QVERIFY(pg >= lastGreen);
+ lastGreen = pg;
+ }
+ }
+ // Test colors outside of sRGB are converted to values outside of 0-1 range.
+ QVERIFY(resultImage.pixelColor(255, 0).redF() > 1.0f);
+ QVERIFY(resultImage.pixelColor(255, 0).greenF() < 0.0f);
+ QVERIFY(resultImage.pixelColor(0, 255).redF() < 0.0f);
+ QVERIFY(resultImage.pixelColor(0, 255).greenF() > 1.0f);
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP_data()
+{
+ QTest::addColumn<QColorSpace::NamedColorSpace>("fromColorSpace");
+ QTest::addColumn<QColorSpace::NamedColorSpace>("toColorSpace");
+
+ QTest::newRow("sRGB -> Display-P3") << QColorSpace::SRgb << QColorSpace::DisplayP3;
+ QTest::newRow("sRGB -> Adobe RGB") << QColorSpace::SRgb << QColorSpace::AdobeRgb;
+ QTest::newRow("sRGB -> ProPhoto RGB") << QColorSpace::SRgb << QColorSpace::ProPhotoRgb;
+ QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb;
+ QTest::newRow("Adobe RGB -> Display-P3") << QColorSpace::AdobeRgb << QColorSpace::DisplayP3;
+ QTest::newRow("Adobe RGB -> ProPhoto RGB") << QColorSpace::AdobeRgb << QColorSpace::ProPhotoRgb;
+ QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb;
+ QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb;
+ QTest::newRow("Display-P3 -> ProPhoto RGB") << QColorSpace::DisplayP3 << QColorSpace::ProPhotoRgb;
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP()
+{
+ QFETCH(QColorSpace::NamedColorSpace, fromColorSpace);
+ QFETCH(QColorSpace::NamedColorSpace, toColorSpace);
+
+ QColorSpace csfrom(fromColorSpace);
+ QColorSpace csto(toColorSpace);
+ csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ csto.setTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QImage testImage(256, 256, QImage::Format_RGBX32FPx4);
+ testImage.setColorSpace(csfrom);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(csto);
+ resultImage.convertToColorSpace(csfrom);
+
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y));
+ }
+ }
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP2_data()
+{
+ imageConversionOverAnyGamutFP_data();
+}
+
+void tst_QColorSpace::imageConversionOverAnyGamutFP2()
+{
+ QFETCH(QColorSpace::NamedColorSpace, fromColorSpace);
+ QFETCH(QColorSpace::NamedColorSpace, toColorSpace);
+
+ // Same as imageConversionOverAnyGamutFP but using format switching transform
+ QColorSpace csfrom(fromColorSpace);
+ QColorSpace csto(toColorSpace);
+ csfrom.setTransferFunction(QColorSpace::TransferFunction::Linear);
+ csto.setTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QImage testImage(256, 256, QImage::Format_RGB32);
+ testImage.setColorSpace(csfrom);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(csto, QImage::Format_RGBX32FPx4);
+ resultImage.convertToColorSpace(csfrom, QImage::Format_RGB32);
+
+ for (int y = 0; y < 256; ++y) {
+ for (int x = 0; x < 256; ++x) {
+ QCOMPARE(resultImage.pixel(x, y), testImage.pixel(x, y));
+ }
+ }
+}
+
+void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix_data()
+{
+ QTest::addColumn<QColorSpace>("fromColorSpace");
+ QTest::addColumn<QColorSpace>("toColorSpace");
+
+ QString prefix = QFINDTESTDATA("resources/");
+ QFile file1(prefix + "VideoHD.icc");
+ QFile file2(prefix + "sRGB_ICC_v4_Appearance.icc");
+ QVERIFY(file1.open(QFile::ReadOnly));
+ QVERIFY(file2.open(QFile::ReadOnly));
+ QByteArray iccProfile1 = file1.readAll();
+ QByteArray iccProfile2 = file2.readAll();
+ QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccProfile1);
+ QColorSpace srgbPcsColorSpace = QColorSpace::fromIccProfile(iccProfile2);
+
+ QTest::newRow("sRGB PCSLab -> sRGB") << srgbPcsColorSpace << QColorSpace(QColorSpace::SRgb);
+ QTest::newRow("sRGB -> sRGB PCSLab") << QColorSpace(QColorSpace::SRgb) << srgbPcsColorSpace;
+ QTest::newRow("HDTV -> sRGB") << hdtvColorSpace << QColorSpace(QColorSpace::SRgb);
+ QTest::newRow("sRGB -> HDTV") << QColorSpace(QColorSpace::SRgb) << hdtvColorSpace;
+ QTest::newRow("sRGB PCSLab -> HDTV") << srgbPcsColorSpace << hdtvColorSpace;
+ QTest::newRow("HDTV -> sRGB PCSLab") << hdtvColorSpace << srgbPcsColorSpace;
+}
+
+void tst_QColorSpace::imageConversionOverNonThreeComponentMatrix()
+{
+ QFETCH(QColorSpace, fromColorSpace);
+ QFETCH(QColorSpace, toColorSpace);
+ QVERIFY(fromColorSpace.isValid());
+ QVERIFY(toColorSpace.isValidTarget());
+
+ QVERIFY(!fromColorSpace.transformationToColorSpace(toColorSpace).isIdentity());
+
+ QImage testImage(256, 256, QImage::Format_RGBX64);
+ testImage.setColorSpace(fromColorSpace);
+ for (int y = 0; y < 256; ++y)
+ for (int x = 0; x < 256; ++x)
+ testImage.setPixel(x, y, qRgb(x, y, 0));
+
+ QImage resultImage = testImage.convertedToColorSpace(toColorSpace);
+ QCOMPARE(resultImage.size(), testImage.size());
+ for (int y = 0; y < 256; ++y) {
+ int lastRed = 0;
+ for (int x = 0; x < 256; ++x) {
+ QRgb p = resultImage.pixel(x, y);
+ QVERIFY(qRed(p) >= lastRed);
+ lastRed = qRed(p);
+ }
+ }
+ for (int x = 0; x < 256; ++x) {
+ int lastGreen = 0;
+ for (int y = 0; y < 256; ++y) {
+ QRgb p = resultImage.pixel(x, y);
+ QVERIFY(qGreen(p) >= lastGreen);
+ lastGreen = qGreen(p);
+ }
+ }
+}
+
void tst_QColorSpace::loadImage()
{
QString prefix = QFINDTESTDATA("resources/");
@@ -666,10 +873,28 @@ void tst_QColorSpace::changePrimaries()
cs.setPrimaries(QColorSpace::Primaries::DciP3D65);
QVERIFY(cs.isValid());
QCOMPARE(cs, QColorSpace(QColorSpace::DisplayP3));
+ QCOMPARE(cs.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix);
cs.setTransferFunction(QColorSpace::TransferFunction::Linear);
cs.setPrimaries(QPointF(0.3127, 0.3290), QPointF(0.640, 0.330),
QPointF(0.3000, 0.6000), QPointF(0.150, 0.060));
QCOMPARE(cs, QColorSpace(QColorSpace::SRgbLinear));
+
+
+ QFile iccFile(QFINDTESTDATA("resources/") + "VideoHD.icc");
+ QVERIFY(iccFile.open(QFile::ReadOnly));
+ QByteArray iccData = iccFile.readAll();
+ QColorSpace hdtvColorSpace = QColorSpace::fromIccProfile(iccData);
+ QVERIFY(hdtvColorSpace.isValid());
+ QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ElementListProcessing);
+ QCOMPARE(hdtvColorSpace.primaries(), QColorSpace::Primaries::Custom);
+ QCOMPARE(hdtvColorSpace.transferFunction(), QColorSpace::TransferFunction::Custom);
+ // Unsets both primaries and transferfunction because they were inseparable in element list processing
+ hdtvColorSpace.setPrimaries(QColorSpace::Primaries::SRgb);
+ QVERIFY(!hdtvColorSpace.isValid());
+ hdtvColorSpace.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QVERIFY(hdtvColorSpace.isValid());
+ QCOMPARE(hdtvColorSpace.transformModel(), QColorSpace::TransformModel::ThreeComponentMatrix);
+ QCOMPARE(hdtvColorSpace, QColorSpace(QColorSpace::SRgb));
}
void tst_QColorSpace::transferFunctionTable()
@@ -718,5 +943,92 @@ void tst_QColorSpace::description()
QCOMPARE(srgb.description(), QLatin1String("Linear sRGB")); // Set to empty returns default behavior
}
+void tst_QColorSpace::whitePoint_data()
+{
+ QTest::addColumn<QColorSpace::NamedColorSpace>("namedColorSpace");
+ QTest::addColumn<QPointF>("whitePoint");
+
+ QTest::newRow("sRGB") << QColorSpace::SRgb << QColorVector::D65Chromaticity();
+ QTest::newRow("Adobe RGB") << QColorSpace::AdobeRgb << QColorVector::D65Chromaticity();
+ QTest::newRow("Display-P3") << QColorSpace::DisplayP3 << QColorVector::D65Chromaticity();
+ QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << QColorVector::D50Chromaticity();
+}
+
+void tst_QColorSpace::whitePoint()
+{
+ QFETCH(QColorSpace::NamedColorSpace, namedColorSpace);
+ QFETCH(QPointF, whitePoint);
+
+ QColorSpace colorSpace(namedColorSpace);
+ QPointF wpt = colorSpace.whitePoint();
+ QCOMPARE_LE(qAbs(wpt.x() - whitePoint.x()), 0.0000001);
+ QCOMPARE_LE(qAbs(wpt.y() - whitePoint.y()), 0.0000001);
+}
+
+void tst_QColorSpace::setWhitePoint()
+{
+ QColorSpace colorSpace(QColorSpace::SRgb);
+ colorSpace.setWhitePoint(QPointF(0.33, 0.33));
+ QCOMPARE_NE(colorSpace, QColorSpace(QColorSpace::SRgb));
+ colorSpace.setWhitePoint(QColorVector::D65Chromaticity());
+ // Check our matrix manipulations returned us to where we came from
+ QCOMPARE(colorSpace, QColorSpace(QColorSpace::SRgb));
+}
+
+void tst_QColorSpace::grayColorSpace()
+{
+ QColorSpace spc;
+ QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Undefined);
+ QVERIFY(!spc.isValid());
+ spc.setWhitePoint(QColorVector::D65Chromaticity());
+ spc.setTransferFunction(QColorSpace::TransferFunction::SRgb);
+ QVERIFY(spc.isValid());
+ QCOMPARE(spc.colorModel(), QColorSpace::ColorModel::Gray);
+
+ QColorSpace spc2(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb);
+ QVERIFY(spc2.isValid());
+ QCOMPARE(spc2.colorModel(), QColorSpace::ColorModel::Gray);
+ QCOMPARE(spc, spc2);
+
+ QImage rgbImage(1, 8, QImage::Format_RGB32);
+ QImage grayImage(1, 255, QImage::Format_Grayscale8);
+ // RGB images can not have gray color space
+ rgbImage.setColorSpace(spc2);
+ grayImage.setColorSpace(spc2);
+ QCOMPARE_NE(rgbImage.colorSpace(), spc2);
+ QCOMPARE(grayImage.colorSpace(), spc2);
+ // But gray images can have RGB color space
+ rgbImage.setColorSpace(QColorSpace::SRgb);
+ grayImage.setColorSpace(QColorSpace::SRgb);
+ QCOMPARE(rgbImage.colorSpace(), QColorSpace(QColorSpace::SRgb));
+ QCOMPARE(grayImage.colorSpace(), QColorSpace(QColorSpace::SRgb));
+
+ // While we can not set a grayscale color space on rgb image, we can convert to one
+ QImage grayImage2 = rgbImage.convertedToColorSpace(spc2);
+ QCOMPARE(grayImage2.colorSpace(), spc2);
+ QCOMPARE(grayImage2.format(), QImage::Format_Grayscale8);
+}
+
+void tst_QColorSpace::grayColorSpaceEffectivelySRgb()
+{
+ // Test grayscale colorspace conversion by making a gray color space that should act like sRGB on gray values.
+ QColorSpace sRgb(QColorSpace::SRgb);
+ QColorSpace sRgbGray(QColorVector::D65Chromaticity(), QColorSpace::TransferFunction::SRgb);
+
+ QImage grayImage1(256, 1, QImage::Format_Grayscale8);
+ QImage grayImage2(256, 1, QImage::Format_Grayscale8);
+ for (int i = 0; i < 256; ++i) {
+ grayImage1.bits()[i] = i;
+ grayImage2.bits()[i] = i;
+ }
+ grayImage1.setColorSpace(sRgb);
+ grayImage2.setColorSpace(sRgbGray);
+
+ QImage rgbImage1 = grayImage1.convertedTo(QImage::Format_RGB32);
+ QImage rgbImage2 = grayImage2.convertedToColorSpace(sRgb, QImage::Format_RGB32);
+
+ QCOMPARE(rgbImage1, rgbImage2);
+}
+
QTEST_MAIN(tst_QColorSpace)
#include "tst_qcolorspace.moc"
diff --git a/tests/auto/gui/painting/qcolortransform/CMakeLists.txt b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
new file mode 100644
index 0000000000..4aa4a8bc4a
--- /dev/null
+++ b/tests/auto/gui/painting/qcolortransform/CMakeLists.txt
@@ -0,0 +1,20 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## tst_qcolortransform Test:
+#####################################################################
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcolortransform LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+qt_internal_add_test(tst_qcolortransform
+ SOURCES
+ tst_qcolortransform.cpp
+ LIBRARIES
+ Qt::Gui
+ Qt::GuiPrivate
+)
diff --git a/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
new file mode 100644
index 0000000000..7a976b5f5e
--- /dev/null
+++ b/tests/auto/gui/painting/qcolortransform/tst_qcolortransform.cpp
@@ -0,0 +1,380 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <QTest>
+
+#include <qcolorspace.h>
+#include <qcolortransform.h>
+#include <qrgbafloat.h>
+#include <QtGui/private/qcolortransform_p.h>
+
+class tst_QColorTransform : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QColorTransform();
+
+private slots:
+ void mapRGB32_data();
+ void mapRGB32();
+ void mapRGB64_data();
+ void mapRGB64();
+ void mapRGBAFP16x4_data();
+ void mapRGBAFP16x4();
+ void mapRGBAFP32x4_data();
+ void mapRGBAFP32x4();
+ void mapQColor_data();
+ void mapQColor();
+ void mapRGB32Prepared_data();
+ void mapRGB32Prepared();
+
+ void transformIsIdentity();
+};
+
+tst_QColorTransform::tst_QColorTransform()
+{ }
+
+
+void tst_QColorTransform::mapRGB32_data()
+{
+ QTest::addColumn<QColorTransform>("transform");
+ QTest::addColumn<bool>("sharesRed");
+
+ QColorSpace srgb(QColorSpace::SRgb);
+ QColorSpace srgbLinear(QColorSpace::SRgbLinear);
+ QColorSpace adobeRgb(QColorSpace::AdobeRgb);
+ QColorSpace adobeRgbLinear = adobeRgb.withTransferFunction(QColorSpace::TransferFunction::Linear);
+ QColorSpace dp3(QColorSpace::DisplayP3);
+ QColorSpace dp3Linear = dp3.withTransferFunction(QColorSpace::TransferFunction::Linear);
+
+ QTest::newRow("default") << QColorTransform() << true;
+ QTest::newRow("sRGB to Linear sRGB") << srgb.transformationToColorSpace(srgbLinear) << true;
+ QTest::newRow("AdobeRGB to sRGB") << adobeRgb.transformationToColorSpace(srgb) << true;
+ QTest::newRow("Linear AdobeRGB to AdobeRGB") << adobeRgbLinear.transformationToColorSpace(adobeRgb) << true;
+ QTest::newRow("Linear AdobeRGB to Linear sRGB") << adobeRgbLinear.transformationToColorSpace(srgbLinear) << true;
+ QTest::newRow("sRgb to AdobeRGB") << srgb.transformationToColorSpace(adobeRgb) << true;
+ QTest::newRow("DP3 to sRGB") << dp3.transformationToColorSpace(srgb) << false;
+ QTest::newRow("DP3 to Linear DP3") << dp3.transformationToColorSpace(dp3Linear) << false;
+ QTest::newRow("Linear DP3 to Linear sRGB") << dp3Linear.transformationToColorSpace(srgbLinear) << false;
+}
+
+void tst_QColorTransform::mapRGB32()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+ // Do basic sanity tests of conversions between similar sane color spaces
+
+ QRgb testColor = qRgb(32, 64, 128);
+ QRgb result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(128, 64, 32);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) > qGreen(result));
+ QVERIFY(qGreen(result) > qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgba(15, 31, 63, 128);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 128);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(0, 0, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 0);
+ QCOMPARE(qGreen(result), 0);
+ QCOMPARE(qBlue(result), 0);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 255);
+ QCOMPARE(qGreen(result), 255);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qAlpha(result), 255);
+ if (sharesRed)
+ QCOMPARE(qRed(result), 255);
+
+ testColor = qRgb(0, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+}
+
+void tst_QColorTransform::mapRGB64_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapRGB64()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ QRgba64 testColor = QRgba64::fromRgba(128, 64, 32, 255);
+ QRgba64 result = transform.map(testColor);
+ QVERIFY(result.red() > result.green());
+ QVERIFY(result.green() > result.blue());
+ QCOMPARE(result.alpha(), 0xffff);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = QRgba64::fromRgba64(0, 0, 0, 0xffff);
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = QRgba64::fromRgba64(0xffff, 0xffff, 0xffff, 0xffff);
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = QRgba64::fromRgba64(0xffff, 0xffff, 0, 0xffff);
+ result = transform.map(testColor);
+ QCOMPARE(result.alpha(), 0xffff);
+ if (sharesRed)
+ QCOMPARE(result.red(), 0xffff);
+
+ testColor = QRgba64::fromRgba64(0, 0xffff, 0xffff, 0xffff);
+ result = transform.map(testColor);
+ QCOMPARE(result.blue(), 0xffff);
+ QCOMPARE(result.alpha(), 0xffff);
+}
+
+void tst_QColorTransform::mapRGBAFP16x4_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapRGBAFP16x4()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ QRgbaFloat16 testColor = QRgbaFloat16::fromRgba(128, 64, 32, 255);
+ QRgbaFloat16 result = transform.map(testColor);
+ QVERIFY(result.red() > result.green());
+ QVERIFY(result.green() > result.blue());
+ QCOMPARE(result.alpha(), 1.0f);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = QRgbaFloat16{qfloat16(0.0f), qfloat16(0.0f), qfloat16(0.0f), qfloat16(1.0f)};
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = QRgbaFloat16{qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)};
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = QRgbaFloat16{qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)};
+ result = transform.map(testColor);
+ QCOMPARE(result.alpha(), 1.0f);
+ if (sharesRed)
+ QCOMPARE(result.red(), 1.0f);
+
+ testColor = QRgbaFloat16{qfloat16(0.0f), qfloat16(1.0f), qfloat16(1.0f), qfloat16(1.0f)};
+ result = transform.map(testColor);
+ // QRgbaFloat16 might overflow blue if we convert to a smaller gamut:
+ QCOMPARE(result.blue16(), 65535);
+ QCOMPARE(result.alpha(), 1.0f);
+}
+
+void tst_QColorTransform::mapRGBAFP32x4_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapRGBAFP32x4()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ QRgbaFloat32 testColor = QRgbaFloat32::fromRgba(128, 64, 32, 255);
+ QRgbaFloat32 result = transform.map(testColor);
+ QVERIFY(result.red() > result.green());
+ QVERIFY(result.green() > result.blue());
+ QCOMPARE(result.alpha(), 1.0f);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = QRgbaFloat32{0.0f, 0.0f, 0.0f, 1.0f};
+ result = transform.map(testColor);
+ QCOMPARE(result.red(), 0.0f);
+ QCOMPARE(result.green(), 0.0f);
+ QCOMPARE(result.blue(), 0.0f);
+ QCOMPARE(result.alpha(), 1.0f);
+
+ testColor = QRgbaFloat32{1.0f, 1.0f, 1.0f, 1.0f};
+ result = transform.map(testColor);
+ QCOMPARE(result.red(), 1.0f);
+ QCOMPARE(result.green(), 1.0f);
+ QCOMPARE(result.blue(), 1.0f);
+ QCOMPARE(result.alpha(), 1.0f);
+
+ testColor = QRgbaFloat32{1.0f, 1.0f, 0.0f, 1.0f};
+ result = transform.map(testColor);
+ QCOMPARE(result.alpha(), 1.0f);
+ if (sharesRed)
+ QCOMPARE(result.red(), 1.0f);
+
+ testColor = QRgbaFloat32{0.0f, 1.0f, 1.0f, 1.0f};
+ result = transform.map(testColor);
+ // QRgbaFloat16 might overflow blue if we convert to a smaller gamut:
+ QCOMPARE(result.blue16(), 65535);
+ QCOMPARE(result.alpha(), 1.0f);
+}
+
+void tst_QColorTransform::mapQColor_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapQColor()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ QColor testColor(32, 64, 128);
+ QColor result = transform.map(testColor);
+ QVERIFY(result.redF() < result.greenF());
+ QVERIFY(result.greenF() < result.blueF());
+ QCOMPARE(result.alphaF(), 1.0f);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = Qt::black;
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = Qt::white;
+ result = transform.map(testColor);
+ QCOMPARE(result, testColor);
+
+ testColor = QColor(255, 255, 0);
+ result = transform.map(testColor);
+ QCOMPARE(result.alphaF(), 1);
+ if (sharesRed)
+ QVERIFY(result.redF() >= 1.0f);
+
+ testColor = QColor(0, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(result.alphaF(), 1.0f);
+ QVERIFY(result.blueF() >= 1.0f);
+}
+
+void tst_QColorTransform::mapRGB32Prepared_data()
+{
+ mapRGB32_data();
+}
+
+void tst_QColorTransform::mapRGB32Prepared()
+{
+ QFETCH(QColorTransform, transform);
+ QFETCH(bool, sharesRed);
+
+ // The same tests as mapRGB32 but prepared, to use the LUT code-paths
+ if (!transform.isIdentity())
+ QColorTransformPrivate::get(transform)->prepare();
+
+ QRgb testColor = qRgb(32, 64, 128);
+ QRgb result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(128, 64, 32);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) > qGreen(result));
+ QVERIFY(qGreen(result) > qBlue(result));
+ QCOMPARE(qAlpha(result), 255);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgba(15, 31, 63, 128);
+ result = transform.map(testColor);
+ QVERIFY(qRed(result) < qGreen(result));
+ QVERIFY(qGreen(result) < qBlue(result));
+ QCOMPARE(qAlpha(result), 128);
+ if (transform.isIdentity())
+ QVERIFY(result == testColor);
+ else
+ QVERIFY(result != testColor);
+
+ testColor = qRgb(0, 0, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 0);
+ QCOMPARE(qGreen(result), 0);
+ QCOMPARE(qBlue(result), 0);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qRed(result), 255);
+ QCOMPARE(qGreen(result), 255);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+
+ testColor = qRgb(255, 255, 0);
+ result = transform.map(testColor);
+ QCOMPARE(qAlpha(result), 255);
+ if (sharesRed)
+ QCOMPARE(qRed(result), 255);
+
+ testColor = qRgb(0, 255, 255);
+ result = transform.map(testColor);
+ QCOMPARE(qBlue(result), 255);
+ QCOMPARE(qAlpha(result), 255);
+}
+
+void tst_QColorTransform::transformIsIdentity()
+{
+ QColorTransform ct;
+ QVERIFY(ct.isIdentity());
+
+ QColorSpace cs = QColorSpace::SRgb;
+ ct = cs.transformationToColorSpace(QColorSpace::SRgb);
+ QVERIFY(ct.isIdentity());
+
+ ct = cs.transformationToColorSpace(QColorSpace::SRgbLinear);
+ QVERIFY(!ct.isIdentity());
+
+ ct = cs.withTransferFunction(QColorSpace::TransferFunction::Linear).transformationToColorSpace(QColorSpace::SRgbLinear);
+ QVERIFY(ct.isIdentity());
+}
+
+QTEST_MAIN(tst_QColorTransform)
+#include "tst_qcolortransform.moc"
diff --git a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
index 913619461e..b19568592b 100644
--- a/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpagelayout/CMakeLists.txt
@@ -1,15 +1,22 @@
-# Generated from qpagelayout.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpagelayout Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpagelayout LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpagelayout
SOURCES
tst_qpagelayout.cpp
DEFINES
QT_USE_USING_NAMESPACE
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
index 830e0cd16c..cbbf857357 100644
--- a/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
+++ b/tests/auto/gui/painting/qpagelayout/tst_qpagelayout.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 John Layt <jlayt@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2014 John Layt <jlayt@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/qpagelayout.h>
@@ -37,6 +12,8 @@ private slots:
void invalid();
void basics();
void setGetMargins();
+ void setUnits_data();
+ void setUnits();
};
void tst_QPageLayout::invalid()
@@ -113,12 +90,14 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.margins(QPageLayout::Millimeter), QMarginsF(3.53, 3.53, 3.53, 3.53));
QCOMPARE(tenpoint.marginsPoints(), QMargins(10, 10, 10, 10));
QCOMPARE(tenpoint.marginsPixels(72), QMargins(10, 10, 10, 10));
+ QCOMPARE(tenpoint.marginsPixels(600), QMargins(83, 83, 83, 83));
QCOMPARE(tenpoint.minimumMargins(), QMarginsF(0, 0, 0, 0));
QCOMPARE(tenpoint.maximumMargins(), QMarginsF(595, 842, 595, 842));
QCOMPARE(tenpoint.fullRect(), QRectF(0, 0, 595, 842));
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 595, 842));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 4958, 7016));
QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 575, 822));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 202.94, 289.94));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).x(), 3.53);
@@ -131,6 +110,7 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter).bottom(), 293.47);
QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 575, 822));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 575, 822));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 4792, 6850));
// Change orientation
tenpoint.setOrientation(QPageLayout::Landscape);
@@ -142,10 +122,12 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958));
QCOMPARE(tenpoint.paintRect(), QRectF(10, 10, 822, 575));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(3.53, 3.53, 289.94, 202.94));
QCOMPARE(tenpoint.paintRectPoints(), QRect(10, 10, 822, 575));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(10, 10, 822, 575));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(83, 83, 6850, 4792));
// Change mode
QCOMPARE(tenpoint.mode(), QPageLayout::StandardMode);
@@ -159,10 +141,77 @@ void tst_QPageLayout::basics()
QCOMPARE(tenpoint.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.fullRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.fullRectPixels(600), QRect(0, 0, 7016, 4958));
QCOMPARE(tenpoint.paintRect(), QRectF(0, 0, 842, 595));
QCOMPARE(tenpoint.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
QCOMPARE(tenpoint.paintRectPoints(), QRect(0, 0, 842, 595));
QCOMPARE(tenpoint.paintRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(tenpoint.paintRectPixels(600), QRect(0, 0, 7016, 4958));
+
+ // A4, 8.4pt margins
+ QPageLayout fraction = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.isValid(), true);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.margins(QPageLayout::Millimeter), QMarginsF(2.96, 2.96, 2.96, 2.96));
+ QCOMPARE(fraction.marginsPoints(), QMarginsF(8, 8, 8, 8));
+ QCOMPARE(fraction.marginsPixels(72), QMargins(8, 8, 8, 8));
+ QCOMPARE(fraction.marginsPixels(600), QMargins(70, 70, 70, 70));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(595, 842, 595, 842));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 210, 297));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 4958, 7016));
+ QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 578.2, 825.2));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 204.08, 291.08));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).x(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).y(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).width(), 204.08);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).height(), 291.08);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).left(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).right(), 207.04);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).top(), 2.96);
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter).bottom(), 294.04);
+ QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 579, 826));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 579, 826));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 4818, 6876));
+
+ // Change orientation
+ fraction.setOrientation(QPageLayout::Landscape);
+ QCOMPARE(fraction.orientation(), QPageLayout::Landscape);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958));
+ QCOMPARE(fraction.paintRect(), QRectF(8.4, 8.4, 825.2, 578.2));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(2.96, 2.96, 291.08, 204.08));
+ QCOMPARE(fraction.paintRectPoints(), QRect(8, 8, 826, 579));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(8, 8, 826, 579));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(70, 70, 6876, 4818));
+
+ // Change mode
+ QCOMPARE(fraction.mode(), QPageLayout::StandardMode);
+ fraction.setMode(QPageLayout::FullPageMode);
+ QCOMPARE(fraction.mode(), QPageLayout::FullPageMode);
+ QCOMPARE(fraction.orientation(), QPageLayout::Landscape);
+ QCOMPARE(fraction.margins(), QMarginsF(8.4, 8.4, 8.4, 8.4));
+ QCOMPARE(fraction.minimumMargins(), QMarginsF(0, 0, 0, 0));
+ QCOMPARE(fraction.maximumMargins(), QMarginsF(842, 595, 842, 595));
+ QCOMPARE(fraction.fullRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.fullRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.fullRectPixels(600), QRect(0, 0, 7016, 4958));
+ QCOMPARE(fraction.paintRect(), QRectF(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRect(QPageLayout::Millimeter), QRectF(0, 0, 297, 210));
+ QCOMPARE(fraction.paintRectPoints(), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRectPixels(72), QRect(0, 0, 842, 595));
+ QCOMPARE(fraction.paintRectPixels(600), QRect(0, 0, 7016, 4958));
}
void tst_QPageLayout::setGetMargins()
@@ -263,6 +312,54 @@ void tst_QPageLayout::setGetMargins()
QCOMPARE(fullPage.maximumMargins(), max);
}
+void tst_QPageLayout::setUnits_data()
+{
+ QTest::addColumn<QPageLayout::Unit>("units");
+ QTest::newRow("Millimeter") << QPageLayout::Millimeter;
+ QTest::newRow("Point") << QPageLayout::Point;
+ QTest::newRow("Inch") << QPageLayout::Inch;
+ QTest::newRow("Pica") << QPageLayout::Pica;
+ QTest::newRow("Didot") << QPageLayout::Didot;
+ QTest::newRow("Cicero") << QPageLayout::Cicero;
+}
+
+void tst_QPageLayout::setUnits()
+{
+ QFETCH(QPageLayout::Unit, units);
+ QPageLayout pageLayout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(), units);
+ int maxLeftX100 = qFloor(pageLayout.maximumMargins().left() * 100);
+ QVERIFY(maxLeftX100 > 0);
+ for (int i = 1; i <= maxLeftX100; ++i) {
+ const qreal margin = i / 100.;
+ const QMarginsF unitsMargins = QMarginsF(margin, margin, margin, margin);
+ pageLayout.setMargins(unitsMargins);
+ pageLayout.setUnits(QPageLayout::Point);
+ const QMarginsF pointsMargins = pageLayout.margins();
+ if (units == QPageLayout::Point) {
+ QCOMPARE(pointsMargins, unitsMargins);
+ } else {
+ QCOMPARE_GT(pointsMargins.left(), unitsMargins.left());
+ QCOMPARE_GT(pointsMargins.top(), unitsMargins.top());
+ QCOMPARE_GT(pointsMargins.right(), unitsMargins.right());
+ QCOMPARE_GT(pointsMargins.bottom(), unitsMargins.bottom());
+ }
+ pageLayout.setUnits(units);
+ const QMarginsF convertedUnitsMargins = pageLayout.margins();
+ if (units == QPageLayout::Didot) {
+ // When using Didot units, the small multiplier and ceiling function in conversion
+ // may cause the converted units to not match the original exactly. However, we
+ // can verify that the converted margins are always greater than or equal to the
+ // original.
+ QCOMPARE_GE(convertedUnitsMargins.left(), unitsMargins.left());
+ QCOMPARE_GE(convertedUnitsMargins.top(), unitsMargins.top());
+ QCOMPARE_GE(convertedUnitsMargins.right(), unitsMargins.right());
+ QCOMPARE_GE(convertedUnitsMargins.bottom(), unitsMargins.bottom());
+ } else {
+ QCOMPARE(convertedUnitsMargins, unitsMargins);
+ }
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QPageLayout)
#include "tst_qpagelayout.moc"
diff --git a/tests/auto/gui/painting/qpageranges/CMakeLists.txt b/tests/auto/gui/painting/qpageranges/CMakeLists.txt
index 660d4b4336..99ab477eae 100644
--- a/tests/auto/gui/painting/qpageranges/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpageranges/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qpageranges.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpageranges Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpageranges LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpageranges
SOURCES
tst_qpageranges.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
index 4912aa43c1..d2dbf990e3 100644
--- a/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
+++ b/tests/auto/gui/painting/qpageranges/tst_qpageranges.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qpageranges.h>
@@ -95,7 +70,7 @@ void tst_QPageRanges::addPage()
QFETCH(PageRangeList, expected);
QPageRanges result;
- for (int pageNumber : qAsConst(pageNumbers)) {
+ for (int pageNumber : std::as_const(pageNumbers)) {
if (QByteArrayView(QTest::currentDataTag()) == "invalid")
QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addPage: 'pageNumber' must be greater than 0");
result.addPage(pageNumber);
@@ -137,7 +112,7 @@ void tst_QPageRanges::addRange()
QFETCH(PageRangeList, expected);
QPageRanges result;
- for (const auto &range : qAsConst(ranges)) {
+ for (const auto &range : std::as_const(ranges)) {
const QByteArrayView testdata(QTest::currentDataTag());
if (testdata.startsWith("invalid"))
QTest::ignoreMessage(QtWarningMsg, "QPageRanges::addRange: 'from' and 'to' must be greater than 0");
diff --git a/tests/auto/gui/painting/qpagesize/CMakeLists.txt b/tests/auto/gui/painting/qpagesize/CMakeLists.txt
index fc6fd931c2..b16cd2714a 100644
--- a/tests/auto/gui/painting/qpagesize/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpagesize/CMakeLists.txt
@@ -1,14 +1,21 @@
-# Generated from qpagesize.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpagesize Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpagesize LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpagesize
SOURCES
tst_qpagesize.cpp
DEFINES
QT_USE_USING_NAMESPACE
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
index 838f7e59cd..de9b799902 100644
--- a/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
+++ b/tests/auto/gui/painting/qpagesize/tst_qpagesize.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGlobal>
@@ -74,11 +49,13 @@ void tst_QPageSize::basics()
QCOMPARE(a4.size(QPageSize::Pica), QSizeF(49.58, 70.17));
QCOMPARE(a4.sizePoints(), QSize(595, 842));
QCOMPARE(a4.sizePixels(72), QSize(595, 842));
+ QCOMPARE(a4.sizePixels(600), QSize(4958, 7016)); // Rounded down
QCOMPARE(a4.rect(QPageSize::Millimeter), QRectF(0, 0, 210, 297));
QCOMPARE(a4.rect(QPageSize::Inch), QRectF(0, 0, 8.27, 11.69));
QCOMPARE(a4.rect(QPageSize::Pica), QRectF(0, 0, 49.58, 70.17));
QCOMPARE(a4.rectPoints(), QRect(0, 0, 595, 842));
QCOMPARE(a4.rectPixels(72), QRect(0, 0, 595, 842));
+ QCOMPARE(a4.rectPixels(600), QRect(0, 0, 4958, 7016)); // Rounded down
// Simple QPageSize::PaperSizeId later in list
QPageSize folio = QPageSize(QPageSize::Folio);
diff --git a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
index b843135645..4cd0151a01 100644
--- a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpaintengine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpaintengine Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpaintengine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpaintengine
SOURCES
tst_qpaintengine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
index 4363799702..02441de54c 100644
--- a/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
+++ b/tests/auto/gui/painting/qpaintengine/tst_qpaintengine.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpainter/CMakeLists.txt b/tests/auto/gui/painting/qpainter/CMakeLists.txt
index 9466dddadd..261e1eb2cf 100644
--- a/tests/auto/gui/painting/qpainter/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainter/CMakeLists.txt
@@ -1,9 +1,16 @@
-# Generated from qpainter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpainter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpainter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
@@ -26,7 +33,7 @@ list(APPEND test_data "task217400.png")
qt_internal_add_test(tst_qpainter
SOURCES
tst_qpainter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
@@ -37,202 +44,7 @@ qt_internal_add_test(tst_qpainter
#####################################################################
qt_internal_extend_target(tst_qpainter CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
Qt::WidgetsPrivate
)
-
-if(ANDROID)
- # Resources:
- set(testdata_resource_files
- "drawEllipse/10x10SizeAt0x0.png"
- "drawEllipse/10x10SizeAt100x100.png"
- "drawEllipse/10x10SizeAt200x200.png"
- "drawEllipse/13x100SizeAt0x0.png"
- "drawEllipse/13x100SizeAt100x100.png"
- "drawEllipse/13x100SizeAt200x200.png"
- "drawEllipse/200x200SizeAt0x0.png"
- "drawEllipse/200x200SizeAt100x100.png"
- "drawEllipse/200x200SizeAt200x200.png"
- "drawLine_rop_bitmap/dst.xbm"
- "drawLine_rop_bitmap/res/res_AndNotROP.xbm"
- "drawLine_rop_bitmap/res/res_AndROP.xbm"
- "drawLine_rop_bitmap/res/res_ClearROP.xbm"
- "drawLine_rop_bitmap/res/res_CopyROP.xbm"
- "drawLine_rop_bitmap/res/res_NandROP.xbm"
- "drawLine_rop_bitmap/res/res_NopROP.xbm"
- "drawLine_rop_bitmap/res/res_NorROP.xbm"
- "drawLine_rop_bitmap/res/res_NotAndROP.xbm"
- "drawLine_rop_bitmap/res/res_NotCopyROP.xbm"
- "drawLine_rop_bitmap/res/res_NotOrROP.xbm"
- "drawLine_rop_bitmap/res/res_NotROP.xbm"
- "drawLine_rop_bitmap/res/res_NotXorROP.xbm"
- "drawLine_rop_bitmap/res/res_OrNotROP.xbm"
- "drawLine_rop_bitmap/res/res_OrROP.xbm"
- "drawLine_rop_bitmap/res/res_SetROP.xbm"
- "drawLine_rop_bitmap/res/res_XorROP.xbm"
- "drawPixmap_rop/dst1.png"
- "drawPixmap_rop/dst2.png"
- "drawPixmap_rop/dst3.png"
- "drawPixmap_rop/res/res_AndNotROP0.png"
- "drawPixmap_rop/res/res_AndNotROP1.png"
- "drawPixmap_rop/res/res_AndNotROP2.png"
- "drawPixmap_rop/res/res_AndNotROP3.png"
- "drawPixmap_rop/res/res_AndNotROP4.png"
- "drawPixmap_rop/res/res_AndNotROP5.png"
- "drawPixmap_rop/res/res_AndNotROP6.png"
- "drawPixmap_rop/res/res_AndNotROP7.png"
- "drawPixmap_rop/res/res_AndROP0.png"
- "drawPixmap_rop/res/res_AndROP1.png"
- "drawPixmap_rop/res/res_AndROP2.png"
- "drawPixmap_rop/res/res_AndROP3.png"
- "drawPixmap_rop/res/res_AndROP4.png"
- "drawPixmap_rop/res/res_AndROP5.png"
- "drawPixmap_rop/res/res_AndROP6.png"
- "drawPixmap_rop/res/res_AndROP7.png"
- "drawPixmap_rop/res/res_ClearROP0.png"
- "drawPixmap_rop/res/res_ClearROP1.png"
- "drawPixmap_rop/res/res_ClearROP2.png"
- "drawPixmap_rop/res/res_ClearROP3.png"
- "drawPixmap_rop/res/res_ClearROP4.png"
- "drawPixmap_rop/res/res_ClearROP5.png"
- "drawPixmap_rop/res/res_ClearROP6.png"
- "drawPixmap_rop/res/res_ClearROP7.png"
- "drawPixmap_rop/res/res_CopyROP0.png"
- "drawPixmap_rop/res/res_CopyROP1.png"
- "drawPixmap_rop/res/res_CopyROP2.png"
- "drawPixmap_rop/res/res_CopyROP3.png"
- "drawPixmap_rop/res/res_CopyROP4.png"
- "drawPixmap_rop/res/res_CopyROP5.png"
- "drawPixmap_rop/res/res_CopyROP6.png"
- "drawPixmap_rop/res/res_CopyROP7.png"
- "drawPixmap_rop/res/res_NandROP0.png"
- "drawPixmap_rop/res/res_NandROP1.png"
- "drawPixmap_rop/res/res_NandROP2.png"
- "drawPixmap_rop/res/res_NandROP3.png"
- "drawPixmap_rop/res/res_NandROP4.png"
- "drawPixmap_rop/res/res_NandROP5.png"
- "drawPixmap_rop/res/res_NandROP6.png"
- "drawPixmap_rop/res/res_NandROP7.png"
- "drawPixmap_rop/res/res_NopROP0.png"
- "drawPixmap_rop/res/res_NopROP1.png"
- "drawPixmap_rop/res/res_NopROP2.png"
- "drawPixmap_rop/res/res_NopROP3.png"
- "drawPixmap_rop/res/res_NopROP4.png"
- "drawPixmap_rop/res/res_NopROP5.png"
- "drawPixmap_rop/res/res_NopROP6.png"
- "drawPixmap_rop/res/res_NopROP7.png"
- "drawPixmap_rop/res/res_NorROP0.png"
- "drawPixmap_rop/res/res_NorROP1.png"
- "drawPixmap_rop/res/res_NorROP2.png"
- "drawPixmap_rop/res/res_NorROP3.png"
- "drawPixmap_rop/res/res_NorROP4.png"
- "drawPixmap_rop/res/res_NorROP5.png"
- "drawPixmap_rop/res/res_NorROP6.png"
- "drawPixmap_rop/res/res_NorROP7.png"
- "drawPixmap_rop/res/res_NotAndROP0.png"
- "drawPixmap_rop/res/res_NotAndROP1.png"
- "drawPixmap_rop/res/res_NotAndROP2.png"
- "drawPixmap_rop/res/res_NotAndROP3.png"
- "drawPixmap_rop/res/res_NotAndROP4.png"
- "drawPixmap_rop/res/res_NotAndROP5.png"
- "drawPixmap_rop/res/res_NotAndROP6.png"
- "drawPixmap_rop/res/res_NotAndROP7.png"
- "drawPixmap_rop/res/res_NotCopyROP0.png"
- "drawPixmap_rop/res/res_NotCopyROP1.png"
- "drawPixmap_rop/res/res_NotCopyROP2.png"
- "drawPixmap_rop/res/res_NotCopyROP3.png"
- "drawPixmap_rop/res/res_NotCopyROP4.png"
- "drawPixmap_rop/res/res_NotCopyROP5.png"
- "drawPixmap_rop/res/res_NotCopyROP6.png"
- "drawPixmap_rop/res/res_NotCopyROP7.png"
- "drawPixmap_rop/res/res_NotOrROP0.png"
- "drawPixmap_rop/res/res_NotOrROP1.png"
- "drawPixmap_rop/res/res_NotOrROP2.png"
- "drawPixmap_rop/res/res_NotOrROP3.png"
- "drawPixmap_rop/res/res_NotOrROP4.png"
- "drawPixmap_rop/res/res_NotOrROP5.png"
- "drawPixmap_rop/res/res_NotOrROP6.png"
- "drawPixmap_rop/res/res_NotOrROP7.png"
- "drawPixmap_rop/res/res_NotROP0.png"
- "drawPixmap_rop/res/res_NotROP1.png"
- "drawPixmap_rop/res/res_NotROP2.png"
- "drawPixmap_rop/res/res_NotROP3.png"
- "drawPixmap_rop/res/res_NotROP4.png"
- "drawPixmap_rop/res/res_NotROP5.png"
- "drawPixmap_rop/res/res_NotROP6.png"
- "drawPixmap_rop/res/res_NotROP7.png"
- "drawPixmap_rop/res/res_NotXorROP0.png"
- "drawPixmap_rop/res/res_NotXorROP1.png"
- "drawPixmap_rop/res/res_NotXorROP2.png"
- "drawPixmap_rop/res/res_NotXorROP3.png"
- "drawPixmap_rop/res/res_NotXorROP4.png"
- "drawPixmap_rop/res/res_NotXorROP5.png"
- "drawPixmap_rop/res/res_NotXorROP6.png"
- "drawPixmap_rop/res/res_NotXorROP7.png"
- "drawPixmap_rop/res/res_OrNotROP0.png"
- "drawPixmap_rop/res/res_OrNotROP1.png"
- "drawPixmap_rop/res/res_OrNotROP2.png"
- "drawPixmap_rop/res/res_OrNotROP3.png"
- "drawPixmap_rop/res/res_OrNotROP4.png"
- "drawPixmap_rop/res/res_OrNotROP5.png"
- "drawPixmap_rop/res/res_OrNotROP6.png"
- "drawPixmap_rop/res/res_OrNotROP7.png"
- "drawPixmap_rop/res/res_OrROP0.png"
- "drawPixmap_rop/res/res_OrROP1.png"
- "drawPixmap_rop/res/res_OrROP2.png"
- "drawPixmap_rop/res/res_OrROP3.png"
- "drawPixmap_rop/res/res_OrROP4.png"
- "drawPixmap_rop/res/res_OrROP5.png"
- "drawPixmap_rop/res/res_OrROP6.png"
- "drawPixmap_rop/res/res_OrROP7.png"
- "drawPixmap_rop/res/res_SetROP0.png"
- "drawPixmap_rop/res/res_SetROP1.png"
- "drawPixmap_rop/res/res_SetROP2.png"
- "drawPixmap_rop/res/res_SetROP3.png"
- "drawPixmap_rop/res/res_SetROP4.png"
- "drawPixmap_rop/res/res_SetROP5.png"
- "drawPixmap_rop/res/res_SetROP6.png"
- "drawPixmap_rop/res/res_SetROP7.png"
- "drawPixmap_rop/res/res_XorROP0.png"
- "drawPixmap_rop/res/res_XorROP1.png"
- "drawPixmap_rop/res/res_XorROP2.png"
- "drawPixmap_rop/res/res_XorROP3.png"
- "drawPixmap_rop/res/res_XorROP4.png"
- "drawPixmap_rop/res/res_XorROP5.png"
- "drawPixmap_rop/res/res_XorROP6.png"
- "drawPixmap_rop/res/res_XorROP7.png"
- "drawPixmap_rop/src1.xbm"
- "drawPixmap_rop/src2-mask.xbm"
- "drawPixmap_rop/src2.xbm"
- "drawPixmap_rop/src3.xbm"
- "drawPixmap_rop_bitmap/dst.xbm"
- "drawPixmap_rop_bitmap/res/res_AndNotROP.xbm"
- "drawPixmap_rop_bitmap/res/res_AndROP.xbm"
- "drawPixmap_rop_bitmap/res/res_ClearROP.xbm"
- "drawPixmap_rop_bitmap/res/res_CopyROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NandROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NopROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NorROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NotAndROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NotCopyROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NotOrROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NotROP.xbm"
- "drawPixmap_rop_bitmap/res/res_NotXorROP.xbm"
- "drawPixmap_rop_bitmap/res/res_OrNotROP.xbm"
- "drawPixmap_rop_bitmap/res/res_OrROP.xbm"
- "drawPixmap_rop_bitmap/res/res_SetROP.xbm"
- "drawPixmap_rop_bitmap/res/res_XorROP.xbm"
- "drawPixmap_rop_bitmap/src1-mask.xbm"
- "drawPixmap_rop_bitmap/src1.xbm"
- "drawPixmap_rop_bitmap/src2.xbm"
- "task217400.png"
- )
-
- qt_internal_add_resource(tst_qpainter "testdata"
- PREFIX
- "/"
- FILES
- ${testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/painting/qpainter/testdata.qrc b/tests/auto/gui/painting/qpainter/testdata.qrc
deleted file mode 100644
index a7b8c222e5..0000000000
--- a/tests/auto/gui/painting/qpainter/testdata.qrc
+++ /dev/null
@@ -1,186 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>task217400.png</file>
- <file>drawEllipse/10x10SizeAt0x0.png</file>
- <file>drawEllipse/10x10SizeAt100x100.png</file>
- <file>drawEllipse/10x10SizeAt200x200.png</file>
- <file>drawEllipse/13x100SizeAt0x0.png</file>
- <file>drawEllipse/13x100SizeAt100x100.png</file>
- <file>drawEllipse/13x100SizeAt200x200.png</file>
- <file>drawEllipse/200x200SizeAt0x0.png</file>
- <file>drawEllipse/200x200SizeAt100x100.png</file>
- <file>drawEllipse/200x200SizeAt200x200.png</file>
- <file>drawLine_rop_bitmap/dst.xbm</file>
- <file>drawLine_rop_bitmap/res/res_AndNotROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_AndROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_ClearROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_CopyROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NandROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NopROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NorROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NotAndROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NotCopyROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NotOrROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NotROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_NotXorROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_OrNotROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_OrROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_SetROP.xbm</file>
- <file>drawLine_rop_bitmap/res/res_XorROP.xbm</file>
- <file>drawPixmap_rop/dst1.png</file>
- <file>drawPixmap_rop/dst2.png</file>
- <file>drawPixmap_rop/dst3.png</file>
- <file>drawPixmap_rop/src1.xbm</file>
- <file>drawPixmap_rop/src2-mask.xbm</file>
- <file>drawPixmap_rop/src2.xbm</file>
- <file>drawPixmap_rop/src3.xbm</file>
- <file>drawPixmap_rop/res/res_AndNotROP0.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP1.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP2.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP3.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP4.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP5.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP6.png</file>
- <file>drawPixmap_rop/res/res_AndNotROP7.png</file>
- <file>drawPixmap_rop/res/res_AndROP0.png</file>
- <file>drawPixmap_rop/res/res_AndROP1.png</file>
- <file>drawPixmap_rop/res/res_AndROP2.png</file>
- <file>drawPixmap_rop/res/res_AndROP3.png</file>
- <file>drawPixmap_rop/res/res_AndROP4.png</file>
- <file>drawPixmap_rop/res/res_AndROP5.png</file>
- <file>drawPixmap_rop/res/res_AndROP6.png</file>
- <file>drawPixmap_rop/res/res_AndROP7.png</file>
- <file>drawPixmap_rop/res/res_ClearROP0.png</file>
- <file>drawPixmap_rop/res/res_ClearROP1.png</file>
- <file>drawPixmap_rop/res/res_ClearROP2.png</file>
- <file>drawPixmap_rop/res/res_ClearROP3.png</file>
- <file>drawPixmap_rop/res/res_ClearROP4.png</file>
- <file>drawPixmap_rop/res/res_ClearROP5.png</file>
- <file>drawPixmap_rop/res/res_ClearROP6.png</file>
- <file>drawPixmap_rop/res/res_ClearROP7.png</file>
- <file>drawPixmap_rop/res/res_CopyROP0.png</file>
- <file>drawPixmap_rop/res/res_CopyROP1.png</file>
- <file>drawPixmap_rop/res/res_CopyROP2.png</file>
- <file>drawPixmap_rop/res/res_CopyROP3.png</file>
- <file>drawPixmap_rop/res/res_CopyROP4.png</file>
- <file>drawPixmap_rop/res/res_CopyROP5.png</file>
- <file>drawPixmap_rop/res/res_CopyROP6.png</file>
- <file>drawPixmap_rop/res/res_CopyROP7.png</file>
- <file>drawPixmap_rop/res/res_NandROP0.png</file>
- <file>drawPixmap_rop/res/res_NandROP1.png</file>
- <file>drawPixmap_rop/res/res_NandROP2.png</file>
- <file>drawPixmap_rop/res/res_NandROP3.png</file>
- <file>drawPixmap_rop/res/res_NandROP4.png</file>
- <file>drawPixmap_rop/res/res_NandROP5.png</file>
- <file>drawPixmap_rop/res/res_NandROP6.png</file>
- <file>drawPixmap_rop/res/res_NandROP7.png</file>
- <file>drawPixmap_rop/res/res_NopROP0.png</file>
- <file>drawPixmap_rop/res/res_NopROP1.png</file>
- <file>drawPixmap_rop/res/res_NopROP2.png</file>
- <file>drawPixmap_rop/res/res_NopROP3.png</file>
- <file>drawPixmap_rop/res/res_NopROP4.png</file>
- <file>drawPixmap_rop/res/res_NopROP5.png</file>
- <file>drawPixmap_rop/res/res_NopROP6.png</file>
- <file>drawPixmap_rop/res/res_NopROP7.png</file>
- <file>drawPixmap_rop/res/res_NorROP0.png</file>
- <file>drawPixmap_rop/res/res_NorROP1.png</file>
- <file>drawPixmap_rop/res/res_NorROP2.png</file>
- <file>drawPixmap_rop/res/res_NorROP3.png</file>
- <file>drawPixmap_rop/res/res_NorROP4.png</file>
- <file>drawPixmap_rop/res/res_NorROP5.png</file>
- <file>drawPixmap_rop/res/res_NorROP6.png</file>
- <file>drawPixmap_rop/res/res_NorROP7.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP0.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP1.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP2.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP3.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP4.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP5.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP6.png</file>
- <file>drawPixmap_rop/res/res_NotAndROP7.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP0.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP1.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP2.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP3.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP4.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP5.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP6.png</file>
- <file>drawPixmap_rop/res/res_NotCopyROP7.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP0.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP1.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP2.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP3.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP4.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP5.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP6.png</file>
- <file>drawPixmap_rop/res/res_NotOrROP7.png</file>
- <file>drawPixmap_rop/res/res_NotROP0.png</file>
- <file>drawPixmap_rop/res/res_NotROP1.png</file>
- <file>drawPixmap_rop/res/res_NotROP2.png</file>
- <file>drawPixmap_rop/res/res_NotROP3.png</file>
- <file>drawPixmap_rop/res/res_NotROP4.png</file>
- <file>drawPixmap_rop/res/res_NotROP5.png</file>
- <file>drawPixmap_rop/res/res_NotROP6.png</file>
- <file>drawPixmap_rop/res/res_NotROP7.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP0.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP1.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP2.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP3.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP4.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP5.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP6.png</file>
- <file>drawPixmap_rop/res/res_NotXorROP7.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP0.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP1.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP2.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP3.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP4.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP5.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP6.png</file>
- <file>drawPixmap_rop/res/res_OrNotROP7.png</file>
- <file>drawPixmap_rop/res/res_OrROP0.png</file>
- <file>drawPixmap_rop/res/res_OrROP1.png</file>
- <file>drawPixmap_rop/res/res_OrROP2.png</file>
- <file>drawPixmap_rop/res/res_OrROP3.png</file>
- <file>drawPixmap_rop/res/res_OrROP4.png</file>
- <file>drawPixmap_rop/res/res_OrROP5.png</file>
- <file>drawPixmap_rop/res/res_OrROP6.png</file>
- <file>drawPixmap_rop/res/res_OrROP7.png</file>
- <file>drawPixmap_rop/res/res_SetROP0.png</file>
- <file>drawPixmap_rop/res/res_SetROP1.png</file>
- <file>drawPixmap_rop/res/res_SetROP2.png</file>
- <file>drawPixmap_rop/res/res_SetROP3.png</file>
- <file>drawPixmap_rop/res/res_SetROP4.png</file>
- <file>drawPixmap_rop/res/res_SetROP5.png</file>
- <file>drawPixmap_rop/res/res_SetROP6.png</file>
- <file>drawPixmap_rop/res/res_SetROP7.png</file>
- <file>drawPixmap_rop/res/res_XorROP0.png</file>
- <file>drawPixmap_rop/res/res_XorROP1.png</file>
- <file>drawPixmap_rop/res/res_XorROP2.png</file>
- <file>drawPixmap_rop/res/res_XorROP3.png</file>
- <file>drawPixmap_rop/res/res_XorROP4.png</file>
- <file>drawPixmap_rop/res/res_XorROP5.png</file>
- <file>drawPixmap_rop/res/res_XorROP6.png</file>
- <file>drawPixmap_rop/res/res_XorROP7.png</file>
- <file>drawPixmap_rop_bitmap/dst.xbm</file>
- <file>drawPixmap_rop_bitmap/src1-mask.xbm</file>
- <file>drawPixmap_rop_bitmap/src1.xbm</file>
- <file>drawPixmap_rop_bitmap/src2.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_AndNotROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_AndROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_ClearROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_CopyROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NandROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NopROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NorROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NotAndROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NotCopyROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NotOrROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NotROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_NotXorROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_OrNotROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_OrROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_SetROP.xbm</file>
- <file>drawPixmap_rop_bitmap/res/res_XorROP.xbm</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 45490ef815..92b28f65bd 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -1,31 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qpainter.h>
@@ -69,6 +43,9 @@ Q_OBJECT
public:
tst_QPainter();
+ enum ClipType { ClipRect, ClipRectF, ClipRegionSingle, ClipRegionMulti, ClipPathR, ClipPath };
+ Q_ENUM(ClipType);
+
private slots:
void cleanupTestCase();
void getSetCheck();
@@ -84,6 +61,7 @@ private slots:
#endif
void drawPixmapFragments();
void drawPixmapNegativeScale();
+ void drawPixmapRounding();
void drawLine_data();
void drawLine();
@@ -155,6 +133,8 @@ private slots:
void clipBoundingRect();
void transformedClip();
+ void scaledClipConsistency_data();
+ void scaledClipConsistency();
void setOpacity_data();
void setOpacity();
@@ -190,6 +170,7 @@ private slots:
void radialGradientRgb30();
#endif
+ void radialGradient_QTBUG120332_ubsan();
void fpe_pixmapTransform();
void fpe_zeroLengthLines();
void fpe_divByZero();
@@ -301,6 +282,9 @@ private slots:
void drawImageAtPointF();
void scaledDashes();
+#if QT_CONFIG(raster_fp)
+ void hdrColors();
+#endif
private:
void fillData();
@@ -764,6 +748,16 @@ void tst_QPainter::drawPixmapNegativeScale()
QVERIFY(resultImage.pixel(12, 8) == qRgba(0, 0, 0, 255)); // and right strip is now black
}
+void tst_QPainter::drawPixmapRounding()
+{
+ // Just test that we don't assert
+ QBitmap bm(8, 8);
+ QImage out(64, 64, QImage::Format_RGB32);
+ QPainter p(&out);
+ qreal y = 26.499999999999996;
+ p.drawPixmap(QPointF(0, y), bm);
+}
+
void tst_QPainter::drawLine_data()
{
QTest::addColumn<QLine>("line");
@@ -1749,10 +1743,11 @@ void tst_QPainter::setClipRect()
/*
Verify that the clipping works correctly.
- The red outline should be covered by the blue rect on top and left,
- while it should be clipped on the right and bottom and thus the red outline be visible
+ Just like fillRect, cliprect should snap rightwards and downwards in case of .5 coordinates.
+ The red outline should be covered by the blue rect on top,
+ while it should be clipped on the other edges and thus the red outline be visible
- See: QTBUG-83229
+ See: QTBUG-83229, modified by QTBUG-100329
*/
void tst_QPainter::clipRect()
{
@@ -1778,7 +1773,7 @@ void tst_QPainter::clipRect()
p.end();
QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.top()), QColor(Qt::blue));
- QCOMPARE(image.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::blue));
+ QCOMPARE(image.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::red));
QCOMPARE(image.pixelColor(clipRect.left() + 1, clipRect.bottom()), QColor(Qt::red));
QCOMPARE(image.pixelColor(clipRect.right(), clipRect.top() + 1), QColor(Qt::red));
}
@@ -2098,21 +2093,22 @@ void tst_QPainter::clippedLines_data()
QPen pen2(QColor(223, 223, 0, 223));
pen2.setWidth(2);
- QList<QLineF> lines;
- lines << QLineF(15, 15, 65, 65)
- << QLineF(14, 14, 66, 66)
- << QLineF(16, 16, 64, 64)
- << QLineF(65, 65, 15, 15)
- << QLineF(66, 66, 14, 14)
- << QLineF(64, 64, 14, 14)
- << QLineF(15, 50, 15, 64)
- << QLineF(15, 50, 15, 65)
- << QLineF(15, 50, 15, 66)
- << QLineF(15, 50, 64, 50)
- << QLineF(15, 50, 65, 50)
- << QLineF(15, 50, 66, 50);
-
- foreach (QLineF line, lines) {
+ const auto lines = {
+ QLineF(15, 15, 65, 65),
+ QLineF(14, 14, 66, 66),
+ QLineF(16, 16, 64, 64),
+ QLineF(65, 65, 15, 15),
+ QLineF(66, 66, 14, 14),
+ QLineF(64, 64, 14, 14),
+ QLineF(15, 50, 15, 64),
+ QLineF(15, 50, 15, 65),
+ QLineF(15, 50, 15, 66),
+ QLineF(15, 50, 64, 50),
+ QLineF(15, 50, 65, 50),
+ QLineF(15, 50, 66, 50),
+ };
+
+ for (QLineF line : lines) {
const QByteArray desc = "line (" + QByteArray::number(line.x1())
+ ", " + QByteArray::number(line.y1()) + ", "
+ QByteArray::number(line.x2()) + ", " + QByteArray::number(line.y2())
@@ -2513,6 +2509,12 @@ void tst_QPainter::drawhelper_blend_untransformed_data()
setOpacity_data();
}
+static const auto &defaultOpacities()
+{
+ static const std::array opacities = {qreal(0.0), 0.1 , 0.01, 0.4, 0.5, 0.6, 0.9, 1.0};
+ return opacities;
+}
+
void tst_QPainter::drawhelper_blend_untransformed()
{
QFETCH(QImage::Format, destFormat);
@@ -2533,9 +2535,7 @@ void tst_QPainter::drawhelper_blend_untransformed()
p.fillRect(paintRect, srcColor);
p.end();
- QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4
- << 0.5 << 0.6 << 0.9 << 1.0);
- foreach (qreal opacity, opacities) {
+ for (qreal opacity : defaultOpacities()) {
p.begin(&dest);
p.fillRect(paintRect, destColor);
@@ -2590,9 +2590,7 @@ void tst_QPainter::drawhelper_blend_tiled_untransformed()
const QBrush brush(src);
- QList<qreal> opacities = (QList<qreal>() << 0.0 << 0.1 << 0.01 << 0.4
- << 0.5 << 0.6 << 0.9 << 1.0);
- foreach (qreal opacity, opacities) {
+ for (qreal opacity : defaultOpacities()) {
p.begin(&dest);
p.fillRect(paintRect, destColor);
@@ -2786,7 +2784,7 @@ void tst_QPainter::monoImages()
for (int i = 1; i < QImage::NImageFormats; ++i) {
for (int j = 0; j < numColorPairs; ++j) {
const QImage::Format format = QImage::Format(i);
- if (format == QImage::Format_Indexed8)
+ if (format == QImage::Format_Indexed8 || format == QImage::Format_CMYK8888)
continue;
QImage img(2, 2, format);
@@ -2846,7 +2844,14 @@ void tst_QPainter::monoImages()
}
}
-#if !defined(Q_OS_AIX) && !defined(Q_CC_MSVC) && !defined(Q_OS_SOLARIS) && !defined(__UCLIBC__) && !defined(Q_OS_INTEGRITY)
+#if defined(Q_OS_DARWIN) || defined(Q_OS_FREEBSD) || defined(Q_OS_ANDROID)
+# define TEST_FPE_EXCEPTIONS
+#elif defined(Q_OS_LINUX) && defined(__GLIBC__)
+# define TEST_FPE_EXCEPTIONS
+#elif defined(Q_OS_WIN) && defined(Q_CC_GNU)
+# define TEST_FPE_EXCEPTIONS
+#endif
+#ifdef TEST_FPE_EXCEPTIONS
#include <fenv.h>
static const QString fpeExceptionString(int exception)
@@ -3549,9 +3554,13 @@ void tst_QPainter::drawImage_data()
for (int srcFormat = QImage::Format_Mono; srcFormat < QImage::NImageFormats; ++srcFormat) {
for (int dstFormat = QImage::Format_Mono; dstFormat < QImage::NImageFormats; ++dstFormat) {
- // Indexed8 can't be painted to, and Alpha8 can't hold a color.
- if (dstFormat == QImage::Format_Indexed8 || dstFormat == QImage::Format_Alpha8)
+ // Indexed8 and CMYK8888 can't be painted to, and Alpha8 can't hold a color.
+ if (dstFormat == QImage::Format_Indexed8 ||
+ dstFormat == QImage::Format_CMYK8888 ||
+ dstFormat == QImage::Format_Alpha8) {
continue;
+ }
+
for (int odd_x = 0; odd_x <= 1; ++odd_x) {
for (int odd_width = 0; odd_width <= 1; ++odd_width) {
QTest::addRow("srcFormat %d, dstFormat %d, odd x: %d, odd width: %d",
@@ -3794,10 +3803,10 @@ static QLinearGradient inverseGradient(QLinearGradient g)
{
QLinearGradient g2 = g;
- QGradientStops stops = g.stops();
+ const QGradientStops stops = g.stops();
QGradientStops inverse;
- foreach (QGradientStop stop, stops)
+ for (const QGradientStop &stop : stops)
inverse << QGradientStop(1 - stop.first, stop.second);
g2.setStops(inverse);
@@ -3903,6 +3912,21 @@ void tst_QPainter::gradientPixelFormat()
QCOMPARE(a, b.convertToFormat(QImage::Format_ARGB32_Premultiplied));
}
+void tst_QPainter::radialGradient_QTBUG120332_ubsan()
+{
+ // Check if Radial Gradient will cause division by zero or not when
+ // the center point coincide with the focal point.
+ QImage image(8, 8, QImage::Format_ARGB32_Premultiplied);
+ QPainter painter(&image);
+
+ QPointF center(0.5, 0.5);
+ QPointF focal(0.5, 0.5);
+ QRadialGradient gradient(center, 0.5, focal, 0.5);
+ gradient.setColorAt(0, Qt::blue);
+ gradient.setColorAt(1, Qt::red);
+ painter.fillRect(image.rect(), QBrush(gradient));
+}
+
void tst_QPainter::gradientInterpolation()
{
QImage image(256, 8, QImage::Format_ARGB32_Premultiplied);
@@ -4580,6 +4604,96 @@ void tst_QPainter::transformedClip()
}
}
+void tst_QPainter::scaledClipConsistency_data()
+{
+ QTest::addColumn<ClipType>("clipType");
+
+ QTest::newRow("clipRect") << ClipRect;
+ QTest::newRow("clipRectF") << ClipRectF;
+ QTest::newRow("clipRegionSingle") << ClipRegionSingle;
+ QTest::newRow("clipRegionMulti") << ClipRegionMulti;
+ QTest::newRow("clipPathR") << ClipPathR;
+ QTest::newRow("clipPath") << ClipPath;
+}
+
+void tst_QPainter::scaledClipConsistency()
+{
+ QFETCH(ClipType, clipType);
+
+ const QList<QRect> clipRects = {
+ // Varying odd and even coordinates and width/height
+ QRect(1, 1, 7, 8),
+ QRect(8, 0, 8, 9),
+ QRect(0, 9, 8, 7),
+ QRect(8, 9, 8, 7),
+ };
+ // Assert that these are edge to edge:
+ QPointF center = QRectF(clipRects[0]).bottomRight();
+ Q_ASSERT(QRectF(clipRects[1]).bottomLeft() == center);
+ Q_ASSERT(QRectF(clipRects[2]).topRight() == center);
+ Q_ASSERT(QRectF(clipRects[3]).topLeft() == center);
+
+ QRegion multiRegion;
+ for (const QRect &clipRect : clipRects)
+ multiRegion += clipRect;
+
+ QColor fillColor(Qt::black);
+ fillColor.setAlphaF(0.5);
+
+ for (int i = 100; i <= 300; i++) {
+ qreal dpr = qreal(i) / 100.0;
+ QImage img(QSize(16, 16) * dpr, QImage::Format_RGB32);
+ img.fill(Qt::white);
+ img.setDevicePixelRatio(dpr);
+
+ for (const QRect &clipRect : clipRects) {
+ QPainter p(&img);
+ switch (clipType) {
+ case ClipRect:
+ p.setClipRect(clipRect);
+ break;
+ case ClipRectF:
+ p.setClipRect(QRectF(clipRect));
+ break;
+ case ClipRegionSingle:
+ p.setClipRegion(QRegion(clipRect));
+ break;
+ case ClipRegionMulti:
+ p.setClipRegion(multiRegion);
+ break;
+ case ClipPath:
+ p.rotate(0.001); // Avoid the path being optimized to a rectf
+ Q_FALLTHROUGH();
+ case ClipPathR: {
+ QPainterPath path;
+ path.addRect(clipRect); // Will be recognized and converted back to a rectf
+ p.setClipPath(path);
+ break;
+ }
+ default:
+ Q_ASSERT(false);
+ break;
+ }
+ p.fillRect(p.window(), fillColor);
+ if (clipType == ClipRegionMulti)
+ break; // once is enough, we're not using the clipRect anyway
+ }
+
+ int qtWidth = img.width() / 4;
+ int qtHeight = img.height() / 4;
+ QPoint imgCenter = img.rect().center();
+ const QRgb targetColor = img.pixel(qtWidth, qtHeight);
+
+ // Test that there are no gaps or overlaps where the cliprects meet
+ for (int offset = -2; offset <= 2; offset++) {
+ QCOMPARE(img.pixel(imgCenter.x() + offset, qtHeight), targetColor);
+ QCOMPARE(img.pixel(imgCenter.x() + offset, img.height() - qtHeight), targetColor);
+ QCOMPARE(img.pixel(qtWidth, imgCenter.y() + offset), targetColor);
+ QCOMPARE(img.pixel(img.width() - qtWidth, imgCenter.y() + offset), targetColor);
+ }
+ }
+}
+
#if defined(Q_OS_MAC)
// Only Mac supports sub pixel positions in raster engine currently
void tst_QPainter::drawText_subPixelPositionsInRaster_qtbug5053()
@@ -4816,10 +4930,7 @@ void tst_QPainter::QTBUG25153_drawLine()
{
QImage image(2, 2, QImage::Format_RGB32);
- QList<Qt::PenCapStyle> styles;
- styles << Qt::FlatCap << Qt::SquareCap << Qt::RoundCap;
-
- foreach (Qt::PenCapStyle style, styles) {
+ for (Qt::PenCapStyle style : {Qt::FlatCap, Qt::SquareCap, Qt::RoundCap}) {
image.fill(0xffffffff);
QPainter p(&image);
p.setPen(QPen(Qt::black, 0, Qt::SolidLine, style));
@@ -4930,16 +5041,16 @@ void tst_QPainter::blendARGBonRGB_data()
QTest::newRow("ARGB_PM over RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
<< QPainter::CompositionMode_SourceOver << qRgba(85, 0, 0, 85) << 85;
#if QT_CONFIG(raster_64bit)
- QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
- << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 85) << 85;
- QTest::newRow("ARGB source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
- << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 120) << 85;
+ QTest::newRow("ARGB@85 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 85) << 85;
+ QTest::newRow("ARGB@120 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
+ << QPainter::CompositionMode_Source << qRgba(255, 0, 0, 120) << 85;
#endif
- QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
- << QPainter::CompositionMode_Source << qRgba(85, 0, 0, 85) << 85;
+ QTest::newRow("ARGB_PM@85 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_Source << qRgba(85, 0, 0, 85) << 85;
#if QT_CONFIG(raster_64bit)
- QTest::newRow("ARGB_PM source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
- << QPainter::CompositionMode_Source << qRgba(180, 0, 0, 180) << 170;
+ QTest::newRow("ARGB_PM@180 source RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32_Premultiplied
+ << QPainter::CompositionMode_Source << qRgba(180, 0, 0, 180) << 170;
#endif
QTest::newRow("ARGB source-in RGB30") << QImage::Format_RGB30 << QImage::Format_ARGB32
<< QPainter::CompositionMode_SourceIn << qRgba(255, 0, 0, 85) << 85;
@@ -5100,7 +5211,7 @@ void tst_QPainter::drawPolyline()
p.setPen(pen);
QVERIFY(p.pen().isCosmetic());
if (r) {
- for (int i = 0; i < points.count()-1; i++) {
+ for (int i = 0; i < points.size()-1; i++) {
p.drawLine(points.at(i), points.at(i+1));
}
} else {
@@ -5393,6 +5504,49 @@ void tst_QPainter::scaledDashes()
QVERIFY(backFound);
}
+#if QT_CONFIG(raster_fp)
+void tst_QPainter::hdrColors()
+{
+ QImage img(10, 10, QImage::Format_RGBA32FPx4_Premultiplied);
+ img.fill(Qt::transparent);
+
+ QColor color = QColor::fromRgbF(2.0f, -0.25f, 1.5f);
+ img.setPixelColor(2, 2, color);
+ QCOMPARE(img.pixelColor(2, 2), color);
+
+ {
+ QPainterPath path;
+ path.addEllipse(4, 4, 2, 2);
+ QPainter p(&img);
+ p.fillPath(path, color);
+ p.end();
+ }
+ QCOMPARE(img.pixelColor(4, 4), color);
+
+ img.fill(color);
+ QCOMPARE(img.pixelColor(8, 8), color);
+
+ QColor color2 = QColor::fromRgbF(0.0f, 1.25f, 2.5f);
+ {
+ QPainter p(&img);
+ p.fillRect(0, 0, 3, 3, color2);
+ p.end();
+ }
+ QCOMPARE(img.pixelColor(1, 1), color2);
+ QCOMPARE(img.pixelColor(4, 4), color);
+
+ QImage img2(10, 10, QImage::Format_RGBX32FPx4);
+ img2.fill(Qt::black); // fill to avoid random FP values like Inf which can break SourceOver composition
+ {
+ QPainter p(&img2);
+ p.drawImage(0, 0, img);
+ p.end();
+ }
+ QCOMPARE(img2.pixelColor(2, 2), color2);
+ QCOMPARE(img2.pixelColor(5, 5), color);
+}
+#endif
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"
diff --git a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
index 53ea3ce9fb..7cb9e74216 100644
--- a/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
+++ b/tests/auto/gui/painting/qpainter/utils/createImages/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qapplication.h>
diff --git a/tests/auto/gui/painting/qpainterpath/BLACKLIST b/tests/auto/gui/painting/qpainterpath/BLACKLIST
deleted file mode 100644
index b3e6d3bfe4..0000000000
--- a/tests/auto/gui/painting/qpainterpath/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-[contains_QPointF]
-msvc-2019
diff --git a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
index 47450c9146..1da6e25511 100644
--- a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpainterpath.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpainterpath Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpainterpath LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpainterpath
SOURCES
tst_qpainterpath.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index dcba95d33c..c00dc3a78a 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -106,6 +81,8 @@ private slots:
void intersectionEquality();
void intersectionPointOnEdge();
+
+ void boundsAtStartPoint();
};
void tst_QPainterPath::cleanupTestCase()
@@ -410,11 +387,11 @@ void tst_QPainterPath::contains_QRectF_data()
QTest::newRow("inside 2 rects (winding)") << path << QRectF(51, 51, 48, 48) << true;
path.addEllipse(0, 0, 150, 150);
- QTest::newRow("topRight 2 rects") << path << QRectF(100, 25, 24, 24) << true;
- QTest::newRow("bottomLeft 2 rects") << path << QRectF(25, 100, 24, 24) << true;
+ QTest::newRow("topRight rects+circle") << path << QRectF(100, 25, 24, 24) << true;
+ QTest::newRow("bottomLeft rects+circle") << path << QRectF(25, 100, 24, 24) << true;
path.setFillRule(Qt::OddEvenFill);
- QTest::newRow("inside 2 rects") << path << QRectF(50, 50, 49, 49) << false;
+ QTest::newRow("inside rects+circle") << path << QRectF(50, 50, 49, 49) << false;
}
void tst_QPainterPath::contains_QRectF()
@@ -788,6 +765,21 @@ void tst_QPainterPath::testOperatorDatastream()
}
QCOMPARE(other, path);
+
+ // Check reset & detach
+ QPainterPath p3;
+ p3.lineTo(1, 1);
+ QCOMPARE(p3.elementCount(), 2);
+ QPainterPath p4 = p3;
+ QCOMPARE(p4.elementCount(), 2);
+ {
+ QFile data(tempDir.path() + "/data");
+ QVERIFY(data.open(QFile::ReadOnly));
+ QDataStream stream(&data);
+ stream >> p3;
+ }
+ QCOMPARE(p3.elementCount(), path.elementCount());
+ QCOMPARE(p4.elementCount(), 2);
}
void tst_QPainterPath::closing()
@@ -918,17 +910,17 @@ void tst_QPainterPath::testArcMoveTo_data()
QRectF(100, 100, 100, -100),
QRectF(100, 100, -100, -100),
};
+ constexpr qreal tinyAngle = 1e-10;
- for (uint domain = 0; domain < sizeof rects / sizeof *rects; ++domain) {
- const QByteArray dB = QByteArray::number(domain);
- for (int i=-360; i<=360; ++i) {
- QTest::newRow(("test " + dB + ' ' + QByteArray::number(i)).constData())
- << rects[domain] << (qreal) i;
- }
+ int index = 0;
+ for (const auto &rect : rects) {
+ for (int i = -360; i <= 360; ++i)
+ QTest::addRow("test %d %d", index, i) << rect << qreal(i);
// test low angles
- QTest::newRow("low angles 1") << rects[domain] << (qreal) 1e-10;
- QTest::newRow("low angles 2") << rects[domain] << (qreal)-1e-10;
+ QTest::addRow("low +angle %d", index) << rect << tinyAngle;
+ QTest::addRow("low -angle %d", index) << rect << -tinyAngle;
+ ++index;
}
}
@@ -1245,38 +1237,65 @@ void tst_QPainterPath::testNaNandInfinites()
QPointF p3 = QPointF(qQNaN(), 1);
QPointF pInf = QPointF(qInf(), 1);
- // all these operations with NaN/Inf should be ignored
- // can't test operator>> reliably, as we can't create a path with NaN to << later
+ // All these operations with NaN/Inf should be ignored.
+ // Can't test operator>> reliably, as we can't create a path with NaN to << later.
+#ifdef QT_NO_DEBUG
+# define WARNS(name)
+#else
+# define WARNS(name) \
+ QTest::ignoreMessage(QtWarningMsg, "QPainterPath::" #name ": " \
+ "Adding point with invalid coordinates, ignoring call")
+#endif
+ WARNS(moveTo);
path1.moveTo(p1);
+ WARNS(moveTo);
path1.moveTo(qSNaN(), qQNaN());
+ WARNS(moveTo);
path1.moveTo(pInf);
+ WARNS(lineTo);
path1.lineTo(p1);
+ WARNS(lineTo);
path1.lineTo(qSNaN(), qQNaN());
+ WARNS(lineTo);
path1.lineTo(pInf);
+ WARNS(cubicTo);
path1.cubicTo(p1, p2, p3);
+ WARNS(cubicTo);
path1.cubicTo(p1, QPointF(1, 1), QPointF(2, 2));
+ WARNS(cubicTo);
path1.cubicTo(pInf, QPointF(10, 10), QPointF(5, 1));
+ WARNS(quadTo);
path1.quadTo(p1, p2);
+ WARNS(quadTo);
path1.quadTo(QPointF(1, 1), p3);
+ WARNS(quadTo);
path1.quadTo(QPointF(1, 1), pInf);
+ WARNS(arcTo);
path1.arcTo(QRectF(p1, p2), 5, 5);
+ WARNS(arcTo);
path1.arcTo(QRectF(pInf, QPointF(1, 1)), 5, 5);
+ WARNS(addRect);
path1.addRect(QRectF(p1, p2));
+ WARNS(addRect);
path1.addRect(QRectF(pInf, QPointF(1, 1)));
+ WARNS(addEllipse);
path1.addEllipse(QRectF(p1, p2));
+ WARNS(addEllipse);
path1.addEllipse(QRectF(pInf, QPointF(1, 1)));
+#undef WARNS
+
QCOMPARE(path1, path2);
path1.lineTo(QPointF(1, 1));
- QVERIFY(path1 != path2);
+ QCOMPARE_NE(path1, path2);
}
#endif // signaling_nan
@@ -1440,6 +1459,32 @@ void tst_QPainterPath::intersectionPointOnEdge()
QVERIFY(p.intersects(r));
}
+void tst_QPainterPath::boundsAtStartPoint()
+{
+ const QPointF startPoint(10, 10);
+ const QPainterPath constructedPath(startPoint);
+ {
+ const auto boundingRect = constructedPath.boundingRect();
+ const auto topLeft = boundingRect.topLeft();
+ QCOMPARE(topLeft, startPoint);
+ QCOMPARE(topLeft, constructedPath.elementAt(0));
+ QCOMPARE(boundingRect, constructedPath.controlPointRect());
+ }
+
+ QPainterPath defaultPath;
+ defaultPath.moveTo(startPoint);
+ {
+ const auto boundingRect = defaultPath.boundingRect();
+ const auto topLeft = boundingRect.topLeft();
+ QCOMPARE(topLeft, startPoint);
+ QCOMPARE(topLeft, defaultPath.elementAt(0));
+ QCOMPARE(boundingRect, defaultPath.controlPointRect());
+ }
+
+ QCOMPARE(constructedPath.boundingRect(), defaultPath.boundingRect());
+ QCOMPARE(constructedPath.controlPointRect(), defaultPath.controlPointRect());
+}
+
QTEST_APPLESS_MAIN(tst_QPainterPath)
#include "tst_qpainterpath.moc"
diff --git a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
index f4c301c42e..d30778de3f 100644
--- a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpainterpathstroker.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpainterpathstroker Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpainterpathstroker LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpainterpathstroker
SOURCES
tst_qpainterpathstroker.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
index de3f612b10..ce80019273 100644
--- a/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
+++ b/tests/auto/gui/painting/qpainterpathstroker/tst_qpainterpathstroker.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
index 191b1b8a93..2cf25cfdf2 100644
--- a/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpathclipper/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qpathclipper.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpathclipper LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
@@ -14,18 +21,15 @@ qt_internal_add_test(tst_qpathclipper
tst_qpathclipper.cpp
INCLUDE_DIRECTORIES
.
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
-#### Keys ignored in scope 1:.:.:qpathclipper.pro:<TRUE>:
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qpathclipper CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY
- PUBLIC_LIBRARIES
+ LIBRARIES
m
)
diff --git a/tests/auto/gui/painting/qpathclipper/pathcompare.h b/tests/auto/gui/painting/qpathclipper/pathcompare.h
index 4f855194a4..593176686e 100644
--- a/tests/auto/gui/painting/qpathclipper/pathcompare.h
+++ b/tests/auto/gui/painting/qpathclipper/pathcompare.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PATHCOMPARE_H
#define PATHCOMPARE_H
diff --git a/tests/auto/gui/painting/qpathclipper/paths.cpp b/tests/auto/gui/painting/qpathclipper/paths.cpp
index a814958394..7b1486152b 100644
--- a/tests/auto/gui/painting/qpathclipper/paths.cpp
+++ b/tests/auto/gui/painting/qpathclipper/paths.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "paths.h"
QPainterPath Paths::rect()
diff --git a/tests/auto/gui/painting/qpathclipper/paths.h b/tests/auto/gui/painting/qpathclipper/paths.h
index 61daa0c3a4..73b41d324a 100644
--- a/tests/auto/gui/painting/qpathclipper/paths.h
+++ b/tests/auto/gui/painting/qpathclipper/paths.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef PATHS_H
#define PATHS_H
diff --git a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
index 83a8d6bd47..c5ef8373fd 100644
--- a/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
+++ b/tests/auto/gui/painting/qpathclipper/tst_qpathclipper.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "private/qpathclipper_p.h"
#include "paths.h"
#include "pathcompare.h"
@@ -495,15 +470,19 @@ void tst_QPathClipper::clipTest(int subjectIndex, int clipIndex, QPathClipper::O
break;
}
- if (expected != inResult) {
- char str[256];
- const char *opStr =
- op == QPathClipper::BoolAnd ? "and" :
- op == QPathClipper::BoolOr ? "or" : "sub";
- sprintf(str, "Expected: %d, actual: %d, subject: %d, clip: %d, op: %s\n",
- int(expected), int(inResult), subjectIndex, clipIndex, opStr);
- QFAIL(str);
- }
+ auto failLogger = qScopeGuard([&]{
+ qCritical().noquote().nospace()
+ << "\n\tExpected: " << expected
+ << "\n\tActual: " << inResult
+ << "\n\tSubject: " << subjectIndex
+ << "\n\tClip: " << clipIndex
+ << "\n\tOp: " << (op == QPathClipper::BoolAnd
+ ? "and"
+ : op == QPathClipper::BoolOr
+ ? "or" : "sub");
+ });
+ QCOMPARE(inResult, expected);
+ failLogger.dismiss();
}
}
@@ -797,7 +776,7 @@ void tst_QPathClipper::testIntersections7()
void tst_QPathClipper::testIntersections8()
{
QPainterPath path1 = Paths::node() * QTransform().translate(100, 50);
- QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);;
+ QPainterPath path2 = Paths::node() * QTransform().translate(150, 50);
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
@@ -845,7 +824,7 @@ void tst_QPathClipper::testIntersections9()
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
- path1 = QPainterPath();;
+ path1 = QPainterPath();
path2 = QPainterPath();
path1.addRect(QRectF(-1,191, 136, 106));
@@ -853,7 +832,7 @@ void tst_QPathClipper::testIntersections9()
QVERIFY(path1.intersects(path2));
QVERIFY(path2.intersects(path1));
- path1 = QPainterPath();;
+ path1 = QPainterPath();
path2 = QPainterPath();
path1.moveTo(-1 , 143);
diff --git a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
index c6eb5b1034..3a42d81600 100644
--- a/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpdfwriter/CMakeLists.txt
@@ -1,15 +1,22 @@
-# Generated from qpdfwriter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpdfwriter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpdfwriter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpdfwriter
SOURCES
tst_qpdfwriter.cpp
DEFINES
QT_USE_USING_NAMESPACE
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
index c74baf0ba4..4d6b1f01b9 100644
--- a/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
+++ b/tests/auto/gui/painting/qpdfwriter/tst_qpdfwriter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGlobal>
diff --git a/tests/auto/gui/painting/qpen/CMakeLists.txt b/tests/auto/gui/painting/qpen/CMakeLists.txt
index 321c40fa8f..05fbbfb552 100644
--- a/tests/auto/gui/painting/qpen/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpen/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qpen.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpen Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpen LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpen
SOURCES
tst_qpen.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/painting/qpen/tst_qpen.cpp b/tests/auto/gui/painting/qpen/tst_qpen.cpp
index 64c01a81b5..b3ff1c76f9 100644
--- a/tests/auto/gui/painting/qpen/tst_qpen.cpp
+++ b/tests/auto/gui/painting/qpen/tst_qpen.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qpolygon/CMakeLists.txt b/tests/auto/gui/painting/qpolygon/CMakeLists.txt
index a61529d397..42b108efcd 100644
--- a/tests/auto/gui/painting/qpolygon/CMakeLists.txt
+++ b/tests/auto/gui/painting/qpolygon/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qpolygon.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qpolygon Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qpolygon LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qpolygon
SOURCES
tst_qpolygon.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
@@ -15,6 +22,6 @@ qt_internal_add_test(tst_qpolygon
#####################################################################
qt_internal_extend_target(tst_qpolygon CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY
- PUBLIC_LIBRARIES
+ LIBRARIES
m
)
diff --git a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
index 4cde0aa549..cd24135ac6 100644
--- a/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
+++ b/tests/auto/gui/painting/qpolygon/tst_qpolygon.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -41,6 +16,7 @@ class tst_QPolygon : public QObject
private slots:
void constructors();
+ void toPolygonF();
void boundingRect_data();
void boundingRect();
void boundingRectF_data();
@@ -80,6 +56,17 @@ void tst_QPolygon::constructors()
constructors_helperF(QRectF(1, 2, 3, 4));
}
+void tst_QPolygon::toPolygonF()
+{
+ const QPolygon p = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
+ auto pf = p.toPolygonF();
+ static_assert(std::is_same_v<decltype(pf), QPolygonF>);
+ QCOMPARE(pf.size(), p.size());
+ auto p2 = pf.toPolygon();
+ static_assert(std::is_same_v<decltype(p2), QPolygon>);
+ QCOMPARE(p, p2);
+}
+
void tst_QPolygon::boundingRect_data()
{
QTest::addColumn<QPolygon>("poly");
@@ -181,8 +168,8 @@ void tst_QPolygon::swap()
QPolygon p2(QList<QPoint>() << QPoint(0, 0) << QPoint(0, 10) << QPoint(10, 10)
<< QPoint(10, 0));
p1.swap(p2);
- QCOMPARE(p1.count(),4);
- QCOMPARE(p2.count(),3);
+ QCOMPARE(p1.size(),4);
+ QCOMPARE(p2.size(),3);
}
void tst_QPolygon::intersections_data()
diff --git a/tests/auto/gui/painting/qregion/CMakeLists.txt b/tests/auto/gui/painting/qregion/CMakeLists.txt
index 9564e0719e..ba580438cd 100644
--- a/tests/auto/gui/painting/qregion/CMakeLists.txt
+++ b/tests/auto/gui/painting/qregion/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qregion.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qregion Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qregion LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qregion
SOURCES
tst_qregion.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/painting/qregion/tst_qregion.cpp b/tests/auto/gui/painting/qregion/tst_qregion.cpp
index 29179c44a0..3d60e62fc1 100644
--- a/tests/auto/gui/painting/qregion/tst_qregion.cpp
+++ b/tests/auto/gui/painting/qregion/tst_qregion.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/painting/qtransform/CMakeLists.txt b/tests/auto/gui/painting/qtransform/CMakeLists.txt
index 4d50e2cf33..557e5fa742 100644
--- a/tests/auto/gui/painting/qtransform/CMakeLists.txt
+++ b/tests/auto/gui/painting/qtransform/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtransform.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtransform Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtransform LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtransform
SOURCES
tst_qtransform.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
@@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtransform
#####################################################################
qt_internal_extend_target(tst_qtransform CONDITION UNIX AND NOT APPLE AND NOT HAIKU AND NOT INTEGRITY
- PUBLIC_LIBRARIES
+ LIBRARIES
m
)
diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
index 1bab7200f0..428174bfc6 100644
--- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
+++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/platform/CMakeLists.txt b/tests/auto/gui/platform/CMakeLists.txt
index fc2d330fd7..4b2cee205d 100644
--- a/tests/auto/gui/platform/CMakeLists.txt
+++ b/tests/auto/gui/platform/CMakeLists.txt
@@ -1,3 +1,6 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
if(QT_FEATURE_xcb)
add_subdirectory(qx11info)
endif()
diff --git a/tests/auto/gui/platform/qx11info/CMakeLists.txt b/tests/auto/gui/platform/qx11info/CMakeLists.txt
index c4ce1f91c8..40188f24a0 100644
--- a/tests/auto/gui/platform/qx11info/CMakeLists.txt
+++ b/tests/auto/gui/platform/qx11info/CMakeLists.txt
@@ -1,7 +1,16 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qx11info LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qx11info
SOURCES
tst_qx11info.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::GuiPrivate
XCB::XCB
)
diff --git a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp
index 0cd11c87ac..a4effb07cc 100644
--- a/tests/auto/gui/platform/qx11info/tst_qx11info.cpp
+++ b/tests/auto/gui/platform/qx11info/tst_qx11info.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 David Faure <david.faure@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 David Faure <david.faure@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui>
#include <QtTest/QtTest>
@@ -112,6 +87,8 @@ void tst_QX11Info::startupId()
{
int argc = 0;
QGuiApplication app(argc, 0);
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("This test is only for X11, not Wayland.");
// This relies on the fact that no widget was shown yet,
// so please make sure this method is always the first test.
@@ -133,6 +110,8 @@ void tst_QX11Info::isPlatformX11()
{
int argc = 0;
QGuiApplication app(argc, 0);
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("This test is only for X11, not Wayland.");
QVERIFY(QX11Info::isPlatformX11());
}
@@ -141,6 +120,8 @@ void tst_QX11Info::appTime()
{
int argc = 0;
QGuiApplication app(argc, 0);
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("This test is only for X11, not Wayland.");
// No X11 event received yet
QCOMPARE(QX11Info::appTime(), 0ul);
@@ -367,6 +348,8 @@ void tst_QX11Info::peeker()
{
int argc = 0;
QGuiApplication app(argc, 0);
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("This test is only for X11, not Wayland.");
PeekerTest test;
test.show();
@@ -378,6 +361,8 @@ void tst_QX11Info::isCompositingManagerRunning()
{
int argc = 0;
QGuiApplication app(argc, 0);
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("This test is only for X11, not Wayland.");
const bool b = QX11Info::isCompositingManagerRunning();
Q_UNUSED(b);
const bool b2 = QX11Info::isCompositingManagerRunning(0);
diff --git a/tests/auto/gui/qopengl/CMakeLists.txt b/tests/auto/gui/qopengl/CMakeLists.txt
index 3be29695a5..48e07d2878 100644
--- a/tests/auto/gui/qopengl/CMakeLists.txt
+++ b/tests/auto/gui/qopengl/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qopengl.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qopengl Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qopengl LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qopengl
SOURCES
tst_qopengl.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index e2e7f153a0..af59f3e31a 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtOpenGL/QOpenGLFramebufferObject>
#include <QtOpenGL/QOpenGLPaintDevice>
@@ -32,7 +7,9 @@
#include <QtOpenGL/qopengltextureblitter.h>
#include <QtOpenGL/QOpenGLVertexArrayObject>
#include <QtOpenGL/QOpenGLBuffer>
-#include <QtOpenGL/QOpenGLFunctions_4_2_Core>
+#if !QT_CONFIG(opengles2)
+# include <QtOpenGL/QOpenGLFunctions_4_2_Core>
+#endif
#include <QtOpenGL/QOpenGLVersionFunctionsFactory>
#include <QtGui/private/qopenglcontext_p.h>
#include <QtGui/QOpenGLFunctions>
@@ -643,6 +620,10 @@ static bool supportsInternalFboFormat(QOpenGLContext *ctx, int glFormat)
void tst_QOpenGL::fboRenderingRGB30()
{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-105738)");
+#endif
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
QSKIP("QTBUG-22617");
#endif
@@ -1182,6 +1163,7 @@ void tst_QOpenGL::sizeLessWindow()
// child window
{
QWindow parent;
+ parent.setSurfaceType(QWindow::OpenGLSurface);
QWindow window(&parent);
window.setSurfaceType(QWindow::OpenGLSurface);
@@ -1610,6 +1592,13 @@ void tst_QOpenGL::bufferCreate()
buf.allocate(128);
QCOMPARE(buf.size(), 128);
+ {
+ QOpenGLBuffer moved = std::move(buf);
+ QCOMPARE_EQ(moved.isCreated(), true);
+ QCOMPARE_EQ(moved.size(), 128);
+ buf = std::move(moved);
+ }
+
buf.release();
buf.destroy();
@@ -1695,10 +1684,11 @@ void tst_QOpenGL::nullTextureInitializtion()
/*
Verify that the clipping works correctly.
- The red outline should be covered by the blue rect on top and left,
- while it should be clipped on the right and bottom and thus the red outline be visible
+ Just like fillRect, cliprect should snap rightwards and downwards in case of .5 coordinates.
+ The red outline should be covered by the blue rect on top,
+ while it should be clipped on the other edges and thus the red outline be visible
- See: QTBUG-83229
+ See: QTBUG-83229, modified by QTBUG-100329
*/
void tst_QOpenGL::clipRect()
{
@@ -1754,7 +1744,7 @@ void tst_QOpenGL::clipRect()
QCOMPARE(fb.size(), size);
QCOMPARE(fb.pixelColor(clipRect.left() + 1, clipRect.top()), QColor(Qt::blue));
- QCOMPARE(fb.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::blue));
+ QCOMPARE(fb.pixelColor(clipRect.left(), clipRect.top() + 1), QColor(Qt::red));
QCOMPARE(fb.pixelColor(clipRect.left() + 1, clipRect.bottom()), QColor(Qt::red));
// Enable this once QTBUG-85286 is fixed
diff --git a/tests/auto/gui/qopenglconfig/CMakeLists.txt b/tests/auto/gui/qopenglconfig/CMakeLists.txt
index d193e15c2e..ea70afd20a 100644
--- a/tests/auto/gui/qopenglconfig/CMakeLists.txt
+++ b/tests/auto/gui/qopenglconfig/CMakeLists.txt
@@ -1,16 +1,23 @@
-# Generated from qopenglconfig.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qopenglconfig Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qopenglconfig LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
list(APPEND test_data "buglist.json")
qt_internal_add_test(tst_qopenglconfig
SOURCES
tst_qopenglconfig.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp
index d65293f8b8..423f9419da 100644
--- a/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp
+++ b/tests/auto/gui/qopenglconfig/tst_qopenglconfig.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QScreen>
diff --git a/tests/auto/gui/qvulkan/CMakeLists.txt b/tests/auto/gui/qvulkan/CMakeLists.txt
index 7cca165ed2..d4e2dd6f87 100644
--- a/tests/auto/gui/qvulkan/CMakeLists.txt
+++ b/tests/auto/gui/qvulkan/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qvulkan.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qvulkan Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qvulkan LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qvulkan
SOURCES
tst_qvulkan.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/qvulkan/tst_qvulkan.cpp b/tests/auto/gui/qvulkan/tst_qvulkan.cpp
index b1cc2dd052..c8f5c27481 100644
--- a/tests/auto/gui/qvulkan/tst_qvulkan.cpp
+++ b/tests/auto/gui/qvulkan/tst_qvulkan.cpp
@@ -1,34 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QVulkanInstance>
#include <QtGui/QVulkanFunctions>
#include <QtGui/QVulkanWindow>
+#include <QtCore/qvarlengtharray.h>
#include <QTest>
@@ -112,6 +88,10 @@ void tst_QVulkan::vulkanCheckSupported()
void tst_QVulkan::vulkan11()
{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-105739)");
+#endif
#if VK_VERSION_1_1
QVulkanInstance inst;
if (inst.supportedApiVersion() < QVersionNumber(1, 1))
@@ -161,15 +141,17 @@ void tst_QVulkan::vulkan11()
QByteArray deviceUuid = QByteArray::fromRawData((const char *) deviceIdProps.deviceUUID, VK_UUID_SIZE).toHex();
QByteArray driverUuid = QByteArray::fromRawData((const char *) deviceIdProps.driverUUID, VK_UUID_SIZE).toHex();
qDebug() << "deviceUUID" << deviceUuid << "driverUUID" << driverUuid;
+ const bool deviceUuidZero = std::find_if(deviceUuid.cbegin(), deviceUuid.cend(), [](char c) -> bool { return c; }) == deviceUuid.cend();
+ const bool driverUuidZero = std::find_if(driverUuid.cbegin(), driverUuid.cend(), [](char c) -> bool { return c; }) == driverUuid.cend();
// deviceUUID cannot be all zero as per spec
- bool seenNonZero = false;
- for (int i = 0; i < VK_UUID_SIZE; ++i) {
- if (deviceIdProps.deviceUUID[i]) {
- seenNonZero = true;
- break;
- }
+ if (!driverUuidZero) {
+ // ...but then there are implementations such as some
+ // versions of Mesa lavapipe, that returns all zeroes
+ // for both uuids. skip the check if the driver uuid
+ // was zero too.
+ // https://gitlab.freedesktop.org/mesa/mesa/-/issues/5875
+ QVERIFY(!deviceUuidZero);
}
- QVERIFY(seenNonZero);
} else {
qDebug("Physical device is not Vulkan 1.1 capable");
}
@@ -184,6 +166,10 @@ void tst_QVulkan::vulkan11()
void tst_QVulkan::vulkanPlainWindow()
{
+#ifdef Q_OS_ANDROID
+ QSKIP("Fails on Android 7 emulator (QTBUG-108328)");
+#endif
+
QVulkanInstance inst;
if (!inst.create())
QSKIP("Vulkan init failed; skip");
@@ -471,6 +457,10 @@ void tst_QVulkan::vulkanWindowRenderer()
void tst_QVulkan::vulkanWindowGrab()
{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-105739)");
+#endif
QVulkanInstance inst;
inst.setLayers(QByteArrayList() << "VK_LAYER_KHRONOS_validation");
if (!inst.create())
diff --git a/tests/auto/gui/rhi/CMakeLists.txt b/tests/auto/gui/rhi/CMakeLists.txt
index 786e121f00..898a67d2dc 100644
--- a/tests/auto/gui/rhi/CMakeLists.txt
+++ b/tests/auto/gui/rhi/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from rhi.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qshader)
add_subdirectory(qrhi)
diff --git a/tests/auto/gui/rhi/qrhi/BLACKLIST b/tests/auto/gui/rhi/qrhi/BLACKLIST
index 68621ac66b..b3284f8979 100644
--- a/tests/auto/gui/rhi/qrhi/BLACKLIST
+++ b/tests/auto/gui/rhi/qrhi/BLACKLIST
@@ -7,3 +7,15 @@ android
# Skip 3D textures with Android emulator, the sw-based GL there is no good
[threeDimTexture]
android
+# Same here, GLES 3.0 features seem hopeless
+[renderToTextureTextureArray]
+android
+# Ditto
+[renderToTextureSampleWithSeparateTextureAndSampler]
+android
+[renderToFloatTexture]
+android
+[renderToRgb10Texture]
+android
+[tessellation vulkan]
+android
diff --git a/tests/auto/gui/rhi/qrhi/CMakeLists.txt b/tests/auto/gui/rhi/qrhi/CMakeLists.txt
index 65d072c6b9..3b0d643060 100644
--- a/tests/auto/gui/rhi/qrhi/CMakeLists.txt
+++ b/tests/auto/gui/rhi/qrhi/CMakeLists.txt
@@ -1,26 +1,28 @@
-# Generated from qrhi.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qrhi Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qrhi LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# 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
+ 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}
-)
-
diff --git a/tests/auto/gui/rhi/qrhi/data/buildshaders.bat b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat
index 0102457b8a..fe40459719 100644
--- a/tests/auto/gui/rhi/qrhi/data/buildshaders.bat
+++ b/tests/auto/gui/rhi/qrhi/data/buildshaders.bat
@@ -1,48 +1,30 @@
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
-::
:: Copyright (C) 2019 The Qt Company Ltd.
-:: Contact: https://www.qt.io/licensing/
-::
-:: This file is part of the QtQuick module of the Qt Toolkit.
-::
-:: $QT_BEGIN_LICENSE:LGPL$
-:: Commercial License Usage
-:: Licensees holding valid commercial Qt licenses may use this file in
-:: accordance with the commercial license agreement provided with the
-:: Software or, alternatively, in accordance with the terms contained in
-:: a written agreement between you and The Qt Company. For licensing terms
-:: and conditions see https://www.qt.io/terms-conditions. For further
-:: information use the contact form at https://www.qt.io/contact-us.
-::
-:: GNU Lesser General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU Lesser
-:: General Public License version 3 as published by the Free Software
-:: Foundation and appearing in the file LICENSE.LGPL3 included in the
-:: packaging of this file. Please review the following information to
-:: ensure the GNU Lesser General Public License version 3 requirements
-:: will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-::
-:: GNU General Public License Usage
-:: Alternatively, this file may be used under the terms of the GNU
-:: General Public License version 2.0 or (at your option) the GNU General
-:: Public license version 3 or any later version approved by the KDE Free
-:: Qt Foundation. The licenses are as published by the Free Software
-:: Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-:: included in the packaging of this file. Please review the following
-:: information to ensure the GNU General Public License requirements will
-:: be met: https://www.gnu.org/licenses/gpl-2.0.html and
-:: https://www.gnu.org/licenses/gpl-3.0.html.
-::
-:: $QT_END_LICENSE$
-::
-:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
+:: SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.vert.qsb simple.vert
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simple.frag.qsb simple.frag
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.vert.qsb simpletextured.vert
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured.frag.qsb simpletextured.frag
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 20 -o simpletextured_array.frag.qsb simpletextured_array.frag
+qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o simpletextured_separate.frag.qsb simpletextured_separate.frag
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.vert.qsb textured.vert
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured.frag.qsb textured.frag
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured_multiubuf.vert.qsb textured_multiubuf.vert
qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o textured_multiubuf.frag.qsb textured_multiubuf.frag
+qsb --glsl 320es,410 --msl 12 --msltess simpletess.vert -o simpletess.vert.qsb
+qsb --glsl 320es,410 --msl 12 --tess-mode triangles simpletess.tesc -o simpletess.tesc.qsb
+qsb --glsl 320es,410 --msl 12 --tess-vertex-count 3 simpletess.tese -o simpletess.tese.qsb
+qsb --glsl 320es,410 --msl 12 simpletess.frag -o simpletess.frag.qsb
+qsb --glsl 310es,430 --msl 12 --hlsl 50 storagebuffer.comp -o storagebuffer.comp.qsb
+qsb --glsl 320es,430 --msl 12 --msltess storagebuffer_runtime.vert -o storagebuffer_runtime.vert.qsb
+qsb --glsl 320es,430 --msl 12 --tess-mode triangles storagebuffer_runtime.tesc -o storagebuffer_runtime.tesc.qsb
+qsb --glsl 320es,430 --msl 12 --tess-vertex-count 3 storagebuffer_runtime.tese -o storagebuffer_runtime.tese.qsb
+qsb --glsl 320es,430 --msl 12 storagebuffer_runtime.frag -o storagebuffer_runtime.frag.qsb
+qsb --glsl 320es,430 --hlsl 50 -c --msl 12 storagebuffer_runtime.comp -o storagebuffer_runtime.comp.qsb
+qsb --glsl "150,120,100 es" --hlsl 50 -c --msl 12 -o half.vert.qsb half.vert
+qsb --glsl 320es,430 --msl 21 --msltess tessinterfaceblocks.vert -o tessinterfaceblocks.vert.qsb
+qsb --glsl 320es,430 --msl 21 --tess-mode triangles tessinterfaceblocks.tesc -o tessinterfaceblocks.tesc.qsb
+qsb --glsl 320es,430 --msl 21 --tess-vertex-count 3 tessinterfaceblocks.tese -o tessinterfaceblocks.tese.qsb
+qsb --glsl 320es,430 --msl 21 simpletess.frag -o tessinterfaceblocks.frag.qsb
+qsb --view-count 2 --glsl "300 es,330" --hlsl 61 -c --msl 12 multiview.vert -o multiview.vert.qsb
+qsb --glsl "300 es,330" --hlsl 61 -c --msl 12 multiview.frag -o multiview.frag.qsb
diff --git a/tests/auto/gui/rhi/qrhi/data/half.vert b/tests/auto/gui/rhi/qrhi/data/half.vert
new file mode 100644
index 0000000000..b503201351
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/half.vert
@@ -0,0 +1,10 @@
+#version 440
+
+layout(location = 0) in vec3 position;
+
+out gl_PerVertex { vec4 gl_Position; };
+
+void main()
+{
+ gl_Position = vec4(position, 1.0);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/half.vert.qsb b/tests/auto/gui/rhi/qrhi/data/half.vert.qsb
new file mode 100644
index 0000000000..fb8680024a
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/half.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.frag b/tests/auto/gui/rhi/qrhi/data/multiview.frag
new file mode 100644
index 0000000000..375587662f
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/multiview.frag
@@ -0,0 +1,10 @@
+#version 440
+
+layout(location = 0) in vec3 v_color;
+
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(v_color, 1.0);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb b/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb
new file mode 100644
index 0000000000..db8133f12e
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/multiview.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.vert b/tests/auto/gui/rhi/qrhi/data/multiview.vert
new file mode 100644
index 0000000000..b9c9e5a704
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/multiview.vert
@@ -0,0 +1,18 @@
+#version 440
+#extension GL_EXT_multiview : require
+
+layout(location = 0) in vec4 pos;
+layout(location = 1) in vec3 color;
+
+layout(location = 0) out vec3 v_color;
+
+layout(std140, binding = 0) uniform buf
+{
+ mat4 mvp[2];
+};
+
+void main()
+{
+ v_color = color;
+ gl_Position = mvp[gl_ViewIndex] * pos;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb b/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb
new file mode 100644
index 0000000000..cf1f67f58f
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/multiview.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.frag b/tests/auto/gui/rhi/qrhi/data/simpletess.frag
new file mode 100644
index 0000000000..375587662f
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.frag
@@ -0,0 +1,10 @@
+#version 440
+
+layout(location = 0) in vec3 v_color;
+
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(v_color, 1.0);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb
new file mode 100644
index 0000000000..0f42103ac5
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tesc b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc
new file mode 100644
index 0000000000..e192fc77c7
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc
@@ -0,0 +1,22 @@
+#version 440
+
+layout(vertices = 3) out;
+
+layout(location = 0) in vec3 inColor[];
+layout(location = 0) out vec3 outColor[];
+layout(location = 1) patch out float a_per_patch_output_variable;
+
+void main()
+{
+ if (gl_InvocationID == 0) {
+ gl_TessLevelOuter[0] = 4.0;
+ gl_TessLevelOuter[1] = 4.0;
+ gl_TessLevelOuter[2] = 4.0;
+
+ gl_TessLevelInner[0] = 4.0;
+ }
+
+ gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
+ outColor[gl_InvocationID] = inColor[gl_InvocationID];
+ a_per_patch_output_variable = 1.0;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb
new file mode 100644
index 0000000000..8c98d92c46
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tesc.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tese b/tests/auto/gui/rhi/qrhi/data/simpletess.tese
new file mode 100644
index 0000000000..17b348635a
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tese
@@ -0,0 +1,17 @@
+#version 440
+
+layout(triangles, fractional_odd_spacing, ccw) in;
+
+layout(location = 0) in vec3 inColor[];
+layout(location = 0) out vec3 outColor;
+layout(location = 1) patch in float a_per_patch_output_variable;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+};
+
+void main()
+{
+ gl_Position = mvp * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position));
+ outColor = gl_TessCoord.x * inColor[0] + gl_TessCoord.y * inColor[1] + gl_TessCoord.z * inColor[2] * a_per_patch_output_variable;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb
new file mode 100644
index 0000000000..8aa7632717
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.tese.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.vert b/tests/auto/gui/rhi/qrhi/data/simpletess.vert
new file mode 100644
index 0000000000..3838d2f3bb
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.vert
@@ -0,0 +1,12 @@
+#version 440
+
+layout(location = 0) in vec3 position;
+layout(location = 1) in vec3 color;
+
+layout(location = 0) out vec3 v_color;
+
+void main()
+{
+ gl_Position = vec4(position, 1.0);
+ v_color = color;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb b/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb
new file mode 100644
index 0000000000..ee90983e0b
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletess.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag b/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag
new file mode 100644
index 0000000000..41b0e4f1c2
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag
@@ -0,0 +1,14 @@
+#version 440
+
+layout(location = 0) in vec2 uv;
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 3) uniform texture2D tex;
+layout(binding = 5) uniform sampler samp;
+
+void main()
+{
+ vec4 c = texture(sampler2D(tex, samp), uv);
+ c.rgb *= c.a;
+ fragColor = c;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag.qsb b/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag.qsb
new file mode 100644
index 0000000000..c5afe1a8eb
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/simpletextured_separate.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp
new file mode 100644
index 0000000000..ffa0bc7004
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp
@@ -0,0 +1,28 @@
+#version 430
+layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+
+
+layout (binding = 0, std430) readonly buffer toGpu
+{
+ float _float;
+ vec2 _vec2;
+ vec3 _vec3;
+ vec4 _vec4;
+};
+
+layout (binding = 1, std140) buffer fromGpu
+{
+ int _int;
+ ivec2 _ivec2;
+ ivec3 _ivec3;
+ ivec4 _ivec4;
+};
+
+void main()
+{
+ _int = int(_float);
+ _ivec2 = ivec2(_vec2);
+ _ivec3 = ivec3(_vec3);
+ _ivec4 = ivec4(_vec4);
+}
+
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb
new file mode 100644
index 0000000000..b02f541cc5
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer.comp.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp
new file mode 100644
index 0000000000..d36f5426bc
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp
@@ -0,0 +1,25 @@
+#version 430
+
+layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+
+layout (binding = 0, std430) buffer toGpu
+{
+ float _float[];
+};
+
+
+layout (binding = 1, std140) buffer fromGpu
+{
+ int _int[];
+};
+
+void main()
+{
+ int length = min(_float.length(), _int.length());
+
+ for (int i = 0; i < length; ++i)
+ _int[i] = int(_float[i]);
+
+}
+
+
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb
new file mode 100644
index 0000000000..b4c43ecc9b
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.comp.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag
new file mode 100644
index 0000000000..2e45a5f62a
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag
@@ -0,0 +1,33 @@
+#version 450
+
+layout (location = 0) out vec4 fragColor;
+
+layout (std430, binding = 1) readonly buffer ssboG
+{
+ float g[];
+};
+
+layout (std430, binding = 2) readonly buffer ssboB
+{
+ float b[];
+};
+
+layout (std430, binding = 6) readonly buffer ssboR
+{
+ float r[];
+};
+
+layout (std430, binding = 3) readonly buffer ssbo3
+{
+ vec4 _vec4;
+};
+
+void main()
+{
+
+ // some OpenGL implementations will optimize out the buffer variables if we don't use them
+ // resulting in a .length() of 0.
+ float a = (r[0]+g[0]+b[0])>0?1:1;
+
+ fragColor = a * vec4(r.length(), g.length(), b.length(), 255)/vec4(255);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb
new file mode 100644
index 0000000000..53fc9a1906
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc
new file mode 100644
index 0000000000..56060285d2
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc
@@ -0,0 +1,42 @@
+#version 450
+
+layout(vertices = 3) out;
+
+
+layout (std430, binding = 7) readonly buffer ssbo7
+{
+ float float7[];
+};
+
+layout (std430, binding = 8) readonly buffer ssbo8
+{
+ float float8[];
+};
+
+layout (std430, binding = 9) readonly buffer ssbo9
+{
+ float float9[];
+};
+
+layout (std430, binding = 10) readonly buffer ssbo10
+{
+ float float10[];
+};
+
+void main()
+{
+
+ // some OpenGL implementations will optimize out the buffer variables if we don't use them
+ // resulting in a .length() of 0
+ float a = float7[0] == 0 && float8[0] == 0 && float9[0] == 0 && float10[0] == 0 ? 1 : 1;
+
+ if (gl_InvocationID == 0) {
+ gl_TessLevelOuter[0] = float7.length() * a;
+ gl_TessLevelOuter[1] = float8.length() * a;
+ gl_TessLevelOuter[2] = float9.length() * a;
+ gl_TessLevelInner[0] = float10.length() * a;
+ }
+
+ gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
+
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb
new file mode 100644
index 0000000000..e48aa0269c
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tesc.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese
new file mode 100644
index 0000000000..a8bec13561
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese
@@ -0,0 +1,39 @@
+#version 450
+
+layout(triangles, fractional_odd_spacing, ccw) in;
+
+layout (std140, binding = 6) uniform unused0
+{
+ int unused;
+}u0;
+
+layout (binding = 0) uniform u
+{
+ mat4 matrix;
+};
+
+layout (std430, binding = 5) readonly buffer ssbo5
+{
+ float _float[];
+};
+
+layout (std430, binding = 8) readonly buffer ssbo8
+{
+ float float8[];
+};
+
+layout (std430, binding = 1) readonly buffer unused1
+{
+ int unused[];
+}u1;
+
+
+void main()
+{
+ // some OpenGL implementations will optimize out the buffer variables if we don't use them
+ // resulting in a .length() of 0
+ float a = _float[0] == 0 && float8[0] == 1 ? 1 : 1;
+
+ if(_float.length() == 64)
+ gl_Position = a * matrix * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position)) * (float8.length()==2?1:0);
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb
new file mode 100644
index 0000000000..23a433b5ae
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.tese.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert
new file mode 100644
index 0000000000..b3ac10efea
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert
@@ -0,0 +1,48 @@
+#version 450
+
+layout (location = 0) in vec3 position;
+
+layout (std140, binding = 6) uniform unused0
+{
+ int unused;
+}u0;
+
+layout (binding = 0) uniform u
+{
+ mat4 matrix;
+};
+
+layout (std430, binding = 5) readonly buffer ssbo5
+{
+ float _float[];
+};
+
+layout (std140, binding = 3) readonly buffer ssbo3
+{
+ vec4 _vec4;
+};
+
+layout (std430, binding = 4) readonly buffer ssbo1
+{
+ bool _bool[];
+};
+
+layout (std430, binding = 1) readonly buffer unused1
+{
+ int unused[];
+}u1;
+
+
+void main()
+{
+
+ // some OpenGL implementations will optimize out the buffer variables if we don't use them
+ // resulting in a .length() of 0
+ float a = _float[0] == 0 && _bool[0] ? 1 : 1;
+
+ gl_Position = vec4(0);
+
+ if(_bool.length() == 32)
+ gl_Position = a * matrix * vec4(position*_vec4.xyz, _float.length() == 64 ? 1.0 : 0.0);
+
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb
new file mode 100644
index 0000000000..8b1cff52fd
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/storagebuffer_runtime.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb
new file mode 100644
index 0000000000..7eda4bed2d
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc
new file mode 100644
index 0000000000..92a2dc28fa
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc
@@ -0,0 +1,56 @@
+#version 440
+
+layout(vertices = 3) out;
+
+layout(location = 4) in VertOut
+{
+ vec3 v_color;
+ int a;
+ float b;
+}vOut[];
+
+layout(location = 5) out TescOutA {
+ vec3 color;
+ int id;
+}tcOutA[];
+
+layout(location = 10) out TescOutB {
+ vec2 some;
+ int other[3];
+ vec3 variables;
+}tcOutB[];
+
+layout(location = 2) patch out TescOutC {
+ vec3 stuff;
+ float more_stuff;
+}tcOutC;
+
+void main()
+{
+ // tesc builtin outputs
+ gl_TessLevelOuter[0] = 1.0;
+ gl_TessLevelOuter[1] = 2.0;
+ gl_TessLevelOuter[2] = 3.0;
+ gl_TessLevelOuter[3] = 4.0;
+ gl_TessLevelInner[0] = 5.0;
+ gl_TessLevelInner[1] = 6.0;
+
+ gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
+ gl_out[gl_InvocationID].gl_PointSize = 10 + gl_InvocationID;
+ gl_out[gl_InvocationID].gl_ClipDistance[0] = 20.0 + gl_InvocationID;
+ gl_out[gl_InvocationID].gl_ClipDistance[1] = 40.0 + gl_InvocationID;
+ gl_out[gl_InvocationID].gl_ClipDistance[2] = 60.0 + gl_InvocationID;
+ gl_out[gl_InvocationID].gl_ClipDistance[3] = 80.0 + gl_InvocationID;
+ gl_out[gl_InvocationID].gl_ClipDistance[4] = 100.0 + gl_InvocationID;
+
+ // outputs
+ tcOutA[gl_InvocationID].color = vOut[gl_InvocationID].v_color;
+ tcOutA[gl_InvocationID].id = gl_InvocationID + 91;
+ tcOutB[gl_InvocationID].some = vec2(gl_InvocationID, vOut[gl_InvocationID].a);
+ tcOutB[gl_InvocationID].other[0] = gl_PrimitiveID + 10;
+ tcOutB[gl_InvocationID].other[1] = gl_PrimitiveID + 20;
+ tcOutB[gl_InvocationID].other[2] = gl_PrimitiveID + 30;
+ tcOutB[gl_InvocationID].variables = vec3(3.0f, vOut[gl_InvocationID].b, 17.0f);
+ tcOutC.stuff = vec3(1.0, 2.0, 3.0);
+ tcOutC.more_stuff = 4.0;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb
new file mode 100644
index 0000000000..b503d596c6
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tesc.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese
new file mode 100644
index 0000000000..05430a5f63
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese
@@ -0,0 +1,96 @@
+#version 440
+
+layout(triangles, fractional_odd_spacing, ccw) in;
+
+layout(std140, binding = 0) uniform buf {
+ mat4 mvp;
+};
+
+layout(location = 5) in TescOutA {
+ vec3 color;
+ int id;
+}tcOutA[];
+
+layout(location = 10) in TescOutB {
+ vec2 some;
+ int other[3];
+ vec3 variables;
+}tcOutB[];
+
+layout(location = 2) patch in TescOutC {
+ vec3 stuff;
+ float more_stuff;
+}tcOutC;
+
+layout(location = 0) out vec3 outColor;
+
+struct A {
+ vec3 color;
+ int id;
+};
+
+struct B {
+ vec2 some;
+ int other[3];
+ vec3 variables;
+};
+
+struct C {
+ vec3 stuff;
+ float more_stuff;
+};
+
+struct Element {
+ A a[3];
+ B b[3];
+ C c;
+ vec4 tesslevelOuter;
+ vec2 tessLevelInner;
+ float pointSize[3];
+ float clipDistance[3][5];
+ vec3 tessCoord;
+ int patchVerticesIn;
+ int primitiveID;
+};
+
+layout(std430, binding = 1) buffer result {
+ int count;
+ Element elements[];
+};
+
+void main()
+{
+ gl_Position = mvp * ((gl_TessCoord.x * gl_in[0].gl_Position) + (gl_TessCoord.y * gl_in[1].gl_Position) + (gl_TessCoord.z * gl_in[2].gl_Position));
+ outColor = gl_TessCoord.x * tcOutA[0].color + gl_TessCoord.y * tcOutA[1].color + gl_TessCoord.z * tcOutA[2].color;
+
+ count = 1;
+
+ elements[gl_PrimitiveID].c.stuff = tcOutC.stuff;
+ elements[gl_PrimitiveID].c.more_stuff = tcOutC.more_stuff;
+ elements[gl_PrimitiveID].tesslevelOuter = vec4(gl_TessLevelOuter[0], gl_TessLevelOuter[1], gl_TessLevelOuter[2], gl_TessLevelOuter[3]);
+ elements[gl_PrimitiveID].tessLevelInner = vec2(gl_TessLevelInner[0], gl_TessLevelInner[1]);
+
+ for (int i = 0; i < 3; ++i) {
+
+ elements[gl_PrimitiveID].a[i].color = tcOutA[i].color;
+ elements[gl_PrimitiveID].a[i].id = tcOutA[i].id;
+
+ elements[gl_PrimitiveID].b[i].some = tcOutB[i].some;
+ elements[gl_PrimitiveID].b[i].other = tcOutB[i].other;
+ elements[gl_PrimitiveID].b[i].variables = tcOutB[i].variables;
+
+ elements[gl_PrimitiveID].pointSize[i] = gl_in[i].gl_PointSize;
+ elements[gl_PrimitiveID].clipDistance[i][0] = gl_in[i].gl_ClipDistance[0];
+ elements[gl_PrimitiveID].clipDistance[i][1] = gl_in[i].gl_ClipDistance[1];
+ elements[gl_PrimitiveID].clipDistance[i][2] = gl_in[i].gl_ClipDistance[2];
+ elements[gl_PrimitiveID].clipDistance[i][3] = gl_in[i].gl_ClipDistance[3];
+ elements[gl_PrimitiveID].clipDistance[i][4] = gl_in[i].gl_ClipDistance[4];
+
+ }
+
+ elements[gl_PrimitiveID].tessCoord = gl_TessCoord;
+ elements[gl_PrimitiveID].patchVerticesIn = 3;
+ elements[gl_PrimitiveID].primitiveID = gl_PrimitiveID;
+
+}
+
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb
new file mode 100644
index 0000000000..898bda454a
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.tese.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert
new file mode 100644
index 0000000000..7c722bb374
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert
@@ -0,0 +1,20 @@
+#version 440
+
+layout(location = 0) in vec3 position;
+layout(location = 1) in vec3 color;
+
+
+layout(location = 4) out VertOut
+{
+ vec3 v_color;
+ int a;
+ float b;
+};
+
+void main()
+{
+ gl_Position = vec4(position, 1.0);
+ v_color = color;
+ a = gl_VertexIndex;
+ b = 13.0f + gl_VertexIndex;
+}
diff --git a/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb
new file mode 100644
index 0000000000..07384d643c
--- /dev/null
+++ b/tests/auto/gui/rhi/qrhi/data/tessinterfaceblocks.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qrhi/qrhi.qrc b/tests/auto/gui/rhi/qrhi/qrhi.qrc
deleted file mode 100644
index f161d8aad6..0000000000
--- a/tests/auto/gui/rhi/qrhi/qrhi.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>data</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
index 24d6ad2d7c..8929b69cec 100644
--- a/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
+++ b/tests/auto/gui/rhi/qrhi/tst_qrhi.cpp
@@ -1,62 +1,36 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QThread>
#include <QFile>
#include <QOffscreenSurface>
#include <QPainter>
+#include <qrgbafloat.h>
+#include <qrgba64.h>
-#include <QtGui/private/qrhi_p.h>
-#include <QtGui/private/qrhi_p_p.h>
-#include <QtGui/private/qrhinull_p.h>
+#include <private/qrhi_p.h>
#if QT_CONFIG(opengl)
# include <QOpenGLContext>
# include <QOpenGLFunctions>
-# include <QtGui/private/qrhigles2_p.h>
+# include <QtGui/private/qguiapplication_p.h>
+# include <qpa/qplatformintegration.h>
# define TST_GL
#endif
#if QT_CONFIG(vulkan)
# include <QVulkanInstance>
# include <QVulkanFunctions>
-# include <QtGui/private/qrhivulkan_p.h>
# define TST_VK
#endif
#ifdef Q_OS_WIN
-#include <QtGui/private/qrhid3d11_p.h>
# define TST_D3D11
+# define TST_D3D12
#endif
-#if defined(Q_OS_MACOS) || defined(Q_OS_IOS)
-# include <QtGui/private/qrhimetal_p.h>
+#if QT_CONFIG(metal)
# define TST_MTL
#endif
@@ -72,9 +46,10 @@ private slots:
void cleanupTestCase();
void rhiTestData();
- void rhiTestDataOpenGL();
void create_data();
void create();
+ void stats_data();
+ void stats();
void nativeHandles_data();
void nativeHandles();
void nativeHandlesImportVulkan();
@@ -96,6 +71,8 @@ private slots:
void resourceUpdateBatchTextureRawDataStride();
void resourceUpdateBatchLotsOfResources_data();
void resourceUpdateBatchLotsOfResources();
+ void resourceUpdateBatchBetweenFrames_data();
+ void resourceUpdateBatchBetweenFrames();
void invalidPipeline_data();
void invalidPipeline();
void srbLayoutCompatibility_data();
@@ -106,6 +83,8 @@ private slots:
void renderPassDescriptorCompatibility();
void renderPassDescriptorClone_data();
void renderPassDescriptorClone();
+ void textureWithSampleCount_data();
+ void textureWithSampleCount();
void renderToTextureSimple_data();
void renderToTextureSimple();
@@ -113,8 +92,12 @@ private slots:
void renderToTextureMip();
void renderToTextureCubemapFace_data();
void renderToTextureCubemapFace();
+ void renderToTextureTextureArray_data();
+ void renderToTextureTextureArray();
void renderToTextureTexturedQuad_data();
void renderToTextureTexturedQuad();
+ void renderToTextureSampleWithSeparateTextureAndSampler_data();
+ void renderToTextureSampleWithSeparateTextureAndSampler();
void renderToTextureArrayOfTexturedQuad_data();
void renderToTextureArrayOfTexturedQuad();
void renderToTextureTexturedQuadAndUniformBuffer_data();
@@ -123,28 +106,57 @@ private slots:
void renderToTextureTexturedQuadAllDynamicBuffers();
void renderToTextureDeferredSrb_data();
void renderToTextureDeferredSrb();
+ void renderToTextureDeferredUpdateSamplerInSrb_data();
+ void renderToTextureDeferredUpdateSamplerInSrb();
void renderToTextureMultipleUniformBuffersAndDynamicOffset_data();
void renderToTextureMultipleUniformBuffersAndDynamicOffset();
void renderToTextureSrbReuse_data();
void renderToTextureSrbReuse();
void renderToTextureIndexedDraw_data();
void renderToTextureIndexedDraw();
+ void renderToTextureArrayMultiView_data();
+ void renderToTextureArrayMultiView();
void renderToWindowSimple_data();
void renderToWindowSimple();
void finishWithinSwapchainFrame_data();
void finishWithinSwapchainFrame();
+ void resourceUpdateBatchBufferTextureWithSwapchainFrames_data();
+ void resourceUpdateBatchBufferTextureWithSwapchainFrames();
+ void textureRenderTargetAutoRebuild_data();
+ void textureRenderTargetAutoRebuild();
void pipelineCache_data();
void pipelineCache();
- void textureImportOpenGL_data();
void textureImportOpenGL();
- void renderbufferImportOpenGL_data();
void renderbufferImportOpenGL();
void threeDimTexture_data();
void threeDimTexture();
+ void oneDimTexture_data();
+ void oneDimTexture();
void leakedResourceDestroy_data();
void leakedResourceDestroy();
+ void renderToFloatTexture_data();
+ void renderToFloatTexture();
+ void renderToRgb10Texture_data();
+ void renderToRgb10Texture();
+
+ void tessellation_data();
+ void tessellation();
+
+ void tessellationInterfaceBlocks_data();
+ void tessellationInterfaceBlocks();
+
+ void storageBuffer_data();
+ void storageBuffer();
+ void storageBufferRuntimeSizeCompute_data();
+ void storageBufferRuntimeSizeCompute();
+ void storageBufferRuntimeSizeGraphics_data();
+ void storageBufferRuntimeSizeGraphics();
+
+ void halfPrecisionAttributes_data();
+ void halfPrecisionAttributes();
+
private:
void setWindowType(QWindow *window, QRhi::Implementation impl);
@@ -157,7 +169,10 @@ private:
QRhiVulkanInitParams vk;
#endif
#ifdef TST_D3D11
- QRhiD3D11InitParams d3d;
+ QRhiD3D11InitParams d3d11;
+#endif
+#ifdef TST_D3D12
+ QRhiD3D12InitParams d3d12;
#endif
#ifdef TST_MTL
QRhiMetalInitParams mtl;
@@ -173,6 +188,12 @@ private:
void tst_QRhi::initTestCase()
{
#ifdef TST_GL
+ QSurfaceFormat fmt;
+ fmt.setDepthBufferSize(24);
+ fmt.setStencilBufferSize(8);
+ QSurfaceFormat::setDefaultFormat(fmt);
+
+ initParams.gl.format = QSurfaceFormat::defaultFormat();
fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
initParams.gl.fallbackSurface = fallbackSurface;
#endif
@@ -182,7 +203,7 @@ void tst_QRhi::initTestCase()
if (supportedVersion >= QVersionNumber(1, 2))
vulkanInstance.setApiVersion(QVersionNumber(1, 2));
else if (supportedVersion >= QVersionNumber(1, 1))
- vulkanInstance.setApiVersion(QVersionNumber(1, 2));
+ vulkanInstance.setApiVersion(QVersionNumber(1, 1));
vulkanInstance.setLayers({ "VK_LAYER_KHRONOS_validation" });
vulkanInstance.setExtensions(QRhiVulkanInitParams::preferredInstanceExtensions());
vulkanInstance.create();
@@ -190,7 +211,10 @@ void tst_QRhi::initTestCase()
#endif
#ifdef TST_D3D11
- initParams.d3d.enableDebugLayer = true;
+ initParams.d3d11.enableDebugLayer = true;
+#endif
+#ifdef TST_D3D12
+ initParams.d3d12.enableDebugLayer = true;
#endif
}
@@ -208,32 +232,29 @@ void tst_QRhi::rhiTestData()
QTest::addColumn<QRhi::Implementation>("impl");
QTest::addColumn<QRhiInitParams *>("initParams");
+// webOS does not support raster (software) pipeline
+#ifndef Q_OS_WEBOS
QTest::newRow("Null") << QRhi::Null << static_cast<QRhiInitParams *>(&initParams.null);
+#endif
#ifdef TST_GL
- QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl);
+ if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
+ QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl);
#endif
#ifdef TST_VK
if (vulkanInstance.isValid())
QTest::newRow("Vulkan") << QRhi::Vulkan << static_cast<QRhiInitParams *>(&initParams.vk);
#endif
#ifdef TST_D3D11
- QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d);
+ QTest::newRow("Direct3D 11") << QRhi::D3D11 << static_cast<QRhiInitParams *>(&initParams.d3d11);
+#endif
+#ifdef TST_D3D12
+ QTest::newRow("Direct3D 12") << QRhi::D3D12 << static_cast<QRhiInitParams *>(&initParams.d3d12);
#endif
#ifdef TST_MTL
QTest::newRow("Metal") << QRhi::Metal << static_cast<QRhiInitParams *>(&initParams.mtl);
#endif
}
-void tst_QRhi::rhiTestDataOpenGL()
-{
- QTest::addColumn<QRhi::Implementation>("impl");
- QTest::addColumn<QRhiInitParams *>("initParams");
-
-#ifdef TST_GL
- QTest::newRow("OpenGL") << QRhi::OpenGLES2 << static_cast<QRhiInitParams *>(&initParams.gl);
-#endif
-}
-
void tst_QRhi::create_data()
{
rhiTestData();
@@ -256,10 +277,13 @@ void tst_QRhi::create()
QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
if (rhi) {
+ QVERIFY(QRhi::probe(impl, initParams));
+
qDebug() << rhi->driverInfo();
QCOMPARE(rhi->backend(), impl);
QVERIFY(strcmp(rhi->backendName(), ""));
+ QVERIFY(!strcmp(rhi->backendName(), QRhi::backendName(rhi->backend())));
QVERIFY(!rhi->driverInfo().deviceName.isEmpty());
QCOMPARE(rhi->thread(), QThread::currentThread());
@@ -294,8 +318,13 @@ void tst_QRhi::create()
QVERIFY(resUpd);
resUpd->release();
- QVERIFY(!rhi->supportedSampleCounts().isEmpty());
- QVERIFY(rhi->supportedSampleCounts().contains(1));
+ const QVector<int> supportedSampleCounts = rhi->supportedSampleCounts();
+ QVERIFY(!supportedSampleCounts.isEmpty());
+ QVERIFY(supportedSampleCounts.contains(1));
+ for (int i = 1; i < supportedSampleCounts.count(); ++i) {
+ // Verify the list is sorted. Internally the backends rely on this.
+ QVERIFY(supportedSampleCounts[i] > supportedSampleCounts[i - 1]);
+ }
QVERIFY(rhi->ubufAlignment() > 0);
QCOMPARE(rhi->ubufAligned(123), aligned(123, rhi->ubufAlignment()));
@@ -336,13 +365,22 @@ void tst_QRhi::create()
const int texMax = rhi->resourceLimit(QRhi::TextureSizeMax);
const int maxAtt = rhi->resourceLimit(QRhi::MaxColorAttachments);
const int framesInFlight = rhi->resourceLimit(QRhi::FramesInFlight);
+ const int texArrayMax = rhi->resourceLimit(QRhi::TextureArraySizeMax);
+ const int uniBufRangeMax = rhi->resourceLimit(QRhi::MaxUniformBufferRange);
+ const int maxVertexInputs = rhi->resourceLimit(QRhi::MaxVertexInputs);
+ const int maxVertexOutputs = rhi->resourceLimit(QRhi::MaxVertexOutputs);
+
QVERIFY(texMin >= 1);
QVERIFY(texMax >= texMin);
QVERIFY(maxAtt >= 1);
QVERIFY(framesInFlight >= 1);
+ if (rhi->isFeatureSupported(QRhi::TextureArrays))
+ QVERIFY(texArrayMax > 1);
+ QVERIFY(uniBufRangeMax >= 224 * 4 * 4);
+ QVERIFY(maxVertexInputs >= 8);
+ QVERIFY(maxVertexOutputs >= 8);
QVERIFY(rhi->nativeHandles());
- QVERIFY(rhi->profiler());
const QRhi::Feature features[] = {
QRhi::MultisampleTexture,
@@ -373,7 +411,21 @@ void tst_QRhi::create()
QRhi::PipelineCacheDataLoadSave,
QRhi::ImageDataStride,
QRhi::RenderBufferImport,
- QRhi::ThreeDimensionalTextures
+ QRhi::ThreeDimensionalTextures,
+ QRhi::RenderTo3DTextureSlice,
+ QRhi::TextureArrays,
+ QRhi::Tessellation,
+ QRhi::GeometryShader,
+ QRhi::TextureArrayRange,
+ QRhi::NonFillPolygonMode,
+ QRhi::OneDimensionalTextures,
+ QRhi::OneDimensionalTextureMipmaps,
+ QRhi::HalfAttributes,
+ QRhi::RenderToOneDimensionalTexture,
+ QRhi::ThreeDimensionalTextureMipmaps,
+ QRhi::MultiView,
+ QRhi::TextureViewFormat,
+ QRhi::ResolveDepthStencil
};
for (size_t i = 0; i <sizeof(features) / sizeof(QRhi::Feature); ++i)
rhi->isFeatureSupported(features[i]);
@@ -389,6 +441,38 @@ void tst_QRhi::create()
}
}
+void tst_QRhi::stats_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::stats()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing statistics getter");
+
+ QRhiStats stats = rhi->statistics();
+ qDebug() << stats;
+ QCOMPARE(stats.totalPipelineCreationTime, 0);
+
+ if (impl == QRhi::Vulkan) {
+ QScopedPointer<QRhiBuffer> buf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, 32768));
+ QVERIFY(buf->create());
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(1024, 1024)));
+ QVERIFY(tex->create());
+
+ stats = rhi->statistics();
+ qDebug() << stats;
+ QVERIFY(stats.allocCount > 0);
+ QVERIFY(stats.blockCount > 0);
+ QVERIFY(stats.usedBytes > 0);
+ }
+}
+
void tst_QRhi::nativeHandles_data()
{
rhiTestData();
@@ -415,10 +499,10 @@ void tst_QRhi::nativeHandles()
case QRhi::Vulkan:
{
const QRhiVulkanNativeHandles *vkHandles = static_cast<const QRhiVulkanNativeHandles *>(rhiHandles);
+ QVERIFY(vkHandles->inst);
+ QCOMPARE(vkHandles->inst, &vulkanInstance);
QVERIFY(vkHandles->physDev);
QVERIFY(vkHandles->dev);
- QVERIFY(vkHandles->gfxQueueFamilyIdx >= 0);
- QVERIFY(vkHandles->gfxQueueIdx >= 0);
QVERIFY(vkHandles->gfxQueue);
QVERIFY(vkHandles->vmemAllocator);
}
@@ -448,6 +532,17 @@ void tst_QRhi::nativeHandles()
}
break;
#endif
+#ifdef TST_D3D12
+ case QRhi::D3D12:
+ {
+ const QRhiD3D12NativeHandles *d3dHandles = static_cast<const QRhiD3D12NativeHandles *>(rhiHandles);
+ QVERIFY(d3dHandles->dev);
+ QVERIFY(d3dHandles->minimumFeatureLevel > 0);
+ QVERIFY(d3dHandles->adapterLuidLow || d3dHandles->adapterLuidHigh);
+ QVERIFY(d3dHandles->commandQueue);
+ }
+ break;
+#endif
#ifdef TST_MTL
case QRhi::Metal:
{
@@ -492,6 +587,10 @@ void tst_QRhi::nativeHandles()
case QRhi::D3D11:
break;
#endif
+#ifdef TST_D3D12
+ case QRhi::D3D12:
+ break;
+#endif
#ifdef TST_MTL
case QRhi::Metal:
{
@@ -551,6 +650,10 @@ void tst_QRhi::nativeHandles()
case QRhi::D3D11:
break;
#endif
+#ifdef TST_D3D12
+ case QRhi::D3D12:
+ break;
+#endif
#ifdef TST_MTL
case QRhi::Metal:
break;
@@ -618,7 +721,7 @@ void tst_QRhi::nativeHandlesImportVulkan()
void tst_QRhi::nativeHandlesImportD3D11()
{
#ifdef TST_D3D11
- QScopedPointer<QRhi> rhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), nullptr));
+ QScopedPointer<QRhi> rhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), nullptr));
if (!rhi)
QSKIP("QRhi could not be created, skipping testing D3D11 native handle import");
@@ -630,7 +733,7 @@ void tst_QRhi::nativeHandlesImportD3D11()
h.featureLevel = 0; // see if these are queried as expected, even when not provided
h.adapterLuidLow = 0;
h.adapterLuidHigh = 0;
- QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), &h));
+ QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), &h));
QVERIFY(adoptingRhi);
const QRhiD3D11NativeHandles *newNativeHandles = static_cast<const QRhiD3D11NativeHandles *>(adoptingRhi->nativeHandles());
QCOMPARE(newNativeHandles->dev, nativeHandles->dev);
@@ -645,7 +748,7 @@ void tst_QRhi::nativeHandlesImportD3D11()
QRhiD3D11NativeHandles h = *nativeHandles;
h.dev = nullptr;
h.context = nullptr;
- QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d, QRhi::Flags(), &h));
+ QScopedPointer<QRhi> adoptingRhi(QRhi::create(QRhi::D3D11, &initParams.d3d11, QRhi::Flags(), &h));
QVERIFY(adoptingRhi);
const QRhiD3D11NativeHandles *newNativeHandles = static_cast<const QRhiD3D11NativeHandles *>(adoptingRhi->nativeHandles());
QVERIFY(newNativeHandles->dev != nativeHandles->dev);
@@ -665,7 +768,6 @@ void tst_QRhi::nativeHandlesImportOpenGL()
#ifdef TST_GL
QRhiGles2NativeHandles h;
QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext);
- ctx->setFormat(QRhiGles2InitParams::adjustedFormat());
if (!ctx->create())
QSKIP("No OpenGL context, skipping OpenGL-specific test");
h.context = ctx.data();
@@ -731,6 +833,14 @@ void tst_QRhi::nativeTexture()
}
break;
#endif
+#ifdef TST_D3D12
+ case QRhi::D3D12:
+ {
+ auto *texture = reinterpret_cast<void *>(nativeTex.object);
+ QVERIFY(texture);
+ }
+ break;
+#endif
#ifdef TST_MTL
case QRhi::Metal:
{
@@ -806,6 +916,18 @@ void tst_QRhi::nativeBuffer()
}
break;
#endif
+ #ifdef TST_D3D12
+ case QRhi::D3D12:
+ {
+ QVERIFY(nativeBuf.slotCount >= 1); // always backed by native buffers
+ for (int i = 0; i < nativeBuf.slotCount; ++i) {
+ auto *buffer = static_cast<void * const *>(nativeBuf.objects[i]);
+ QVERIFY(buffer);
+ QVERIFY(*buffer);
+ }
+ }
+ break;
+ #endif
#ifdef TST_MTL
case QRhi::Metal:
{
@@ -870,7 +992,7 @@ void tst_QRhi::resourceUpdateBatchBuffer()
batch->updateDynamicBuffer(dynamicBuffer.data(), 10, bufferSize - 10, a.constData());
batch->updateDynamicBuffer(dynamicBuffer.data(), 0, 12, b.constData());
- QRhiBufferReadbackResult readResult;
+ QRhiReadbackResult readResult;
bool readCompleted = false;
readResult.completed = [&readCompleted] { readCompleted = true; };
batch->readBackBuffer(dynamicBuffer.data(), 5, 10, &readResult);
@@ -897,12 +1019,14 @@ void tst_QRhi::resourceUpdateBatchBuffer()
batch->uploadStaticBuffer(dynamicBuffer.data(), 10, bufferSize - 10, a.constData());
batch->uploadStaticBuffer(dynamicBuffer.data(), 0, 12, b.constData());
- QRhiBufferReadbackResult readResult;
+ QRhiReadbackResult readResult;
bool readCompleted = false;
readResult.completed = [&readCompleted] { readCompleted = true; };
if (rhi->isFeatureSupported(QRhi::ReadBackNonUniformBuffer))
batch->readBackBuffer(dynamicBuffer.data(), 5, 10, &readResult);
+ else
+ qDebug("Skipping verification of buffer data as ReadBackNonUniformBuffer is not supported");
QVERIFY(submitResourceUpdates(rhi.data(), batch));
@@ -1004,7 +1128,7 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload()
QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
- QRhiTextureUploadEntry upload(0, 0, { image.constBits(), int(image.sizeInBytes()) });
+ QRhiTextureUploadEntry upload(0, 0, { image.constBits(), quint32(image.sizeInBytes()) });
QRhiTextureUploadDescription uploadDesc(upload);
batch->uploadTexture(texture.data(), uploadDesc);
@@ -1092,8 +1216,8 @@ void tst_QRhi::resourceUpdateBatchRGBATextureUpload()
// SourceTopLeft is not supported for non-QImage-based uploads.
const QImage im = image.copy(QRect(greenRectPos, copySize));
QRhiTextureSubresourceUploadDescription desc;
- desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()),
- int(im.sizeInBytes())));
+ desc.setData(QByteArray::fromRawData(reinterpret_cast<const char *>(im.constBits()), im.sizeInBytes()));
+
desc.setSourceSize(copySize);
desc.setDestinationTopLeft(QPoint(gap, gap));
@@ -1417,6 +1541,86 @@ void tst_QRhi::resourceUpdateBatchLotsOfResources()
submitResourceUpdates(rhi.data(), b);
}
+void tst_QRhi::resourceUpdateBatchBetweenFrames_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::resourceUpdateBatchBetweenFrames()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing resource updates");
+
+ QImage image(128, 128, QImage::Format_RGBA8888_Premultiplied);
+ image.fill(Qt::red);
+ static const float bufferData[64] = {};
+
+ QRhiCommandBuffer *cb = nullptr;
+ QRhi::FrameOpResult result = rhi->beginOffscreenFrame(&cb);
+ QVERIFY(result == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ static const int TEXTURE_COUNT = 123;
+ static const int BUFFER_COUNT = 456;
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ std::vector<std::unique_ptr<QRhiTexture>> textures;
+ std::vector<std::unique_ptr<QRhiBuffer>> buffers;
+
+ for (int i = 0; i < TEXTURE_COUNT; ++i) {
+ std::unique_ptr<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8,
+ image.size(),
+ 1,
+ QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+ u->uploadTexture(texture.get(), image);
+ textures.push_back(std::move(texture));
+ }
+
+ for (int i = 0; i < BUFFER_COUNT; ++i) {
+ std::unique_ptr<QRhiBuffer> buffer(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, 256));
+ QVERIFY(buffer->create());
+ u->uploadStaticBuffer(buffer.get(), bufferData);
+ buffers.push_back(std::move(buffer));
+ }
+
+ rhi->endOffscreenFrame();
+ cb = nullptr;
+
+ // 'u' stays valid, commit it in another frame
+
+ result = rhi->beginOffscreenFrame(&cb);
+ QVERIFY(result == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ cb->resourceUpdate(u); // this should work
+
+ rhi->endOffscreenFrame();
+
+ u = rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult readResult;
+ bool readCompleted = false;
+ readResult.completed = [&readCompleted] { readCompleted = true; };
+ u->readBackTexture(textures[5].get(), &readResult);
+
+ QVERIFY(submitResourceUpdates(rhi.data(), u));
+ QVERIFY(readCompleted);
+ QCOMPARE(readResult.format, QRhiTexture::RGBA8);
+ QCOMPARE(readResult.pixelSize, image.size());
+
+ QImage wrapperImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888_Premultiplied);
+ for (int y = 0; y < image.height(); ++y) {
+ for (int x = 0; x < image.width(); ++x)
+ QCOMPARE(wrapperImage.pixel(x, y), qRgba(255, 0, 0, 255));
+ }
+}
+
static QShader loadShader(const char *name)
{
QFile f(QString::fromUtf8(name));
@@ -1518,6 +1722,31 @@ void tst_QRhi::renderToTextureSimple_data()
rhiTestData();
}
+static QRhiGraphicsPipeline *createSimplePipeline(QRhi *rhi, QRhiShaderResourceBindings *srb, QRhiRenderPassDescriptor *rpDesc)
+{
+ std::unique_ptr<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+ QShader vs = loadShader(":/data/simple.vert.qsb");
+ if (!vs.isValid())
+ return nullptr;
+ QShader fs = loadShader(":/data/simple.frag.qsb");
+ if (!fs.isValid())
+ return nullptr;
+ pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 2 * sizeof(float) } });
+ inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb);
+ pipeline->setRenderPassDescriptor(rpDesc);
+ return pipeline->create() ? pipeline.release() : nullptr;
+}
+
+static const float triangleVertices[] = {
+ -1.0f, -1.0f,
+ 1.0f, -1.0f,
+ 0.0f, 1.0f
+};
+
void tst_QRhi::renderToTextureSimple()
{
QFETCH(QRhi::Implementation, impl);
@@ -1543,32 +1772,15 @@ void tst_QRhi::renderToTextureSimple()
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
-
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
cb->setGraphicsPipeline(pipeline.data());
@@ -1670,32 +1882,15 @@ void tst_QRhi::renderToTextureMip()
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
-
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
cb->setGraphicsPipeline(pipeline.data());
@@ -1792,32 +1987,15 @@ void tst_QRhi::renderToTextureCubemapFace()
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
-
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
cb->setGraphicsPipeline(pipeline.data());
@@ -1880,6 +2058,116 @@ void tst_QRhi::renderToTextureCubemapFace()
QFAIL("Encountered a pixel that is neither red or blue");
}
+ QVERIFY(redCount > 0 && blueCount > 0);
+ QCOMPARE(redCount + blueCount, outputSize.width());
+
+ if (rhi->isYUpInFramebuffer() == rhi->isYUpInNDC())
+ QVERIFY(redCount < blueCount); // 100, 412
+ else
+ QVERIFY(redCount > blueCount); // 412, 100
+}
+
+void tst_QRhi::renderToTextureTextureArray_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToTextureTextureArray()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::TextureArrays))
+ QSKIP("TextureArrays is not supported with this backend, skipping test");
+
+ const QSize outputSize(512, 256);
+ const int ARRAY_SIZE = 8;
+ QScopedPointer<QRhiTexture> texture(rhi->newTextureArray(QRhiTexture::RGBA8,
+ ARRAY_SIZE,
+ outputSize,
+ 1,
+ QRhiTexture::RenderTarget
+ | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ const int LAYER = 5; // render into element #5
+
+ QRhiColorAttachment colorAtt(texture.data());
+ colorAtt.setLayer(LAYER);
+ QRhiTextureRenderTargetDescription rtDesc(colorAtt);
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QCOMPARE(rt->pixelSize(), texture->pixelSize());
+ QCOMPARE(rt->pixelSize(), outputSize);
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
+
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ QRhiReadbackDescription readbackDescription(texture.data());
+ readbackDescription.setLayer(LAYER);
+ readbackBatch->readBackTexture(readbackDescription, &readResult);
+
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ QCOMPARE(result.size(), outputSize);
+
+ if (impl == QRhi::Null)
+ return;
+
+ const int y = 100;
+ const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y));
+ int x = result.width() - 1;
+ int redCount = 0;
+ int blueCount = 0;
+ const int maxFuzz = 1;
+ while (x-- >= 0) {
+ const QRgb c(*p++);
+ if (qRed(c) >= (255 - maxFuzz) && qGreen(c) == 0 && qBlue(c) == 0)
+ ++redCount;
+ else if (qRed(c) == 0 && qGreen(c) == 0 && qBlue(c) >= (255 - maxFuzz))
+ ++blueCount;
+ else
+ QFAIL("Encountered a pixel that is neither red or blue");
+ }
+
+ QVERIFY(redCount > 0 && blueCount > 0);
QCOMPARE(redCount + blueCount, outputSize.width());
if (rhi->isYUpInFramebuffer() == rhi->isYUpInNDC())
@@ -2018,6 +2306,131 @@ void tst_QRhi::renderToTextureTexturedQuad()
QVERIFY(qGreen(result.pixel(214, 191)) > 2 * qBlue(result.pixel(214, 191)));
}
+void tst_QRhi::renderToTextureSampleWithSeparateTextureAndSampler_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToTextureSampleWithSeparateTextureAndSampler()
+{
+ // Same as renderToTextureTexturedQuad but the fragment shader uses a
+ // separate image and sampler. For Vulkan/Metal/D3D11 these are natively
+ // supported. For OpenGL this exercises the auto-generated combined sampler
+ // in the GLSL code and the mapping table that gets applied at run time by
+ // the backend.
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ QImage inputImage;
+ inputImage.load(QLatin1String(":/data/qt256.png"));
+ QVERIFY(!inputImage.isNull());
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size(), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(quadVerticesUvs)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), quadVerticesUvs);
+
+ QScopedPointer<QRhiTexture> inputTexture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size()));
+ QVERIFY(inputTexture->create());
+ updates->uploadTexture(inputTexture.data(), inputImage);
+
+ QScopedPointer<QRhiSampler> sampler(rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ QVERIFY(sampler->create());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({
+ QRhiShaderResourceBinding::texture(3, QRhiShaderResourceBinding::FragmentStage, inputTexture.data()),
+ QRhiShaderResourceBinding::sampler(5, QRhiShaderResourceBinding::FragmentStage, sampler.data())
+ });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+ pipeline->setTopology(QRhiGraphicsPipeline::TriangleStrip);
+ QShader vs = loadShader(":/data/simpletextured.vert.qsb");
+ QVERIFY(vs.isValid());
+ QShader fs = loadShader(":/data/simpletextured_separate.frag.qsb");
+ QVERIFY(fs.isValid());
+ pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 4 * sizeof(float) } });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
+ });
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+
+ QVERIFY(pipeline->create());
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setShaderResources();
+ cb->setViewport({ 0, 0, float(texture->pixelSize().width()), float(texture->pixelSize().height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(4);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888_Premultiplied);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ QVERIFY(!result.isNull());
+
+ if (impl == QRhi::Null)
+ return;
+
+ if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC())
+ result = std::move(result).mirrored();
+
+ QRgb white = qRgba(255, 255, 255, 255);
+ QCOMPARE(result.pixel(79, 77), white);
+ QCOMPARE(result.pixel(124, 81), white);
+ QCOMPARE(result.pixel(128, 149), white);
+ QCOMPARE(result.pixel(120, 189), white);
+ QCOMPARE(result.pixel(116, 185), white);
+
+ QRgb empty = qRgba(0, 0, 0, 0);
+ QCOMPARE(result.pixel(11, 45), empty);
+ QCOMPARE(result.pixel(246, 202), empty);
+ QCOMPARE(result.pixel(130, 18), empty);
+ QCOMPARE(result.pixel(4, 227), empty);
+
+ QVERIFY(qGreen(result.pixel(32, 52)) > 2 * qRed(result.pixel(32, 52)));
+ QVERIFY(qGreen(result.pixel(32, 52)) > 2 * qBlue(result.pixel(32, 52)));
+ QVERIFY(qGreen(result.pixel(214, 191)) > 2 * qRed(result.pixel(214, 191)));
+ QVERIFY(qGreen(result.pixel(214, 191)) > 2 * qBlue(result.pixel(214, 191)));
+}
+
void tst_QRhi::renderToTextureArrayOfTexturedQuad_data()
{
rhiTestData();
@@ -2696,6 +3109,147 @@ void tst_QRhi::renderToTextureDeferredSrb()
QCOMPARE(result.pixel(4, 227), empty);
}
+void tst_QRhi::renderToTextureDeferredUpdateSamplerInSrb_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToTextureDeferredUpdateSamplerInSrb()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ QImage inputImage;
+ inputImage.load(QLatin1String(":/data/qt256.png"));
+ QVERIFY(!inputImage.isNull());
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size(), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(quadVerticesUvs)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), quadVerticesUvs);
+
+ QScopedPointer<QRhiTexture> inputTexture(rhi->newTexture(QRhiTexture::RGBA8, inputImage.size()));
+ QVERIFY(inputTexture->create());
+ updates->uploadTexture(inputTexture.data(), inputImage);
+
+ QScopedPointer<QRhiSampler> sampler1(rhi->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::Linear,
+ QRhiSampler::Repeat, QRhiSampler::Repeat));
+ QVERIFY(sampler1->create());
+ QScopedPointer<QRhiSampler> sampler2(rhi->newSampler(QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
+ QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge));
+ QVERIFY(sampler2->create());
+
+ QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64 + 4));
+ QVERIFY(ubuf->create());
+
+ QMatrix4x4 matrix;
+ updates->updateDynamicBuffer(ubuf.data(), 0, 64, matrix.constData());
+ float opacity = 0.5f;
+ updates->updateDynamicBuffer(ubuf.data(), 64, 4, &opacity);
+
+ const QRhiShaderResourceBinding::StageFlags commonVisibility = QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage;
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, commonVisibility, ubuf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, inputTexture.data(), sampler1.data())
+ });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+ pipeline->setTopology(QRhiGraphicsPipeline::TriangleStrip);
+ QShader vs = loadShader(":/data/textured.vert.qsb");
+ QVERIFY(vs.isValid());
+ QShader fs = loadShader(":/data/textured.frag.qsb");
+ QVERIFY(fs.isValid());
+ pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 4 * sizeof(float) } });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float2, 2 * sizeof(float) }
+ });
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+
+ QVERIFY(pipeline->create());
+
+ // Now update the sampler to a different one, so if the pipeline->create()
+ // baked in static samplers somewhere (with 3D APIs where that's a thing),
+ // based on sampler1, that's now all invalid.
+ srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, commonVisibility, ubuf.data()),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, inputTexture.data(), sampler2.data())
+ });
+ srb->updateResources(); // now it references sampler2, not sampler1
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setShaderResources();
+ cb->setViewport({ 0, 0, float(texture->pixelSize().width()), float(texture->pixelSize().height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(4);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888_Premultiplied);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ QVERIFY(!result.isNull());
+
+ if (impl == QRhi::Null)
+ return;
+
+ if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC())
+ result = std::move(result).mirrored();
+
+ // opacity 0.5 (premultiplied)
+ static const auto checkSemiWhite = [](const QRgb &c) {
+ QRgb semiWhite127 = qPremultiply(qRgba(255, 255, 255, 127));
+ QRgb semiWhite128 = qPremultiply(qRgba(255, 255, 255, 128));
+ return c == semiWhite127 || c == semiWhite128;
+ };
+ QVERIFY(checkSemiWhite(result.pixel(79, 77)));
+ QVERIFY(checkSemiWhite(result.pixel(124, 81)));
+ QVERIFY(checkSemiWhite(result.pixel(128, 149)));
+ QVERIFY(checkSemiWhite(result.pixel(120, 189)));
+ QVERIFY(checkSemiWhite(result.pixel(116, 185)));
+ QVERIFY(checkSemiWhite(result.pixel(191, 172)));
+
+ QRgb empty = qRgba(0, 0, 0, 0);
+ QCOMPARE(result.pixel(11, 45), empty);
+ QCOMPARE(result.pixel(246, 202), empty);
+ QCOMPARE(result.pixel(130, 18), empty);
+ QCOMPARE(result.pixel(4, 227), empty);
+}
+
void tst_QRhi::renderToTextureMultipleUniformBuffersAndDynamicOffset_data()
{
rhiTestData();
@@ -3013,7 +3567,6 @@ void tst_QRhi::setWindowType(QWindow *window, QRhi::Implementation impl)
switch (impl) {
#ifdef TST_GL
case QRhi::OpenGLES2:
- window->setFormat(QRhiGles2InitParams::adjustedFormat());
window->setSurfaceType(QSurface::OpenGLSurface);
break;
#endif
@@ -3064,18 +3617,13 @@ void tst_QRhi::renderToTextureIndexedDraw()
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
static const quint16 indices[] = {
0, 1, 2
};
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
QScopedPointer<QRhiBuffer> ibuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::IndexBuffer, sizeof(indices)));
QVERIFY(ibuf->create());
@@ -3084,20 +3632,8 @@ void tst_QRhi::renderToTextureIndexedDraw()
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
-
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
@@ -3171,6 +3707,182 @@ void tst_QRhi::renderToTextureIndexedDraw()
QVERIFY(redCount > blueCount);
}
+void tst_QRhi::renderToTextureArrayMultiView_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToTextureArrayMultiView()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::MultiView))
+ QSKIP("Multiview not supported, skipping testing on this backend");
+
+ if (rhi->backend() == QRhi::Vulkan && rhi->driverInfo().deviceType == QRhiDriverInfo::CpuDevice)
+ QSKIP("lavapipe does not like multiview, skip for now");
+
+ for (int sampleCount : rhi->supportedSampleCounts()) {
+ const QSize outputSize(1920, 1080);
+ QRhiTexture::Flags textureFlags = QRhiTexture::RenderTarget;
+ if (sampleCount <= 1)
+ textureFlags |= QRhiTexture::UsedAsTransferSource;
+ QScopedPointer<QRhiTexture> texture(rhi->newTextureArray(QRhiTexture::RGBA8, 2, outputSize, sampleCount, textureFlags));
+ QVERIFY(texture->create());
+
+ // exercise a depth-stencil buffer as well, not that the triangle needs it; note that this also needs to be a two-layer texture array
+ QScopedPointer<QRhiTexture> ds(rhi->newTextureArray(QRhiTexture::D24S8, 2, outputSize, sampleCount, QRhiTexture::RenderTarget));
+ QVERIFY(ds->create());
+
+ QScopedPointer<QRhiTexture> resolveTexture;
+ if (sampleCount > 1) {
+ resolveTexture.reset(rhi->newTextureArray(QRhiTexture::RGBA8, 2, outputSize, 1, QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(resolveTexture->create());
+ }
+
+ QRhiColorAttachment multiViewAtt(texture.get());
+ multiViewAtt.setMultiViewCount(2);
+ if (sampleCount > 1)
+ multiViewAtt.setResolveTexture(resolveTexture.get());
+
+ QRhiTextureRenderTargetDescription rtDesc(multiViewAtt);
+ rtDesc.setDepthTexture(ds.get());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ static float triangleData[] = {
+ 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,
+ -0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
+ 0.5f, -0.5f, 0.0f, 0.0f, 1.0f
+ };
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleData)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), triangleData);
+
+ QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 128)); // mat4 mvp[2]
+ QVERIFY(ubuf->create());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, ubuf.get())
+ });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> ps(rhi->newGraphicsPipeline());
+ ps->setShaderStages({
+ { QRhiShaderStage::Vertex, loadShader(":/data/multiview.vert.qsb") },
+ { QRhiShaderStage::Fragment, loadShader(":/data/multiview.frag.qsb") }
+ });
+ ps->setMultiViewCount(2); // the view count must be set both on the render target and the pipeline
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 5 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float2, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float3, quint32(2 * sizeof(float)) }
+ });
+ ps->setDepthTest(true);
+ ps->setDepthWrite(true);
+ ps->setSampleCount(sampleCount);
+ ps->setVertexInputLayout(inputLayout);
+ ps->setShaderResourceBindings(srb.get());
+ ps->setRenderPassDescriptor(rpDesc.get());
+ QVERIFY(ps->create());
+
+ QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix();
+ mvp.perspective(45.0f, outputSize.width() / float(outputSize.height()), 0.01f, 1000.0f);
+ mvp.translate(0, 0, -2);
+ mvp.rotate(90, 0, 0, 1); // point left
+ updates->updateDynamicBuffer(ubuf.get(), 0, 64, mvp.constData());
+ mvp.rotate(-180, 0, 0, 1); // point right
+ updates->updateDynamicBuffer(ubuf.get(), 64, 64, mvp.constData());
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(ps.data());
+ cb->setShaderResources();
+ cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(3);
+
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult readResult[2];
+ QRhiReadbackDescription readbackDesc;
+ if (sampleCount > 1)
+ readbackDesc.setTexture(resolveTexture.get());
+ else
+ readbackDesc.setTexture(texture.get());
+ readbackDesc.setLayer(0);
+ readbackBatch->readBackTexture(readbackDesc, &readResult[0]);
+ readbackDesc.setLayer(1);
+ readbackBatch->readBackTexture(readbackDesc, &readResult[1]);
+
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ if (rhi->backend() == QRhi::Null)
+ QSKIP("No real content with Null backend, skipping multiview content check");
+
+ // both readbacks should be finished now due to using offscreen frames
+
+ QImage image0 = QImage(reinterpret_cast<const uchar *>(readResult[0].data.constData()),
+ readResult[0].pixelSize.width(), readResult[0].pixelSize.height(),
+ QImage::Format_RGBA8888);
+ if (rhi->isYUpInFramebuffer()) // note that we used clipSpaceCorrMatrix
+ image0 = image0.mirrored();
+
+ QImage image1 = QImage(reinterpret_cast<const uchar *>(readResult[1].data.constData()),
+ readResult[1].pixelSize.width(), readResult[1].pixelSize.height(),
+ QImage::Format_RGBA8888);
+ if (rhi->isYUpInFramebuffer())
+ image1 = image1.mirrored();
+
+ QVERIFY(!image0.isNull());
+ QVERIFY(!image1.isNull());
+
+ // image0 should have a triangle rotated so that it points left with the red
+ // tip. image1 should have a triangle rotated so that it points right with
+ // the red tip. Both are centered, so we will check in range 0..width/2 for
+ // image0 and width/2..width-1 for image1 to see if the red-enough pixels
+ // are present.
+
+ int y = image0.height() / 2;
+ int n = 0;
+ for (int x = 0; x < image0.width() / 2; ++x) {
+ QRgb c = image0.pixel(x, y);
+ if (qRed(c) > 250 && qGreen(c) < 10 && qBlue(c) < 10)
+ ++n;
+ }
+ QVERIFY(n >= 10);
+
+ y = image1.height() / 2;
+ n = 0;
+ for (int x = image1.width() / 2; x < image1.width(); ++x) {
+ QRgb c = image1.pixel(x, y);
+ if (qRed(c) > 250 && qGreen(c) < 10 && qBlue(c) < 10)
+ ++n;
+ }
+ QVERIFY(n >= 10);
+ }
+}
+
void tst_QRhi::renderToWindowSimple_data()
{
rhiTestData();
@@ -3204,32 +3916,15 @@ void tst_QRhi::renderToWindowSimple()
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
-
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
const int asyncReadbackFrames = rhi->resourceLimit(QRhi::MaxAsyncReadbackFrames);
// one frame issues the readback, then we do MaxAsyncReadbackFrames more to ensure the readback completes
@@ -3243,6 +3938,9 @@ void tst_QRhi::renderToWindowSimple()
QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
QRhiRenderTarget *rt = swapChain->currentFrameRenderTarget();
+ QCOMPARE(rt->resourceType(), QRhiResource::SwapChainRenderTarget);
+ QVERIFY(rt->renderPassDescriptor());
+ QCOMPARE(static_cast<QRhiSwapChainRenderTarget *>(rt)->swapChain(), swapChain.data());
const QSize outputSize = swapChain->currentPixelSize();
QCOMPARE(rt->pixelSize(), outputSize);
QRhiViewport viewport(0, 0, float(outputSize.width()), float(outputSize.height()));
@@ -3343,26 +4041,10 @@ void tst_QRhi::finishWithinSwapchainFrame()
QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
QVERIFY(srb->create());
- QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
- QShader vs = loadShader(":/data/simple.vert.qsb");
- QVERIFY(vs.isValid());
- QShader fs = loadShader(":/data/simple.frag.qsb");
- QVERIFY(fs.isValid());
- pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
- QRhiVertexInputLayout inputLayout;
- inputLayout.setBindings({ { 2 * sizeof(float) } });
- inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float2, 0 } });
- pipeline->setVertexInputLayout(inputLayout);
- pipeline->setShaderResourceBindings(srb.data());
- pipeline->setRenderPassDescriptor(rpDesc.data());
- QVERIFY(pipeline->create());
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
- static const float vertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- 0.0f, 1.0f
- };
- QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
QVERIFY(vbuf->create());
// exercise begin/endExternal() just a little bit, note ExternalContent for beginPass()
@@ -3375,7 +4057,7 @@ void tst_QRhi::finishWithinSwapchainFrame()
// times within the same frame
for (int i = 0; i < 5; ++i) {
QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
- updates->uploadStaticBuffer(vbuf.data(), vertices);
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
cb->beginPass(rt, Qt::blue, { 1.0f, 0 }, updates, QRhiCommandBuffer::ExternalContent);
@@ -3419,6 +4101,277 @@ void tst_QRhi::finishWithinSwapchainFrame()
rhi->endFrame(swapChain.data());
}
+void tst_QRhi::resourceUpdateBatchBufferTextureWithSwapchainFrames_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::resourceUpdateBatchBufferTextureWithSwapchainFrames()
+{
+ if (QGuiApplication::platformName().startsWith(QLatin1String("offscreen"), Qt::CaseInsensitive))
+ QSKIP("Offscreen: Skipping onscreen test");
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing buffer resource updates");
+
+ QScopedPointer<QWindow> window(new QWindow);
+ setWindowType(window.data(), impl);
+
+ window->setGeometry(0, 0, 640, 480);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QScopedPointer<QRhiSwapChain> swapChain(rhi->newSwapChain());
+ swapChain->setWindow(window.data());
+ swapChain->setFlags(QRhiSwapChain::UsedAsTransferSource);
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(swapChain->newCompatibleRenderPassDescriptor());
+ swapChain->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(swapChain->createOrResize());
+
+ const int bufferSize = 18;
+ const char *a = "123456789";
+ const char *b = "abcdefghi";
+
+ bool readCompleted = false;
+ QRhiReadbackResult readResult;
+ readResult.completed = [&readCompleted] { readCompleted = true; };
+ QRhiReadbackResult texReadResult;
+ texReadResult.completed = [&readCompleted] { readCompleted = true; };
+
+ {
+ QScopedPointer<QRhiBuffer> dynamicBuffer(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, bufferSize));
+ QVERIFY(dynamicBuffer->create());
+
+ for (int i = 0; i < bufferSize; ++i) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+
+ // One byte every 16.66 ms should be enough for everyone: fill up
+ // the buffer with "123456789abcdefghi", one byte in each frame.
+ if (i >= bufferSize / 2)
+ batch->updateDynamicBuffer(dynamicBuffer.data(), i, 1, b + (i - bufferSize / 2));
+ else
+ batch->updateDynamicBuffer(dynamicBuffer.data(), i, 1, a + i);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ // just clear to black, but submit the resource update
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+ }
+
+ {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ readCompleted = false;
+ batch->readBackBuffer(dynamicBuffer.data(), 0, bufferSize, &readResult);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+
+ // This is a proper, typically at least double buffered renderer (as
+ // a real swapchain is involved). readCompleted may only become true
+ // in a future frame.
+ while (!readCompleted) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+ rhi->endFrame(swapChain.data());
+ }
+
+ QVERIFY(readResult.data.size() == bufferSize);
+ QCOMPARE(readResult.data.left(bufferSize / 2), QByteArray(a));
+ QCOMPARE(readResult.data.mid(bufferSize / 2), QByteArray(b));
+ }
+ }
+
+ // Repeat for types Immutable and Static, declare Vertex usage.
+ // This may not be readable on GLES 2.0 so skip the verification then.
+ for (QRhiBuffer::Type type : { QRhiBuffer::Immutable, QRhiBuffer::Static }) {
+ QScopedPointer<QRhiBuffer> buffer(rhi->newBuffer(type, QRhiBuffer::VertexBuffer, bufferSize));
+ QVERIFY(buffer->create());
+
+ for (int i = 0; i < bufferSize; ++i) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ if (i >= bufferSize / 2)
+ batch->uploadStaticBuffer(buffer.data(), i, 1, b + (i - bufferSize / 2));
+ else
+ batch->uploadStaticBuffer(buffer.data(), i, 1, a + i);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+ }
+
+ if (rhi->isFeatureSupported(QRhi::ReadBackNonUniformBuffer)) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ readCompleted = false;
+ batch->readBackBuffer(buffer.data(), 0, bufferSize, &readResult);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+
+ while (!readCompleted) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+ rhi->endFrame(swapChain.data());
+ }
+
+ QVERIFY(readResult.data.size() == bufferSize);
+ QCOMPARE(readResult.data.left(bufferSize / 2), QByteArray(a));
+ QCOMPARE(readResult.data.mid(bufferSize / 2), QByteArray(b));
+ } else {
+ qDebug("Skipping verification of buffer data as ReadBackNonUniformBuffer is not supported");
+ }
+ }
+
+ // Now exercise a texture. Internally this is expected (with low level APIs
+ // at least) to be similar to what happens with a staic buffer: copy to host
+ // visible staging buffer, enqueue buffer-to-buffer (or here
+ // buffer-to-image) copy.
+ {
+ const int w = 234;
+ const int h = 8; // use a small height because vsync throttling is active
+ const QColor colors[] = { Qt::red, Qt::green, Qt::blue, Qt::gray, Qt::yellow, Qt::black, Qt::white, Qt::magenta };
+ QImage image(w, h, QImage::Format_RGBA8888);
+ for (int i = 0; i < h; ++i) {
+ QRgb c = colors[i].rgb();
+ uchar *p = image.scanLine(i);
+ int x = w;
+ while (x--) {
+ *p++ = qRed(c);
+ *p++ = qGreen(c);
+ *p++ = qBlue(c);
+ *p++ = qAlpha(c);
+ }
+ }
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(w, h), 1, QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ // fill a texture from the image, two lines at a time
+ for (int i = 0; i < h / 2; ++i) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+
+ QRhiTextureSubresourceUploadDescription subresDesc(image);
+ subresDesc.setSourceSize(QSize(w, 2));
+ subresDesc.setSourceTopLeft(QPoint(0, i * 2));
+ subresDesc.setDestinationTopLeft(QPoint(0, i * 2));
+ QRhiTextureUploadDescription uploadDesc(QRhiTextureUploadEntry(0, 0, subresDesc));
+ batch->uploadTexture(texture.data(), uploadDesc);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+ }
+
+ {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ readCompleted = false;
+ batch->readBackTexture(texture.data(), &texReadResult);
+
+ QRhiCommandBuffer *cb = swapChain->currentFrameCommandBuffer();
+ cb->beginPass(swapChain->currentFrameRenderTarget(), Qt::black, { 1.0f, 0 }, batch);
+ cb->endPass();
+
+ rhi->endFrame(swapChain.data());
+
+ while (!readCompleted) {
+ QVERIFY(rhi->beginFrame(swapChain.data()) == QRhi::FrameOpSuccess);
+ rhi->endFrame(swapChain.data());
+ }
+
+ QCOMPARE(texReadResult.pixelSize, image.size());
+ QImage wrapperImage(reinterpret_cast<const uchar *>(texReadResult.data.constData()),
+ texReadResult.pixelSize.width(), texReadResult.pixelSize.height(),
+ image.format());
+ QVERIFY(imageRGBAEquals(image, wrapperImage));
+ }
+ }
+}
+
+void tst_QRhi::textureRenderTargetAutoRebuild_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::textureRenderTargetAutoRebuild()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ // case 1: beginPass's implicit create()
+ {
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget));
+ QVERIFY(texture->create());
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ { texture.data() } }));
+ QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rp.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+ cb->beginPass(rt.data(), Qt::red, { 1.0f, 0 });
+ cb->endPass();
+ rhi->endOffscreenFrame();
+
+ texture->setPixelSize(QSize(256, 256));
+ QVERIFY(texture->create());
+ QCOMPARE(texture->pixelSize(), QSize(256, 256));
+
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+ // no rt->create() but beginPass() does it implicitly for us
+ cb->beginPass(rt.data(), Qt::red, { 1.0f, 0 });
+ QCOMPARE(rt->pixelSize(), QSize(256, 256));
+ cb->endPass();
+ rhi->endOffscreenFrame();
+ }
+
+ // case 2: pixelSize's implicit create()
+ {
+ QSize sz(512, 512);
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, sz, 1, QRhiTexture::RenderTarget));
+ QVERIFY(texture->create());
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ { texture.data() } }));
+ QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rp.data());
+ QVERIFY(rt->create());
+ QCOMPARE(rt->pixelSize(), sz);
+
+ sz = QSize(256, 256);
+ texture->setPixelSize(sz);
+ QVERIFY(texture->create());
+ QCOMPARE(rt->pixelSize(), sz);
+ }
+}
+
void tst_QRhi::srbLayoutCompatibility_data()
{
rhiTestData();
@@ -3458,7 +4411,7 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(srb2->isLayoutCompatible(srb1.data()));
QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription());
- QVERIFY(srb1->serializedLayoutDescription().count() == 0);
+ QVERIFY(srb1->serializedLayoutDescription().size() == 0);
}
// different count (not compatible)
@@ -3476,8 +4429,8 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(!srb2->isLayoutCompatible(srb1.data()));
QVERIFY(srb1->serializedLayoutDescription() != srb2->serializedLayoutDescription());
- QVERIFY(srb1->serializedLayoutDescription().count() == 0);
- QVERIFY(srb2->serializedLayoutDescription().count() == 1 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
+ QVERIFY(srb1->serializedLayoutDescription().size() == 0);
+ QVERIFY(srb2->serializedLayoutDescription().size() == 1 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
}
// full match (compatible)
@@ -3502,7 +4455,7 @@ void tst_QRhi::srbLayoutCompatibility()
QVERIFY(!srb1->serializedLayoutDescription().isEmpty());
QVERIFY(!srb2->serializedLayoutDescription().isEmpty());
QCOMPARE(srb1->serializedLayoutDescription(), srb2->serializedLayoutDescription());
- QVERIFY(srb1->serializedLayoutDescription().count() == 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
+ QVERIFY(srb1->serializedLayoutDescription().size() == 2 * QRhiShaderResourceBinding::LAYOUT_DESC_ENTRIES_PER_BINDING);
// see what we would get if a binding list got serialized "manually", without pulling it out from the srb after building
// (the results should be identical)
@@ -3817,6 +4770,59 @@ void tst_QRhi::renderPassDescriptorCompatibility()
} else {
qDebug("Skipping texture format dependent tests");
}
+
+ if (rhi->isFeatureSupported(QRhi::MultiView)) {
+ {
+ QScopedPointer<QRhiTexture> texArr(rhi->newTextureArray(QRhiTexture::RGBA8, 2, QSize(512, 512), 1, QRhiTexture::RenderTarget));
+ QVERIFY(texArr->create());
+ QRhiColorAttachment multiViewAtt(texArr.data());
+ multiViewAtt.setMultiViewCount(2);
+ QRhiTextureRenderTargetDescription rtDesc(multiViewAtt);
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt2(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc2(rt2->newCompatibleRenderPassDescriptor());
+ rt2->setRenderPassDescriptor(rpDesc2.data());
+ QVERIFY(rt2->create());
+
+ QVERIFY(rpDesc->isCompatible(rpDesc2.data()));
+ QVERIFY(rpDesc2->isCompatible(rpDesc.data()));
+ QCOMPARE(rpDesc->serializedFormat(), rpDesc2->serializedFormat());
+
+ QScopedPointer<QRhiRenderPassDescriptor> rpDescClone(rpDesc->newCompatibleRenderPassDescriptor());
+ QVERIFY(rpDesc->isCompatible(rpDescClone.data()));
+ QVERIFY(rpDesc2->isCompatible(rpDescClone.data()));
+ QCOMPARE(rpDesc->serializedFormat(), rpDescClone->serializedFormat());
+
+ // With Vulkan the multiViewCount really matters since it is baked
+ // in to underlying native object (VkRenderPass). Verify that the
+ // compatibility check fails when the view count differs. Other
+ // backends cannot do this test since they will likely report the
+ // rps being compatible regardless.
+ if (impl == QRhi::Vulkan) {
+ QRhiColorAttachment nonMultiViewAtt(texArr.data());
+ QRhiTextureRenderTargetDescription rtDesc3(nonMultiViewAtt);
+ QScopedPointer<QRhiTextureRenderTarget> rt3(rhi->newTextureRenderTarget(rtDesc3));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc3(rt3->newCompatibleRenderPassDescriptor());
+ rt3->setRenderPassDescriptor(rpDesc3.data());
+ QVERIFY(rt3->create());
+
+ QVERIFY(!rpDesc->isCompatible(rpDesc3.data()));
+ QVERIFY(!rpDesc2->isCompatible(rpDesc3.data()));
+ QVERIFY(rpDesc->serializedFormat() != rpDesc3->serializedFormat());
+
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc3Clone(rpDesc3->newCompatibleRenderPassDescriptor());
+ QVERIFY(!rpDesc->isCompatible(rpDesc3Clone.data()));
+ QVERIFY(!rpDesc2->isCompatible(rpDesc3Clone.data()));
+ QVERIFY(rpDesc->serializedFormat() != rpDesc3Clone->serializedFormat());
+ }
+ }
+ } else {
+ qDebug("Skipping multiview dependent tests");
+ }
}
void tst_QRhi::renderPassDescriptorClone_data()
@@ -3934,22 +4940,67 @@ void tst_QRhi::pipelineCache()
}
}
-void tst_QRhi::textureImportOpenGL_data()
+void tst_QRhi::textureWithSampleCount_data()
{
- rhiTestDataOpenGL();
+ rhiTestData();
}
-void tst_QRhi::textureImportOpenGL()
+void tst_QRhi::textureWithSampleCount()
{
QFETCH(QRhi::Implementation, impl);
- if (impl != QRhi::OpenGLES2)
- QSKIP("Skipping OpenGL-dependent test");
-
-#ifdef TST_GL
QFETCH(QRhiInitParams *, initParams);
QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing renderpass descriptors");
+
+ if (!rhi->isFeatureSupported(QRhi::MultisampleTexture))
+ QSKIP("No multisample texture support with this backend, skipping");
+
+ {
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1));
+ QVERIFY(tex->create());
+ }
+
+ // Ensure 0 is accepted the same way as 1.
+ {
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 0));
+ QVERIFY(tex->create());
+ }
+
+ // Note that we intentionally do not pass in RenderTarget in flags. Where
+ // matters for create(), the backend is expected to act as if it was
+ // specified whenever samples > 1. (in practice it does not make sense to not
+ // have the flag for an msaa texture, but we only care about create() here)
+
+ // Pick the commonly supported sample count of 4.
+ {
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 4));
+ QVERIFY(tex->create());
+ }
+
+ // Now a bogus value that is typically in-between the supported values.
+ {
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 3));
+ QVERIFY(tex->create());
+ }
+
+ // Now a bogus value that is out of range.
+ {
+ QScopedPointer<QRhiTexture> tex(rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 123));
+ QVERIFY(tex->create());
+ }
+}
+
+
+void tst_QRhi::textureImportOpenGL()
+{
+#ifdef TST_GL
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
+ QSKIP("Skipping OpenGL-dependent test");
+
+ QScopedPointer<QRhi> rhi(QRhi::create(QRhi::OpenGLES2, &initParams.gl, QRhi::Flags(), nullptr));
+ if (!rhi)
QSKIP("QRhi could not be created, skipping testing native texture");
QVERIFY(rhi->makeThreadLocalNativeContextCurrent());
@@ -3988,21 +5039,13 @@ void tst_QRhi::textureImportOpenGL()
#endif
}
-void tst_QRhi::renderbufferImportOpenGL_data()
-{
- rhiTestDataOpenGL();
-}
-
void tst_QRhi::renderbufferImportOpenGL()
{
- QFETCH(QRhi::Implementation, impl);
- if (impl != QRhi::OpenGLES2)
- QSKIP("Skipping OpenGL-dependent test");
-
#ifdef TST_GL
- QFETCH(QRhiInitParams *, initParams);
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::OpenGL))
+ QSKIP("Skipping OpenGL-dependent test");
- QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ QScopedPointer<QRhi> rhi(QRhi::create(QRhi::OpenGLES2, &initParams.gl, QRhi::Flags(), nullptr));
if (!rhi)
QSKIP("QRhi could not be created, skipping testing native texture");
@@ -4094,7 +5137,7 @@ void tst_QRhi::threeDimTexture()
}
// mipmaps
- {
+ if (rhi->isFeatureSupported(QRhi::ThreeDimensionalTextureMipmaps)) {
QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, WIDTH, HEIGHT, DEPTH,
1, QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
QVERIFY(texture->create());
@@ -4139,6 +5182,8 @@ void tst_QRhi::threeDimTexture()
// problems with this.
if (impl != QRhi::Null && impl != QRhi::OpenGLES2)
QVERIFY(imageRGBAEquals(result, referenceImage, 2));
+ } else {
+ qDebug("Skipping 3D texture mipmap generation test because it is reported as unsupported");
}
// render target (one slice)
@@ -4157,11 +5202,531 @@ void tst_QRhi::threeDimTexture()
rt->setRenderPassDescriptor(rp.data());
QVERIFY(rt->create());
+ // render to slice 23
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 });
+ // slice 23 is now blue
+ cb->endPass();
+ rhi->endOffscreenFrame();
+
+ // Fill all other slices with some color. We should be free to do this
+ // step *before* the "render to slice 23" block above as well. However,
+ // as QTBUG-111772 shows, some Vulkan implementations have problems
+ // then. (or it could be QRhi is doing something wrong, but there is no
+ // evidence of that yet) For now, keep the order of first rendering to
+ // a slice and then uploading data for the rest.
QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
QVERIFY(batch);
-
for (int i = 0; i < DEPTH; ++i) {
- QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888);
+ if (i != SLICE) {
+ QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(i * 2, 0, 0));
+ QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), sliceUpload);
+ }
+ }
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+
+ // read back slice 23 (blue)
+ batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiReadbackDescription readbackDescription(texture.data());
+ readbackDescription.setLayer(23);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, HEIGHT, result.format());
+ referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f));
+ // the Null backend does not render so skip the verification for that
+ if (impl != QRhi::Null)
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+
+ // read back slice 0 (black)
+ batch = rhi->nextResourceUpdateBatch();
+ result = QImage();
+ readbackDescription.setLayer(0);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 0.0f));
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+
+ // read back slice 127 (almost red)
+ batch = rhi->nextResourceUpdateBatch();
+ result = QImage();
+ readbackDescription.setLayer(127);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ referenceImage.fill(QColor::fromRgb(254, 0, 0));
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+}
+void tst_QRhi::oneDimTexture_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::oneDimTexture()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing 1D textures");
+
+ if (!rhi->isFeatureSupported(QRhi::OneDimensionalTextures))
+ QSKIP("Skipping testing 1D textures because they are reported as unsupported");
+
+ const int WIDTH = 512;
+ const int LAYERS = 128;
+
+ {
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0));
+ QVERIFY(texture->create());
+
+ QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::OneDimensional));
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(255, 0, 0));
+
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), upload);
+
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ }
+
+ {
+ QScopedPointer<QRhiTexture> texture(
+ rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0)));
+ QVERIFY(texture->create());
+
+ QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::OneDimensional));
+ QVERIFY(texture->flags().testFlag(QRhiTexture::Flag::TextureArray));
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ for (int i = 0; i < LAYERS; ++i) {
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(i * 2, 0, 0));
+ QRhiTextureUploadEntry layerUpload(i, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), layerUpload);
+ }
+
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ }
+
+ // Copy from 2D texture to 1D texture
+ {
+ const int WIDTH = 256;
+ const int HEIGHT = 256;
+
+ QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture(
+ QRhiTexture::RGBA8, WIDTH, HEIGHT, 0, 1, QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(srcTexture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888);
+ for (int x = 0; x < WIDTH; ++x) {
+ for (int y = 0; y < HEIGHT; ++y) {
+ img.setPixelColor(x, y, QColor::fromRgb(x, y, 0));
+ }
+ }
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(srcTexture.data(), upload);
+
+ QScopedPointer<QRhiTexture> dstTexture(rhi->newTexture(
+ QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(dstTexture->create());
+
+ QRhiTextureCopyDescription copy;
+ copy.setPixelSize(QSize(WIDTH / 2, 1));
+ copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0));
+ copy.setSourceTopLeft(QPoint(33, 67));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ copy.setDestinationTopLeft(QPoint(0, 0));
+ copy.setSourceTopLeft(QPoint(99, 12));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+
+ QRhiReadbackDescription readbackDescription(dstTexture.data());
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, 1, result.format());
+ for (int i = 0; i < WIDTH / 2; ++i) {
+ referenceImage.setPixelColor(i, 0, img.pixelColor(99 + i, 12));
+ referenceImage.setPixelColor(WIDTH / 2 + i, 0, img.pixelColor(33 + i, 67));
+ }
+
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+
+ // Copy from 2D texture to 1D texture array
+ {
+ const int WIDTH = 256;
+ const int HEIGHT = 256;
+ const int LAYERS = 64;
+
+ QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture(
+ QRhiTexture::RGBA8, WIDTH, HEIGHT, 0, 1, QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(srcTexture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, HEIGHT, QImage::Format_RGBA8888);
+ for (int x = 0; x < WIDTH; ++x) {
+ for (int y = 0; y < HEIGHT; ++y) {
+ img.setPixelColor(x, y, QColor::fromRgb(x, y, 0));
+ }
+ }
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(srcTexture.data(), upload);
+
+ QScopedPointer<QRhiTexture> dstTexture(
+ rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1,
+ QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(dstTexture->create());
+
+ QRhiTextureCopyDescription copy;
+ copy.setPixelSize(QSize(WIDTH / 2, 1));
+ copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0));
+ copy.setSourceTopLeft(QPoint(33, 67));
+ copy.setDestinationLayer(12);
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ copy.setDestinationTopLeft(QPoint(0, 0));
+ copy.setSourceTopLeft(QPoint(99, 12));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+
+ QRhiReadbackDescription readbackDescription(dstTexture.data());
+ readbackDescription.setLayer(12);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, 1, result.format());
+ for (int i = 0; i < WIDTH / 2; ++i) {
+ referenceImage.setPixelColor(i, 0, img.pixelColor(99 + i, 12));
+ referenceImage.setPixelColor(WIDTH / 2 + i, 0, img.pixelColor(33 + i, 67));
+ }
+
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+
+ // Copy from 1D texture array to 1D texture
+ {
+ const int WIDTH = 256;
+ const int LAYERS = 256;
+
+ QScopedPointer<QRhiTexture> srcTexture(
+ rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1,
+ QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(srcTexture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ for (int y = 0; y < LAYERS; ++y) {
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ for (int x = 0; x < WIDTH; ++x) {
+ img.setPixelColor(x, 0, QColor::fromRgb(x, y, 0));
+ }
+ QRhiTextureUploadEntry upload(y, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(srcTexture.data(), upload);
+ }
+
+ QScopedPointer<QRhiTexture> dstTexture(rhi->newTexture(
+ QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(dstTexture->create());
+
+ QRhiTextureCopyDescription copy;
+ copy.setPixelSize(QSize(WIDTH / 2, 1));
+ copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0));
+ copy.setSourceLayer(67);
+ copy.setSourceTopLeft(QPoint(33, 0));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ copy.setDestinationTopLeft(QPoint(0, 0));
+ copy.setSourceLayer(12);
+ copy.setSourceTopLeft(QPoint(99, 0));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+
+ QRhiReadbackDescription readbackDescription(dstTexture.data());
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, 1, result.format());
+ for (int i = 0; i < WIDTH / 2; ++i) {
+ referenceImage.setPixelColor(i, 0, QColor::fromRgb(99 + i, 12, 0));
+ referenceImage.setPixelColor(WIDTH / 2 + i, 0, QColor::fromRgb(33 + i, 67, 0));
+ }
+
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+
+ // Copy from 1D texture to 1D texture array
+ {
+ const int WIDTH = 256;
+ const int LAYERS = 256;
+
+ QScopedPointer<QRhiTexture> srcTexture(rhi->newTexture(
+ QRhiTexture::RGBA8, WIDTH, 0, 0, 1, QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(srcTexture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ for (int x = 0; x < WIDTH; ++x) {
+ img.setPixelColor(x, 0, QColor::fromRgb(x, 0, 0));
+ }
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(srcTexture.data(), upload);
+
+ QScopedPointer<QRhiTexture> dstTexture(
+ rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1,
+ QRhiTexture::Flag::UsedAsTransferSource));
+ QVERIFY(dstTexture->create());
+
+ QRhiTextureCopyDescription copy;
+ copy.setPixelSize(QSize(WIDTH / 2, 1));
+ copy.setDestinationTopLeft(QPoint(WIDTH / 2, 0));
+ copy.setDestinationLayer(67);
+ copy.setSourceTopLeft(QPoint(33, 0));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ copy.setDestinationTopLeft(QPoint(0, 0));
+ copy.setSourceTopLeft(QPoint(99, 0));
+ batch->copyTexture(dstTexture.data(), srcTexture.data(), copy);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+
+ QRhiReadbackDescription readbackDescription(dstTexture.data());
+ readbackDescription.setLayer(67);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, 1, result.format());
+ for (int i = 0; i < WIDTH / 2; ++i) {
+ referenceImage.setPixelColor(i, 0, QColor::fromRgb(99 + i, 0, 0));
+ referenceImage.setPixelColor(WIDTH / 2 + i, 0, QColor::fromRgb(33 + i, 0, 0));
+ }
+
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+
+ // mipmaps and 1D render target
+ if (!rhi->isFeatureSupported(QRhi::OneDimensionalTextureMipmaps)
+ || !rhi->isFeatureSupported(QRhi::RenderToOneDimensionalTexture))
+ {
+ QSKIP("Skipping testing 1D texture mipmaps and 1D render target because they are reported as unsupported");
+ }
+
+ {
+ QScopedPointer<QRhiTexture> texture(
+ rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0, 1,
+ QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
+ QVERIFY(texture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(128, 0, 0));
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), upload);
+
+ batch->generateMips(texture.data());
+
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+
+ // read back level 1 (256x1, #800000ff)
+ batch = rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiReadbackDescription readbackDescription(texture.data());
+ readbackDescription.setLevel(1);
+ readbackDescription.setLayer(0);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH / 2, 1, result.format());
+ referenceImage.fill(QColor::fromRgb(128, 0, 0));
+
+ QVERIFY(imageRGBAEquals(result, referenceImage, 2));
+ }
+
+ {
+ QScopedPointer<QRhiTexture> texture(
+ rhi->newTextureArray(QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1,
+ QRhiTexture::MipMapped | QRhiTexture::UsedWithGenerateMips));
+ QVERIFY(texture->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ for (int i = 0; i < LAYERS; ++i) {
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(i * 2, 0, 0));
+ QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), sliceUpload);
+ }
+
+ batch->generateMips(texture.data());
+
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+
+ // read back slice 63 of level 1 (256x1, #7E0000FF)
+ batch = rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiReadbackDescription readbackDescription(texture.data());
+ readbackDescription.setLevel(1);
+ readbackDescription.setLayer(63);
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH / 2, 1, result.format());
+ referenceImage.fill(QColor::fromRgb(126, 0, 0));
+
+ // Now restrict the test a bit. The Null QRhi backend has broken support for
+ // mipmap generation of 1D texture arrays.
+ if (impl != QRhi::Null)
+ QVERIFY(imageRGBAEquals(result, referenceImage, 2));
+ }
+
+ // 1D texture render target
+ // NB with Vulkan we require Vulkan 1.1 for this to work.
+ // Metal does not allow 1D texture render targets
+ {
+ QScopedPointer<QRhiTexture> texture(
+ rhi->newTexture(QRhiTexture::RGBA8, WIDTH, 0, 0, 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QRhiColorAttachment att(texture.data());
+ QRhiTextureRenderTargetDescription rtDesc(att);
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rp.data());
+ QVERIFY(rt->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
+ img.fill(QColor::fromRgb(128, 0, 0));
+ QRhiTextureUploadEntry upload(0, 0, QRhiTextureSubresourceUploadDescription(img));
+ batch->uploadTexture(texture.data(), upload);
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, batch);
+ // texture is now blue
+ cb->endPass();
+ rhi->endOffscreenFrame();
+
+ // read back texture (blue)
+ batch = rhi->nextResourceUpdateBatch();
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiReadbackDescription readbackDescription(texture.data());
+ batch->readBackTexture(readbackDescription, &readResult);
+ QVERIFY(submitResourceUpdates(rhi.data(), batch));
+ QVERIFY(!result.isNull());
+ QImage referenceImage(WIDTH, 1, result.format());
+ referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f));
+ // the Null backend does not render so skip the verification for that
+ if (impl != QRhi::Null)
+ QVERIFY(imageRGBAEquals(result, referenceImage));
+ }
+
+ // 1D array texture render target (one slice)
+ // NB with Vulkan we require Vulkan 1.1 for this to work.
+ // Metal does not allow 1D texture render targets
+ {
+ const int SLICE = 23;
+ QScopedPointer<QRhiTexture> texture(rhi->newTextureArray(
+ QRhiTexture::RGBA8, LAYERS, QSize(WIDTH, 0), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QRhiColorAttachment att(texture.data());
+ att.setLayer(SLICE);
+ QRhiTextureRenderTargetDescription rtDesc(att);
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget(rtDesc));
+ QScopedPointer<QRhiRenderPassDescriptor> rp(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rp.data());
+ QVERIFY(rt->create());
+
+ QRhiResourceUpdateBatch *batch = rhi->nextResourceUpdateBatch();
+ QVERIFY(batch);
+
+ for (int i = 0; i < LAYERS; ++i) {
+ QImage img(WIDTH, 1, QImage::Format_RGBA8888);
img.fill(QColor::fromRgb(i * 2, 0, 0));
QRhiTextureUploadEntry sliceUpload(i, 0, QRhiTextureSubresourceUploadDescription(img));
batch->uploadTexture(texture.data(), sliceUpload);
@@ -4189,7 +5754,7 @@ void tst_QRhi::threeDimTexture()
batch->readBackTexture(readbackDescription, &readResult);
QVERIFY(submitResourceUpdates(rhi.data(), batch));
QVERIFY(!result.isNull());
- QImage referenceImage(WIDTH, HEIGHT, result.format());
+ QImage referenceImage(WIDTH, 1, result.format());
referenceImage.fill(QColor::fromRgbF(0.0f, 0.0f, 1.0f));
// the Null backend does not render so skip the verification for that
if (impl != QRhi::Null)
@@ -4256,12 +5821,1263 @@ void tst_QRhi::leakedResourceDestroy()
rt->setRenderPassDescriptor(rpDesc.data());
QVERIFY(rt->create());
+ QRhiRenderBuffer *rb = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(512, 512));
+ QVERIFY(rb->create());
+
+ QRhiShaderResourceBindings *srb = rhi->newShaderResourceBindings();
+ QVERIFY(srb->create());
+
if (impl == QRhi::Vulkan)
qDebug("Vulkan validation layer warnings may be printed below - this is expected");
+ if (impl == QRhi::D3D12)
+ qDebug("QD3D12CpuDescriptorPool warnings may be printed below - this is expected");
+
+ qDebug("QRhi resource leak check warnings may be printed below - this is expected");
+
+ // make the QRhi go away early
rhi.reset();
- // let the scoped ptr do its job with the resources
+ // see if the internal rhi backpointer got nulled out
+ QVERIFY(buffer->rhi() == nullptr);
+ QVERIFY(texture->rhi() == nullptr);
+ QVERIFY(rt->rhi() == nullptr);
+ QVERIFY(rpDesc->rhi() == nullptr);
+ QVERIFY(rb->rhi() == nullptr);
+ QVERIFY(srb->rhi() == nullptr);
+
+ // test out deleteLater on some of the resources
+ rb->deleteLater();
+ srb->deleteLater();
+
+ // let the scoped ptr do its job with the rest
+}
+
+void tst_QRhi::renderToFloatTexture_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToFloatTexture()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isTextureFormatSupported(QRhiTexture::RGBA16F))
+ QSKIP("RGBA16F is not supported, skipping test");
+
+ const QSize outputSize(1920, 1080);
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA16F, outputSize, 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
+
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA16FPx4);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+ QCOMPARE(result.size(), texture->pixelSize());
+
+ if (impl == QRhi::Null)
+ return;
+
+ if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC())
+ result = std::move(result).mirrored();
+
+ // Now we have a red rectangle on blue background.
+ const int y = 100;
+ const QRgbaFloat16 *p = reinterpret_cast<const QRgbaFloat16 *>(result.constScanLine(y));
+ int redCount = 0;
+ int blueCount = 0;
+ int x = result.width() - 1;
+ while (x-- >= 0) {
+ QRgbaFloat16 c = *p++;
+ if (c.red() >= 0.95f && qFuzzyIsNull(c.green()) && qFuzzyIsNull(c.blue()))
+ ++redCount;
+ else if (qFuzzyIsNull(c.red()) && qFuzzyIsNull(c.green()) && c.blue() >= 0.95f)
+ ++blueCount;
+ else
+ QFAIL("Encountered a pixel that is neither red or blue");
+ }
+ QCOMPARE(redCount + blueCount, texture->pixelSize().width());
+ QVERIFY(redCount > blueCount); // 1742 > 178
+}
+
+void tst_QRhi::renderToRgb10Texture_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::renderToRgb10Texture()
+{
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isTextureFormatSupported(QRhiTexture::RGB10A2))
+ QSKIP("RGB10A2 is not supported, skipping test");
+
+ const QSize outputSize(1920, 1080);
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGB10A2, outputSize, 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(createSimplePipeline(rhi.data(), srb.data(), rpDesc.data()));
+ QVERIFY(pipeline);
+
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_A2BGR30_Premultiplied);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+ QCOMPARE(result.size(), texture->pixelSize());
+
+ if (impl == QRhi::Null)
+ return;
+
+ if (rhi->isYUpInFramebuffer() != rhi->isYUpInNDC())
+ result = std::move(result).mirrored();
+
+ // Now we have a red rectangle on blue background.
+ const int y = 100;
+ int redCount = 0;
+ int blueCount = 0;
+ const int maxFuzz = 1;
+ for (int x = 0; x < result.width(); ++x) {
+ QRgb c = result.pixel(x, y);
+ if (qRed(c) >= (255 - maxFuzz) && qGreen(c) == 0 && qBlue(c) == 0)
+ ++redCount;
+ else if (qRed(c) == 0 && qGreen(c) == 0 && qBlue(c) >= (255 - maxFuzz))
+ ++blueCount;
+ else
+ QFAIL("Encountered a pixel that is neither red or blue");
+ }
+ QCOMPARE(redCount + blueCount, texture->pixelSize().width());
+ QVERIFY(redCount > blueCount); // 1742 > 178
+}
+
+void tst_QRhi::tessellation_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::tessellation()
+{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-108844)");
+#endif
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::Tessellation)) {
+ // From a Vulkan or Metal implementation we expect tessellation to work,
+ // even though it is optional (as per spec) for Vulkan.
+ QVERIFY(rhi->backend() != QRhi::Vulkan);
+ QVERIFY(rhi->backend() != QRhi::Metal);
+ QSKIP("Tessellation is not supported with this graphics API, skipping test");
+ }
+
+ if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12)
+ QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet");
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(1280, 720), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ static const float triangleVertices[] = {
+ 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f,
+ -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
+ };
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ u->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64));
+ QVERIFY(ubuf->create());
+
+ // Use the 3D API specific correction matrix that flips Y, so we can use
+ // the OpenGL-targeted vertex data and the tessellation winding order of
+ // counter-clockwise to get uniform results.
+ QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix();
+ u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()),
+ });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+
+ pipeline->setTopology(QRhiGraphicsPipeline::Patches);
+ pipeline->setPatchControlPointCount(3);
+
+ pipeline->setShaderStages({
+ { QRhiShaderStage::Vertex, loadShader(":/data/simpletess.vert.qsb") },
+ { QRhiShaderStage::TessellationControl, loadShader(":/data/simpletess.tesc.qsb") },
+ { QRhiShaderStage::TessellationEvaluation, loadShader(":/data/simpletess.tese.qsb") },
+ { QRhiShaderStage::Fragment, loadShader(":/data/simpletess.frag.qsb") }
+ });
+
+ pipeline->setCullMode(QRhiGraphicsPipeline::Back); // to ensure the winding order is correct
+
+ // won't get the wireframe with OpenGL ES
+ if (rhi->isFeatureSupported(QRhi::NonFillPolygonMode))
+ pipeline->setPolygonMode(QRhiGraphicsPipeline::Line);
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 6 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float3, 3 * sizeof(float) }
+ });
+
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+
+ QVERIFY(pipeline->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess);
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) });
+ cb->setShaderResources();
+ QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many other tests
+ result = std::move(result).mirrored();
+
+ QCOMPARE(result.size(), rt->pixelSize());
+
+ // cannot check rendering results with Null, because there is no rendering there
+ if (impl == QRhi::Null)
+ return;
+
+ int redCount = 0, greenCount = 0, blueCount = 0;
+ for (int y = 0; y < result.height(); ++y) {
+ const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y));
+ int x = result.width() - 1;
+ while (x-- >= 0) {
+ const QRgb c(*p++);
+ const int red = qRed(c);
+ const int green = qGreen(c);
+ const int blue = qBlue(c);
+ // just count the color components that are above a certain threshold
+ if (red > 240)
+ ++redCount;
+ if (green > 240)
+ ++greenCount;
+ if (blue > 240)
+ ++blueCount;
+ }
+ }
+
+ // Line drawing can be different between the 3D APIs. What we will check if
+ // the number of strong-enough r/g/b components above a certain threshold.
+ // That is good enough to ensure that something got rendered, i.e. that
+ // tessellation is not completely broken.
+ //
+ // For the record the actual values are something like:
+ // OpenGL (NVIDIA, Windows) 59 82 82
+ // Metal (Intel, macOS 12.5) 59 79 79
+ // Vulkan (NVIDIA, Windows) 71 85 85
+
+ QVERIFY(redCount > 50);
+ QVERIFY(blueCount > 50);
+ QVERIFY(greenCount > 50);
+}
+
+void tst_QRhi::tessellationInterfaceBlocks_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::tessellationInterfaceBlocks()
+{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-108844)");
+#endif
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ // This test is intended for Metal, but will run on other tessellation render pipelines
+ //
+ // Metal tessellation uses a combination of compute pipelines for the vert and tesc, and a
+ // render pipeline for the tese and frag. This test uses input output interface blocks between
+ // the tesc and tese, and all tese stage builtin inputs to check that the Metal tese-frag
+ // pipeline vertex inputs are correctly configured. The tese writes the values to a storage
+ // buffer whose values are checked by the unit test. MSL 2.1 is required for this test.
+ // (requires support for writing to a storage buffer in the vertex shader within a render
+ // pipeline)
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::Tessellation)) {
+ // From a Vulkan or Metal implementation we expect tessellation to work,
+ // even though it is optional (as per spec) for Vulkan.
+ QVERIFY(rhi->backend() != QRhi::Vulkan);
+ QVERIFY(rhi->backend() != QRhi::Metal);
+ QSKIP("Tessellation is not supported with this graphics API, skipping test");
+ }
+
+ if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12)
+ QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet");
+
+ if (rhi->backend() == QRhi::OpenGLES2)
+ QSKIP("Skipping test on OpenGL as gl_ClipDistance[] support inconsistent");
+
+ QScopedPointer<QRhiTexture> texture(
+ rhi->newTexture(QRhiTexture::RGBA8, QSize(1280, 720), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ static const float triangleVertices[] = {
+ 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, -0.5f, -0.5f, 0.0f,
+ 1.0f, 0.0f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f,
+ };
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer,
+ sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ u->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiBuffer> ubuf(
+ rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64));
+ QVERIFY(ubuf->create());
+
+ // Use the 3D API specific correction matrix that flips Y, so we can use
+ // the OpenGL-targeted vertex data and the tessellation winding order of
+ // counter-clockwise to get uniform results.
+ QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix();
+ u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData());
+
+ QScopedPointer<QRhiBuffer> buffer(
+ rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::UsageFlag::StorageBuffer, 1024));
+ QVERIFY(buffer->create());
+
+ u->uploadStaticBuffer(buffer.data(), 0, 1024, QByteArray(1024, 0).constData());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings(
+ { QRhiShaderResourceBinding::uniformBuffer(
+ 0, QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()),
+ QRhiShaderResourceBinding::bufferLoadStore(
+ 1, QRhiShaderResourceBinding::TessellationEvaluationStage, buffer.data()) });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+
+ pipeline->setTopology(QRhiGraphicsPipeline::Patches);
+ pipeline->setPatchControlPointCount(3);
+
+ pipeline->setShaderStages(
+ { { QRhiShaderStage::Vertex, loadShader(":/data/tessinterfaceblocks.vert.qsb") },
+ { QRhiShaderStage::TessellationControl,
+ loadShader(":/data/tessinterfaceblocks.tesc.qsb") },
+ { QRhiShaderStage::TessellationEvaluation,
+ loadShader(":/data/tessinterfaceblocks.tese.qsb") },
+ { QRhiShaderStage::Fragment, loadShader(":/data/tessinterfaceblocks.frag.qsb") } });
+
+ pipeline->setCullMode(QRhiGraphicsPipeline::Back); // to ensure the winding order is correct
+
+ // won't get the wireframe with OpenGL ES
+ if (rhi->isFeatureSupported(QRhi::NonFillPolygonMode))
+ pipeline->setPolygonMode(QRhiGraphicsPipeline::Line);
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 6 * sizeof(float) } });
+ inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
+ { 0, 1, QRhiVertexInputAttribute::Float3, 3 * sizeof(float) } });
+
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+
+ QVERIFY(pipeline->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess);
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) });
+ cb->setShaderResources();
+ QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+
+ QRhiReadbackResult bufferReadResult;
+ bufferReadResult.completed = []() {};
+ readbackBatch->readBackBuffer(buffer.data(), 0, 1024, &bufferReadResult);
+
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ if (rhi->isYUpInFramebuffer()) // we used clipSpaceCorrMatrix so this is different from many
+ // other tests
+ result = std::move(result).mirrored();
+
+ QCOMPARE(result.size(), rt->pixelSize());
+
+ // cannot check rendering results with Null, because there is no rendering there
+ if (impl == QRhi::Null)
+ return;
+
+ int redCount = 0, greenCount = 0, blueCount = 0;
+ for (int y = 0; y < result.height(); ++y) {
+ const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y));
+ int x = result.width() - 1;
+ while (x-- >= 0) {
+ const QRgb c(*p++);
+ const int red = qRed(c);
+ const int green = qGreen(c);
+ const int blue = qBlue(c);
+ // just count the color components that are above a certain threshold
+ if (red > 240)
+ ++redCount;
+ if (green > 240)
+ ++greenCount;
+ if (blue > 240)
+ ++blueCount;
+ }
+ }
+
+ // make sure we drew something
+ QVERIFY(redCount > 50);
+ QVERIFY(blueCount > 50);
+ QVERIFY(greenCount > 50);
+
+ // StorageBlock("result" "" knownSize=16 binding=1 set=0 runtimeArrayStride=336 QList(
+ // BlockVariable("int" "count" offset=0 size=4),
+ // BlockVariable("struct" "elements" offset=16 size=0 array=QList(0) structMembers=QList(
+ // BlockVariable("struct" "a" offset=0 size=48 array=QList(3) structMembers=QList(
+ // BlockVariable("vec3" "color" offset=0 size=12),
+ // BlockVariable("int" "id" offset=12 size=4))),
+ // BlockVariable("struct" "b" offset=48 size=144 array=QList(3) structMembers=QList(
+ // BlockVariable("vec2" "some" offset=0 size=8),
+ // BlockVariable("int" "other" offset=8 size=12 array=QList(3)),
+ // BlockVariable("vec3" "variables" offset=32 size=12))),
+ // BlockVariable("struct" "c" offset=192 size=16 structMembers=QList(
+ // BlockVariable("vec3" "stuff" offset=0 size=12),
+ // BlockVariable("float" "more_stuff" offset=12 size=4))),
+ // BlockVariable("vec4" "tesslevelOuter" offset=208 size=16),
+ // BlockVariable("vec2" "tessLevelInner" offset=224 size=8),
+ // BlockVariable("float" "pointSize" offset=232 size=12 array=QList(3)),
+ // BlockVariable("float" "clipDistance" offset=244 size=60 array=QList(5, 3)),
+ // BlockVariable("vec3" "tessCoord" offset=304 size=12),
+ // BlockVariable("int" "patchVerticesIn" offset=316 size=4),
+ // BlockVariable("int" "primitiveID" offset=320 size=4)))))
+
+ // int count
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[0])[0], 1);
+
+ // a[0].color
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[0], 0.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[1], 0.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 0 + 0])[2], 1.0f);
+
+ // a[0].id
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 0 + 12])[0], 91);
+
+ // a[1].color
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[0], 1.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[1], 0.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 16 + 0])[2], 0.0f);
+
+ // a[1].id
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 16 + 12])[0], 92);
+
+ // a[2].color
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[0], 0.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[1], 1.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 32 + 0])[2], 0.0f);
+
+ // a[2].id
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 32 + 12])[0], 93);
+
+ // b[0].some
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 0])[0], 0.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 0])[1], 0.0f);
+
+ // b[0].other[0]
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[0], 10.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[1], 20.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 48 + 8])[2], 30.0f);
+
+ // b[0].variables
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[0], 3.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[1], 13.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 48 + 32])[2], 17.0f);
+
+ // b[1].some
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 0])[0], 1.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 0])[1], 1.0f);
+
+ // b[1].other[0]
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[0], 10.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[1], 20.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 96 + 8])[2], 30.0f);
+
+ // b[1].variables
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[0], 3.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[1], 14.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 96 + 32])[2], 17.0f);
+
+ // b[2].some
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 0])[0], 2.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 0])[1], 2.0f);
+
+ // b[2].other[0]
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[0], 10.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[1], 20.0f);
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 144 + 8])[2], 30.0f);
+
+ // b[2].variables
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[0], 3.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[1], 15.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 144 + 32])[2], 17.0f);
+
+ // c.stuff
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[0], 1.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[1], 2.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 0])[2], 3.0f);
+
+ // c.more_stuff
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 192 + 12])[0], 4.0f);
+
+ // tessLevelOuter
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[0], 1.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[1], 2.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 208 + 0])[2], 3.0f);
+
+ // tessLevelInner
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 224 + 0])[0], 5.0f);
+
+ // pointSize[0]
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[0], 10.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[1], 11.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 232 + 0])[2], 12.0f);
+
+ // clipDistance[0][0]
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[0], 20.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[1], 40.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[2], 60.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[3], 80.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 0])[4], 100.0f);
+
+ // clipDistance[1][0]
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[0], 21.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[1], 41.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[2], 61.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[3], 81.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 20])[4], 101.0f);
+
+ // clipDistance[2][0]
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[0], 22.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[1], 42.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[2], 62.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[3], 82.0f);
+ QCOMPARE(reinterpret_cast<const float *>(&bufferReadResult.data.constData()[16 + 244 + 40])[4], 102.0f);
+
+ // patchVerticesIn
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 316 + 0])[0], 3);
+
+ // primitiveID
+ QCOMPARE(reinterpret_cast<const int *>(&bufferReadResult.data.constData()[16 + 320 + 0])[0], 0);
+}
+
+void tst_QRhi::storageBuffer_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::storageBuffer()
+{
+ // Use a compute shader to copy from one storage buffer of float types to
+ // another of int types. We fill the "toGpu" buffer with known float type
+ // data generated and uploaded from the CPU, then dispatch a compute shader
+ // to copy from the "toGpu" buffer to the "fromGpu" buffer. We then
+ // readback the "fromGpu" buffer and verify that the results are as
+ // expected.
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ // we can't test with Null as there is no compute
+ if (impl == QRhi::Null)
+ return;
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing");
+
+ if (!rhi->isFeatureSupported(QRhi::Feature::Compute))
+ QSKIP("Compute is not supported with this graphics API, skipping test");
+
+ QShader s = loadShader(":/data/storagebuffer.comp.qsb");
+ QVERIFY(s.isValid());
+ QCOMPARE(s.description().storageBlocks().size(), 2);
+
+ QMap<QByteArray, QShaderDescription::StorageBlock> blocks;
+ for (const QShaderDescription::StorageBlock &block : s.description().storageBlocks())
+ blocks[block.blockName] = block;
+
+ QMap<QByteArray, QShaderDescription::BlockVariable> toGpuMembers;
+ for (const QShaderDescription::BlockVariable &member: blocks["toGpu"].members)
+ toGpuMembers[member.name] = member;
+
+ QMap<QByteArray, QShaderDescription::BlockVariable> fromGpuMembers;
+ for (const QShaderDescription::BlockVariable &member: blocks["fromGpu"].members)
+ fromGpuMembers[member.name] = member;
+
+ for (QRhiBuffer::Type type : {QRhiBuffer::Type::Immutable, QRhiBuffer::Type::Static}) {
+
+ QRhiCommandBuffer *cb = nullptr;
+ rhi->beginOffscreenFrame(&cb);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ QVERIFY(u);
+
+ QScopedPointer<QRhiBuffer> toGpuBuffer(rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, blocks["toGpu"].knownSize));
+ QVERIFY(toGpuBuffer->create());
+
+ QScopedPointer<QRhiBuffer> fromGpuBuffer(rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer, blocks["fromGpu"].knownSize));
+ QVERIFY(fromGpuBuffer->create());
+
+ QByteArray toGpuData(blocks["toGpu"].knownSize, 0);
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_float"].offset])[0] = 1.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec2"].offset])[0] = 2.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec2"].offset])[1] = 3.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[0] = 4.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[1] = 5.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec3"].offset])[2] = 6.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[0] = 7.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[1] = 8.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[2] = 9.0f;
+ reinterpret_cast<float *>(&toGpuData.data()[toGpuMembers["_vec4"].offset])[3] = 10.0f;
+
+ u->uploadStaticBuffer(toGpuBuffer.data(), 0, toGpuData.size(), toGpuData.constData());
+ u->uploadStaticBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize, QByteArray(blocks["fromGpu"].knownSize, 0).constData());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({QRhiShaderResourceBinding::bufferLoad(blocks["toGpu"].binding, QRhiShaderResourceBinding::ComputeStage, toGpuBuffer.data()),
+ QRhiShaderResourceBinding::bufferLoadStore(blocks["fromGpu"].binding, QRhiShaderResourceBinding::ComputeStage, fromGpuBuffer.data())});
+
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiComputePipeline> pipeline(rhi->newComputePipeline());
+ pipeline->setShaderStage({QRhiShaderStage::Compute, s});
+ pipeline->setShaderResourceBindings(srb.data());
+ QVERIFY(pipeline->create());
+
+ cb->beginComputePass(u);
+
+ cb->setComputePipeline(pipeline.data());
+ cb->setShaderResources();
+ cb->dispatch(1, 1, 1);
+
+ u = rhi->nextResourceUpdateBatch();
+ QVERIFY(u);
+
+ int readCompletedNotifications = 0;
+ QRhiReadbackResult result;
+ result.completed = [&readCompletedNotifications]() { readCompletedNotifications++; };
+ u->readBackBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize, &result);
+
+ cb->endComputePass(u);
+
+ rhi->endOffscreenFrame();
+
+ QCOMPARE(readCompletedNotifications, 1);
+
+ QCOMPARE(result.data.size(), blocks["fromGpu"].knownSize);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_int"].offset])[0], 1);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec2"].offset])[0], 2);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec2"].offset])[1], 3);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[0], 4);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[1], 5);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec3"].offset])[2], 6);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[0], 7);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[1], 8);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[2], 9);
+ QCOMPARE(reinterpret_cast<const int *>(&result.data.constData()[fromGpuMembers["_ivec4"].offset])[3], 10);
+
+ }
+}
+
+ void tst_QRhi::storageBufferRuntimeSizeCompute_data()
+{
+ rhiTestData();
+}
+
+ void tst_QRhi::storageBufferRuntimeSizeCompute()
+{
+ // Use a compute shader to copy from one storage buffer with std430 runtime
+ // float array to another with std140 runtime int array. We fill the
+ // "toGpu" buffer with known float data generated and uploaded from the
+ // CPU, then dispatch a compute shader to copy from the "toGpu" buffer to
+ // the "fromGpu" buffer. We then readback the "fromGpu" buffer and verify
+ // that the results are as expected. This is primarily to test Metal
+ // SPIRV-Cross buffer size buffers.
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ // we can't test with Null as there is no compute
+ if (impl == QRhi::Null)
+ return;
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing");
+
+ if (!rhi->isFeatureSupported(QRhi::Feature::Compute))
+ QSKIP("Compute is not supported with this graphics API, skipping test");
+
+ QShader s = loadShader(":/data/storagebuffer_runtime.comp.qsb");
+ QVERIFY(s.isValid());
+ QCOMPARE(s.description().storageBlocks().size(), 2);
+
+ QMap<QByteArray, QShaderDescription::StorageBlock> blocks;
+ for (const QShaderDescription::StorageBlock &block : s.description().storageBlocks())
+ blocks[block.blockName] = block;
+
+ QMap<QByteArray, QShaderDescription::BlockVariable> toGpuMembers;
+ for (const QShaderDescription::BlockVariable &member : blocks["toGpu"].members)
+ toGpuMembers[member.name] = member;
+
+ QMap<QByteArray, QShaderDescription::BlockVariable> fromGpuMembers;
+ for (const QShaderDescription::BlockVariable &member : blocks["fromGpu"].members)
+ fromGpuMembers[member.name] = member;
+
+ for (QRhiBuffer::Type type : { QRhiBuffer::Type::Immutable, QRhiBuffer::Type::Static }) {
+ QRhiCommandBuffer *cb = nullptr;
+
+ rhi->beginOffscreenFrame(&cb);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ QVERIFY(u);
+
+ const int stride430 = sizeof(float);
+ const int stride140 = 4 * sizeof(float);
+ const int length = 32;
+
+ QScopedPointer<QRhiBuffer> toGpuBuffer(
+ rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer,
+ blocks["toGpu"].knownSize + length * stride430));
+ QVERIFY(toGpuBuffer->create());
+
+ QScopedPointer<QRhiBuffer> fromGpuBuffer(
+ rhi->newBuffer(type, QRhiBuffer::UsageFlag::StorageBuffer,
+ blocks["fromGpu"].knownSize + length * stride140));
+ QVERIFY(fromGpuBuffer->create());
+
+ QByteArray toGpuData(toGpuBuffer->size(), 0);
+ for (int i = 0; i < length; ++i)
+ reinterpret_cast<float &>(toGpuData.data()[toGpuMembers["_float"].offset + i * stride430]) = float(i);
+
+ u->uploadStaticBuffer(toGpuBuffer.data(), 0, toGpuData.size(), toGpuData.constData());
+ u->uploadStaticBuffer(fromGpuBuffer.data(), 0, blocks["fromGpu"].knownSize,
+ QByteArray(fromGpuBuffer->size(), 0).constData());
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings(
+ { QRhiShaderResourceBinding::bufferLoadStore(
+ blocks["toGpu"].binding, QRhiShaderResourceBinding::ComputeStage,
+ toGpuBuffer.data()),
+ QRhiShaderResourceBinding::bufferLoadStore(
+ blocks["fromGpu"].binding, QRhiShaderResourceBinding::ComputeStage,
+ fromGpuBuffer.data()) });
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiComputePipeline> pipeline(rhi->newComputePipeline());
+ pipeline->setShaderStage({ QRhiShaderStage::Compute, s });
+ pipeline->setShaderResourceBindings(srb.data());
+ QVERIFY(pipeline->create());
+
+ cb->beginComputePass(u);
+
+ cb->setComputePipeline(pipeline.data());
+ cb->setShaderResources();
+ cb->dispatch(1, 1, 1);
+
+ u = rhi->nextResourceUpdateBatch();
+ QVERIFY(u);
+ int readbackCompleted = 0;
+ QRhiReadbackResult result;
+ result.completed = [&readbackCompleted]() { readbackCompleted++; };
+ u->readBackBuffer(fromGpuBuffer.data(), 0, fromGpuBuffer->size(), &result);
+
+ cb->endComputePass(u);
+
+ rhi->endOffscreenFrame();
+
+ QVERIFY(readbackCompleted > 0);
+ QCOMPARE(result.data.size(), fromGpuBuffer->size());
+
+ for (int i = 0; i < length; ++i)
+ QCOMPARE(reinterpret_cast<const int &>(result.data.constData()[fromGpuMembers["_int"].offset + i * stride140]), i);
+
+ QCOMPARE(readbackCompleted, 1);
+
+ }
+
+}
+
+void tst_QRhi::storageBufferRuntimeSizeGraphics_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::storageBufferRuntimeSizeGraphics()
+{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-108844)");
+#endif
+ // Draws a tessellated triangle with color determined by the length of
+ // buffers bound to shader stages. This is primarily to test Metal
+ // SPIRV-Cross buffer size buffers.
+
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::Tessellation)) {
+ // From a Vulkan or Metal implementation we expect tessellation to work,
+ // even though it is optional (as per spec) for Vulkan.
+ QVERIFY(rhi->backend() != QRhi::Vulkan);
+ QVERIFY(rhi->backend() != QRhi::Metal);
+ QSKIP("Tessellation is not supported with this graphics API, skipping test");
+ }
+
+ if (rhi->backend() == QRhi::D3D11 || rhi->backend() == QRhi::D3D12)
+ QSKIP("Skipping tessellation test on D3D for now, test assets not prepared for HLSL yet");
+
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, QSize(64, 64), 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ static const float triangleVertices[] = {
+ 0.0f, 0.5f, 0.0f,
+ -0.5f, -0.5f, 0.0f,
+ 0.5f, -0.5f, 0.0f,
+ };
+
+ QRhiResourceUpdateBatch *u = rhi->nextResourceUpdateBatch();
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(triangleVertices)));
+ QVERIFY(vbuf->create());
+ u->uploadStaticBuffer(vbuf.data(), triangleVertices);
+
+ QScopedPointer<QRhiBuffer> ubuf(rhi->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64));
+ QVERIFY(ubuf->create());
+
+ QMatrix4x4 mvp = rhi->clipSpaceCorrMatrix();
+ u->updateDynamicBuffer(ubuf.data(), 0, 64, mvp.constData());
+
+ QScopedPointer<QRhiBuffer> ssbo5(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 256));
+ QVERIFY(ssbo5->create());
+
+ QScopedPointer<QRhiBuffer> ssbo3(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 16));
+ QVERIFY(ssbo3->create());
+
+ u->uploadStaticBuffer(ssbo3.data(), QVector<float>({ 1.0f, 1.0f, 1.0f, 1.0f }).constData());
+
+ QScopedPointer<QRhiBuffer> ssbo4(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, 128));
+ QVERIFY(ssbo4->create());
+
+ const int red = 79;
+ const int green = 43;
+ const int blue = 251;
+
+ QScopedPointer<QRhiBuffer> ssboR(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, red * sizeof(float)));
+ QVERIFY(ssboR->create());
+
+ QScopedPointer<QRhiBuffer> ssboG(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, green * sizeof(float)));
+ QVERIFY(ssboG->create());
+
+ QScopedPointer<QRhiBuffer> ssboB(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, blue * sizeof(float)));
+ QVERIFY(ssboB->create());
+
+ const int tessOuter0 = 1;
+ const int tessOuter1 = 2;
+ const int tessOuter2 = 3;
+ const int tessInner0 = 4;
+
+ QScopedPointer<QRhiBuffer> ssboTessOuter0(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter0 * sizeof(float)));
+ QVERIFY(ssboTessOuter0->create());
+
+ QScopedPointer<QRhiBuffer> ssboTessOuter1(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter1 * sizeof(float)));
+ QVERIFY(ssboTessOuter1->create());
+
+ QScopedPointer<QRhiBuffer> ssboTessOuter2(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessOuter2 * sizeof(float)));
+ QVERIFY(ssboTessOuter2->create());
+
+ QScopedPointer<QRhiBuffer> ssboTessInner0(rhi->newBuffer(QRhiBuffer::Static, QRhiBuffer::StorageBuffer, tessInner0 * sizeof(float)));
+ QVERIFY(ssboTessInner0->create());
+
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ srb->setBindings({ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ubuf.data()),
+ QRhiShaderResourceBinding::bufferLoad(5, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssbo5.data()),
+ QRhiShaderResourceBinding::bufferLoad(3, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage | QRhiShaderResourceBinding::FragmentStage, ssbo3.data()),
+ QRhiShaderResourceBinding::bufferLoad(4, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssbo4.data()),
+ QRhiShaderResourceBinding::bufferLoad(7, QRhiShaderResourceBinding::TessellationControlStage, ssboTessOuter0.data()),
+ QRhiShaderResourceBinding::bufferLoad(8, QRhiShaderResourceBinding::TessellationControlStage | QRhiShaderResourceBinding::TessellationEvaluationStage, ssboTessOuter1.data()),
+ QRhiShaderResourceBinding::bufferLoad(9, QRhiShaderResourceBinding::TessellationControlStage, ssboTessOuter2.data()),
+ QRhiShaderResourceBinding::bufferLoad(10, QRhiShaderResourceBinding::TessellationControlStage, ssboTessInner0.data()),
+ QRhiShaderResourceBinding::bufferLoad(1, QRhiShaderResourceBinding::FragmentStage, ssboG.data()),
+ QRhiShaderResourceBinding::bufferLoad(2, QRhiShaderResourceBinding::FragmentStage, ssboB.data()),
+ QRhiShaderResourceBinding::bufferLoad(6, QRhiShaderResourceBinding::FragmentStage, ssboR.data()) });
+
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+
+ pipeline->setTopology(QRhiGraphicsPipeline::Patches);
+ pipeline->setPatchControlPointCount(3);
+
+ pipeline->setShaderStages({
+ { QRhiShaderStage::Vertex, loadShader(":/data/storagebuffer_runtime.vert.qsb") },
+ { QRhiShaderStage::TessellationControl, loadShader(":/data/storagebuffer_runtime.tesc.qsb") },
+ { QRhiShaderStage::TessellationEvaluation, loadShader(":/data/storagebuffer_runtime.tese.qsb") },
+ { QRhiShaderStage::Fragment, loadShader(":/data/storagebuffer_runtime.frag.qsb") }
+ });
+
+ pipeline->setCullMode(QRhiGraphicsPipeline::None);
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 3 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float3, 0 },
+ });
+
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+
+ QVERIFY(pipeline->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QCOMPARE(rhi->beginOffscreenFrame(&cb), QRhi::FrameOpSuccess);
+
+ cb->beginPass(rt.data(), Qt::black, { 1.0f, 0 }, u);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(rt->pixelSize().width()), float(rt->pixelSize().height()) });
+ cb->setShaderResources();
+ QRhiCommandBuffer::VertexInput vbufBinding(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888);
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+
+ QCOMPARE(result.size(), rt->pixelSize());
+
+ // cannot check rendering results with Null, because there is no rendering there
+ if (impl == QRhi::Null)
+ return;
+
+ QCOMPARE(result.pixel(32, 32), qRgb(red, green, blue));
+}
+
+void tst_QRhi::halfPrecisionAttributes_data()
+{
+ rhiTestData();
+}
+
+void tst_QRhi::halfPrecisionAttributes()
+{
+#ifdef Q_OS_ANDROID
+ if (QNativeInterface::QAndroidApplication::sdkVersion() >= 31)
+ QSKIP("Fails on Android 12 (QTBUG-108844)");
+#endif
+ QFETCH(QRhi::Implementation, impl);
+ QFETCH(QRhiInitParams *, initParams);
+
+ QScopedPointer<QRhi> rhi(QRhi::create(impl, initParams, QRhi::Flags(), nullptr));
+ if (!rhi)
+ QSKIP("QRhi could not be created, skipping testing rendering");
+
+ if (!rhi->isFeatureSupported(QRhi::HalfAttributes)) {
+ QVERIFY(rhi->backend() != QRhi::Vulkan);
+ QVERIFY(rhi->backend() != QRhi::Metal);
+ QVERIFY(rhi->backend() != QRhi::D3D11);
+ QVERIFY(rhi->backend() != QRhi::D3D12);
+ QSKIP("Half precision vertex attributes are not supported with this graphics API, skipping test");
+ }
+
+ const QSize outputSize(1920, 1080);
+ QScopedPointer<QRhiTexture> texture(rhi->newTexture(QRhiTexture::RGBA8, outputSize, 1,
+ QRhiTexture::RenderTarget | QRhiTexture::UsedAsTransferSource));
+ QVERIFY(texture->create());
+
+ QScopedPointer<QRhiTextureRenderTarget> rt(rhi->newTextureRenderTarget({ texture.data() }));
+ QScopedPointer<QRhiRenderPassDescriptor> rpDesc(rt->newCompatibleRenderPassDescriptor());
+ rt->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(rt->create());
+
+ QRhiCommandBuffer *cb = nullptr;
+ QVERIFY(rhi->beginOffscreenFrame(&cb) == QRhi::FrameOpSuccess);
+ QVERIFY(cb);
+
+ QRhiResourceUpdateBatch *updates = rhi->nextResourceUpdateBatch();
+
+ //
+ // This test uses half3 vertices
+ //
+ // Note: D3D does not support half3 - rhi passes it through as half4. Because of this, D3D will
+ // report the following warning and error if we don't take precautions:
+ //
+ // D3D11 WARNING: ID3D11DeviceContext::Draw: Input vertex slot 0 has stride 6 which is less than
+ // the minimum stride logically expected from the current Input Layout (8 bytes). This is OK, as
+ // hardware is perfectly capable of reading overlapping data. However the developer probably did
+ // not intend to make use of this behavior. [ EXECUTION WARNING #355:
+ // DEVICE_DRAW_VERTEX_BUFFER_STRIDE_TOO_SMALL]
+ //
+ // D3D11 ERROR: ID3D11DeviceContext::Draw: Vertex Buffer Stride (6) at the input vertex slot 0
+ // is not aligned properly. The current Input Layout imposes an alignment of (4) because of the
+ // Formats used with this slot. [ EXECUTION ERROR #367: DEVICE_DRAW_VERTEX_STRIDE_UNALIGNED]
+ //
+ // The same warning and error are produced for D3D12. The rendered output is correct despite
+ // the warning and error.
+ //
+ // To avoid these errors, we pad the vertices to 8 byte stride.
+ //
+ static const qfloat16 vertices[] = {
+ qfloat16(-1.0), qfloat16(-1.0), qfloat16(0.0), qfloat16(0.0),
+ qfloat16(1.0), qfloat16(-1.0), qfloat16(0.0), qfloat16(0.0),
+ qfloat16(0.0), qfloat16(1.0), qfloat16(0.0), qfloat16(0.0),
+ };
+
+ QScopedPointer<QRhiBuffer> vbuf(rhi->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(vertices)));
+ QVERIFY(vbuf->create());
+ updates->uploadStaticBuffer(vbuf.data(), vertices);
+
+ QScopedPointer<QRhiShaderResourceBindings> srb(rhi->newShaderResourceBindings());
+ QVERIFY(srb->create());
+
+ QScopedPointer<QRhiGraphicsPipeline> pipeline(rhi->newGraphicsPipeline());
+ QShader vs = loadShader(":/data/half.vert.qsb");
+ QVERIFY(vs.isValid());
+ QShader fs = loadShader(":/data/simple.frag.qsb");
+ QVERIFY(fs.isValid());
+ pipeline->setShaderStages({ { QRhiShaderStage::Vertex, vs }, { QRhiShaderStage::Fragment, fs } });
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({ { 4 * sizeof(qfloat16) } }); // 8 byte vertex stride for D3D
+ inputLayout.setAttributes({ { 0, 0, QRhiVertexInputAttribute::Half3, 0 } });
+ pipeline->setVertexInputLayout(inputLayout);
+ pipeline->setShaderResourceBindings(srb.data());
+ pipeline->setRenderPassDescriptor(rpDesc.data());
+ QVERIFY(pipeline->create());
+
+ cb->beginPass(rt.data(), Qt::blue, { 1.0f, 0 }, updates);
+ cb->setGraphicsPipeline(pipeline.data());
+ cb->setViewport({ 0, 0, float(outputSize.width()), float(outputSize.height()) });
+ QRhiCommandBuffer::VertexInput vbindings(vbuf.data(), 0);
+ cb->setVertexInput(0, 1, &vbindings);
+ cb->draw(3);
+
+ QRhiReadbackResult readResult;
+ QImage result;
+ readResult.completed = [&readResult, &result] {
+ result = QImage(reinterpret_cast<const uchar *>(readResult.data.constData()),
+ readResult.pixelSize.width(), readResult.pixelSize.height(),
+ QImage::Format_RGBA8888_Premultiplied); // non-owning, no copy needed because readResult outlives result
+ };
+ QRhiResourceUpdateBatch *readbackBatch = rhi->nextResourceUpdateBatch();
+ readbackBatch->readBackTexture({ texture.data() }, &readResult);
+ cb->endPass(readbackBatch);
+
+ rhi->endOffscreenFrame();
+ // Offscreen frames are synchronous, so the readback is guaranteed to
+ // complete at this point. This would not be the case with swapchain-based
+ // frames.
+ QCOMPARE(result.size(), texture->pixelSize());
+
+ if (impl == QRhi::Null)
+ return;
+
+ // Now we have a red rectangle on blue background.
+ const int y = 100;
+ const quint32 *p = reinterpret_cast<const quint32 *>(result.constScanLine(y));
+ int x = result.width() - 1;
+ int redCount = 0;
+ int blueCount = 0;
+ const int maxFuzz = 1;
+ while (x-- >= 0) {
+ const QRgb c(*p++);
+ if (qRed(c) >= (255 - maxFuzz) && qGreen(c) == 0 && qBlue(c) == 0)
+ ++redCount;
+ else if (qRed(c) == 0 && qGreen(c) == 0 && qBlue(c) >= (255 - maxFuzz))
+ ++blueCount;
+ else
+ QFAIL("Encountered a pixel that is neither red or blue");
+ }
+
+ QCOMPARE(redCount + blueCount, texture->pixelSize().width());
+ QVERIFY(redCount != 0);
+ QVERIFY(blueCount != 0);
+
+ // The triangle is "pointing up" in the resulting image with OpenGL
+ // (because Y is up both in normalized device coordinates and in images)
+ // and Vulkan (because Y is down in both and the vertex data was specified
+ // with Y up in mind), but "pointing down" with D3D (because Y is up in NDC
+ // but down in images).
+ if (rhi->isYUpInFramebuffer() == rhi->isYUpInNDC())
+ QVERIFY(redCount < blueCount);
+ else
+ QVERIFY(redCount > blueCount);
+
}
#include <tst_qrhi.moc>
diff --git a/tests/auto/gui/rhi/qshader/CMakeLists.txt b/tests/auto/gui/rhi/qshader/CMakeLists.txt
index 9a0e246aa4..09bf0d585d 100644
--- a/tests/auto/gui/rhi/qshader/CMakeLists.txt
+++ b/tests/auto/gui/rhi/qshader/CMakeLists.txt
@@ -1,26 +1,28 @@
-# Generated from qshader.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qshader Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qshader LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# 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
+ 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}
-)
-
diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb
new file mode 100644
index 0000000000..4d49ede3ff
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb
new file mode 100644
index 0000000000..ea68da7eb4
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tesc.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb
new file mode 100644
index 0000000000..41005f76bc
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.tese.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb
new file mode 100644
index 0000000000..39734b6d5d
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/metal_enabled_tessellation_v7.vert.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb b/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb
new file mode 100644
index 0000000000..edcd84cbe6
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/storage_buffer_info_v8.comp.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/texture_sep_v6.frag.qsb b/tests/auto/gui/rhi/qshader/data/texture_sep_v6.frag.qsb
new file mode 100644
index 0000000000..b654ee576d
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data/texture_sep_v6.frag.qsb
Binary files differ
diff --git a/tests/auto/gui/rhi/qshader/data/color.vert b/tests/auto/gui/rhi/qshader/data_src/color.vert
index c92f71b9e1..c92f71b9e1 100644
--- a/tests/auto/gui/rhi/qshader/data/color.vert
+++ b/tests/auto/gui/rhi/qshader/data_src/color.vert
diff --git a/tests/auto/gui/rhi/qshader/data/texture.frag b/tests/auto/gui/rhi/qshader/data_src/texture.frag
index bd22f817e0..bd22f817e0 100644
--- a/tests/auto/gui/rhi/qshader/data/texture.frag
+++ b/tests/auto/gui/rhi/qshader/data_src/texture.frag
diff --git a/tests/auto/gui/rhi/qshader/data_src/texture_sep.frag b/tests/auto/gui/rhi/qshader/data_src/texture_sep.frag
new file mode 100644
index 0000000000..368e851bb4
--- /dev/null
+++ b/tests/auto/gui/rhi/qshader/data_src/texture_sep.frag
@@ -0,0 +1,17 @@
+#version 440
+
+layout(location = 0) in vec2 v_texcoord;
+
+layout(location = 0) out vec4 fragColor;
+
+layout(binding = 1) uniform sampler2D combinedTexSampler;
+layout(binding = 2) uniform texture2D sepTex;
+layout(binding = 3) uniform sampler sepSampler;
+layout(binding = 4) uniform sampler sepSampler2;
+
+void main()
+{
+ fragColor = texture(sampler2D(sepTex, sepSampler), v_texcoord);
+ fragColor *= texture(sampler2D(sepTex, sepSampler2), v_texcoord);
+ fragColor *= texture(combinedTexSampler, v_texcoord);
+}
diff --git a/tests/auto/gui/rhi/qshader/qshader.qrc b/tests/auto/gui/rhi/qshader/qshader.qrc
deleted file mode 100644
index f161d8aad6..0000000000
--- a/tests/auto/gui/rhi/qshader/qshader.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>data</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/rhi/qshader/tst_qshader.cpp b/tests/auto/gui/rhi/qshader/tst_qshader.cpp
index 1b3d861756..9e179c95c3 100644
--- a/tests/auto/gui/rhi/qshader/tst_qshader.cpp
+++ b/tests/auto/gui/rhi/qshader/tst_qshader.cpp
@@ -1,37 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QFile>
#include <QBuffer>
-#include <QtGui/private/qshaderdescription_p_p.h>
-#include <QtGui/private/qshader_p_p.h>
+#include <private/qshaderdescription_p.h>
+#include <private/qshader_p.h>
class tst_QShader : public QObject
{
@@ -43,11 +18,15 @@ private slots:
void genVariants();
void shaderDescImplicitSharing();
void bakedShaderImplicitSharing();
+ void sortedKeys();
void mslResourceMapping();
void serializeShaderDesc();
void comparison();
void loadV4();
void manualShaderPackCreation();
+ void loadV6WithSeparateImagesAndSamplers();
+ void loadV7();
+ void loadV8();
};
static QShader getShader(const QString &name)
@@ -80,7 +59,7 @@ void tst_QShader::simpleCompileCheckResults()
QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
QVERIFY(s.isValid());
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
- QCOMPARE(s.availableShaders().count(), 1);
+ QCOMPARE(s.availableShaders().size(), 1);
const QShaderCode shader = s.shader(QShaderKey(QShader::SpirvShader,
QShaderVersion(100)));
@@ -89,7 +68,7 @@ void tst_QShader::simpleCompileCheckResults()
const QShaderDescription desc = s.description();
QVERIFY(desc.isValid());
- QCOMPARE(desc.inputVariables().count(), 2);
+ QCOMPARE(desc.inputVariables().size(), 2);
for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) {
switch (v.location) {
case 0:
@@ -105,7 +84,7 @@ void tst_QShader::simpleCompileCheckResults()
break;
}
}
- QCOMPARE(desc.outputVariables().count(), 1);
+ QCOMPARE(desc.outputVariables().size(), 1);
for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) {
switch (v.location) {
case 0:
@@ -117,15 +96,15 @@ void tst_QShader::simpleCompileCheckResults()
break;
}
}
- QCOMPARE(desc.uniformBlocks().count(), 1);
+ QCOMPARE(desc.uniformBlocks().size(), 1);
const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first();
QCOMPARE(blk.blockName, QByteArrayLiteral("buf"));
QCOMPARE(blk.structName, QByteArrayLiteral("ubuf"));
QCOMPARE(blk.size, 68);
QCOMPARE(blk.binding, 0);
QCOMPARE(blk.descriptorSet, 0);
- QCOMPARE(blk.members.count(), 2);
- for (int i = 0; i < blk.members.count(); ++i) {
+ QCOMPARE(blk.members.size(), 2);
+ for (int i = 0; i < blk.members.size(); ++i) {
const QShaderDescription::BlockVariable v = blk.members[i];
switch (i) {
case 0:
@@ -142,7 +121,7 @@ void tst_QShader::simpleCompileCheckResults()
QCOMPARE(v.type, QShaderDescription::Float);
break;
default:
- QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.count())));
+ QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.size())));
break;
}
}
@@ -155,7 +134,7 @@ void tst_QShader::genVariants()
// + batchable variants
QVERIFY(s.isValid());
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
- QCOMPARE(s.availableShaders().count(), 2 * 6);
+ QCOMPARE(s.availableShaders().size(), 2 * 6);
int batchableVariantCount = 0;
int batchableGlslVariantCount = 0;
@@ -178,33 +157,33 @@ void tst_QShader::shaderDescImplicitSharing()
QShader s = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
QVERIFY(s.isValid());
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 5);
- QCOMPARE(s.availableShaders().count(), 1);
+ QCOMPARE(s.availableShaders().size(), 1);
QVERIFY(s.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QShaderDescription d0 = s.description();
QVERIFY(d0.isValid());
- QCOMPARE(d0.inputVariables().count(), 2);
- QCOMPARE(d0.outputVariables().count(), 1);
- QCOMPARE(d0.uniformBlocks().count(), 1);
+ QCOMPARE(d0.inputVariables().size(), 2);
+ QCOMPARE(d0.outputVariables().size(), 1);
+ QCOMPARE(d0.uniformBlocks().size(), 1);
QShaderDescription d1 = d0;
QVERIFY(QShaderDescriptionPrivate::get(&d0) == QShaderDescriptionPrivate::get(&d1));
- QCOMPARE(d0.inputVariables().count(), 2);
- QCOMPARE(d0.outputVariables().count(), 1);
- QCOMPARE(d0.uniformBlocks().count(), 1);
- QCOMPARE(d1.inputVariables().count(), 2);
- QCOMPARE(d1.outputVariables().count(), 1);
- QCOMPARE(d1.uniformBlocks().count(), 1);
+ QCOMPARE(d0.inputVariables().size(), 2);
+ QCOMPARE(d0.outputVariables().size(), 1);
+ QCOMPARE(d0.uniformBlocks().size(), 1);
+ QCOMPARE(d1.inputVariables().size(), 2);
+ QCOMPARE(d1.outputVariables().size(), 1);
+ QCOMPARE(d1.uniformBlocks().size(), 1);
QCOMPARE(d0, d1);
d1.detach();
QVERIFY(QShaderDescriptionPrivate::get(&d0) != QShaderDescriptionPrivate::get(&d1));
- QCOMPARE(d0.inputVariables().count(), 2);
- QCOMPARE(d0.outputVariables().count(), 1);
- QCOMPARE(d0.uniformBlocks().count(), 1);
- QCOMPARE(d1.inputVariables().count(), 2);
- QCOMPARE(d1.outputVariables().count(), 1);
- QCOMPARE(d1.uniformBlocks().count(), 1);
+ QCOMPARE(d0.inputVariables().size(), 2);
+ QCOMPARE(d0.outputVariables().size(), 1);
+ QCOMPARE(d0.uniformBlocks().size(), 1);
+ QCOMPARE(d1.inputVariables().size(), 2);
+ QCOMPARE(d1.outputVariables().size(), 1);
+ QCOMPARE(d1.uniformBlocks().size(), 1);
QCOMPARE(d0, d1);
d1 = QShaderDescription();
@@ -216,24 +195,24 @@ void tst_QShader::bakedShaderImplicitSharing()
QShader s0 = getShader(QLatin1String(":/data/color_spirv_v5.vert.qsb"));
QVERIFY(s0.isValid());
QCOMPARE(QShaderPrivate::get(&s0)->qsbVersion, 5);
- QCOMPARE(s0.availableShaders().count(), 1);
+ QCOMPARE(s0.availableShaders().size(), 1);
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
{
QShader s1 = s0;
QVERIFY(QShaderPrivate::get(&s0) == QShaderPrivate::get(&s1));
- QCOMPARE(s0.availableShaders().count(), 1);
+ QCOMPARE(s0.availableShaders().size(), 1);
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
- QCOMPARE(s1.availableShaders().count(), 1);
+ QCOMPARE(s1.availableShaders().size(), 1);
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QCOMPARE(s0.stage(), s1.stage());
QCOMPARE(s0, s1);
s1.detach();
QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1));
- QCOMPARE(s0.availableShaders().count(), 1);
+ QCOMPARE(s0.availableShaders().size(), 1);
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
- QCOMPARE(s1.availableShaders().count(), 1);
+ QCOMPARE(s1.availableShaders().size(), 1);
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QCOMPARE(s0.stage(), s1.stage());
QCOMPARE(s0, s1);
@@ -246,22 +225,32 @@ void tst_QShader::bakedShaderImplicitSharing()
s1.setStage(QShader::FragmentStage); // call a setter to trigger a detach
QVERIFY(QShaderPrivate::get(&s0) != QShaderPrivate::get(&s1));
- QCOMPARE(s0.availableShaders().count(), 1);
+ QCOMPARE(s0.availableShaders().size(), 1);
QVERIFY(s0.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
- QCOMPARE(s1.availableShaders().count(), 1);
+ QCOMPARE(s1.availableShaders().size(), 1);
QVERIFY(s1.availableShaders().contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QShaderDescription d0 = s0.description();
- QCOMPARE(d0.inputVariables().count(), 2);
- QCOMPARE(d0.outputVariables().count(), 1);
- QCOMPARE(d0.uniformBlocks().count(), 1);
+ QCOMPARE(d0.inputVariables().size(), 2);
+ QCOMPARE(d0.outputVariables().size(), 1);
+ QCOMPARE(d0.uniformBlocks().size(), 1);
QShaderDescription d1 = s1.description();
- QCOMPARE(d1.inputVariables().count(), 2);
- QCOMPARE(d1.outputVariables().count(), 1);
- QCOMPARE(d1.uniformBlocks().count(), 1);
+ QCOMPARE(d1.inputVariables().size(), 2);
+ QCOMPARE(d1.outputVariables().size(), 1);
+ QCOMPARE(d1.uniformBlocks().size(), 1);
QVERIFY(s0 != s1);
}
}
+void tst_QShader::sortedKeys()
+{
+ QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
+ QVERIFY(s.isValid());
+ QList<QShaderKey> availableShaders = s.availableShaders();
+ QCOMPARE(availableShaders.size(), 7);
+ std::sort(availableShaders.begin(), availableShaders.end());
+ QCOMPARE(availableShaders, s.availableShaders());
+}
+
void tst_QShader::mslResourceMapping()
{
QShader s = getShader(QLatin1String(":/data/texture_all_v4.frag.qsb"));
@@ -269,7 +258,7 @@ void tst_QShader::mslResourceMapping()
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4);
const QList<QShaderKey> availableShaders = s.availableShaders();
- QCOMPARE(availableShaders.count(), 7);
+ QCOMPARE(availableShaders.size(), 7);
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
@@ -278,19 +267,19 @@ void tst_QShader::mslResourceMapping()
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(330))));
- const QShader::NativeResourceBindingMap *resMap =
+ QShader::NativeResourceBindingMap resMap =
s.nativeResourceBindingMap(QShaderKey(QShader::GlslShader, QShaderVersion(330)));
- QVERIFY(!resMap);
+ QVERIFY(resMap.isEmpty());
// The Metal shader must come with a mapping table for binding points 0
// (uniform buffer) and 1 (combined image sampler mapped to a texture and
// sampler in the shader).
resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
- QVERIFY(resMap);
+ QVERIFY(!resMap.isEmpty());
- QCOMPARE(resMap->count(), 2);
- QCOMPARE(resMap->value(0).first, 0); // mapped to native buffer index 0
- QCOMPARE(resMap->value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0
+ QCOMPARE(resMap.size(), 2);
+ QCOMPARE(resMap.value(0).first, 0); // mapped to native buffer index 0
+ QCOMPARE(resMap.value(1), qMakePair(0, 0)); // mapped to native texture index 0 and sampler index 0
}
void tst_QShader::serializeShaderDesc()
@@ -305,7 +294,7 @@ void tst_QShader::serializeShaderDesc()
QBuffer buf(&data);
QDataStream ds(&buf);
QVERIFY(buf.open(QIODevice::WriteOnly));
- desc.serialize(&ds);
+ desc.serialize(&ds, QShaderPrivate::QSB_VERSION);
}
QVERIFY(!data.isEmpty());
@@ -330,7 +319,7 @@ void tst_QShader::serializeShaderDesc()
QBuffer buf(&data);
QDataStream ds(&buf);
QVERIFY(buf.open(QIODevice::WriteOnly));
- desc.serialize(&ds);
+ desc.serialize(&ds, QShaderPrivate::QSB_VERSION);
}
QVERIFY(!data.isEmpty());
@@ -390,7 +379,7 @@ void tst_QShader::loadV4()
QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 4);
const QList<QShaderKey> availableShaders = s.availableShaders();
- QCOMPARE(availableShaders.count(), 7);
+ QCOMPARE(availableShaders.size(), 7);
QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
@@ -401,7 +390,7 @@ void tst_QShader::loadV4()
const QShaderDescription desc = s.description();
QVERIFY(desc.isValid());
- QCOMPARE(desc.inputVariables().count(), 1);
+ QCOMPARE(desc.inputVariables().size(), 1);
for (const QShaderDescription::InOutVariable &v : desc.inputVariables()) {
switch (v.location) {
case 0:
@@ -413,7 +402,7 @@ void tst_QShader::loadV4()
break;
}
}
- QCOMPARE(desc.outputVariables().count(), 1);
+ QCOMPARE(desc.outputVariables().size(), 1);
for (const QShaderDescription::InOutVariable &v : desc.outputVariables()) {
switch (v.location) {
case 0:
@@ -425,15 +414,15 @@ void tst_QShader::loadV4()
break;
}
}
- QCOMPARE(desc.uniformBlocks().count(), 1);
+ QCOMPARE(desc.uniformBlocks().size(), 1);
const QShaderDescription::UniformBlock blk = desc.uniformBlocks().first();
QCOMPARE(blk.blockName, QByteArrayLiteral("buf"));
QCOMPARE(blk.structName, QByteArrayLiteral("ubuf"));
QCOMPARE(blk.size, 68);
QCOMPARE(blk.binding, 0);
QCOMPARE(blk.descriptorSet, 0);
- QCOMPARE(blk.members.count(), 2);
- for (int i = 0; i < blk.members.count(); ++i) {
+ QCOMPARE(blk.members.size(), 2);
+ for (int i = 0; i < blk.members.size(); ++i) {
const QShaderDescription::BlockVariable v = blk.members[i];
switch (i) {
case 0:
@@ -450,7 +439,7 @@ void tst_QShader::loadV4()
QCOMPARE(v.type, QShaderDescription::Float);
break;
default:
- QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.count())));
+ QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.size())));
break;
}
}
@@ -561,14 +550,151 @@ void tst_QShader::manualShaderPackCreation()
const QByteArray serialized = shaderPack.serialized();
QShader newShaderPack = QShader::fromSerialized(serialized);
- QCOMPARE(newShaderPack.availableShaders().count(), 2);
- QCOMPARE(newShaderPack.description().inputVariables().count(), 1);
- QCOMPARE(newShaderPack.description().outputVariables().count(), 1);
- QCOMPARE(newShaderPack.description().uniformBlocks().count(), 1);
- QCOMPARE(newShaderPack.description().combinedImageSamplers().count(), 1);
+ QCOMPARE(newShaderPack.availableShaders().size(), 2);
+ QCOMPARE(newShaderPack.description().inputVariables().size(), 1);
+ QCOMPARE(newShaderPack.description().outputVariables().size(), 1);
+ QCOMPARE(newShaderPack.description().uniformBlocks().size(), 1);
+ QCOMPARE(newShaderPack.description().combinedImageSamplers().size(), 1);
QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))).shader(), fs_gles);
QCOMPARE(newShaderPack.shader(QShaderKey(QShader::GlslShader, QShaderVersion(120))).shader(), fs_gl);
}
+void tst_QShader::loadV6WithSeparateImagesAndSamplers()
+{
+ QShader s = getShader(QLatin1String(":/data/texture_sep_v6.frag.qsb"));
+ QVERIFY(s.isValid());
+ QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 6);
+
+ const QList<QShaderKey> availableShaders = s.availableShaders();
+ QCOMPARE(availableShaders.size(), 6);
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(120))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(150))));
+
+ QShader::NativeResourceBindingMap resMap =
+ s.nativeResourceBindingMap(QShaderKey(QShader::HlslShader, QShaderVersion(50)));
+ QVERIFY(resMap.size() == 4);
+ QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::HlslShader, QShaderVersion(50))).isEmpty());
+ resMap = s.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12)));
+ QVERIFY(resMap.size() == 4);
+ QVERIFY(s.separateToCombinedImageSamplerMappingList(QShaderKey(QShader::MslShader, QShaderVersion(12))).isEmpty());
+
+ for (auto key : {
+ QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs)),
+ QShaderKey(QShader::GlslShader, QShaderVersion(120)),
+ QShaderKey(QShader::GlslShader, QShaderVersion(150)) })
+ {
+ auto list = s.separateToCombinedImageSamplerMappingList(key);
+ QCOMPARE(list.size(), 2);
+ }
+}
+
+void tst_QShader::loadV7()
+{
+ QShader vert = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.vert.qsb"));
+ QVERIFY(vert.isValid());
+ QCOMPARE(QShaderPrivate::get(&vert)->qsbVersion, 7);
+ QCOMPARE(vert.availableShaders().size(), 8);
+
+ QCOMPARE(vert.description().inputVariables().size(), 2);
+ QCOMPARE(vert.description().outputBuiltinVariables().size(), 1);
+ QCOMPARE(vert.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
+ QCOMPARE(vert.description().outputVariables().size(), 1);
+ QCOMPARE(vert.description().outputVariables()[0].name, QByteArrayLiteral("v_color"));
+
+ QVERIFY(vert.availableShaders().contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
+ QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::NonIndexedVertexAsComputeShader)).shader().isEmpty());
+ QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt16IndexedVertexAsComputeShader)).shader().isEmpty());
+ QVERIFY(!vert.shader(QShaderKey(QShader::MslShader, QShaderVersion(12), QShader::UInt32IndexedVertexAsComputeShader)).shader().isEmpty());
+
+ QShader tesc = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tesc.qsb"));
+ QVERIFY(tesc.isValid());
+ QCOMPARE(QShaderPrivate::get(&tesc)->qsbVersion, 7);
+ QCOMPARE(tesc.availableShaders().size(), 5);
+ QCOMPARE(tesc.description().tessellationOutputVertexCount(), 3u);
+
+ QCOMPARE(tesc.description().inputBuiltinVariables().size(), 2);
+ QCOMPARE(tesc.description().outputBuiltinVariables().size(), 3);
+ // builtins must be sorted based on the type
+ QCOMPARE(tesc.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
+ QCOMPARE(tesc.description().inputBuiltinVariables()[1].type, QShaderDescription::InvocationIdBuiltin);
+ QCOMPARE(tesc.description().outputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
+ QCOMPARE(tesc.description().outputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin);
+ QCOMPARE(tesc.description().outputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin);
+
+ QCOMPARE(tesc.description().outputVariables().size(), 3);
+ for (const QShaderDescription::InOutVariable &v : tesc.description().outputVariables()) {
+ switch (v.location) {
+ case 0:
+ QCOMPARE(v.name, QByteArrayLiteral("outColor"));
+ QCOMPARE(v.type, QShaderDescription::Vec3);
+ QCOMPARE(v.perPatch, false);
+ break;
+ case 1:
+ QCOMPARE(v.name, QByteArrayLiteral("stuff"));
+ QCOMPARE(v.type, QShaderDescription::Vec3);
+ QCOMPARE(v.perPatch, true);
+ break;
+ case 2:
+ QCOMPARE(v.name, QByteArrayLiteral("more_stuff"));
+ QCOMPARE(v.type, QShaderDescription::Float);
+ QCOMPARE(v.perPatch, true);
+ break;
+ default:
+ QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
+ break;
+ }
+ }
+
+ QVERIFY(!tesc.shader(QShaderKey(QShader::MslShader, QShaderVersion(12))).shader().isEmpty());
+ QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::SpirvShader, QShaderVersion(100))).extraBufferBindings.size(), 0);
+ QCOMPARE(tesc.nativeShaderInfo(QShaderKey(QShader::MslShader, QShaderVersion(12))).extraBufferBindings.size(), 5);
+
+ QShader tese = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.tese.qsb"));
+ QVERIFY(tese.isValid());
+ QCOMPARE(QShaderPrivate::get(&tese)->qsbVersion, 7);
+ QCOMPARE(tese.availableShaders().size(), 5);
+ QCOMPARE(tese.description().tessellationMode(), QShaderDescription::TrianglesTessellationMode);
+ QCOMPARE(tese.description().tessellationWindingOrder(), QShaderDescription::CcwTessellationWindingOrder);
+ QCOMPARE(tese.description().tessellationPartitioning(), QShaderDescription::FractionalOddTessellationPartitioning);
+
+ QCOMPARE(tese.description().inputBuiltinVariables()[0].type, QShaderDescription::PositionBuiltin);
+ QCOMPARE(tese.description().inputBuiltinVariables()[1].type, QShaderDescription::TessLevelOuterBuiltin);
+ QCOMPARE(tese.description().inputBuiltinVariables()[2].type, QShaderDescription::TessLevelInnerBuiltin);
+ QCOMPARE(tese.description().inputBuiltinVariables()[3].type, QShaderDescription::TessCoordBuiltin);
+
+ QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).size(), 1);
+ QCOMPARE(tese.nativeResourceBindingMap(QShaderKey(QShader::MslShader, QShaderVersion(12))).value(0), qMakePair(0, -1));
+
+ QShader frag = getShader(QLatin1String(":/data/metal_enabled_tessellation_v7.frag.qsb"));
+ QVERIFY(frag.isValid());
+ QCOMPARE(QShaderPrivate::get(&frag)->qsbVersion, 7);
+}
+
+void tst_QShader::loadV8()
+{
+ QShader s = getShader(QLatin1String(":/data/storage_buffer_info_v8.comp.qsb"));
+ QVERIFY(s.isValid());
+ QCOMPARE(QShaderPrivate::get(&s)->qsbVersion, 8);
+
+ const QList<QShaderKey> availableShaders = s.availableShaders();
+ QCOMPARE(availableShaders.size(), 5);
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::SpirvShader, QShaderVersion(100))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::MslShader, QShaderVersion(12))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::HlslShader, QShaderVersion(50))));
+ QVERIFY(availableShaders.contains(
+ QShaderKey(QShader::GlslShader, QShaderVersion(310, QShaderVersion::GlslEs))));
+ QVERIFY(availableShaders.contains(QShaderKey(QShader::GlslShader, QShaderVersion(430))));
+
+ QCOMPARE(s.description().storageBlocks().size(), 1);
+ QCOMPARE(s.description().storageBlocks().last().runtimeArrayStride, 4);
+ QCOMPARE(s.description().storageBlocks().last().qualifierFlags,
+ QShaderDescription::QualifierFlags(QShaderDescription::QualifierWriteOnly
+ | QShaderDescription::QualifierRestrict));
+}
+
#include <tst_qshader.moc>
QTEST_MAIN(tst_QShader)
diff --git a/tests/auto/gui/text/CMakeLists.txt b/tests/auto/gui/text/CMakeLists.txt
index b7262f7c00..bad13de7dc 100644
--- a/tests/auto/gui/text/CMakeLists.txt
+++ b/tests/auto/gui/text/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from text.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qabstracttextdocumentlayout)
add_subdirectory(qfont)
@@ -13,9 +14,10 @@ add_subdirectory(qtextcursor)
add_subdirectory(qtextdocumentfragment)
add_subdirectory(qtextdocumentlayout)
add_subdirectory(qtextformat)
+add_subdirectory(qtextimagehandler)
add_subdirectory(qtextlist)
add_subdirectory(qtextobject)
-# add_subdirectory(qtextscriptengine) # disable until system_harfbuzz feature is available # special case
+# add_subdirectory(qtextscriptengine) # disable until system_harfbuzz feature is available
add_subdirectory(qtexttable)
add_subdirectory(qinputcontrol)
if(QT_FEATURE_private_tests AND TARGET Qt::Xml)
@@ -24,11 +26,9 @@ endif()
if(QT_FEATURE_private_tests)
add_subdirectory(qfontcache)
add_subdirectory(qtextlayout)
- add_subdirectory(qzip)
add_subdirectory(qtextodfwriter)
endif()
-# QTBUG-87671 # special case
-if(TARGET Qt::Xml AND NOT ANDROID)
+if(TARGET Qt::Xml)
add_subdirectory(qtextdocument)
endif()
if(QT_FEATURE_private_tests AND UNIX)
diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt
index f78e1d81c7..316b9cd3c6 100644
--- a/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt
+++ b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qabstracttextdocumentlayout.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qabstracttextdocumentlayout Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qabstracttextdocumentlayout LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qabstracttextdocumentlayout
SOURCES
tst_qabstracttextdocumentlayout.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
index cdd2b9cd44..2ae2ccda0a 100644
--- a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
+++ b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -151,7 +126,7 @@ void tst_QAbstractTextDocumentLayout::anchorAt()
QAbstractTextDocumentLayout *documentLayout = doc.documentLayout();
QTextBlock firstBlock = doc.begin();
QTextLayout *layout = firstBlock.layout();
- layout->setPreeditArea(doc.toPlainText().length(), "xxx");
+ layout->setPreeditArea(doc.toPlainText().size(), "xxx");
doc.setPageSize(QSizeF(1000, 1000));
QFontMetrics metrics(layout->font());
@@ -181,7 +156,7 @@ void tst_QAbstractTextDocumentLayout::imageAt()
QAbstractTextDocumentLayout *documentLayout = doc.documentLayout();
QTextBlock firstBlock = doc.begin();
QTextLayout *layout = firstBlock.layout();
- layout->setPreeditArea(doc.toPlainText().length(), "xxx");
+ layout->setPreeditArea(doc.toPlainText().size(), "xxx");
doc.setPageSize(QSizeF(1000, 1000));
QFontMetrics metrics(layout->font());
@@ -206,7 +181,7 @@ void tst_QAbstractTextDocumentLayout::formatAt()
QAbstractTextDocumentLayout *documentLayout = doc.documentLayout();
QTextBlock firstBlock = doc.begin();
QTextLayout *layout = firstBlock.layout();
- layout->setPreeditArea(doc.toPlainText().length(), "xxx");
+ layout->setPreeditArea(doc.toPlainText().size(), "xxx");
doc.setPageSize(QSizeF(1000, 1000));
QFontMetrics metrics(layout->font());
diff --git a/tests/auto/gui/text/qcssparser/CMakeLists.txt b/tests/auto/gui/text/qcssparser/CMakeLists.txt
index 058a42d68c..e766ec5484 100644
--- a/tests/auto/gui/text/qcssparser/CMakeLists.txt
+++ b/tests/auto/gui/text/qcssparser/CMakeLists.txt
@@ -1,55 +1,28 @@
-# Generated from qcssparser.pro.
-
-if(NOT QT_FEATURE_private_tests)
- return()
-endif()
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcssparser Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcssparser LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
-list(APPEND test_data "testdata")
+file(GLOB_RECURSE test_data
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ testdata/*
+)
qt_internal_add_test(tst_qcssparser
SOURCES
tst_qcssparser.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
Qt::Xml
TESTDATA ${test_data}
)
-
-#### Keys ignored in scope 1:.:.:qcssparser.pro:<TRUE>:
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(testdata_resource_files
- "testdata/scanner/comments/input"
- "testdata/scanner/comments/output"
- "testdata/scanner/comments2/input"
- "testdata/scanner/comments2/output"
- "testdata/scanner/comments3/input"
- "testdata/scanner/comments3/output"
- "testdata/scanner/comments4/input"
- "testdata/scanner/comments4/output"
- "testdata/scanner/quotedstring/input"
- "testdata/scanner/quotedstring/output"
- "testdata/scanner/simple/input"
- "testdata/scanner/simple/output"
- "testdata/scanner/unicode/input"
- "testdata/scanner/unicode/output"
- )
-
- qt_internal_add_resource(tst_qcssparser "testdata"
- PREFIX
- "/"
- FILES
- ${testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/text/qcssparser/testdata.qrc b/tests/auto/gui/text/qcssparser/testdata.qrc
deleted file mode 100644
index 56e45cfbb0..0000000000
--- a/tests/auto/gui/text/qcssparser/testdata.qrc
+++ /dev/null
@@ -1,18 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>testdata/scanner/comments/input</file>
- <file>testdata/scanner/comments/output</file>
- <file>testdata/scanner/comments2/input</file>
- <file>testdata/scanner/comments2/output</file>
- <file>testdata/scanner/comments3/input</file>
- <file>testdata/scanner/comments3/output</file>
- <file>testdata/scanner/comments4/input</file>
- <file>testdata/scanner/comments4/output</file>
- <file>testdata/scanner/quotedstring/input</file>
- <file>testdata/scanner/quotedstring/output</file>
- <file>testdata/scanner/simple/input</file>
- <file>testdata/scanner/simple/output</file>
- <file>testdata/scanner/unicode/input</file>
- <file>testdata/scanner/unicode/output</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
index f51c0eab20..a438d7ebc8 100644
--- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
+++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
@@ -1,30 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
#include <QTest>
#include <QtXml/QtXml>
#include <QtGui/QFontInfo>
@@ -94,7 +70,8 @@ void tst_QCssParser::scanner_data()
#endif
d.cd("testdata");
d.cd("scanner");
- foreach (QFileInfo test, d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) {
+ const auto entries = d.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
+ for (const QFileInfo &test : entries) {
QString dir = test.absoluteFilePath() + QDir::separator();
QTest::newRow(qPrintable(test.baseName()))
<< dir + "input"
@@ -151,7 +128,7 @@ static const char *tokenName(QCss::TokenType t)
static void debug(const QList<QCss::Symbol> &symbols, int index = -1)
{
qDebug() << "all symbols:";
- for (int i = 0; i < symbols.count(); ++i)
+ for (int i = 0; i < symbols.size(); ++i)
qDebug() << '(' << i << "); Token:" << tokenName(symbols.at(i).token) << "; Lexem:" << symbols.at(i).lexem();
if (index != -1)
qDebug() << "failure at index" << index;
@@ -169,10 +146,10 @@ void tst_QCssParser::scanner()
QList<QCss::Symbol> symbols;
QCss::Scanner::scan(QCss::Scanner::preprocess(QString::fromUtf8(inputFile.readAll())), &symbols);
- QVERIFY(symbols.count() > 1);
+ QVERIFY(symbols.size() > 1);
QCOMPARE(symbols.last().token, QCss::S);
QCOMPARE(symbols.last().lexem(), QLatin1String("\n"));
- symbols.remove(symbols.count() - 1, 1);
+ symbols.remove(symbols.size() - 1, 1);
QFile outputFile(output);
QVERIFY(outputFile.open(QIODevice::ReadOnly|QIODevice::Text));
@@ -184,14 +161,14 @@ void tst_QCssParser::scanner()
lines.append(line);
}
- if (lines.count() != symbols.count()) {
+ if (lines.size() != symbols.size()) {
debug(symbols);
- QCOMPARE(lines.count(), symbols.count());
+ QCOMPARE(lines.size(), symbols.size());
}
- for (int i = 0; i < lines.count(); ++i) {
+ for (int i = 0; i < lines.size(); ++i) {
QStringList l = lines.at(i).split(QChar::fromLatin1('|'));
- QCOMPARE(l.count(), 2);
+ QCOMPARE(l.size(), 2);
const QString expectedToken = l.at(0);
const QString expectedLexem = l.at(1);
QString actualToken = QString::fromLatin1(tokenName(symbols.at(i).token));
@@ -375,9 +352,9 @@ void tst_QCssParser::expr()
QVERIFY(parser.testExpr());
QCOMPARE(parser.parseExpr(&values), parseSuccess);
if (parseSuccess) {
- QCOMPARE(values.count(), expectedValues.count());
+ QCOMPARE(values.size(), expectedValues.size());
- for (int i = 0; i < values.count(); ++i) {
+ for (int i = 0; i < values.size(); ++i) {
QCOMPARE(int(values.at(i).type), int(expectedValues.at(i).type));
QCOMPARE(values.at(i).variant, expectedValues.at(i).variant);
}
@@ -396,7 +373,7 @@ void tst_QCssParser::import()
QVERIFY(parser.testImport());
QVERIFY(parser.parseImport(&rule));
QCOMPARE(rule.href, QString("www.kde.org"));
- QCOMPARE(rule.media.count(), 2);
+ QCOMPARE(rule.media.size(), 2);
QCOMPARE(rule.media.at(0), QString("print"));
QCOMPARE(rule.media.at(1), QString("screen"));
}
@@ -407,7 +384,7 @@ void tst_QCssParser::media()
QVERIFY(parser.testMedia());
QCss::MediaRule rule;
QVERIFY(parser.parseMedia(&rule));
- QCOMPARE(rule.media.count(), 2);
+ QCOMPARE(rule.media.size(), 2);
QCOMPARE(rule.media.at(0), QString("print"));
QCOMPARE(rule.media.at(1), QString("screen"));
QVERIFY(rule.styleRules.isEmpty());
@@ -430,8 +407,8 @@ void tst_QCssParser::ruleset()
QVERIFY(parser.testRuleset());
QCss::StyleRule rule;
QVERIFY(parser.parseRuleset(&rule));
- QCOMPARE(rule.selectors.count(), 1);
- QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1);
+ QCOMPARE(rule.selectors.size(), 1);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1);
QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p"));
QVERIFY(rule.declarations.isEmpty());
}
@@ -441,10 +418,10 @@ void tst_QCssParser::ruleset()
QVERIFY(parser.testRuleset());
QCss::StyleRule rule;
QVERIFY(parser.parseRuleset(&rule));
- QCOMPARE(rule.selectors.count(), 2);
- QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1);
+ QCOMPARE(rule.selectors.size(), 2);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1);
QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p"));
- QCOMPARE(rule.selectors.at(1).basicSelectors.count(), 1);
+ QCOMPARE(rule.selectors.at(1).basicSelectors.size(), 1);
QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).elementName, QString("div"));
QVERIFY(rule.declarations.isEmpty());
}
@@ -454,14 +431,14 @@ void tst_QCssParser::ruleset()
QVERIFY(parser.testRuleset());
QCss::StyleRule rule;
QVERIFY(parser.parseRuleset(&rule));
- QCOMPARE(rule.selectors.count(), 2);
+ QCOMPARE(rule.selectors.size(), 2);
- QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1);
- QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.count(), 1);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.size(), 1);
QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).pseudos.at(0).name, QString("before"));
- QCOMPARE(rule.selectors.at(1).basicSelectors.count(), 1);
- QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.count(), 1);
+ QCOMPARE(rule.selectors.at(1).basicSelectors.size(), 1);
+ QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.size(), 1);
QCOMPARE(rule.selectors.at(1).basicSelectors.at(0).pseudos.at(0).name, QString("after"));
QVERIFY(rule.declarations.isEmpty());
@@ -713,21 +690,21 @@ void tst_QCssParser::selector()
QCss::Selector selector;
QVERIFY(parser.parseSelector(&selector));
- QCOMPARE(selector.basicSelectors.count(), expectedSelector.basicSelectors.count());
- for (int i = 0; i < selector.basicSelectors.count(); ++i) {
+ QCOMPARE(selector.basicSelectors.size(), expectedSelector.basicSelectors.size());
+ for (int i = 0; i < selector.basicSelectors.size(); ++i) {
const QCss::BasicSelector sel = selector.basicSelectors.at(i);
const QCss::BasicSelector expectedSel = expectedSelector.basicSelectors.at(i);
QCOMPARE(sel.elementName, expectedSel.elementName);
QCOMPARE(int(sel.relationToNext), int(expectedSel.relationToNext));
- QCOMPARE(sel.pseudos.count(), expectedSel.pseudos.count());
- for (int i = 0; i < sel.pseudos.count(); ++i) {
+ QCOMPARE(sel.pseudos.size(), expectedSel.pseudos.size());
+ for (int i = 0; i < sel.pseudos.size(); ++i) {
QCOMPARE(sel.pseudos.at(i).name, expectedSel.pseudos.at(i).name);
QCOMPARE(sel.pseudos.at(i).function, expectedSel.pseudos.at(i).function);
}
- QCOMPARE(sel.attributeSelectors.count(), expectedSel.attributeSelectors.count());
- for (int i = 0; i < sel.attributeSelectors.count(); ++i) {
+ QCOMPARE(sel.attributeSelectors.size(), expectedSel.attributeSelectors.size());
+ for (int i = 0; i < sel.attributeSelectors.size(); ++i) {
QCOMPARE(sel.attributeSelectors.at(i).name, expectedSel.attributeSelectors.at(i).name);
QCOMPARE(sel.attributeSelectors.at(i).value, expectedSel.attributeSelectors.at(i).value);
QCOMPARE(int(sel.attributeSelectors.at(i).valueMatchCriterium), int(expectedSel.attributeSelectors.at(i).valueMatchCriterium));
@@ -785,13 +762,13 @@ void tst_QCssParser::malformedDeclarations()
QCss::StyleRule rule;
QVERIFY(parser.parseRuleset(&rule));
- QCOMPARE(rule.selectors.count(), 1);
- QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1);
+ QCOMPARE(rule.selectors.size(), 1);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1);
QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("p"));
- QVERIFY(rule.declarations.count() >= 1);
+ QVERIFY(rule.declarations.size() >= 1);
QCOMPARE(int(rule.declarations.last().d->propertyId), int(QCss::Color));
- QCOMPARE(rule.declarations.last().d->values.count(), 1);
+ QCOMPARE(rule.declarations.last().d->values.size(), 1);
QCOMPARE(int(rule.declarations.last().d->values.at(0).type), int(QCss::Value::Identifier));
QCOMPARE(rule.declarations.last().d->values.at(0).variant.toString(), QString("green"));
}
@@ -811,17 +788,17 @@ void tst_QCssParser::invalidAtKeywords()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
- QCOMPARE(rule.selectors.count(), 1);
- QCOMPARE(rule.selectors.at(0).basicSelectors.count(), 1);
+ QCOMPARE(rule.selectors.size(), 1);
+ QCOMPARE(rule.selectors.at(0).basicSelectors.size(), 1);
QCOMPARE(rule.selectors.at(0).basicSelectors.at(0).elementName, QString("h1"));
- QCOMPARE(rule.declarations.count(), 1);
+ QCOMPARE(rule.declarations.size(), 1);
QCOMPARE(int(rule.declarations.at(0).d->propertyId), int(QCss::Color));
- QCOMPARE(rule.declarations.at(0).d->values.count(), 1);
+ QCOMPARE(rule.declarations.at(0).d->values.size(), 1);
QCOMPARE(int(rule.declarations.at(0).d->values.at(0).type), int(QCss::Value::Identifier));
QCOMPARE(rule.declarations.at(0).d->values.at(0).variant.toString(), QString("blue"));
}
@@ -886,32 +863,34 @@ public:
styleSheets.append(sheet);
}
- virtual QStringList nodeNames(NodePtr node) const override { return QStringList(reinterpret_cast<QDomElement *>(node.ptr)->tagName()); }
- virtual QString attribute(NodePtr node, const QString &name) const override { return reinterpret_cast<QDomElement *>(node.ptr)->attribute(name); }
- virtual bool hasAttribute(NodePtr node, const QString &name) const { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttribute(name); }
- virtual bool hasAttributes(NodePtr node) const override { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttributes(); }
-
- virtual bool isNullNode(NodePtr node) const override {
- return reinterpret_cast<QDomElement *>(node.ptr)->isNull();
- }
- virtual NodePtr parentNode(NodePtr node) const override {
+ QStringList nodeNames(NodePtr node) const override
+ { return QStringList(reinterpret_cast<QDomElement *>(node.ptr)->tagName()); }
+ QString attributeValue(NodePtr node, const QCss::AttributeSelector &aSel) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->attribute(aSel.name); }
+ bool hasAttribute(NodePtr node, const QString &name) const
+ { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttribute(name); }
+ bool hasAttributes(NodePtr node) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->hasAttributes(); }
+
+ bool isNullNode(NodePtr node) const override
+ { return reinterpret_cast<QDomElement *>(node.ptr)->isNull(); }
+ NodePtr parentNode(NodePtr node) const override {
NodePtr parent;
parent.ptr = new QDomElement(reinterpret_cast<QDomElement *>(node.ptr)->parentNode().toElement());
return parent;
}
- virtual NodePtr duplicateNode(NodePtr node) const override {
+ NodePtr duplicateNode(NodePtr node) const override {
NodePtr n;
n.ptr = new QDomElement(*reinterpret_cast<QDomElement *>(node.ptr));
return n;
}
- virtual NodePtr previousSiblingNode(NodePtr node) const override {
+ NodePtr previousSiblingNode(NodePtr node) const override {
NodePtr sibling;
sibling.ptr = new QDomElement(reinterpret_cast<QDomElement *>(node.ptr)->previousSiblingElement());
return sibling;
}
- virtual void freeNode(NodePtr node) const override {
- delete reinterpret_cast<QDomElement *>(node.ptr);
- }
+ void freeNode(NodePtr node) const override
+ { delete reinterpret_cast<QDomElement *>(node.ptr); }
private:
QDomDocument doc;
@@ -1164,9 +1143,9 @@ void tst_QCssParser::styleSelector()
QList<QCss::Declaration> decls = testSelector.declarationsForNode(n);
if (match) {
- QCOMPARE(decls.count(), 1);
+ QCOMPARE(decls.size(), 1);
QCOMPARE(int(decls.at(0).d->propertyId), int(QCss::BackgroundColor));
- QCOMPARE(decls.at(0).d->values.count(), 1);
+ QCOMPARE(decls.at(0).d->values.size(), 1);
QCOMPARE(int(decls.at(0).d->values.at(0).type), int(QCss::Value::Identifier));
QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), QString("green"));
} else {
@@ -1206,11 +1185,11 @@ void tst_QCssParser::specificity()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count() + sheet.idIndex.count() , 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size() + sheet.idIndex.size() , 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ? sheet.styleRules.at(0)
: (!sheet.nameIndex.isEmpty()) ? *sheet.nameIndex.begin()
: *sheet.idIndex.begin();
- QCOMPARE(rule.selectors.count(), 1);
+ QCOMPARE(rule.selectors.size(), 1);
QTEST(rule.selectors.at(0).specificity(), "specificity");
}
@@ -1259,15 +1238,15 @@ void tst_QCssParser::specificitySort()
n.ptr = &e;
QList<QCss::Declaration> decls = testSelector.declarationsForNode(n);
- QCOMPARE(decls.count(), 2);
+ QCOMPARE(decls.size(), 2);
QCOMPARE(int(decls.at(0).d->propertyId), int(QCss::Color));
- QCOMPARE(decls.at(0).d->values.count(), 1);
+ QCOMPARE(decls.at(0).d->values.size(), 1);
QCOMPARE(int(decls.at(0).d->values.at(0).type), int(QCss::Value::Identifier));
QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), QString("green"));
QCOMPARE(int(decls.at(1).d->propertyId), int(QCss::Color));
- QCOMPARE(decls.at(1).d->values.count(), 1);
+ QCOMPARE(decls.at(1).d->values.size(), 1);
QCOMPARE(int(decls.at(1).d->values.at(0).type), int(QCss::Value::Identifier));
QCOMPARE(decls.at(1).d->values.at(0).variant.toString(), QString("red"));
}
@@ -1342,7 +1321,7 @@ void tst_QCssParser::rulesForNode()
QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n);
QList<QCss::Declaration> decls;
- for (int i = 0; i < rules.count(); i++) {
+ for (int i = 0; i < rules.size(); i++) {
const QCss::Selector &selector = rules.at(i).selectors.at(0);
quint64 negated = 0;
quint64 cssClass = selector.pseudoClass(&negated);
@@ -1351,7 +1330,7 @@ void tst_QCssParser::rulesForNode()
decls += rules.at(i).declarations;
}
- QCOMPARE(decls.count(), declCount);
+ QCOMPARE(decls.size(), declCount);
if (declCount > 0)
QCOMPARE(decls.at(0).d->values.at(0).variant.toString(), value0);
@@ -1478,14 +1457,14 @@ void tst_QCssParser::pseudoElement()
n.ptr = &e;
QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n);
QList<QCss::Declaration> decls;
- for (int i = 0; i < rules.count(); i++) {
+ for (int i = 0; i < rules.size(); i++) {
const QCss::Selector& selector = rules.at(i).selectors.at(0);
if (pseudoElement.compare(selector.pseudoElement(), Qt::CaseInsensitive) != 0)
continue;
decls += rules.at(i).declarations;
}
- QCOMPARE(decls.count(), declCount);
+ QCOMPARE(decls.size(), declCount);
}
void tst_QCssParser::gradient_data()
@@ -1566,20 +1545,26 @@ void tst_QCssParser::gradient()
QList<QCss::StyleRule> rules = testSelector.styleRulesForNode(n);
QList<QCss::Declaration> decls = rules.at(0).declarations;
QCss::ValueExtractor ve(decls);
- QBrush fg, sfg;
- QBrush sbg, abg;
- QVERIFY(ve.extractPalette(&fg, &sfg, &sbg, &abg));
+ QBrush foreground;
+ QBrush selectedForeground;
+ QBrush selectedBackground;
+ QBrush alternateBackground;
+ QBrush placeHolderTextForeground;
+ QBrush accent;
+ QVERIFY(ve.extractPalette(&foreground, &selectedForeground, &selectedBackground,
+ &alternateBackground, &placeHolderTextForeground, &accent));
+
if (type == "linear") {
- QCOMPARE(sbg.style(), Qt::LinearGradientPattern);
- const QLinearGradient *lg = static_cast<const QLinearGradient *>(sbg.gradient());
+ QCOMPARE(selectedBackground.style(), Qt::LinearGradientPattern);
+ const auto *lg = static_cast<const QLinearGradient *>(selectedBackground.gradient());
QCOMPARE(lg->start(), start);
QCOMPARE(lg->finalStop(), finalStop);
} else if (type == "conical") {
- QCOMPARE(sbg.style(), Qt::ConicalGradientPattern);
- const QConicalGradient *cg = static_cast<const QConicalGradient *>(sbg.gradient());
+ QCOMPARE(selectedBackground.style(), Qt::ConicalGradientPattern);
+ const auto *cg = static_cast<const QConicalGradient *>(selectedBackground.gradient());
QCOMPARE(cg->center(), start);
}
- const QGradient *g = sbg.gradient();
+ const QGradient *g = selectedBackground.gradient();
QCOMPARE(g->spread(), QGradient::Spread(spread));
QCOMPARE(g->stops().at(0).first, stop0);
QCOMPARE(g->stops().at(0).second, color0);
@@ -1619,7 +1604,7 @@ void tst_QCssParser::extractFontFamily()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
@@ -1677,7 +1662,7 @@ void tst_QCssParser::extractBorder()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
const QList<QCss::Declaration> decls = rule.declarations;
@@ -1707,7 +1692,7 @@ void tst_QCssParser::noTextDecoration()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
const QList<QCss::Declaration> decls = rule.declarations;
@@ -1732,7 +1717,7 @@ void tst_QCssParser::quotedAndUnquotedIdentifiers()
QCss::StyleSheet sheet;
QVERIFY(parser.parse(&sheet));
- QCOMPARE(sheet.styleRules.count() + sheet.nameIndex.count(), 1);
+ QCOMPARE(sheet.styleRules.size() + sheet.nameIndex.size(), 1);
QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
sheet.styleRules.at(0) : *sheet.nameIndex.begin();
const QList<QCss::Declaration> decls = rule.declarations;
diff --git a/tests/auto/gui/text/qfont/BLACKLIST b/tests/auto/gui/text/qfont/BLACKLIST
index 3629f1fee6..f85d8ceebb 100644
--- a/tests/auto/gui/text/qfont/BLACKLIST
+++ b/tests/auto/gui/text/qfont/BLACKLIST
@@ -1,10 +1,8 @@
[defaultFamily:cursive]
-ubuntu-20.04
centos
b2qt
rhel
[defaultFamily:fantasy]
-ubuntu-20.04
centos
b2qt
rhel
diff --git a/tests/auto/gui/text/qfont/CMakeLists.txt b/tests/auto/gui/text/qfont/CMakeLists.txt
index 05c6ca8270..88ae9959e4 100644
--- a/tests/auto/gui/text/qfont/CMakeLists.txt
+++ b/tests/auto/gui/text/qfont/CMakeLists.txt
@@ -1,36 +1,38 @@
-# Generated from qfont.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfont Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfont LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+# Resources:
+set(testfont_resource_files
+ "datastream.515"
+ "weirdfont.otf"
+)
+
qt_internal_add_test(tst_qfont
SOURCES
tst_qfont.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
Qt::TestPrivate
+ TESTDATA ${testfont_resource_files}
+ BUILTIN_TESTDATA
)
-# Resources:
-set(testfont_resource_files
- "weirdfont.otf"
-)
-
-qt_internal_add_resource(tst_qfont "testfont"
- PREFIX
- "/"
- FILES
- ${testfont_resource_files}
-)
-
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qfont CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qfont/datastream.515 b/tests/auto/gui/text/qfont/datastream.515
new file mode 100644
index 0000000000..acd99e7e9b
--- /dev/null
+++ b/tests/auto/gui/text/qfont/datastream.515
Binary files differ
diff --git a/tests/auto/gui/text/qfont/testfont.qrc b/tests/auto/gui/text/qfont/testfont.qrc
deleted file mode 100644
index cf51e4a2b4..0000000000
--- a/tests/auto/gui/text/qfont/testfont.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>weirdfont.otf</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 6bae45e5c3..5426d7b117 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -1,30 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QBuffer>
@@ -44,6 +21,9 @@
#endif
#include <qlist.h>
#include <QtTest/private/qemulationdetector_p.h>
+#include <private/qcomparisontesthelper_p.h>
+
+using namespace Qt::StringLiterals;
class tst_QFont : public QObject
{
@@ -62,6 +42,7 @@ private slots:
void insertAndRemoveSubstitutions();
void serialize_data();
void serialize();
+ void deserializeQt515();
void styleName();
void defaultFamily_data();
@@ -78,6 +59,9 @@ private slots:
void setFamilies();
void setFamiliesAndFamily_data();
void setFamiliesAndFamily();
+ void featureAccessors();
+ void tagCompares_data();
+ void tagCompares();
};
// Testing get/set functions
@@ -174,7 +158,7 @@ void tst_QFont::italicOblique()
continue;
}
QFont f = QFontDatabase::font(family, style, 12);
- QVERIFY(f.italic());
+ QVERIFY2(f.italic(), qPrintable(QString::asprintf("Failed for font \"%ls\"", qUtf16Printable(f.family()))));
}
}
}
@@ -381,15 +365,15 @@ void tst_QFont::insertAndRemoveSubstitutions()
// inserting Foo
QFont::insertSubstitution("BogusFontFamily", "Foo");
- QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 1);
- QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 1);
+ QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 1);
+ QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 1);
// inserting Bar and Baz
QStringList moreFonts;
moreFonts << "Bar" << "Baz";
QFont::insertSubstitutions("BogusFontFamily", moreFonts);
- QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 3);
- QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 3);
+ QCOMPARE(QFont::substitutes("BogusFontFamily").size(), 3);
+ QCOMPARE(QFont::substitutes("bogusfontfamily").size(), 3);
QFont::removeSubstitutions("BogusFontFamily");
// make sure it is empty again
@@ -416,7 +400,7 @@ void tst_QFont::serialize_data()
QTest::newRow("defaultConstructed") << font << QDataStream::Qt_1_0;
font.setLetterSpacing(QFont::AbsoluteSpacing, 105);
- QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;
+ QTest::newRow("letterSpacing=105") << font << QDataStream::Qt_4_5;
font = basicFont;
font.setWordSpacing(50.0);
@@ -460,7 +444,7 @@ void tst_QFont::serialize_data()
font = basicFont;
font.setLetterSpacing(QFont::AbsoluteSpacing, 10);
// Fails for 4.4 because letterSpacing wasn't read until 4.5.
- QTest::newRow("letterSpacing") << font << QDataStream::Qt_4_5;
+ QTest::newRow("letterSpacing=10") << font << QDataStream::Qt_4_5;
font = basicFont;
font.setKerning(false);
@@ -511,6 +495,43 @@ void tst_QFont::serialize()
}
}
+void tst_QFont::deserializeQt515()
+{
+ QFile file;
+ file.setFileName(QFINDTESTDATA("datastream.515"));
+ QVERIFY(file.open(QIODevice::ReadOnly));
+
+ QFont font;
+ {
+ QDataStream stream(&file);
+ stream.setVersion(QDataStream::Qt_5_15);
+ stream >> font;
+ }
+
+ QCOMPARE(font.family(), QStringLiteral("FirstFamily"));
+ QCOMPARE(font.families().size(), 3);
+ QCOMPARE(font.families().at(0), QStringLiteral("FirstFamily"));
+ QCOMPARE(font.families().at(1), QStringLiteral("OtherFamily1"));
+ QCOMPARE(font.families().at(2), QStringLiteral("OtherFamily2"));
+ QCOMPARE(font.pointSize(), 12);
+
+ QVERIFY(file.reset());
+ QByteArray fileContent = file.readAll();
+ QByteArray serializedContent;
+ {
+ QBuffer buffer(&serializedContent);
+ QVERIFY(buffer.open(QIODevice::WriteOnly));
+
+ QDataStream stream(&buffer);
+ stream.setVersion(QDataStream::Qt_5_15);
+ stream << font;
+ }
+
+ QCOMPARE(serializedContent, fileContent);
+
+ file.close();
+}
+
void tst_QFont::styleName()
{
#if !defined(Q_OS_MAC)
@@ -576,6 +597,11 @@ void tst_QFont::defaultFamily()
break;
}
}
+
+#if defined(Q_OS_UNIX) && defined(QT_NO_FONTCONFIG)
+ QSKIP("This platform does not support checking for default font acceptability");
+#endif
+
#ifdef Q_PROCESSOR_ARM_32
if (QTestPrivate::isRunningArmOnX86())
QEXPECT_FAIL("", "Fails on ARMv7 QEMU (QTQAINFRA-4127)", Continue);
@@ -823,5 +849,83 @@ void tst_QFont::setFamiliesAndFamily()
QFontDatabase::removeApplicationFont(weirdFontId);
}
+void tst_QFont::featureAccessors()
+{
+ const QFont::Tag abcdTag("abcd");
+ QCOMPARE(abcdTag.toString(), "abcd");
+ QVERIFY(abcdTag.isValid());
+
+ QFont font;
+ QVERIFY(font.featureTags().isEmpty());
+ font.setFeature("abcd", 0xc0ffee);
+
+ QVERIFY(font.isFeatureSet(abcdTag));
+ QVERIFY(!font.isFeatureSet("bcde"));
+ QCOMPARE(font.featureTags().size(), 1);
+ QCOMPARE(font.featureTags().first(), abcdTag);
+ QCOMPARE(font.featureTags().first(), "abcd");
+ QCOMPARE(font.featureValue(abcdTag), 0xc0ffeeU);
+ QCOMPARE(font.featureValue("bcde"), 0U);
+ font.setFeature(abcdTag, 0xf00d);
+ QCOMPARE(font.featureTags().size(), 1);
+ QCOMPARE(font.featureValue(abcdTag), 0xf00dU);
+
+ QFont::Tag invalidTag;
+ QVERIFY(!invalidTag.isValid());
+ font.setFeature(invalidTag, 0xcaca0);
+ QVERIFY(!font.isFeatureSet(invalidTag));
+ QCOMPARE(font.featureTags().size(), 1);
+ QFont font2 = font;
+
+ font.unsetFeature("abcd");
+ QVERIFY(!font.isFeatureSet("abcd"));
+ QVERIFY(font.featureTags().isEmpty());
+
+ QVERIFY(font2.isFeatureSet("abcd"));
+ font2.clearFeatures();
+ QVERIFY(font.featureTags().isEmpty());
+
+ // various constructor compile tests
+ QFont::Tag tag;
+ tag = QFont::Tag("1234");
+ QVERIFY(QFont::Tag::fromString(QByteArray("abcd")));
+ QVERIFY(QFont::Tag::fromString(u"frac"_s));
+
+ // named constructors with invalid input
+ QTest::ignoreMessage(QtWarningMsg, "The tag name must be exactly 4 characters long!");
+ QVERIFY(!QFont::Tag::fromString(u"fraction"_s));
+ QVERIFY(!QFont::Tag::fromValue(0));
+ QVERIFY(QFont::Tag::fromValue(abcdTag.value()));
+
+ enum Features {
+ Frac = QFont::Tag("frac").value()
+ };
+}
+
+void tst_QFont::tagCompares_data()
+{
+ QTestPrivate::testAllComparisonOperatorsCompile<QFont::Tag>();
+
+ QTest::addColumn<QFont::Tag>("lhs");
+ QTest::addColumn<QFont::Tag>("rhs");
+ QTest::addColumn<Qt::strong_ordering>("expectedOrder");
+
+ auto row = [](QFont::Tag left, QFont::Tag right) {
+ QTest::addRow("%s<=>%s", left.toString().constData(), right.toString().constData())
+ << left << right << Qt::compareThreeWay(left.value(), right.value());
+ };
+ row("frac", "wght");
+}
+
+void tst_QFont::tagCompares()
+{
+ QFETCH(QFont::Tag, lhs);
+ QFETCH(QFont::Tag, rhs);
+ QFETCH(Qt::strong_ordering, expectedOrder);
+
+ QVERIFY(comparesEqual(lhs, lhs));
+ QCOMPARE(compareThreeWay(lhs, rhs), expectedOrder);
+}
+
QTEST_MAIN(tst_QFont)
#include "tst_qfont.moc"
diff --git a/tests/auto/gui/text/qfontcache/CMakeLists.txt b/tests/auto/gui/text/qfontcache/CMakeLists.txt
index fb93c91e0c..d9645c115a 100644
--- a/tests/auto/gui/text/qfontcache/CMakeLists.txt
+++ b/tests/auto/gui/text/qfontcache/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qfontcache.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfontcache Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfontcache LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qfontcache
SOURCES
tst_qfontcache.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
index 17d199210d..79f24a2f0d 100644
--- a/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
+++ b/tests/auto/gui/text/qfontcache/tst_qfontcache.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/text/qfontdatabase/BLACKLIST b/tests/auto/gui/text/qfontdatabase/BLACKLIST
index 95494d6111..88aa9e9c79 100644
--- a/tests/auto/gui/text/qfontdatabase/BLACKLIST
+++ b/tests/auto/gui/text/qfontdatabase/BLACKLIST
@@ -1,5 +1,4 @@
-[systemFixedFont] # QTBUG-54623
-b2qt
-# QTBUG-87405
[systemFixedFont]
-android
+b2qt
+# QTBUG-100948
+qnx
diff --git a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
index 73ab56d49f..18b96ded5d 100644
--- a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
+++ b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
@@ -1,16 +1,23 @@
-# Generated from qfontdatabase.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfontdatabase Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfontdatabase LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
list(APPEND test_data "LED_REAL.TTF")
qt_internal_add_test(tst_qfontdatabase
SOURCES
tst_qfontdatabase.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
@@ -30,11 +37,15 @@ set_source_files_properties("../../../shared/resources/testfont_italic.ttf"
set_source_files_properties("../../../shared/resources/testfont_open.otf"
PROPERTIES QT_RESOURCE_ALIAS "testfont_open.otf"
)
+set_source_files_properties("../../../shared/resources/testfont_variable.ttf"
+ PROPERTIES QT_RESOURCE_ALIAS "testfont_variable.ttf"
+)
set(testdata_resource_files
"../../../shared/resources/testfont.ttf"
"../../../shared/resources/testfont_condensed.ttf"
"../../../shared/resources/testfont_italic.ttf"
"../../../shared/resources/testfont_open.otf"
+ "../../../shared/resources/testfont_variable.ttf"
"LED_REAL.TTF"
)
diff --git a/tests/auto/gui/text/qfontdatabase/testdata.qrc b/tests/auto/gui/text/qfontdatabase/testdata.qrc
deleted file mode 100644
index a590099b20..0000000000
--- a/tests/auto/gui/text/qfontdatabase/testdata.qrc
+++ /dev/null
@@ -1,9 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>LED_REAL.TTF</file>
- <file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
- <file alias="testfont_condensed.ttf">../../../shared/resources/testfont_condensed.ttf</file>
- <file alias="testfont_italic.ttf">../../../shared/resources/testfont_italic.ttf</file>
- <file alias="testfont_open.otf">../../../shared/resources/testfont_open.otf</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index dd3bbde871..b2d00f6666 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -34,7 +9,14 @@
#include <qfontmetrics.h>
#include <qtextlayout.h>
#include <private/qrawfont_p.h>
+#include <private/qfont_p.h>
+#include <private/qfontengine_p.h>
#include <qpa/qplatformfontdatabase.h>
+#include <qpa/qplatformintegration.h>
+
+#include <QtGui/private/qguiapplication_p.h>
+
+using namespace Qt::StringLiterals;
Q_LOGGING_CATEGORY(lcTests, "qt.text.tests")
@@ -82,11 +64,18 @@ private slots:
void stretchRespected();
+ void variableFont();
+
+#ifdef Q_OS_WIN
+ void findCourier();
+#endif
+
private:
QString m_ledFont;
QString m_testFont;
QString m_testFontCondensed;
QString m_testFontItalic;
+ QString m_testFontVariable;
};
tst_QFontDatabase::tst_QFontDatabase()
@@ -99,10 +88,12 @@ void tst_QFontDatabase::initTestCase()
m_testFont = QFINDTESTDATA("testfont.ttf");
m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf");
m_testFontItalic = QFINDTESTDATA("testfont_italic.ttf");
+ m_testFontVariable = QFINDTESTDATA("testfont_variable.ttf");
QVERIFY(!m_ledFont.isEmpty());
QVERIFY(!m_testFont.isEmpty());
QVERIFY(!m_testFontCondensed.isEmpty());
QVERIFY(!m_testFontItalic.isEmpty());
+ QVERIFY(!m_testFontVariable.isEmpty());
}
void tst_QFontDatabase::styles_data()
@@ -240,7 +231,7 @@ void tst_QFontDatabase::addAppFont()
int id;
if (useMemoryFont) {
QFile fontfile(m_ledFont);
- fontfile.open(QIODevice::ReadOnly);
+ QVERIFY(fontfile.open(QIODevice::ReadOnly));
QByteArray fontdata = fontfile.readAll();
QVERIFY(!fontdata.isEmpty());
id = QFontDatabase::addApplicationFontFromData(fontdata);
@@ -253,7 +244,7 @@ void tst_QFontDatabase::addAppFont()
QCOMPARE(id, -1);
return;
#endif
- QCOMPARE(fontDbChangedSpy.count(), 1);
+ QCOMPARE(fontDbChangedSpy.size(), 1);
if (id == -1)
QSKIP("Skip the test since app fonts are not supported on this system");
@@ -262,9 +253,9 @@ void tst_QFontDatabase::addAppFont()
const QStringList newFamilies = QFontDatabase::families();
QVERIFY(!newFamilies.isEmpty());
- QVERIFY(newFamilies.count() >= oldFamilies.count());
+ QVERIFY(newFamilies.size() >= oldFamilies.size());
- for (int i = 0; i < addedFamilies.count(); ++i) {
+ for (int i = 0; i < addedFamilies.size(); ++i) {
QString family = addedFamilies.at(i);
QVERIFY(newFamilies.contains(family));
QFont qfont(family);
@@ -273,9 +264,9 @@ void tst_QFontDatabase::addAppFont()
}
QVERIFY(QFontDatabase::removeApplicationFont(id));
- QCOMPARE(fontDbChangedSpy.count(), 2);
+ QCOMPARE(fontDbChangedSpy.size(), 2);
- QVERIFY(QFontDatabase::families().count() <= oldFamilies.count());
+ QVERIFY(QFontDatabase::families().size() <= oldFamilies.size());
}
void tst_QFontDatabase::addTwoAppFontsFromFamily()
@@ -336,8 +327,8 @@ void tst_QFontDatabase::fallbackFonts()
layout.createLine();
layout.endLayout();
- QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
- foreach (QGlyphRun run, runs) {
+ const QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
+ for (QGlyphRun run : runs) {
QRawFont rawFont = run.rawFont();
QVERIFY(rawFont.isValid());
@@ -429,12 +420,15 @@ void tst_QFontDatabase::condensedFontMatching()
tfcByStyleName.setStyleName("Condensed");
#ifdef Q_OS_WIN
- QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue);
+ QFont f;
+ f.setStyleStrategy(QFont::NoFontMerging);
+ QFontPrivate *font_d = QFontPrivate::get(f);
+ if (font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::Freetype
+ && font_d->engineForScript(QChar::Script_Common)->type() != QFontEngine::DirectWrite) {
+ QEXPECT_FAIL("","No matching of sub-family by stretch on Windows", Continue);
+ }
#endif
-#ifdef Q_OS_ANDROID
- QEXPECT_FAIL("", "QTBUG-69216", Continue);
-#endif
QCOMPARE(QFontMetrics(tfcByStretch).horizontalAdvance(testString()),
QFontMetrics(tfcByStyleName).horizontalAdvance(testString()));
@@ -494,5 +488,72 @@ void tst_QFontDatabase::registerOpenTypePreferredNamesApplication()
QFontDatabase::removeApplicationFont(id);
}
+#ifdef Q_OS_WIN
+void tst_QFontDatabase::findCourier()
+{
+ QFont font = QFontDatabase::font(u"Courier"_s, u""_s, 16);
+ QFontInfo info(font);
+ QCOMPARE(info.family(), u"Courier New"_s);
+ QCOMPARE(info.pointSize(), 16);
+
+ font = QFontDatabase::font("Courier", "", 64);
+ info = font;
+ QCOMPARE(info.family(), u"Courier New"_s);
+ QCOMPARE(info.pointSize(), 64);
+
+ // By setting "PreferBitmap" we should get Courier itself.
+ font.setStyleStrategy(QFont::PreferBitmap);
+ info = font;
+ QCOMPARE(info.family(), u"Courier"_s);
+ // Which has an upper bound on point size
+ QCOMPARE(info.pointSize(), 19);
+
+ font.setStyleStrategy(QFont::PreferDefault);
+ info = font;
+ QCOMPARE(info.family(), u"Courier New"_s);
+ QCOMPARE(info.pointSize(), 64);
+}
+#endif
+
+void tst_QFontDatabase::variableFont()
+{
+ {
+ QPlatformFontDatabase *pfdb = QGuiApplicationPrivate::platformIntegration()->fontDatabase();
+ if (!pfdb->supportsVariableApplicationFonts())
+ QSKIP("Variable application fonts not supported on this platform");
+ }
+
+ int id = QFontDatabase::addApplicationFont(m_testFontVariable);
+ if (id == -1)
+ QSKIP("Skip the test since app fonts are not supported on this system");
+
+ QString family = QFontDatabase::applicationFontFamilies(id).first();
+ {
+ QFont font(family);
+ QCOMPARE(QFontInfo(font).styleName(), u"Regular"_s);
+ QCOMPARE(QFontInfo(font).weight(), QFont::Normal);
+ }
+
+ {
+ QFont font(family);
+ font.setWeight(QFont::Black);
+ QCOMPARE(QFontInfo(font).styleName(), u"QtExtraBold"_s);
+ QCOMPARE(QFontInfo(font).weight(), int(QFont::Black));
+ }
+
+ {
+ QFont regularFont(family);
+ QFont extraBoldFont(family);
+ extraBoldFont.setStyleName(u"QtExtraBold"_s);
+
+ QFontMetricsF regularFm(regularFont);
+ QFontMetricsF extraBoldFm(extraBoldFont);
+
+ QVERIFY(regularFm.horizontalAdvance(QLatin1Char('1')) < extraBoldFm.horizontalAdvance(QLatin1Char('1')));
+ }
+
+ QFontDatabase::removeApplicationFont(id);
+}
+
QTEST_MAIN(tst_QFontDatabase)
#include "tst_qfontdatabase.moc"
diff --git a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
index d7a22671d6..d014d27d46 100644
--- a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
+++ b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qfontmetrics.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qfontmetrics Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qfontmetrics LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qfontmetrics
SOURCES
tst_qfontmetrics.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qfontmetrics/testfont.qrc b/tests/auto/gui/text/qfontmetrics/testfont.qrc
deleted file mode 100644
index 30b4a3f82e..0000000000
--- a/tests/auto/gui/text/qfontmetrics/testfont.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/fonts">
- <file>ucs4font.ttf</file>
- <file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
index 9ed88fe8ed..678eb0393f 100644
--- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
+++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -57,6 +32,10 @@ private slots:
void leadingBelowLine();
void elidedMetrics();
void zeroWidthMetrics();
+ void verticalMetrics_data();
+ void verticalMetrics();
+ void largeText_data();
+ void largeText(); // QTBUG-123339
};
void tst_QFontMetrics::same()
@@ -394,5 +373,42 @@ void tst_QFontMetrics::zeroWidthMetrics()
QCOMPARE(fm.tightBoundingRect(string3).width(), fm.tightBoundingRect(string4).width());
}
+void tst_QFontMetrics::verticalMetrics_data()
+{
+ QTest::addColumn<QFont>("font");
+ QStringList families = QFontDatabase::families();
+ for (const QString &family : families) {
+ QFont font(family);
+ QTest::newRow(family.toUtf8()) << font;
+ }
+}
+
+void tst_QFontMetrics::verticalMetrics()
+{
+ QFETCH(QFont, font);
+ QFontMetrics fm(font);
+ QVERIFY(fm.ascent() != 0 || fm.descent() != 0);
+}
+
+void tst_QFontMetrics::largeText_data()
+{
+ QTest::addColumn<qsizetype>("size");
+ for (int i = 1; i < 20; ++i) {
+ qsizetype size = qsizetype(1) << i;
+ QByteArray rowText = QByteArray::number(size);
+ QTest::newRow(rowText.constData()) << size;
+ }
+}
+
+void tst_QFontMetrics::largeText()
+{
+ QFont font;
+ QFontMetrics fm(font);
+ QFETCH(qsizetype, size);
+ QString string(size, QLatin1Char('A'));
+ QRect boundingRect = fm.boundingRect(string);
+ QVERIFY(boundingRect.isValid());
+}
+
QTEST_MAIN(tst_QFontMetrics)
#include "tst_qfontmetrics.moc"
diff --git a/tests/auto/gui/text/qglyphrun/BLACKLIST b/tests/auto/gui/text/qglyphrun/BLACKLIST
deleted file mode 100644
index d8fefd3d9f..0000000000
--- a/tests/auto/gui/text/qglyphrun/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-[mixedScripts]
-ubuntu-18.04
-ubuntu-20.04
diff --git a/tests/auto/gui/text/qglyphrun/CMakeLists.txt b/tests/auto/gui/text/qglyphrun/CMakeLists.txt
index b0585af16f..a9ffd3729d 100644
--- a/tests/auto/gui/text/qglyphrun/CMakeLists.txt
+++ b/tests/auto/gui/text/qglyphrun/CMakeLists.txt
@@ -1,15 +1,15 @@
-# Generated from qglyphrun.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qglyphrun Test:
#####################################################################
-qt_internal_add_test(tst_qglyphrun
- SOURCES
- tst_qglyphrun.cpp
- PUBLIC_LIBRARIES
- Qt::Gui
-)
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qglyphrun LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
# Resources:
set_source_files_properties("../../../shared/resources/test.ttf"
@@ -17,12 +17,15 @@ set_source_files_properties("../../../shared/resources/test.ttf"
)
set(testdata_resource_files
"../../../shared/resources/test.ttf"
+ "Ligatures.otf"
)
-qt_internal_add_resource(tst_qglyphrun "testdata"
- PREFIX
- "/"
- FILES
- ${testdata_resource_files}
+qt_internal_add_test(tst_qglyphrun
+ SOURCES
+ tst_qglyphrun.cpp
+ LIBRARIES
+ Qt::Gui
+ TESTDATA ${testdata_resource_files}
+ BUILTIN_TESTDATA
)
diff --git a/tests/auto/gui/text/qglyphrun/Ligatures.otf b/tests/auto/gui/text/qglyphrun/Ligatures.otf
new file mode 100644
index 0000000000..194218a0f6
--- /dev/null
+++ b/tests/auto/gui/text/qglyphrun/Ligatures.otf
Binary files differ
diff --git a/tests/auto/gui/text/qglyphrun/testdata.qrc b/tests/auto/gui/text/qglyphrun/testdata.qrc
deleted file mode 100644
index 25cadc477e..0000000000
--- a/tests/auto/gui/text/qglyphrun/testdata.qrc
+++ /dev/null
@@ -1,5 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file alias="test.ttf">../../../shared/resources/test.ttf</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp
index 119ec7a19d..8c0c0324c9 100644
--- a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp
+++ b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -64,6 +39,10 @@ private slots:
void mixedScripts();
void multiLineBoundingRect();
void defaultIgnorables();
+ void stringIndexes();
+ void retrievalFlags_data();
+ void retrievalFlags();
+ void objectReplacementCharacter();
private:
int m_testFontId;
@@ -429,7 +408,7 @@ void tst_QGlyphRun::drawMultiScriptText1()
QPixmap drawGlyphs(1000, 1000);
drawGlyphs.fill(Qt::white);
- QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
+ const QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
QCOMPARE(glyphsList.size(), 1);
{
@@ -439,8 +418,7 @@ void tst_QGlyphRun::drawMultiScriptText1()
{
QPainter p(&drawGlyphs);
- foreach (QGlyphRun glyphs, glyphsList)
- p.drawGlyphRun(QPointF(50, 50), glyphs);
+ p.drawGlyphRun(QPointF(50, 50), glyphsList.first());
}
#if defined(DEBUG_SAVE_IMAGE)
@@ -470,7 +448,7 @@ void tst_QGlyphRun::drawMultiScriptText2()
QPixmap drawGlyphs(1000, 1000);
drawGlyphs.fill(Qt::white);
- QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
+ const QList<QGlyphRun> glyphsList = textLayout.glyphRuns();
QCOMPARE(glyphsList.size(), 2);
{
@@ -480,7 +458,7 @@ void tst_QGlyphRun::drawMultiScriptText2()
{
QPainter p(&drawGlyphs);
- foreach (QGlyphRun glyphs, glyphsList)
+ for (const QGlyphRun &glyphs : glyphsList)
p.drawGlyphRun(QPointF(50, 50), glyphs);
}
@@ -585,6 +563,9 @@ void tst_QGlyphRun::boundingRect()
void tst_QGlyphRun::mixedScripts()
{
+ if (QFontDatabase::families(QFontDatabase::Korean).isEmpty())
+ QSKIP("This test requires support for Hangul text");
+
QString s;
s += QChar(0x31); // The character '1'
s += QChar(0xbc14); // Hangul character
@@ -630,17 +611,365 @@ void tst_QGlyphRun::multiLineBoundingRect()
void tst_QGlyphRun::defaultIgnorables()
{
+ {
+ QTextLayout layout;
+ layout.setFont(QFont("QtsSpecialTestFont"));
+ layout.setText(QChar(0x200D));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> runs = layout.glyphRuns();
+ QCOMPARE(runs.size(), 0);
+ }
+
+ {
+ QTextLayout layout;
+ layout.setFont(QFont("QtsSpecialTestFont"));
+ layout.setText(QStringLiteral("AAA") + QChar(0xFE0F) + QStringLiteral("111"));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> runs = layout.glyphRuns();
+ QVERIFY(!runs.isEmpty());
+
+ bool hasFullMainFontRun = false;
+ for (const QGlyphRun &run : runs) {
+ // QtsSpecialFont will be used for at least five characters: AA[...]111
+ // Depending on the font selected for the 0xFE0F variant selector, the
+ // third 'A' may be in QtsSpecialFont or in the fallback. This is platform-specific,
+ // so we accept either.
+ if (run.rawFont().familyName() == QStringLiteral("QtsSpecialTestFont")
+ && run.glyphIndexes().size() >= 5) {
+ hasFullMainFontRun = true;
+ break;
+ }
+ }
+ QVERIFY(hasFullMainFontRun);
+ }
+}
+
+void tst_QGlyphRun::stringIndexes()
+{
+ int ligatureFontId = QFontDatabase::addApplicationFont(QFINDTESTDATA("Ligatures.otf"));
+ QVERIFY(ligatureFontId >= 0);
+
+ QFont ligatureFont = QFont("QtLigatures");
+ QCOMPARE(QFontInfo(ligatureFont).family(), QString::fromLatin1("QtLigatures"));
+
+ QTextLayout::GlyphRunRetrievalFlags retrievalFlags
+ = QTextLayout::RetrieveGlyphIndexes | QTextLayout::RetrieveStringIndexes;
+
+ // Three characters -> three glyphs
+ {
+ QTextLayout layout;
+ layout.setText("f i");
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 3);
+ QCOMPARE(stringIndexes.at(0), 0);
+ QCOMPARE(stringIndexes.at(1), 1);
+ QCOMPARE(stringIndexes.at(2), 2);
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(2, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 1);
+ QCOMPARE(stringIndexes.at(0), 2);
+ }
+ }
+
+ // Two characters -> one glyph
+ {
+ QTextLayout layout;
+ layout.setText("fi");
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 1);
+ QCOMPARE(stringIndexes.at(0), 0);
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 1);
+ QCOMPARE(stringIndexes.at(0), 1);
+ }
+ }
+
+ // Four characters -> three glyphs
+ {
+ QTextLayout layout;
+ layout.setText("ffii");
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(233));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(74));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 3);
+ QCOMPARE(stringIndexes.at(0), uint(0));
+ QCOMPARE(stringIndexes.at(1), uint(1));
+ QCOMPARE(stringIndexes.at(2), uint(3));
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 1);
+ QCOMPARE(stringIndexes.at(0), uint(1));
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 2, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 1);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 1);
+ QCOMPARE(stringIndexes.at(0), uint(1));
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, 3, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 2);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(233));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(74));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 2);
+ QCOMPARE(stringIndexes.at(0), 1);
+ QCOMPARE(stringIndexes.at(1), 3);
+ }
+
+ }
+
+ // One character -> two glyphs
+ {
+ QTextLayout layout;
+ layout.setText(QChar(0xe6)); // LATIN SMALL LETTER AE
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 2);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(66));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(70));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 2);
+ QCOMPARE(stringIndexes.at(0), uint(0));
+ QCOMPARE(stringIndexes.at(1), uint(0));
+ }
+
+ // Three characters -> four glyphs
+ {
+ QTextLayout layout;
+ layout.setText(QString('f') + QChar(0xe6) + QChar('i'));
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 4);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(66));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(70));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(3), uint(74));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 4);
+ QCOMPARE(stringIndexes.at(0), 0);
+ QCOMPARE(stringIndexes.at(1), 1);
+ QCOMPARE(stringIndexes.at(2), 1);
+ QCOMPARE(stringIndexes.at(3), 2);
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(66));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(70));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(74));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 3);
+ QCOMPARE(stringIndexes.at(0), 1);
+ QCOMPARE(stringIndexes.at(1), 1);
+ QCOMPARE(stringIndexes.at(2), 2);
+ }
+
+ {
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(0, 2, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 3);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(66));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(70));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 3);
+ QCOMPARE(stringIndexes.at(0), 0);
+ QCOMPARE(stringIndexes.at(1), 1);
+ QCOMPARE(stringIndexes.at(2), 1);
+ }
+
+
+ }
+
+ // Five characters -> five glyphs
+ {
+ QTextLayout layout;
+ layout.setText(QLatin1String("ffi") + QChar(0xe6) + QLatin1Char('i'));
+ layout.setFont(ligatureFont);
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, retrievalFlags);
+ QCOMPARE(glyphRuns.size(), 1);
+
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().size(), 5);
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(0), uint(71));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(1), uint(233));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(2), uint(66));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(3), uint(70));
+ QCOMPARE(glyphRuns.at(0).glyphIndexes().at(4), uint(74));
+
+ QList<qsizetype> stringIndexes = glyphRuns.at(0).stringIndexes();
+ QCOMPARE(stringIndexes.size(), 5);
+ QCOMPARE(stringIndexes.at(0), 0);
+ QCOMPARE(stringIndexes.at(1), 1);
+ QCOMPARE(stringIndexes.at(2), 3);
+ QCOMPARE(stringIndexes.at(3), 3);
+ QCOMPARE(stringIndexes.at(4), 4);
+ }
+
+}
+
+void tst_QGlyphRun::retrievalFlags_data()
+{
+ QTest::addColumn<QTextLayout::GlyphRunRetrievalFlags>("flags");
+ QTest::addColumn<bool>("expectedGlyphIndexes");
+ QTest::addColumn<bool>("expectedStringIndexes");
+ QTest::addColumn<bool>("expectedString");
+ QTest::addColumn<bool>("expectedGlyphPositions");
+
+ QTest::newRow("Glyph indexes")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveGlyphIndexes)
+ << true << false << false << false;
+ QTest::newRow("Glyph Positions")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveGlyphPositions)
+ << false << false << false << true;
+ QTest::newRow("String indexes")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveStringIndexes)
+ << false << true << false << false;
+ QTest::newRow("String")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveString)
+ << false << false << true << false;
+
+ QTest::newRow("Default")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::DefaultRetrievalFlags)
+ << true << false << false << true;
+ QTest::newRow("All")
+ << QTextLayout::GlyphRunRetrievalFlags(QTextLayout::RetrieveAll)
+ << true << true << true << true;
+}
+
+void tst_QGlyphRun::retrievalFlags()
+{
+ QFETCH(QTextLayout::GlyphRunRetrievalFlags, flags);
+ QFETCH(bool, expectedGlyphIndexes);
+ QFETCH(bool, expectedStringIndexes);
+ QFETCH(bool, expectedString);
+ QFETCH(bool, expectedGlyphPositions);
+
QTextLayout layout;
- layout.setFont(QFont("QtsSpecialTestFont"));
- layout.setText(QChar(0x200D));
+ layout.setText(QLatin1String("abc"));
layout.beginLayout();
layout.createLine();
layout.endLayout();
- QList<QGlyphRun> runs = layout.glyphRuns();
- QCOMPARE(runs.size(), 1);
- QCOMPARE(runs.at(0).glyphIndexes().size(), 1);
- QCOMPARE(runs.at(0).glyphIndexes()[0], uint(0));
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns(-1, -1, flags);
+ QVERIFY(!glyphRuns.isEmpty());
+
+ QGlyphRun firstGlyphRun = glyphRuns.first();
+ QCOMPARE(firstGlyphRun.glyphIndexes().isEmpty(), !expectedGlyphIndexes);
+ QCOMPARE(firstGlyphRun.stringIndexes().isEmpty(), !expectedStringIndexes);
+ QCOMPARE(firstGlyphRun.sourceString().isEmpty(), !expectedString);
+ QCOMPARE(firstGlyphRun.positions().isEmpty(), !expectedGlyphPositions);
+}
+
+void tst_QGlyphRun::objectReplacementCharacter()
+{
+ QTextLayout layout;
+ layout.setFont(m_testFont);
+ layout.setText(QStringLiteral("\uFFFC"));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QCOMPARE(glyphRuns.size(), 1);
+ QCOMPARE(glyphRuns.first().glyphIndexes().size(), 1);
+ QCOMPARE(glyphRuns.first().glyphIndexes().first(), uint(5));
}
#endif // QT_NO_RAWFONT
diff --git a/tests/auto/gui/text/qinputcontrol/CMakeLists.txt b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt
index 048a96ef77..75fc85bc39 100644
--- a/tests/auto/gui/text/qinputcontrol/CMakeLists.txt
+++ b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qinputcontrol.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qinputcontrol Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qinputcontrol LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qinputcontrol
SOURCES
tst_qinputcontrol.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp
index 3e64c3c09a..678f4491c4 100644
--- a/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp
+++ b/tests/auto/gui/text/qinputcontrol/tst_qinputcontrol.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/text/qrawfont/BLACKLIST b/tests/auto/gui/text/qrawfont/BLACKLIST
deleted file mode 100644
index 44b3d7d481..0000000000
--- a/tests/auto/gui/text/qrawfont/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-# QTBUG-85364
-windows-10 gcc cmake
diff --git a/tests/auto/gui/text/qrawfont/CMakeLists.txt b/tests/auto/gui/text/qrawfont/CMakeLists.txt
index 04db8d8760..d2a318a2a3 100644
--- a/tests/auto/gui/text/qrawfont/CMakeLists.txt
+++ b/tests/auto/gui/text/qrawfont/CMakeLists.txt
@@ -1,17 +1,15 @@
-# Generated from qrawfont.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qrawfont Test:
#####################################################################
-qt_internal_add_test(tst_qrawfont
- SOURCES
- tst_qrawfont.cpp
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::Gui
- Qt::GuiPrivate
-)
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qrawfont LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
# Resources:
set_source_files_properties("../../../shared/resources/testfont.ttf"
@@ -23,10 +21,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
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ TESTDATA ${testdata_resource_files}
+ BUILTIN_TESTDATA
)
diff --git a/tests/auto/gui/text/qrawfont/testdata.qrc b/tests/auto/gui/text/qrawfont/testdata.qrc
deleted file mode 100644
index c7ac9641d1..0000000000
--- a/tests/auto/gui/text/qrawfont/testdata.qrc
+++ /dev/null
@@ -1,7 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>testfont_bold_italic.ttf</file>
- <file>testfont_os2_v1.ttf</file>
- <file alias="testfont.ttf">../../../shared/resources/testfont.ttf</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index a730174ee9..5ec2536718 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui/QFontDatabase>
@@ -121,7 +96,7 @@ void tst_QRawFont::initTestCase()
if (testFont.isEmpty() || testFontBoldItalic.isEmpty())
QFAIL("qrawfont unittest font files not found!");
- if (QFontDatabase::families().count() == 0)
+ if (QFontDatabase::families().size() == 0)
QSKIP("No fonts available!!!");
}
@@ -423,13 +398,13 @@ void tst_QRawFont::textLayout()
void tst_QRawFont::fontTable_data()
{
- QTest::addColumn<QByteArray>("tagName");
+ QTest::addColumn<QFont::Tag>("tag");
QTest::addColumn<QFont::HintingPreference>("hintingPreference");
QTest::addColumn<int>("offset");
QTest::addColumn<quint32>("expectedValue");
QTest::newRow("Head table, magic number, default hinting")
- << QByteArray("head")
+ << QFont::Tag("head")
<< QFont::PreferDefaultHinting
<< 12
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
@@ -437,7 +412,7 @@ void tst_QRawFont::fontTable_data()
: 0xF53C0F5F);
QTest::newRow("Head table, magic number, no hinting")
- << QByteArray("head")
+ << QFont::Tag("head")
<< QFont::PreferNoHinting
<< 12
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
@@ -445,7 +420,7 @@ void tst_QRawFont::fontTable_data()
: 0xF53C0F5F);
QTest::newRow("Head table, magic number, vertical hinting")
- << QByteArray("head")
+ << QFont::Tag("head")
<< QFont::PreferVerticalHinting
<< 12
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
@@ -453,7 +428,7 @@ void tst_QRawFont::fontTable_data()
: 0xF53C0F5F);
QTest::newRow("Head table, magic number, full hinting")
- << QByteArray("head")
+ << QFont::Tag("head")
<< QFont::PreferFullHinting
<< 12
<< (QSysInfo::ByteOrder == QSysInfo::BigEndian
@@ -463,7 +438,7 @@ void tst_QRawFont::fontTable_data()
void tst_QRawFont::fontTable()
{
- QFETCH(QByteArray, tagName);
+ QFETCH(QFont::Tag, tag);
QFETCH(QFont::HintingPreference, hintingPreference);
QFETCH(int, offset);
QFETCH(quint32, expectedValue);
@@ -471,11 +446,13 @@ void tst_QRawFont::fontTable()
QRawFont font(testFont, 10, hintingPreference);
QVERIFY(font.isValid());
- QByteArray table = font.fontTable(tagName);
+ QByteArray table = font.fontTable(tag);
QVERIFY(!table.isEmpty());
const quint32 *value = reinterpret_cast<const quint32 *>(table.constData() + offset);
QCOMPARE(*value, expectedValue);
+
+ QCOMPARE(font.fontTable(tag.toString()), table);
}
typedef QList<QFontDatabase::WritingSystem> WritingSystemList;
@@ -515,7 +492,7 @@ void tst_QRawFont::supportedWritingSystems_data()
void tst_QRawFont::supportedWritingSystems()
{
QFETCH(QString, fileName);
- QFETCH(WritingSystemList, writingSystems);
+ QFETCH(const WritingSystemList, writingSystems);
QFETCH(QFont::HintingPreference, hintingPreference);
QRawFont font(fileName, 10, hintingPreference);
@@ -524,7 +501,7 @@ void tst_QRawFont::supportedWritingSystems()
WritingSystemList actualWritingSystems = font.supportedWritingSystems();
QCOMPARE(actualWritingSystems.size(), writingSystems.size());
- foreach (QFontDatabase::WritingSystem writingSystem, writingSystems)
+ for (QFontDatabase::WritingSystem writingSystem : writingSystems)
QVERIFY(actualWritingSystems.contains(writingSystem));
}
@@ -1077,7 +1054,7 @@ void tst_QRawFont::qtbug65923_partal_clone_data()
void tst_QRawFont::qtbug65923_partal_clone()
{
QFile file(testFont);
- file.open(QIODevice::ReadOnly);
+ QVERIFY(file.open(QIODevice::ReadOnly));
QByteArray fontData = file.readAll();
QRawFont outerFont;
diff --git a/tests/auto/gui/text/qstatictext/CMakeLists.txt b/tests/auto/gui/text/qstatictext/CMakeLists.txt
index a7ba4e392a..bdad2609fe 100644
--- a/tests/auto/gui/text/qstatictext/CMakeLists.txt
+++ b/tests/auto/gui/text/qstatictext/CMakeLists.txt
@@ -1,21 +1,28 @@
-# Generated from qstatictext.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qstatictext Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qstatictext LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qstatictext
SOURCES
tst_qstatictext.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
## Scopes:
#####################################################################
-qt_internal_extend_target(tst_qstatictext CONDITION QT_FEATURE_private_tests
- PUBLIC_LIBRARIES
+qt_internal_extend_target(tst_qstatictext CONDITION QT_FEATURE_developer_build
+ LIBRARIES
Qt::CorePrivate
Qt::GuiPrivate
)
diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
index b55257533a..add2303199 100644
--- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
+++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp
@@ -1,32 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QtCore/QSet>
#include <QtGui/QGuiApplication>
#include <QtGui/QPainter>
#include <QtGui/QImage>
@@ -74,10 +50,6 @@ private slots:
void rotatedPainter();
void scaledPainter();
void projectedPainter();
-#if 0
- void rotatedScaledAndTranslatedPainter_data();
- void rotatedScaledAndTranslatedPainter();
-#endif
void transformationChanged();
void plainTextVsRichText();
@@ -261,8 +233,8 @@ void tst_QStaticText::compareToDrawText()
#if defined(DEBUG_SAVE_IMAGE)
imageDrawText.save("compareToDrawText_imageDrawText.png");
- imageDrawStaticText.save("compareToDrawText_imageDrawStaticPlainText.png");
- imageDrawStaticText.save("compareToDrawText_imageDrawStaticRichText.png");
+ imageDrawStaticPlainText.save("compareToDrawText_imageDrawStaticPlainText.png");
+ imageDrawStaticRichText.save("compareToDrawText_imageDrawStaticRichText.png");
#endif
QVERIFY(imageDrawText.toImage() != m_whiteSquare);
@@ -525,61 +497,6 @@ void tst_QStaticText::projectedPainter()
QCOMPARE(imageDrawStaticText, imageDrawText);
}
-#if 0
-void tst_QStaticText::rotatedScaledAndTranslatedPainter_data()
-{
- QTest::addColumn<qreal>("offset");
-
- for (int i=0; i<100; ++i) {
- qreal offset = 300 + i / 100.;
- QTest::newRow(QByteArray::number(offset).constData()) << offset;
- }
-}
-
-void tst_QStaticText::rotatedScaledAndTranslatedPainter()
-{
- QFETCH(qreal, offset);
-
- QPixmap imageDrawText(1000, 1000);
- imageDrawText.fill(Qt::white);
- {
- QPainter p(&imageDrawText);
- p.translate(offset, 0);
- p.rotate(45.0);
- p.scale(2.0, 2.0);
- p.translate(100, 200);
-
- p.drawText(11, 12, "Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
- }
-
- QPixmap imageDrawStaticText(1000, 1000);
- imageDrawStaticText.fill(Qt::white);
- {
- QPainter p(&imageDrawStaticText);
- p.translate(offset, 0);
- p.rotate(45.0);
- p.scale(2.0, 2.0);
- p.translate(100, 200);
-
- QStaticText text("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
- text.setTextFormat(Qt::PlainText);
-
- p.drawStaticText(QPointF(11, 12 - QFontMetricsF(p.font()).ascent()), text);
- }
-
-#if defined(DEBUG_SAVE_IMAGE)
- imageDrawText.save("rotatedScaledAndPainter_imageDrawText.png");
- imageDrawStaticText.save("rotatedScaledAndPainter_imageDrawStaticText.png");
-#endif
-
- QVERIFY(imageDrawText.toImage() != m_whiteSquare);
-
- if (!supportsTransformations())
- QEXPECT_FAIL("", "Graphics system does not support transformed text on this platform", Abort);
- QCOMPARE(imageDrawStaticText, imageDrawText);
-}
-#endif
-
void tst_QStaticText::transformationChanged()
{
QPixmap imageDrawText(1000, 1000);
diff --git a/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt
index 9ac732cee0..f1c9146ce1 100644
--- a/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt
+++ b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qsyntaxhighlighter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsyntaxhighlighter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsyntaxhighlighter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsyntaxhighlighter
SOURCES
tst_qsyntaxhighlighter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
@@ -15,6 +22,6 @@ qt_internal_add_test(tst_qsyntaxhighlighter
#####################################################################
qt_internal_extend_target(tst_qsyntaxhighlighter CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp
index 43086a1c14..748f494a41 100644
--- a/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp
+++ b/tests/auto/gui/text/qsyntaxhighlighter/tst_qsyntaxhighlighter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -125,7 +100,7 @@ public:
virtual void highlightBlock(const QString &text) override
{
- for (int i = 0; i < formats.count(); ++i) {
+ for (int i = 0; i < formats.size(); ++i) {
const QTextLayout::FormatRange &range = formats.at(i);
setFormat(range.start, range.length, range.format);
}
@@ -186,7 +161,7 @@ public:
commentFormat.setForeground(Qt::darkGreen);
commentFormat.setFontWeight(QFont::StyleItalic);
commentFormat.setFontFixedPitch(true);
- int textLength = text.length();
+ int textLength = text.size();
if (text.startsWith(QLatin1Char(';'))){
// The entire line is a comment
@@ -439,7 +414,7 @@ void tst_QSyntaxHighlighter::preservePreeditArea()
QCOMPARE(hl->callCount, 1);
formats = layout->formats();
- QCOMPARE(formats.count(), 3);
+ QCOMPARE(formats.size(), 3);
range = formats.at(0);
@@ -518,7 +493,7 @@ void tst_QSyntaxHighlighter::noContentsChangedDuringHighlight()
QSignalSpy contentsChangedSpy(doc, SIGNAL(contentsChanged()));
cursor.insertText("Hello World");
- QCOMPARE(contentsChangedSpy.count(), 1);
+ QCOMPARE(contentsChangedSpy.size(), 1);
QVERIFY(hl->highlighted);
QVERIFY(lout->documentChangedCalled);
}
diff --git a/tests/auto/gui/text/qtextblock/CMakeLists.txt b/tests/auto/gui/text/qtextblock/CMakeLists.txt
index aedd6c27a3..83cc1ce08e 100644
--- a/tests/auto/gui/text/qtextblock/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextblock/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextblock.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextblock Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextblock LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextblock
SOURCES
tst_qtextblock.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp b/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp
index 0d638706eb..50331ddef2 100644
--- a/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp
+++ b/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
diff --git a/tests/auto/gui/text/qtextcursor/CMakeLists.txt b/tests/auto/gui/text/qtextcursor/CMakeLists.txt
index a82dc928e9..487965f9f8 100644
--- a/tests/auto/gui/text/qtextcursor/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextcursor/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextcursor.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextcursor Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextcursor LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextcursor
SOURCES
tst_qtextcursor.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
index 17d2336b74..6984cd1bd2 100644
--- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
+++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
@@ -1,34 +1,11 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
+#include <QLoggingCategory>
+#include <qfontinfo.h>
#include <qtextdocument.h>
#include <qtexttable.h>
#include <qvariant.h>
@@ -41,6 +18,8 @@
#include <private/qtextcursor_p.h>
+Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
+
QT_FORWARD_DECLARE_CLASS(QTextDocument)
class tst_QTextCursor : public QObject
@@ -110,6 +89,14 @@ private slots:
void selectVisually();
void insertText();
+#ifndef QT_NO_TEXTHTMLPARSER
+ void insertHtml_data();
+ void insertHtml();
+#endif
+#if QT_CONFIG(textmarkdownreader)
+ void insertMarkdown_data();
+ void insertMarkdown();
+#endif
void insertFragmentShouldUseCurrentCharFormat();
@@ -1428,6 +1415,221 @@ void tst_QTextCursor::insertText()
QCOMPARE(cursor.block().text(), QString("yoyodyne"));
}
+
+#ifndef QT_NO_TEXTHTMLPARSER
+
+void tst_QTextCursor::insertHtml_data()
+{
+ QTest::addColumn<QString>("initialText");
+ QTest::addColumn<int>("expectedInitialBlockCount");
+ QTest::addColumn<bool>("insertBlock");
+ QTest::addColumn<bool>("insertAsPlainText");
+ QTest::addColumn<int>("insertPosition");
+ QTest::addColumn<QString>("insertText");
+ QTest::addColumn<QString>("expectedSelText");
+ QTest::addColumn<QString>("expectedText");
+ QTest::addColumn<QString>("expectedMarkdown");
+
+ const QString htmlHeadingString("<h1>Hello World</h1>");
+
+ QTest::newRow("insert as html at end of heading")
+ << htmlHeadingString << 1
+ << false << false << 11 << QString("Other\ntext")
+ << QString("Hello WorldOther text")
+ << QString("Hello WorldOther text")
+ << QString("# Hello WorldOther text\n\n");
+
+ QTest::newRow("insert as html in new block at end of heading")
+ << htmlHeadingString << 1
+ << false << true << 11 << QString("Other\ntext")
+ << QString("Hello WorldOther\u2029text")
+ << QString("Hello WorldOther\ntext")
+ << QString("# Hello WorldOther\n\n# text\n\n");
+
+ QTest::newRow("insert as html in middle of heading")
+ << htmlHeadingString << 1
+ << false << false << 6 << QString("\n\nOther\ntext\n\n")
+ << QString("Hello Other text World")
+ << QString("Hello Other text World")
+ << QString("# Hello Other text World\n\n");
+
+ QTest::newRow("insert as text at end of heading")
+ << htmlHeadingString << 1
+ << true << false << 11 << QString("\n\nOther\ntext")
+ << QString("Hello World\u2029Other text")
+ << QString("Hello World\nOther text")
+ << QString("# Hello World\n\nOther text\n\n");
+
+ QTest::newRow("insert as text in new block at end of heading")
+ << htmlHeadingString << 1
+ << true << true << 11 << QString("\n\nOther\ntext")
+ << QString("Hello World\u2029\u2029\u2029Other\u2029text")
+ << QString("Hello World\n\n\nOther\ntext")
+ << QString("# Hello World\n\n**Other**\n\n**text**\n\n");
+
+ QTest::newRow("insert as text in middle of heading")
+ << htmlHeadingString << 1
+ << true << false << 6 << QString("Other\ntext")
+ << QString("Hello \u2029Other textWorld")
+ << QString("Hello \nOther textWorld")
+ << QString("# Hello \n\nOther text**World**\n\n");
+}
+
+void tst_QTextCursor::insertHtml()
+{
+ QFETCH(QString, initialText);
+ QFETCH(int, expectedInitialBlockCount);
+ QFETCH(bool, insertBlock);
+ QFETCH(bool, insertAsPlainText);
+ QFETCH(int, insertPosition);
+ QFETCH(QString, insertText);
+ QFETCH(QString, expectedSelText);
+ QFETCH(QString, expectedText);
+ QFETCH(QString, expectedMarkdown);
+
+ cursor.insertHtml(initialText);
+ QCOMPARE(blockCount(), expectedInitialBlockCount);
+ cursor.setPosition(insertPosition);
+ if (insertBlock)
+ cursor.insertBlock(QTextBlockFormat());
+ qCDebug(lcTests) << "pos" << cursor.position() << "block" << cursor.blockNumber()
+ << "heading" << cursor.blockFormat().headingLevel();
+ if (insertAsPlainText)
+ cursor.insertText(insertText);
+ else
+ cursor.insertHtml(insertText);
+ cursor.select(QTextCursor::Document);
+ qCDebug(lcTests) << "sel text after insertion" << cursor.selectedText();
+ qCDebug(lcTests) << "text after insertion" << cursor.document()->toPlainText();
+ qCDebug(lcTests) << "html after insertion" << cursor.document()->toHtml();
+ qCDebug(lcTests) << "markdown after insertion" << cursor.document()->toMarkdown();
+ QCOMPARE(cursor.selectedText(), expectedSelText);
+ QCOMPARE(cursor.document()->toPlainText(), expectedText);
+ if (auto defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); QFontInfo(defaultFont).fixedPitch()) {
+ qWarning() << defaultFont << "is QFontDatabase::GeneralFont, and is fixedPitch";
+ QSKIP("cannot reliably distinguish normal and monospace markdown spans on this system (QTBUG-103484)");
+ }
+ QCOMPARE(cursor.document()->toMarkdown(), expectedMarkdown);
+}
+
+#endif // QT_NO_TEXTHTMLPARSER
+
+#if QT_CONFIG(textmarkdownreader)
+
+void tst_QTextCursor::insertMarkdown_data()
+{
+ QTest::addColumn<QString>("initialText");
+ QTest::addColumn<int>("expectedInitialBlockCount");
+ QTest::addColumn<int>("insertPosition");
+ QTest::addColumn<QString>("insertText");
+ QTest::addColumn<QString>("expectedSelText");
+ QTest::addColumn<QString>("expectedText");
+ QTest::addColumn<QString>("expectedMarkdown");
+
+ QTest::newRow("bold fragment in italic span")
+ << "someone said *hello world*" << 1
+ << 19 << QString(" **crazy** ")
+ << QString("someone said hello crazyworld")
+ << QString("someone said hello crazyworld")
+ << QString("someone said *hello ***crazy***world*\n\n"); // explicit B+I: not necessary but OK
+
+ QTest::newRow("list in a paragraph")
+ << "hello list with 3 items" << 1
+ << 10 << QString("1. one\n2. two\n")
+ << QString("hello list\u2029one\u2029two\u2029 with 3 items")
+ << QString("hello list\none\ntwo\n with 3 items")
+ << QString("hello list\n\n1. one\n2. two\n3. with 3 items\n");
+
+ QTest::newRow("list in a list")
+ << "1) bread\n2) milk\n" << 2
+ << 6 << QString("0) eggs\n1) maple syrup\n")
+ << QString("bread\u2029eggs\u2029maple syrup\u2029milk")
+ << QString("bread\neggs\nmaple syrup\nmilk")
+ << QString("1) bread\n2) eggs\n0) maple syrup\n1) milk\n");
+ // Renumbering would happen if we re-read the whole document.
+ // Currently insertion only uses the new list format after a paragraph separator.
+ // For that reason "bread" and "eggs" use the original list format, while "maple syrup" and
+ // "milk" use the format from the just inserted list.
+
+ QTest::newRow("list after a list")
+ << "1) bread\n2) milk\n\n" << 2
+ << 13 << QString("\n0) eggs\n1) maple syrup\n")
+ << QString("bread\u2029milk\u2029eggs\u2029maple syrup")
+ << QString("bread\nmilk\neggs\nmaple syrup")
+ << QString("1) bread\n2) milk\n3) eggs\n0) maple syrup\n");
+ // Same behavior as above. "eggs" uses the original list format, but "maple syrup" uses the
+ // format of the inserted list, which means "maple syrup" now has a start of 0.
+
+ const QString markdownHeadingString("# Hello\nWorld\n");
+
+ QTest::newRow("markdown heading at end of markdown heading")
+ << markdownHeadingString << 2
+ << 11 << QString("\n\n## Other text")
+ << QString("Hello\u2029World\u2029Other text")
+ << QString("Hello\nWorld\nOther text")
+ << QString("# Hello\n\nWorld\n\n## Other text\n\n");
+
+ QTest::newRow("markdown heading into middle of markdown heading")
+ << markdownHeadingString << 2
+ << 6 << QString("## Other\ntext\n\n")
+ << QString("Hello\u2029Other\u2029text\u2029World")
+ << QString("Hello\nOther\ntext\nWorld")
+ << QString("# Hello\n\n**Other**\n\ntext\n\nWorld\n\n");
+
+ QTest::newRow("markdown heading without trailing newline into middle of markdown heading")
+ << markdownHeadingString << 2
+ << 6 << QString("## Other\ntext")
+ << QString("Hello\u2029Other\u2029textWorld")
+ << QString("Hello\nOther\ntextWorld")
+ << QString("# Hello\n\n**Other**\n\ntextWorld\n\n");
+
+ QTest::newRow("text into middle of markdown heading after newline")
+ << markdownHeadingString << 2
+ << 6 << QString("Other ")
+ << QString("Hello\u2029OtherWorld")
+ << QString("Hello\nOtherWorld")
+ << QString("# Hello\n\nOtherWorld\n\n");
+
+ QTest::newRow("text into middle of markdown heading before newline")
+ << markdownHeadingString << 2
+ << 5 << QString(" Other ")
+ << QString("HelloOther\u2029World")
+ << QString("HelloOther\nWorld")
+ << QString("# HelloOther\n\nWorld\n\n");
+}
+
+void tst_QTextCursor::insertMarkdown()
+{
+ QFETCH(QString, initialText);
+ QFETCH(int, expectedInitialBlockCount);
+ QFETCH(int, insertPosition);
+ QFETCH(QString, insertText);
+ QFETCH(QString, expectedSelText);
+ QFETCH(QString, expectedText);
+ QFETCH(QString, expectedMarkdown);
+
+ cursor.insertMarkdown(initialText);
+ QCOMPARE(blockCount(), expectedInitialBlockCount);
+ cursor.setPosition(insertPosition);
+ qCDebug(lcTests) << "pos" << cursor.position() << "block" << cursor.blockNumber()
+ << "heading" << cursor.blockFormat().headingLevel();
+ cursor.insertMarkdown(insertText);
+ cursor.select(QTextCursor::Document);
+ qCDebug(lcTests) << "sel text after insertion" << cursor.selectedText();
+ qCDebug(lcTests) << "text after insertion" << cursor.document()->toPlainText();
+ qCDebug(lcTests) << "html after insertion" << cursor.document()->toHtml();
+ qCDebug(lcTests) << "markdown after insertion" << cursor.document()->toMarkdown();
+ QCOMPARE(cursor.selectedText(), expectedSelText);
+ QCOMPARE(cursor.document()->toPlainText(), expectedText);
+ if (auto defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); QFontInfo(defaultFont).fixedPitch()) {
+ qWarning() << defaultFont << "is QFontDatabase::GeneralFont, and is fixedPitch";
+ QSKIP("cannot reliably distinguish normal and monospace markdown spans on this system (QTBUG-103484)");
+ }
+ QCOMPARE(cursor.document()->toMarkdown(), expectedMarkdown);
+}
+
+#endif // textmarkdownreader
+
void tst_QTextCursor::insertFragmentShouldUseCurrentCharFormat()
{
QTextDocumentFragment fragment = QTextDocumentFragment::fromPlainText("Hello World");
@@ -1557,26 +1759,26 @@ void tst_QTextCursor::update_data()
QTest::newRow("removeInsideSelection")
<< text
<< /*position*/ 0
- << /*anchor*/ int(text.length())
+ << /*anchor*/ int(text.size())
// delete 'big'
<< 6
<< 6 + charsToDelete
<< QString() // don't insert anything, just remove
<< /*expectedPosition*/ 0
- << /*expectedAnchor*/ int(text.length() - charsToDelete)
+ << /*expectedAnchor*/ int(text.size() - charsToDelete)
;
text = "Hello big world";
charsToDelete = 3;
QTest::newRow("removeInsideSelectionWithSwappedAnchorAndPosition")
<< text
- << /*position*/ int(text.length())
+ << /*position*/ int(text.size())
<< /*anchor*/ 0
// delete 'big'
<< 6
<< 6 + charsToDelete
<< QString() // don't insert anything, just remove
- << /*expectedPosition*/ int(text.length() - charsToDelete)
+ << /*expectedPosition*/ int(text.size() - charsToDelete)
<< /*expectedAnchor*/ 0
;
@@ -1587,13 +1789,13 @@ void tst_QTextCursor::update_data()
QTest::newRow("replaceInsideSelection")
<< text
<< /*position*/ 0
- << /*anchor*/ int(text.length())
+ << /*anchor*/ int(text.size())
// delete 'big' ...
<< 6
<< 6 + charsToDelete
<< textToInsert // ... and replace 'big' with 'small'
<< /*expectedPosition*/ 0
- << /*expectedAnchor*/ int(text.length() - charsToDelete + textToInsert.length())
+ << /*expectedAnchor*/ int(text.size() - charsToDelete + textToInsert.size())
;
text = "Hello big world";
@@ -1601,13 +1803,13 @@ void tst_QTextCursor::update_data()
textToInsert = "small";
QTest::newRow("replaceInsideSelectionWithSwappedAnchorAndPosition")
<< text
- << /*position*/ int(text.length())
+ << /*position*/ int(text.size())
<< /*anchor*/ 0
// delete 'big' ...
<< 6
<< 6 + charsToDelete
<< textToInsert // ... and replace 'big' with 'small'
- << /*expectedPosition*/ int(text.length() - charsToDelete + textToInsert.length())
+ << /*expectedPosition*/ int(text.size() - charsToDelete + textToInsert.size())
<< /*expectedAnchor*/ 0
;
@@ -1616,14 +1818,14 @@ void tst_QTextCursor::update_data()
charsToDelete = 3;
QTest::newRow("removeBeforeSelection")
<< text
- << /*position*/ int(text.length() - 5)
- << /*anchor*/ int(text.length())
+ << /*position*/ int(text.size() - 5)
+ << /*anchor*/ int(text.size())
// delete 'big'
<< 6
<< 6 + charsToDelete
<< QString() // don't insert anything, just remove
- << /*expectedPosition*/ int(text.length() - 5 - charsToDelete)
- << /*expectedAnchor*/ int(text.length() - charsToDelete)
+ << /*expectedPosition*/ int(text.size() - 5 - charsToDelete)
+ << /*expectedAnchor*/ int(text.size() - charsToDelete)
;
text = "Hello big world";
diff --git a/tests/auto/gui/text/qtextdocument/CMakeLists.txt b/tests/auto/gui/text/qtextdocument/CMakeLists.txt
index bff5cabfb7..62fa1d46ca 100644
--- a/tests/auto/gui/text/qtextdocument/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextdocument/CMakeLists.txt
@@ -1,14 +1,21 @@
-# Generated from qtextdocument.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextdocument Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextdocument LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextdocument
SOURCES
common.h
tst_qtextdocument.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextdocument/common.h b/tests/auto/gui/text/qtextdocument/common.h
index 11ad99cfa0..3c05913008 100644
--- a/tests/auto/gui/text/qtextdocument/common.h
+++ b/tests/auto/gui/text/qtextdocument/common.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QAbstractTextDocumentLayout>
#include <private/qtextdocument_p.h>
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index c028ae1b9c..40f78ed778 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -96,6 +71,7 @@ private slots:
void toHtml2();
void setFragmentMarkersInHtmlExport();
+ void setMediaRule();
void toHtmlBodyBgColor();
void toHtmlBodyBgColorRgba();
@@ -198,6 +174,18 @@ private slots:
void resourceProvider();
+ void contentsChangeIndices_data();
+ void contentsChangeIndices();
+
+ void insertHtmlWithComments_data();
+ void insertHtmlWithComments();
+
+ void delayedLayout();
+ void undoContentChangeIndices();
+
+ void restoreStrokeFromHtml();
+ void restoreForegroundGradientFromHtml();
+
private:
void backgroundImage_checkExpectedHtml(const QTextDocument &doc);
void buildRegExpData();
@@ -290,6 +278,8 @@ void tst_QTextDocument::init()
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"hr { height: 1px; border-width: 0; }\n"
+ "li.unchecked::marker { content: \"\\2610\"; }\n"
+ "li.checked::marker { content: \"\\2612\"; }\n"
"</style></head>"
"<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\">\n");
htmlHead = htmlHead.arg(defaultFont.family())
@@ -479,17 +469,17 @@ void tst_QTextDocument::basicIsModifiedChecks()
QVERIFY(!doc->isModified());
cursor.insertText("Hello World");
QVERIFY(doc->isModified());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(spy.takeFirst().at(0).toBool());
doc->undo();
QVERIFY(!doc->isModified());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(!spy.takeFirst().at(0).toBool());
doc->redo();
QVERIFY(doc->isModified());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(spy.takeFirst().at(0).toBool());
}
@@ -580,16 +570,16 @@ void tst_QTextDocument::noundo_basicIsModifiedChecks()
QVERIFY(!doc->isModified());
cursor.insertText("Hello World");
QVERIFY(doc->isModified());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(spy.takeFirst().at(0).toBool());
doc->undo();
QVERIFY(doc->isModified());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
doc->redo();
QVERIFY(doc->isModified());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTextDocument::task240325()
@@ -609,9 +599,6 @@ void tst_QTextDocument::task240325()
QCOMPARE(doc->blockCount(), 1);
for (QTextBlock block = doc->begin() ; block!=doc->end() ; block = block.next()) {
QTextLayout *layout = block.layout();
-#ifdef Q_OS_ANDROID
- QEXPECT_FAIL("", "QTBUG-69242", Abort);
-#endif
QCOMPARE(layout->lineCount(), 4);
for (int lineIdx=0;lineIdx<layout->lineCount();++lineIdx) {
@@ -760,6 +747,9 @@ void tst_QTextDocument::mightBeRichText_data()
" PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN\" \"DTD/xhtml1-strict.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
QVERIFY(Qt::mightBeRichText(QString::fromLatin1(qtDocuHeader)));
+ QVERIFY(Qt::mightBeRichText(QLatin1StringView(qtDocuHeader)));
+ QVERIFY(QUtf8StringView(qtDocuHeader).isValidUtf8());
+ QVERIFY(Qt::mightBeRichText(QUtf8StringView(qtDocuHeader)));
QTest::addColumn<QString>("input");
QTest::addColumn<bool>("result");
@@ -779,6 +769,10 @@ void tst_QTextDocument::mightBeRichText()
QFETCH(QString, input);
QFETCH(bool, result);
QCOMPARE(result, Qt::mightBeRichText(input));
+ QCOMPARE(result, Qt::mightBeRichText(QStringView(input)));
+ QCOMPARE(result, Qt::mightBeRichText(QUtf8StringView(input.toUtf8())));
+ QVERIFY(QtPrivate::isLatin1(input));
+ QCOMPARE(result, Qt::mightBeRichText(QLatin1StringView(input.toLatin1())));
}
Q_DECLARE_METATYPE(QTextDocumentFragment)
@@ -1390,7 +1384,7 @@ void tst_QTextDocument::toHtml_data()
QTest::newRow("lists") << QTextDocumentFragment(&doc)
<<
QString("EMPTYBLOCK") +
- QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>");
+ QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blubb</li>\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>");
}
{
@@ -1413,7 +1407,7 @@ void tst_QTextDocument::toHtml_data()
QTest::newRow("charfmt-for-list-item") << QTextDocumentFragment(&doc)
<<
QString("EMPTYBLOCK") +
- QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blubb</li>\n<li style=\" color:#0000ff;\" DEFAULTBLOCKSTYLE><span style=\" color:#ff0000;\">Blah</span></li></ul>");
+ QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blubb</li>\n<li style=\" color:#0000ff;\" DEFAULTBLOCKSTYLE><span style=\" color:#ff0000;\">Blah</span></li></ul>");
}
{
@@ -1443,7 +1437,7 @@ void tst_QTextDocument::toHtml_data()
QTest::newRow("list-indent") << QTextDocumentFragment(&doc)
<<
QString("EMPTYBLOCK") +
- QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 4;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>");
+ QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 4;\">\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>");
}
{
@@ -1731,7 +1725,7 @@ void tst_QTextDocument::toHtml_data()
QTest::newRow("list-ul-margin") << QTextDocumentFragment(&doc)
<< QString("EMPTYBLOCK") +
- QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\"><li DEFAULTBLOCKSTYLE>Blah</li></ul>");
+ QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li DEFAULTBLOCKSTYLE>Blah</li></ul>");
}
{
CREATE_DOC_AND_CURSOR();
@@ -1741,12 +1735,12 @@ void tst_QTextDocument::toHtml_data()
cursor.insertHtml(listHtml);
QTest::newRow("nested-lists-one") << QTextDocumentFragment(&doc)
- << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
- "item-1</li>\n<li DEFAULTBLOCKSTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "item-1</li>\n<li DEFAULTBLOCKSTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li "
"DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2\n<ul "
- "DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>item-2.2.1</li></ul></li>\n"
- "<li DEFAULTBLOCKSTYLE>item-2.3\n<ul DEFAULTULSTYLE 3;\"><li DEFAULTBLOCKSTYLE>"
+ "DEFAULTULSTYLE 3;\">\n<li DEFAULTBLOCKSTYLE>item-2.2.1</li></ul></li>\n"
+ "<li DEFAULTBLOCKSTYLE>item-2.3\n<ul DEFAULTULSTYLE 3;\">\n<li DEFAULTBLOCKSTYLE>"
"item-2.3.1</li></ul></li></ul></li>\n<li DEFAULTLASTLISTYLE>item-3</li></ul>");
}
{
@@ -1755,9 +1749,9 @@ void tst_QTextDocument::toHtml_data()
cursor.insertHtml(listHtml);
QTest::newRow("nested-lists-two") << QTextDocumentFragment(&doc)
- << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
- "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li "
"DEFAULTBLOCKSTYLE>item-2.1</li></ul></li></ul>");
}
{
@@ -1767,9 +1761,9 @@ void tst_QTextDocument::toHtml_data()
cursor.insertHtml(listHtml);
QTest::newRow("nested-lists-three") << QTextDocumentFragment(&doc)
- << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
- "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\"><li "
+ "item-1</li>\n<li DEFAULTLASTLISTYLE>item-2\n<ul DEFAULTULSTYLE 2;\">\n<li "
"DEFAULTBLOCKSTYLE>item-2.1</li>\n<li DEFAULTBLOCKSTYLE>item-2.2</li></ul>"
"</li></ul>");
}
@@ -1780,12 +1774,39 @@ void tst_QTextDocument::toHtml_data()
cursor.insertHtml(listHtml);
QTest::newRow("not-nested-list") << QTextDocumentFragment(&doc)
- << QString("<ul DEFAULTULSTYLE 1;\"><li style=\" margin-top:12px; margin-bottom:0px; "
+ << QString("<ul DEFAULTULSTYLE 1;\">\n<li style=\" margin-top:12px; margin-bottom:0px; "
"margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
- "item-1.1</li>\n<li DEFAULTBLOCKSTYLE>item-1.2</li></ul>\n<ul DEFAULTULSTYLE 1;\">"
+ "item-1.1</li>\n<li DEFAULTBLOCKSTYLE>item-1.2</li></ul>\n<ul DEFAULTULSTYLE 1;\">\n"
"<li style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; "
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\">item-2.1</li></ul>");
}
+ {
+ CREATE_DOC_AND_CURSOR();
+ const QString listHtml = "<ul><li>bullet</li><li class=\"unchecked\">unchecked item</li><li class=\"checked\">checked item</li></ul>";
+ cursor.insertHtml(listHtml);
+
+ QTest::newRow("list with and without checkboxes") << QTextDocumentFragment(&doc)
+ << QString("<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n"
+ "<li style=\" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">bullet</li>\n"
+ "<li class=\"unchecked\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">unchecked item</li>\n"
+ "<li class=\"checked\" style=\" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">checked item</li></ul>");
+ }
+
+ {
+ CREATE_DOC_AND_CURSOR();
+
+ QTextListFormat fmt;
+ fmt.setStyle(QTextListFormat::ListDecimal);
+ fmt.setStart(4);
+ cursor.insertList(fmt);
+ cursor.insertText("Blah");
+ cursor.insertBlock();
+ cursor.insertText("Bleh");
+
+ QTest::newRow("ordered list with start") << QTextDocumentFragment(&doc)
+ << QString("EMPTYBLOCK") +
+ QString("<ol start=\"4\" style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;\">\n<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</li>\n<li style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Bleh</li></ol>");
+ }
}
void tst_QTextDocument::toHtml()
@@ -1907,6 +1928,39 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport()
}
}
+void tst_QTextDocument::setMediaRule()
+{
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#000000;\"><span style=\" background-color:#000000;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setMetaInformation(QTextDocument::CssMedia, "screen");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#000000;\"><span style=\" background-color:#000000;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setMetaInformation(QTextDocument::CssMedia, "print");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;\"><span style=\" background-color:#ffffff;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+}
+
void tst_QTextDocument::toHtmlBodyBgColor()
{
CREATE_DOC_AND_CURSOR();
@@ -1918,7 +1972,7 @@ void tst_QTextDocument::toHtmlBodyBgColor()
doc.rootFrame()->setFrameFormat(fmt);
QString expectedHtml = htmlHead;
- expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"#0000ff\"");
+ expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"#0000ff\"");
expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ htmlTail;
@@ -1938,7 +1992,7 @@ void tst_QTextDocument::toHtmlBodyBgColorRgba()
doc.rootFrame()->setFrameFormat(fmt);
QString expectedHtml = htmlHead;
- expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"rgba(255,0,0,0.2)\"");
+ expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"rgba(255,0,0,0.2)\"");
expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ htmlTail;
@@ -1958,7 +2012,7 @@ void tst_QTextDocument::toHtmlBodyBgColorTransparent()
doc.rootFrame()->setFrameFormat(fmt);
QString expectedHtml = htmlHead;
- expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"transparent\"");
+ expectedHtml.insert(htmlHead.size() - 2, " bgcolor=\"transparent\"");
expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ htmlTail;
@@ -2024,7 +2078,7 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties()
doc.setDefaultFont(fnt);
QString expectedOutput = htmlHead;
- expectedOutput.insert(htmlHead.length() - 3, " letter-spacing:13px; word-spacing:15px;");
+ expectedOutput.insert(htmlHead.size() - 3, " letter-spacing:13px; word-spacing:15px;");
expectedOutput +=
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ htmlTail;
@@ -2044,7 +2098,7 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline()
doc.setDefaultFont(fnt);
QString expectedOutput = htmlHead;
- expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;");
+ expectedOutput.insert(htmlHead.size() - 3, " text-decoration: underline;");
expectedOutput +=
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>"
+ htmlTail;
@@ -2059,7 +2113,7 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline()
cursor.mergeCharFormat(format);
expectedOutput = htmlHead;
- expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;");
+ expectedOutput.insert(htmlHead.size() - 3, " text-decoration: underline;");
expectedOutput +=
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
@@ -2291,14 +2345,18 @@ void tst_QTextDocument::clonePreservesMetaInformation()
{
const QString title("Foobar");
const QString url("about:blank");
+ const QString media("print");
doc->setHtml("<html><head><title>" + title + "</title></head><body>Hrm</body></html>");
doc->setMetaInformation(QTextDocument::DocumentUrl, url);
+ doc->setMetaInformation(QTextDocument::CssMedia, media);
QCOMPARE(doc->metaInformation(QTextDocument::DocumentTitle), title);
QCOMPARE(doc->metaInformation(QTextDocument::DocumentUrl), url);
+ QCOMPARE(doc->metaInformation(QTextDocument::CssMedia), media);
QTextDocument *clone = doc->clone();
QCOMPARE(clone->metaInformation(QTextDocument::DocumentTitle), title);
QCOMPARE(clone->metaInformation(QTextDocument::DocumentUrl), url);
+ QCOMPARE(clone->metaInformation(QTextDocument::CssMedia), media);
delete clone;
}
@@ -2709,11 +2767,11 @@ void tst_QTextDocument::defaultTableStyle()
brushes << sideProperty.value<QBrush>();
}
auto errorDetails = qScopeGuard([&]{
- if (brushes.count() != borderBrushes.count()) {
- qWarning("Different count: %lld vs %lld", brushes.count(), borderBrushes.count());
+ if (brushes.size() != borderBrushes.size()) {
+ qWarning("Different count: %lld vs %lld", brushes.size(), borderBrushes.size());
return;
}
- for (int i = 0; i < brushes.count(); ++i) {
+ for (int i = 0; i < brushes.size(); ++i) {
QString side;
QDebug(&side) << QTextFormat::Property(QTextFormat::TableCellTopBorderBrush + i);
QString actual;
@@ -2837,13 +2895,13 @@ void tst_QTextDocument::blockCountChanged()
doc->setPlainText("Foo");
QCOMPARE(doc->blockCount(), 1);
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
spy.clear();
doc->setPlainText("Foo\nBar");
QCOMPARE(doc->blockCount(), 2);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.at(0).value(0).toInt(), 2);
spy.clear();
@@ -2851,16 +2909,16 @@ void tst_QTextDocument::blockCountChanged()
cursor.movePosition(QTextCursor::End);
cursor.insertText("Blahblah");
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
cursor.insertBlock();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.at(0).value(0).toInt(), 3);
spy.clear();
doc->undo();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(spy.at(0).value(0).toInt(), 2);
}
@@ -3039,12 +3097,12 @@ void tst_QTextDocument::characterAt()
QString text("12345\n67890");
cursor.insertText(text);
int length = doc.characterCount();
- QCOMPARE(length, text.length() + 1);
+ QCOMPARE(length, text.size() + 1);
QCOMPARE(doc.characterAt(length-1), QChar(QChar::ParagraphSeparator));
QCOMPARE(doc.characterAt(-1), QChar());
QCOMPARE(doc.characterAt(length), QChar());
QCOMPARE(doc.characterAt(length + 1), QChar());
- for (int i = 0; i < text.length(); ++i) {
+ for (int i = 0; i < text.size(); ++i) {
QChar c = text.at(i);
if (c == QLatin1Char('\n'))
c = QChar(QChar::ParagraphSeparator);
@@ -3124,11 +3182,11 @@ void tst_QTextDocument::testUndoCommandAdded()
QVERIFY(spy.isEmpty());
cursor.insertText("a");
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
cursor.insertText("b"); // should be merged
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
cursor.insertText("c"); // should be merged
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QCOMPARE(doc->toPlainText(), QString("abc"));
doc->undo();
QCOMPARE(doc->toPlainText(), QString(""));
@@ -3136,11 +3194,11 @@ void tst_QTextDocument::testUndoCommandAdded()
doc->clear();
spy.clear();
cursor.insertText("aaa");
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
cursor.insertText("aaaa\nbcd");
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
cursor.beginEditBlock();
@@ -3150,11 +3208,11 @@ void tst_QTextDocument::testUndoCommandAdded()
cursor.insertText("\nccc");
QVERIFY(spy.isEmpty());
cursor.endEditBlock();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
cursor.insertBlock();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
cursor.setPosition(5);
@@ -3166,18 +3224,18 @@ void tst_QTextDocument::testUndoCommandAdded()
QTextCharFormat cf;
cf.setFontItalic(true);
cursor.mergeCharFormat(cf);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
spy.clear();
doc->undo();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
doc->undo();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
spy.clear();
doc->redo();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
doc->redo();
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
}
void tst_QTextDocument::testUndoBlocks()
@@ -3757,7 +3815,7 @@ void tst_QTextDocument::mergeFontFamilies()
QTextCursor cursor = QTextCursor(&td);
cursor.setPosition(0);
- cursor.setPosition(QByteArray("Hello World").length(), QTextCursor::KeepAnchor);
+ cursor.setPosition(QByteArray("Hello World").size(), QTextCursor::KeepAnchor);
cursor.mergeCharFormat(newFormat);
QVERIFY(td.toHtml().contains(QLatin1String("font-family:'Jokerman';")));
@@ -3820,5 +3878,285 @@ void tst_QTextDocument::resourceProvider()
QCOMPARE(providerCalled, 2);
}
+void tst_QTextDocument::contentsChangeIndices_data()
+{
+ QTest::addColumn<QString>("html");
+ // adding list entries change the entire block, so change position is
+ // not the same as the cursor position if this value is >= 0
+ QTest::addColumn<int>("expectedBegin");
+
+ QTest::addRow("text") << "Test" << -1;
+ QTest::addRow("unnumbered list") << "<ul><li>Test</li></ul>" << 0;
+ QTest::addRow("numbered list") << "<ol><li>Test</li></ol>" << 0;
+ QTest::addRow("table") << "<table><tr><td>Test</td></tr></table>" << -1;
+}
+
+void tst_QTextDocument::contentsChangeIndices()
+{
+ QFETCH(QString, html);
+ QFETCH(int, expectedBegin);
+
+ QTextDocument doc;
+ QTestDocumentLayout *layout = new QTestDocumentLayout(&doc);
+ doc.setDocumentLayout(layout);
+ doc.setHtml(QString("<html><body>%1</body></html>").arg(html));
+
+ int documentLength = 0;
+ int cursorLength = 0;
+ int changeBegin = 0;
+ int changeRemoved = 0;
+ int changeAdded = 0;
+ connect(&doc, &QTextDocument::contentsChange, this, [&](int pos, int removed, int added){
+ documentLength = doc.characterCount();
+
+ QTextCursor cursor(&doc);
+ cursor.movePosition(QTextCursor::End);
+ // includes end-of-paragraph character
+ cursorLength = cursor.position() + 1;
+
+ changeBegin = pos;
+ changeRemoved = removed;
+ changeAdded = added;
+ });
+
+ QTextCursor cursor(&doc);
+ cursor.movePosition(QTextCursor::End);
+ if (expectedBegin < 0)
+ expectedBegin = cursor.position();
+ cursor.insertBlock();
+
+ const int changeEnd = changeBegin + changeAdded;
+
+ QVERIFY(documentLength > 0);
+ QCOMPARE(documentLength, cursorLength);
+ QVERIFY(documentLength >= changeEnd);
+ QCOMPARE(changeBegin, expectedBegin);
+ QCOMPARE(changeAdded - changeRemoved, 1);
+}
+
+void tst_QTextDocument::insertHtmlWithComments_data()
+{
+ QTest::addColumn<QString>("html");
+ QTest::addColumn<QStringList>("expectedBlocks");
+
+ QTest::newRow("commentless") << "<p>first</p><p>second</p><p>third</p>"
+ << QStringList { "first", "second", "third" };
+ QTest::newRow("normal") << "<p>first</p><!--<p>second</p>--><p>third</p>"
+ << QStringList { "first", "third" };
+ QTest::newRow("nonClosing") << "<p>first</p><!--<p>second</p><p>third</p>"
+ << QStringList { "first" };
+ QTest::newRow("immediatelyClosing") << "<p>first</p><!----><p>second</p><p>third</p>"
+ << QStringList { "first", "second", "third" };
+ QTest::newRow("fake") << "<p>first</p><!-<p>second</p><p>third</p>"
+ << QStringList { "first", "second", "third" };
+ QTest::newRow("endingNonExistant") << "<p>first</p>--><p>second</p><p>third</p>"
+ << QStringList { "first", "-->", "second", "third" };
+}
+
+void tst_QTextDocument::insertHtmlWithComments()
+{
+ QFETCH(QString, html);
+ QFETCH(QStringList, expectedBlocks);
+
+ QTextDocument doc;
+ doc.setHtml(html);
+
+ QCOMPARE(doc.blockCount(), expectedBlocks.size());
+
+ QStringList blockContent;
+ auto currentBlock = doc.begin();
+ while (currentBlock != doc.end()) {
+ blockContent.append(currentBlock.text());
+ currentBlock = currentBlock.next();
+ }
+
+ QCOMPARE(blockContent, expectedBlocks);
+}
+
+void tst_QTextDocument::delayedLayout()
+{
+ QTextDocument doc;
+ doc.setHtml("<html>Foobar</html>");
+ QCOMPARE(doc.blockCount(), 1);
+
+ doc.setLayoutEnabled(false);
+
+ // Force creation of a layout
+ QVERIFY(doc.documentLayout());
+
+ QTextBlock block = doc.begin();
+ QTextLayout *layout = block.layout();
+ QCOMPARE(layout->lineCount(), 0); // layout didn't happen yet
+
+ doc.setLayoutEnabled(true);
+ QCOMPARE(layout->lineCount(), 1); // layout happened
+}
+
+void tst_QTextDocument::undoContentChangeIndices() // QTBUG-113865
+{
+ QTextDocument doc;
+ QTestDocumentLayout *layout = new QTestDocumentLayout(&doc);
+ QString content = QString("<html><body>"
+ "<ul><li>Undo</li></ul>"
+ "<ul><li>operation</li></ul>"
+ "<ul><li>of</li></ul>"
+ "<ul><li>unnumbered</li></ul>"
+ "<ul><li>lists</li></ul>"
+ "<ul><li>shows</li></ul>"
+ "<ul><li>invalid</li></ul>"
+ "<ul><li>content</li></ul>"
+ "<ul><li>indices</li></ul>"
+ "</body></html>");
+ doc.setDocumentLayout(layout);
+ doc.setHtml(content);
+
+ // Select the entire document content
+ QTextCursor cursor(&doc);
+ cursor.select(QTextCursor::Document);
+ cursor.removeSelectedText();
+
+ // Undo above operation
+ doc.undo();
+
+ // Move the cursor to the end
+ cursor.movePosition(QTextCursor::End);
+ cursor.insertHtml(content);
+
+ // Select the whole document and remove the content
+ cursor.select(QTextCursor::Document);
+ cursor.removeSelectedText();
+
+ int documentLength = 0;
+ int changeRemoved = 0;
+ int changeAdded = 0;
+ int changePos = 0;
+ connect(&doc, &QTextDocument::contentsChange, this, [&](int pos, int removed, int added){
+ documentLength = doc.characterCount();
+ changeRemoved = removed;
+ changeAdded = added;
+ changePos = pos;
+ });
+
+ // Undo above operation
+ doc.undo();
+
+ const int changeEnd = changeAdded + changeRemoved;
+
+ QVERIFY(documentLength > 0);
+ QCOMPARE(changePos, 0);
+ QVERIFY(changeRemoved >= 0);
+ QVERIFY(documentLength >= changeEnd);
+}
+
+void tst_QTextDocument::restoreStrokeFromHtml()
+{
+ QTextDocument document;
+ QTextCursor textCursor(&document);
+ QTextCharFormat textOutline;
+ textOutline.setTextOutline(QPen(Qt::red, 2.3));
+ textCursor.insertText("Outlined text", textOutline);
+ {
+ QTextDocument otherDocument;
+ otherDocument.setHtml(document.toHtml());
+ QCOMPARE(otherDocument.blockCount(), 1);
+ QTextBlock block = otherDocument.firstBlock();
+ QTextFragment fragment = block.begin().fragment();
+ QCOMPARE(fragment.text(), QStringLiteral("Outlined text"));
+ QTextCharFormat fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
+ QPen pen = fmt.textOutline();
+ QCOMPARE(pen.color(), QColor(Qt::red));
+ QCOMPARE(pen.widthF(), 2.3);
+ }
+}
+
+void tst_QTextDocument::restoreForegroundGradientFromHtml()
+{
+ QTextDocument document;
+
+ QTextCursor textCursor(&document);
+
+ QTextCharFormat foregroundGradient;
+ QLinearGradient lg;
+ lg.setColorAt(0.0, Qt::green);
+ lg.setColorAt(1.0, Qt::blue);
+ lg.setStart(QPointF(0,0));
+ lg.setFinalStop(QPointF(800, 1000));
+ foregroundGradient.setForeground(QBrush(lg));
+ textCursor.insertText("Linear gradient text\n", foregroundGradient);
+
+ QRadialGradient rg;
+ rg.setCoordinateMode(QGradient::ObjectBoundingMode);
+ rg.setSpread(QGradient::ReflectSpread);
+ rg.setColorAt(0.0, Qt::green);
+ rg.setColorAt(1.0, Qt::blue);
+ QPointF center(0.5, 0.5);
+ rg.setCenter(center);
+ rg.setFocalPoint(center);
+ rg.setRadius(0.5);
+ foregroundGradient.setForeground(QBrush(rg));
+ textCursor.insertText("Radial gradient text\n", foregroundGradient);
+
+ QConicalGradient cg;
+ cg.setCoordinateMode(QGradient::ObjectMode);
+ cg.setSpread(QGradient::RepeatSpread);
+ cg.setColorAt(0.0, Qt::green);
+ cg.setColorAt(1.0, Qt::blue);
+ cg.setCenter(QPointF(0.5, 0.5));
+ cg.setAngle(0.0);
+ foregroundGradient.setForeground(QBrush(cg));
+ textCursor.insertText("Conical gradient text\n", foregroundGradient);
+
+ {
+ QTextDocument otherDocument;
+ otherDocument.setHtml(document.toHtml());
+
+ QCOMPARE(otherDocument.blockCount(), document.blockCount());
+
+ QTextBlock block = otherDocument.firstBlock();
+ QTextFragment fragment = block.begin().fragment();
+
+ QCOMPARE(fragment.text(), QStringLiteral("Linear gradient text"));
+
+ QTextCharFormat fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush));
+
+ QBrush brush = fmt.foreground();
+ QCOMPARE(brush.style(), Qt::LinearGradientPattern);
+ QCOMPARE(brush.gradient()->coordinateMode(), lg.coordinateMode());
+ QCOMPARE(brush.gradient()->spread(), lg.spread());
+ QCOMPARE(brush.gradient()->stops().size(), lg.stops().size());
+ QCOMPARE(static_cast<const QLinearGradient *>(brush.gradient())->start(), lg.start());
+ QCOMPARE(static_cast<const QLinearGradient *>(brush.gradient())->finalStop(), lg.finalStop());
+
+ block = block.next();
+ fragment = block.begin().fragment();
+
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush));
+
+ brush = fmt.foreground();
+ QCOMPARE(brush.style(), Qt::RadialGradientPattern);
+ QCOMPARE(brush.gradient()->coordinateMode(), rg.coordinateMode());
+ QCOMPARE(brush.gradient()->spread(), rg.spread());
+ QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->center(), rg.center());
+ QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->focalPoint(), rg.focalPoint());
+ QCOMPARE(static_cast<const QRadialGradient *>(brush.gradient())->radius(), rg.radius());
+
+ block = block.next();
+ fragment = block.begin().fragment();
+
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::ForegroundBrush));
+
+ brush = fmt.foreground();
+ QCOMPARE(brush.style(), Qt::ConicalGradientPattern);
+ QCOMPARE(brush.gradient()->coordinateMode(), cg.coordinateMode());
+ QCOMPARE(brush.gradient()->spread(), cg.spread());
+ QCOMPARE(static_cast<const QConicalGradient *>(brush.gradient())->center(), cg.center());
+ QCOMPARE(static_cast<const QConicalGradient *>(brush.gradient())->angle(), cg.angle());
+ }
+}
+
QTEST_MAIN(tst_QTextDocument)
#include "tst_qtextdocument.moc"
diff --git a/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt
index 6f1207c49a..4a4075106e 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextdocumentfragment.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextdocumentfragment Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextdocumentfragment LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextdocumentfragment
SOURCES
tst_qtextdocumentfragment.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index 24704bec37..f2c3b36dcd 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -41,6 +16,8 @@
#include <qtextcursor.h>
+using namespace Qt::StringLiterals;
+
QT_FORWARD_DECLARE_CLASS(QTextDocument)
class tst_QTextDocumentFragment : public QObject
@@ -100,6 +77,7 @@ private slots:
void inheritAlignment();
void dontEmitEmptyNodeWhenEmptyTagIsFollowedByCloseTag();
void toPlainText();
+ void toRawText();
void copyTableRow();
void copyTableColumn();
void copySubTable();
@@ -120,6 +98,7 @@ private slots:
void html_thCentered();
void orderedListNumbering();
void html_blockAfterList();
+ void html_listStartAttribute();
void html_subAndSuperScript();
void html_cssColors();
void obeyFragmentMarkersInImport();
@@ -268,6 +247,7 @@ private slots:
void html_fromFirefox();
void html_emptyInlineInsideBlock();
void css_fontAndWordSpacing();
+ void html_brWithWhitespaceAfterList();
private:
inline void setHtml(const QString &html)
@@ -1094,6 +1074,14 @@ void tst_QTextDocumentFragment::toPlainText()
QCOMPARE(doc->blockCount(), 3);
}
+void tst_QTextDocumentFragment::toRawText()
+{
+ // Make sure nbsp, line separator, paragraph separator is preserved
+ doc->setPlainText("Hello\u0A00\u2028\u2029World");
+
+ QCOMPARE(QTextDocumentFragment(doc).toRawText(), "Hello\u0A00\u2028\u2029World");
+}
+
void tst_QTextDocumentFragment::copyTableRow()
{
QTextDocumentFragment frag;
@@ -1191,7 +1179,7 @@ void tst_QTextDocumentFragment::copySubTable()
table->cellAt(row, col).firstCursorPosition().insertText(rowS + QString::number(col));
}
- QCOMPARE(table->format().columnWidthConstraints().count(), table->columns());
+ QCOMPARE(table->format().columnWidthConstraints().size(), table->columns());
// select 2x2 subtable
cursor = table->cellAt(1, 1).firstCursorPosition();
@@ -1487,6 +1475,22 @@ void tst_QTextDocumentFragment::html_blockAfterList()
QCOMPARE(cursor.blockFormat().indent(), 0);
}
+void tst_QTextDocumentFragment::html_listStartAttribute()
+{
+ const char html[] = "<ol start=-1><li>Foo</ol><ol><li>Bar</ol>";
+ cursor.insertFragment(QTextDocumentFragment::fromHtml(html));
+
+ cursor.movePosition(QTextCursor::Start);
+
+ QVERIFY(cursor.currentList());
+ QCOMPARE(cursor.currentList()->format().start(), -1);
+
+ QVERIFY(cursor.movePosition(QTextCursor::NextBlock));
+
+ QVERIFY(cursor.currentList());
+ QCOMPARE(cursor.currentList()->format().start(), 1);
+}
+
void tst_QTextDocumentFragment::html_subAndSuperScript()
{
const char subHtml[] = "<sub>Subby</sub>";
@@ -2251,7 +2255,7 @@ void tst_QTextDocumentFragment::html_frameImport()
cursor.insertFragment(frag);
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
QCOMPARE(frame->frameFormat().margin(), ffmt.margin());
QCOMPARE(frame->frameFormat().border(), ffmt.border());
@@ -2279,7 +2283,7 @@ void tst_QTextDocumentFragment::html_frameImport2()
cursor.insertFragment(frag);
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
QCOMPARE(frame->frameFormat().topMargin(), ffmt.topMargin());
QCOMPARE(frame->frameFormat().bottomMargin(), ffmt.bottomMargin());
@@ -2294,7 +2298,7 @@ void tst_QTextDocumentFragment::html_dontAddMarginsAcrossTableCells()
cursor.insertFragment(QTextDocumentFragment::fromHtml(QString::fromLatin1(html)));
QList<QTextFrame *> childFrames = doc->rootFrame()->childFrames();
- QCOMPARE(childFrames.count(), 1);
+ QCOMPARE(childFrames.size(), 1);
QTextFrame *frame = childFrames.first();
cursor = frame->firstCursorPosition();
QCOMPARE(cursor.blockFormat().leftMargin(), qreal(50.0));
@@ -2776,7 +2780,7 @@ void tst_QTextDocumentFragment::html_columnWidths()
QTextTableFormat fmt = table->format();
const QList<QTextLength> columnWidths = fmt.columnWidthConstraints();
- QCOMPARE(columnWidths.count(), 2);
+ QCOMPARE(columnWidths.size(), 2);
QCOMPARE(columnWidths.at(0).type(), QTextLength::VariableLength);
QCOMPARE(columnWidths.at(1).type(), QTextLength::PercentageLength);
QCOMPARE(columnWidths.at(1).rawValue(), qreal(1));
@@ -4184,7 +4188,7 @@ void tst_QTextDocumentFragment::html_entities()
setHtml(html);
QCOMPARE(doc->blockCount(), 1);
QString txt = doc->begin().text();
- QCOMPARE(txt.length(), 1);
+ QCOMPARE(txt.size(), 1);
QCOMPARE(txt.at(0).unicode(), code);
}
@@ -4319,5 +4323,24 @@ void tst_QTextDocumentFragment::css_fontAndWordSpacing()
}
}
+void tst_QTextDocumentFragment::html_brWithWhitespaceAfterList() // QTBUG-81662
+{
+ setHtml(QString::fromLatin1("<ul><li>one</li><li>two</li></ul>\n <br/>\nhello"));
+
+ QCOMPARE(doc->blockCount(), 3);
+
+ QTextBlock block = doc->begin();
+ QVERIFY(block.textList());
+
+ block = block.next();
+ QVERIFY(block.textList());
+
+ block = block.next();
+ QCOMPARE(block.text(), u"\u2028hello"_s);
+
+ block = block.next();
+ QVERIFY(block.text().isEmpty());
+}
+
QTEST_MAIN(tst_QTextDocumentFragment)
#include "tst_qtextdocumentfragment.moc"
diff --git a/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST b/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST
index 5a2f81c448..ed85376c92 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST
+++ b/tests/auto/gui/text/qtextdocumentlayout/BLACKLIST
@@ -1,6 +1,3 @@
[imageAtRightAlignedTab]
-rhel-6.6
-rhel-7.4
-rhel-7.6
sles
centos
diff --git a/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt
index da41073962..07386d4e24 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextdocumentlayout.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextdocumentlayout Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextdocumentlayout LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextdocumentlayout
SOURCES
tst_qtextdocumentlayout.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
@@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtextdocumentlayout
#####################################################################
qt_internal_extend_target(tst_qtextdocumentlayout CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
index 0075203c97..2a279682ca 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
+++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -58,6 +33,7 @@ private slots:
void floatingTablePageBreak();
void imageAtRightAlignedTab();
void blockVisibility();
+ void testHitTest();
void largeImage();
@@ -405,5 +381,41 @@ void tst_QTextDocumentLayout::largeImage()
}
}
+void tst_QTextDocumentLayout::testHitTest()
+{
+ QTextDocument document;
+ QTextCursor cur(&document);
+ int topMargin = 20;
+
+ //insert 500 blocks into textedit
+ for (int i = 0; i < 500; i++) {
+ cur.insertBlock();
+ cur.insertHtml(QString("block %1").arg(i));
+ }
+
+ //randomly set half the blocks invisible
+ QTextBlock blk=document.begin();
+ for (int i = 0; i < 500; i++) {
+ if (i % 7)
+ blk.setVisible(0);
+ blk = blk.next();
+ }
+
+ //set margin for all blocks (not strictly necessary, but makes easier to click in between blocks)
+ QTextBlockFormat blkfmt;
+ blkfmt.setTopMargin(topMargin);
+ cur.movePosition(QTextCursor::Start);
+ cur.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+ cur.mergeBlockFormat(blkfmt);
+
+ for (int y = cur.selectionStart(); y < cur.selectionEnd(); y += 10) {
+ QPoint mousePoint(1, y);
+ int cursorPos = document.documentLayout()->hitTest(mousePoint, Qt::FuzzyHit);
+ int positionY = document.findBlock(cursorPos).layout()->position().toPoint().y();
+ //mousePoint is in the rect of the current Block
+ QVERIFY(positionY - topMargin <= y);
+ }
+}
+
QTEST_MAIN(tst_QTextDocumentLayout)
#include "tst_qtextdocumentlayout.moc"
diff --git a/tests/auto/gui/text/qtextformat/CMakeLists.txt b/tests/auto/gui/text/qtextformat/CMakeLists.txt
index cacd7fbd18..4dea90900e 100644
--- a/tests/auto/gui/text/qtextformat/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextformat/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextformat.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextformat Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextformat LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextformat
SOURCES
tst_qtextformat.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
index cf87cd41aa..d20a2f1ea5 100644
--- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
+++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -212,7 +187,7 @@ void tst_QTextFormat::resolveFont()
QTextCursor(&doc).insertText("Test", fmt);
QList<QTextFormat> formats = doc.allFormats();
- QCOMPARE(formats.count(), 3);
+ QCOMPARE(formats.size(), 3);
QCOMPARE(formats.at(2).type(), int(QTextFormat::CharFormat));
fmt = formats.at(2).toCharFormat();
@@ -337,8 +312,8 @@ void tst_QTextFormat::getSetTabs()
public:
Comparator(const QList<QTextOption::Tab> &tabs, const QList<QTextOption::Tab> &tabs2)
{
- QCOMPARE(tabs.count(), tabs2.count());
- for(int i=0; i < tabs.count(); i++) {
+ QCOMPARE(tabs.size(), tabs2.size());
+ for(int i=0; i < tabs.size(); i++) {
QTextOption::Tab t1 = tabs[i];
QTextOption::Tab t2 = tabs2[i];
QCOMPARE(t1.position, t2.position);
@@ -389,7 +364,7 @@ void tst_QTextFormat::testTabsUsed()
QCOMPARE(line.cursorToX(4), 100.);
QTextOption option = layout->textOption();
- QCOMPARE(option.tabs().count(), tabs.count());
+ QCOMPARE(option.tabs().size(), tabs.size());
}
@@ -673,16 +648,16 @@ void tst_QTextFormat::clearCollection()
charFormat2.setUnderlineStyle(QTextCharFormat::SingleUnderline);
int formatIndex2 = collection.indexForFormat(charFormat2);
QCOMPARE(formatIndex2, 1);
- QCOMPARE(collection.formats.count(), 2);
- QCOMPARE(collection.hashes.count(), 2);
+ QCOMPARE(collection.formats.size(), 2);
+ QCOMPARE(collection.hashes.size(), 2);
QCOMPARE(collection.defaultFont(), f);
collection.clear();
- QCOMPARE(collection.formats.count(), 0);
- QCOMPARE(collection.hashes.count(), 0);
+ QCOMPARE(collection.formats.size(), 0);
+ QCOMPARE(collection.hashes.size(), 0);
QCOMPARE(collection.indexForFormat(charFormat2), 0);
- QCOMPARE(collection.formats.count(), 1);
- QCOMPARE(collection.hashes.count(), 1);
+ QCOMPARE(collection.formats.size(), 1);
+ QCOMPARE(collection.hashes.size(), 1);
QCOMPARE(collection.defaultFont(), f); // kept, QTextDocument::clear or setPlainText should not reset the font set by setDefaultFont
}
@@ -704,7 +679,7 @@ void tst_QTextFormat::dataStreamCompatibility()
QVERIFY(properties.contains(QTextFormat::FontFamilies));
QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
- QVERIFY(!properties.contains(QTextFormat::FontFamily));
+ QVERIFY(!properties.contains(QTextFormat::OldFontFamily));
}
QByteArray memory;
@@ -735,7 +710,7 @@ void tst_QTextFormat::dataStreamCompatibility()
QVERIFY(properties.contains(QTextFormat::FontFamilies));
QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
- QVERIFY(!properties.contains(QTextFormat::FontFamily));
+ QVERIFY(!properties.contains(QTextFormat::OldFontFamily));
}
}
@@ -755,7 +730,7 @@ void tst_QTextFormat::dataStreamCompatibility()
QVERIFY(properties.contains(QTextFormat::FontFamilies));
QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
- QVERIFY(!properties.contains(QTextFormat::FontFamily));
+ QVERIFY(!properties.contains(QTextFormat::OldFontFamily));
}
}
@@ -788,7 +763,7 @@ void tst_QTextFormat::dataStreamCompatibility()
QVERIFY(properties.contains(QTextFormat::FontFamilies));
QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType));
QVERIFY(!properties.contains(QTextFormat::OldFontStretch));
- QVERIFY(!properties.contains(QTextFormat::FontFamily));
+ QVERIFY(!properties.contains(QTextFormat::OldFontFamily));
}
}
@@ -810,7 +785,7 @@ void tst_QTextFormat::dataStreamCompatibility()
QVERIFY(!properties.contains(QTextFormat::FontFamilies));
QVERIFY(properties.contains(QTextFormat::OldFontLetterSpacingType));
QVERIFY(properties.contains(QTextFormat::OldFontStretch));
- QVERIFY(properties.contains(QTextFormat::FontFamily));
+ QVERIFY(properties.contains(QTextFormat::OldFontFamily));
}
}
diff --git a/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt
new file mode 100644
index 0000000000..8d282b8f2c
--- /dev/null
+++ b/tests/auto/gui/text/qtextimagehandler/CMakeLists.txt
@@ -0,0 +1,29 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextimagehandler LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+list(APPEND test_data "data/image.png")
+list(APPEND test_data "data/image@2x.png")
+
+qt_internal_add_test(tst_qtextimagehandler
+ SOURCES
+ tst_qtextimagehandler.cpp
+ LIBRARIES
+ Qt::CorePrivate
+ Qt::Gui
+ Qt::GuiPrivate
+ TESTDATA
+ ${test_data}
+)
+
+qt_internal_add_resource(tst_qtextimagehandler "qtextimagehandler"
+ PREFIX
+ "/"
+ FILES
+ ${test_data}
+)
diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
index d5dde13770..5311aa6f2b 100644
--- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
+++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
- **
- ** Copyright (C) 2020 The Qt Company Ltd.
- ** Contact: https://www.qt.io/licensing/
- **
- ** This file is part of the test suite of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
- ** Commercial License Usage
- ** Licensees holding valid commercial Qt licenses may use this file in
- ** accordance with the commercial license agreement provided with the
- ** Software or, alternatively, in accordance with the terms contained in
- ** a written agreement between you and The Qt Company. For licensing terms
- ** and conditions see https://www.qt.io/terms-conditions. For further
- ** information use the contact form at https://www.qt.io/contact-us.
- **
- ** GNU General Public License Usage
- ** Alternatively, this file may be used under the terms of the GNU
- ** General Public License version 3 as published by the Free Software
- ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
- ** included in the packaging of this file. Please review the following
- ** information to ensure the GNU General Public License requirements will
- ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -42,6 +17,7 @@ private slots:
void init();
void cleanup();
void cleanupTestCase();
+ void loadAtNImages_data();
void loadAtNImages();
};
@@ -61,24 +37,40 @@ void tst_QTextImageHandler::cleanupTestCase()
{
}
+void tst_QTextImageHandler::loadAtNImages_data()
+{
+ QTest::addColumn<QString>("imageFile");
+
+ QTest::addRow("file") << QFINDTESTDATA("data/image.png");
+ QTest::addRow("file_url") << QUrl::fromLocalFile(QFINDTESTDATA("data/image.png")).toString();
+ QTest::addRow("resource") << ":/data/image.png";
+ QTest::addRow("qrc_url") << "qrc:/data/image.png";
+}
+
void tst_QTextImageHandler::loadAtNImages()
{
+ QFETCH(QString, imageFile);
+
QTextDocument doc;
QTextCursor c(&doc);
- c.insertHtml("<img src=\"data/image.png\">");
+ c.insertHtml("<img src=\"" + imageFile + "\">");
+ const auto formats = doc.allFormats();
+ const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){
+ return format.objectType() == QTextFormat::ImageObject;
+ });
+ QVERIFY(it != formats.end());
+ const QTextImageFormat format = (*it).toImageFormat();
QTextImageHandler handler;
- QTextImageFormat fmt;
- fmt.setName("data/image.png");
- for (int i = 1; i < 3; ++i) {
+ for (const auto &dpr : {1, 2}) {
QImage img(20, 20, QImage::Format_ARGB32_Premultiplied);
img.fill(Qt::white);
- img.setDevicePixelRatio(i);
+ img.setDevicePixelRatio(dpr);
QPainter p(&img);
- handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, fmt);
+ handler.drawObject(&p, QRect(0, 0, 20, 20), &doc, 0, format);
p.end();
QVERIFY(!img.isNull());
- const auto expectedColor = i == 1 ? Qt::red : Qt::green;
+ const auto expectedColor = dpr == 1 ? Qt::red : Qt::green;
QCOMPARE(img.pixelColor(0, 0), expectedColor);
}
}
diff --git a/tests/auto/gui/text/qtextlayout/CMakeLists.txt b/tests/auto/gui/text/qtextlayout/CMakeLists.txt
index 3fb5dea8b9..655c0985a0 100644
--- a/tests/auto/gui/text/qtextlayout/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextlayout/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextlayout.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextlayout Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextlayout LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextlayout
SOURCES
tst_qtextlayout.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index 32a0374fcd..209f5a56e2 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -1,31 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
/*
!!!!!! Warning !!!!!
@@ -149,7 +125,9 @@ private slots:
void tooManyDirectionalCharctersCrash_qtbug77819();
void softHyphens_data();
void softHyphens();
+ void min_maximumWidth_data();
void min_maximumWidth();
+ void negativeLineWidth();
private:
QFont testFont;
@@ -314,14 +292,14 @@ void tst_QTextLayout::simpleBoundingRect()
QString hello("hello world");
- const int width = hello.length() * testFont.pixelSize();
+ const int width = hello.size() * testFont.pixelSize();
QTextLayout layout(hello, testFont);
layout.beginLayout();
QTextLine line = layout.createLine();
line.setLineWidth(width);
- QCOMPARE(line.textLength(), hello.length());
+ QCOMPARE(line.textLength(), hello.size());
QCOMPARE(layout.boundingRect(), QRectF(0, 0, width, QFontMetrics(testFont).height()));
}
@@ -356,18 +334,18 @@ void tst_QTextLayout::threeLineBoundingRect()
QString thirdWord("world");
QString text(firstWord + wordBoundary1 + secondWord + wordBoundary2 + thirdWord);
- int firstLineWidth = firstWord.length() * testFont.pixelSize();
- int secondLineWidth = secondWord.length() * testFont.pixelSize();
- int thirdLineWidth = thirdWord.length() * testFont.pixelSize();
+ int firstLineWidth = firstWord.size() * testFont.pixelSize();
+ int secondLineWidth = secondWord.size() * testFont.pixelSize();
+ int thirdLineWidth = thirdWord.size() * testFont.pixelSize();
// Trailing spaces do not count to line width:
if (!wordBoundary1.isSpace())
firstLineWidth += testFont.pixelSize();
if (!wordBoundary2.isSpace())
secondLineWidth += testFont.pixelSize();
// But trailing spaces do count to line length:
- const int firstLineLength = firstWord.length() + 1;
- const int secondLineLength = secondWord.length() + 1;
- const int thirdLineLength = thirdWord.length();
+ const int firstLineLength = firstWord.size() + 1;
+ const int secondLineLength = secondWord.size() + 1;
+ const int thirdLineLength = thirdWord.size();
const int longestLine = qMax(firstLineWidth, qMax(secondLineWidth, thirdLineWidth));
@@ -411,7 +389,7 @@ void tst_QTextLayout::boundingRectWithLongLineAndNoWrap()
{
QString longString("thisisaverylongstringthatcannotbewrappedatallitjustgoesonandonlikeonebigword");
- const int width = longString.length() * testFont.pixelSize() / 20; // very small widthx
+ const int width = longString.size() * testFont.pixelSize() / 20; // very small widthx
QTextLayout layout(longString, testFont);
layout.beginLayout();
@@ -536,18 +514,24 @@ void tst_QTextLayout::noWrap()
void tst_QTextLayout::cursorToXForInlineObjects()
{
- QChar ch(QChar::ObjectReplacementCharacter);
- QString text(ch);
- QTextLayout layout(text, testFont);
- layout.beginLayout();
+ QString text = QStringLiteral("<html><body><img src=\"\" width=\"32\" height=\"32\" /></body></html>");
- QTextEngine *engine = layout.engine();
- const int item = engine->findItem(0);
- engine->layoutData->items[item].width = 32;
+ QTextDocument document;
+ document.setHtml(text);
+ QCOMPARE(document.blockCount(), 1);
- QTextLine line = layout.createLine();
- line.setLineWidth(0x10000);
+ // Trigger layout
+ {
+ QImage img(1, 1, QImage::Format_ARGB32_Premultiplied);
+ QPainter p(&img);
+ document.drawContents(&p);
+ }
+ QTextLayout *layout = document.firstBlock().layout();
+ QVERIFY(layout != nullptr);
+ QCOMPARE(layout->lineCount(), 1);
+
+ QTextLine line = layout->lineAt(0);
QCOMPARE(line.cursorToX(0), qreal(0));
QCOMPARE(line.cursorToX(1), qreal(32));
}
@@ -745,29 +729,29 @@ void tst_QTextLayout::cursorToXForBidiBoundaries_data()
QTest::addColumn<Qt::LayoutDirection>("textDirection");
QTest::addColumn<QString>("text");
QTest::addColumn<int>("cursorPosition");
- QTest::addColumn<int>("expectedX");
+ QTest::addColumn<int>("runsToInclude");
QTest::addRow("LTR, abcشزذabc, 0") << Qt::LeftToRight << "abcشزذabc"
<< 0 << 0;
QTest::addRow("RTL, abcشزذabc, 9") << Qt::RightToLeft << "abcشزذabc"
- << 9 << TESTFONT_SIZE * 3;
+ << 9 << 1;
QTest::addRow("LTR, abcشزذabc, 3") << Qt::LeftToRight << "abcشزذabc"
<< 0 << 0;
QTest::addRow("RTL, abcشزذabc, 6") << Qt::RightToLeft << "abcشزذabc"
- << 9 << TESTFONT_SIZE * 3;
+ << 9 << 1;
QTest::addRow("LTR, شزذabcشزذ, 0") << Qt::LeftToRight << "شزذabcشزذ"
- << 0 << TESTFONT_SIZE * 2;
+ << 0 << 1;
QTest::addRow("RTL, شزذabcشزذ, 9") << Qt::RightToLeft << "شزذabcشزذ"
<< 9 << 0;
QTest::addRow("LTR, شزذabcشزذ, 3") << Qt::LeftToRight << "شزذabcشزذ"
- << 3 << TESTFONT_SIZE * 2;
+ << 3 << 1;
QTest::addRow("RTL, شزذabcشزذ, 3") << Qt::RightToLeft << "شزذabcشزذ"
- << 3 << TESTFONT_SIZE * 5;
+ << 3 << 2;
QTest::addRow("LTR, شزذabcشزذ, 6") << Qt::LeftToRight << "شزذabcشزذ"
- << 6 << TESTFONT_SIZE * 5;
+ << 6 << 2;
QTest::addRow("RTL, شزذabcشزذ, 6") << Qt::RightToLeft << "شزذabcشزذ"
- << 6 << TESTFONT_SIZE * 2;
+ << 6 << 1;
}
void tst_QTextLayout::cursorToXForBidiBoundaries()
@@ -775,7 +759,7 @@ void tst_QTextLayout::cursorToXForBidiBoundaries()
QFETCH(Qt::LayoutDirection, textDirection);
QFETCH(QString, text);
QFETCH(int, cursorPosition);
- QFETCH(int, expectedX);
+ QFETCH(int, runsToInclude);
QTextOption option;
option.setTextDirection(textDirection);
@@ -784,12 +768,30 @@ void tst_QTextLayout::cursorToXForBidiBoundaries()
layout.setTextOption(option);
layout.beginLayout();
- QTextLine line = layout.createLine();
- line.setLineWidth(0x10000);
+ {
+ QTextLine line = layout.createLine();
+ line.setLineWidth(0x10000);
+ }
+ layout.endLayout();
- QCOMPARE(line.cursorToX(cursorPosition), expectedX);
+ QTextLine line = layout.lineAt(0);
+ QList<QGlyphRun> glyphRuns = line.glyphRuns(-1,
+ -1,
+ QTextLayout::RetrieveStringIndexes
+ | QTextLayout::RetrieveGlyphIndexes);
+ QVERIFY(runsToInclude <= glyphRuns.size());
+
+ std::sort(glyphRuns.begin(), glyphRuns.end(),
+ [](const QGlyphRun &first, const QGlyphRun &second) {
+ return first.stringIndexes().first() < second.stringIndexes().first();
+ });
+
+ qreal expectedX = 0.0;
+ for (int i = 0; i < runsToInclude; ++i) {
+ expectedX += glyphRuns.at(i).boundingRect().width();
+ }
- layout.endLayout();
+ QCOMPARE(line.cursorToX(cursorPosition), expectedX);
}
void tst_QTextLayout::horizontalAlignment_data()
@@ -1084,7 +1086,7 @@ void tst_QTextLayout::defaultWordSeparators_data()
QString separators(".,:;-<>[](){}=/+%&^*");
separators += QLatin1String("!?");
- for (int i = 0; i < separators.count(); ++i) {
+ for (int i = 0; i < separators.size(); ++i) {
QTest::newRow(QString::number(i).toLatin1().data())
<< QString::fromLatin1("abcd") + separators.at(i) + QString::fromLatin1("efgh")
<< 0 << 4;
@@ -1164,7 +1166,7 @@ void tst_QTextLayout::xToCursorAtEndOfLine()
QString text = "FirstLine SecondLine";
text.replace('\n', QChar::LineSeparator);
- const qreal firstLineWidth = QString("FirstLine").length() * testFont.pixelSize();
+ const qreal firstLineWidth = QString("FirstLine").size() * testFont.pixelSize();
QTextLayout layout(text, testFont);
layout.setCacheEnabled(true);
@@ -1307,7 +1309,7 @@ void tst_QTextLayout::integerOverflow()
QVERIFY(line.isValid());
line.setLineWidth(INT_MAX);
- QCOMPARE(line.textLength(), txt.length());
+ QCOMPARE(line.textLength(), txt.size());
QVERIFY(!layout.createLine().isValid());
@@ -1882,7 +1884,7 @@ void tst_QTextLayout::capitalization_allUpperCase()
QTextEngine *engine = layout.engine();
engine->itemize();
- QCOMPARE(engine->layoutData->items.count(), 1);
+ QCOMPARE(engine->layoutData->items.size(), 1);
QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase));
}
@@ -1902,7 +1904,7 @@ void tst_QTextLayout::capitalization_allUpperCase_newline()
QTextEngine *engine = layout.engine();
engine->itemize();
- QCOMPARE(engine->layoutData->items.count(), 3);
+ QCOMPARE(engine->layoutData->items.size(), 3);
QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase));
QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::LineOrParagraphSeparator));
QCOMPARE(engine->layoutData->items.at(2).analysis.flags, ushort(QScriptAnalysis::Uppercase));
@@ -1920,7 +1922,7 @@ void tst_QTextLayout::capitalization_allLowerCase()
QTextEngine *engine = layout.engine();
engine->itemize();
- QCOMPARE(engine->layoutData->items.count(), 1);
+ QCOMPARE(engine->layoutData->items.size(), 1);
QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Lowercase));
}
@@ -1936,7 +1938,7 @@ void tst_QTextLayout::capitalization_smallCaps()
QTextEngine *engine = layout.engine();
engine->itemize();
- QCOMPARE(engine->layoutData->items.count(), 2);
+ QCOMPARE(engine->layoutData->items.size(), 2);
QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::None));
QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::SmallCaps));
}
@@ -1953,7 +1955,7 @@ void tst_QTextLayout::capitalization_capitalize()
QTextEngine *engine = layout.engine();
engine->itemize();
- QCOMPARE(engine->layoutData->items.count(), 5);
+ QCOMPARE(engine->layoutData->items.size(), 5);
QCOMPARE(engine->layoutData->items.at(0).analysis.flags, ushort(QScriptAnalysis::Uppercase));
QCOMPARE(engine->layoutData->items.at(1).analysis.flags, ushort(QScriptAnalysis::None));
QCOMPARE(engine->layoutData->items.at(2).analysis.flags, ushort(QScriptAnalysis::Tab));
@@ -2064,7 +2066,7 @@ void tst_QTextLayout::columnWrapWithTabs()
textLayout.beginLayout();
QTextLine line = textLayout.createLine();
line.setNumColumns(30);
- QCOMPARE(line.textLength(), text.length());
+ QCOMPARE(line.textLength(), text.size());
textLayout.endLayout();
}
@@ -2075,7 +2077,7 @@ void tst_QTextLayout::columnWrapWithTabs()
textLayout.beginLayout();
QTextLine line = textLayout.createLine();
line.setNumColumns(30);
- QVERIFY(line.textLength() < text.length());
+ QVERIFY(line.textLength() < text.size());
textLayout.endLayout();
}
@@ -2479,7 +2481,7 @@ void tst_QTextLayout::nbspWithFormat()
layout.setText(s1 + s2 + nbsp + s3);
QTextLayout::FormatRange formatRange;
- formatRange.start = s1.length() + s2.length();
+ formatRange.start = s1.size() + s2.size();
formatRange.length = 1;
formatRange.format.setFontUnderline(true);
@@ -2496,9 +2498,9 @@ void tst_QTextLayout::nbspWithFormat()
QCOMPARE(layout.lineCount(), 2);
QCOMPARE(layout.lineAt(0).textStart(), 0);
- QCOMPARE(layout.lineAt(0).textLength(), s1.length());
- QCOMPARE(layout.lineAt(1).textStart(), s1.length());
- QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length());
+ QCOMPARE(layout.lineAt(0).textLength(), s1.size());
+ QCOMPARE(layout.lineAt(1).textStart(), s1.size());
+ QCOMPARE(layout.lineAt(1).textLength(), s2.size() + 1 + s3.size());
}
void tst_QTextLayout::koreanWordWrap()
@@ -2672,13 +2674,35 @@ void tst_QTextLayout::softHyphens()
}
}
+void tst_QTextLayout::min_maximumWidth_data()
+{
+ QTest::addColumn<QString>("text");
+
+ QTest::newRow("long string") << QStringLiteral("lmong_long_crazy_87235982735_23857239682376923876923876-fuwhfhfw-names-AAAA-deeaois2019-03-03.and.more");
+ QTest::newRow("QTBUG-106947") << QStringLiteral("text text");
+ QTest::newRow("spaces") << QStringLiteral(" text text ");
+ QTest::newRow("QTBUG-104986") << QStringLiteral("text\ntext\ntext");
+ QTest::newRow("spaces + line breaks") << QStringLiteral(" \n text\n \ntext \n ");
+}
+
void tst_QTextLayout::min_maximumWidth()
{
- QString longString("lmong_long_crazy_87235982735_23857239682376923876923876-fuwhfhfw-names-AAAA-deeaois2019-03-03.and.more");
- QTextLayout layout(longString, testFont);
+ QFETCH(QString, text);
+ text.replace('\n', QChar::LineSeparator);
+
+ QTextLayout layout(text, testFont);
+ layout.setCacheEnabled(true);
+
+ QTextOption opt;
+ opt.setWrapMode(QTextOption::NoWrap);
+ layout.setTextOption(opt);
+ layout.beginLayout();
+ while (layout.createLine().isValid()) { }
+ layout.endLayout();
+
+ const qreal nonWrappedMaxWidth = layout.maximumWidth();
for (int wrapMode = QTextOption::NoWrap; wrapMode <= QTextOption::WrapAtWordBoundaryOrAnywhere; ++wrapMode) {
- QTextOption opt;
opt.setWrapMode((QTextOption::WrapMode)wrapMode);
layout.setTextOption(opt);
layout.beginLayout();
@@ -2687,6 +2711,9 @@ void tst_QTextLayout::min_maximumWidth()
const qreal minWidth = layout.minimumWidth();
const qreal maxWidth = layout.maximumWidth();
+ QCOMPARE_LE(minWidth, maxWidth);
+ QCOMPARE_LE(maxWidth, nonWrappedMaxWidth); // maxWidth for wrapped text shouldn't exceed maxWidth for the text without wrapping.
+
// Try the layout from slightly wider than the widest (maxWidth)
// and narrow it down to slighly narrower than minWidth
// layout.maximumWidth() should return the same regardless
@@ -2708,5 +2735,28 @@ void tst_QTextLayout::min_maximumWidth()
}
}
+void tst_QTextLayout::negativeLineWidth()
+{
+ {
+ QTextLayout layout;
+ layout.setText("Foo bar");
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setLineWidth(-1);
+ QVERIFY(line.textLength() > 0);
+ layout.endLayout();
+ }
+
+ {
+ QTextLayout layout;
+ layout.setText("Foo bar");
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setNumColumns(2, -1);
+ QVERIFY(line.textLength() > 0);
+ layout.endLayout();
+ }
+}
+
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"
diff --git a/tests/auto/gui/text/qtextlist/CMakeLists.txt b/tests/auto/gui/text/qtextlist/CMakeLists.txt
index 2f325d5e17..5764df3e99 100644
--- a/tests/auto/gui/text/qtextlist/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextlist/CMakeLists.txt
@@ -1,14 +1,21 @@
-# Generated from qtextlist.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextlist Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextlist LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextlist
SOURCES
../qtextdocument/common.h
tst_qtextlist.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
index b160d41a05..28eae93f6a 100644
--- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
+++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -61,6 +36,8 @@ private slots:
void blockUpdate();
void numbering_data();
void numbering();
+ void start_data();
+ void start();
private:
QTextDocument *doc;
@@ -425,5 +402,61 @@ void tst_QTextList::numbering()
QCOMPARE(cursor.currentList()->itemText(cursor.block()), result);
}
+void tst_QTextList::start_data()
+{
+ QTest::addColumn<int>("format");
+ QTest::addColumn<int>("start");
+ QTest::addColumn<QStringList>("expectedItemTexts");
+
+ QTest::newRow("-1.") << int(QTextListFormat::ListDecimal) << -1
+ << QStringList{ "-1.", "0.", "1." };
+ QTest::newRow("0.") << int(QTextListFormat::ListDecimal) << 0
+ << QStringList{ "0.", "1.", "2." };
+ QTest::newRow("1.") << int(QTextListFormat::ListDecimal) << 1
+ << QStringList{ "1.", "2.", "3." };
+
+ QTest::newRow("A. -1") << int(QTextListFormat::ListUpperAlpha) << -1
+ << QStringList{ "-1.", "0.", "A." };
+ QTest::newRow("A. 0.") << int(QTextListFormat::ListUpperAlpha) << 0
+ << QStringList{ "0.", "A.", "B." };
+ QTest::newRow("a. -1") << int(QTextListFormat::ListLowerAlpha) << -1
+ << QStringList{ "-1.", "0.", "a." };
+ QTest::newRow("a. 0.") << int(QTextListFormat::ListLowerAlpha) << 0
+ << QStringList{ "0.", "a.", "b." };
+ QTest::newRow("d. 4.") << int(QTextListFormat::ListLowerAlpha) << 4
+ << QStringList{ "d.", "e.", "f." };
+
+ QTest::newRow("I. -1") << int(QTextListFormat::ListUpperRoman) << -1
+ << QStringList{ "-1.", "0.", "I." };
+ QTest::newRow("I. 0.") << int(QTextListFormat::ListUpperRoman) << 0
+ << QStringList{ "0.", "I.", "II." };
+ QTest::newRow("i. -1") << int(QTextListFormat::ListLowerRoman) << -1
+ << QStringList{ "-1.", "0.", "i." };
+ QTest::newRow("i. 0.") << int(QTextListFormat::ListLowerRoman) << 0
+ << QStringList{ "0.", "i.", "ii." };
+}
+
+void tst_QTextList::start()
+{
+ QFETCH(int, format);
+ QFETCH(int, start);
+ QFETCH(QStringList, expectedItemTexts);
+
+ QTextListFormat fmt;
+ fmt.setStyle(QTextListFormat::Style(format));
+ fmt.setStart(start);
+ QTextList *list = cursor.createList(fmt);
+ QVERIFY(list);
+
+ while (list->count() < int(expectedItemTexts.size()))
+ cursor.insertBlock();
+
+ QCOMPARE(list->count(), expectedItemTexts.size());
+
+ for (int i = 0; i < list->count(); ++i)
+ QCOMPARE(cursor.currentList()->itemText(cursor.currentList()->item(i)),
+ expectedItemTexts[i]);
+}
+
QTEST_MAIN(tst_QTextList)
#include "tst_qtextlist.moc"
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST b/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST
deleted file mode 100644
index ee09d02090..0000000000
--- a/tests/auto/gui/text/qtextmarkdownimporter/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-# QTBUG-89819
-[lists]
-ci b2qt 32bit
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt
index 3f23f03c3d..937dd5bd80 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt
@@ -1,19 +1,26 @@
-# Generated from qtextmarkdownimporter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextmarkdownimporter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextmarkdownimporter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
-list(APPEND test_data "data/thematicBreaks.md")
-list(APPEND test_data "data/headingBulletsContinuations.md")
-list(APPEND test_data "data/fuzz20450.md")
-list(APPEND test_data "data/fuzz20580.md")
+file(GLOB_RECURSE test_data
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ data/*
+)
qt_internal_add_test(tst_qtextmarkdownimporter
SOURCES
tst_qtextmarkdownimporter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md b/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md
new file mode 100644
index 0000000000..3d89536376
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownimporter/data/paragraphs.md
@@ -0,0 +1,9 @@
+This paragraph has enough text to auto-wrap when QTextMarkdownWriter writes it
+to a markdown file. The wrapping should be around 80 columns.
+
+This paragrah has been broken up into shorter lines.
+Each line break is created
+by hitting shift-enter in QTextEdit.
+But it's treated as one QTextBlock.
+
+This paragraph also has short lines.
Each ends with a Unicode LineSeparator.

diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md
index 7a0d5388ad..e784879326 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md
+++ b/tests/auto/gui/text/qtextmarkdownimporter/data/thematicBreaks.md
@@ -11,6 +11,7 @@ stars
stars with tabs between
***
stars with whitespace after
+
---
hyphens with whitespace after
_____
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md
new file mode 100644
index 0000000000..1eff4db37f
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml-only.md
@@ -0,0 +1,6 @@
+---
+name: "Space"
+title: "Outer space"
+keywords:
+ - astronomy
+---
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md
new file mode 100644
index 0000000000..41303a0187
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownimporter/data/yaml.md
@@ -0,0 +1,11 @@
+---
+name: "Venus"
+discoverer: "Galileo Galilei"
+title: "A description of the planet Venus"
+keywords:
+ - planets
+ - solar system
+ - astronomy
+---
+*Venus* is the second planet from the Sun, orbiting it every 224.7 Earth days.
+
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 9b376c41f4..d9fe000253 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QBuffer>
@@ -54,6 +29,7 @@ class tst_QTextMarkdownImporter : public QObject
Q_OBJECT
private slots:
+ void paragraphs();
void headingBulletsContinuations();
void thematicBreaks();
void lists_data();
@@ -66,6 +42,15 @@ private slots:
void fragmentsAndProperties();
void pathological_data();
void pathological();
+ void fencedCodeBlocks_data();
+ void fencedCodeBlocks();
+ void frontMatter_data();
+ void frontMatter();
+ void toRawText_data();
+ void toRawText();
+
+private:
+ bool isMainFontFixed();
public:
enum CharFormat {
@@ -77,12 +62,62 @@ public:
Mono = 0x10,
Link = 0x20
};
+ Q_ENUM(CharFormat)
Q_DECLARE_FLAGS(CharFormats, CharFormat)
};
Q_DECLARE_METATYPE(tst_QTextMarkdownImporter::CharFormats)
Q_DECLARE_OPERATORS_FOR_FLAGS(tst_QTextMarkdownImporter::CharFormats)
+bool tst_QTextMarkdownImporter::isMainFontFixed()
+{
+ bool ret = QFontInfo(QGuiApplication::font()).fixedPitch();
+ if (ret) {
+ qCWarning(lcTests) << "QFontDatabase::GeneralFont is monospaced: markdown writing is likely to use too many backticks";
+ qCWarning(lcTests) << "system fonts: fixed" << QFontDatabase::systemFont(QFontDatabase::FixedFont)
+ << "fixed?" << QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).fixedPitch()
+ << "general" << QFontDatabase::systemFont(QFontDatabase::GeneralFont);
+ }
+ return ret;
+}
+
+void tst_QTextMarkdownImporter::paragraphs()
+{
+ QFile f(QFINDTESTDATA("data/paragraphs.md"));
+ QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text));
+ QString md = QString::fromUtf8(f.readAll());
+ f.close();
+
+ int lineSeparatorCount = 0;
+ QTextDocument doc;
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md);
+ QTextFrame::iterator iterator = doc.rootFrame()->begin();
+ int i = 0;
+ while (!iterator.atEnd()) {
+ QTextBlock block = iterator.currentBlock();
+ int lineSeparatorPos = block.text().indexOf(QChar::LineSeparator);
+ qCDebug(lcTests) << i << block.text();
+ while (lineSeparatorPos > 0) {
+ ++lineSeparatorCount;
+ qCDebug(lcTests) << " LineSeparator @" << lineSeparatorPos;
+ lineSeparatorPos = block.text().indexOf(QChar::LineSeparator, lineSeparatorPos + 1);
+ }
+ ++iterator;
+ ++i;
+ }
+ QCOMPARE(doc.blockCount(), 3);
+ QCOMPARE(lineSeparatorCount, 2);
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/paragraphs.html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+}
+
void tst_QTextMarkdownImporter::headingBulletsContinuations()
{
const QStringList expectedBlocks = QStringList() <<
@@ -108,7 +143,7 @@ void tst_QTextMarkdownImporter::headingBulletsContinuations()
f.close();
QTextDocument doc;
- QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md);
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md);
QTextFrame::iterator iterator = doc.rootFrame()->begin();
QTextFrame *currentFrame = iterator.currentFrame();
QStringList::const_iterator expectedIt = expectedBlocks.constBegin();
@@ -156,7 +191,7 @@ void tst_QTextMarkdownImporter::thematicBreaks()
f.close();
QTextDocument doc;
- QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, md);
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md);
QTextFrame::iterator iterator = doc.rootFrame()->begin();
QTextFrame *currentFrame = iterator.currentFrame();
int i = 0;
@@ -189,61 +224,123 @@ void tst_QTextMarkdownImporter::thematicBreaks()
void tst_QTextMarkdownImporter::lists_data()
{
QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("skipToCheckStart");
+ QTest::addColumn<int>("expectedListStart");
QTest::addColumn<int>("expectedItemCount");
QTest::addColumn<bool>("expectedEmptyItems");
QTest::addColumn<QString>("rewrite");
// Some of these cases show odd behavior, which is subject to change
// as the importer and the writer are tweaked to fix bugs over time.
- QTest::newRow("dot newline") << ".\n" << 0 << true << ".\n\n";
- QTest::newRow("number dot newline") << "1.\n" << 1 << true << "1. \n";
- QTest::newRow("star newline") << "*\n" << 1 << true << "* \n";
- QTest::newRow("hyphen newline") << "-\n" << 1 << true << "- \n";
- QTest::newRow("hyphen space newline") << "- \n" << 1 << true << "- \n";
- QTest::newRow("hyphen space letter newline") << "- a\n" << 1 << false << "- a\n";
+ QTest::newRow("dot newline") << ".\n" << 0 << 1 << 0 << true << ".\n\n";
+ QTest::newRow("number dot newline") << "1.\n" << 0 << 1 << 1 << true << "1. \n";
+ QTest::newRow("number offset start") << "2. text\n" << 0 << 2 << 1 << false << "2. text\n";
+ QTest::newRow("second list offset start")
+ << "1. text\n\nintervening paragraph\n\n4. second list item"
+ << 2 << 4 << 2 << false
+ << "1. text\n\nintervening paragraph\n\n4. second list item\n";
+ QTest::newRow("list continuation offset start")
+ << "3. text\n\n next paragraph in item 1\n10. second list item"
+ << 2 << 3 << 2 << false
+ << "3. text\n\n next paragraph in item 1\n\n4. second list item\n";
+ QTest::newRow("nested list offset start")
+ << "1. text\n\n 0. indented list item\n\n4. second item in first list"
+ << 1 << 0 << 3 << false
+ << "1. text\n 0. indented list item\n2. second item in first list\n";
+ QTest::newRow("offset start after nested list")
+ << "1. text\n\n 0. indented list item\n\n4. second item in first list"
+ << 2 << 1 << 3 << false
+ << "1. text\n 0. indented list item\n2. second item in first list\n";
+ QTest::newRow("star newline") << "*\n" << 0 << 1 << 1 << true << "* \n";
+ QTest::newRow("hyphen newline") << "-\n" << 0 << 1 << 1 << true << "- \n";
+ QTest::newRow("hyphen space newline") << "- \n" << 0 << 1 << 1 << true << "- \n";
+ QTest::newRow("hyphen space letter newline") << "- a\n" << 0 << 1 << 1 << false << "- a\n";
QTest::newRow("hyphen nbsp newline") <<
- QString::fromUtf8("-\u00A0\n") << 0 << true << "-\u00A0\n\n";
- QTest::newRow("nested empty lists") << "*\n *\n *\n" << 1 << true << " * \n";
- QTest::newRow("list nested in empty list") << "-\n * a\n" << 2 << false << "- \n * a\n";
+ QString::fromUtf8("-\u00A0\n") << 0 << 1 << 0 << true << "\\-\u00A0\n\n";
+ QTest::newRow("nested empty lists") << "*\n *\n *\n" << 0 << 1 << 1 << true << " * \n";
+ QTest::newRow("list nested in empty list") << "-\n * a\n" << 0 << 1 << 2 << false << "- \n * a\n";
QTest::newRow("lists nested in empty lists")
- << "-\n * a\n * b\n- c\n *\n + d\n" << 5 << false
+ << "-\n * a\n * b\n- c\n *\n + d\n" << 0 << 1 << 5 << false
<< "- \n * a\n * b\n- c *\n + d\n";
QTest::newRow("numeric lists nested in empty lists")
- << "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 4 << false
+ << "- \n 1. a\n 2. b\n- c\n 1.\n + d\n" << 0 << 1 << 4 << false
<< "- \n 1. a\n 2. b\n- c 1. + d\n";
+ QTest::newRow("styled spans in list items")
+ << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n"
+ << 0 << 1 << 5 << false
+ << "1. normal text\n2. **bold** text\n3. `code` in the item\n4. *italic* text\n5. _underlined_ text\n";
}
void tst_QTextMarkdownImporter::lists()
{
QFETCH(QString, input);
+ QFETCH(int, skipToCheckStart);
+ QFETCH(int, expectedListStart);
QFETCH(int, expectedItemCount);
QFETCH(bool, expectedEmptyItems);
QFETCH(QString, rewrite);
QTextDocument doc;
doc.setMarkdown(input); // QTBUG-78870 : don't crash
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+ qCDebug(lcTests) << " original:" << input;
+ qCDebug(lcTests) << "rewritten:" << doc.toMarkdown();
+
QTextFrame::iterator iterator = doc.rootFrame()->begin();
QTextFrame *currentFrame = iterator.currentFrame();
int i = 0;
int itemCount = 0;
bool emptyItems = true;
+ QString firstItemFontFamily;
while (!iterator.atEnd()) {
// There are no child frames
QCOMPARE(iterator.currentFrame(), currentFrame);
// Check whether the block is text or a horizontal rule
QTextBlock block = iterator.currentBlock();
+ QTextListFormat listFmt;
if (block.textList()) {
++itemCount;
if (!block.text().isEmpty())
emptyItems = false;
+ listFmt = block.textList()->format();
}
qCDebug(lcTests, "%d %s%s", i,
(block.textList() ? "<li>" : "<p>"), qPrintable(block.text()));
+ QTextCharFormat listItemFmt = block.charFormat();
+ QFont listItemFont = listItemFmt.font();
+ // QTextDocumentLayoutPrivate::drawListItem() uses listItemFont to render numbers in an ordered list.
+ // We want that to be consistent, regardless whether the list item's text begins with a styled span.
+ if (firstItemFontFamily.isEmpty())
+ firstItemFontFamily = listItemFont.family();
+ else
+ QCOMPARE(listItemFont.family(), firstItemFontFamily);
+ QCOMPARE(listItemFont.bold(), false);
+ QCOMPARE(listItemFont.italic(), false);
+ QCOMPARE(listItemFont.underline(), false);
+ QCOMPARE(listItemFont.fixedPitch(), false);
+ QCOMPARE(listItemFmt.fontItalic(), false);
+ QCOMPARE(listItemFmt.fontUnderline(), false);
+ QCOMPARE(listItemFmt.fontFixedPitch(), false);
+ if (i == skipToCheckStart) {
+ qCDebug(lcTests) << "skipped to list item" << i << block.text()
+ << "start" << listFmt.start() << "expected" << expectedListStart;
+ QCOMPARE(listFmt.start(), expectedListStart);
+ }
++iterator;
++i;
}
QCOMPARE(itemCount, expectedItemCount);
QCOMPARE(emptyItems, expectedEmptyItems);
+ if (doc.toMarkdown() != rewrite && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
QCOMPARE(doc.toMarkdown(), rewrite);
}
@@ -335,13 +432,15 @@ void tst_QTextMarkdownImporter::nestedSpans()
<< "underlined" << fmt.fontUnderline()
<< "strikeout" << fmt.fontStrikeOut() << "anchor" << fmt.isAnchor()
<< "monospace" << QFontInfo(fmt.font()).fixedPitch() // depends on installed fonts (QTBUG-75649)
- << fmt.fontFixedPitch() // returns false even when font family is "monospace"
- << fmt.hasProperty(QTextFormat::FontFixedPitch); // works
+ << fmt.fontFixedPitch()
+ << fmt.hasProperty(QTextFormat::FontFixedPitch)
+ << "expected" << expectedFormat;
QCOMPARE(fmt.fontWeight() > QFont::Normal, expectedFormat.testFlag(Bold));
QCOMPARE(fmt.fontItalic(), expectedFormat.testFlag(Italic));
QCOMPARE(fmt.fontUnderline(), expectedFormat.testFlag(Underlined));
QCOMPARE(fmt.fontStrikeOut(), expectedFormat.testFlag(Strikeout));
QCOMPARE(fmt.isAnchor(), expectedFormat.testFlag(Link));
+ QCOMPARE(fmt.fontFixedPitch(), expectedFormat.testFlag(Mono));
QCOMPARE(fmt.hasProperty(QTextFormat::FontFixedPitch), expectedFormat.testFlag(Mono));
++iterator;
}
@@ -354,7 +453,7 @@ void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning_data()
QTest::newRow("Text block") << QString("Markdown text") << 1;
QTest::newRow("Headline") << QString("Markdown text\n============") << 1;
- QTest::newRow("Code block") << QString(" Markdown text") << 2;
+ QTest::newRow("Code block") << QString(" Markdown text") << 1;
QTest::newRow("Unordered list") << QString("* Markdown text") << 1;
QTest::newRow("Ordered list") << QString("1. Markdown text") << 1;
QTest::newRow("Blockquote") << QString("> Markdown text") << 1;
@@ -366,7 +465,7 @@ void tst_QTextMarkdownImporter::avoidBlankLineAtBeginning() // QTBUG-81060
QFETCH(int, expectedNumberOfParagraphs);
QTextDocument doc;
- QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, input);
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(input);
QTextFrame::iterator iterator = doc.rootFrame()->begin();
int i = 0;
while (!iterator.atEnd()) {
@@ -411,7 +510,7 @@ void tst_QTextMarkdownImporter::fragmentsAndProperties()
QFETCH(int, expectedNumberOfFragments);
QTextDocument doc;
- QTextMarkdownImporter(QTextMarkdownImporter::DialectGitHub).import(&doc, input);
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(input);
#ifdef DEBUG_WRITE_HTML
{
QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
@@ -466,5 +565,211 @@ void tst_QTextMarkdownImporter::pathological() // avoid crashing on crazy input
QTextDocument().setMarkdown(f.readAll());
}
+void tst_QTextMarkdownImporter::fencedCodeBlocks_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("expectedCodeBlockCount");
+ QTest::addColumn<int>("expectedPlainBlockCount");
+ QTest::addColumn<QString>("expectedLanguage");
+ QTest::addColumn<QString>("expectedFenceChar");
+ QTest::addColumn<QString>("rewrite");
+
+ QTest::newRow("backtick fence with language")
+ << "```pseudocode\nprint('hello world\\n')\n```\n"
+ << 1 << 0 << "pseudocode" << "`"
+ << "```pseudocode\nprint('hello world\\n')\n```\n\n";
+ QTest::newRow("backtick fence with punctuated language")
+ << "```html+js\n<html><head><script>function hi() { console.log('\\\"hello world') }</script></head>blah</html>\n```\n"
+ << 1 << 0 << "html+js" << "`"
+ << "```html+js\n<html><head><script>function hi() { console.log('\\\"hello world') }</script></head>blah</html>\n```\n\n";
+ QTest::newRow("tilde fence with language")
+ << "~~~pseudocode\nprint('hello world\\n')\n~~~\n"
+ << 1 << 0 << "pseudocode" << "~"
+ << "~~~pseudocode\nprint('hello world\\n')\n~~~\n\n";
+ QTest::newRow("embedded backticks")
+ << "```\nnone `one` ``two``\n```\nplain\n```\n```three``` ````four````\n```\nplain\n"
+ << 2 << 2 << QString() << "`"
+ << "```\nnone `one` ``two``\n```\nplain\n\n```\n```three``` ````four````\n```\nplain\n\n";
+}
+
+void tst_QTextMarkdownImporter::fencedCodeBlocks()
+{
+ QFETCH(QString, input);
+ QFETCH(int, expectedCodeBlockCount);
+ QFETCH(int, expectedPlainBlockCount);
+ QFETCH(QString, expectedLanguage);
+ QFETCH(QString, expectedFenceChar);
+ QFETCH(QString, rewrite);
+
+ QTextDocument doc;
+ doc.setMarkdown(input);
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+
+ QTextFrame::iterator iterator = doc.rootFrame()->begin();
+ QTextFrame *currentFrame = iterator.currentFrame();
+ int codeBlockCount = 0;
+ int plainBlockCount = 0;
+ while (!iterator.atEnd()) {
+ // There are no child frames
+ QCOMPARE(iterator.currentFrame(), currentFrame);
+ // Check whether the block is code or plain
+ QTextBlock block = iterator.currentBlock();
+ const bool codeBlock = block.blockFormat().hasProperty(QTextFormat::BlockCodeFence);
+ QCOMPARE(block.blockFormat().nonBreakableLines(), codeBlock);
+ QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeLanguage), codeBlock ? expectedLanguage : QString());
+ if (codeBlock) {
+ QCOMPARE(block.blockFormat().stringProperty(QTextFormat::BlockCodeFence), expectedFenceChar);
+ ++codeBlockCount;
+ } else {
+ ++plainBlockCount;
+ }
+ qCDebug(lcTests) << (codeBlock ? "code" : "text") << block.text() << block.charFormat().fontFamilies();
+ ++iterator;
+ }
+ QCOMPARE(codeBlockCount, expectedCodeBlockCount);
+ QCOMPARE(plainBlockCount, expectedPlainBlockCount);
+ if (doc.toMarkdown() != rewrite && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(doc.toMarkdown(), rewrite);
+}
+
+void tst_QTextMarkdownImporter::frontMatter_data()
+{
+ QTest::addColumn<QString>("inputFile");
+ QTest::addColumn<int>("expectedBlockCount");
+
+ QTest::newRow("yaml + markdown") << QFINDTESTDATA("data/yaml.md") << 1;
+ QTest::newRow("yaml only") << QFINDTESTDATA("data/yaml-only.md") << 0;
+}
+
+void tst_QTextMarkdownImporter::frontMatter()
+{
+ QFETCH(QString, inputFile);
+ QFETCH(int, expectedBlockCount);
+
+ QFile f(inputFile);
+ QVERIFY(f.open(QFile::ReadOnly | QIODevice::Text));
+ QString md = QString::fromUtf8(f.readAll());
+ f.close();
+ const int yamlBegin = md.indexOf("name:");
+ const int yamlEnd = md.indexOf("---", yamlBegin);
+ const QString yaml = md.sliced(yamlBegin, yamlEnd - yamlBegin);
+
+ QTextDocument doc;
+ QTextMarkdownImporter(&doc, QTextMarkdownImporter::DialectGitHub).import(md);
+ int blockCount = 0;
+ for (QTextFrame::iterator iterator = doc.rootFrame()->begin(); !iterator.atEnd(); ++iterator) {
+ // Check whether the block is text or a horizontal rule
+ if (!iterator.currentBlock().text().isEmpty())
+ ++blockCount;
+ }
+ QCOMPARE(blockCount, expectedBlockCount); // yaml is not part of the markdown text
+ QCOMPARE(doc.metaInformation(QTextDocument::FrontMatter), yaml); // without fences
+}
+
+void tst_QTextMarkdownImporter::toRawText_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expectedRawText");
+
+ // tests to verify that fixing QTBUG-122083 is safe
+ // https://spec.commonmark.org/0.31.2/#example-12
+ QTest::newRow("punctuation backslash escapes") <<
+ R"(\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~)" <<
+ R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)";
+ // https://spec.commonmark.org/0.31.2/#example-13
+ QTest::newRow("literal backslashes") <<
+ QString(uR"(\→\A\a\ \3\φ\«)") <<
+ QString(uR"(\→\A\a\ \3\φ\«)");
+ // https://spec.commonmark.org/0.31.2/#example-14
+ QTest::newRow("escape to avoid em") <<
+ R"(\*not emphasized*)" <<
+ R"(*not emphasized*)";
+ QTest::newRow("escape to avoid html") <<
+ R"(\<br/> not a tag)" <<
+ R"(<br/> not a tag)";
+ QTest::newRow("escape to avoid link") <<
+ R"(\[not a link](/foo))" <<
+ R"([not a link](/foo))";
+ QTest::newRow("escape to avoid mono") <<
+ R"(\`not code`)" <<
+ R"(`not code`)";
+ QTest::newRow("escape to avoid num list") <<
+ R"(1\. not a list)" <<
+ R"(1. not a list)";
+ QTest::newRow("escape to avoid list") <<
+ R"(\* not a list)" <<
+ R"(* not a list)";
+ QTest::newRow("escape to avoid heading") <<
+ R"(\# not a heading)" <<
+ R"(# not a heading)";
+ QTest::newRow("escape to avoid reflink") <<
+ R"(\[foo]: /url "not a reference")" <<
+ R"([foo]: /url "not a reference")";
+ QTest::newRow("escape to avoid entity") <<
+ R"(\&ouml; not a character entity)" <<
+ R"(&ouml; not a character entity)";
+ // https://spec.commonmark.org/0.31.2/#example-15
+ QTest::newRow("escape backslash only") <<
+ R"(\\*emphasis*)" <<
+ R"(\emphasis)";
+ // https://spec.commonmark.org/0.31.2/#example-16
+ QTest::newRow("backslash line break") <<
+ "foo\\\nbar" <<
+ "foo\u2029bar";
+ // https://spec.commonmark.org/0.31.2/#example-17
+ QTest::newRow("backslash in mono span") <<
+ R"(`` \[\` ``)" <<
+ R"(\[\`)";
+ // https://spec.commonmark.org/0.31.2/#example-18
+ QTest::newRow("backslash in indented code") <<
+ R"( \[\])" <<
+ R"(\[\])";
+ // https://spec.commonmark.org/0.31.2/#example-19
+ QTest::newRow("backslash in fenced code") <<
+ "~~~\n\\[\\]\n~~~" <<
+ R"(\[\])";
+ // https://spec.commonmark.org/0.31.2/#example-20
+ QTest::newRow("backslash in autolink") <<
+ R"(<https://example.com?find=\*>)" <<
+ R"(https://example.com?find=\*)";
+ // https://spec.commonmark.org/0.31.2/#example-21
+ QTest::newRow("backslash in autolink") <<
+ "<a href=\"/bar\\/)\"" <<
+ "<a href=\"/bar/)\"";
+ // https://spec.commonmark.org/0.31.2/#example-22
+ QTest::newRow("escapes in link") <<
+ R"([foo](/bar\* "ti\*tle"))" <<
+ R"(foo)";
+ // https://spec.commonmark.org/0.31.2/#example-24
+ QTest::newRow("backslash in code lang") <<
+ "```\nfoo\\+bar\nfoo\n```" <<
+ "foo\\+bar\u2029foo";
+ // end of tests to verify that fixing QTBUG-122083 is safe
+ // (it's ok to add unrelated markdown-to-rawtext cases later)
+}
+
+void tst_QTextMarkdownImporter::toRawText()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, expectedRawText);
+
+ QTextDocument doc;
+ doc.setMarkdown(input);
+
+ // These are testing md4c more than Qt, so any change may be an md4c bug, or a fix
+ QCOMPARE(doc.toRawText(), expectedRawText);
+ if (doc.blockCount() == 1)
+ QCOMPARE(doc.firstBlock().text(), expectedRawText);
+}
+
QTEST_MAIN(tst_QTextMarkdownImporter)
#include "tst_qtextmarkdownimporter.moc"
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST b/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST
deleted file mode 100644
index 12cb21f40a..0000000000
--- a/tests/auto/gui/text/qtextmarkdownwriter/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-# QTBUG-89819
-ci b2qt 32bit
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt
index 884195345c..0cdf1d9225 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt
@@ -1,17 +1,26 @@
-# Generated from qtextmarkdownwriter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextmarkdownwriter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextmarkdownwriter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
-list(APPEND test_data "data/example.md")
-list(APPEND test_data "data/blockquotes.md")
+file(GLOB_RECURSE test_data
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ data/*
+)
qt_internal_add_test(tst_qtextmarkdownwriter
SOURCES
tst_qtextmarkdownwriter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md
index 702ccef134..8e605ef7e6 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotes.md
@@ -8,18 +8,17 @@ MacFarlane writes:
> What distinguishes Markdown from many other lightweight markup syntaxes,
> which are often easier to write, is its readability. As Gruber writes:
-
+>
> > The overriding design goal for Markdown's formatting syntax is to make it
> > as readable as possible. The idea is that a Markdown-formatted document should
> > be publishable as-is, as plain text, without looking like it's been marked up
> > with tags or formatting instructions. (
-> > [http://daringfireball.net/projects/markdown/](http://daringfireball.net/projects/markdown/)
-> > )
-
+> > <http://daringfireball.net/projects/markdown/> )
+>
> The point can be illustrated by comparing a sample of AsciiDoc with an
> equivalent sample of Markdown. Here is a sample of AsciiDoc from the AsciiDoc
> manual:
-
+>
> ```AsciiDoc
> 1. List item one.
> +
@@ -50,6 +49,7 @@ Now let's have an indented code block:
}
and end with a fenced code block:
+
~~~pseudocode
#include <something.h>
#include <else.h>
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md
new file mode 100644
index 0000000000..1728889adc
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/blockquotesWithLists.md
@@ -0,0 +1,14 @@
+What if we have a quotation containing a list?
+
+> First some quoted text, and then a list:
+>
+> - one
+> - two is longer and has enough words to form a paragraph with text continuing
+> onto the next line
+>
+> enough of that, let's try a numbered list
+>
+> 1. List item one
+> 2. List item two is longer and has enough words to form a paragraph with
+> text continuing onto the next line.
+> \ No newline at end of file
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
index a9a157f25a..15b30598e6 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
@@ -83,7 +83,7 @@ is used extensively in
[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are
automatically created when an HTML file is imported into an editor. Since the
rich text framework supports hyperlinks natively, they can also be created
-programatically.
+programmatically.
## Undo and Redo
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/links.md b/tests/auto/gui/text/qtextmarkdownwriter/data/links.md
index 33cdb2b3ab..c9aae80c67 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/data/links.md
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/links.md
@@ -23,3 +23,6 @@ title")
* [link](/url "title
title title")
* nonlink
+
+Qt has the <https://qt.io> site
+
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md b/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md
new file mode 100644
index 0000000000..c417125fea
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/listItemWithBlockquote.md
@@ -0,0 +1,6 @@
+What if we have a list item containing a block quote?
+
+- one
+- > two is longer and has enough words to form a paragraph with text continuing
+ > onto the next line
+
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md b/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md
new file mode 100644
index 0000000000..72692b4845
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md
@@ -0,0 +1,9 @@
+# The quick brown fox jumped over the lazy dog while the cat played the fiddle and the cow jumped over the moon
+
+Hey diddle diddle
+
+## This document has a verbose subheading too, which we do not expect to wrap in the output
+
+Qt can write it right. Long text here in this paragraph will actually wrap,
+even though its heading doesn't.
+
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md b/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md
new file mode 100644
index 0000000000..41303a0187
--- /dev/null
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/yaml.md
@@ -0,0 +1,11 @@
+---
+name: "Venus"
+discoverer: "Galileo Galilei"
+title: "A description of the planet Venus"
+keywords:
+ - planets
+ - solar system
+ - astronomy
+---
+*Venus* is the second planet from the Sun, orbiting it every 224.7 Earth days.
+
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
index bc6ee81ad4..0d261bc27e 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QTextDocument>
@@ -34,9 +9,13 @@
#include <QTextTable>
#include <QBuffer>
#include <QDebug>
+#include <QFontInfo>
+#include <QLoggingCategory>
#include <private/qtextmarkdownwriter_p.h>
+Q_LOGGING_CATEGORY(lcTests, "qt.text.tests")
+
// #define DEBUG_WRITE_OUTPUT
class tst_QTextMarkdownWriter : public QObject
@@ -51,20 +30,35 @@ private slots:
void testWriteParagraph();
void testWriteList();
void testWriteEmptyList();
+ void testWriteCheckboxListItemEndingWithCode();
void testWriteNestedBulletLists_data();
void testWriteNestedBulletLists();
void testWriteNestedNumericLists();
+ void testWriteNumericListWithStart();
void testWriteTable();
+ void frontMatter();
+ void charFormatWrapping_data();
+ void charFormatWrapping();
+ void charFormat_data();
+ void charFormat();
void rewriteDocument_data();
void rewriteDocument();
void fromHtml_data();
void fromHtml();
+ void fromPlainTextAndBack_data();
+ void fromPlainTextAndBack();
+ void escapeSpecialCharacters_data();
+ void escapeSpecialCharacters();
private:
+ bool isMainFontFixed();
+ bool isFixedFontProportional();
QString documentToUnixMarkdown();
private:
QTextDocument *document;
+ QFont m_monoFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
+ QFont m_defaultFont;
};
void tst_QTextMarkdownWriter::init()
@@ -77,10 +71,39 @@ void tst_QTextMarkdownWriter::cleanup()
delete document;
}
+bool tst_QTextMarkdownWriter::isMainFontFixed()
+{
+ bool ret = QFontInfo(QGuiApplication::font()).fixedPitch();
+ if (ret) {
+ qCWarning(lcTests) << "QFontDatabase::GeneralFont is monospaced: markdown writing is likely to use too many backticks"
+ << QFontDatabase::systemFont(QFontDatabase::GeneralFont);
+ }
+ return ret;
+}
+
+bool tst_QTextMarkdownWriter::isFixedFontProportional()
+{
+ bool ret = !QFontInfo(QFontDatabase::systemFont(QFontDatabase::FixedFont)).fixedPitch();
+ if (ret) {
+ qCWarning(lcTests) << "QFontDatabase::FixedFont is NOT monospaced: markdown writing is likely to use too few backticks"
+ << QFontDatabase::systemFont(QFontDatabase::FixedFont);
+ }
+ return ret;
+}
+
+QString tst_QTextMarkdownWriter::documentToUnixMarkdown()
+{
+ QString ret;
+ QTextStream ts(&ret, QIODevice::WriteOnly);
+ QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub);
+ writer.writeAll(document);
+ return ret;
+}
+
void tst_QTextMarkdownWriter::testWriteParagraph_data()
{
QTest::addColumn<QString>("input");
- QTest::addColumn<QString>("output");
+ QTest::addColumn<QString>("expectedOutput");
QTest::newRow("empty") << "" <<
"";
@@ -103,12 +126,15 @@ void tst_QTextMarkdownWriter::testWriteParagraph_data()
void tst_QTextMarkdownWriter::testWriteParagraph()
{
QFETCH(QString, input);
- QFETCH(QString, output);
+ QFETCH(QString, expectedOutput);
QTextCursor cursor(document);
cursor.insertText(input);
- QCOMPARE(documentToUnixMarkdown(), output);
+ const QString output = documentToUnixMarkdown();
+ if (output != expectedOutput && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expectedOutput);
}
void tst_QTextMarkdownWriter::testWriteList()
@@ -121,8 +147,11 @@ void tst_QTextMarkdownWriter::testWriteList()
cursor.insertText("ListItem 2");
list->add(cursor.block());
- QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1(
- "- ListItem 1\n- ListItem 2\n"));
+ const QString output = documentToUnixMarkdown();
+ const QString expected = QString::fromLatin1("- ListItem 1\n- ListItem 2\n");
+ if (output != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expected);
}
void tst_QTextMarkdownWriter::testWriteEmptyList()
@@ -133,6 +162,38 @@ void tst_QTextMarkdownWriter::testWriteEmptyList()
QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1("- \n"));
}
+void tst_QTextMarkdownWriter::testWriteCheckboxListItemEndingWithCode()
+{
+ QTextCursor cursor(document);
+ QTextList *list = cursor.createList(QTextListFormat::ListDisc);
+ cursor.insertText("Image.originalSize property (not necessary; PdfDocument.pagePointSize() substitutes)");
+ list->add(cursor.block());
+ {
+ auto fmt = cursor.block().blockFormat();
+ fmt.setMarker(QTextBlockFormat::MarkerType::Unchecked);
+ cursor.setBlockFormat(fmt);
+ }
+ cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 2);
+ cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
+ cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor, 4);
+ QCOMPARE(cursor.selectedText(), QString::fromLatin1("PdfDocument.pagePointSize()"));
+ auto fmt = cursor.charFormat();
+ fmt.setFontFixedPitch(true);
+ cursor.setCharFormat(fmt);
+ cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::MoveAnchor, 5);
+ cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor);
+ cursor.movePosition(QTextCursor::PreviousWord, QTextCursor::KeepAnchor, 4);
+ QCOMPARE(cursor.selectedText(), QString::fromLatin1("Image.originalSize"));
+ cursor.setCharFormat(fmt);
+
+ const QString output = documentToUnixMarkdown();
+ const QString expected = QString::fromLatin1(
+ "- [ ] `Image.originalSize` property (not necessary; `PdfDocument.pagePointSize()`\n substitutes)\n");
+ if (output != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expected);
+}
+
void tst_QTextMarkdownWriter::testWriteNestedBulletLists_data()
{
QTest::addColumn<bool>("checkbox");
@@ -212,7 +273,7 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists()
cursor.insertText("continuation");
}
- QString output = documentToUnixMarkdown();
+ const QString output = documentToUnixMarkdown();
#ifdef DEBUG_WRITE_OUTPUT
{
QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md");
@@ -221,7 +282,9 @@ void tst_QTextMarkdownWriter::testWriteNestedBulletLists()
out.close();
}
#endif
- QCOMPARE(documentToUnixMarkdown(), expectedOutput);
+ if (output != expectedOutput && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expectedOutput);
}
void tst_QTextMarkdownWriter::testWriteNestedNumericLists()
@@ -233,6 +296,7 @@ void tst_QTextMarkdownWriter::testWriteNestedNumericLists()
list1->add(cursor.block());
QTextListFormat fmt2;
+ // Alpha "numbering" is not supported in markdown, so we'll actually get decimal.
fmt2.setStyle(QTextListFormat::ListLowerAlpha);
fmt2.setNumberSuffix(QLatin1String(")"));
fmt2.setIndent(2);
@@ -253,9 +317,116 @@ void tst_QTextMarkdownWriter::testWriteNestedNumericLists()
cursor.insertText("ListItem 5");
list2->add(cursor.block());
- // There's no QTextList API to set the starting number so we hard-coded all lists to start at 1 (QTBUG-65384)
- QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1(
- "1. ListItem 1\n 1) ListItem 2\n 1. ListItem 3\n2. ListItem 4\n 2) ListItem 5\n"));
+ const QString output = documentToUnixMarkdown();
+
+ #ifdef DEBUG_WRITE_OUTPUT
+ {
+ QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".md"));
+ out.open(QFile::WriteOnly);
+ out.write(output.toUtf8());
+ out.close();
+ }
+ {
+ QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".html"));
+ out.open(QFile::WriteOnly);
+ out.write(document->toHtml().toUtf8());
+ out.close();
+ }
+#endif
+
+ // While we can set the start index for a block, if list items intersect each other, they will
+ // still use the list numbering.
+ const QString expected = QString::fromLatin1(
+ "1. ListItem 1\n 1) ListItem 2\n 1. ListItem 3\n2. ListItem 4\n 2) ListItem 5\n");
+ if (output != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expected);
+}
+
+void tst_QTextMarkdownWriter::testWriteNumericListWithStart()
+{
+ QTextCursor cursor(document);
+
+ // The first list will start at 2.
+ QTextListFormat fmt1;
+ fmt1.setStyle(QTextListFormat::ListDecimal);
+ fmt1.setStart(2);
+ QTextList *list1 = cursor.createList(fmt1);
+ cursor.insertText("ListItem 1");
+ list1->add(cursor.block());
+
+ // This list uses the default start (1) again.
+ QTextListFormat fmt2;
+ // Alpha "numbering" is not supported in markdown, so we'll actually get decimal.
+ fmt2.setStyle(QTextListFormat::ListLowerAlpha);
+ fmt2.setNumberSuffix(QLatin1String(")"));
+ fmt2.setIndent(2);
+ QTextList *list2 = cursor.insertList(fmt2);
+ cursor.insertText("ListItem 2");
+
+ // Negative list numbers are disallowed by most Markdown implementations. This list will start
+ // at 1 for that reason.
+ QTextListFormat fmt3;
+ fmt3.setStyle(QTextListFormat::ListDecimal);
+ fmt3.setIndent(3);
+ fmt3.setStart(-1);
+ cursor.insertList(fmt3);
+ cursor.insertText("ListItem 3");
+
+ // Continuing list1, so the second item will have the number 3.
+ cursor.insertBlock();
+ cursor.insertText("ListItem 4");
+ list1->add(cursor.block());
+
+ // This will look out of place: it's in a different position than its list would suggest.
+ // Generates invalid markdown numbering (OK for humans, but md4c will parse it differently than we "meant").
+ // TODO QTBUG-111707: the writer needs to add newlines, otherwise ListItem 5 becomes part of the text for ListItem 4.
+ cursor.insertBlock();
+ cursor.insertText("ListItem 5");
+ list2->add(cursor.block());
+
+ // 0 indexed lists are fine.
+ QTextListFormat fmt4;
+ fmt4.setStyle(QTextListFormat::ListDecimal);
+ fmt4.setStart(0);
+ QTextList *list4 = cursor.insertList(fmt4);
+ cursor.insertText("SecondList Item 0");
+ list4->add(cursor.block());
+
+ // Ensure list numbers are incremented properly.
+ cursor.insertBlock();
+ cursor.insertText("SecondList Item 1");
+ list4->add(cursor.block());
+
+ const QString output = documentToUnixMarkdown();
+ const QString expected = QString::fromLatin1(
+ R"(2. ListItem 1
+ 1) ListItem 2
+ 1. ListItem 3
+3. ListItem 4
+ 2) ListItem 5
+0. SecondList Item 0
+1. SecondList Item 1
+)");
+
+#ifdef DEBUG_WRITE_OUTPUT
+ {
+ QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".md"));
+ out.open(QFile::WriteOnly);
+ out.write(output.toUtf8());
+ out.close();
+ }
+ {
+ QFile out(QDir::temp().filePath(QLatin1String(QTest::currentTestFunction()) + ".html"));
+ out.open(QFile::WriteOnly);
+ out.write(document->toHtml().toUtf8());
+ out.close();
+ }
+#endif
+
+ if (output != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expected);
}
void tst_QTextMarkdownWriter::testWriteTable()
@@ -308,6 +479,8 @@ void tst_QTextMarkdownWriter::testWriteTable()
QString expected = QString::fromLatin1(
"\n|one |two |three|\n|------|----|-----|\n|alice |bob |carl |\n|dennis|eric|fiona|\n|gina | | |\n\n");
+ if (md != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
QCOMPARE(md, expected);
// create table with merged cells
@@ -357,7 +530,221 @@ void tst_QTextMarkdownWriter::testWriteTable()
}
#endif
- QCOMPARE(md, QString::fromLatin1("\n|a ||b|\n|-|-|-|\n|c|d ||\n|e|f| |\n\n"));
+ expected = QString::fromLatin1("\n|a ||b|\n|-|-|-|\n|c|d ||\n|e|f| |\n\n");
+ if (md != expected && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(md, expected);
+}
+
+void tst_QTextMarkdownWriter::frontMatter()
+{
+ QTextCursor cursor(document);
+ cursor.insertText("bar");
+ document->setMetaInformation(QTextDocument::FrontMatter, "foo");
+
+ const QString output = documentToUnixMarkdown();
+ const QString expectedOutput("---\nfoo\n---\nbar\n\n");
+ if (output != expectedOutput && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expectedOutput);
+}
+
+void tst_QTextMarkdownWriter::charFormatWrapping_data()
+{
+ QTest::addColumn<QTextFormat::Property>("property");
+ QTest::addColumn<QVariant>("propertyValue");
+ QTest::addColumn<QString>("followingText");
+ QTest::addColumn<QString>("expectedIndicator");
+
+ const QString spaced = " after";
+ const QString unspaced = ", and some more after";
+
+ QTest::newRow("FontFixedPitch-spaced")
+ << QTextFormat::FontFixedPitch << QVariant(true) << spaced << "`";
+ QTest::newRow("FontFixedPitch-unspaced")
+ << QTextFormat::FontFixedPitch << QVariant(true) << unspaced << "`";
+ QTest::newRow("FontItalic")
+ << QTextFormat::FontItalic << QVariant(true) << spaced << "*";
+ QTest::newRow("FontUnderline")
+ << QTextFormat::FontUnderline << QVariant(true) << spaced << "_";
+ QTest::newRow("FontStrikeOut")
+ << QTextFormat::FontStrikeOut << QVariant(true) << spaced << "~~";
+ QTest::newRow("FontWeight-spaced")
+ << QTextFormat::FontWeight << QVariant(700) << spaced << "**";
+ QTest::newRow("FontWeight-unspaced")
+ << QTextFormat::FontWeight << QVariant(700) << unspaced << "**";
+}
+
+void tst_QTextMarkdownWriter::charFormatWrapping() // QTBUG-116927
+{
+ QFETCH(QTextFormat::Property, property);
+ QFETCH(QVariant, propertyValue);
+ QFETCH(QString, expectedIndicator);
+ QFETCH(QString, followingText);
+
+ const QString newLine("\n");
+ QTextCursor cursor(document);
+ cursor.insertText("around sixty-four characters to go before some formatted words ");
+ QTextCharFormat fmt;
+ fmt.setProperty(property, propertyValue);
+ cursor.setCharFormat(fmt);
+ cursor.insertText("formatted text");
+
+ cursor.setCharFormat({});
+ cursor.insertText(followingText);
+ qsizetype lastNewLineIndex = 100;
+
+ for (int push = 0; push < 10; ++push) {
+ if (push > 0) {
+ cursor.movePosition(QTextCursor::StartOfBlock);
+ cursor.insertText("a");
+ }
+
+ const QString output = documentToUnixMarkdown().trimmed(); // get rid of trailing newlines
+ const auto nlIdx = output.indexOf(newLine);
+ qCDebug(lcTests) << "push" << push << ":" << output << "newline @" << nlIdx;
+ // we're always wrapping in this test: expect to find a newline
+ QCOMPARE_GT(nlIdx, 70);
+ // don't expect the newline to be more than one character to the right of where we found it last time
+ // i.e. if we already started breaking in the middle: "`formatted\ntext`",
+ // then we would not expect that prepending one more character would make it go
+ // back to breaking afterwards: "`formatted text`\n" (because then the line becomes longer than necessary)
+ QCOMPARE_LE(nlIdx, lastNewLineIndex + 1);
+ lastNewLineIndex = nlIdx;
+ const QString nextChars = output.sliced(nlIdx + newLine.size(), expectedIndicator.size());
+ const auto startingIndicatorIdx = output.indexOf(expectedIndicator);
+ // the starting indicator always exists, except in case of font problems on some CI platforms
+ if (startingIndicatorIdx <= 0)
+ QSKIP("starting indicator not found, probably due to platform font problems (QTBUG-103484 etc.)");
+ const auto endingIndicatorIdx = output.indexOf(expectedIndicator, startingIndicatorIdx + 5);
+ qCDebug(lcTests) << "next chars past newline" << nextChars
+ << "indicators @" << startingIndicatorIdx << endingIndicatorIdx;
+ // the closing indicator must exist
+ QCOMPARE_GT(endingIndicatorIdx, startingIndicatorIdx);
+ // don't start a new line with an ending indicator:
+ // we can have "**formatted\ntext**" or "**formatted text**\n" or "\n**formatted text**"
+ // but not "**formatted text\n**"
+ if (startingIndicatorIdx < nlIdx)
+ QCOMPARE_NE(nextChars, expectedIndicator);
+ }
+}
+
+void tst_QTextMarkdownWriter::charFormat_data()
+{
+ QTest::addColumn<QTextFormat::Property>("property");
+ QTest::addColumn<QVariant>("propertyValue");
+ QTest::addColumn<QFont>("explicitFont");
+ QTest::addColumn<QString>("expectedOutput");
+
+ const QTextFormat::Property NoProperty = QTextFormat::ObjectIndex;
+
+ QTest::newRow("FontFixedPitch")
+ << QTextFormat::FontFixedPitch << QVariant(true) << m_defaultFont
+ << "before `formatted` after";
+ if (!isFixedFontProportional()) {
+ // QTBUG-54623 QTBUG-75649 QTBUG-79900 QTBUG-103484 etc.
+ QTest::newRow("mono font") << NoProperty << QVariant() << m_monoFont
+ << "before `formatted` after";
+ }
+
+ {
+ QFont font;
+ font.setItalic(true);
+ QTest::newRow("italic font")
+ << NoProperty << QVariant() << font
+ << "before *formatted* after";
+ }
+ QTest::newRow("FontItalic")
+ << QTextFormat::FontItalic << QVariant(true) << m_defaultFont
+ << "before *formatted* after";
+
+ {
+ QFont font;
+ font.setUnderline(true);
+ QTest::newRow("underline font")
+ << NoProperty << QVariant() << font
+ << "before _formatted_ after";
+ }
+ QTest::newRow("FontUnderline")
+ << QTextFormat::FontUnderline << QVariant(true) << m_defaultFont
+ << "before _formatted_ after";
+
+ {
+ QFont font;
+ font.setStrikeOut(true);
+ QTest::newRow("strikeout font")
+ << NoProperty << QVariant() << font
+ << "before ~~formatted~~ after";
+ }
+ QTest::newRow("FontStrikeOut")
+ << QTextFormat::FontStrikeOut << QVariant(true) << m_defaultFont
+ << "before ~~formatted~~ after";
+
+ {
+ QFont font;
+ font.setBold(true);
+ QTest::newRow("bold font")
+ << NoProperty << QVariant() << font
+ << "before **formatted** after";
+ }
+ {
+ QFont font;
+ font.setWeight(QFont::Black);
+ QTest::newRow("black font")
+ << NoProperty << QVariant() << font
+ << "before **formatted** after";
+ }
+ QTest::newRow("FontWeight")
+ << QTextFormat::FontWeight << QVariant(700) << m_defaultFont
+ << "before **formatted** after";
+
+ QTest::newRow("AnchorHref")
+ << QTextFormat::AnchorHref << QVariant("linky linky") << m_defaultFont
+ << "before [formatted](linky linky) after";
+
+ QTest::newRow("TextToolTip") // no effect without AnchorHref
+ << QTextFormat::TextToolTip << QVariant("such a tool") << m_defaultFont
+ << "before formatted after";
+}
+
+void tst_QTextMarkdownWriter::charFormat()
+{
+ if (isMainFontFixed())
+ QSKIP("QTextMarkdownWriter would generate bogus backticks");
+
+ QFETCH(QTextFormat::Property, property);
+ QFETCH(QVariant, propertyValue);
+ QFETCH(QFont, explicitFont);
+ QFETCH(QString, expectedOutput);
+
+ QTextCursor cursor(document);
+ cursor.insertText("before ");
+
+ QTextCharFormat fmt;
+ if (explicitFont != m_defaultFont)
+ fmt.setFont(explicitFont);
+ if (property != QTextFormat::ObjectIndex) // != 0
+ fmt.setProperty(property, propertyValue);
+ if (explicitFont == m_monoFont) {
+ QFontInfo fontInfo(fmt.font());
+ qCDebug(lcTests) << "mono font" << explicitFont << "fontInfo fixedPitch" << fontInfo.fixedPitch() << "fmt fixedPitch" << fmt.fontFixedPitch();
+ }
+ cursor.setCharFormat(fmt);
+ cursor.insertText("formatted");
+
+ cursor.setCharFormat({});
+ cursor.insertText(" after");
+
+ const QString output = documentToUnixMarkdown();
+#ifdef DEBUG_WRITE_OUTPUT
+ {
+ QFile out(QDir::temp().filePath(QLatin1String(QTest::currentDataTag()) + ".md"));
+ out.open(QFile::WriteOnly);
+ out.write(output.toUtf8());
+ out.close();
+ }
+#endif
+ QCOMPARE(output.trimmed(), expectedOutput);
}
void tst_QTextMarkdownWriter::rewriteDocument_data()
@@ -365,11 +752,15 @@ void tst_QTextMarkdownWriter::rewriteDocument_data()
QTest::addColumn<QString>("inputFile");
QTest::newRow("block quotes") << "blockquotes.md";
+ QTest::newRow("block quotes with lists") << "blockquotesWithLists.md";
+ // QTest::newRow("list item with block quote") << "listItemWithBlockquote.md"; // not supported for now
QTest::newRow("example") << "example.md";
QTest::newRow("list items after headings") << "headingsAndLists.md";
QTest::newRow("word wrap") << "wordWrap.md";
QTest::newRow("links") << "links.md";
QTest::newRow("lists and code blocks") << "listsAndCodeBlocks.md";
+ QTest::newRow("front matter") << "yaml.md";
+ QTest::newRow("long headings") << "longHeadings.md";
}
void tst_QTextMarkdownWriter::rewriteDocument()
@@ -390,17 +781,19 @@ void tst_QTextMarkdownWriter::rewriteDocument()
out.close();
#endif
+ if (md != orig && isMainFontFixed())
+ QEXPECT_FAIL("", "fixed-pitch main font (QTBUG-103484)", Continue);
QCOMPARE(md, orig);
}
void tst_QTextMarkdownWriter::fromHtml_data()
{
- QTest::addColumn<QString>("expectedInput");
+ QTest::addColumn<QString>("input");
QTest::addColumn<QString>("expectedOutput");
QTest::newRow("long URL") <<
"<span style=\"font-style:italic;\">https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/</span>" <<
- "*https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/*\n\n";
+ "\n*https://www.example.com/dir/subdir/subsubdir/subsubsubdir/subsubsubsubdir/subsubsubsubsubdir/*\n\n";
QTest::newRow("non-emphasis inline asterisk") << "3 * 4" << "3 * 4\n\n";
QTest::newRow("arithmetic") << "(2 * a * x + b)^2 = b^2 - 4 * a * c" << "(2 * a * x + b)^2 = b^2 - 4 * a * c\n\n";
QTest::newRow("escaped asterisk after newline") <<
@@ -432,22 +825,51 @@ void tst_QTextMarkdownWriter::fromHtml_data()
"![foo](/url \"title\")\n\n";
QTest::newRow("code") <<
"<pre class=\"language-pseudocode\">\n#include \"foo.h\"\n\nblock {\n statement();\n}\n\n</pre>" <<
- "```pseudocode\n#include \"foo.h\"\n\nblock {\n statement();\n}\n```\n\n";
- // TODO
-// QTest::newRow("escaped number and paren after double newline") <<
-// "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" <<
-// "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n";
-// QTest::newRow("preformats with embedded backticks") <<
-// "<pre>none `one` ``two``</pre><pre>```three``` ````four````</pre>plain" <<
-// "``` none `one` ``two`` ```\n\n````` ```three``` ````four```` `````\n\nplain\n\n";
+ "```pseudocode\n#include \"foo.h\"\n\nblock {\n statement();\n}\n\n```\n\n";
+ QTest::newRow("escaped number and paren after single newline") <<
+ "<p>(The first sentence of this paragraph is a line, next paragraph has a number 13) but that's not part of an ordered list</p>" <<
+ "(The first sentence of this paragraph is a line, next paragraph has a number\n13\\) but that's not part of an ordered list\n\n";
+ QTest::newRow("escaped number and paren after double newline") <<
+ "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" <<
+ "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n";
+ QTest::newRow("preformats with embedded backticks") <<
+ "<pre>none `one` ``two``</pre>plain<pre>```three``` ````four````</pre>plain" <<
+ "```\nnone `one` ``two``\n\n```\nplain\n\n```\n```three``` ````four````\n\n```\nplain\n\n";
+ QTest::newRow("list items with and without checkboxes") <<
+ "<ul><li>bullet</li><li class=\"unchecked\">unchecked item</li><li class=\"checked\">checked item</li></ul>" <<
+ "- bullet\n- [ ] unchecked item\n- [x] checked item\n";
+ QTest::newRow("table with backslash in cell") << // QTBUG-96051
+ "<table><tr><td>1011011 [</td><td>1011100 backslash \\</td></tr></table>" <<
+ "|1011011 [|1011100 backslash \\\\|";
+ // https://spec.commonmark.org/0.31.2/#example-12
+ // escaping punctuation is ok, but QTextMarkdownWriter currently doesn't do that (which is also ok)
+ QTest::newRow("punctuation") <<
+ R"(<p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p>)" <<
+ R"(!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~)";
+ // https://spec.commonmark.org/0.31.2/#example-14
+ QTest::newRow("backslash asterisk no emphasis") << // QTBUG-122083
+ R"(\*no emphasis*)" <<
+ R"(\\\*no emphasis*)";
+ // https://spec.commonmark.org/0.31.2/#example-15
+ QTest::newRow("backslash before emphasis") <<
+ R"(\<em>emphasis</em>)" <<
+ R"(\\*emphasis*)";
+ // https://spec.commonmark.org/0.31.2/#example-20
+ QTest::newRow("backslash-asterisk in autolink") <<
+ R"(<p><a href="https://example.com?find=\\*">https://example.com?find=\*</a></p>)" <<
+ R"(<https://example.com?find=\\*>)";
+ // https://spec.commonmark.org/0.31.2/#example-24
+ QTest::newRow("plus in fenced code lang") <<
+ "<pre class=\"language-foo+bar\">foo</pre>" <<
+ "```foo+bar\nfoo\n```";
}
void tst_QTextMarkdownWriter::fromHtml()
{
- QFETCH(QString, expectedInput);
+ QFETCH(QString, input);
QFETCH(QString, expectedOutput);
- document->setHtml(expectedInput);
+ document->setHtml(input);
QString output = documentToUnixMarkdown();
#ifdef DEBUG_WRITE_OUTPUT
@@ -459,16 +881,140 @@ void tst_QTextMarkdownWriter::fromHtml()
}
#endif
+ output = output.trimmed();
+ expectedOutput = expectedOutput.trimmed();
+ if (output != expectedOutput && (isMainFontFixed() || isFixedFontProportional()))
+ QEXPECT_FAIL("", "fixed main font or proportional fixed font (QTBUG-103484)", Continue);
QCOMPARE(output, expectedOutput);
}
-QString tst_QTextMarkdownWriter::documentToUnixMarkdown()
+void tst_QTextMarkdownWriter::fromPlainTextAndBack_data()
{
- QString ret;
- QTextStream ts(&ret, QIODevice::WriteOnly);
- QTextMarkdownWriter writer(ts, QTextDocument::MarkdownDialectGitHub);
- writer.writeAll(document);
- return ret;
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expectedMarkdown");
+
+ // tests to verify that fixing QTBUG-122083 is safe
+ QTest::newRow("single backslashes") <<
+ R"(\ again: \ not esc: \* \-\-\ \*abc*)" <<
+ R"(\\ again: \\ not esc: \\* \\-\\-\\ \\\*abc*)";
+ // https://spec.commonmark.org/0.31.2/#example-12
+ QTest::newRow("punctuation") <<
+ R"(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)" <<
+ R"(!"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~)";
+ // https://spec.commonmark.org/0.31.2/#example-13
+ QTest::newRow("literal backslashes") <<
+ QString(uR"(\→\A\a\ \3\φ\«)") <<
+ "\\\\\u2192\\\\A\\\\a\\\\ \\\\3\\\\\u03C6\\\\\u00AB";
+ // https://spec.commonmark.org/0.31.2/#example-14
+ QTest::newRow("escape to avoid em") <<
+ R"(*not emphasized*)" <<
+ R"(\*not emphasized*)";
+ QTest::newRow("escape to avoid html") <<
+ R"(<br/> not a tag)" <<
+ R"(\<br/> not a tag)";
+ QTest::newRow("escape to avoid link") <<
+ R"([not a link](/foo))" <<
+ R"(\[not a link](/foo))";
+ QTest::newRow("escape to avoid mono") <<
+ R"(`not code`)" <<
+ R"(\`not code`)";
+ QTest::newRow("escape to avoid num list") <<
+ R"(1. not a list)" <<
+ R"(1\. not a list)";
+ QTest::newRow("escape to avoid list") <<
+ R"(* not a list)" <<
+ R"(\* not a list)";
+ QTest::newRow("escape to avoid heading") <<
+ R"(# not a heading)" <<
+ R"(\# not a heading)";
+ QTest::newRow("escape to avoid reflink") <<
+ R"([foo]: /url "not a reference")" <<
+ R"(\[foo]: /url "not a reference")";
+ QTest::newRow("escape to avoid entity") <<
+ R"(&ouml; not a character entity)" <<
+ R"(\&ouml; not a character entity)";
+ // end of tests to verify that fixing QTBUG-122083 is safe
+ // (it's ok to add unrelated plain-to-markdown-to-plaintext cases later)
+}
+
+void tst_QTextMarkdownWriter::fromPlainTextAndBack()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, expectedMarkdown);
+
+ document->setPlainText(input);
+ QString output = documentToUnixMarkdown();
+
+#ifdef DEBUG_WRITE_OUTPUT
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md");
+ out.open(QFile::WriteOnly);
+ out.write(output.toUtf8());
+ out.close();
+ }
+#endif
+
+ output = output.trimmed();
+ expectedMarkdown = expectedMarkdown.trimmed();
+ if (output != expectedMarkdown && (isMainFontFixed() || isFixedFontProportional()))
+ QSKIP("", "fixed main font or proportional fixed font (QTBUG-103484)");
+ QCOMPARE(output, expectedMarkdown);
+ QCOMPARE(document->toPlainText(), input);
+ document->setMarkdown(output);
+ QCOMPARE(document->toPlainText(), input);
+ if (document->blockCount() == 1)
+ QCOMPARE(document->firstBlock().text(), input);
+}
+
+void tst_QTextMarkdownWriter::escapeSpecialCharacters_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expectedOutput");
+
+ QTest::newRow("backslash") << "foo \\ bar \\\\ baz \\" << "foo \\\\ bar \\\\\\\\ baz \\\\";
+ QTest::newRow("not emphasized") << "*normal* **normal too**" << "\\*normal* \\**normal too**";
+ QTest::newRow("not code") << "`normal` `normal too`" << "\\`normal` \\`normal too`";
+ QTest::newRow("code fence") << "```not a fence; ``` no risk here; ```not a fence" // TODO slightly inconsistent
+ << "\\```not a fence; ``` no risk here; \\```not a fence";
+ QTest::newRow("not html") << "<p>not a tag: <br/> nope</p>" << "\\<p>not a tag: \\<br/> nope\\</p>";
+ QTest::newRow("not a link") << "text [not a link](/foo)" << "text \\[not a link](/foo)";
+ QTest::newRow("not a circle") << "* polaris" << "\\* polaris";
+ QTest::newRow("not a square") << "+ groovy" << "\\+ groovy";
+ QTest::newRow("not a bullet") << "- stayin alive" << "\\- stayin alive";
+ QTest::newRow("arithmetic") << "1 + 2 - 3 * 4" << "1 + 2 - 3 * 4";
+ QTest::newRow("not a list") << "1. not a list" << "1\\. not a list";
+ QTest::newRow("not a list either") << "Jupiter and 10." << "Jupiter and 10.";
+ QTest::newRow("not a heading") << "# not a heading" << "\\# not a heading";
+ QTest::newRow("a non-entity") << "&ouml; not a character entity" << "\\&ouml; not a character entity";
+}
+
+/*! \internal
+ If the user types into a Qt-based editor plain text that the
+ markdown parser would misinterpret, escape it when we save to markdown
+ to clarify that it's plain text.
+ https://spec.commonmark.org/0.31.2/#backslash-escapes
+*/
+void tst_QTextMarkdownWriter::escapeSpecialCharacters() // QTBUG-96051, QTBUG-122083
+{
+ QFETCH(QString, input);
+ QFETCH(QString, expectedOutput);
+
+ document->setPlainText(input);
+ QString output = documentToUnixMarkdown();
+
+#ifdef DEBUG_WRITE_OUTPUT
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".md");
+ out.open(QFile::WriteOnly);
+ out.write(output.toUtf8());
+ out.close();
+ }
+#endif
+
+ output = output.trimmed();
+ if (output != expectedOutput && (isMainFontFixed() || isFixedFontProportional()))
+ QEXPECT_FAIL("", "fixed main font or proportional fixed font (QTBUG-103484)", Continue);
+ QCOMPARE(output, expectedOutput);
}
QTEST_MAIN(tst_QTextMarkdownWriter)
diff --git a/tests/auto/gui/text/qtextobject/CMakeLists.txt b/tests/auto/gui/text/qtextobject/CMakeLists.txt
index 07ea132de0..dd7aeae60e 100644
--- a/tests/auto/gui/text/qtextobject/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextobject/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextobject.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextobject Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextobject LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextobject
SOURCES
tst_qtextobject.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
@@ -15,6 +22,6 @@ qt_internal_add_test(tst_qtextobject
#####################################################################
qt_internal_extend_target(tst_qtextobject CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp b/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp
index 2afca43915..e75dfcb270 100644
--- a/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp
+++ b/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt
index 2a468b0c5e..d371fe2ee1 100644
--- a/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextodfwriter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextodfwriter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextodfwriter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextodfwriter
SOURCES
tst_qtextodfwriter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp
index e9e2eac268..6b56e7c727 100644
--- a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp
+++ b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QTextDocument>
@@ -104,7 +79,7 @@ QString tst_QTextOdfWriter::getContentFromXml()
if (index > 0) {
index = stringContent.indexOf('>', index);
if (index > 0)
- ret = stringContent.mid(index+1, stringContent.length() - index - 10);
+ ret = stringContent.mid(index+1, stringContent.size() - index - 10);
}
return ret;
}
@@ -304,7 +279,7 @@ file.open(QIODevice::WriteOnly);
file.write(buffer->data());
file.close();
*/
- QVERIFY(buffer->data().length() > 80);
+ QVERIFY(buffer->data().size() > 80);
QCOMPARE(buffer->data()[0], 'P'); // its a zip :)
QCOMPARE(buffer->data()[1], 'K');
QString mimetype(buffer->data().mid(38, 39));
diff --git a/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt
index 49cfcfab6a..8bdf17890c 100644
--- a/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qtextpiecetable.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextpiecetable LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(WIN32)
return()
@@ -15,11 +22,8 @@ qt_internal_add_test(tst_qtextpiecetable
SOURCES
../qtextdocument/common.h
tst_qtextpiecetable.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
)
-
-#### Keys ignored in scope 1:.:.:qtextpiecetable.pro:<TRUE>:
-# _REQUIREMENTS = "!win32" "qtConfig(private_tests)"
diff --git a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
index 32ab425ccf..f47d5dc0d6 100644
--- a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
+++ b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -124,21 +99,21 @@ void tst_QTextPieceTable::cleanup()
void tst_QTextPieceTable::insertion1()
{
- table->insert(0, "aacc", charFormatIndex);
+ table->insert(0, u"aacc", charFormatIndex);
QCOMPARE(table->plainText(), QString("aacc"));
- table->insert(2, "bb", charFormatIndex);
+ table->insert(2, u"bb", charFormatIndex);
QCOMPARE(table->plainText(), QString("aabbcc"));
- table->insert(1, "1", charFormatIndex);
+ table->insert(1, u"1", charFormatIndex);
QCOMPARE(table->plainText(), QString("a1abbcc"));
- table->insert(6, "d", charFormatIndex);
+ table->insert(6, u"d", charFormatIndex);
QCOMPARE(table->plainText(), QString("a1abbcdc"));
- table->insert(8, "z", charFormatIndex);
+ table->insert(8, u"z", charFormatIndex);
QCOMPARE(table->plainText(), QString("a1abbcdcz"));
}
void tst_QTextPieceTable::insertion2()
{
- table->insert(0, "bb", charFormatIndex);
+ table->insert(0, u"bb", charFormatIndex);
QCOMPARE(table->plainText(), QString("bb"));
}
@@ -201,21 +176,21 @@ void tst_QTextPieceTable::insertion5()
void tst_QTextPieceTable::removal1()
{
- table->insert(0, "abbccc", charFormatIndex);
+ table->insert(0, u"abbccc", charFormatIndex);
QCOMPARE(table->plainText(), QString("abbccc"));
table->remove(1, 2);
QCOMPARE(table->plainText(), QString("accc"));
- table->insert(1, "1", charFormatIndex);
+ table->insert(1, u"1", charFormatIndex);
QCOMPARE(table->plainText(), QString("a1ccc"));
table->remove(4, 1);
QCOMPARE(table->plainText(), QString("a1cc"));
- table->insert(4, "z", charFormatIndex);
+ table->insert(4, u"z", charFormatIndex);
QCOMPARE(table->plainText(), QString("a1ccz"));
}
void tst_QTextPieceTable::removal2()
{
- table->insert(0, "bb", charFormatIndex);
+ table->insert(0, u"bb", charFormatIndex);
QCOMPARE(table->plainText(), QString("bb"));
table->remove(0, 2);
QCOMPARE(table->plainText(), QString(""));
@@ -224,7 +199,7 @@ void tst_QTextPieceTable::removal2()
table->remove(0, 1);
QCOMPARE(table->plainText(), QString(""));
- table->insert(0, "bb", charFormatIndex);
+ table->insert(0, u"bb", charFormatIndex);
QCOMPARE(table->plainText(), QString("bb"));
table->insertBlock(1, blockFormatIndex, charFormatIndex);
QCOMPARE(table->plainText(), QString("b") + QString(QChar(QChar::ParagraphSeparator)) + QString("b"));
@@ -295,16 +270,16 @@ void tst_QTextPieceTable::removal4()
void tst_QTextPieceTable::undoRedo1()
{
- table->insert(0, "01234567", charFormatIndex);
- table->insert(0, "a", charFormatIndex);
- table->insert(1, "b", charFormatIndex);
+ table->insert(0, u"01234567", charFormatIndex);
+ table->insert(0, u"a", charFormatIndex);
+ table->insert(1, u"b", charFormatIndex);
QCOMPARE(table->plainText(), QString("ab01234567"));
table->undo();
QCOMPARE(table->plainText(), QString("01234567"));
table->redo();
QCOMPARE(table->plainText(), QString("ab01234567"));
table->undo();
- table->insert(1, "c", charFormatIndex);
+ table->insert(1, u"c", charFormatIndex);
QCOMPARE(table->plainText(), QString("0c1234567"));
table->undo();
QCOMPARE(table->plainText(), QString("01234567"));
@@ -314,8 +289,8 @@ void tst_QTextPieceTable::undoRedo1()
void tst_QTextPieceTable::undoRedo2()
{
- table->insert(0, "01", charFormatIndex);
- table->insert(1, "a", charFormatIndex);
+ table->insert(0, u"01", charFormatIndex);
+ table->insert(1, u"a", charFormatIndex);
QCOMPARE(table->plainText(), QString("0a1"));
table->undo();
QCOMPARE(table->plainText(), QString("01"));
@@ -329,8 +304,8 @@ void tst_QTextPieceTable::undoRedo2()
void tst_QTextPieceTable::undoRedo3()
{
- table->insert(0, "01", charFormatIndex);
- table->insert(2, "ab", charFormatIndex);
+ table->insert(0, u"01", charFormatIndex);
+ table->insert(2, u"ab", charFormatIndex);
table->remove(2, 1);
QCOMPARE(table->plainText(), QString("01b"));
table->undo();
@@ -345,8 +320,8 @@ void tst_QTextPieceTable::undoRedo3()
void tst_QTextPieceTable::undoRedo4()
{
- table->insert(0, "01", charFormatIndex);
- table->insert(0, "ab", charFormatIndex);
+ table->insert(0, u"01", charFormatIndex);
+ table->insert(0, u"ab", charFormatIndex);
table->remove(0, 1);
QCOMPARE(table->plainText(), QString("b01"));
table->undo();
@@ -366,7 +341,7 @@ void tst_QTextPieceTable::undoRedo4()
void tst_QTextPieceTable::undoRedo5()
{
table->beginEditBlock();
- table->insert(0, "01", charFormatIndex);
+ table->insert(0, u"01", charFormatIndex);
table->remove(1, 1);
table->endEditBlock();
QCOMPARE(table->plainText(), QString("0"));
@@ -409,8 +384,8 @@ void tst_QTextPieceTable::undoRedo6()
void tst_QTextPieceTable::undoRedo7()
{
- table->insert(0, "a", charFormatIndex);
- table->insert(1, "b", charFormatIndex);
+ table->insert(0, u"a", charFormatIndex);
+ table->insert(1, u"b", charFormatIndex);
QCOMPARE(table->plainText(), QString("ab"));
table->undo();
@@ -419,8 +394,8 @@ void tst_QTextPieceTable::undoRedo7()
void tst_QTextPieceTable::undoRedo8()
{
- table->insert(0, "a", charFormatIndex);
- table->insert(1, "b", charFormatIndex);
+ table->insert(0, u"a", charFormatIndex);
+ table->insert(1, u"b", charFormatIndex);
QCOMPARE(table->plainText(), QString("ab"));
table->remove(0, 1);
@@ -433,8 +408,8 @@ void tst_QTextPieceTable::undoRedo8()
void tst_QTextPieceTable::undoRedo9()
{
- table->insert(0, "a", charFormatIndex);
- table->insert(1, "b", charFormatIndex);
+ table->insert(0, u"a", charFormatIndex);
+ table->insert(1, u"b", charFormatIndex);
QCOMPARE(table->plainText(), QString("ab"));
table->remove(1, 1);
@@ -455,9 +430,9 @@ void tst_QTextPieceTable::undoRedo10()
QTextBlockFormat f;
int idx = table->formatCollection()->indexForFormat(f);
- table->insert(0, "a", cfIdx);
+ table->insert(0, u"a", cfIdx);
table->insertBlock(1, idx, cfIdx);
- table->insert(1, "b", cfIdx);
+ table->insert(1, u"b", cfIdx);
cf.setForeground(Qt::red);
int newCfIdx = table->formatCollection()->indexForFormat(cf);
@@ -510,7 +485,7 @@ void tst_QTextPieceTable::checkDocumentChanged()
// single insert
layout->expect(0, 0, 15);
- table->insert(0, "012345678901234", charFormatIndex);
+ table->insert(0, u"012345678901234", charFormatIndex);
QVERIFY(!layout->error);
// single remove
@@ -521,7 +496,7 @@ void tst_QTextPieceTable::checkDocumentChanged()
// symmetric insert/remove
layout->expect(0, 0, 0);
table->beginEditBlock();
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->remove(0, 5);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -529,7 +504,7 @@ void tst_QTextPieceTable::checkDocumentChanged()
layout->expect(0, 5, 5);
table->beginEditBlock();
table->remove(0, 5);
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -537,13 +512,13 @@ void tst_QTextPieceTable::checkDocumentChanged()
layout->expect(0, 3, 5);
table->beginEditBlock();
table->remove(0, 3);
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 0, 2);
table->beginEditBlock();
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->remove(0, 3);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -551,14 +526,14 @@ void tst_QTextPieceTable::checkDocumentChanged()
// insert + remove inside insert block
layout->expect(0, 0, 2);
table->beginEditBlock();
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->remove(1, 3);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 0, 2);
table->beginEditBlock();
- table->insert(0, "01234", charFormatIndex);
+ table->insert(0, u"01234", charFormatIndex);
table->remove(2, 3);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -566,42 +541,42 @@ void tst_QTextPieceTable::checkDocumentChanged()
// insert + remove partly outside
layout->expect(0, 1, 0);
table->beginEditBlock();
- table->insert(1, "0", charFormatIndex);
+ table->insert(1, u"0", charFormatIndex);
table->remove(0, 2);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 1, 1);
table->beginEditBlock();
- table->insert(1, "01", charFormatIndex);
+ table->insert(1, u"01", charFormatIndex);
table->remove(0, 2);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 1, 2);
table->beginEditBlock();
- table->insert(1, "012", charFormatIndex);
+ table->insert(1, u"012", charFormatIndex);
table->remove(0, 2);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(1, 1, 0);
table->beginEditBlock();
- table->insert(1, "0", charFormatIndex);
+ table->insert(1, u"0", charFormatIndex);
table->remove(1, 2);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(1, 1, 1);
table->beginEditBlock();
- table->insert(1, "01", charFormatIndex);
+ table->insert(1, u"01", charFormatIndex);
table->remove(2, 2);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(1, 1, 2);
table->beginEditBlock();
- table->insert(1, "012", charFormatIndex);
+ table->insert(1, u"012", charFormatIndex);
table->remove(3, 2);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -609,14 +584,14 @@ void tst_QTextPieceTable::checkDocumentChanged()
// insert + remove non overlapping
layout->expect(0, 1, 1);
table->beginEditBlock();
- table->insert(1, "0", charFormatIndex);
+ table->insert(1, u"0", charFormatIndex);
table->remove(0, 1);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 2, 2);
table->beginEditBlock();
- table->insert(2, "1", charFormatIndex);
+ table->insert(2, u"1", charFormatIndex);
table->remove(0, 1);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -624,14 +599,14 @@ void tst_QTextPieceTable::checkDocumentChanged()
layout->expect(0, 2, 2);
table->beginEditBlock();
table->remove(0, 1);
- table->insert(1, "0", charFormatIndex);
+ table->insert(1, u"0", charFormatIndex);
table->endEditBlock();
QVERIFY(!layout->error);
layout->expect(0, 3, 3);
table->beginEditBlock();
table->remove(0, 1);
- table->insert(2, "1", charFormatIndex);
+ table->insert(2, u"1", charFormatIndex);
table->endEditBlock();
@@ -656,9 +631,9 @@ void tst_QTextPieceTable::checkDocumentChanged2()
layout->expect(0, 0, 12);
table->beginEditBlock();
- table->insert(0, "0123", charFormatIndex);
- table->insert(4, "4567", anotherCharFormatIndex);
- table->insert(8, "8901", charFormatIndex);
+ table->insert(0, u"0123", charFormatIndex);
+ table->insert(4, u"4567", anotherCharFormatIndex);
+ table->insert(8, u"8901", charFormatIndex);
table->endEditBlock();
QVERIFY(!layout->error);
@@ -721,7 +696,7 @@ void tst_QTextPieceTable::blockInsertion2()
int pos = 0;
table->insertBlock(pos, blockFormatIndex, charFormatIndex);
pos += 1;
- table->insert(pos, "a", charFormatIndex);
+ table->insert(pos, u"a", charFormatIndex);
pos += 1;
pos -= 1;
@@ -744,11 +719,11 @@ void tst_QTextPieceTable::blockRemoval1()
int idx1 = table->formatCollection()->indexForFormat(fmt1);
int idx2 = table->formatCollection()->indexForFormat(fmt2);
- table->insert(0, "0123", charFormatIndex);
+ table->insert(0, u"0123", charFormatIndex);
table->insertBlock(4, idx1, charFormatIndex);
- table->insert(5, "5678", charFormatIndex);
+ table->insert(5, u"5678", charFormatIndex);
table->insertBlock(9, idx2, charFormatIndex);
- table->insert(10, "0123", charFormatIndex);
+ table->insert(10, u"0123", charFormatIndex);
QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat());
QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat());
@@ -792,11 +767,11 @@ void tst_QTextPieceTable::blockRemoval2()
int idx1 = table->formatCollection()->indexForFormat(fmt1);
int idx2 = table->formatCollection()->indexForFormat(fmt2);
- table->insert(0, "0123", charFormatIndex);
+ table->insert(0, u"0123", charFormatIndex);
table->insertBlock(4, idx1, charFormatIndex);
- table->insert(5, "5678", charFormatIndex);
+ table->insert(5, u"5678", charFormatIndex);
table->insertBlock(9, idx2, charFormatIndex);
- table->insert(10, "0123", charFormatIndex);
+ table->insert(10, u"0123", charFormatIndex);
QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat());
QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat());
@@ -838,11 +813,11 @@ void tst_QTextPieceTable::blockRemoval3()
int idx1 = table->formatCollection()->indexForFormat(fmt1);
int idx2 = table->formatCollection()->indexForFormat(fmt2);
- table->insert(0, "0123", charFormatIndex);
+ table->insert(0, u"0123", charFormatIndex);
table->insertBlock(4, idx1, charFormatIndex);
- table->insert(5, "5678", charFormatIndex);
+ table->insert(5, u"5678", charFormatIndex);
table->insertBlock(9, idx2, charFormatIndex);
- table->insert(10, "0123", charFormatIndex);
+ table->insert(10, u"0123", charFormatIndex);
QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat());
QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat());
@@ -935,11 +910,11 @@ void tst_QTextPieceTable::blockRemoval5()
int idx1 = table->formatCollection()->indexForFormat(fmt1);
int idx2 = table->formatCollection()->indexForFormat(fmt2);
- table->insert(0, "0123", charFormatIndex);
+ table->insert(0, u"0123", charFormatIndex);
table->insertBlock(4, idx1, charFormatIndex);
- table->insert(5, "5678", charFormatIndex);
+ table->insert(5, u"5678", charFormatIndex);
table->insertBlock(9, idx2, charFormatIndex);
- table->insert(10, "0123", charFormatIndex);
+ table->insert(10, u"0123", charFormatIndex);
QCOMPARE(table->blocksFind(0).blockFormat(), QTextBlockFormat());
QCOMPARE(table->blocksFind(4).blockFormat(), QTextBlockFormat());
@@ -987,7 +962,7 @@ void tst_QTextPieceTable::checkBlockSeparation()
void tst_QTextPieceTable::checkFrames1()
{
QTextFrameFormat ffmt;
- table->insert(0, "Hello", charFormatIndex);
+ table->insert(0, u"Hello", charFormatIndex);
QPointer<QTextFrame> frame = table->insertFrame(1, 3, ffmt);
QTextFrame *root = table->rootFrame();
@@ -996,7 +971,7 @@ void tst_QTextPieceTable::checkFrames1()
QVERIFY(root);
QVERIFY(!root->parentFrame());
- QCOMPARE(root->childFrames().count(), 1);
+ QCOMPARE(root->childFrames().size(), 1);
QVERIFY(frame->format() == ffmt);
QCOMPARE(frame->firstPosition(), 2);
QCOMPARE(frame->lastPosition(), 4);
@@ -1004,10 +979,10 @@ void tst_QTextPieceTable::checkFrames1()
QPointer<QTextFrame> frame2 = table->insertFrame(2, 3, ffmt);
- QCOMPARE(root->childFrames().count(), 1);
+ QCOMPARE(root->childFrames().size(), 1);
QCOMPARE(root->childFrames().at(0), frame.data());
- QCOMPARE(frame->childFrames().count(), 1);
- QCOMPARE(frame2->childFrames().count(), 0);
+ QCOMPARE(frame->childFrames().size(), 1);
+ QCOMPARE(frame2->childFrames().size(), 0);
QCOMPARE(frame2->parentFrame(), frame.data());
QCOMPARE(frame2->firstPosition(), 3);
QCOMPARE(frame2->lastPosition(), 4);
@@ -1018,10 +993,10 @@ void tst_QTextPieceTable::checkFrames1()
table->removeFrame(frame);
- QCOMPARE(root->childFrames().count(), 1);
+ QCOMPARE(root->childFrames().size(), 1);
QCOMPARE(root->childFrames().at(0), frame2.data());
QVERIFY(!frame);
- QCOMPARE(frame2->childFrames().count(), 0);
+ QCOMPARE(frame2->childFrames().size(), 0);
QCOMPARE(frame2->parentFrame(), root);
QCOMPARE(frame2->firstPosition(), 2);
QCOMPARE(frame2->lastPosition(), 3);
@@ -1030,11 +1005,11 @@ void tst_QTextPieceTable::checkFrames1()
frame = table->frameAt(2);
- QCOMPARE(root->childFrames().count(), 1);
+ QCOMPARE(root->childFrames().size(), 1);
QCOMPARE(root->childFrames().at(0), frame.data());
- QCOMPARE(frame->childFrames().count(), 1);
+ QCOMPARE(frame->childFrames().size(), 1);
QCOMPARE(frame->childFrames().at(0), frame2.data());
- QCOMPARE(frame2->childFrames().count(), 0);
+ QCOMPARE(frame2->childFrames().size(), 0);
QCOMPARE(frame2->parentFrame(), frame.data());
QCOMPARE(frame2->firstPosition(), 3);
QCOMPARE(frame2->lastPosition(), 4);
@@ -1044,9 +1019,9 @@ void tst_QTextPieceTable::checkFrames1()
table->undo();
- QCOMPARE(root->childFrames().count(), 1);
+ QCOMPARE(root->childFrames().size(), 1);
QCOMPARE(root->childFrames().at(0), frame.data());
- QCOMPARE(frame->childFrames().count(), 0);
+ QCOMPARE(frame->childFrames().size(), 0);
QVERIFY(!frame2);
QCOMPARE(frame->firstPosition(), 2);
@@ -1056,7 +1031,7 @@ void tst_QTextPieceTable::checkFrames1()
void tst_QTextPieceTable::removeFrameDirect()
{
QTextFrameFormat ffmt;
- table->insert(0, "Hello", charFormatIndex);
+ table->insert(0, u"Hello", charFormatIndex);
QTextFrame *frame = table->insertFrame(1, 5, ffmt);
@@ -1090,7 +1065,7 @@ void tst_QTextPieceTable::removeWithChildFrame()
In this case frameAt(2) != frameAt(6), so the assertion in remove() needed an adjustement.
*/
QTextFrameFormat ffmt;
- table->insert(0, "Hello World", charFormatIndex);
+ table->insert(0, u"Hello World", charFormatIndex);
QTextFrame *frame = table->insertFrame(1, 6, ffmt);
QTextFrame *childFrame = table->insertFrame(3, 5, ffmt);
@@ -1120,7 +1095,7 @@ void tst_QTextPieceTable::clearWithFrames()
The idea is to remove from [1] until [7].
*/
QTextFrameFormat ffmt;
- table->insert(0, "Hello World", charFormatIndex);
+ table->insert(0, u"Hello World", charFormatIndex);
QTextFrame *firstFrame = table->insertFrame(1, 2, ffmt);
QTextFrame *secondFrame = table->insertFrame(4, 6, ffmt);
diff --git a/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt
index 01d418ebd4..9bb9e4c13b 100644
--- a/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtextscriptengine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtextscriptengine Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtextscriptengine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtextscriptengine
SOURCES
tst_qtextscriptengine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::GuiPrivate
diff --git a/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt b/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt
index d3b6b1dc6d..db284b2e1c 100644
--- a/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt
+++ b/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from generate.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## generate Binary:
@@ -9,9 +10,8 @@ qt_internal_add_executable(generate
SOURCES
main.cpp
INCLUDE_DIRECTORIES
- .
/usr/include/freetype2
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Gui
)
diff --git a/tests/auto/gui/text/qtextscriptengine/generate/main.cpp b/tests/auto/gui/text/qtextscriptengine/generate/main.cpp
index 708864521a..5082c2b406 100644
--- a/tests/auto/gui/text/qtextscriptengine/generate/main.cpp
+++ b/tests/auto/gui/text/qtextscriptengine/generate/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QApplication>
diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp
index b3a33c2d92..975658005e 100644
--- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp
+++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <private/qfontengine_p.h>
@@ -1119,11 +1094,12 @@ void tst_QTextScriptEngine::combiningMarks_qtbug15675_data()
bool hasTests = false;
- QStringList families;
- families << QStringLiteral("Monaco");
- families << QStringLiteral("DejaVu Sans Mono");
+ const QString families[] = {
+ QStringLiteral("Monaco"),
+ QStringLiteral("DejaVu Sans Mono"),
+ };
- foreach (const QString &family, families) {
+ for (const QString &family : families) {
QFont font(family);
font.setStyleStrategy(QFont::NoFontMerging);
if (QFontInfo(font).family() != family)
diff --git a/tests/auto/gui/text/qtexttable/CMakeLists.txt b/tests/auto/gui/text/qtexttable/CMakeLists.txt
index 94d33d3530..e83a38f087 100644
--- a/tests/auto/gui/text/qtexttable/CMakeLists.txt
+++ b/tests/auto/gui/text/qtexttable/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qtexttable.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtexttable Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtexttable LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qtexttable
SOURCES
tst_qtexttable.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
)
@@ -16,6 +23,6 @@ qt_internal_add_test(tst_qtexttable
#####################################################################
qt_internal_extend_target(tst_qtexttable CONDITION TARGET Qt::Widgets
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Widgets
)
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index dabe51f833..6fb5858c64 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -1,35 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
-
+#include <qbuffer.h>
#include <qtextdocument.h>
#include <qtextdocumentfragment.h>
#include <qtexttable.h>
@@ -44,6 +19,7 @@
#include <QPainter>
#include <QPaintEngine>
#endif
+#include <private/qtextdocumentlayout_p.h>
#include <private/qpagedpaintdevice_p.h>
typedef QList<int> IntList;
@@ -100,6 +76,13 @@ private slots:
void checkBorderAttributes_data();
void checkBorderAttributes();
+#ifndef QT_NO_WIDGETS
+ void columnWidthWithSpans();
+
+ void columnWidthWithImage_data();
+ void columnWidthWithImage();
+#endif
+
private:
QTextTable *create2x2Table();
QTextTable *create4x4Table();
@@ -138,7 +121,7 @@ void tst_QTextTable::variousTableModifications()
QTextTableFormat tableFmt;
QTextTable *tab = cursor.insertTable(2, 2, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
QCOMPARE(tab, cursor.currentTable());
QCOMPARE(tab->columns(), 2);
QCOMPARE(tab->rows(), 2);
@@ -193,14 +176,14 @@ void tst_QTextTable::variousTableModifications()
cursor.movePosition(QTextCursor::NextBlock);
QCOMPARE(cursor.position(), 1);
cursor.deleteChar();
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
cursor.movePosition(QTextCursor::NextBlock);
QCOMPARE(cursor.position(), 2);
cursor.deleteChar();
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
cursor.deletePreviousChar();
QCOMPARE(cursor.position(), 2);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
QTextTable *table = cursor.currentTable();
QCOMPARE(table->rows(), 2);
@@ -209,16 +192,16 @@ void tst_QTextTable::variousTableModifications()
table->insertRows(2, 1);
QCOMPARE(table->rows(), 3);
QCOMPARE(table->columns(), 2);
- QCOMPARE(doc->toPlainText().length(), 7);
+ QCOMPARE(doc->toPlainText().size(), 7);
table->insertColumns(2, 2);
QCOMPARE(table->rows(), 3);
QCOMPARE(table->columns(), 4);
- QCOMPARE(doc->toPlainText().length(), 13);
+ QCOMPARE(doc->toPlainText().size(), 13);
table->resize(4, 5);
QCOMPARE(table->rows(), 4);
QCOMPARE(table->columns(), 5);
- QCOMPARE(doc->toPlainText().length(), 21);
+ QCOMPARE(doc->toPlainText().size(), 21);
}
void tst_QTextTable::tableShrinking()
@@ -226,7 +209,7 @@ void tst_QTextTable::tableShrinking()
QTextTableFormat tableFmt;
cursor.insertTable(3, 4, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 13);
+ QCOMPARE(doc->toPlainText().size(), 13);
QTextTable *table = cursor.currentTable();
QCOMPARE(table->rows(), 3);
@@ -235,16 +218,16 @@ void tst_QTextTable::tableShrinking()
table->removeRows(1, 1);
QCOMPARE(table->rows(), 2);
QCOMPARE(table->columns(), 4);
- QCOMPARE(doc->toPlainText().length(), 9);
+ QCOMPARE(doc->toPlainText().size(), 9);
table->removeColumns(1, 2);
QCOMPARE(table->rows(), 2);
QCOMPARE(table->columns(), 2);
- QCOMPARE(doc->toPlainText().length(), 5);
+ QCOMPARE(doc->toPlainText().size(), 5);
table->resize(1, 1);
QCOMPARE(table->rows(), 1);
QCOMPARE(table->columns(), 1);
- QCOMPARE(doc->toPlainText().length(), 2);
+ QCOMPARE(doc->toPlainText().size(), 2);
}
void tst_QTextTable::spans()
@@ -269,7 +252,7 @@ void tst_QTextTable::variousModifications2()
QTextTableFormat tableFmt;
cursor.insertTable(2, 5, tableFmt);
- QCOMPARE(doc->toPlainText().length(), 11);
+ QCOMPARE(doc->toPlainText().size(), 11);
QTextTable *table = cursor.currentTable();
QCOMPARE(cursor.position(), 1);
QCOMPARE(table->rows(), 2);
@@ -1165,8 +1148,8 @@ void tst_QTextTable::QTBUG31330_renderBackground()
doc.print(&paintDevice);
QVERIFY(paintDevice.pages >= 2);
- QCOMPARE(engine.rects.count(), paintDevice.pages);
- for (int i = 0; i < engine.rects.count(); ++i) {
+ QCOMPARE(engine.rects.size(), paintDevice.pages);
+ for (int i = 0; i < engine.rects.size(); ++i) {
QRectF rect = engine.rects[i];
QVERIFY(rect.top() > 0);
QVERIFY(rect.bottom() < 1000);
@@ -1278,5 +1261,84 @@ void tst_QTextTable::checkBorderAttributes()
}
}
+#ifndef QT_NO_WIDGETS
+void tst_QTextTable::columnWidthWithSpans()
+{
+ cleanup();
+ init();
+ QTextTable *table = cursor.insertTable(4, 4);
+ QTextEdit textEdit;
+ textEdit.setDocument(doc);
+ textEdit.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&textEdit));
+
+ for (int i = 0; i < table->columns(); ++i)
+ table->cellAt(0, i).firstCursorPosition().insertText(QString("Header %1").arg(i));
+
+ QTextBlock block = table->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF beforeRect = table->document()->documentLayout()->blockBoundingRect(block);
+ table->mergeCells(1, 0, 1, table->columns());
+ block = table->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF afterRect = table->document()->documentLayout()->blockBoundingRect(block);
+ QCOMPARE(afterRect, beforeRect);
+}
+
+void tst_QTextTable::columnWidthWithImage_data()
+{
+ const auto imageHtml = [](int width, int height) {
+ QImage image(width, height, QImage::Format_RGB32);
+ image.fill(Qt::red);
+ QByteArray imageBytes;
+ QBuffer buffer(&imageBytes);
+ buffer.open(QIODevice::WriteOnly);
+ image.save(&buffer, "png");
+ return QString("<td><img src='data:image/png;base64,%1'/></td>").arg(imageBytes.toBase64());
+ };
+
+ QTest::addColumn<QString>("leftHtml");
+ QTest::addColumn<QString>("rightHtml");
+ QTest::addColumn<QSize>("imageSize");
+ QTest::addRow("image")
+ << imageHtml(500, 32) << "<td></td>" << QSize(500, 32);
+ QTest::addRow("image, text")
+ << imageHtml(32, 32) << "<td>abc</td>" << QSize(32, 32);
+ QTest::addRow("image, 100%% text")
+ << imageHtml(32, 32) << "<td style='background-color: grey' width='100%'>abc</td>"
+ << QSize(32, 32);
+ QTest::addRow("image, image")
+ << imageHtml(256, 32) << imageHtml(256, 32) << QSize(256, 32);
+}
+
+void tst_QTextTable::columnWidthWithImage()
+{
+ const QString tableTemplate = "<table><tr>%1 %2</tr></table>";
+
+ QFETCH(QString, leftHtml);
+ QFETCH(QString, rightHtml);
+ QFETCH(QSize, imageSize);
+
+ QTextDocument doc;
+ doc.setHtml(tableTemplate.arg(leftHtml).arg(rightHtml));
+ QTextEdit textEdit;
+ textEdit.setDocument(&doc);
+ textEdit.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&textEdit));
+
+ QTextCursor cursor(doc.firstBlock());
+ cursor.movePosition(QTextCursor::Right);
+
+ QTextTable *currentTable = cursor.currentTable();
+ QVERIFY(currentTable);
+
+ QTextBlock block = currentTable->cellAt(0, 0).firstCursorPosition().block();
+ const QRectF leftRect = currentTable->document()->documentLayout()->blockBoundingRect(block);
+ block = currentTable->cellAt(0, 1).firstCursorPosition().block();
+ const QRectF rightRect = currentTable->document()->documentLayout()->blockBoundingRect(block);
+ QCOMPARE(leftRect.size().toSize(), imageSize);
+ QVERIFY(rightRect.left() > leftRect.right());
+}
+#endif
+
+
QTEST_MAIN(tst_QTextTable)
#include "tst_qtexttable.moc"
diff --git a/tests/auto/gui/text/qzip/.gitignore b/tests/auto/gui/text/qzip/.gitignore
deleted file mode 100644
index 2d7dfbe70c..0000000000
--- a/tests/auto/gui/text/qzip/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-tst_qzip
diff --git a/tests/auto/gui/text/qzip/CMakeLists.txt b/tests/auto/gui/text/qzip/CMakeLists.txt
deleted file mode 100644
index 7240a611d2..0000000000
--- a/tests/auto/gui/text/qzip/CMakeLists.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-# Generated from qzip.pro.
-
-#####################################################################
-## tst_qzip Test:
-#####################################################################
-
-# Collect test data
-list(APPEND test_data "testdata")
-
-qt_internal_add_test(tst_qzip
- SOURCES
- tst_qzip.cpp
- PUBLIC_LIBRARIES
- Qt::Gui
- Qt::GuiPrivate
- TESTDATA ${test_data}
-)
-
-## Scopes:
-#####################################################################
-
-if(ANDROID)
- # Resources:
- set(testdata_resource_files
- "testdata/symlink.zip"
- "testdata/test.zip"
- )
-
- qt_internal_add_resource(tst_qzip "testdata"
- PREFIX
- "/"
- FILES
- ${testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/gui/text/qzip/testdata.qrc b/tests/auto/gui/text/qzip/testdata.qrc
deleted file mode 100644
index c7e3a6b14e..0000000000
--- a/tests/auto/gui/text/qzip/testdata.qrc
+++ /dev/null
@@ -1,6 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>testdata/symlink.zip</file>
- <file>testdata/test.zip</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/text/qzip/testdata/symlink.zip b/tests/auto/gui/text/qzip/testdata/symlink.zip
deleted file mode 100644
index 027f96477a..0000000000
--- a/tests/auto/gui/text/qzip/testdata/symlink.zip
+++ /dev/null
Binary files differ
diff --git a/tests/auto/gui/text/qzip/testdata/test.zip b/tests/auto/gui/text/qzip/testdata/test.zip
deleted file mode 100644
index a57ba4e2a9..0000000000
--- a/tests/auto/gui/text/qzip/testdata/test.zip
+++ /dev/null
Binary files differ
diff --git a/tests/auto/gui/text/qzip/tst_qzip.cpp b/tests/auto/gui/text/qzip/tst_qzip.cpp
deleted file mode 100644
index 6be7c7b833..0000000000
--- a/tests/auto/gui/text/qzip/tst_qzip.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QTest>
-#include <QDebug>
-#include <QBuffer>
-
-#include <private/qzipwriter_p.h>
-#include <private/qzipreader_p.h>
-
-class tst_QZip : public QObject
-{
- Q_OBJECT
-
-private slots:
- void basicUnpack();
- void symlinks();
- void readTest();
- void createArchive();
-};
-
-void tst_QZip::basicUnpack()
-{
- QZipReader zip(QFINDTESTDATA("/testdata/test.zip"), QIODevice::ReadOnly);
- QList<QZipReader::FileInfo> files = zip.fileInfoList();
- QCOMPARE(files.count(), 2);
-
- QZipReader::FileInfo fi = files.at(0);
- QVERIFY(fi.isValid());
- QCOMPARE(fi.filePath, QString("test"));
- QCOMPARE(uint(fi.isDir), (uint) 1);
- QCOMPARE(uint(fi.isFile), (uint) 0);
- QCOMPARE(uint(fi.isSymLink), (uint) 0);
-
- QCOMPARE(fi.permissions,QFile::Permissions( QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner
- | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser ));
-
- QCOMPARE(fi.lastModified, QDateTime::fromString("2005.11.11 13:08:02", "yyyy.MM.dd HH:mm:ss"));
-
- fi = files.at(1);
- QVERIFY(fi.isValid());
- QCOMPARE(fi.filePath, QString("test/test.txt"));
- QCOMPARE(uint(fi.isDir), (uint) 0);
- QCOMPARE(uint(fi.isFile), (uint) 1);
- QCOMPARE(uint(fi.isSymLink), (uint) 0);
-
- QVERIFY(fi.permissions == QFile::Permissions( QFile::ReadOwner | QFile::WriteOwner
- | QFile::ReadUser | QFile::WriteUser ));
-
- QCOMPARE(fi.lastModified, QDateTime::fromString("2005.11.11 13:08:02", "yyyy.MM.dd HH:mm:ss"));
-
- QCOMPARE(zip.fileData("test/test.txt"), QByteArray("content\n"));
-
- fi = zip.entryInfoAt(-1);
- QVERIFY(!fi.isValid());
-}
-
-void tst_QZip::symlinks()
-{
- QZipReader zip(QFINDTESTDATA("/testdata/symlink.zip"), QIODevice::ReadOnly);
- QList<QZipReader::FileInfo> files = zip.fileInfoList();
- QCOMPARE(files.count(), 2);
-
- QZipReader::FileInfo fi = files.at(0);
- QVERIFY(fi.isValid());
- QCOMPARE(fi.filePath, QString("symlink"));
- QVERIFY(!fi.isDir);
- QVERIFY(!fi.isFile);
- QVERIFY(fi.isSymLink);
-
- QCOMPARE(zip.fileData("symlink"), QByteArray("destination"));
-
- fi = files.at(1);
- QVERIFY(fi.isValid());
- QCOMPARE(fi.filePath, QString("destination"));
- QVERIFY(!fi.isDir);
- QVERIFY(fi.isFile);
- QVERIFY(!fi.isSymLink);
-}
-
-void tst_QZip::readTest()
-{
- QZipReader zip("foobar.zip", QIODevice::ReadOnly); // non existing file.
- QList<QZipReader::FileInfo> files = zip.fileInfoList();
- QCOMPARE(files.count(), 0);
- QByteArray b = zip.fileData("foobar");
- QCOMPARE(b.size(), 0);
-}
-
-void tst_QZip::createArchive()
-{
- QBuffer buffer;
- QZipWriter zip(&buffer);
- QByteArray fileContents("simple file contents\nline2\n");
- zip.addFile("My Filename", fileContents);
- zip.close();
- QByteArray zipFile = buffer.buffer();
-
- // QFile f("createArchiveTest.zip"); f.open(QIODevice::WriteOnly); f.write(zipFile); f.close();
-
- QBuffer buffer2(&zipFile);
- QZipReader zip2(&buffer2);
- QList<QZipReader::FileInfo> files = zip2.fileInfoList();
- QCOMPARE(files.count(), 1);
- QZipReader::FileInfo file = files.at(0);
- QCOMPARE(file.filePath, QString("My Filename"));
- QCOMPARE(uint(file.isDir), (uint) 0);
- QCOMPARE(uint(file.isFile), (uint) 1);
- QCOMPARE(uint(file.isSymLink), (uint) 0);
- QCOMPARE(file.permissions, QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser) );
- QCOMPARE(file.size, (long long) 27);
- QCOMPARE(zip2.fileData("My Filename"), fileContents);
-}
-
-QTEST_MAIN(tst_QZip)
-#include "tst_qzip.moc"
diff --git a/tests/auto/gui/util/CMakeLists.txt b/tests/auto/gui/util/CMakeLists.txt
index 048e18360c..830a9ff2f0 100644
--- a/tests/auto/gui/util/CMakeLists.txt
+++ b/tests/auto/gui/util/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from util.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qdesktopservices)
add_subdirectory(qdoublevalidator)
diff --git a/tests/auto/gui/util/qdesktopservices/CMakeLists.txt b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt
index 475a3405c0..64a1aaa930 100644
--- a/tests/auto/gui/util/qdesktopservices/CMakeLists.txt
+++ b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt
@@ -1,14 +1,19 @@
-# Generated from qdesktopservices.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qdesktopservices Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qdesktopservices LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qdesktopservices
SOURCES
tst_qdesktopservices.cpp
- DEFINES
- # QT_DISABLE_DEPRECATED_BEFORE=0 # special case
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
index 7446f8ed9f..e08b299209 100644
--- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
+++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp
@@ -1,36 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <qdesktopservices.h>
#include <qregularexpression.h>
+using namespace Qt::StringLiterals;
+
class tst_qdesktopservices : public QObject
{
Q_OBJECT
@@ -65,6 +42,10 @@ public slots:
}
};
+#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
+# define CAN_IMPLICITLY_UNSET
+#endif
+
void tst_qdesktopservices::handlers()
{
MyUrlHandler fooHandler;
@@ -72,6 +53,12 @@ void tst_qdesktopservices::handlers()
QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle");
QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle");
+#ifndef CAN_IMPLICITLY_UNSET
+ const auto unsetHandlers = qScopeGuard([] {
+ QDesktopServices::unsetUrlHandler(u"bar"_s);
+ QDesktopServices::unsetUrlHandler(u"foo"_s);
+ });
+#endif
QUrl fooUrl("foo://blub/meh");
QUrl barUrl("bar://hmm/hmmmm");
@@ -81,6 +68,15 @@ void tst_qdesktopservices::handlers()
QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString());
QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString());
+
+#ifdef CAN_IMPLICITLY_UNSET
+ for (int i = 0; i < 2; ++i)
+ QTest::ignoreMessage(QtWarningMsg,
+ "Please call QDesktopServices::unsetUrlHandler() before destroying a "
+ "registered URL handler object.\n"
+ "Support for destroying a registered URL handler object is deprecated, "
+ "and will be removed in Qt 6.6.");
+#endif
}
QTEST_MAIN(tst_qdesktopservices)
diff --git a/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt
index 27996300d7..f79fe8b00c 100644
--- a/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt
+++ b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qdoublevalidator.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qdoublevalidator Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qdoublevalidator LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qdoublevalidator
SOURCES
tst_qdoublevalidator.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp
index 77d52682f6..b44975ea0b 100644
--- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp
+++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -168,6 +143,7 @@ void tst_QDoubleValidator::validate_data()
QTest::newRow("data56") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+") << ITM << INV;
QTest::newRow("data57") << "C" << 1229.0 << 1231.0 << -1 << QString("123E+1") << ACC << INV;
QTest::newRow("data58") << "C" << 0.0 << 100.0 << -1 << QString("0.0") << ACC << ACC;
+ QTest::newRow("overlong") << "C" << 0.0 << 99.9 << 2 << QString("1234.0") << ITM << INV;
QTest::newRow("data_de0") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC;
QTest::newRow("data_de1") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM;
@@ -335,74 +311,74 @@ void tst_QDoubleValidator::notifySignals()
QCOMPARE(dv.decimals(), 10);
dv.setTop(0.8);
- QCOMPARE(topSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
+ QCOMPARE(topSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
QCOMPARE(dv.top(), 0.8);
dv.setBottom(0.2);
- QCOMPARE(bottomSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 2);
+ QCOMPARE(bottomSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 2);
QCOMPARE(dv.bottom(), 0.2);
dv.setRange(0.2, 0.7);
- QCOMPARE(topSpy.count(), 2);
- QCOMPARE(bottomSpy.count(), 1);
- QCOMPARE(decSpy.count(), 0);
- QCOMPARE(changedSpy.count(), 3);
+ QCOMPARE(topSpy.size(), 2);
+ QCOMPARE(bottomSpy.size(), 1);
+ QCOMPARE(decSpy.size(), 0);
+ QCOMPARE(changedSpy.size(), 3);
QCOMPARE(dv.bottom(), 0.2);
QCOMPARE(dv.top(), 0.7);
QCOMPARE(dv.decimals(), 10);
dv.setRange(0.3, 0.7);
- QCOMPARE(topSpy.count(), 2);
- QCOMPARE(bottomSpy.count(), 2);
- QCOMPARE(changedSpy.count(), 4);
+ QCOMPARE(topSpy.size(), 2);
+ QCOMPARE(bottomSpy.size(), 2);
+ QCOMPARE(changedSpy.size(), 4);
QCOMPARE(dv.bottom(), 0.3);
QCOMPARE(dv.top(), 0.7);
QCOMPARE(dv.decimals(), 10);
dv.setRange(0.4, 0.6);
- QCOMPARE(topSpy.count(), 3);
- QCOMPARE(bottomSpy.count(), 3);
- QCOMPARE(changedSpy.count(), 5);
+ QCOMPARE(topSpy.size(), 3);
+ QCOMPARE(bottomSpy.size(), 3);
+ QCOMPARE(changedSpy.size(), 5);
QCOMPARE(dv.bottom(), 0.4);
QCOMPARE(dv.top(), 0.6);
QCOMPARE(dv.decimals(), 10);
dv.setDecimals(5);
- QCOMPARE(decSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 6);
+ QCOMPARE(decSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 6);
QCOMPARE(dv.decimals(), 5);
dv.setRange(0.4, 0.6, 100);
- QCOMPARE(topSpy.count(), 3);
- QCOMPARE(bottomSpy.count(), 3);
- QCOMPARE(decSpy.count(), 2);
- QCOMPARE(changedSpy.count(), 7);
+ QCOMPARE(topSpy.size(), 3);
+ QCOMPARE(bottomSpy.size(), 3);
+ QCOMPARE(decSpy.size(), 2);
+ QCOMPARE(changedSpy.size(), 7);
QCOMPARE(dv.bottom(), 0.4);
QCOMPARE(dv.top(), 0.6);
QCOMPARE(dv.decimals(), 100);
dv.setNotation(QDoubleValidator::StandardNotation);
- QCOMPARE(notSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 8);
+ QCOMPARE(notSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 8);
QCOMPARE(dv.notation(), QDoubleValidator::StandardNotation);
dv.setRange(dv.bottom(), dv.top(), dv.decimals());
- QCOMPARE(topSpy.count(), 3);
- QCOMPARE(bottomSpy.count(), 3);
- QCOMPARE(decSpy.count(), 2);
- QCOMPARE(changedSpy.count(), 8);
+ QCOMPARE(topSpy.size(), 3);
+ QCOMPARE(bottomSpy.size(), 3);
+ QCOMPARE(decSpy.size(), 2);
+ QCOMPARE(changedSpy.size(), 8);
dv.setNotation(dv.notation());
- QCOMPARE(notSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 8);
+ QCOMPARE(notSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 8);
dv.setLocale(QLocale("C"));
- QCOMPARE(changedSpy.count(), 8);
+ QCOMPARE(changedSpy.size(), 8);
dv.setLocale(QLocale("en"));
- QCOMPARE(changedSpy.count(), 9);
+ QCOMPARE(changedSpy.size(), 9);
}
void tst_QDoubleValidator::fixup()
@@ -441,7 +417,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("C standard with invalid digit grouping")
<< "C" << QDoubleValidator::StandardNotation << -1 << "1,234,5.678"
<< "12345.678";
- QTest::newRow("C standard with invalid number of decimals")
+ QTest::newRow("C standard with invalid group size")
<< "C" << QDoubleValidator::StandardNotation << 2 << "-12,34.678"
<< "-1234.68";
QTest::newRow("C standard truncate decimals")
@@ -470,7 +446,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("C scientific with invalid digit grouping")
<< "C" << QDoubleValidator::ScientificNotation << -1 << "12,34.98765e2"
<< "1.23498765e+05";
- QTest::newRow("C scientific with invalid number of decimals")
+ QTest::newRow("C scientific with invalid group size")
<< "C" << QDoubleValidator::ScientificNotation << 2 << "-12,34.98765e2"
<< "-1.23e+05";
QTest::newRow("C scientific truncate decimals")
@@ -510,7 +486,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("en standard with invalid digit grouping")
<< "en" << QDoubleValidator::StandardNotation << -1 << "-1,234,5.678"
<< "-12,345.678";
- QTest::newRow("en standard with invalid number of decimals")
+ QTest::newRow("en standard with invalid group size")
<< "en" << QDoubleValidator::StandardNotation << 2 << "12,34.678"
<< "1,234.68";
QTest::newRow("en standard no fractional part")
@@ -526,7 +502,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("en scientific with invalid digit grouping")
<< "en" << QDoubleValidator::ScientificNotation << -1 << "-12,34.98765e2"
<< "-1.23498765E+05";
- QTest::newRow("en scientific with invalid number of decimals")
+ QTest::newRow("en scientific with invalid group size")
<< "en" << QDoubleValidator::ScientificNotation << 2 << "12,34.98765e2"
<< "1.23E+05";
QTest::newRow("en scientific no fractional part")
@@ -553,7 +529,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("de standard with invalid digit grouping")
<< "de" << QDoubleValidator::StandardNotation << -1 << "1.234.5,678"
<< "12.345,678";
- QTest::newRow("de standard with invalid number of decimals")
+ QTest::newRow("de standard with invalid group size")
<< "de" << QDoubleValidator::StandardNotation << 2 << "-12.34,678"
<< "-1.234,68";
QTest::newRow("de standard no fractional part")
@@ -568,7 +544,7 @@ void tst_QDoubleValidator::fixup_data()
QTest::newRow("de scientific with invalid digit grouping")
<< "de" << QDoubleValidator::ScientificNotation << -1 << "12.34,98765e2"
<< "1,23498765E+05";
- QTest::newRow("de scientific with invalid number of decimals")
+ QTest::newRow("de scientific with invalid group size")
<< "de" << QDoubleValidator::ScientificNotation << 2 << "-12.34,98765e2"
<< "-1,23E+05";
QTest::newRow("de scientific no fractional part")
@@ -584,6 +560,22 @@ void tst_QDoubleValidator::fixup_data()
<< "de" << QDoubleValidator::ScientificNotation << -1 << "-12.34"
<< "-1,234E+03";
+ // es locale uses ',' as decimal point and '.' as grouping separator.
+ // It doesn't apply grouping unless the the next-to-least significant group
+ // has more than one digit in it.
+ QTest::newRow("es standard no digit grouping")
+ << "es" << QDoubleValidator::StandardNotation << -1 << "1234,567" << "1234,567";
+ QTest::newRow("es standard with digit grouping")
+ << "es" << QDoubleValidator::StandardNotation << -1 << "-12.345,678" << "-12.345,678";
+ QTest::newRow("es standard with invalid group size")
+ << "es" << QDoubleValidator::StandardNotation << -1 << "1.234.5,678" << "12.345,678";
+ QTest::newRow("es standard with invalid digit grouping")
+ << "es" << QDoubleValidator::StandardNotation << 2 << "-1.234,678" << "-1234,68";
+ QTest::newRow("es standard big with invalid digit grouping")
+ << "es" << QDoubleValidator::StandardNotation << 2 << "-1234.678,9" << "-1.234.678,9";
+ QTest::newRow("es standard no fractional part")
+ << "es" << QDoubleValidator::StandardNotation << -1 << "12.34" << "1234";
+
// hi locale uses '.' as decimal point and ',' as grouping separator.
// The rightmost group is of three digits, all the others contain two
// digits.
@@ -666,7 +658,7 @@ void tst_QDoubleValidator::setRangeOverloads_data()
QTest::newRow("scientific, 1 digits after point")
<< QDoubleValidator::ScientificNotation << -1 << -100.0 << 100.0 << 0
<< QString("1.2e1") << ACC << INV;
- QTest::newRow("scientific, 3 digits after point, not in range")
+ QTest::newRow("scientific, 3 digits after point, demand fewer")
<< QDoubleValidator::ScientificNotation << 3 << -100.0 << 100.0 << 1
<< QString("10.234e-1") << ACC << INV;
QTest::newRow("scientific, 3 digits after point, not in range")
diff --git a/tests/auto/gui/util/qintvalidator/CMakeLists.txt b/tests/auto/gui/util/qintvalidator/CMakeLists.txt
index 83891a3541..841b83a8e0 100644
--- a/tests/auto/gui/util/qintvalidator/CMakeLists.txt
+++ b/tests/auto/gui/util/qintvalidator/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qintvalidator.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qintvalidator Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qintvalidator LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qintvalidator
SOURCES
tst_qintvalidator.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp
index 48b04cef14..bfa69c90b8 100644
--- a/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp
+++ b/tests/auto/gui/util/qintvalidator/tst_qintvalidator.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -190,8 +165,10 @@ void tst_QIntValidator::validateFrench()
QIntValidator validator(-2000, 2000, 0);
validator.setLocale(QLocale::French);
int i;
+ // Grouping separator is a narrow no-break space; QLocale accepts a space as it.
QString s = QLatin1String("1 ");
- QCOMPARE(validator.validate(s, i), QValidator::Acceptable);
+ // Shouldn't end with a group separator
+ QCOMPARE(validator.validate(s, i), QValidator::Intermediate);
validator.fixup(s);
QCOMPARE(s, s);
@@ -236,45 +213,45 @@ void tst_QIntValidator::notifySignals()
QSignalSpy changedSpy(&iv, SIGNAL(changed()));
iv.setTop(9);
- QCOMPARE(topSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
+ QCOMPARE(topSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
QCOMPARE(iv.top(), 9);
iv.setBottom(1);
- QCOMPARE(bottomSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 2);
+ QCOMPARE(bottomSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 2);
QCOMPARE(iv.bottom(), 1);
iv.setRange(1, 8);
- QCOMPARE(topSpy.count(), 2);
- QCOMPARE(bottomSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 3);
+ QCOMPARE(topSpy.size(), 2);
+ QCOMPARE(bottomSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 3);
QCOMPARE(iv.top(), 8);
QCOMPARE(iv.bottom(), 1);
iv.setRange(2, 8);
- QCOMPARE(topSpy.count(), 2);
- QCOMPARE(bottomSpy.count(), 2);
- QCOMPARE(changedSpy.count(), 4);
+ QCOMPARE(topSpy.size(), 2);
+ QCOMPARE(bottomSpy.size(), 2);
+ QCOMPARE(changedSpy.size(), 4);
QCOMPARE(iv.top(), 8);
QCOMPARE(iv.bottom(), 2);
iv.setRange(3, 7);
- QCOMPARE(topSpy.count(), 3);
- QCOMPARE(bottomSpy.count(), 3);
- QCOMPARE(changedSpy.count(), 5);
+ QCOMPARE(topSpy.size(), 3);
+ QCOMPARE(bottomSpy.size(), 3);
+ QCOMPARE(changedSpy.size(), 5);
QCOMPARE(iv.top(), 7);
QCOMPARE(iv.bottom(), 3);
iv.setRange(3, 7);
- QCOMPARE(topSpy.count(), 3);
- QCOMPARE(bottomSpy.count(), 3);
- QCOMPARE(changedSpy.count(), 5);
+ QCOMPARE(topSpy.size(), 3);
+ QCOMPARE(bottomSpy.size(), 3);
+ QCOMPARE(changedSpy.size(), 5);
iv.setLocale(QLocale("C"));
- QCOMPARE(changedSpy.count(), 5);
+ QCOMPARE(changedSpy.size(), 5);
iv.setLocale(QLocale("en"));
- QCOMPARE(changedSpy.count(), 6);
+ QCOMPARE(changedSpy.size(), 6);
}
void tst_QIntValidator::fixup()
@@ -331,9 +308,9 @@ void tst_QIntValidator::fixup_data()
// Normally the groups contain three digits, but the leftmost group should
// have at least two digits.
QTest::newRow("es no digit grouping 1000") << "es" << "1000" << "1000";
- QTest::newRow("es no digit grouping 10000") << "es" << "10000" << "10.000";
- QTest::newRow("es with digit grouping") << "es" << "1000.000" << "1000.000";
- QTest::newRow("es invalid digit grouping") << "es" << "1.000.000" << "1000.000";
+ QTest::newRow("es with digit grouping 10000") << "es" << "10000" << "10.000";
+ QTest::newRow("es with digit grouping million") << "es" << "1.000.000" << "1.000.000";
+ QTest::newRow("es invalid digit grouping") << "es" << "1000.000" << "1.000.000";
}
QTEST_APPLESS_MAIN(tst_QIntValidator)
diff --git a/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt
index 9caf7a1596..1d48205537 100644
--- a/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt
+++ b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qregularexpressionvalidator.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qregularexpressionvalidator Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qregularexpressionvalidator LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qregularexpressionvalidator
SOURCES
tst_qregularexpressionvalidator.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
index 0d1d748e00..17f9e6a1bd 100644
--- a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
+++ b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui/QRegularExpressionValidator>
#include <QTest>
@@ -98,12 +73,12 @@ void tst_QRegularExpressionValidator::validate()
QTEST(result, "state");
if (result == QValidator::Invalid)
- QCOMPARE(pos, value.length());
+ QCOMPARE(pos, value.size());
else
QCOMPARE(pos, -1); // ensure pos is not modified if validate returned Acceptable or Intermediate
- QCOMPARE(spy.count(), signalCount);
- QCOMPARE(changedSpy.count(), signalCount);
+ QCOMPARE(spy.size(), signalCount);
+ QCOMPARE(changedSpy.size(), signalCount);
}
QTEST_GUILESS_MAIN(tst_QRegularExpressionValidator)
diff --git a/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt
index de809f577d..70e2c02417 100644
--- a/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt
+++ b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt
@@ -1,16 +1,15 @@
-# Generated from qtexturefilereader.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtexturefilereader Test:
#####################################################################
-qt_internal_add_test(tst_qtexturefilereader
- SOURCES
- tst_qtexturefilereader.cpp
- PUBLIC_LIBRARIES
- Qt::Gui
- Qt::GuiPrivate
-)
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtexturefilereader LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
# Resources:
set(qtexturefilereader_resource_files
@@ -18,15 +17,19 @@ set(qtexturefilereader_resource_files
"texturefiles/car_mips.ktx"
"texturefiles/cubemap_float32_rgba.ktx"
"texturefiles/cubemap_metadata.ktx"
+ "texturefiles/invalid.ktx"
"texturefiles/newlogo.astc"
"texturefiles/newlogo_srgb.astc"
"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
+ LIBRARIES
+ Qt::Gui
+ Qt::GuiPrivate
+ TESTDATA ${qtexturefilereader_resource_files}
+ BUILTIN_TESTDATA
)
diff --git a/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc b/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc
deleted file mode 100644
index c4cef6cc44..0000000000
--- a/tests/auto/gui/util/qtexturefilereader/qtexturefilereader.qrc
+++ /dev/null
@@ -1,11 +0,0 @@
-<RCC>
- <qresource prefix="/">
- <file>texturefiles/car.ktx</file>
- <file>texturefiles/cubemap_float32_rgba.ktx</file>
- <file>texturefiles/cubemap_metadata.ktx</file>
- <file>texturefiles/pattern.pkm</file>
- <file>texturefiles/car_mips.ktx</file>
- <file>texturefiles/newlogo_srgb.astc</file>
- <file>texturefiles/newlogo.astc</file>
- </qresource>
-</RCC>
diff --git a/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx b/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx
new file mode 100644
index 0000000000..68a92221db
--- /dev/null
+++ b/tests/auto/gui/util/qtexturefilereader/texturefiles/invalid.ktx
Binary files differ
diff --git a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp
index 89144eb245..62760e3844 100644
--- a/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp
+++ b/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2018 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <private/qtexturefilereader_p.h>
#include <QTest>
@@ -36,6 +11,7 @@ class tst_qtexturefilereader : public QObject
private slots:
void checkHandlers_data();
void checkHandlers();
+ void checkInvalid();
void checkMetadata();
};
@@ -165,6 +141,18 @@ void tst_qtexturefilereader::checkMetadata()
QCOMPARE(kvs.value("test C"), QByteArrayLiteral("3\x0000"));
}
+void tst_qtexturefilereader::checkInvalid()
+{
+ QFile f(":/texturefiles/invalid.ktx");
+ QVERIFY(f.open(QIODevice::ReadOnly));
+ QTextureFileReader r(&f);
+ QTextureFileData d = r.read();
+ auto kvs = d.keyValueMetadata();
+
+ // Basically just checking that we don't crash on and invalid file
+ QVERIFY(kvs.empty());
+}
+
QTEST_MAIN(tst_qtexturefilereader)
#include "tst_qtexturefilereader.moc"
diff --git a/tests/auto/gui/util/qundogroup/CMakeLists.txt b/tests/auto/gui/util/qundogroup/CMakeLists.txt
index c1396326f7..98c2f64f88 100644
--- a/tests/auto/gui/util/qundogroup/CMakeLists.txt
+++ b/tests/auto/gui/util/qundogroup/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qundogroup.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qundogroup Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qundogroup LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qundogroup
SOURCES
tst_qundogroup.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp
index c609ab4ffd..36f72b2ca0 100644
--- a/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp
+++ b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QUndoGroup>
#include <QUndoStack>
@@ -90,7 +65,7 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
QUndoCommand *parent)
: QUndoCommand(parent)
{
- QVERIFY(str->length() >= idx);
+ QVERIFY(str->size() >= idx);
setText("insert");
@@ -101,22 +76,22 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
void InsertCommand::redo()
{
- QVERIFY(m_str->length() >= m_idx);
+ QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
void InsertCommand::undo()
{
- QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
- m_str->remove(m_idx, m_text.length());
+ m_str->remove(m_idx, m_text.size());
}
RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent)
: QUndoCommand(parent)
{
- QVERIFY(str->length() >= idx + len);
+ QVERIFY(str->size() >= idx + len);
setText("remove");
@@ -127,14 +102,14 @@ RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *paren
void RemoveCommand::redo()
{
- QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
- m_str->remove(m_idx, m_text.length());
+ m_str->remove(m_idx, m_text.size());
}
void RemoveCommand::undo()
{
- QVERIFY(m_str->length() >= m_idx);
+ QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
@@ -156,9 +131,9 @@ void AppendCommand::redo()
void AppendCommand::undo()
{
- QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_str->size() - m_text.size()), m_text);
- m_str->truncate(m_str->length() - m_text.length());
+ m_str->truncate(m_str->size() - m_text.size());
}
int AppendCommand::id() const
diff --git a/tests/auto/gui/util/qundostack/CMakeLists.txt b/tests/auto/gui/util/qundostack/CMakeLists.txt
index 0e56171add..de36f4a1ad 100644
--- a/tests/auto/gui/util/qundostack/CMakeLists.txt
+++ b/tests/auto/gui/util/qundostack/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qundostack.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qundostack Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qundostack LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qundostack
SOURCES
tst_qundostack.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
)
diff --git a/tests/auto/gui/util/qundostack/tst_qundostack.cpp b/tests/auto/gui/util/qundostack/tst_qundostack.cpp
index 6707c12d80..3567bc6097 100644
--- a/tests/auto/gui/util/qundostack/tst_qundostack.cpp
+++ b/tests/auto/gui/util/qundostack/tst_qundostack.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -122,7 +97,7 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
QUndoCommand *parent)
: QUndoCommand(parent)
{
- QVERIFY(str->length() >= idx);
+ QVERIFY(str->size() >= idx);
setText("insert");
@@ -133,22 +108,22 @@ InsertCommand::InsertCommand(QString *str, int idx, const QString &text,
void InsertCommand::redo()
{
- QVERIFY(m_str->length() >= m_idx);
+ QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
void InsertCommand::undo()
{
- QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
- m_str->remove(m_idx, m_text.length());
+ m_str->remove(m_idx, m_text.size());
}
RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent)
: QUndoCommand(parent)
{
- QVERIFY(str->length() >= idx + len);
+ QVERIFY(str->size() >= idx + len);
setText("remove");
@@ -159,14 +134,14 @@ RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *paren
void RemoveCommand::redo()
{
- QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_idx, m_text.size()), m_text);
- m_str->remove(m_idx, m_text.length());
+ m_str->remove(m_idx, m_text.size());
}
void RemoveCommand::undo()
{
- QVERIFY(m_str->length() >= m_idx);
+ QVERIFY(m_str->size() >= m_idx);
m_str->insert(m_idx, m_text);
}
@@ -197,9 +172,9 @@ void AppendCommand::redo()
void AppendCommand::undo()
{
- QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text);
+ QCOMPARE(m_str->mid(m_str->size() - m_text.size()), m_text);
- m_str->truncate(m_str->length() - m_text.length());
+ m_str->truncate(m_str->size() - m_text.size());
}
int AppendCommand::id() const
@@ -349,44 +324,44 @@ static void checkState(QSignalSpy &redoTextChangedSpy,
QCOMPARE(stack.canRedo(), _canRedo);
QCOMPARE(stack.redoText(), QString(_redoText));
if (_indexChanged) {
- QCOMPARE(indexChangedSpy.count(), 1);
+ QCOMPARE(indexChangedSpy.size(), 1);
QCOMPARE(indexChangedSpy.at(0).at(0).toInt(), _index);
indexChangedSpy.clear();
} else {
- QCOMPARE(indexChangedSpy.count(), 0);
+ QCOMPARE(indexChangedSpy.size(), 0);
}
if (_cleanChanged) {
- QCOMPARE(cleanChangedSpy.count(), 1);
+ QCOMPARE(cleanChangedSpy.size(), 1);
QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean);
cleanChangedSpy.clear();
} else {
- QCOMPARE(cleanChangedSpy.count(), 0);
+ QCOMPARE(cleanChangedSpy.size(), 0);
}
if (_undoChanged) {
- QCOMPARE(canUndoChangedSpy.count(), 1);
+ QCOMPARE(canUndoChangedSpy.size(), 1);
QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo);
QCOMPARE(undoAction->isEnabled(), _canUndo);
- QCOMPARE(undoTextChangedSpy.count(), 1);
+ QCOMPARE(undoTextChangedSpy.size(), 1);
QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText));
QCOMPARE(undoAction->text(), glue("foo", _undoText));
canUndoChangedSpy.clear();
undoTextChangedSpy.clear();
} else {
- QCOMPARE(canUndoChangedSpy.count(), 0);
- QCOMPARE(undoTextChangedSpy.count(), 0);
+ QCOMPARE(canUndoChangedSpy.size(), 0);
+ QCOMPARE(undoTextChangedSpy.size(), 0);
}
if (_redoChanged) {
- QCOMPARE(canRedoChangedSpy.count(), 1);
+ QCOMPARE(canRedoChangedSpy.size(), 1);
QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo);
QCOMPARE(redoAction->isEnabled(), _canRedo);
- QCOMPARE(redoTextChangedSpy.count(), 1);
+ QCOMPARE(redoTextChangedSpy.size(), 1);
QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText));
QCOMPARE(redoAction->text(), glue("bar", _redoText));
canRedoChangedSpy.clear();
redoTextChangedSpy.clear();
} else {
- QCOMPARE(canRedoChangedSpy.count(), 0);
- QCOMPARE(redoTextChangedSpy.count(), 0);
+ QCOMPARE(canRedoChangedSpy.size(), 0);
+ QCOMPARE(redoTextChangedSpy.size(), 0);
}
}