diff options
Diffstat (limited to 'tests/auto/gui')
168 files changed, 8118 insertions, 780 deletions
diff --git a/tests/auto/gui/.prev_CMakeLists.txt b/tests/auto/gui/.prev_CMakeLists.txt new file mode 100644 index 0000000000..e7317e932c --- /dev/null +++ b/tests/auto/gui/.prev_CMakeLists.txt @@ -0,0 +1,19 @@ +# Generated from gui.pro. + +add_subdirectory(kernel) +if(NOT UIKIT) + add_subdirectory(image) + add_subdirectory(math3d) + add_subdirectory(painting) + add_subdirectory(text) + add_subdirectory(util) + add_subdirectory(itemmodels) + add_subdirectory(rhi) +endif() +if(QT_FEATURE_opengl AND NOT UIKIT AND NOT WINRT) + add_subdirectory(qopenglconfig) + add_subdirectory(qopengl) +endif() +if(QT_FEATURE_vulkan AND NOT UIKIT) + add_subdirectory(qvulkan) +endif() diff --git a/tests/auto/gui/CMakeLists.txt b/tests/auto/gui/CMakeLists.txt new file mode 100644 index 0000000000..e9c9ffe9fe --- /dev/null +++ b/tests/auto/gui/CMakeLists.txt @@ -0,0 +1,19 @@ +# Generated from gui.pro. + +add_subdirectory(kernel) +if(NOT UIKIT) + add_subdirectory(image) + add_subdirectory(math3d) + add_subdirectory(painting) + add_subdirectory(text) + add_subdirectory(util) + add_subdirectory(itemmodels) + add_subdirectory(rhi) +endif() +if(QT_FEATURE_opengl AND NOT UIKIT AND NOT WINRT) + add_subdirectory(qopenglconfig) + add_subdirectory(qopengl) +endif() +if(QT_FEATURE_vulkan AND NOT UIKIT) + add_subdirectory(qvulkan) +endif() diff --git a/tests/auto/gui/image/CMakeLists.txt b/tests/auto/gui/image/CMakeLists.txt new file mode 100644 index 0000000000..8ae016a8f8 --- /dev/null +++ b/tests/auto/gui/image/CMakeLists.txt @@ -0,0 +1,17 @@ +# Generated from image.pro. + +if(TARGET Qt::Network) + add_subdirectory(qimagereader) +endif() +add_subdirectory(qicoimageformat) +add_subdirectory(qpixmap) +add_subdirectory(qimage) +add_subdirectory(qimageiohandler) +add_subdirectory(qimagewriter) +add_subdirectory(qmovie) +add_subdirectory(qpicture) +add_subdirectory(qicon) +add_subdirectory(qiconhighdpi) +if(QT_FEATURE_private_tests) + add_subdirectory(qpixmapcache) +endif() diff --git a/tests/auto/gui/image/qicoimageformat/CMakeLists.txt b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt new file mode 100644 index 0000000000..0c8393631a --- /dev/null +++ b/tests/auto/gui/image/qicoimageformat/CMakeLists.txt @@ -0,0 +1,49 @@ +# Generated from qicoimageformat.pro. + +##################################################################### +## tst_qicoimageformat Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + icons/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qicoimageformat + SOURCES + tst_qicoimageformat.cpp + PUBLIC_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" + ) + + add_qt_resource(tst_qicoimageformat "qicoimageformat" + PREFIX + "/" + FILES + ${qicoimageformat_resource_files} + ) +endif() diff --git a/tests/auto/gui/image/qicon/CMakeLists.txt b/tests/auto/gui/image/qicon/CMakeLists.txt new file mode 100644 index 0000000000..81f5390d79 --- /dev/null +++ b/tests/auto/gui/image/qicon/CMakeLists.txt @@ -0,0 +1,94 @@ +# Generated from qicon.pro. + +##################################################################### +## tst_qicon Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + icons/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + second_icons/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + fallback_icons/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + *.png) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + *.svg) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + *.svgz) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qicon + SOURCES + tst_qicon.cpp + PUBLIC_LIBRARIES + Qt::Gui + TESTDATA ${test_data} +) + +# Resources: +set(tst_qicon_resource_files + "./fallback_icons/red.png" + "./icons/testtheme/16x16/actions/appointment-new.png" + "./icons/testtheme/22x22/actions/appointment-new.png" + "./icons/testtheme/index.theme" + "./icons/testtheme/scalable/actions/svg-only.svg" + "./icons/themeparent/16x16/actions/address-book-new.png" + "./icons/themeparent/16x16/actions/appointment-new.png" + "./icons/themeparent/22x22/actions/address-book-new.png" + "./icons/themeparent/22x22/actions/appointment-new.png" + "./icons/themeparent/32x32/actions/address-book-new.png" + "./icons/themeparent/32x32/actions/appointment-new.png" + "./icons/themeparent/icon-theme.cache" + "./icons/themeparent/index.theme" + "./icons/themeparent/scalable/actions/address-book-new.svg" + "./icons/themeparent/scalable/actions/appointment-new.svg" + "./second_icons/testtheme/32x32/actions/appointment-new.png" + "./styles/commonstyle/images/standardbutton-open-128.png" + "./styles/commonstyle/images/standardbutton-open-16.png" + "./styles/commonstyle/images/standardbutton-open-32.png" + "./styles/commonstyle/images/standardbutton-save-128.png" + "./styles/commonstyle/images/standardbutton-save-16.png" + "./styles/commonstyle/images/standardbutton-save-32.png" + "image.png" + "rect.png" + "tst_qicon.cpp" +) + +add_qt_resource(tst_qicon "tst_qicon" + PREFIX + "/" + FILES + ${tst_qicon_resource_files} +) +set(qmake_immediate_resource_files + "tst_qicon.cpp" +) + +add_qt_resource(tst_qicon "qmake_immediate" + PREFIX + "/" + FILES + ${qmake_immediate_resource_files} +) + + +## Scopes: +##################################################################### + +extend_target(tst_qicon CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt new file mode 100644 index 0000000000..6f6aaedca5 --- /dev/null +++ b/tests/auto/gui/image/qiconhighdpi/CMakeLists.txt @@ -0,0 +1,37 @@ +# Generated from qiconhighdpi.pro. + +##################################################################### +## tst_qiconhighdpi Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + icons/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qiconhighdpi + SOURCES + tst_qiconhighdpi.cpp + PUBLIC_LIBRARIES + Qt::Gui + TESTDATA ${test_data} +) + +# Resources: +set(tst_qiconhighdpi_resource_files + "icons/misc/button.9.png" + "icons/misc/button@2x.9.png" + "icons/testtheme/16x16/actions/appointment-new.png" + "icons/testtheme/22x22/actions/appointment-new.png" + "icons/testtheme/22x22@2/actions/appointment-new.png" + "icons/testtheme/index.theme" +) + +add_qt_resource(tst_qiconhighdpi "tst_qiconhighdpi" + PREFIX + "/" + FILES + ${tst_qiconhighdpi_resource_files} +) + diff --git a/tests/auto/gui/image/qimage/CMakeLists.txt b/tests/auto/gui/image/qimage/CMakeLists.txt new file mode 100644 index 0000000000..865f1124b9 --- /dev/null +++ b/tests/auto/gui/image/qimage/CMakeLists.txt @@ -0,0 +1,66 @@ +# Generated from qimage.pro. + +##################################################################### +## tst_qimage Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + images/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qimage + SOURCES + tst_qimage.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) + +## Scopes: +##################################################################### + +if(ANDROID AND NOT ANDROID_EMBEDDED) + # 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" + ) + + add_qt_resource(tst_qimage "qimage" + PREFIX + "/" + FILES + ${qimage_resource_files} + ) +endif() + +extend_target(tst_qimage CONDITION WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + gdi32 + user32 +) + +extend_target(tst_qimage CONDITION APPLE + PUBLIC_LIBRARIES + ${FWCoreGraphics} +) diff --git a/tests/auto/gui/image/qimageiohandler/CMakeLists.txt b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt new file mode 100644 index 0000000000..23e5e98b16 --- /dev/null +++ b/tests/auto/gui/image/qimageiohandler/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qimageiohandler.pro. + +##################################################################### +## tst_qimageiohandler Test: +##################################################################### + +add_qt_test(tst_qimageiohandler + SOURCES + tst_qimageiohandler.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/image/qimagereader/CMakeLists.txt b/tests/auto/gui/image/qimagereader/CMakeLists.txt new file mode 100644 index 0000000000..8a96fa18cf --- /dev/null +++ b/tests/auto/gui/image/qimagereader/CMakeLists.txt @@ -0,0 +1,65 @@ +# Generated from qimagereader.pro. + +##################################################################### +## tst_qimagereader Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + images/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + baseline/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qimagereader + SOURCES + tst_qimagereader.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::Network + TESTDATA ${test_data} +) + +file(GLOB resource_glob_0 RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "images/*") +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} +) + +add_qt_resource(tst_qimagereader "qmake_immediate" + PREFIX + "/" + FILES + ${qmake_immediate_resource_files} +) + + +#### Keys ignored in scope 1:.:.:qimagereader.pro:<TRUE>: +# MOC_DIR = "tmp" + +## Scopes: +##################################################################### + +if(ANDROID AND NOT ANDROID_EMBEDDED) + # Resources: + set(android_testdata_resource_files + "images/kollada-noext" + "images/trans.gif" + ) + + add_qt_resource(tst_qimagereader "android_testdata" + PREFIX + "/" + FILES + ${android_testdata_resource_files} + ) +endif() diff --git a/tests/auto/gui/image/qimagewriter/CMakeLists.txt b/tests/auto/gui/image/qimagewriter/CMakeLists.txt new file mode 100644 index 0000000000..1a04dfbce0 --- /dev/null +++ b/tests/auto/gui/image/qimagewriter/CMakeLists.txt @@ -0,0 +1,50 @@ +# Generated from qimagewriter.pro. + +##################################################################### +## tst_qimagewriter Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + images/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qimagewriter + SOURCES + tst_qimagewriter.cpp + PUBLIC_LIBRARIES + Qt::Gui + TESTDATA ${test_data} +) + +#### Keys ignored in scope 1:.:.:qimagewriter.pro:<TRUE>: +# MOC_DIR = "tmp" + +## Scopes: +##################################################################### + +if(ANDROID AND NOT ANDROID_EMBEDDED) + # 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" + ) + + add_qt_resource(tst_qimagewriter "qimagewriter" + PREFIX + "/" + FILES + ${qimagewriter_resource_files} + ) +endif() diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp index aaa8475c74..247f6443c1 100644 --- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp @@ -94,8 +94,8 @@ private: static void initializePadding(QImage *image) { - int effectiveBytesPerLine = (image->width() * image->depth() + 7) / 8; - int paddingBytes = image->bytesPerLine() - effectiveBytesPerLine; + qsizetype effectiveBytesPerLine = (qsizetype(image->width()) * image->depth() + 7) / 8; + qsizetype paddingBytes = image->bytesPerLine() - effectiveBytesPerLine; if (paddingBytes == 0) return; for (int y = 0; y < image->height(); ++y) { diff --git a/tests/auto/gui/image/qmovie/CMakeLists.txt b/tests/auto/gui/image/qmovie/CMakeLists.txt new file mode 100644 index 0000000000..bc841b5d29 --- /dev/null +++ b/tests/auto/gui/image/qmovie/CMakeLists.txt @@ -0,0 +1,56 @@ +# Generated from qmovie.pro. + +##################################################################### +## tst_qmovie Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + animations/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qmovie + SOURCES + tst_qmovie.cpp + PUBLIC_LIBRARIES + Qt::Gui + TESTDATA ${test_data} +) + +# Resources: +set(resources_resource_files + "animations/comicsecard.gif" + "animations/corrupt.gif" + "animations/trolltech.gif" +) + +add_qt_resource(tst_qmovie "resources" + PREFIX + "/" + FILES + ${resources_resource_files} +) + + +#### Keys ignored in scope 1:.:.:qmovie.pro:<TRUE>: +# MOC_DIR = "tmp" +# QT_FOR_CONFIG = "gui-private" + +## Scopes: +##################################################################### + +extend_target(tst_qmovie CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) + +extend_target(tst_qmovie CONDITION QT_FEATURE_gif + DEFINES + QTEST_HAVE_GIF +) + +extend_target(tst_qmovie CONDITION QT_FEATURE_jpeg + DEFINES + QTEST_HAVE_JPEG +) diff --git a/tests/auto/gui/image/qpicture/CMakeLists.txt b/tests/auto/gui/image/qpicture/CMakeLists.txt new file mode 100644 index 0000000000..625d19b3a5 --- /dev/null +++ b/tests/auto/gui/image/qpicture/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpicture.pro. + +##################################################################### +## tst_qpicture Test: +##################################################################### + +add_qt_test(tst_qpicture + SOURCES + tst_qpicture.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp index ec6bb8dcee..6287960457 100644 --- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp +++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp @@ -37,6 +37,8 @@ #include <qscreen.h> #include <limits.h> +#ifndef QT_NO_PICTURE + class tst_QPicture : public QObject { Q_OBJECT @@ -45,7 +47,6 @@ public: tst_QPicture(); private slots: - void getSetCheck(); void devType(); void paintingActive(); void boundingRect(); @@ -56,31 +57,6 @@ private slots: void boundaryValues(); }; -// Testing get/set functions -void tst_QPicture::getSetCheck() -{ - QPictureIO obj1; - // const QPicture & QPictureIO::picture() - // void QPictureIO::setPicture(const QPicture &) - // const char * QPictureIO::format() - // void QPictureIO::setFormat(const char *) - const char var2[] = "PNG"; - obj1.setFormat(var2); - QCOMPARE(var2, obj1.format()); - obj1.setFormat((char *)0); - // The format is stored internally in a QString, so return is always a valid char * - QVERIFY(QString(obj1.format()).isEmpty()); - - // const char * QPictureIO::parameters() - // void QPictureIO::setParameters(const char *) - const char var3[] = "Bogus data"; - obj1.setParameters(var3); - QCOMPARE(var3, obj1.parameters()); - obj1.setParameters((char *)0); - // The format is stored internally in a QString, so return is always a valid char * - QVERIFY(QString(obj1.parameters()).isEmpty()); -} - tst_QPicture::tst_QPicture() { } @@ -316,6 +292,7 @@ void tst_QPicture::boundaryValues() painter.end(); } - QTEST_MAIN(tst_QPicture) #include "tst_qpicture.moc" + +#endif // QT_NO_PICTURE diff --git a/tests/auto/gui/image/qpixmap/CMakeLists.txt b/tests/auto/gui/image/qpixmap/CMakeLists.txt new file mode 100644 index 0000000000..f6a83aa0da --- /dev/null +++ b/tests/auto/gui/image/qpixmap/CMakeLists.txt @@ -0,0 +1,107 @@ +# Generated from qpixmap.pro. + +##################################################################### +## tst_qpixmap Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + convertFromImage/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + convertFromToHICON/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + loadFromData/*) +list(APPEND test_data ${test_data_glob}) +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + images/*) +list(APPEND test_data ${test_data_glob}) + +add_qt_test(tst_qpixmap + SOURCES + tst_qpixmap.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) + +# Resources: +set(qpixmap_resource_files + "convertFromImage/task31722_0/img1.png" + "convertFromImage/task31722_0/img2.png" + "convertFromImage/task31722_1/img1.png" + "convertFromImage/task31722_1/img2.png" + "convertFromToHICON/icon_32bpp.ico" + "convertFromToHICON/icon_32bpp_16x16.png" + "convertFromToHICON/icon_32bpp_256x256.png" + "convertFromToHICON/icon_32bpp_32x32.png" + "convertFromToHICON/icon_32bpp_48x48.png" + "convertFromToHICON/icon_8bpp.ico" + "convertFromToHICON/icon_8bpp_16x16.png" + "convertFromToHICON/icon_8bpp_32x32.png" + "convertFromToHICON/icon_8bpp_48x48.png" + "images/designer.png" + "images/dx_-10_dy_-10_50_50_100_100.png" + "images/dx_-10_dy_-10_x_y_w_h.png" + "images/dx_-10_dy_0_50_50_100_100.png" + "images/dx_-10_dy_0_x_y_w_h.png" + "images/dx_-128_dy_-128_x_y_w_h.png" + "images/dx_-128_dy_0_x_y_w_h.png" + "images/dx_0_dy_-10_50_50_100_100.png" + "images/dx_0_dy_-10_x_y_w_h.png" + "images/dx_0_dy_-128_x_y_w_h.png" + "images/dx_0_dy_0_50_50_100_100.png" + "images/dx_0_dy_0_null.png" + "images/dx_0_dy_0_x_y_w_h.png" + "images/dx_0_dy_10_50_50_100_100.png" + "images/dx_0_dy_10_x_y_w_h.png" + "images/dx_0_dy_128_x_y_w_h.png" + "images/dx_0_dy_1_null.png" + "images/dx_10_dy_0_50_50_100_100.png" + "images/dx_10_dy_0_x_y_w_h.png" + "images/dx_10_dy_10_50_50_100_100.png" + "images/dx_10_dy_10_x_y_w_h.png" + "images/dx_128_dy_0_x_y_w_h.png" + "images/dx_128_dy_128_64_64_128_128.png" + "images/dx_128_dy_128_x_y_w_h.png" + "images/dx_1_dy_0_null.png" + "loadFromData/designer_argb32.png" + "loadFromData/designer_indexed8_no_alpha.gif" + "loadFromData/designer_indexed8_no_alpha.png" + "loadFromData/designer_indexed8_no_alpha_animated.gif" + "loadFromData/designer_indexed8_with_alpha.gif" + "loadFromData/designer_indexed8_with_alpha.png" + "loadFromData/designer_indexed8_with_alpha_animated.gif" + "loadFromData/designer_rgb32.jpg" + "loadFromData/designer_rgb32.png" +) + +add_qt_resource(tst_qpixmap "qpixmap" + PREFIX + "/" + FILES + ${qpixmap_resource_files} +) + + +## Scopes: +##################################################################### + +extend_target(tst_qpixmap CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets + Qt::WidgetsPrivate +) + +extend_target(tst_qpixmap CONDITION WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + gdi32 + user32 +) diff --git a/tests/auto/gui/image/qpixmapcache/CMakeLists.txt b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt new file mode 100644 index 0000000000..ef73f60ca6 --- /dev/null +++ b/tests/auto/gui/image/qpixmapcache/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qpixmapcache.pro. + +##################################################################### +## tst_qpixmapcache Test: +##################################################################### + +add_qt_test(tst_qpixmapcache + SOURCES + tst_qpixmapcache.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/itemmodels/CMakeLists.txt b/tests/auto/gui/itemmodels/CMakeLists.txt new file mode 100644 index 0000000000..196168b1b2 --- /dev/null +++ b/tests/auto/gui/itemmodels/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory("qstandarditem") +if (QT_FEATURE_widgets) +# add_subdirectory("qstandarditemmodel") +endif() diff --git a/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt new file mode 100644 index 0000000000..8a19f6afaf --- /dev/null +++ b/tests/auto/gui/itemmodels/qstandarditem/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qstandarditem.pro. + +##################################################################### +## tst_qstandarditem Test: +##################################################################### + +add_qt_test(tst_qstandarditem + SOURCES + tst_qstandarditem.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/CMakeLists.txt b/tests/auto/gui/kernel/CMakeLists.txt new file mode 100644 index 0000000000..1cb38a7c9e --- /dev/null +++ b/tests/auto/gui/kernel/CMakeLists.txt @@ -0,0 +1,49 @@ +# Generated from kernel.pro. + +if(QT_FEATURE_action) + add_subdirectory(qaction) + add_subdirectory(qactiongroup) +endif() +add_subdirectory(qbackingstore) +add_subdirectory(qcursor) +add_subdirectory(qdrag) +add_subdirectory(qevent) +add_subdirectory(qfileopenevent) +add_subdirectory(qguieventdispatcher) +add_subdirectory(qguitimer) +add_subdirectory(qinputmethod) +add_subdirectory(qkeyevent) +add_subdirectory(qmouseevent) +add_subdirectory(qpalette) +add_subdirectory(qscreen) +add_subdirectory(qsurfaceformat) +add_subdirectory(qwindow) +add_subdirectory(qguiapplication) +add_subdirectory(qpixelformat) +add_subdirectory(qrasterwindow) +add_subdirectory(qaddpostroutine) +if(NOT ANDROID AND NOT UIKIT) + add_subdirectory(qclipboard) +endif() +if(TARGET Qt::Network) + add_subdirectory(qguieventloop) +endif() +if(QT_FEATURE_shortcut) + add_subdirectory(qguimetatype) + add_subdirectory(qguivariant) + add_subdirectory(qkeysequence) + add_subdirectory(qshortcut) +endif() +if(QT_FEATURE_highdpiscaling) + add_subdirectory(qhighdpiscaling) +endif() +if(TARGET Qt::Widgets) + add_subdirectory(qmouseevent_modal) + add_subdirectory(qtouchevent) +endif() +if(QT_FEATURE_opengl) + add_subdirectory(qopenglwindow) +endif() +if(TARGET Qt::Network AND WIN32 AND NOT WINRT) + add_subdirectory(noqteventloop) +endif() diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 3187ea3720..85bebbddc9 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -1,5 +1,7 @@ TEMPLATE=subdirs SUBDIRS=\ + qaction \ + qactiongroup \ qbackingstore \ qclipboard \ qcursor \ @@ -19,6 +21,7 @@ SUBDIRS=\ qmouseevent_modal \ qpalette \ qscreen \ + qshortcut \ qsurfaceformat \ qtouchevent \ qwindow \ @@ -30,6 +33,12 @@ SUBDIRS=\ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop +!qtConfig(shortcut): SUBDIRS -= \ + qkeysequence \ + qshortcut \ + qguimetatype \ + qguivariant + !qtHaveModule(widgets): SUBDIRS -= \ qmouseevent_modal \ qtouchevent @@ -37,6 +46,10 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop !qtHaveModule(network): SUBDIRS -= \ qguieventloop +!qtConfig(action): SUBDIRS -= \ + qaction \ + qactiongroup + !qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling !qtConfig(opengl): SUBDIRS -= qopenglwindow diff --git a/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt new file mode 100644 index 0000000000..82de116f8d --- /dev/null +++ b/tests/auto/gui/kernel/noqteventloop/CMakeLists.txt @@ -0,0 +1,23 @@ +# Generated from noqteventloop.pro. + +##################################################################### +## tst_noqteventloop Test: +##################################################################### + +add_qt_test(tst_noqteventloop + SOURCES + tst_noqteventloop.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::Network +) + +## Scopes: +##################################################################### + +extend_target(tst_noqteventloop CONDITION QT_FEATURE_dynamicgl AND WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + user32 +) diff --git a/tests/auto/gui/kernel/qaction/.gitignore b/tests/auto/gui/kernel/qaction/.gitignore new file mode 100644 index 0000000000..bf81f5bf2c --- /dev/null +++ b/tests/auto/gui/kernel/qaction/.gitignore @@ -0,0 +1 @@ +tst_qaction diff --git a/tests/auto/gui/kernel/qaction/CMakeLists.txt b/tests/auto/gui/kernel/qaction/CMakeLists.txt new file mode 100644 index 0000000000..bdd1a1d165 --- /dev/null +++ b/tests/auto/gui/kernel/qaction/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qaction.pro. + +##################################################################### +## tst_qaction_kernel Test: +##################################################################### + +add_qt_test(tst_qaction_kernel + SOURCES + tst_qaction.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qaction/qaction.pro b/tests/auto/gui/kernel/qaction/qaction.pro new file mode 100644 index 0000000000..83e8296e68 --- /dev/null +++ b/tests/auto/gui/kernel/qaction/qaction.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qaction_kernel +QT += gui-private core-private testlib +SOURCES += tst_qaction.cpp diff --git a/tests/auto/gui/kernel/qaction/tst_qaction.cpp b/tests/auto/gui/kernel/qaction/tst_qaction.cpp new file mode 100644 index 0000000000..a34c763021 --- /dev/null +++ b/tests/auto/gui/kernel/qaction/tst_qaction.cpp @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <qguiapplication.h> +#include <qevent.h> +#include <qaction.h> +#include <qactiongroup.h> +#include <qpa/qplatformtheme.h> + +#include <private/qguiapplication_p.h> + +class tst_QAction : public QObject +{ + Q_OBJECT + +public: + tst_QAction(); + +private slots: + void cleanup(); + void getSetCheck(); + void setText_data(); + void setText(); + void setIconText_data() { setText_data(); } + void setIconText(); +#if QT_CONFIG(shortcut) + void setStandardKeys(); + void task200823_tooltip(); +#endif + void task229128TriggeredSignalWithoutActiongroup(); + void setData(); + void setEnabledSetVisible(); + void setCheckabledSetChecked(); + +private: + const int m_keyboardScheme; +}; + +tst_QAction::tst_QAction() + : m_keyboardScheme(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt()) +{ +} + +void tst_QAction::cleanup() +{ + QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); +} + +// Testing get/set functions +void tst_QAction::getSetCheck() +{ + QAction obj1(nullptr); + auto var1 = new QActionGroup(nullptr); + obj1.setActionGroup(var1); + QCOMPARE(var1, obj1.actionGroup()); + obj1.setActionGroup(nullptr); + QCOMPARE(obj1.actionGroup(), nullptr); + delete var1; + + QCOMPARE(obj1.priority(), QAction::NormalPriority); + obj1.setPriority(QAction::LowPriority); + QCOMPARE(obj1.priority(), QAction::LowPriority); +} + +void tst_QAction::setText_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("iconText"); + QTest::addColumn<QString>("textFromIconText"); + + //next we fill it with data + QTest::newRow("Normal") << "Action" << "Action" << "Action"; + QTest::newRow("Ampersand") << "Search && Destroy" << "Search & Destroy" << "Search && Destroy"; + QTest::newRow("Mnemonic and ellipsis") << "O&pen File ..." << "Open File" << "Open File"; +} + +void tst_QAction::setText() +{ + QFETCH(QString, text); + + QAction action(nullptr); + action.setText(text); + + QCOMPARE(action.text(), text); + + QFETCH(QString, iconText); + QCOMPARE(action.iconText(), iconText); +} + +void tst_QAction::setIconText() +{ + QFETCH(QString, iconText); + + QAction action(nullptr); + action.setIconText(iconText); + QCOMPARE(action.iconText(), iconText); + + QFETCH(QString, textFromIconText); + QCOMPARE(action.text(), textFromIconText); +} + +#if QT_CONFIG(shortcut) + +//basic testing of standard keys +void tst_QAction::setStandardKeys() +{ + QAction act(nullptr); + act.setShortcut(QKeySequence("CTRL+L")); + QList<QKeySequence> list; + act.setShortcuts(list); + act.setShortcuts(QKeySequence::Copy); + QCOMPARE(act.shortcut(), act.shortcuts().constFirst()); + + QList<QKeySequence> expected; + const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C")); + const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT")); + switch (m_keyboardScheme) { + case QPlatformTheme::MacKeyboardScheme: + expected << ctrlC; + break; + case QPlatformTheme::WindowsKeyboardScheme: + expected << ctrlC << ctrlInsert; + break; + default: // X11 + expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16")); + break; + } + + QCOMPARE(act.shortcuts(), expected); +} + +void tst_QAction::task200823_tooltip() +{ + const QScopedPointer<QAction> action(new QAction("foo", nullptr)); + QString shortcut("ctrl+o"); + action->setShortcut(shortcut); + + // we want a non-standard tooltip that shows the shortcut + action->setToolTip(action->text() + QLatin1String(" (") + action->shortcut().toString() + QLatin1Char(')')); + + QString ref = QLatin1String("foo (") + QKeySequence(shortcut).toString() + QLatin1Char(')'); + QCOMPARE(action->toolTip(), ref); +} + +#endif // QT_CONFIG(shortcut) + +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); + actionWithoutGroup->trigger(); + // signal should be emitted + QCOMPARE(spyWithoutGroup.count(), 1); + + // it is now a checkable checked action + actionWithoutGroup->setCheckable(true); + actionWithoutGroup->setChecked(true); + spyWithoutGroup.clear(); + QCOMPARE(spyWithoutGroup.count(), 0); + actionWithoutGroup->trigger(); + // signal should be emitted + QCOMPARE(spyWithoutGroup.count(), 1); +} + +void tst_QAction::setData() // QTBUG-62006 +{ + QAction act(nullptr); + QSignalSpy spy(&act, &QAction::changed); + QCOMPARE(act.data(), QVariant()); + QCOMPARE(spy.count(), 0); + act.setData(QVariant()); + QCOMPARE(spy.count(), 0); + + act.setData(-1); + QCOMPARE(spy.count(), 1); + act.setData(-1); + QCOMPARE(spy.count(), 1); +} + +void tst_QAction::setEnabledSetVisible() +{ + QAction action(nullptr); + QSignalSpy spy(&action, &QAction::enabledChanged); + QVERIFY(action.isEnabled()); + QVERIFY(action.isVisible()); + QCOMPARE(spy.count(), 0); + action.setVisible(false); + QVERIFY(!action.isEnabled()); + QVERIFY(!action.isVisible()); + QCOMPARE(spy.count(), 1); + action.setEnabled(false); + QVERIFY(!action.isEnabled()); + QVERIFY(!action.isVisible()); + QCOMPARE(spy.count(), 1); + action.setVisible(true); + QVERIFY(!action.isEnabled()); + QVERIFY(action.isVisible()); + QCOMPARE(spy.count(), 1); + action.resetEnabled(); + QVERIFY(action.isEnabled()); + QCOMPARE(spy.count(), 2); +} + +void tst_QAction::setCheckabledSetChecked() +{ + QAction action(nullptr); + QSignalSpy changedSpy(&action, &QAction::changed); + QSignalSpy checkedSpy(&action, &QAction::toggled); + QSignalSpy checkableSpy(&action, &QAction::checkableChanged); + QVERIFY(!action.isCheckable()); + QVERIFY(!action.isChecked()); + QCOMPARE(changedSpy.count(), 0); + QCOMPARE(checkedSpy.count(), 0); + QCOMPARE(checkableSpy.count(), 0); + + action.setCheckable(true); + QVERIFY(action.isCheckable()); + QVERIFY(!action.isChecked()); + QCOMPARE(changedSpy.count(), 1); + QCOMPARE(checkedSpy.count(), 0); + QCOMPARE(checkableSpy.count(), 1); + + action.setChecked(true); + QVERIFY(action.isCheckable()); + QVERIFY(action.isChecked()); + QCOMPARE(changedSpy.count(), 2); + QCOMPARE(checkedSpy.count(), 1); + QCOMPARE(checkableSpy.count(), 1); + + action.setCheckable(false); + QVERIFY(!action.isCheckable()); + QVERIFY(!action.isChecked()); + QCOMPARE(changedSpy.count(), 3); + QCOMPARE(checkedSpy.count(), 2); + QCOMPARE(checkableSpy.count(), 2); + + action.setCheckable(true); + QVERIFY(action.isCheckable()); + QVERIFY(action.isChecked()); + QCOMPARE(changedSpy.count(), 4); + QCOMPARE(checkedSpy.count(), 3); + QCOMPARE(checkableSpy.count(), 3); +} + +QTEST_MAIN(tst_QAction) +#include "tst_qaction.moc" diff --git a/tests/auto/gui/kernel/qactiongroup/.gitignore b/tests/auto/gui/kernel/qactiongroup/.gitignore new file mode 100644 index 0000000000..daba003e96 --- /dev/null +++ b/tests/auto/gui/kernel/qactiongroup/.gitignore @@ -0,0 +1 @@ +tst_qactiongroup diff --git a/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt new file mode 100644 index 0000000000..bcab5e05a2 --- /dev/null +++ b/tests/auto/gui/kernel/qactiongroup/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qactiongroup.pro. + +##################################################################### +## tst_qactiongroup_kernel Test: +##################################################################### + +add_qt_test(tst_qactiongroup_kernel + SOURCES + tst_qactiongroup.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qactiongroup/qactiongroup.pro b/tests/auto/gui/kernel/qactiongroup/qactiongroup.pro new file mode 100644 index 0000000000..a60109c63e --- /dev/null +++ b/tests/auto/gui/kernel/qactiongroup/qactiongroup.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qactiongroup_kernel +QT += testlib +SOURCES += tst_qactiongroup.cpp diff --git a/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp new file mode 100644 index 0000000000..c5a3db7b62 --- /dev/null +++ b/tests/auto/gui/kernel/qactiongroup/tst_qactiongroup.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <qaction.h> +#include <qactiongroup.h> + +class tst_QActionGroup : public QObject +{ + Q_OBJECT + +private slots: + void cleanup() { QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); } + void enabledPropagation(); + void visiblePropagation(); + void exclusive(); + void exclusiveOptional(); + void testActionInTwoQActionGroup(); + void unCheckCurrentAction(); +}; + +void tst_QActionGroup::enabledPropagation() +{ + QActionGroup testActionGroup(nullptr); + + auto childAction = new QAction( &testActionGroup ); + auto anotherChildAction = new QAction( &testActionGroup ); + auto freeAction = new QAction(nullptr); + + QVERIFY( testActionGroup.isEnabled() ); + QVERIFY( childAction->isEnabled() ); + + testActionGroup.setEnabled( false ); + QVERIFY( !testActionGroup.isEnabled() ); + QVERIFY( !childAction->isEnabled() ); + QVERIFY( !anotherChildAction->isEnabled() ); + + childAction->setEnabled(true); + QVERIFY( !childAction->isEnabled()); + + anotherChildAction->setEnabled( false ); + + testActionGroup.setEnabled( true ); + QVERIFY( testActionGroup.isEnabled() ); + QVERIFY( childAction->isEnabled() ); + QVERIFY( !anotherChildAction->isEnabled() ); + + testActionGroup.setEnabled( false ); + auto lastChildAction = new QAction(&testActionGroup); + + QVERIFY(!lastChildAction->isEnabled()); + testActionGroup.setEnabled( true ); + QVERIFY(lastChildAction->isEnabled()); + + freeAction->setEnabled(false); + testActionGroup.addAction(freeAction); + QVERIFY(!freeAction->isEnabled()); + delete freeAction; +} + +void tst_QActionGroup::visiblePropagation() +{ + QActionGroup testActionGroup(nullptr); + + auto childAction = new QAction( &testActionGroup ); + auto anotherChildAction = new QAction( &testActionGroup ); + auto freeAction = new QAction(nullptr); + + QVERIFY( testActionGroup.isVisible() ); + QVERIFY( childAction->isVisible() ); + + testActionGroup.setVisible( false ); + QVERIFY( !testActionGroup.isVisible() ); + QVERIFY( !childAction->isVisible() ); + QVERIFY( !anotherChildAction->isVisible() ); + + anotherChildAction->setVisible(false); + + testActionGroup.setVisible( true ); + QVERIFY( testActionGroup.isVisible() ); + QVERIFY( childAction->isVisible() ); + + QVERIFY( !anotherChildAction->isVisible() ); + + testActionGroup.setVisible( false ); + auto lastChildAction = new QAction(&testActionGroup); + + QVERIFY(!lastChildAction->isVisible()); + testActionGroup.setVisible( true ); + QVERIFY(lastChildAction->isVisible()); + + freeAction->setVisible(false); + testActionGroup.addAction(freeAction); + QVERIFY(!freeAction->isVisible()); + delete freeAction; +} + +void tst_QActionGroup::exclusive() +{ + QActionGroup group(nullptr); + group.setExclusive(false); + QVERIFY( !group.isExclusive() ); + + auto actOne = new QAction(&group); + actOne->setCheckable( true ); + auto actTwo = new QAction(&group); + actTwo->setCheckable( true ); + auto actThree = new QAction(&group); + actThree->setCheckable( true ); + + group.setExclusive( true ); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->setChecked( true ); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->setChecked( true ); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + +void tst_QActionGroup::exclusiveOptional() +{ + QActionGroup group(0); + group.setExclusive(true); + QVERIFY( group.isExclusive() ); + + auto actOne = new QAction(&group); + actOne->setCheckable( true ); + auto actTwo = new QAction(&group); + actTwo->setCheckable( true ); + auto actThree = new QAction(&group); + actThree->setCheckable( true ); + + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + group.setExclusionPolicy(QActionGroup::ExclusionPolicy::ExclusiveOptional); + QVERIFY( group.isExclusive() ); + + actOne->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + +void tst_QActionGroup::testActionInTwoQActionGroup() +{ + QAction action1("Action 1", this); + + QActionGroup group1(this); + QActionGroup group2(this); + + group1.addAction(&action1); + group2.addAction(&action1); + + QCOMPARE(action1.actionGroup(), &group2); + QCOMPARE(group2.actions().constFirst(), &action1); + QCOMPARE(group1.actions().isEmpty(), true); +} + +void tst_QActionGroup::unCheckCurrentAction() +{ + QActionGroup group(nullptr); + QAction action1(&group) ,action2(&group); + action1.setCheckable(true); + action2.setCheckable(true); + QVERIFY(!action1.isChecked()); + QVERIFY(!action2.isChecked()); + action1.setChecked(true); + QVERIFY(action1.isChecked()); + QVERIFY(!action2.isChecked()); + auto current = group.checkedAction(); + QCOMPARE(current, &action1); + current->setChecked(false); + QVERIFY(!action1.isChecked()); + QVERIFY(!action2.isChecked()); + QVERIFY(!group.checkedAction()); +} + + +QTEST_MAIN(tst_QActionGroup) +#include "tst_qactiongroup.moc" diff --git a/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt new file mode 100644 index 0000000000..4af9ebedd5 --- /dev/null +++ b/tests/auto/gui/kernel/qaddpostroutine/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qaddpostroutine.pro. + +##################################################################### +## tst_qaddpostroutine Test: +##################################################################### + +qt_add_test(tst_qaddpostroutine + SOURCES + tst_qaddpostroutine.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt new file mode 100644 index 0000000000..639e88fb4c --- /dev/null +++ b/tests/auto/gui/kernel/qbackingstore/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qbackingstore.pro. + +##################################################################### +## tst_qbackingstore Test: +##################################################################### + +add_qt_test(tst_qbackingstore + SOURCES + tst_qbackingstore.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt new file mode 100644 index 0000000000..b795d32520 --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt @@ -0,0 +1,7 @@ +# Generated from qclipboard.pro. + +add_subdirectory(test) +if(NOT WINRT) + add_subdirectory(copier) + add_subdirectory(paster) +endif() diff --git a/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt new file mode 100644 index 0000000000..30990c1387 --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt @@ -0,0 +1,18 @@ +# Generated from copier.pro. + +##################################################################### +## copier Binary: +##################################################################### + +add_qt_executable(copier + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +#### Keys ignored in scope 2:.:.:copier.pro:WIN32: +# DESTDIR = "../copier" diff --git a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt new file mode 100644 index 0000000000..4595093b3b --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt @@ -0,0 +1,26 @@ +# Generated from copier.pro. + +##################################################################### +## copier Binary: +##################################################################### + +# special case begin +set(win32_args) +if (WIN32) + set(win32_args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +endif() +# special case end + +add_qt_executable(copier + ${win32_args} # special case + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +#### Keys ignored in scope 2:.:.:copier.pro:WIN32: +# DESTDIR = "../copier" diff --git a/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt new file mode 100644 index 0000000000..2c90c1530f --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt @@ -0,0 +1,18 @@ +# Generated from paster.pro. + +##################################################################### +## paster Binary: +##################################################################### + +add_qt_executable(paster + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +#### Keys ignored in scope 2:.:.:paster.pro:WIN32: +# DESTDIR = "../paster" diff --git a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt new file mode 100644 index 0000000000..b9f118929c --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt @@ -0,0 +1,26 @@ +# Generated from paster.pro. + +##################################################################### +## paster Binary: +##################################################################### + +# special case begin +set(win32_args) +if (WIN32) + set(win32_args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +endif() +# special case end + +add_qt_executable(paster + ${win32_args} # special case + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +#### Keys ignored in scope 2:.:.:paster.pro:WIN32: +# DESTDIR = "../paster" diff --git a/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt new file mode 100644 index 0000000000..36d9f7b00c --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt @@ -0,0 +1,24 @@ +# Generated from test.pro. + +##################################################################### +## tst_qclipboard Test: +##################################################################### + +add_qt_test(tst_qclipboard + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" + SOURCES + ../tst_qclipboard.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qclipboard CONDITION MACOS + PUBLIC_LIBRARIES + ${FWAppKit} +) + +#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID AND NOT WINRT: +# TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster" diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt new file mode 100644 index 0000000000..36d9f7b00c --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt @@ -0,0 +1,24 @@ +# Generated from test.pro. + +##################################################################### +## tst_qclipboard Test: +##################################################################### + +add_qt_test(tst_qclipboard + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" + SOURCES + ../tst_qclipboard.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qclipboard CONDITION MACOS + PUBLIC_LIBRARIES + ${FWAppKit} +) + +#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID AND NOT WINRT: +# TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster" diff --git a/tests/auto/gui/kernel/qcursor/CMakeLists.txt b/tests/auto/gui/kernel/qcursor/CMakeLists.txt new file mode 100644 index 0000000000..8f4062a42a --- /dev/null +++ b/tests/auto/gui/kernel/qcursor/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qcursor.pro. + +##################################################################### +## tst_qcursor Test: +##################################################################### + +add_qt_test(tst_qcursor + SOURCES + tst_qcursor.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qdrag/CMakeLists.txt b/tests/auto/gui/kernel/qdrag/CMakeLists.txt new file mode 100644 index 0000000000..84bceaf0de --- /dev/null +++ b/tests/auto/gui/kernel/qdrag/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qdrag.pro. + +##################################################################### +## tst_qdrag Test: +##################################################################### + +add_qt_test(tst_qdrag + SOURCES + tst_qdrag.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qevent/CMakeLists.txt b/tests/auto/gui/kernel/qevent/CMakeLists.txt new file mode 100644 index 0000000000..01d6db7225 --- /dev/null +++ b/tests/auto/gui/kernel/qevent/CMakeLists.txt @@ -0,0 +1,10 @@ +# Generated from qevent.pro. + +##################################################################### +## tst_qevent Test: +##################################################################### + +add_qt_test(tst_qevent + SOURCES + tst_qevent.cpp +) diff --git a/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt new file mode 100644 index 0000000000..2404833737 --- /dev/null +++ b/tests/auto/gui/kernel/qfileopenevent/CMakeLists.txt @@ -0,0 +1,4 @@ +# Generated from qfileopenevent.pro. + +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 new file mode 100644 index 0000000000..0c50f7ff56 --- /dev/null +++ b/tests/auto/gui/kernel/qfileopenevent/qfileopeneventexternal/CMakeLists.txt @@ -0,0 +1,16 @@ +# Generated from qfileopeneventexternal.pro. + +##################################################################### +## qfileopeneventexternal Binary: +##################################################################### + +add_qt_executable(qfileopeneventexternal + GUI + SOURCES + qfileopeneventexternal.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +#### Keys ignored in scope 1:.:.:qfileopeneventexternal.pro:<TRUE>: +# TEMPLATE = "app" diff --git a/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt b/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt new file mode 100644 index 0000000000..6695ef42b3 --- /dev/null +++ b/tests/auto/gui/kernel/qfileopenevent/test/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from test.pro. + +##################################################################### +## tst_qfileopenevent Test: +##################################################################### + +add_qt_test(tst_qfileopenevent + SOURCES + tst_qfileopenevent.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qguiapplication/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qguiapplication/.prev_CMakeLists.txt new file mode 100644 index 0000000000..30a6436ece --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/.prev_CMakeLists.txt @@ -0,0 +1,45 @@ +# Generated from qguiapplication.pro. + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qguiapplication Test: +##################################################################### + +add_qt_test(tst_qguiapplication + SOURCES + tst_qcoreapplication.cpp tst_qcoreapplication.h + tst_qguiapplication.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0x050E00 + INCLUDE_DIRECTORIES + ../../../corelib/kernel/qcoreapplication + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::GuiPrivate +) + +# Resources: +set(tst_qguiapplication_resource_files + "icons/appicon.png" + "icons/usericon.png" +) + +add_qt_resource(tst_qguiapplication "tst_qguiapplication" + PREFIX + "/" + FILES + ${tst_qguiapplication_resource_files} +) + + +## 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/BLACKLIST b/tests/auto/gui/kernel/qguiapplication/BLACKLIST index e6ffe78ae3..58ca7bf782 100644 --- a/tests/auto/gui/kernel/qguiapplication/BLACKLIST +++ b/tests/auto/gui/kernel/qguiapplication/BLACKLIST @@ -1,3 +1,6 @@ [focusObject] ubuntu-16.04 opensuse-42.3 + +[quitOnLastWindowClosedMulti] +macos ci diff --git a/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt new file mode 100644 index 0000000000..24fa6572c1 --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/CMakeLists.txt @@ -0,0 +1,55 @@ +# Generated from qguiapplication.pro. + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qguiapplication Test: +##################################################################### + +# special case begin +if (WIN32) + set(target_version "1.2.3.4") +else() + set(target_version "1.2.3") +endif() +# special case end + +add_qt_test(tst_qguiapplication + VERSION ${target_version} + SOURCES + ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp ../../../corelib/kernel/qcoreapplication/tst_qcoreapplication.h # special case + tst_qguiapplication.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0x050E00 + INCLUDE_DIRECTORIES + ../../../corelib/kernel/qcoreapplication + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::GuiPrivate + Threads::Threads # special case +) + +# Resources: +set(tst_qguiapplication_resource_files + "icons/appicon.png" + "icons/usericon.png" +) + +add_qt_resource(tst_qguiapplication "tst_qguiapplication" + PREFIX + "/" + FILES + ${tst_qguiapplication_resource_files} +) + + +## 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/qguieventdispatcher/CMakeLists.txt b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt new file mode 100644 index 0000000000..eb36e0ece7 --- /dev/null +++ b/tests/auto/gui/kernel/qguieventdispatcher/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qguieventdispatcher.pro. + +##################################################################### +## tst_qguieventdispatcher Test: +##################################################################### + +add_qt_test(tst_qguieventdispatcher + SOURCES + ../../../corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qguieventloop/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qguieventloop/.prev_CMakeLists.txt new file mode 100644 index 0000000000..c4daa5a310 --- /dev/null +++ b/tests/auto/gui/kernel/qguieventloop/.prev_CMakeLists.txt @@ -0,0 +1,28 @@ +# Generated from qguieventloop.pro. + +##################################################################### +## tst_qguieventloop Test: +##################################################################### + +add_qt_test(tst_qguieventloop + SOURCES + ../../../corelib/kernel/qeventloop/tst_qeventloop.cpp + LIBRARIES + Qt::CorePrivate + PUBLIC_LIBRARIES + Qt::Gui + Qt::Network +) + +## Scopes: +##################################################################### + +extend_target(tst_qguieventloop CONDITION WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + user32 +) + +extend_target(tst_qguieventloop CONDITION QT_FEATURE_glib + DEFINES + HAVE_GLIB +) diff --git a/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt new file mode 100644 index 0000000000..de9a876e9d --- /dev/null +++ b/tests/auto/gui/kernel/qguieventloop/CMakeLists.txt @@ -0,0 +1,27 @@ +# Generated from qguieventloop.pro. + +##################################################################### +## tst_qguieventloop Test: +##################################################################### + +add_qt_test(tst_qguieventloop + SOURCES + ../../../corelib/kernel/qeventloop/tst_qeventloop.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::Network +) + +## Scopes: +##################################################################### + +extend_target(tst_qguieventloop CONDITION WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + user32 +) + +extend_target(tst_qguieventloop CONDITION QT_FEATURE_glib + DEFINES + HAVE_GLIB +) diff --git a/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt new file mode 100644 index 0000000000..3701b3983a --- /dev/null +++ b/tests/auto/gui/kernel/qguimetatype/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qguimetatype.pro. + +##################################################################### +## tst_qguimetatype Test: +##################################################################### + +add_qt_test(tst_qguimetatype + SOURCES + tst_qguimetatype.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp index 81f0183728..f0c5bf79a7 100644 --- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp +++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp @@ -67,7 +67,6 @@ private slots: F(QPen, QPen) \ F(QTextLength, QTextLength) \ F(QTextFormat, QTextFormat) \ - F(QMatrix, QMatrix) \ F(QTransform, QTransform) \ F(QMatrix4x4, QMatrix4x4) \ F(QVector2D, QVector2D) \ @@ -181,9 +180,13 @@ template<> struct TestValueFactory<QMetaType::QCursor> { static QCursor *create() { return new QCursor(Qt::WaitCursor); } }; #endif + +#if QT_CONFIG(shortcut) template<> struct TestValueFactory<QMetaType::QKeySequence> { static QKeySequence *create() { return new QKeySequence(QKeySequence::Close); } }; +#endif + template<> struct TestValueFactory<QMetaType::QPen> { static QPen *create() { return new QPen(Qt::DashDotDotLine); } }; @@ -193,14 +196,6 @@ template<> struct TestValueFactory<QMetaType::QTextLength> { template<> struct TestValueFactory<QMetaType::QTextFormat> { static QTextFormat *create() { return new QTextFormat(QTextFormat::FrameFormat); } }; -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -template<> struct TestValueFactory<QMetaType::QMatrix> { - static QMatrix *create() { return new QMatrix(10, 20, 30, 40, 50, 60); } -}; -QT_WARNING_POP -#endif template<> struct TestValueFactory<QMetaType::QTransform> { static QTransform *create() { return new QTransform(10, 20, 30, 40, 50, 60); } }; @@ -317,30 +312,10 @@ void tst_QGuiMetaType::sizeOf() QCOMPARE(QMetaType::sizeOf(type), size); } -#ifndef Q_ALIGNOF -template<uint N> -struct RoundToNextHighestPowerOfTwo -{ -private: - enum { V1 = N-1 }; - enum { V2 = V1 | (V1 >> 1) }; - enum { V3 = V2 | (V2 >> 2) }; - enum { V4 = V3 | (V3 >> 4) }; - enum { V5 = V4 | (V4 >> 8) }; - enum { V6 = V5 | (V5 >> 16) }; -public: - enum { Value = V6 + 1 }; -}; -#endif - template<class T> struct TypeAlignment { -#ifdef Q_ALIGNOF - enum { Value = Q_ALIGNOF(T) }; -#else - enum { Value = RoundToNextHighestPowerOfTwo<sizeof(T)>::Value }; -#endif + enum { Value = alignof(T) }; }; void tst_QGuiMetaType::flags_data() diff --git a/tests/auto/gui/kernel/qguitimer/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qguitimer/.prev_CMakeLists.txt new file mode 100644 index 0000000000..c4e5117e8c --- /dev/null +++ b/tests/auto/gui/kernel/qguitimer/.prev_CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qguitimer.pro. + +##################################################################### +## tst_qguitimer Test: +##################################################################### + +add_qt_test(tst_qguitimer + SOURCES + ../../../corelib/kernel/qtimer/tst_qtimer.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qguitimer/CMakeLists.txt b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt new file mode 100644 index 0000000000..2be3339fe3 --- /dev/null +++ b/tests/auto/gui/kernel/qguitimer/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qguitimer.pro. + +##################################################################### +## tst_qguitimer Test: +##################################################################### + +add_qt_test(tst_qguitimer + SOURCES + ../../../corelib/kernel/qtimer/tst_qtimer.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Threads::Threads # special case +) diff --git a/tests/auto/gui/kernel/qguivariant/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt new file mode 100644 index 0000000000..3a0adab6e3 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/CMakeLists.txt @@ -0,0 +1,4 @@ +# Generated from qguivariant.pro. + +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 new file mode 100644 index 0000000000..8261212801 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/no_application/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from no_application.pro. + +##################################################################### +## no_application Test: +##################################################################### + +add_qt_test(no_application + SOURCES + main.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt new file mode 100644 index 0000000000..af2cea60e6 --- /dev/null +++ b/tests/auto/gui/kernel/qguivariant/test/CMakeLists.txt @@ -0,0 +1,38 @@ +# Generated from test.pro. + +##################################################################### +## tst_qguivariant Test: +##################################################################### + +add_qt_test(tst_qguivariant + SOURCES + tst_qguivariant.cpp + INCLUDE_DIRECTORIES + ../../../../other/qvariant_common + PUBLIC_LIBRARIES + Qt::Gui +) + +# Resources: +set(tst_qguivariant_resource_files + "black.png" + "black2.png" +) + +add_qt_resource(tst_qguivariant "tst_qguivariant" + PREFIX + "/" + FILES + ${tst_qguivariant_resource_files} +) +set(qguivariant_resource_files + "data" +) + +add_qt_resource(tst_qguivariant "qguivariant" + PREFIX + "/" + FILES + ${qguivariant_resource_files} +) + diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp index 8b301c145a..12998add71 100644 --- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp @@ -36,7 +36,6 @@ #include <qcursor.h> #include <qimage.h> #include <qicon.h> -#include <qmatrix.h> #include <qmatrix4x4.h> #include <qpen.h> #include <qpolygon.h> @@ -87,8 +86,6 @@ private slots: void toBrush_data(); void toBrush(); - void matrix(); - void transform(); void matrix4x4(); @@ -402,24 +399,6 @@ void tst_QGuiVariant::toString() QCOMPARE( str, result ); } -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -void tst_QGuiVariant::matrix() -{ - QVariant variant; - QMatrix matrix = qvariant_cast<QMatrix>(variant); - QVERIFY(matrix.isIdentity()); - variant.setValue(QMatrix().rotate(90)); - QCOMPARE(QMatrix().rotate(90), qvariant_cast<QMatrix>(variant)); - - void *mmatrix = QMetaType::create(QVariant::Matrix, 0); - QVERIFY(mmatrix); - QMetaType::destroy(QVariant::Matrix, mmatrix); -} -QT_WARNING_POP -#endif - void tst_QGuiVariant::matrix4x4() { QVariant variant; @@ -711,7 +690,6 @@ void tst_QGuiVariant::implicitConstruction() F(Pen) \ F(TextLength) \ F(TextFormat) \ - F(Matrix) \ F(Transform) \ F(Matrix4x4) \ F(Vector2D) \ diff --git a/tests/auto/gui/kernel/qhighdpiscaling/CMakeLists.txt b/tests/auto/gui/kernel/qhighdpiscaling/CMakeLists.txt new file mode 100644 index 0000000000..69cff9229f --- /dev/null +++ b/tests/auto/gui/kernel/qhighdpiscaling/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qhighdpiscaling.pro. + +##################################################################### +## tst_qhighdpiscaling Test: +##################################################################### + +qt_add_test(tst_qhighdpiscaling + SOURCES + tst_qhighdpiscaling.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt new file mode 100644 index 0000000000..2eee15b816 --- /dev/null +++ b/tests/auto/gui/kernel/qinputmethod/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qinputmethod.pro. + +##################################################################### +## tst_qinputmethod Test: +##################################################################### + +add_qt_test(tst_qinputmethod + SOURCES + tst_qinputmethod.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt new file mode 100644 index 0000000000..2e36795375 --- /dev/null +++ b/tests/auto/gui/kernel/qkeyevent/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qkeyevent.pro. + +##################################################################### +## tst_qkeyevent Test: +##################################################################### + +add_qt_test(tst_qkeyevent + SOURCES + tst_qkeyevent.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index 87a47bd93b..6a928cac7a 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -64,8 +64,10 @@ public: private slots: void basicEventDelivery(); +#if QT_CONFIG(shortcut) void modifiers_data(); void modifiers(); +#endif }; tst_QKeyEvent::tst_QKeyEvent() @@ -128,6 +130,8 @@ static QByteArray modifiersTestRowName(const QString &keySequence) return result; } +#if QT_CONFIG(shortcut) + void tst_QKeyEvent::modifiers_data() { struct Modifier @@ -198,5 +202,7 @@ void tst_QKeyEvent::modifiers() } } +#endif // QT_CONFIG(shortcut) + QTEST_MAIN(tst_QKeyEvent) #include "tst_qkeyevent.moc" diff --git a/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt new file mode 100644 index 0000000000..07e480c9dd --- /dev/null +++ b/tests/auto/gui/kernel/qkeysequence/CMakeLists.txt @@ -0,0 +1,28 @@ +# Generated from qkeysequence.pro. + +##################################################################### +## tst_qkeysequence Test: +##################################################################### + +add_qt_test(tst_qkeysequence + SOURCES + tst_qkeysequence.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set(qkeysequence_resource_files + "keys_de.qm" + "qt_de.qm" +) + +add_qt_resource(tst_qkeysequence "qkeysequence" + PREFIX + "/" + FILES + ${qkeysequence_resource_files} +) + diff --git a/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt new file mode 100644 index 0000000000..4e1081c6ad --- /dev/null +++ b/tests/auto/gui/kernel/qmouseevent/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qmouseevent.pro. + +##################################################################### +## tst_qmouseevent Test: +##################################################################### + +add_qt_test(tst_qmouseevent + SOURCES + tst_qmouseevent.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt new file mode 100644 index 0000000000..c7f447ffeb --- /dev/null +++ b/tests/auto/gui/kernel/qmouseevent_modal/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qmouseevent_modal.pro. + +##################################################################### +## tst_qmouseevent_modal Test: +##################################################################### + +add_qt_test(tst_qmouseevent_modal + SOURCES + tst_qmouseevent_modal.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::Widgets +) diff --git a/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt new file mode 100644 index 0000000000..4176be9840 --- /dev/null +++ b/tests/auto/gui/kernel/qopenglwindow/CMakeLists.txt @@ -0,0 +1,15 @@ +# Generated from qopenglwindow.pro. + +##################################################################### +## tst_qopenglwindow Test: +##################################################################### + +add_qt_test(tst_qopenglwindow + SOURCES + tst_qopenglwindow.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::OpenGL +) diff --git a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro index 759b608c93..28b12f0677 100644 --- a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro +++ b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qopenglwindow -QT += core-private gui-private testlib +QT += opengl core-private gui-private testlib SOURCES += tst_qopenglwindow.cpp diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp index 9c36b6898a..2785d57a42 100644 --- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp +++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include <QtGui/QOpenGLWindow> +#include <QtOpenGL/QOpenGLWindow> #include <QtTest/QtTest> #include <QtGui/QOpenGLFunctions> #include <QtGui/QOpenGLContext> diff --git a/tests/auto/gui/kernel/qpalette/CMakeLists.txt b/tests/auto/gui/kernel/qpalette/CMakeLists.txt new file mode 100644 index 0000000000..4bd2ce7cc5 --- /dev/null +++ b/tests/auto/gui/kernel/qpalette/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpalette.pro. + +##################################################################### +## tst_qpalette Test: +##################################################################### + +add_qt_test(tst_qpalette + SOURCES + tst_qpalette.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index 6ce6422f48..04343727bb 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -41,6 +41,12 @@ private Q_SLOTS: void copySemantics(); void moveSemantics(); void setBrush(); + + void isBrushSet(); + void setAllPossibleBrushes(); + void noBrushesSetForDefaultPalette(); + void cannotCheckIfInvalidBrushSet(); + void checkIfBrushForCurrentGroupSet(); }; void tst_QPalette::roleValues_data() @@ -118,23 +124,35 @@ void tst_QPalette::resolve() QVERIFY(p2ResolvedTo1 != p2); } + +static void compareAllPaletteData(const QPalette &firstPalette, const QPalette &secondPalette) +{ + QCOMPARE(firstPalette, secondPalette); + + // For historical reasons, operator== compares only brushes, but it's not enough for proper + // comparison after move/copy, because some additional data can also be moved/copied. + // Let's compare this data here. + QCOMPARE(firstPalette.resolve(), secondPalette.resolve()); + QCOMPARE(firstPalette.currentColorGroup(), secondPalette.currentColorGroup()); +} + void tst_QPalette::copySemantics() { QPalette src(Qt::red), dst; const QPalette control = src; // copy construction QVERIFY(src != dst); QVERIFY(!src.isCopyOf(dst)); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(src.isCopyOf(control)); dst = src; // copy assignment - QCOMPARE(dst, src); - QCOMPARE(dst, control); + compareAllPaletteData(dst, src); + compareAllPaletteData(dst, control); QVERIFY(dst.isCopyOf(src)); dst = QPalette(Qt::green); QVERIFY(dst != src); QVERIFY(dst != control); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(src.isCopyOf(control)); } @@ -144,13 +162,13 @@ void tst_QPalette::moveSemantics() QPalette src(Qt::red), dst; const QPalette control = src; QVERIFY(src != dst); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(!dst.isCopyOf(control)); dst = std::move(src); // move assignment QVERIFY(!dst.isCopyOf(src)); // isCopyOf() works on moved-from palettes, too QVERIFY(dst.isCopyOf(control)); - QCOMPARE(dst, control); + compareAllPaletteData(dst, control); src = control; // check moved-from 'src' can still be assigned to (doesn't crash) QVERIFY(src.isCopyOf(dst)); QVERIFY(src.isCopyOf(control)); @@ -158,7 +176,7 @@ void tst_QPalette::moveSemantics() QVERIFY(!src.isCopyOf(dst)); QVERIFY(!src.isCopyOf(dst2)); QVERIFY(!src.isCopyOf(control)); - QCOMPARE(dst2, control); + compareAllPaletteData(dst2, control); QVERIFY(dst2.isCopyOf(dst)); QVERIFY(dst2.isCopyOf(control)); // check moved-from 'src' can still be destroyed (doesn't crash) @@ -194,5 +212,62 @@ void tst_QPalette::setBrush() QVERIFY(pp.isCopyOf(p)); } +void tst_QPalette::isBrushSet() +{ + QPalette p; + + // Set only one color group + p.setBrush(QPalette::Active, QPalette::Mid, QBrush(Qt::red)); + QVERIFY(p.isBrushSet(QPalette::Active, QPalette::Mid)); + QVERIFY(!p.isBrushSet(QPalette::Inactive, QPalette::Mid)); + QVERIFY(!p.isBrushSet(QPalette::Disabled, QPalette::Mid)); + + // Set all color groups + p.setBrush(QPalette::LinkVisited, QBrush(Qt::green)); + QVERIFY(p.isBrushSet(QPalette::Active, QPalette::LinkVisited)); + QVERIFY(p.isBrushSet(QPalette::Inactive, QPalette::LinkVisited)); + QVERIFY(p.isBrushSet(QPalette::Disabled, QPalette::LinkVisited)); +} + +void tst_QPalette::setAllPossibleBrushes() +{ + QPalette p; + + QCOMPARE(p.resolve(), QPalette::ResolveMask(0)); + + for (int r = 0; r < QPalette::NColorRoles; ++r) { + p.setBrush(QPalette::All, QPalette::ColorRole(r), Qt::red); + } + + for (int r = 0; r < QPalette::NColorRoles; ++r) { + for (int g = 0; g < QPalette::NColorGroups; ++g) { + QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r))); + } + } +} + +void tst_QPalette::noBrushesSetForDefaultPalette() +{ + QCOMPARE(QPalette().resolve(), QPalette::ResolveMask(0)); +} + +void tst_QPalette::cannotCheckIfInvalidBrushSet() +{ + QPalette p(Qt::red); + + QVERIFY(!p.isBrushSet(QPalette::All, QPalette::LinkVisited)); + QVERIFY(!p.isBrushSet(QPalette::Active, QPalette::NColorRoles)); +} + +void tst_QPalette::checkIfBrushForCurrentGroupSet() +{ + QPalette p; + + p.setCurrentColorGroup(QPalette::Disabled); + p.setBrush(QPalette::Current, QPalette::Link, QBrush(Qt::yellow)); + + QVERIFY(p.isBrushSet(QPalette::Current, QPalette::Link)); +} + 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 new file mode 100644 index 0000000000..43deb02af1 --- /dev/null +++ b/tests/auto/gui/kernel/qpixelformat/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpixelformat.pro. + +##################################################################### +## tst_qpixelformat Test: +##################################################################### + +add_qt_test(tst_qpixelformat + SOURCES + tst_qpixelformat.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt new file mode 100644 index 0000000000..9b586ce4c8 --- /dev/null +++ b/tests/auto/gui/kernel/qrasterwindow/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qrasterwindow.pro. + +##################################################################### +## tst_qrasterwindow Test: +##################################################################### + +add_qt_test(tst_qrasterwindow + SOURCES + tst_qrasterwindow.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qscreen/CMakeLists.txt b/tests/auto/gui/kernel/qscreen/CMakeLists.txt new file mode 100644 index 0000000000..dd54db4753 --- /dev/null +++ b/tests/auto/gui/kernel/qscreen/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qscreen.pro. + +##################################################################### +## tst_qscreen Test: +##################################################################### + +add_qt_test(tst_qscreen + SOURCES + tst_qscreen.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qshortcut/CMakeLists.txt b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt new file mode 100644 index 0000000000..fab20dceed --- /dev/null +++ b/tests/auto/gui/kernel/qshortcut/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qshortcut.pro. + +##################################################################### +## tst_qshortcut_kernel Test: +##################################################################### + +add_qt_test(tst_qshortcut_kernel + SOURCES + tst_qshortcut.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/kernel/qshortcut/qshortcut.pro b/tests/auto/gui/kernel/qshortcut/qshortcut.pro new file mode 100644 index 0000000000..5dc016b099 --- /dev/null +++ b/tests/auto/gui/kernel/qshortcut/qshortcut.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qshortcut_kernel +QT += testlib +SOURCES += tst_qshortcut.cpp diff --git a/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp new file mode 100644 index 0000000000..fd5a4bdccf --- /dev/null +++ b/tests/auto/gui/kernel/qshortcut/tst_qshortcut.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtGui/qguiapplication.h> +#include <QtGui/qshortcut.h> +#include <QtGui/qpainter.h> +#include <QtGui/qrasterwindow.h> +#include <QtGui/qscreen.h> +#include <QtGui/qwindow.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 ColoredWindow::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.fillRect(QRect(QPoint(), size()), m_color); +} + +static void sendKey(QWindow *target, Qt::Key k, char c, Qt::KeyboardModifiers modifiers) +{ + 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); + new QShortcut(Qt::CTRL + Qt::Key_Q, &w, SLOT(close())); + w.show(); + QVERIFY(QTest::qWaitForWindowExposed(&w)); + sendKey(&w, Qt::Key_Q, 'q', Qt::ControlModifier); + QTRY_VERIFY(!w.isVisible()); +} + +QTEST_MAIN(tst_QShortcut) +#include "tst_qshortcut.moc" diff --git a/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt new file mode 100644 index 0000000000..d12e1da106 --- /dev/null +++ b/tests/auto/gui/kernel/qsurfaceformat/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qsurfaceformat.pro. + +##################################################################### +## tst_qsurfaceformat Test: +##################################################################### + +add_qt_test(tst_qsurfaceformat + SOURCES + tst_qsurfaceformat.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt new file mode 100644 index 0000000000..7d489e3066 --- /dev/null +++ b/tests/auto/gui/kernel/qtouchevent/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtouchevent.pro. + +##################################################################### +## tst_qtouchevent Test: +##################################################################### + +add_qt_test(tst_qtouchevent + SOURCES + tst_qtouchevent.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate + Qt::Widgets +) diff --git a/tests/auto/gui/kernel/qwindow/CMakeLists.txt b/tests/auto/gui/kernel/qwindow/CMakeLists.txt new file mode 100644 index 0000000000..cfd17219bd --- /dev/null +++ b/tests/auto/gui/kernel/qwindow/CMakeLists.txt @@ -0,0 +1,22 @@ +# Generated from qwindow.pro. + +##################################################################### +## tst_qwindow Test: +##################################################################### + +add_qt_test(tst_qwindow + SOURCES + tst_qwindow.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) + +## Scopes: +##################################################################### + +extend_target(tst_qwindow CONDITION QT_FEATURE_dynamicgl AND WIN32 AND NOT WINRT + PUBLIC_LIBRARIES + user32 +) diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 34de756ab5..1db7e9a9c7 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1717,7 +1717,7 @@ public: eventType = ev->type(); eventGlobal = ev->globalPosF(); eventLocal = ev->posF(); - eventDevice = ev->device(); + eventDevice = ev->deviceType(); } QEvent::Type eventType = QEvent::None; @@ -1730,7 +1730,7 @@ public: || ev->type() == QEvent::TabletLeaveProximity) { eventType = ev->type(); QTabletEvent *te = static_cast<QTabletEvent *>(ev); - eventDevice = te->device(); + eventDevice = te->deviceType(); } return QWindow::eventFilter(obj, ev); } diff --git a/tests/auto/gui/math3d/CMakeLists.txt b/tests/auto/gui/math3d/CMakeLists.txt new file mode 100644 index 0000000000..91e59874b7 --- /dev/null +++ b/tests/auto/gui/math3d/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory("qquaternion") +add_subdirectory("qvectornd") +add_subdirectory("qmatrixnxn") diff --git a/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt new file mode 100644 index 0000000000..71daeba361 --- /dev/null +++ b/tests/auto/gui/math3d/qmatrixnxn/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qmatrixnxn.pro. + +##################################################################### +## tst_qmatrixnxn Test: +##################################################################### + +add_qt_test(tst_qmatrixnxn + SOURCES + tst_qmatrixnxn.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp index 3c4f2f2e75..26e22e5883 100644 --- a/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp +++ b/tests/auto/gui/math3d/qmatrixnxn/tst_qmatrixnxn.cpp @@ -144,7 +144,6 @@ private slots: void columnsAndRows(); - void convertQMatrix(); void convertQTransform(); void fill(); @@ -3061,58 +3060,6 @@ void tst_QMatrixNxN::columnsAndRows() QVERIFY(m1.row(3) == QVector4D(4, 8, 12, 16)); } -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -// Test converting QMatrix objects into QMatrix4x4 and then -// checking that transformations in the original perform the -// equivalent transformations in the new matrix. -void tst_QMatrixNxN::convertQMatrix() -{ - QMatrix m1; - m1.translate(-3.5, 2.0); - QPointF p1 = m1.map(QPointF(100.0, 150.0)); - QCOMPARE(p1.x(), 100.0 - 3.5); - QCOMPARE(p1.y(), 150.0 + 2.0); - - QMatrix4x4 m2(m1); - QPointF p2 = m2 * QPointF(100.0, 150.0); - QCOMPARE((double)p2.x(), 100.0 - 3.5); - QCOMPARE((double)p2.y(), 150.0 + 2.0); - QCOMPARE(m1, m2.toAffine()); - - QMatrix m3; - m3.scale(1.5, -2.0); - QPointF p3 = m3.map(QPointF(100.0, 150.0)); - QCOMPARE(p3.x(), 1.5 * 100.0); - QCOMPARE(p3.y(), -2.0 * 150.0); - - QMatrix4x4 m4(m3); - QPointF p4 = m4 * QPointF(100.0, 150.0); - QCOMPARE((double)p4.x(), 1.5 * 100.0); - QCOMPARE((double)p4.y(), -2.0 * 150.0); - QCOMPARE(m3, m4.toAffine()); - - QMatrix m5; - m5.rotate(45.0); - QPointF p5 = m5.map(QPointF(100.0, 150.0)); - - QMatrix4x4 m6(m5); - QPointF p6 = m6 * QPointF(100.0, 150.0); - QVERIFY(qFuzzyCompare(float(p5.x()), float(p6.x()))); - QVERIFY(qFuzzyCompare(float(p5.y()), float(p6.y()))); - - QMatrix m7 = m6.toAffine(); - QVERIFY(qFuzzyCompare(float(m5.m11()), float(m7.m11()))); - QVERIFY(qFuzzyCompare(float(m5.m12()), float(m7.m12()))); - QVERIFY(qFuzzyCompare(float(m5.m21()), float(m7.m21()))); - QVERIFY(qFuzzyCompare(float(m5.m22()), float(m7.m22()))); - QVERIFY(qFuzzyCompare(float(m5.dx()), float(m7.dx()))); - QVERIFY(qFuzzyCompare(float(m5.dy()), float(m7.dy()))); -} -QT_WARNING_POP -#endif - // Test converting QTransform objects into QMatrix4x4 and then // checking that transformations in the original perform the // equivalent transformations in the new matrix. diff --git a/tests/auto/gui/math3d/qquaternion/CMakeLists.txt b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt new file mode 100644 index 0000000000..77d035cbf9 --- /dev/null +++ b/tests/auto/gui/math3d/qquaternion/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qquaternion.pro. + +##################################################################### +## tst_qquaternion Test: +##################################################################### + +add_qt_test(tst_qquaternion + SOURCES + tst_qquaternion.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/math3d/qvectornd/CMakeLists.txt b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt new file mode 100644 index 0000000000..5d8a373234 --- /dev/null +++ b/tests/auto/gui/math3d/qvectornd/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qvectornd.pro. + +##################################################################### +## tst_qvectornd Test: +##################################################################### + +add_qt_test(tst_qvectornd + SOURCES + tst_qvectornd.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/CMakeLists.txt b/tests/auto/gui/painting/CMakeLists.txt new file mode 100644 index 0000000000..7cb4c55cee --- /dev/null +++ b/tests/auto/gui/painting/CMakeLists.txt @@ -0,0 +1,19 @@ +# Generated from painting.pro. + +add_subdirectory("qpainterpath") +add_subdirectory("qpainterpathstroker") +# add_subdirectory("qcolor") +# add_subdirectory("qbrush") +# add_subdirectory("qregion") +# add_subdirectory("qpagelayout") +add_subdirectory("qpagesize") +# add_subdirectory("qpainter") +if (QT_FEATURE_private_tests) + # not converted yet + #add_subdirectory("qpathclipper") +endif() +# add_subdirectory("qpdfwriter") +add_subdirectory("qpen") +add_subdirectory("qpaintengine") +# add_subdirectory("qtransform") +# add_subdirectory("qpolygon") diff --git a/tests/auto/gui/painting/painting.pro b/tests/auto/gui/painting/painting.pro index 26e84c1b15..3fdb0db760 100644 --- a/tests/auto/gui/painting/painting.pro +++ b/tests/auto/gui/painting/painting.pro @@ -14,7 +14,6 @@ SUBDIRS=\ qpen \ qpaintengine \ qtransform \ - qwmatrix \ qpolygon \ !qtConfig(private_tests): SUBDIRS -= \ diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 07c820dc86..f8502c1e2f 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1032,6 +1032,15 @@ void tst_QColor::setRgbF() QCOMPARE(qfloat16(b2), qfloat16(b)); } } + QVERIFY(color.isValid()); + QColor invalidRgb = color; + QColor invalidRgbF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range"); + invalidRgb.setRgb(-1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range"); + invalidRgbF.setRgb(-1, -1, -1, -1); + QVERIFY(!invalidRgb.isValid()); + QVERIFY(!invalidRgbF.isValid()); } void tst_QColor::setRgba() @@ -1146,6 +1155,16 @@ void tst_QColor::setHsv() QCOMPARE(v2, v); } } + QVERIFY(color.isValid()); + QVERIFY(color.isValid()); + QColor invalidHsv = color; + QColor invalidHsvF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsv: HSV parameters out of range"); + invalidHsv.setHsv(-1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsvF: HSV parameters out of range"); + invalidHsvF.setHsvF(-1, -1, -1); + QVERIFY(!invalidHsv.isValid()); + QVERIFY(!invalidHsvF.isValid()); } void tst_QColor::setCmyk() @@ -1271,6 +1290,15 @@ void tst_QColor::setCmyk() QCOMPARE(k2, k); } } + QVERIFY(color.isValid()); + QColor invalidCmyk = color; + QColor invalidCmykF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setCmyk: CMYK parameters out of range"); + invalidCmyk.setCmyk(-1, -1, -1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setCmykF: CMYK parameters out of range"); + invalidCmykF.setCmykF(-1, -1, -1, -1, -1); + QVERIFY(!invalidCmyk.isValid()); + QVERIFY(!invalidCmykF.isValid()); } void tst_QColor::setHsl() @@ -1372,6 +1400,15 @@ void tst_QColor::setHsl() QCOMPARE(l2, l); } } + QVERIFY(color.isValid()); + QColor invalidHsl = color; + QColor invalidHslF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsl: HSL parameters out of range"); + invalidHsl.setHsl(-1, -1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setHslF: HSL parameters out of range"); + invalidHslF.setHslF(-1, -1, -1, -1); + QVERIFY(!invalidHsl.isValid()); + QVERIFY(!invalidHslF.isValid()); } void tst_QColor::toRgb_data() diff --git a/tests/auto/gui/painting/qpagesize/CMakeLists.txt b/tests/auto/gui/painting/qpagesize/CMakeLists.txt new file mode 100644 index 0000000000..260abfbc0f --- /dev/null +++ b/tests/auto/gui/painting/qpagesize/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qpagesize.pro. + +##################################################################### +## tst_qpagesize Test: +##################################################################### + +add_qt_test(tst_qpagesize + SOURCES + tst_qpagesize.cpp + DEFINES + QT_USE_USING_NAMESPACE + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/qpaintengine/CMakeLists.txt b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt new file mode 100644 index 0000000000..8125a98d3e --- /dev/null +++ b/tests/auto/gui/painting/qpaintengine/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpaintengine.pro. + +##################################################################### +## tst_qpaintengine Test: +##################################################################### + +add_qt_test(tst_qpaintengine + SOURCES + tst_qpaintengine.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 45798cc527..ce88c6a7a4 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -141,7 +141,7 @@ private slots: void setWindow(); - void combinedMatrix(); + void combinedTransform(); void renderHints(); void disableEnableClipping(); @@ -1693,7 +1693,7 @@ void tst_QPainter::setWindow() QVERIFY(195 < painted.height() && painted.height() < 205); // correct value is around 200 } -void tst_QPainter::combinedMatrix() +void tst_QPainter::combinedTransform() { QPixmap pm(64, 64); @@ -1704,15 +1704,7 @@ void tst_QPainter::combinedMatrix() p.translate(0.5, 0.5); QTransform ct = p.combinedTransform(); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - QMatrix cm = p.combinedMatrix(); - QCOMPARE(cm, ct.toAffine()); -QT_WARNING_POP -#endif - - QPointF pt = QPointF(0, 0) * ct.toAffine(); + QPointF pt = QPointF(0, 0) * ct; QCOMPARE(pt.x(), 48.0); QCOMPARE(pt.y(), 16.0); @@ -4068,7 +4060,7 @@ void tst_QPainter::drawPolygon() path.moveTo(2, 34); path.lineTo(34, 2); - QPolygonF poly = stroker.createStroke(path).toFillPolygon(QTransform()); + QPolygonF poly = stroker.createStroke(path).toFillPolygon(); img.fill(0xffffffff); QPainter p(&img); @@ -4136,24 +4128,12 @@ void tst_QPainter::inactivePainter() p.setClipRegion(region); p.setClipping(true); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.combinedMatrix(); -QT_WARNING_POP -#endif p.combinedTransform(); p.compositionMode(); p.setCompositionMode(QPainter::CompositionMode_Plus); p.device(); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.deviceMatrix(); -QT_WARNING_POP -#endif p.deviceTransform(); p.font(); @@ -4177,12 +4157,6 @@ QT_WARNING_POP p.setRenderHint(QPainter::Antialiasing, true); p.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, false); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.resetMatrix(); -QT_WARNING_POP -#endif p.resetTransform(); p.rotate(1); p.scale(2, 2); @@ -4198,13 +4172,9 @@ QT_WARNING_POP p.window(); p.setWindow(QRect(10, 10, 620, 460)); -#if QT_DEPRECATED_SINCE(5, 13) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - p.worldMatrix(); - p.setWorldMatrix(QMatrix().translate(43, 21), true); -QT_WARNING_POP -#endif + p.worldTransform(); + p.setWorldTransform(QTransform().translate(43, 21), true); + p.setWorldMatrixEnabled(true); p.transform(); diff --git a/tests/auto/gui/painting/qpainterpath/CMakeLists.txt b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt new file mode 100644 index 0000000000..c2c88cc258 --- /dev/null +++ b/tests/auto/gui/painting/qpainterpath/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpainterpath.pro. + +##################################################################### +## tst_qpainterpath Test: +##################################################################### + +add_qt_test(tst_qpainterpath + SOURCES + tst_qpainterpath.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt new file mode 100644 index 0000000000..a1c5f6547f --- /dev/null +++ b/tests/auto/gui/painting/qpainterpathstroker/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpainterpathstroker.pro. + +##################################################################### +## tst_qpainterpathstroker Test: +##################################################################### + +add_qt_test(tst_qpainterpathstroker + SOURCES + tst_qpainterpathstroker.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/qpen/CMakeLists.txt b/tests/auto/gui/painting/qpen/CMakeLists.txt new file mode 100644 index 0000000000..d096f7a6ce --- /dev/null +++ b/tests/auto/gui/painting/qpen/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qpen.pro. + +##################################################################### +## tst_qpen Test: +##################################################################### + +add_qt_test(tst_qpen + SOURCES + tst_qpen.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp index f31e2bf41b..2dcb564e2b 100644 --- a/tests/auto/gui/painting/qtransform/tst_qtransform.cpp +++ b/tests/auto/gui/painting/qtransform/tst_qtransform.cpp @@ -46,8 +46,6 @@ private slots: void qhash(); void translate(); void scale(); - void matrix(); - void testOffset(); void types(); void types2_data(); void types2(); @@ -372,67 +370,6 @@ void tst_QTransform::scale() QVERIFY( QTransform::fromScale( 1, 1 ) == QTransform()); } -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED -void tst_QTransform::matrix() -{ - QMatrix mat1; - mat1.scale(0.3, 0.7); - mat1.translate(53.3, 94.4); - mat1.rotate(45); - - QMatrix mat2; - mat2.rotate(33); - mat2.scale(0.6, 0.6); - mat2.translate(13.333, 7.777); - - QTransform tran1(mat1); - QTransform tran2(mat2); - QTransform dummy; - dummy.setMatrix(mat1.m11(), mat1.m12(), 0, - mat1.m21(), mat1.m22(), 0, - mat1.dx(), mat1.dy(), 1); - - QCOMPARE(tran1, dummy); - QCOMPARE(tran1.inverted(), dummy.inverted()); - QCOMPARE(tran1.inverted(), QTransform(mat1.inverted())); - QCOMPARE(tran2.inverted(), QTransform(mat2.inverted())); - - QMatrix mat3 = mat1 * mat2; - QTransform tran3 = tran1 * tran2; - QCOMPARE(QTransform(mat3), tran3); - - /* QMatrix::operator==() doesn't use qFuzzyCompare(), which - * on win32-g++ results in a failure. So we work around it by - * calling QTranform::operator==(), which performs a fuzzy compare. */ - QCOMPARE(QTransform(mat3), QTransform(tran3.toAffine())); - - QTransform tranInv = tran1.inverted(); - QMatrix matInv = mat1.inverted(); - - QRect rect(43, 70, 200, 200); - QPoint pt(43, 66); - QCOMPARE(tranInv.mapRect(rect), matInv.mapRect(rect)); - QCOMPARE(tranInv.map(pt), matInv.map(pt)); - - QPainterPath path; - path.moveTo(55, 60); - path.lineTo(110, 110); - path.quadTo(220, 50, 10, 20); - path.closeSubpath(); - QCOMPARE(tranInv.map(path), matInv.map(path)); -} - -void tst_QTransform::testOffset() -{ - QTransform trans; - const QMatrix &aff = trans.toAffine(); - QCOMPARE((void*)(&aff), (void*)(&trans)); -} -QT_WARNING_POP -#endif - void tst_QTransform::types() { QTransform m1; diff --git a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro b/tests/auto/gui/painting/qwmatrix/qwmatrix.pro deleted file mode 100644 index de6454025c..0000000000 --- a/tests/auto/gui/painting/qwmatrix/qwmatrix.pro +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG += testcase -TARGET = tst_qwmatrix -SOURCES += tst_qwmatrix.cpp -QT += testlib - -unix:!darwin:!haiku:!integrity: LIBS += -lm diff --git a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp deleted file mode 100644 index 281639c27a..0000000000 --- a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp +++ /dev/null @@ -1,334 +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 <QtTest/QtTest> -#include <qmatrix.h> -#include <qmath.h> -#include <qpolygon.h> - -#if QT_DEPRECATED_SINCE(5, 15) -QT_WARNING_PUSH -QT_WARNING_DISABLE_DEPRECATED - -class tst_QWMatrix : public QObject -{ - Q_OBJECT - -private slots: - void mapRect_data(); - void mapToPolygon_data(); - void mapRect(); - void operator_star_qwmatrix(); - void assignments(); - void mapToPolygon(); - void translate(); - void scale(); - void mapPolygon(); - -private: - void mapping_data(); -}; - -void tst_QWMatrix::mapRect_data() -{ - mapping_data(); -} - -void tst_QWMatrix::mapToPolygon_data() -{ - mapping_data(); -} - -void tst_QWMatrix::mapping_data() -{ - //create the testtable instance and define the elements - QTest::addColumn<QMatrix>("matrix"); - QTest::addColumn<QRect>("src"); - QTest::addColumn<QPolygon>("res"); - - //next we fill it with data - - // identity - QTest::newRow( "identity" ) << QMatrix( 1, 0, 0, 1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 10, 20, 30, 40 ) ); - // scaling - QTest::newRow( "scale 0" ) << QMatrix( 2, 0, 0, 2, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 20, 40, 60, 80 ) ); - QTest::newRow( "scale 1" ) << QMatrix( 10, 0, 0, 10, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 100, 200, 300, 400 ) ); - // mirroring - QTest::newRow( "mirror 0" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -40, 20, 30, 40 ) ); - QTest::newRow( "mirror 1" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 10, -60, 30, 40 ) ); - QTest::newRow( "mirror 2" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -40, -60, 30, 40 ) ); - QTest::newRow( "mirror 3" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -80, -120, 60, 80 ) ); - QTest::newRow( "mirror 4" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -400, -600, 300, 400 ) ); - QTest::newRow( "mirror 5" ) << QMatrix( -1, 0, 0, 1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -30, 0, 30, 40 ) ); - QTest::newRow( "mirror 6" ) << QMatrix( 1, 0, 0, -1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -40, 30, 40 ) ); - QTest::newRow( "mirror 7" ) << QMatrix( -1, 0, 0, -1, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -30, -40, 30, 40 ) ); - QTest::newRow( "mirror 8" ) << QMatrix( -2, 0, 0, -2, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -60, -80, 60, 80 ) ); - QTest::newRow( "mirror 9" ) << QMatrix( -10, 0, 0, -10, 0, 0 ) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -300, -400, 300, 400 ) ); - - const auto rotate = [](qreal degrees) { - const qreal rad = qDegreesToRadians(degrees); - return QMatrix(std::cos(rad), -std::sin(rad), - std::sin(rad), std::cos(rad), 0, 0); - }; - - // rotations - QTest::newRow( "rot 0 a" ) << rotate(0.) - << QRect( 0, 0, 30, 40 ) - << QPolygon ( QRect( 0, 0, 30, 40 ) ); - QTest::newRow( "rot 0 b" ) << rotate(0.00001f) - << QRect( 0, 0, 30, 40 ) - << QPolygon ( QRect( 0, 0, 30, 40 ) ); - QTest::newRow( "rot 0 c" ) << rotate(0.) - << QRect( 10, 20, 30, 40 ) - << QPolygon ( QRect( 10, 20, 30, 40 ) ); - QTest::newRow( "rot 0 d" ) << rotate(0.00001f) - << QRect( 10, 20, 30, 40 ) - << QPolygon ( QRect( 10, 20, 30, 40 ) ); - -#if 0 - const auto rotScale = [](qreal degrees, qreal scale) { - const qreal rad = qDegreesToRadians(degrees); - return QMatrix(scale * std::cos(rad), -scale * std::sin(rad), - scale * std::sin(rad), scale * std::cos(rad), 0, 0); - }; - // rotations with scaling - QTest::newRow( "rotscale 90 a" ) << rotScale(90., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -299, 400, 300 ) ); - QTest::newRow( "rotscale 90 b" ) << rotScale(90.00001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( 0, -299, 400, 300 ) ); - QTest::newRow( "rotscale 90 c" ) << rotScale(90., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 200, -399, 400, 300 ) ); - QTest::newRow( "rotscale 90 d" ) << rotScale(90.00001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 200, -399, 400, 300 ) ); - - QTest::newRow( "rotscale 180 a" ) << rotScale(180., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -299, -399, 300, 400 ) ); - QTest::newRow( "rotscale 180 b" ) << rotScale(180.000001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -299, -399, 300, 400 ) ); - QTest::newRow( "rotscale 180 c" ) << rotScale(180., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -399, -599, 300, 400 ) ); - QTest::newRow( "rotscale 180 d" ) << rotScale(180.000001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -399, -599, 300, 400 ) ); - - QTest::newRow( "rotscale 270 a" ) << rotScale(270., 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -399, 00, 400, 300 ) ); - QTest::newRow( "rotscale 270 b" ) << rotScale(270.0000001, 10) - << QRect( 0, 0, 30, 40 ) - << QPolygon( QRect( -399, 00, 400, 300 ) ); - QTest::newRow( "rotscale 270 c" ) << rotScale(270., 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -599, 100, 400, 300 ) ); - QTest::newRow( "rotscale 270 d" ) << rotScale(270.000001, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -599, 100, 400, 300 ) ); - - // rotations that are not multiples of 90 degrees. mapRect returns the bounding rect here. - QTest::newRow( "rot 45 a" ) << rotate(45) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( 0, -7, 14, 14 ) ); - QTest::newRow( "rot 45 b" ) << rotate(45) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 21, -14, 49, 49 ) ); - QTest::newRow( "rot 45 c" ) << rotScale(45, 10) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( 0, -70, 141, 141 ) ); - QTest::newRow( "rot 45 d" ) << rotScale(45, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( 212, -141, 495, 495 ) ); - - QTest::newRow( "rot -45 a" ) << rotate(-45) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( -7, 0, 14, 14 ) ); - QTest::newRow( "rot -45 b" ) << rotate(-45) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -35, 21, 49, 49 ) ); - QTest::newRow( "rot -45 c" ) << rotScale(-45, 10) - << QRect( 0, 0, 10, 10 ) - << QPolygon( QRect( -70, 0, 141, 141 ) ); - QTest::newRow( "rot -45 d" ) << rotScale(-45, 10) - << QRect( 10, 20, 30, 40 ) - << QPolygon( QRect( -353, 212, 495, 495 ) ); -#endif -} - -void tst_QWMatrix::mapRect() -{ - QFETCH( QMatrix, matrix ); - QFETCH( QRect, src ); -// qDebug( "got src: %d/%d (%d/%d), matrix=[ %f %f %f %f %f %f ]", -// src.x(), src.y(), src.width(), src.height(), -// matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), matrix.dx(), matrix.dy() ); - QTEST( QPolygon( matrix.mapRect(src) ), "res" ); -} - -void tst_QWMatrix::operator_star_qwmatrix() -{ - QMatrix m1( 2, 3, 4, 5, 6, 7 ); - QMatrix m2( 3, 4, 5, 6, 7, 8 ); - - QMatrix result1x2( 21, 26, 37, 46, 60, 74 ); - QMatrix result2x1( 22, 29, 34, 45, 52, 68); - - QMatrix product12 = m1*m2; - QMatrix product21 = m2*m1; - - QVERIFY( product12==result1x2 ); - QVERIFY( product21==result2x1 ); -} - - -void tst_QWMatrix::assignments() -{ - QMatrix m; - m.scale(2, 3); - m.rotate(45); - m.shear(4, 5); - - QMatrix c1(m); - - QCOMPARE(m.m11(), c1.m11()); - QCOMPARE(m.m12(), c1.m12()); - QCOMPARE(m.m21(), c1.m21()); - QCOMPARE(m.m22(), c1.m22()); - QCOMPARE(m.dx(), c1.dx()); - QCOMPARE(m.dy(), c1.dy()); - - QMatrix c2 = m; - QCOMPARE(m.m11(), c2.m11()); - QCOMPARE(m.m12(), c2.m12()); - QCOMPARE(m.m21(), c2.m21()); - QCOMPARE(m.m22(), c2.m22()); - QCOMPARE(m.dx(), c2.dx()); - QCOMPARE(m.dy(), c2.dy()); -} - - -void tst_QWMatrix::mapToPolygon() -{ - QFETCH( QMatrix, matrix ); - QFETCH( QRect, src ); - QFETCH( QPolygon, res ); - - QCOMPARE( matrix.mapToPolygon( src ), res ); -} - - -void tst_QWMatrix::translate() -{ - QMatrix m( 1, 2, 3, 4, 5, 6 ); - QMatrix res2( m ); - QMatrix res( 1, 2, 3, 4, 75, 106 ); - m.translate( 10, 20 ); - QVERIFY( m == res ); - m.translate( -10, -20 ); - QVERIFY( m == res2 ); -} - -void tst_QWMatrix::scale() -{ - QMatrix m( 1, 2, 3, 4, 5, 6 ); - QMatrix res2( m ); - QMatrix res( 10, 20, 60, 80, 5, 6 ); - m.scale( 10, 20 ); - QVERIFY( m == res ); - m.scale( 1./10., 1./20. ); - QVERIFY( m == res2 ); -} - -void tst_QWMatrix::mapPolygon() -{ - QPolygon poly; - poly << QPoint(0, 0) << QPoint(1, 1) << QPoint(100, 1) << QPoint(1, 100) << QPoint(-1, -1) << QPoint(-1000, 1000); - - { - QMatrix m; - m.rotate(90); - - // rotating 90 degrees four times should result in original poly - QPolygon mapped = m.map(m.map(m.map(m.map(poly)))); - QCOMPARE(mapped, poly); - - QMatrix m2; - m2.scale(10, 10); - QMatrix m3; - m3.scale(0.1, 0.1); - - mapped = m3.map(m2.map(poly)); - QCOMPARE(mapped, poly); - } - - { - QMatrix m(1, 2, 3, 4, 5, 6); - - QPolygon mapped = m.map(poly); - for (int i = 0; i < mapped.size(); ++i) - QCOMPARE(mapped.at(i), m.map(poly.at(i))); - } -} - -QT_WARNING_POP -#endif - -QTEST_APPLESS_MAIN(tst_QWMatrix) -#include "tst_qwmatrix.moc" diff --git a/tests/auto/gui/qopengl/CMakeLists.txt b/tests/auto/gui/qopengl/CMakeLists.txt new file mode 100644 index 0000000000..1c7c9b6ec0 --- /dev/null +++ b/tests/auto/gui/qopengl/CMakeLists.txt @@ -0,0 +1,23 @@ +# Generated from qopengl.pro. + +##################################################################### +## tst_qopengl Test: +##################################################################### + +add_qt_test(tst_qopengl + SOURCES + tst_qopengl.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::OpenGL +) + +## Scopes: +##################################################################### + +extend_target(tst_qopengl CONDITION LINUX AND QT_FEATURE_xcb AND QT_FEATURE_xcb_glx_plugin + DEFINES + USE_GLX +) diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro index 722c99ee0b..604aa59d8a 100644 --- a/tests/auto/gui/qopengl/qopengl.pro +++ b/tests/auto/gui/qopengl/qopengl.pro @@ -4,7 +4,7 @@ CONFIG += testcase TARGET = tst_qopengl -QT += gui-private core-private testlib +QT += opengl gui-private core-private testlib SOURCES += tst_qopengl.cpp diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 8e516e428a..ad0dfb5c08 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -26,15 +26,15 @@ ** ****************************************************************************/ - +#include <QtOpenGL/QOpenGLFramebufferObject> +#include <QtOpenGL/QOpenGLPaintDevice> +#include <QtOpenGL/QOpenGLTexture> +#include <QtOpenGL/qopengltextureblitter.h> +#include <QtOpenGL/QOpenGLVertexArrayObject> +#include <QtOpenGL/QOpenGLBuffer> #include <QtGui/private/qopenglcontext_p.h> -#include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QOpenGLFunctions> #include <QtGui/QOpenGLFunctions_4_2_Core> -#include <QtGui/QOpenGLVertexArrayObject> -#include <QtGui/QOpenGLBuffer> -#include <QtGui/QOpenGLPaintDevice> -#include <QtGui/QOpenGLTexture> #include <QtGui/QPainter> #include <QtGui/QPainterPath> #include <QtGui/QScreen> @@ -42,7 +42,6 @@ #include <QtGui/QOffscreenSurface> #include <QtGui/QGenericMatrix> #include <QtGui/QMatrix4x4> -#include <QtGui/qopengltextureblitter.h> #include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qopenglextensions_p.h> #include <qpa/qplatformintegration.h> diff --git a/tests/auto/gui/qopenglconfig/CMakeLists.txt b/tests/auto/gui/qopenglconfig/CMakeLists.txt new file mode 100644 index 0000000000..26ce58d98c --- /dev/null +++ b/tests/auto/gui/qopenglconfig/CMakeLists.txt @@ -0,0 +1,18 @@ +# Generated from qopenglconfig.pro. + +##################################################################### +## tst_qopenglconfig Test: +##################################################################### + +# Collect test data +list(APPEND test_data "buglist.json") + +add_qt_test(tst_qopenglconfig + SOURCES + tst_qopenglconfig.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) diff --git a/tests/auto/gui/qvulkan/CMakeLists.txt b/tests/auto/gui/qvulkan/CMakeLists.txt new file mode 100644 index 0000000000..6316aa8f68 --- /dev/null +++ b/tests/auto/gui/qvulkan/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qvulkan.pro. + +##################################################################### +## tst_qvulkan Test: +##################################################################### + +add_qt_test(tst_qvulkan + SOURCES + tst_qvulkan.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/rhi/CMakeLists.txt b/tests/auto/gui/rhi/CMakeLists.txt new file mode 100644 index 0000000000..786e121f00 --- /dev/null +++ b/tests/auto/gui/rhi/CMakeLists.txt @@ -0,0 +1,4 @@ +# Generated from rhi.pro. + +add_subdirectory(qshader) +add_subdirectory(qrhi) diff --git a/tests/auto/gui/rhi/qrhi/CMakeLists.txt b/tests/auto/gui/rhi/qrhi/CMakeLists.txt new file mode 100644 index 0000000000..8c3026c176 --- /dev/null +++ b/tests/auto/gui/rhi/qrhi/CMakeLists.txt @@ -0,0 +1,26 @@ +# Generated from qrhi.pro. + +##################################################################### +## tst_qrhi Test: +##################################################################### + +add_qt_test(tst_qrhi + SOURCES + tst_qrhi.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set(qrhi_resource_files + "data" +) + +add_qt_resource(tst_qrhi "qrhi" + PREFIX + "/" + FILES + ${qrhi_resource_files} +) + diff --git a/tests/auto/gui/rhi/qshader/CMakeLists.txt b/tests/auto/gui/rhi/qshader/CMakeLists.txt new file mode 100644 index 0000000000..472fc3b7e4 --- /dev/null +++ b/tests/auto/gui/rhi/qshader/CMakeLists.txt @@ -0,0 +1,26 @@ +# Generated from qshader.pro. + +##################################################################### +## tst_qshader Test: +##################################################################### + +add_qt_test(tst_qshader + SOURCES + tst_qshader.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set(qshader_resource_files + "data" +) + +add_qt_resource(tst_qshader "qshader" + PREFIX + "/" + FILES + ${qshader_resource_files} +) + diff --git a/tests/auto/gui/text/CMakeLists.txt b/tests/auto/gui/text/CMakeLists.txt new file mode 100644 index 0000000000..b5c91a2cfa --- /dev/null +++ b/tests/auto/gui/text/CMakeLists.txt @@ -0,0 +1,41 @@ +# Generated from text.pro. + +add_subdirectory(qabstracttextdocumentlayout) +add_subdirectory(qfont) +add_subdirectory(qfontdatabase) +add_subdirectory(qfontmetrics) +add_subdirectory(qglyphrun) +add_subdirectory(qrawfont) +add_subdirectory(qstatictext) +add_subdirectory(qsyntaxhighlighter) +add_subdirectory(qtextblock) +add_subdirectory(qtextcursor) +add_subdirectory(qtextdocumentfragment) +add_subdirectory(qtextdocumentlayout) +add_subdirectory(qtextformat) +add_subdirectory(qtextlist) +add_subdirectory(qtextobject) +# 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) + add_subdirectory(qcssparser) +endif() +if(QT_FEATURE_private_tests) + add_subdirectory(qfontcache) + add_subdirectory(qtextlayout) + add_subdirectory(qzip) + add_subdirectory(qtextodfwriter) +endif() +if(TARGET Qt::Xml) + add_subdirectory(qtextdocument) +endif() +if(QT_FEATURE_private_tests AND UNIX) + add_subdirectory(qtextpiecetable) +endif() +if(QT_FEATURE_textmarkdownreader) + add_subdirectory(qtextmarkdownimporter) +endif() +if(QT_FEATURE_private_tests AND QT_FEATURE_textmarkdownwriter) + add_subdirectory(qtextmarkdownwriter) +endif() diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt new file mode 100644 index 0000000000..62d4ce9d32 --- /dev/null +++ b/tests/auto/gui/text/qabstracttextdocumentlayout/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qabstracttextdocumentlayout.pro. + +##################################################################### +## tst_qabstracttextdocumentlayout Test: +##################################################################### + +add_qt_test(tst_qabstracttextdocumentlayout + SOURCES + tst_qabstracttextdocumentlayout.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/text/qcssparser/CMakeLists.txt b/tests/auto/gui/text/qcssparser/CMakeLists.txt new file mode 100644 index 0000000000..09e1672bc4 --- /dev/null +++ b/tests/auto/gui/text/qcssparser/CMakeLists.txt @@ -0,0 +1,57 @@ +# Generated from qcssparser.pro. + +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qcssparser Test: +##################################################################### + +# Collect test data +list(APPEND test_data "testdata") + +add_qt_test(tst_qcssparser + SOURCES + tst_qcssparser.cpp + DEFINES + SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" + PUBLIC_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" + ) + + add_qt_resource(tst_qcssparser "testdata" + PREFIX + "/" + FILES + ${testdata_resource_files} + ) +endif() diff --git a/tests/auto/gui/text/qfont/CMakeLists.txt b/tests/auto/gui/text/qfont/CMakeLists.txt new file mode 100644 index 0000000000..a04f8365b1 --- /dev/null +++ b/tests/auto/gui/text/qfont/CMakeLists.txt @@ -0,0 +1,35 @@ +# Generated from qfont.pro. + +##################################################################### +## tst_qfont Test: +##################################################################### + +add_qt_test(tst_qfont + SOURCES + tst_qfont.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set(testfont_resource_files + "weirdfont.otf" +) + +add_qt_resource(tst_qfont "testfont" + PREFIX + "/" + FILES + ${testfont_resource_files} +) + + +## Scopes: +##################################################################### + +extend_target(tst_qfont CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/text/qfontcache/CMakeLists.txt b/tests/auto/gui/text/qfontcache/CMakeLists.txt new file mode 100644 index 0000000000..84f6373328 --- /dev/null +++ b/tests/auto/gui/text/qfontcache/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qfontcache.pro. + +##################################################################### +## tst_qfontcache Test: +##################################################################### + +add_qt_test(tst_qfontcache + SOURCES + tst_qfontcache.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt new file mode 100644 index 0000000000..65c6224a00 --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt @@ -0,0 +1,47 @@ +# Generated from qfontdatabase.pro. + +##################################################################### +## tst_qfontdatabase Test: +##################################################################### + +# Collect test data +list(APPEND test_data "LED_REAL.TTF") + +add_qt_test(tst_qfontdatabase + SOURCES + tst_qfontdatabase.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) + +# Resources: +set_source_files_properties("../../../shared/resources/testfont.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf" +) +set_source_files_properties("../../../shared/resources/testfont_condensed.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont_condensed.ttf" +) +set_source_files_properties("../../../shared/resources/testfont_italic.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont_italic.ttf" +) +set_source_files_properties("../../../shared/resources/testfont_open.otf" + PROPERTIES QT_RESOURCE_ALIAS "testfont_open.otf" +) +set(testdata_resource_files + "../../../shared/resources/testfont.ttf" + "../../../shared/resources/testfont_condensed.ttf" + "../../../shared/resources/testfont_italic.ttf" + "../../../shared/resources/testfont_open.otf" + "LED_REAL.TTF" +) + +add_qt_resource(tst_qfontdatabase "testdata" + PREFIX + "/" + FILES + ${testdata_resource_files} +) + diff --git a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt new file mode 100644 index 0000000000..029f5d5ce3 --- /dev/null +++ b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt @@ -0,0 +1,31 @@ +# Generated from qfontmetrics.pro. + +##################################################################### +## tst_qfontmetrics Test: +##################################################################### + +add_qt_test(tst_qfontmetrics + SOURCES + tst_qfontmetrics.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set_source_files_properties("../../../shared/resources/testfont.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf" +) +set(testfont_resource_files + "../../../shared/resources/testfont.ttf" + "ucs4font.ttf" +) + +add_qt_resource(tst_qfontmetrics "testfont" + PREFIX + "/fonts" + FILES + ${testfont_resource_files} +) + diff --git a/tests/auto/gui/text/qglyphrun/CMakeLists.txt b/tests/auto/gui/text/qglyphrun/CMakeLists.txt new file mode 100644 index 0000000000..8efcfc0cf9 --- /dev/null +++ b/tests/auto/gui/text/qglyphrun/CMakeLists.txt @@ -0,0 +1,28 @@ +# Generated from qglyphrun.pro. + +##################################################################### +## tst_qglyphrun Test: +##################################################################### + +add_qt_test(tst_qglyphrun + SOURCES + tst_qglyphrun.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +# Resources: +set_source_files_properties("../../../shared/resources/test.ttf" + PROPERTIES QT_RESOURCE_ALIAS "test.ttf" +) +set(testdata_resource_files + "../../../shared/resources/test.ttf" +) + +add_qt_resource(tst_qglyphrun "testdata" + PREFIX + "/" + FILES + ${testdata_resource_files} +) + diff --git a/tests/auto/gui/text/qinputcontrol/CMakeLists.txt b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt new file mode 100644 index 0000000000..e544fb313c --- /dev/null +++ b/tests/auto/gui/text/qinputcontrol/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qinputcontrol.pro. + +##################################################################### +## tst_qinputcontrol Test: +##################################################################### + +add_qt_test(tst_qinputcontrol + SOURCES + tst_qinputcontrol.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qrawfont/CMakeLists.txt b/tests/auto/gui/text/qrawfont/CMakeLists.txt new file mode 100644 index 0000000000..5044866c49 --- /dev/null +++ b/tests/auto/gui/text/qrawfont/CMakeLists.txt @@ -0,0 +1,32 @@ +# Generated from qrawfont.pro. + +##################################################################### +## tst_qrawfont Test: +##################################################################### + +add_qt_test(tst_qrawfont + SOURCES + tst_qrawfont.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set_source_files_properties("../../../shared/resources/testfont.ttf" + PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf" +) +set(testdata_resource_files + "../../../shared/resources/testfont.ttf" + "testfont_bold_italic.ttf" + "testfont_os2_v1.ttf" +) + +add_qt_resource(tst_qrawfont "testdata" + PREFIX + "/" + FILES + ${testdata_resource_files} +) + diff --git a/tests/auto/gui/text/qstatictext/CMakeLists.txt b/tests/auto/gui/text/qstatictext/CMakeLists.txt new file mode 100644 index 0000000000..80eef2f254 --- /dev/null +++ b/tests/auto/gui/text/qstatictext/CMakeLists.txt @@ -0,0 +1,21 @@ +# Generated from qstatictext.pro. + +##################################################################### +## tst_qstatictext Test: +##################################################################### + +add_qt_test(tst_qstatictext + SOURCES + tst_qstatictext.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qstatictext CONDITION QT_FEATURE_private_tests + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt new file mode 100644 index 0000000000..c4ea8b4a1e --- /dev/null +++ b/tests/auto/gui/text/qsyntaxhighlighter/CMakeLists.txt @@ -0,0 +1,20 @@ +# Generated from qsyntaxhighlighter.pro. + +##################################################################### +## tst_qsyntaxhighlighter Test: +##################################################################### + +add_qt_test(tst_qsyntaxhighlighter + SOURCES + tst_qsyntaxhighlighter.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qsyntaxhighlighter CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/text/qtextblock/CMakeLists.txt b/tests/auto/gui/text/qtextblock/CMakeLists.txt new file mode 100644 index 0000000000..18e0be18c6 --- /dev/null +++ b/tests/auto/gui/text/qtextblock/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextblock.pro. + +##################################################################### +## tst_qtextblock Test: +##################################################################### + +add_qt_test(tst_qtextblock + SOURCES + tst_qtextblock.cpp + PUBLIC_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 a9004edfc0..0d638706eb 100644 --- a/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp +++ b/tests/auto/gui/text/qtextblock/tst_qtextblock.cpp @@ -89,7 +89,7 @@ void tst_QTextBlock::fragmentOverBlockBoundaries() // Block separators are always a fragment of their self. Thus: // |Hello|\b|World|\b| #if !defined(Q_OS_WIN) - QCOMPARE(doc->docHandle()->fragmentMap().numNodes(), 4); + QCOMPARE(QTextDocumentPrivate::get(doc)->fragmentMap().numNodes(), 4); #endif QCOMPARE(cursor.block().text(), QString("Hello")); cursor.movePosition(QTextCursor::NextBlock); diff --git a/tests/auto/gui/text/qtextcursor/CMakeLists.txt b/tests/auto/gui/text/qtextcursor/CMakeLists.txt new file mode 100644 index 0000000000..78b6ed191d --- /dev/null +++ b/tests/auto/gui/text/qtextcursor/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextcursor.pro. + +##################################################################### +## tst_qtextcursor Test: +##################################################################### + +add_qt_test(tst_qtextcursor + SOURCES + tst_qtextcursor.cpp + PUBLIC_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 2bc611fe93..3da32a2842 100644 --- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp +++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp @@ -1280,7 +1280,7 @@ void tst_QTextCursor::anchorInitialized1() void tst_QTextCursor::anchorInitialized2() { cursor.insertBlock(); - cursor = QTextCursorPrivate::fromPosition(cursor.block().docHandle(), 1); + cursor = QTextCursorPrivate::fromPosition(const_cast<QTextDocumentPrivate *>(QTextDocumentPrivate::get(cursor.block())), 1); QCOMPARE(cursor.position(), 1); QCOMPARE(cursor.anchor(), 1); QCOMPARE(cursor.selectionStart(), 1); diff --git a/tests/auto/gui/text/qtextdocument/CMakeLists.txt b/tests/auto/gui/text/qtextdocument/CMakeLists.txt new file mode 100644 index 0000000000..7ea22d3fb0 --- /dev/null +++ b/tests/auto/gui/text/qtextdocument/CMakeLists.txt @@ -0,0 +1,16 @@ +# Generated from qtextdocument.pro. + +##################################################################### +## tst_qtextdocument Test: +##################################################################### + +add_qt_test(tst_qtextdocument + SOURCES + common.h + tst_qtextdocument.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::Xml +) diff --git a/tests/auto/gui/text/qtextdocument/common.h b/tests/auto/gui/text/qtextdocument/common.h index 33afb98c61..0681f7f0e2 100644 --- a/tests/auto/gui/text/qtextdocument/common.h +++ b/tests/auto/gui/text/qtextdocument/common.h @@ -42,7 +42,7 @@ public: virtual void documentChanged(int from, int oldLength, int length) { called = true; - lastDocumentLengths.append(document()->docHandle()->length()); + lastDocumentLengths.append(QTextDocumentPrivate::get(document())->length()); if (f < 0) return; diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 10a627bb82..71456fbd09 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -70,8 +70,6 @@ private slots: void find_data(); void find(); void find2(); - void findWithRegExp_data(); - void findWithRegExp(); void findWithRegularExpression_data(); void findWithRegularExpression(); void findMultiple(); @@ -380,39 +378,8 @@ void tst_QTextDocument::find() } //search using a regular expression - QRegExp expr(needle); - expr.setPatternSyntax(QRegExp::FixedString); + QRegularExpression expr(QRegularExpression::escape(needle)); QTextDocument::FindFlags flg(flags); - expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); - cursor = doc->find(expr, from, flg); - - if (anchor != -1) { - QCOMPARE(cursor.anchor(), anchor); - QCOMPARE(cursor.position(), position); - } else { - QVERIFY(cursor.isNull()); - } -} - -void tst_QTextDocument::findWithRegExp_data() -{ - buildRegExpData(); -} - -void tst_QTextDocument::findWithRegExp() -{ - QFETCH(QString, haystack); - QFETCH(QString, needle); - QFETCH(int, flags); - QFETCH(int, from); - QFETCH(int, anchor); - QFETCH(int, position); - - cursor.insertText(haystack); - //search using a regular expression - QRegExp expr(needle); - QTextDocument::FindFlags flg(flags); - expr.setCaseSensitivity((flg & QTextDocument::FindCaseSensitively) ? Qt::CaseSensitive : Qt::CaseInsensitive); cursor = doc->find(expr, from, flg); if (anchor != -1) { @@ -482,26 +449,6 @@ void tst_QTextDocument::findMultiple() QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); - - QRegExp expr("bar"); - expr.setPatternSyntax(QRegExp::FixedString); - - cursor.movePosition(QTextCursor::End); - cursor = doc->find(expr, cursor, QTextDocument::FindBackward); - QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); - QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); - cursor = doc->find(expr, cursor, QTextDocument::FindBackward); - QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); - QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); - - cursor.movePosition(QTextCursor::Start); - cursor = doc->find(expr, cursor); - QCOMPARE(cursor.selectionStart(), text.indexOf("bar")); - QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); - cursor = doc->find(expr, cursor); - QCOMPARE(cursor.selectionStart(), text.lastIndexOf("bar")); - QCOMPARE(cursor.selectionEnd(), cursor.selectionStart() + 3); - QRegularExpression regularExpression("bar"); cursor.movePosition(QTextCursor::End); @@ -1863,7 +1810,7 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport() QTextDocumentFragment fragment(cursor); QString expected = htmlHead; - expected.replace(QRegExp("<body.*>"), QString("<body>")); + expected.replace(QRegularExpression("<body.*>"), QString("<body>")); expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<span style=\" color:#00ff00;\">Blah</span><!--EndFragment--></p>") + htmlTail; QCOMPARE(fragment.toHtml(), expected); } @@ -1883,7 +1830,7 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport() QTextDocumentFragment fragment(cursor); QString expected = htmlHead; - expected.replace(QRegExp("<body.*>"), QString("<body>")); + expected.replace(QRegularExpression("<body.*>"), QString("<body>")); expected += QString("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><!--StartFragment-->Test<!--EndFragment--></p>") + htmlTail; QCOMPARE(fragment.toHtml(), expected); } @@ -2024,8 +1971,9 @@ void tst_QTextDocument::capitalizationHtmlInExport() { doc->setPlainText("Test"); - QRegExp re(".*span style=\"(.*)\">Test.*"); - QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span + QRegularExpression re(".*span style=\"(.*)\">Test.*"); + QCOMPARE(re.captureCount(), 1); + QVERIFY(!re.match(doc->toHtml()).hasMatch()); // no span QTextCursor cursor(doc); cursor.setPosition(4, QTextCursor::KeepAnchor); @@ -2034,23 +1982,23 @@ void tst_QTextDocument::capitalizationHtmlInExport() cursor.mergeCharFormat(cf); const QString smallcaps = doc->toHtml(); - QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.captureCount(), 1); - QCOMPARE(re.cap(1).trimmed(), QString("font-variant:small-caps;")); + auto match = re.match(doc->toHtml()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1).trimmed(), QString("font-variant:small-caps;")); cf.setFontCapitalization(QFont::AllUppercase); cursor.mergeCharFormat(cf); const QString uppercase = doc->toHtml(); - QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.captureCount(), 1); - QCOMPARE(re.cap(1).trimmed(), QString("text-transform:uppercase;")); + match = re.match(doc->toHtml()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1).trimmed(), QString("text-transform:uppercase;")); cf.setFontCapitalization(QFont::AllLowercase); cursor.mergeCharFormat(cf); const QString lowercase = doc->toHtml(); - QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.captureCount(), 1); - QCOMPARE(re.cap(1).trimmed(), QString("text-transform:lowercase;")); + match = re.match(doc->toHtml()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1).trimmed(), QString("text-transform:lowercase;")); doc->setHtml(smallcaps); cursor.setPosition(1); @@ -2065,8 +2013,9 @@ void tst_QTextDocument::wordspacingHtmlExport() { doc->setPlainText("Test"); - QRegExp re(".*span style=\"(.*)\">Test.*"); - QVERIFY(re.exactMatch(doc->toHtml()) == false); // no span + QRegularExpression re(".*span style=\"(.*)\">Test.*"); + QCOMPARE(re.captureCount(), 1); + QVERIFY(!re.match(doc->toHtml()).hasMatch()); // no span QTextCursor cursor(doc); cursor.setPosition(4, QTextCursor::KeepAnchor); @@ -2074,16 +2023,16 @@ void tst_QTextDocument::wordspacingHtmlExport() cf.setFontWordSpacing(4); cursor.mergeCharFormat(cf); - QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.captureCount(), 1); - QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:4px;")); + auto match = re.match(doc->toHtml()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1).trimmed(), QString("word-spacing:4px;")); cf.setFontWordSpacing(-8.5); cursor.mergeCharFormat(cf); - QVERIFY(re.exactMatch(doc->toHtml())); - QCOMPARE(re.captureCount(), 1); - QCOMPARE(re.cap(1).trimmed(), QString("word-spacing:-8.5px;")); + match = re.match(doc->toHtml()); + QVERIFY(match.hasMatch()); + QCOMPARE(match.captured(1).trimmed(), QString("word-spacing:-8.5px;")); } class CursorPosSignalSpy : public QObject diff --git a/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt new file mode 100644 index 0000000000..f92a82a262 --- /dev/null +++ b/tests/auto/gui/text/qtextdocumentfragment/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextdocumentfragment.pro. + +##################################################################### +## tst_qtextdocumentfragment Test: +##################################################################### + +add_qt_test(tst_qtextdocumentfragment + SOURCES + tst_qtextdocumentfragment.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt new file mode 100644 index 0000000000..c7212209ee --- /dev/null +++ b/tests/auto/gui/text/qtextdocumentlayout/CMakeLists.txt @@ -0,0 +1,20 @@ +# Generated from qtextdocumentlayout.pro. + +##################################################################### +## tst_qtextdocumentlayout Test: +##################################################################### + +add_qt_test(tst_qtextdocumentlayout + SOURCES + tst_qtextdocumentlayout.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qtextdocumentlayout CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/text/qtextformat/CMakeLists.txt b/tests/auto/gui/text/qtextformat/CMakeLists.txt new file mode 100644 index 0000000000..be7653abd4 --- /dev/null +++ b/tests/auto/gui/text/qtextformat/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextformat.pro. + +##################################################################### +## tst_qtextformat Test: +##################################################################### + +add_qt_test(tst_qtextformat + SOURCES + tst_qtextformat.cpp + PUBLIC_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 4ab80bdcfe..4e5ef7c555 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -40,6 +40,10 @@ #include <qtextlayout.h> #include <qabstracttextdocumentlayout.h> +#ifndef QT_NO_DATASTREAM +# include <qdatastream.h> +#endif + class tst_QTextFormat : public QObject { Q_OBJECT @@ -61,6 +65,10 @@ private slots: void setFont_collection_data(); void setFont_collection(); void clearCollection(); + +#ifndef QT_NO_DATASTREAM + void dataStreamCompatibility(); +#endif }; /*! \internal @@ -677,5 +685,125 @@ void tst_QTextFormat::clearCollection() QCOMPARE(collection.defaultFont(), f); // kept, QTextDocument::clear or setPlainText should not reset the font set by setDefaultFont } +#ifndef QT_NO_DATASTREAM +void tst_QTextFormat::dataStreamCompatibility() +{ + // Make sure that we are still compatible with the old values of QTextFormat::FontLetterSpacingType + // and QTextFormat::FontStretch, when used with earlier QDataStream versions + QTextCharFormat format; + format.setFontStretch(42); + format.setFontLetterSpacingType(QFont::AbsoluteSpacing); + + // Sanity check + { + QMap<int, QVariant> properties = format.properties(); + QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType)); + QVERIFY(properties.contains(QTextFormat::FontStretch)); + QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); + QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); + } + + QByteArray memory; + + // Current stream version + { + { + QBuffer buffer(&memory); + buffer.open(QIODevice::WriteOnly); + + QDataStream stream(&buffer); + stream << format; + } + + { + QBuffer buffer(&memory); + buffer.open(QIODevice::ReadOnly); + + QDataStream stream(&buffer); + + QTextFormat other; + stream >> other; + + { + QMap<int, QVariant> properties = other.properties(); + QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType)); + QVERIFY(properties.contains(QTextFormat::FontStretch)); + QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); + QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); + } + } + + { + QBuffer buffer(&memory); + buffer.open(QIODevice::ReadOnly); + + QDataStream stream(&buffer); + + quint32 type; + stream >> type; + + QMap<qint32, QVariant> properties; + stream >> properties; + QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType)); + QVERIFY(properties.contains(QTextFormat::FontStretch)); + QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); + QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); + } + } + + // Qt 5.15 stream version + memory.clear(); + { + { + QBuffer buffer(&memory); + buffer.open(QIODevice::WriteOnly); + + QDataStream stream(&buffer); + stream.setVersion(QDataStream::Qt_5_15); + stream << format; + } + + { + QBuffer buffer(&memory); + buffer.open(QIODevice::ReadOnly); + + QDataStream stream(&buffer); + stream.setVersion(QDataStream::Qt_5_15); + + QTextFormat other; + stream >> other; + + { + QMap<int, QVariant> properties = other.properties(); + QVERIFY(properties.contains(QTextFormat::FontLetterSpacingType)); + QVERIFY(properties.contains(QTextFormat::FontStretch)); + QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); + QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); + } + } + + { + QBuffer buffer(&memory); + buffer.open(QIODevice::ReadOnly); + + QDataStream stream(&buffer); + stream.setVersion(QDataStream::Qt_5_15); + + quint32 type; + stream >> type; + + // Verify that old data stream still has the compatibility values + QMap<qint32, QVariant> properties; + stream >> properties; + QVERIFY(!properties.contains(QTextFormat::FontLetterSpacingType)); + QVERIFY(!properties.contains(QTextFormat::FontStretch)); + QVERIFY(properties.contains(QTextFormat::OldFontLetterSpacingType)); + QVERIFY(properties.contains(QTextFormat::OldFontStretch)); + } + } + +} +#endif // QT_NO_DATASTREAM + QTEST_MAIN(tst_QTextFormat) #include "tst_qtextformat.moc" diff --git a/tests/auto/gui/text/qtextlayout/CMakeLists.txt b/tests/auto/gui/text/qtextlayout/CMakeLists.txt new file mode 100644 index 0000000000..c87d5bdd4d --- /dev/null +++ b/tests/auto/gui/text/qtextlayout/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextlayout.pro. + +##################################################################### +## tst_qtextlayout Test: +##################################################################### + +add_qt_test(tst_qtextlayout + SOURCES + tst_qtextlayout.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qtextlist/CMakeLists.txt b/tests/auto/gui/text/qtextlist/CMakeLists.txt new file mode 100644 index 0000000000..f22de38a8c --- /dev/null +++ b/tests/auto/gui/text/qtextlist/CMakeLists.txt @@ -0,0 +1,15 @@ +# Generated from qtextlist.pro. + +##################################################################### +## tst_qtextlist Test: +##################################################################### + +add_qt_test(tst_qtextlist + SOURCES + ../qtextdocument/common.h + tst_qtextlist.cpp + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt new file mode 100644 index 0000000000..29cafad93f --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownimporter/CMakeLists.txt @@ -0,0 +1,23 @@ +# Generated from qtextmarkdownimporter.pro. + +##################################################################### +## tst_qtextmarkdownimporter Test: +##################################################################### + +# 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") + +add_qt_test(tst_qtextmarkdownimporter + SOURCES + tst_qtextmarkdownimporter.cpp + DEFINES + SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) diff --git a/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt new file mode 100644 index 0000000000..7360b40994 --- /dev/null +++ b/tests/auto/gui/text/qtextmarkdownwriter/CMakeLists.txt @@ -0,0 +1,21 @@ +# Generated from qtextmarkdownwriter.pro. + +##################################################################### +## tst_qtextmarkdownwriter Test: +##################################################################### + +# Collect test data +list(APPEND test_data "data/example.md") +list(APPEND test_data "data/blockquotes.md") + +add_qt_test(tst_qtextmarkdownwriter + SOURCES + tst_qtextmarkdownwriter.cpp + DEFINES + SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + TESTDATA ${test_data} +) diff --git a/tests/auto/gui/text/qtextobject/CMakeLists.txt b/tests/auto/gui/text/qtextobject/CMakeLists.txt new file mode 100644 index 0000000000..b8d7f7b548 --- /dev/null +++ b/tests/auto/gui/text/qtextobject/CMakeLists.txt @@ -0,0 +1,20 @@ +# Generated from qtextobject.pro. + +##################################################################### +## tst_qtextobject Test: +##################################################################### + +add_qt_test(tst_qtextobject + SOURCES + tst_qtextobject.cpp + PUBLIC_LIBRARIES + Qt::Gui +) + +## Scopes: +##################################################################### + +extend_target(tst_qtextobject CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt new file mode 100644 index 0000000000..18c84e5a45 --- /dev/null +++ b/tests/auto/gui/text/qtextodfwriter/CMakeLists.txt @@ -0,0 +1,16 @@ +# Generated from qtextodfwriter.pro. + +##################################################################### +## tst_qtextodfwriter Test: +##################################################################### + +add_qt_test(tst_qtextodfwriter + SOURCES + tst_qtextodfwriter.cpp + DEFINES + SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt new file mode 100644 index 0000000000..5fb8db5405 --- /dev/null +++ b/tests/auto/gui/text/qtextpiecetable/CMakeLists.txt @@ -0,0 +1,25 @@ +# Generated from qtextpiecetable.pro. + +if(WIN32) + return() +endif() +if(NOT QT_FEATURE_private_tests) + return() +endif() + +##################################################################### +## tst_qtextpiecetable Test: +##################################################################### + +add_qt_test(tst_qtextpiecetable + SOURCES + ../qtextdocument/common.h + tst_qtextpiecetable.cpp + PUBLIC_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 39f5e9ecc3..436cd09914 100644 --- a/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp +++ b/tests/auto/gui/text/qtextpiecetable/tst_qtextpiecetable.cpp @@ -110,7 +110,7 @@ tst_QTextPieceTable::tst_QTextPieceTable() void tst_QTextPieceTable::init() { doc = new QTextDocument(0); - table = doc->docHandle(); + table = QTextDocumentPrivate::get(doc); blockFormatIndex = table->formatCollection()->indexForFormat(QTextBlockFormat()); charFormatIndex = table->formatCollection()->indexForFormat(QTextCharFormat()); } diff --git a/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt new file mode 100644 index 0000000000..8d94e33b6c --- /dev/null +++ b/tests/auto/gui/text/qtextscriptengine/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qtextscriptengine.pro. + +##################################################################### +## tst_qtextscriptengine Test: +##################################################################### + +add_qt_test(tst_qtextscriptengine + SOURCES + tst_qtextscriptengine.cpp + PUBLIC_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 new file mode 100644 index 0000000000..b2434569d4 --- /dev/null +++ b/tests/auto/gui/text/qtextscriptengine/generate/CMakeLists.txt @@ -0,0 +1,17 @@ +# Generated from generate.pro. + +##################################################################### +## generate Binary: +##################################################################### + +add_qt_executable(generate + GUI + SOURCES + main.cpp + INCLUDE_DIRECTORIES + . + /usr/include/freetype2 + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui +) diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index 0371f51961..cea1dc6dd3 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -1210,6 +1210,10 @@ void tst_QTextScriptEngine::thaiIsolatedSaraAm() void tst_QTextScriptEngine::thaiWithZWJ() { +#if QT_CONFIG(system_harfbuzz) + QSKIP("Requires up-to-date Harfbuzz"); +#endif + QFontDatabase db; if (!db.families().contains("Waree")) QSKIP("couldn't find 'Waree' font"); @@ -1217,9 +1221,6 @@ void tst_QTextScriptEngine::thaiWithZWJ() QFont font(QStringLiteral("Waree")); font.setStyleStrategy(QFont::NoFontMerging); - if (QFontInfo(font).styleName() != QStringLiteral("Book")) - QSKIP("couldn't find 'Waree Book' font"); - QString s(QString::fromUtf8("\xe0\xb8\xa3\xe2\x80\x8d\xe0\xb8\xa3\xe2\x80" "\x8c\x2e\xe0\xb8\xa3\x2e\xe2\x80\x9c\xe0\xb8" "\xa3\xe2\x80\xa6\xe0\xb8\xa3\xe2\x80\x9d\xe0" @@ -1239,14 +1240,13 @@ void tst_QTextScriptEngine::thaiWithZWJ() QCOMPARE(e->layoutData->items[2].num_glyphs, ushort(2)); // Thai: Thai character followed by superscript "a" which is of inherited type //A quick sanity check - check all the characters are individual clusters - // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them. - // The current implementation hides them, so we test for that. + // A thai implementation could either remove the ZWJ character, or hide it. + // The current implementation merges the cluster for ZWJ and keeps ZWNJ, so we test for that. unsigned short *logClusters = e->layoutData->logClustersPtr; QCOMPARE(logClusters[0], ushort(0)); QCOMPARE(logClusters[1], ushort(0)); QCOMPARE(logClusters[2], ushort(2)); - QCOMPARE(logClusters[3], ushort(2)); - for (int i = 4; i < 15; i++) + for (int i = 3; i < 15; i++) QCOMPARE(logClusters[i], ushort(i)); for (int i = 0; i < 3; i++) QCOMPARE(logClusters[i+15], ushort(0)); diff --git a/tests/auto/gui/text/qtexttable/CMakeLists.txt b/tests/auto/gui/text/qtexttable/CMakeLists.txt new file mode 100644 index 0000000000..de82c94233 --- /dev/null +++ b/tests/auto/gui/text/qtexttable/CMakeLists.txt @@ -0,0 +1,21 @@ +# Generated from qtexttable.pro. + +##################################################################### +## tst_qtexttable Test: +##################################################################### + +add_qt_test(tst_qtexttable + SOURCES + tst_qtexttable.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) + +## Scopes: +##################################################################### + +extend_target(tst_qtexttable CONDITION TARGET Qt::Widgets + PUBLIC_LIBRARIES + Qt::Widgets +) diff --git a/tests/auto/gui/text/qzip/CMakeLists.txt b/tests/auto/gui/text/qzip/CMakeLists.txt new file mode 100644 index 0000000000..dfeb968cc1 --- /dev/null +++ b/tests/auto/gui/text/qzip/CMakeLists.txt @@ -0,0 +1,35 @@ +# Generated from qzip.pro. + +##################################################################### +## tst_qzip Test: +##################################################################### + +# Collect test data +list(APPEND test_data "testdata") + +add_qt_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" + ) + + add_qt_resource(tst_qzip "testdata" + PREFIX + "/" + FILES + ${testdata_resource_files} + ) +endif() diff --git a/tests/auto/gui/util/CMakeLists.txt b/tests/auto/gui/util/CMakeLists.txt new file mode 100644 index 0000000000..4feae26818 --- /dev/null +++ b/tests/auto/gui/util/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from util.pro. + +add_subdirectory(qdesktopservices) +add_subdirectory(qdoublevalidator) +add_subdirectory(qintvalidator) +add_subdirectory(qregularexpressionvalidator) +add_subdirectory(qshadergenerator) +add_subdirectory(qshadergraph) +add_subdirectory(qshadergraphloader) +add_subdirectory(qshadernodes) +add_subdirectory(qshadernodesloader) +add_subdirectory(qtexturefilereader) +add_subdirectory(qundogroup) +add_subdirectory(qundostack) diff --git a/tests/auto/gui/util/qdesktopservices/.prev_CMakeLists.txt b/tests/auto/gui/util/qdesktopservices/.prev_CMakeLists.txt new file mode 100644 index 0000000000..8163ec80b6 --- /dev/null +++ b/tests/auto/gui/util/qdesktopservices/.prev_CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qdesktopservices.pro. + +##################################################################### +## tst_qdesktopservices Test: +##################################################################### + +add_qt_test(tst_qdesktopservices + SOURCES + tst_qdesktopservices.cpp + DEFINES + QT_DISABLE_DEPRECATED_BEFORE=0 + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qdesktopservices/CMakeLists.txt b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt new file mode 100644 index 0000000000..c62cecac30 --- /dev/null +++ b/tests/auto/gui/util/qdesktopservices/CMakeLists.txt @@ -0,0 +1,14 @@ +# Generated from qdesktopservices.pro. + +##################################################################### +## tst_qdesktopservices Test: +##################################################################### + +add_qt_test(tst_qdesktopservices + SOURCES + tst_qdesktopservices.cpp + DEFINES + # QT_DISABLE_DEPRECATED_BEFORE=0 # special case + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt new file mode 100644 index 0000000000..6cccd082a9 --- /dev/null +++ b/tests/auto/gui/util/qdoublevalidator/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qdoublevalidator.pro. + +##################################################################### +## tst_qdoublevalidator Test: +##################################################################### + +add_qt_test(tst_qdoublevalidator + SOURCES + tst_qdoublevalidator.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qintvalidator/CMakeLists.txt b/tests/auto/gui/util/qintvalidator/CMakeLists.txt new file mode 100644 index 0000000000..69a5503d8e --- /dev/null +++ b/tests/auto/gui/util/qintvalidator/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qintvalidator.pro. + +##################################################################### +## tst_qintvalidator Test: +##################################################################### + +add_qt_test(tst_qintvalidator + SOURCES + tst_qintvalidator.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qregexpvalidator/.gitignore b/tests/auto/gui/util/qregexpvalidator/.gitignore deleted file mode 100644 index cff9b076b2..0000000000 --- a/tests/auto/gui/util/qregexpvalidator/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qregexpvalidator diff --git a/tests/auto/gui/util/qregexpvalidator/qregexpvalidator.pro b/tests/auto/gui/util/qregexpvalidator/qregexpvalidator.pro deleted file mode 100644 index 8f1de5b747..0000000000 --- a/tests/auto/gui/util/qregexpvalidator/qregexpvalidator.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG += testcase -TARGET = tst_qregexpvalidator -SOURCES += tst_qregexpvalidator.cpp -QT += testlib diff --git a/tests/auto/gui/util/qregexpvalidator/tst_qregexpvalidator.cpp b/tests/auto/gui/util/qregexpvalidator/tst_qregexpvalidator.cpp deleted file mode 100644 index fbb4f0b4ea..0000000000 --- a/tests/auto/gui/util/qregexpvalidator/tst_qregexpvalidator.cpp +++ /dev/null @@ -1,93 +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 <QtTest/QtTest> -#include <qregexp.h> - - -#include <qvalidator.h> - -class tst_QRegExpValidator : public QObject -{ - Q_OBJECT - -private slots: - void validate_data(); - void validate(); -}; - -void tst_QRegExpValidator::validate_data() -{ - - QTest::addColumn<QString>("rx"); - QTest::addColumn<QString>("value"); - QTest::addColumn<int>("state"); - - QTest::newRow( "data0" ) << QString("[1-9]\\d{0,3}") << QString("0") << 0; - QTest::newRow( "data1" ) << QString("[1-9]\\d{0,3}") << QString("12345") << 0; - QTest::newRow( "data2" ) << QString("[1-9]\\d{0,3}") << QString("1") << 2; - - QTest::newRow( "data3" ) << QString("\\S+") << QString("myfile.txt") << 2; - QTest::newRow( "data4" ) << QString("\\S+") << QString("my file.txt") << 0; - - QTest::newRow( "data5" ) << QString("[A-C]\\d{5}[W-Z]") << QString("a12345Z") << 0; - QTest::newRow( "data6" ) << QString("[A-C]\\d{5}[W-Z]") << QString("A12345Z") << 2; - QTest::newRow( "data7" ) << QString("[A-C]\\d{5}[W-Z]") << QString("B12") << 1; - - QTest::newRow( "data8" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readme") << 2; - QTest::newRow( "data9" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << 0; - QTest::newRow( "data10" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << 1; -} - -void tst_QRegExpValidator::validate() -{ - QFETCH( QString, rx ); - QFETCH( QString, value ); - QFETCH( int, state ); - - QRegExpValidator rv( 0 ); - QSignalSpy spy(&rv, SIGNAL(regExpChanged(QRegExp))); - QSignalSpy changedSpy(&rv, SIGNAL(changed())); - - rv.setRegExp( QRegExp( rx ) ); - int pos = -1; - - QCOMPARE( (int)rv.validate( value, pos ), state ); - - if (state == QValidator::Invalid) - QCOMPARE(pos, value.length()); - else - QCOMPARE(pos, -1); // untouched on Acceptable or Intermediate - - QCOMPARE(spy.count(), 1); - QCOMPARE(changedSpy.count(), 1); -} - -QTEST_APPLESS_MAIN(tst_QRegExpValidator) -#include "tst_qregexpvalidator.moc" diff --git a/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt new file mode 100644 index 0000000000..8633a171e5 --- /dev/null +++ b/tests/auto/gui/util/qregularexpressionvalidator/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qregularexpressionvalidator.pro. + +##################################################################### +## tst_qregularexpressionvalidator Test: +##################################################################### + +add_qt_test(tst_qregularexpressionvalidator + SOURCES + tst_qregularexpressionvalidator.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qshadergenerator/CMakeLists.txt b/tests/auto/gui/util/qshadergenerator/CMakeLists.txt new file mode 100644 index 0000000000..e9cb62377f --- /dev/null +++ b/tests/auto/gui/util/qshadergenerator/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qshadergenerator.pro. + +##################################################################### +## tst_qshadergenerator Test: +##################################################################### + +add_qt_test(tst_qshadergenerator + SOURCES + tst_qshadergenerator.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/util/qshadergraph/CMakeLists.txt b/tests/auto/gui/util/qshadergraph/CMakeLists.txt new file mode 100644 index 0000000000..ede24f2a40 --- /dev/null +++ b/tests/auto/gui/util/qshadergraph/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qshadergraph.pro. + +##################################################################### +## tst_qshadergraph Test: +##################################################################### + +add_qt_test(tst_qshadergraph + SOURCES + tst_qshadergraph.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/util/qshadergraphloader/CMakeLists.txt b/tests/auto/gui/util/qshadergraphloader/CMakeLists.txt new file mode 100644 index 0000000000..caf863d42d --- /dev/null +++ b/tests/auto/gui/util/qshadergraphloader/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qshadergraphloader.pro. + +##################################################################### +## tst_qshadergraphloader Test: +##################################################################### + +add_qt_test(tst_qshadergraphloader + SOURCES + tst_qshadergraphloader.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/util/qshadernodes/CMakeLists.txt b/tests/auto/gui/util/qshadernodes/CMakeLists.txt new file mode 100644 index 0000000000..d7cc14b09c --- /dev/null +++ b/tests/auto/gui/util/qshadernodes/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qshadernodes.pro. + +##################################################################### +## tst_qshadernodes Test: +##################################################################### + +add_qt_test(tst_qshadernodes + SOURCES + tst_qshadernodes.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/util/qshadernodesloader/CMakeLists.txt b/tests/auto/gui/util/qshadernodesloader/CMakeLists.txt new file mode 100644 index 0000000000..e381af4f7b --- /dev/null +++ b/tests/auto/gui/util/qshadernodesloader/CMakeLists.txt @@ -0,0 +1,13 @@ +# Generated from qshadernodesloader.pro. + +##################################################################### +## tst_qshadernodesloader Test: +##################################################################### + +add_qt_test(tst_qshadernodesloader + SOURCES + tst_qshadernodesloader.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) diff --git a/tests/auto/gui/util/qshadernodesloader/tst_qshadernodesloader.cpp b/tests/auto/gui/util/qshadernodesloader/tst_qshadernodesloader.cpp index 4782e40ed8..ec1bd87a32 100644 --- a/tests/auto/gui/util/qshadernodesloader/tst_qshadernodesloader.cpp +++ b/tests/auto/gui/util/qshadernodesloader/tst_qshadernodesloader.cpp @@ -272,6 +272,10 @@ void tst_QShaderNodesLoader::shouldLoadFromJsonStream_data() QTest::newRow("NotOpen") << createBuffer(smallJson, QIODevice::NotOpen) << NodeHash() << QShaderNodesLoader::Error; QTest::newRow("CorrectJSON") << createBuffer(smallJson) << smallProtos << QShaderNodesLoader::Ready; + + // These types are normaly registered by QShaderGraphLoader + qRegisterMetaType<QShaderLanguage::StorageQualifier>(); + qRegisterMetaType<QShaderLanguage::VariableType>(); } void tst_QShaderNodesLoader::shouldLoadFromJsonStream() diff --git a/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt new file mode 100644 index 0000000000..3b6d99c0e8 --- /dev/null +++ b/tests/auto/gui/util/qtexturefilereader/CMakeLists.txt @@ -0,0 +1,30 @@ +# Generated from qtexturefilereader.pro. + +##################################################################### +## tst_qtexturefilereader Test: +##################################################################### + +add_qt_test(tst_qtexturefilereader + SOURCES + tst_qtexturefilereader.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::GuiPrivate +) + +# Resources: +set(qtexturefilereader_resource_files + "texturefiles/car.ktx" + "texturefiles/car_mips.ktx" + "texturefiles/newlogo.astc" + "texturefiles/newlogo_srgb.astc" + "texturefiles/pattern.pkm" +) + +add_qt_resource(tst_qtexturefilereader "qtexturefilereader" + PREFIX + "/" + FILES + ${qtexturefilereader_resource_files} +) + diff --git a/tests/auto/gui/util/qundogroup/.gitignore b/tests/auto/gui/util/qundogroup/.gitignore new file mode 100644 index 0000000000..bc3e8c4691 --- /dev/null +++ b/tests/auto/gui/util/qundogroup/.gitignore @@ -0,0 +1 @@ +tst_qundogroup diff --git a/tests/auto/gui/util/qundogroup/CMakeLists.txt b/tests/auto/gui/util/qundogroup/CMakeLists.txt new file mode 100644 index 0000000000..3325556a3e --- /dev/null +++ b/tests/auto/gui/util/qundogroup/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qundogroup.pro. + +##################################################################### +## tst_qundogroup Test: +##################################################################### + +add_qt_test(tst_qundogroup + SOURCES + tst_qundogroup.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qundogroup/qundogroup.pro b/tests/auto/gui/util/qundogroup/qundogroup.pro new file mode 100644 index 0000000000..fbae557207 --- /dev/null +++ b/tests/auto/gui/util/qundogroup/qundogroup.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +QT += testlib +SOURCES += tst_qundogroup.cpp +TARGET = tst_qundogroup diff --git a/tests/auto/gui/util/qundogroup/testdata/qundogroup.ts b/tests/auto/gui/util/qundogroup/testdata/qundogroup.ts new file mode 100644 index 0000000000..a059bcb486 --- /dev/null +++ b/tests/auto/gui/util/qundogroup/testdata/qundogroup.ts @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="en"> +<context> + <name>QUndoGroup</name> + <message> + <source>Undo %1</source> + <translation>undo-prefix %1 undo-suffix</translation> + </message> + <message> + <source>Undo</source> + <comment>Default text for undo action</comment> + <translation>Undo-default-text</translation> + </message> + <message> + <source>Redo %1</source> + <translation>redo-prefix %1 redo-suffix</translation> + </message> + <message> + <source>Redo</source> + <comment>Default text for redo action</comment> + <translation>Redo-default-text</translation> + </message> +</context> +</TS> diff --git a/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp new file mode 100644 index 0000000000..ba238105ec --- /dev/null +++ b/tests/auto/gui/util/qundogroup/tst_qundogroup.cpp @@ -0,0 +1,641 @@ +/**************************************************************************** +** +** 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 <QtTest/QtTest> +#include <QUndoGroup> +#include <QUndoStack> +#include <QAction> + +/****************************************************************************** +** Commands +*/ + +class InsertCommand : public QUndoCommand +{ +public: + InsertCommand(QString *str, int idx, const QString &text, + QUndoCommand *parent = 0); + + virtual void undo(); + virtual void redo(); + +private: + QString *m_str; + int m_idx; + QString m_text; +}; + +class RemoveCommand : public QUndoCommand +{ +public: + RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent = 0); + + virtual void undo(); + virtual void redo(); + +private: + QString *m_str; + int m_idx; + QString m_text; +}; + +class AppendCommand : public QUndoCommand +{ +public: + AppendCommand(QString *str, const QString &text, QUndoCommand *parent = 0); + + virtual void undo(); + virtual void redo(); + virtual int id() const; + virtual bool mergeWith(const QUndoCommand *other); + + bool merged; + +private: + QString *m_str; + QString m_text; +}; + +InsertCommand::InsertCommand(QString *str, int idx, const QString &text, + QUndoCommand *parent) + : QUndoCommand(parent) +{ + QVERIFY(str->length() >= idx); + + setText("insert"); + + m_str = str; + m_idx = idx; + m_text = text; +} + +void InsertCommand::redo() +{ + QVERIFY(m_str->length() >= m_idx); + + m_str->insert(m_idx, m_text); +} + +void InsertCommand::undo() +{ + QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + + m_str->remove(m_idx, m_text.length()); +} + +RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) + : QUndoCommand(parent) +{ + QVERIFY(str->length() >= idx + len); + + setText("remove"); + + m_str = str; + m_idx = idx; + m_text = m_str->mid(m_idx, len); +} + +void RemoveCommand::redo() +{ + QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + + m_str->remove(m_idx, m_text.length()); +} + +void RemoveCommand::undo() +{ + QVERIFY(m_str->length() >= m_idx); + + m_str->insert(m_idx, m_text); +} + +AppendCommand::AppendCommand(QString *str, const QString &text, QUndoCommand *parent) + : QUndoCommand(parent) +{ + setText("append"); + + m_str = str; + m_text = text; + merged = false; +} + +void AppendCommand::redo() +{ + m_str->append(m_text); +} + +void AppendCommand::undo() +{ + QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); + + m_str->truncate(m_str->length() - m_text.length()); +} + +int AppendCommand::id() const +{ + return 1; +} + +bool AppendCommand::mergeWith(const QUndoCommand *other) +{ + if (other->id() != id()) + return false; + m_text += static_cast<const AppendCommand*>(other)->m_text; + merged = true; + return true; +} + +/****************************************************************************** +** tst_QUndoStack +*/ + +class tst_QUndoGroup : public QObject +{ + Q_OBJECT +public: + tst_QUndoGroup(); + +private slots: + void setActive(); + void addRemoveStack(); + void deleteStack(); + void checkSignals(); + void addStackAndDie(); + void commandTextFormat(); +}; + +tst_QUndoGroup::tst_QUndoGroup() +{ +} + +void tst_QUndoGroup::setActive() +{ + QUndoGroup group; + QUndoStack stack1(&group), stack2(&group); + + QCOMPARE(group.activeStack(), nullptr); + QCOMPARE(stack1.isActive(), false); + QCOMPARE(stack2.isActive(), false); + + QUndoStack stack3; + QCOMPARE(stack3.isActive(), true); + + group.addStack(&stack3); + QCOMPARE(stack3.isActive(), false); + + stack1.setActive(); + QCOMPARE(group.activeStack(), &stack1); + QCOMPARE(stack1.isActive(), true); + QCOMPARE(stack2.isActive(), false); + QCOMPARE(stack3.isActive(), false); + + group.setActiveStack(&stack2); + QCOMPARE(group.activeStack(), &stack2); + QCOMPARE(stack1.isActive(), false); + QCOMPARE(stack2.isActive(), true); + QCOMPARE(stack3.isActive(), false); + + group.removeStack(&stack2); + QCOMPARE(group.activeStack(), nullptr); + QCOMPARE(stack1.isActive(), false); + QCOMPARE(stack2.isActive(), true); + QCOMPARE(stack3.isActive(), false); + + group.removeStack(&stack2); + QCOMPARE(group.activeStack(), nullptr); + QCOMPARE(stack1.isActive(), false); + QCOMPARE(stack2.isActive(), true); + QCOMPARE(stack3.isActive(), false); +} + +void tst_QUndoGroup::addRemoveStack() +{ + QUndoGroup group; + + QUndoStack stack1(&group); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << &stack1); + + QUndoStack stack2; + group.addStack(&stack2); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << &stack1 << &stack2); + + group.addStack(&stack1); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << &stack1 << &stack2); + + group.removeStack(&stack1); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << &stack2); + + group.removeStack(&stack1); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << &stack2); + + group.removeStack(&stack2); + QCOMPARE(group.stacks(), QList<QUndoStack*>()); +} + +void tst_QUndoGroup::deleteStack() +{ + QUndoGroup group; + + QUndoStack *stack1 = new QUndoStack(&group); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1); + QCOMPARE(group.activeStack(), nullptr); + + stack1->setActive(); + QCOMPARE(group.activeStack(), stack1); + + QUndoStack *stack2 = new QUndoStack(&group); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack2); + QCOMPARE(group.activeStack(), stack1); + + QUndoStack *stack3 = new QUndoStack(&group); + QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack2 << stack3); + QCOMPARE(group.activeStack(), stack1); + + delete stack2; + QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack1 << stack3); + QCOMPARE(group.activeStack(), stack1); + + delete stack1; + QCOMPARE(group.stacks(), QList<QUndoStack*>() << stack3); + QCOMPARE(group.activeStack(), nullptr); + + stack3->setActive(false); + QCOMPARE(group.activeStack(), nullptr); + + stack3->setActive(true); + QCOMPARE(group.activeStack(), stack3); + + group.removeStack(stack3); + QCOMPARE(group.stacks(), QList<QUndoStack*>()); + QCOMPARE(group.activeStack(), nullptr); + + delete stack3; +} + +static QString glue(const QString &s1, const QString &s2) +{ + QString result; + + result.append(s1); + if (!s1.isEmpty() && !s2.isEmpty()) + result.append(' '); + result.append(s2); + + return result; +} + +#define CHECK_STATE(_activeStack, _clean, _canUndo, _undoText, _canRedo, _redoText, \ + _cleanChanged, _indexChanged, _undoChanged, _redoChanged) \ + QCOMPARE(group.activeStack(), (QUndoStack*)_activeStack); \ + QCOMPARE(group.isClean(), _clean); \ + QCOMPARE(group.canUndo(), _canUndo); \ + QCOMPARE(group.undoText(), QString(_undoText)); \ + QCOMPARE(group.canRedo(), _canRedo); \ + QCOMPARE(group.redoText(), QString(_redoText)); \ + if (_indexChanged) { \ + QCOMPARE(indexChangedSpy.count(), 1); \ + indexChangedSpy.clear(); \ + } else { \ + QCOMPARE(indexChangedSpy.count(), 0); \ + } \ + if (_cleanChanged) { \ + QCOMPARE(cleanChangedSpy.count(), 1); \ + QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); \ + cleanChangedSpy.clear(); \ + } else { \ + QCOMPARE(cleanChangedSpy.count(), 0); \ + } \ + if (_undoChanged) { \ + QCOMPARE(canUndoChangedSpy.count(), 1); \ + QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); \ + QCOMPARE(undo_action->isEnabled(), _canUndo); \ + QCOMPARE(undoTextChangedSpy.count(), 1); \ + QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText)); \ + QCOMPARE(undo_action->text(), glue("foo", _undoText)); \ + canUndoChangedSpy.clear(); \ + undoTextChangedSpy.clear(); \ + } else { \ + QCOMPARE(canUndoChangedSpy.count(), 0); \ + QCOMPARE(undoTextChangedSpy.count(), 0); \ + } \ + if (_redoChanged) { \ + QCOMPARE(canRedoChangedSpy.count(), 1); \ + QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); \ + QCOMPARE(redo_action->isEnabled(), _canRedo); \ + QCOMPARE(redoTextChangedSpy.count(), 1); \ + QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText)); \ + QCOMPARE(redo_action->text(), glue("bar", _redoText)); \ + canRedoChangedSpy.clear(); \ + redoTextChangedSpy.clear(); \ + } else { \ + QCOMPARE(canRedoChangedSpy.count(), 0); \ + QCOMPARE(redoTextChangedSpy.count(), 0); \ + } + +void tst_QUndoGroup::checkSignals() +{ + QUndoGroup group; + QScopedPointer<QAction> undo_action(group.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redo_action(group.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&group, &QUndoGroup::indexChanged); + QSignalSpy cleanChangedSpy(&group, &QUndoGroup::cleanChanged); + QSignalSpy canUndoChangedSpy(&group, &QUndoGroup::canUndoChanged); + QSignalSpy undoTextChangedSpy(&group, &QUndoGroup::undoTextChanged); + QSignalSpy canRedoChangedSpy(&group, &QUndoGroup::canRedoChanged); + QSignalSpy redoTextChangedSpy(&group, &QUndoGroup::redoTextChanged); + + QString str; + + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + group.undo(); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + group.redo(); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + QUndoStack *stack1 = new QUndoStack(&group); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + stack1->push(new AppendCommand(&str, "foo")); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + stack1->setActive(); + CHECK_STATE(stack1, // activeStack + false, // clean + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->push(new InsertCommand(&str, 0, "bar")); + CHECK_STATE(stack1, // activeStack + false, // clean + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->undo(); + CHECK_STATE(stack1, // activeStack + false, // clean + true, // canUndo + "append", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->undo(); + CHECK_STATE(stack1, // activeStack + true, // clean + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->undo(); + CHECK_STATE(stack1, // activeStack + true, // clean + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + group.undo(); + CHECK_STATE(stack1, // activeStack + true, // clean + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + group.redo(); + CHECK_STATE(stack1, // activeStack + false, // clean + true, // canUndo + "append", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->setActive(false); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + QUndoStack *stack2 = new QUndoStack(&group); + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false) // redoChanged + + stack2->setActive(); + CHECK_STATE(stack2, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + stack1->setActive(); + CHECK_STATE(stack1, // activeStack + false, // clean + true, // canUndo + "append", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged + + delete stack1; + CHECK_STATE(0, // activeStack + true, // clean + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true) // redoChanged +} + +void tst_QUndoGroup::addStackAndDie() +{ + // Test that QUndoStack doesn't keep a reference to QUndoGroup after the + // group is deleted. + QUndoStack *stack = new QUndoStack; + QUndoGroup *group = new QUndoGroup; + group->addStack(stack); + delete group; + stack->setActive(true); + delete stack; +} + +void tst_QUndoGroup::commandTextFormat() +{ +#if !QT_CONFIG(process) + QSKIP("No QProcess available"); +#else + QString binDir = QLibraryInfo::location(QLibraryInfo::BinariesPath); + + if (QProcess::execute(binDir + "/lrelease -version") != 0) + QSKIP("lrelease is missing or broken"); + + const QString tsFile = QFINDTESTDATA("testdata/qundogroup.ts"); + QVERIFY(!tsFile.isEmpty()); + QFile::remove("qundogroup.qm"); // Avoid confusion by strays. + QVERIFY(!QProcess::execute(binDir + "/lrelease -silent " + tsFile + " -qm qundogroup.qm")); + + QTranslator translator; + + QVERIFY(translator.load("qundogroup.qm")); + QFile::remove("qundogroup.qm"); + qApp->installTranslator(&translator); + + QUndoGroup group; + QScopedPointer<QAction> undo_action(group.createUndoAction(nullptr)); + QScopedPointer<QAction> redo_action(group.createRedoAction(nullptr)); + + QCOMPARE(undo_action->text(), QString("Undo-default-text")); + QCOMPARE(redo_action->text(), QString("Redo-default-text")); + + QUndoStack stack(&group); + stack.setActive(); + QString str; + + stack.push(new AppendCommand(&str, "foo")); + QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix")); + QCOMPARE(redo_action->text(), QString("Redo-default-text")); + + stack.push(new InsertCommand(&str, 0, "bar")); + stack.undo(); + QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix")); + QCOMPARE(redo_action->text(), QString("redo-prefix insert redo-suffix")); + + stack.undo(); + QCOMPARE(undo_action->text(), QString("Undo-default-text")); + QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix")); + + qApp->removeTranslator(&translator); +#endif +} + +QTEST_MAIN(tst_QUndoGroup) + +#include "tst_qundogroup.moc" + diff --git a/tests/auto/gui/util/qundostack/.gitignore b/tests/auto/gui/util/qundostack/.gitignore new file mode 100644 index 0000000000..f8faf2771f --- /dev/null +++ b/tests/auto/gui/util/qundostack/.gitignore @@ -0,0 +1 @@ +tst_qundostack diff --git a/tests/auto/gui/util/qundostack/CMakeLists.txt b/tests/auto/gui/util/qundostack/CMakeLists.txt new file mode 100644 index 0000000000..d6cf36187e --- /dev/null +++ b/tests/auto/gui/util/qundostack/CMakeLists.txt @@ -0,0 +1,12 @@ +# Generated from qundostack.pro. + +##################################################################### +## tst_qundostack Test: +##################################################################### + +add_qt_test(tst_qundostack + SOURCES + tst_qundostack.cpp + PUBLIC_LIBRARIES + Qt::Gui +) diff --git a/tests/auto/gui/util/qundostack/qundostack.pro b/tests/auto/gui/util/qundostack/qundostack.pro new file mode 100644 index 0000000000..bbade9635f --- /dev/null +++ b/tests/auto/gui/util/qundostack/qundostack.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +QT += gui testlib +SOURCES += tst_qundostack.cpp +TARGET = tst_qundostack diff --git a/tests/auto/gui/util/qundostack/testdata/qundostack.ts b/tests/auto/gui/util/qundostack/testdata/qundostack.ts new file mode 100644 index 0000000000..4584036af2 --- /dev/null +++ b/tests/auto/gui/util/qundostack/testdata/qundostack.ts @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS> +<TS version="2.0" language="en"> +<context> + <name>QUndoStack</name> + <message> + <source>Undo %1</source> + <translation>undo-prefix %1 undo-suffix</translation> + </message> + <message> + <source>Undo</source> + <comment>Default text for undo action</comment> + <translation>Undo-default-text</translation> + </message> + <message> + <source>Redo %1</source> + <translation>redo-prefix %1 redo-suffix</translation> + </message> + <message> + <source>Redo</source> + <comment>Default text for redo action</comment> + <translation>Redo-default-text</translation> + </message> +</context> +</TS> diff --git a/tests/auto/gui/util/qundostack/tst_qundostack.cpp b/tests/auto/gui/util/qundostack/tst_qundostack.cpp new file mode 100644 index 0000000000..a24798cba7 --- /dev/null +++ b/tests/auto/gui/util/qundostack/tst_qundostack.cpp @@ -0,0 +1,3930 @@ +/**************************************************************************** +** +** 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 <QtTest/QtTest> +#include <QAction> +#include <QUndoStack> + +/****************************************************************************** +** Commands +*/ + +class InsertCommand : public QUndoCommand +{ +public: + InsertCommand(QString *str, int idx, const QString &text, + QUndoCommand *parent = 0); + + virtual void undo(); + virtual void redo(); + +private: + QString *m_str; + int m_idx; + QString m_text; +}; + +class RemoveCommand : public QUndoCommand +{ +public: + RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent = 0); + + virtual void undo(); + virtual void redo(); + +private: + QString *m_str; + int m_idx; + QString m_text; +}; + +class AppendCommand : public QUndoCommand +{ +public: + AppendCommand(QString *str, const QString &text, bool _fail_merge = false, + QUndoCommand *parent = 0); + ~AppendCommand(); + + virtual void undo(); + virtual void redo(); + virtual int id() const; + virtual bool mergeWith(const QUndoCommand *other); + + bool merged; + bool fail_merge; + static int delete_cnt; + +private: + QString *m_str; + QString m_text; +}; + +class IdleCommand : public QUndoCommand +{ +public: + IdleCommand(QUndoCommand *parent = 0); + ~IdleCommand(); + + virtual void undo(); + virtual void redo(); +}; + +class MoveMouseCommand : public QUndoCommand +{ +public: + MoveMouseCommand(QPoint *mouse, QPoint oldPoint, QPoint newPoint, QUndoCommand *parent = 0); + ~MoveMouseCommand(); + + virtual void undo(); + virtual void redo(); + virtual int id() const; + virtual bool mergeWith(const QUndoCommand *other); + +private: + QPoint *m_mouse; + QPoint m_oldPoint; + QPoint m_newPoint; +}; + +InsertCommand::InsertCommand(QString *str, int idx, const QString &text, + QUndoCommand *parent) + : QUndoCommand(parent) +{ + QVERIFY(str->length() >= idx); + + setText("insert"); + + m_str = str; + m_idx = idx; + m_text = text; +} + +void InsertCommand::redo() +{ + QVERIFY(m_str->length() >= m_idx); + + m_str->insert(m_idx, m_text); +} + +void InsertCommand::undo() +{ + QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + + m_str->remove(m_idx, m_text.length()); +} + +RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) + : QUndoCommand(parent) +{ + QVERIFY(str->length() >= idx + len); + + setText("remove"); + + m_str = str; + m_idx = idx; + m_text = m_str->mid(m_idx, len); +} + +void RemoveCommand::redo() +{ + QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); + + m_str->remove(m_idx, m_text.length()); +} + +void RemoveCommand::undo() +{ + QVERIFY(m_str->length() >= m_idx); + + m_str->insert(m_idx, m_text); +} + +int AppendCommand::delete_cnt = 0; + +AppendCommand::AppendCommand(QString *str, const QString &text, bool _fail_merge, + QUndoCommand *parent) + : QUndoCommand(parent) +{ + setText("append"); + + m_str = str; + m_text = text; + merged = false; + fail_merge = _fail_merge; +} + +AppendCommand::~AppendCommand() +{ + ++delete_cnt; +} + +void AppendCommand::redo() +{ + m_str->append(m_text); +} + +void AppendCommand::undo() +{ + QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); + + m_str->truncate(m_str->length() - m_text.length()); +} + +int AppendCommand::id() const +{ + return 1; +} + +bool AppendCommand::mergeWith(const QUndoCommand *other) +{ + if (other->id() != id()) + return false; + if (fail_merge) + return false; + m_text += static_cast<const AppendCommand*>(other)->m_text; + merged = true; + return true; +} + +IdleCommand::IdleCommand(QUndoCommand *parent) + : QUndoCommand(parent) +{ + // "idle-item" goes to QUndoStack::{redo,undo}Text + // "idle-action" goes to all other places (e.g. QUndoView) + setText("idle-item\nidle-action"); +} + +IdleCommand::~IdleCommand() +{ +} + +void IdleCommand::redo() +{ +} + +void IdleCommand::undo() +{ +} + +MoveMouseCommand::MoveMouseCommand(QPoint *mouse, QPoint oldPoint, QPoint newPoint, QUndoCommand *parent) + : QUndoCommand(parent) +{ + setText("move mouse"); + + m_mouse = mouse; + m_oldPoint = oldPoint; + m_newPoint = newPoint; + + if (m_oldPoint == m_newPoint) + setObsolete(true); +} + +MoveMouseCommand::~MoveMouseCommand() +{ +} + +void MoveMouseCommand::redo() +{ + *m_mouse = m_newPoint; +} + +void MoveMouseCommand::undo() +{ + *m_mouse = m_oldPoint; +} + +int MoveMouseCommand::id() const +{ + return 2; +} + +bool MoveMouseCommand::mergeWith(const QUndoCommand *other) +{ + m_newPoint = static_cast<const MoveMouseCommand*>(other)->m_newPoint; + + if (m_newPoint == m_oldPoint) + setObsolete(true); + + return true; +} + +/****************************************************************************** +** tst_QUndoStack +*/ + +class tst_QUndoStack : public QObject +{ + Q_OBJECT +public: + tst_QUndoStack(); + +private slots: + void undoRedo(); + void setIndex(); + void setClean(); + void clear(); + void childCommand(); + void macroBeginEnd(); + void compression(); + void obsolete(); + void undoLimit(); + void commandTextFormat(); + void separateUndoText(); +}; + +tst_QUndoStack::tst_QUndoStack() +{ +} + +static QString glue(const QString &s1, const QString &s2) +{ + QString result; + + result.append(s1); + if (!s1.isEmpty() && !s2.isEmpty()) + result.append(' '); + result.append(s2); + + return result; +} + +static void checkState(QSignalSpy &redoTextChangedSpy, + QSignalSpy &canRedoChangedSpy, + QSignalSpy &undoTextChangedSpy, + const QScopedPointer<QAction> &redoAction, + const QScopedPointer<QAction> &undoAction, + QSignalSpy &canUndoChangedSpy, + QSignalSpy &cleanChangedSpy, + QSignalSpy &indexChangedSpy, + QUndoStack &stack, + const bool _clean, + const int _count, + const int _index, + const bool _canUndo, + const QString &_undoText, + const bool _canRedo, + const QString &_redoText, + const bool _cleanChanged, + const bool _indexChanged, + const bool _undoChanged, + const bool _redoChanged) +{ + QCOMPARE(stack.count(), _count); + QCOMPARE(stack.isClean(), _clean); + QCOMPARE(stack.index(), _index); + QCOMPARE(stack.canUndo(), _canUndo); + QCOMPARE(stack.undoText(), QString(_undoText)); + QCOMPARE(stack.canRedo(), _canRedo); + QCOMPARE(stack.redoText(), QString(_redoText)); + if (_indexChanged) { + QCOMPARE(indexChangedSpy.count(), 1); + QCOMPARE(indexChangedSpy.at(0).at(0).toInt(), _index); + indexChangedSpy.clear(); + } else { + QCOMPARE(indexChangedSpy.count(), 0); + } + if (_cleanChanged) { + QCOMPARE(cleanChangedSpy.count(), 1); + QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); + cleanChangedSpy.clear(); + } else { + QCOMPARE(cleanChangedSpy.count(), 0); + } + if (_undoChanged) { + QCOMPARE(canUndoChangedSpy.count(), 1); + QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); + QCOMPARE(undoAction->isEnabled(), _canUndo); + QCOMPARE(undoTextChangedSpy.count(), 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); + } + if (_redoChanged) { + QCOMPARE(canRedoChangedSpy.count(), 1); + QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); + QCOMPARE(redoAction->isEnabled(), _canRedo); + QCOMPARE(redoTextChangedSpy.count(), 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); + } +} + +void tst_QUndoStack::undoRedo() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + // push, undo, redo + + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.undo(); // nothing to undo + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new InsertCommand(&str, 0, "hello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 2, "123")); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + + stack.undo(); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.redo(); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.redo(); // nothing to redo + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); // nothing to undo + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + // push after undo - check that undone commands get deleted + + stack.redo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new RemoveCommand(&str, 2, 2)); + QCOMPARE(str, QString("heo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count - still 2, last command got deleted + 2, // index + true, // canUndo + "remove", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "remove", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 0, "goodbye")); + QCOMPARE(str, QString("goodbye")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count - two commands got deleted + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::setIndex() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + stack.setIndex(10); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setIndex(0); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setIndex(-10); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new InsertCommand(&str, 0, "hello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 2, "123")); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(2); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setIndex(0); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(10); // should set index to 2 + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(-10); // should set index to 0 + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(1); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(2); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::setClean() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + QCOMPARE(stack.cleanIndex(), 0); + stack.setClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 0); + + stack.push(new InsertCommand(&str, 0, "goodbye")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 0); + + stack.setClean(); + QCOMPARE(str, QString("goodbye")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.push(new AppendCommand(&str, " cowboy")); + QCOMPARE(str, QString("goodbye cowboy")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.undo(); // reaching clean state from above + QCOMPARE(str, QString("goodbye")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.redo(); // reaching clean state from below + QCOMPARE(str, QString("goodbye")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.push(new InsertCommand(&str, 0, "foo")); // the clean state gets deleted! + QCOMPARE(str, QString("foo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.setClean(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 0); + + stack.resetClean(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.redo(); + QCOMPARE(str, QString("foo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.setClean(); + QCOMPARE(str, QString("foo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.undo(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), 1); + + stack.resetClean(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); +} + +void tst_QUndoStack::clear() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + stack.clear(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new InsertCommand(&str, 0, "hello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 2, "123")); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.clear(); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + str.clear(); + stack.push(new InsertCommand(&str, 0, "hello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 2, "123")); + QCOMPARE(str, QString("he123llo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(0); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.clear(); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::childCommand() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + stack.push(new InsertCommand(&str, 0, "hello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + QUndoCommand *cmd = new QUndoCommand(); + cmd->setText("ding"); + new InsertCommand(&str, 5, "world", cmd); + new RemoveCommand(&str, 4, 1, cmd); + stack.push(cmd); + QCOMPARE(str, QString("hellworld")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "ding", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.redo(); + QCOMPARE(str, QString("hellworld")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::macroBeginEnd() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + stack.beginMacro("ding"); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setClean(); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.undo(); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.redo(); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setIndex(0); // should do nothing + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index - endMacro() increments index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 0, "h")); + QCOMPARE(str, QString("h")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 1, "owdy")); + QCOMPARE(str, QString("howdy")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(2); + QCOMPARE(str, QString("h")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.beginMacro("dong"); // the "owdy" command gets deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 1, "ello")); + QCOMPARE(str, QString("hello")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new RemoveCommand(&str, 1, 2)); + QCOMPARE(str, QString("hlo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.beginMacro("dong2"); + QCOMPARE(str, QString("hlo")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new RemoveCommand(&str, 1, 1)); + QCOMPARE(str, QString("ho")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + QCOMPARE(str, QString("ho")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + QCOMPARE(str, QString("ho")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "dong", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("h")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "dong", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 1, // index + true, // canUndo + "ding", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(3); + QCOMPARE(str, QString("ho")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "dong", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setIndex(1); + QCOMPARE(str, QString()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 1, // index + true, // canUndo + "ding", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::compression() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QString str; + + AppendCommand::delete_cnt = 0; + + stack.push(new InsertCommand(&str, 0, "ene")); + QCOMPARE(str, QString("ene")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, " due")); // #1 + QCOMPARE(str, QString("ene due")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, " rike")); // #2 should merge + QCOMPARE(str, QString("ene due rike")); + QCOMPARE(AppendCommand::delete_cnt, 1); // #2 should be deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new AppendCommand(&str, " fake")); // #3 should NOT merge, since the stack was clean + QCOMPARE(str, QString("ene due rike fake")); // and we want to be able to return to this state + QCOMPARE(AppendCommand::delete_cnt, 1); // #3 should not be deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("ene due rike")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 3, // count + 2, // index + true, // canUndo + "append", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("ene")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "ma", true)); // #4 clean state gets deleted! + QCOMPARE(str, QString("enema")); + QCOMPARE(AppendCommand::delete_cnt, 3); // #1 got deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "trix")); // #5 should NOT merge + QCOMPARE(str, QString("enematrix")); + QCOMPARE(AppendCommand::delete_cnt, 3); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("enema")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + true, // canUndo + "append", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + // and now for command compression inside macros + + stack.setClean(); + QCOMPARE(str, QString("enema")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 3, // count + 2, // index + true, // canUndo + "append", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.beginMacro("ding"); + QCOMPARE(str, QString("enema")); + QCOMPARE(AppendCommand::delete_cnt, 4); // #5 gets deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + true, // undoChanged + true); // redoChanged + + AppendCommand *merge_cmd = new AppendCommand(&str, "top"); + stack.push(merge_cmd); // #6 + QCOMPARE(merge_cmd->merged, false); + QCOMPARE(str, QString("enematop")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new AppendCommand(&str, "eja")); // #7 should merge + QCOMPARE(str, QString("enematopeja")); + QCOMPARE(merge_cmd->merged, true); + QCOMPARE(AppendCommand::delete_cnt, 5); // #7 gets deleted + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + merge_cmd->merged = false; + + stack.push(new InsertCommand(&str, 2, "123")); // should not merge + QCOMPARE(str, QString("en123ematopeja")); + QCOMPARE(merge_cmd->merged, false); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + QCOMPARE(str, QString("en123ematopeja")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("enema")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 3, // count + 2, // index + true, // canUndo + "append", // undoText + true, // canRedo + "ding", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.redo(); + QCOMPARE(str, QString("en123ematopeja")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::obsolete() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + QPoint mouse(0, 0); + QString str; + MoveMouseCommand *cmd1 = 0; + MoveMouseCommand *cmd2 = 0; + + stack.resetClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #1 should not merge but will be deleted (b/c oldPoint == newPoint) + QCOMPARE(mouse, QPoint(0, 0)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(12, 0))); // #2 should not merge or be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(12, 0)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(8, 2))); // #3 should merge and not be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(8, 2)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #4 should merge and be deleted (b/c oldPoint == newPoint) + QCOMPARE(mouse, QPoint(0, 0)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + + + + stack.push(new InsertCommand(&str, 0, "ene")); // #5 should not merge or be deleted + QCOMPARE(str, QString("ene")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + cmd1 = new MoveMouseCommand(&mouse, mouse, QPoint(6, 5)); + stack.push(cmd1); // #6 should not merge or be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(6, 5)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 3, "ma")); // #7 should not merge or be deleted + QCOMPARE(str, QString("enema")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + cmd2 = new MoveMouseCommand(&mouse, mouse, QPoint(12, 4)); + stack.push(cmd2); // #8 should not merge or be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(12, 4)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 4, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 4, // count + 4, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 4); + + cmd2->setObsolete(true); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 4, // count + 4, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.undo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.undo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + true, // canUndo + "move mouse", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 3, // count + 2, // index + true, // canUndo + "move mouse", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 2); + + stack.undo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "move mouse", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + cmd1->setObsolete(true); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "move mouse", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.redo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "insert", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + stack.redo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + cmd1 = new MoveMouseCommand(&mouse, mouse, QPoint(13, 2)); + stack.push(cmd1); // #9 should not merge or be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(13, 2)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new InsertCommand(&str, 3, "ma")); // #10 should not merge or be deleted + QCOMPARE(str, QString("enemama")); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 4, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + cmd2 = new MoveMouseCommand(&mouse, mouse, QPoint(6, 20)); + stack.push(cmd2); // #11 should not merge or be deleted (b/c oldPoint != newPoint) + QCOMPARE(mouse, QPoint(6, 20)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 5, // count + 5, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + cmd1->setObsolete(true); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 5, // count + 5, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setClean(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 5, // count + 5, // index + true, // canUndo + "move mouse", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + QCOMPARE(stack.cleanIndex(), 5); + + stack.setIndex(0); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + QCOMPARE(stack.cleanIndex(), -1); + + cmd2->setObsolete(true); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "insert", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.setIndex(stack.count()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 3, // index + true, // canUndo + "insert", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + mouse = QPoint(0, 0); // Reset mouse position + stack.beginMacro("ding"); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 3, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(7, 7))); // #12 should not merge or be deleted (b/c oldPoint != newPoint & in macro) + QCOMPARE(mouse, QPoint(7, 7)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 3, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #13 should merge and be deleted (b/c oldPoint = newPoint) + QCOMPARE(mouse, QPoint(0, 0)); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 3, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 4, // count + 4, // index + true, // canUndo + "ding", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::undoLimit() +{ + QUndoStack stack; + QScopedPointer<QAction> undoAction(stack.createUndoAction(nullptr, QString("foo"))); + QScopedPointer<QAction> redoAction(stack.createRedoAction(nullptr, QString("bar"))); + QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); + QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); + QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); + QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); + QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); + QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); + AppendCommand::delete_cnt = 0; + QString str; + + QCOMPARE(stack.undoLimit(), 0); + stack.setUndoLimit(2); + QCOMPARE(stack.undoLimit(), 2); + + stack.push(new AppendCommand(&str, "1", true)); + QCOMPARE(str, QString("1")); + QCOMPARE(AppendCommand::delete_cnt, 0); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "2", true)); + QCOMPARE(str, QString("12")); + QCOMPARE(AppendCommand::delete_cnt, 0); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.setClean(); + QCOMPARE(str, QString("12")); + QCOMPARE(AppendCommand::delete_cnt, 0); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new AppendCommand(&str, "3", true)); + QCOMPARE(str, QString("123")); + QCOMPARE(AppendCommand::delete_cnt, 1); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "4", true)); + QCOMPARE(str, QString("1234")); + QCOMPARE(AppendCommand::delete_cnt, 2); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("123")); + QCOMPARE(AppendCommand::delete_cnt, 2); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "append", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("12")); + QCOMPARE(AppendCommand::delete_cnt, 2); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + true, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "3", true)); + QCOMPARE(str, QString("123")); + QCOMPARE(AppendCommand::delete_cnt, 4); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + true, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "4", true)); + QCOMPARE(str, QString("1234")); + QCOMPARE(AppendCommand::delete_cnt, 4); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "5", true)); + QCOMPARE(str, QString("12345")); + QCOMPARE(AppendCommand::delete_cnt, 5); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("1234")); + QCOMPARE(AppendCommand::delete_cnt, 5); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "append", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("123")); + QCOMPARE(AppendCommand::delete_cnt, 5); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "4", true)); + QCOMPARE(str, QString("1234")); + QCOMPARE(AppendCommand::delete_cnt, 7); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "5")); + QCOMPARE(str, QString("12345")); + QCOMPARE(AppendCommand::delete_cnt, 7); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "6", true)); // should be merged + QCOMPARE(str, QString("123456")); + QCOMPARE(AppendCommand::delete_cnt, 8); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "append", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.beginMacro("foo"); + QCOMPARE(str, QString("123456")); + QCOMPARE(AppendCommand::delete_cnt, 8); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.push(new AppendCommand(&str, "7", true)); + QCOMPARE(str, QString("1234567")); + QCOMPARE(AppendCommand::delete_cnt, 8); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.push(new AppendCommand(&str, "8")); + QCOMPARE(str, QString("12345678")); + QCOMPARE(AppendCommand::delete_cnt, 8); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 3, // count + 2, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + false); // redoChanged + + stack.endMacro(); + QCOMPARE(str, QString("12345678")); + QCOMPARE(AppendCommand::delete_cnt, 9); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 2, // index + true, // canUndo + "foo", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("123456")); + QCOMPARE(AppendCommand::delete_cnt, 9); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 1, // index + true, // canUndo + "append", // undoText + true, // canRedo + "foo", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + QCOMPARE(str, QString("1234")); + QCOMPARE(AppendCommand::delete_cnt, 9); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 2, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "append", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged +} + +void tst_QUndoStack::commandTextFormat() +{ +#if !QT_CONFIG(process) + QSKIP("No QProcess available"); +#else + QString binDir = QLibraryInfo::location(QLibraryInfo::BinariesPath); + + if (QProcess::execute(binDir + "/lrelease -version") != 0) + QSKIP("lrelease is missing or broken"); + + const QString tsFile = QFINDTESTDATA("testdata/qundostack.ts"); + QVERIFY(!tsFile.isEmpty()); + QFile::remove("qundostack.qm"); // Avoid confusion by strays. + QVERIFY(!QProcess::execute(binDir + "/lrelease -silent " + tsFile + " -qm qundostack.qm")); + + QTranslator translator; + QVERIFY(translator.load("qundostack.qm")); + QFile::remove("qundostack.qm"); + qApp->installTranslator(&translator); + + QUndoStack stack; + QScopedPointer<QAction> undo_action(stack.createUndoAction(nullptr)); + QScopedPointer<QAction> redo_action(stack.createRedoAction(nullptr)); + + QCOMPARE(undo_action->text(), QString("Undo-default-text")); + QCOMPARE(redo_action->text(), QString("Redo-default-text")); + + QString str; + + stack.push(new AppendCommand(&str, "foo")); + QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix")); + QCOMPARE(redo_action->text(), QString("Redo-default-text")); + + stack.push(new InsertCommand(&str, 0, "bar")); + stack.undo(); + QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix")); + QCOMPARE(redo_action->text(), QString("redo-prefix insert redo-suffix")); + + stack.undo(); + QCOMPARE(undo_action->text(), QString("Undo-default-text")); + QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix")); + + qApp->removeTranslator(&translator); +#endif +} + +void tst_QUndoStack::separateUndoText() +{ + QUndoStack stack; + QScopedPointer<QAction> undo_action(stack.createUndoAction(nullptr)); + QScopedPointer<QAction> redo_action(stack.createRedoAction(nullptr)); + + QUndoCommand *command1 = new IdleCommand(); + QUndoCommand *command2 = new IdleCommand(); + stack.push(command1); + stack.push(command2); + stack.undo(); + + QCOMPARE(undo_action->text(), QString("Undo idle-action")); + QCOMPARE(redo_action->text(), QString("Redo idle-action")); + QCOMPARE(command1->actionText(), QString("idle-action")); + + QCOMPARE(command1->text(), QString("idle-item")); + QCOMPARE(stack.text(0), QString("idle-item")); + + command1->setText("idle"); + QCOMPARE(command1->actionText(), QString("idle")); + QCOMPARE(command1->text(), QString("idle")); + + command1->setText("idle-item\nidle-action"); + QCOMPARE(command1->actionText(), QString("idle-action")); + QCOMPARE(command1->text(), QString("idle-item")); +} + +QTEST_MAIN(tst_QUndoStack) + +#include "tst_qundostack.moc" diff --git a/tests/auto/gui/util/util.pro b/tests/auto/gui/util/util.pro index 2789ffb55d..7523e01ca4 100644 --- a/tests/auto/gui/util/util.pro +++ b/tests/auto/gui/util/util.pro @@ -3,11 +3,12 @@ SUBDIRS= \ qdesktopservices \ qdoublevalidator \ qintvalidator \ - qregexpvalidator \ qregularexpressionvalidator \ qshadergenerator \ qshadergraph \ qshadergraphloader \ qshadernodes \ qshadernodesloader \ - qtexturefilereader + qtexturefilereader \ + qundogroup \ + qundostack |