diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg | bin | 0 -> 705 bytes | |||
-rw-r--r-- | tests/auto/gui/image/qimage/qimage.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 141 | ||||
-rw-r--r-- | tests/auto/gui/image/qimagereader/qimagereader.pro | 3 | ||||
-rw-r--r-- | tests/auto/gui/image/qimagereader/qimagereader.qrc | 69 | ||||
-rw-r--r-- | tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 22 | ||||
-rw-r--r-- | tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp | 3 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 55 | ||||
-rw-r--r-- | tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp | 4 | ||||
-rw-r--r-- | tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp | 8 |
10 files changed, 232 insertions, 75 deletions
diff --git a/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg b/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg Binary files differnew file mode 100644 index 0000000000..42b305f5b8 --- /dev/null +++ b/tests/auto/gui/image/qimage/images/jpeg_exif_utf8_comment.jpg diff --git a/tests/auto/gui/image/qimage/qimage.pro b/tests/auto/gui/image/qimage/qimage.pro index 56618e0bfa..39fb4d0cc3 100644 --- a/tests/auto/gui/image/qimage/qimage.pro +++ b/tests/auto/gui/image/qimage/qimage.pro @@ -7,4 +7,6 @@ qtConfig(c++11): CONFIG += c++11 android:!android-embedded: RESOURCES += qimage.qrc +win32:!winrt: LIBS += -lgdi32 -luser32 + TESTDATA += images/* diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 7ad4a9e9bb..1f52018d7f 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -44,6 +44,10 @@ #include <CoreGraphics/CoreGraphics.h> #endif +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +# include <qt_windows.h> +#endif + Q_DECLARE_METATYPE(QImage::Format) Q_DECLARE_METATYPE(Qt::GlobalColor) @@ -192,6 +196,7 @@ private slots: void exif_QTBUG45865(); void exifInvalidData_data(); void exifInvalidData(); + void exifReadComments(); void cleanupFunctions(); @@ -222,6 +227,11 @@ private slots: void hugeQImage(); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + void toWinHBITMAP_data(); + void toWinHBITMAP(); +#endif // Q_OS_WIN && !Q_OS_WINRT + private: const QString m_prefix; }; @@ -3066,6 +3076,34 @@ void tst_QImage::exifInvalidData() QVERIFY(!image.isNull()); } +void tst_QImage::exifReadComments() +{ + QImage image; + QVERIFY(image.load(m_prefix + "jpeg_exif_utf8_comment.jpg")); + QVERIFY(!image.isNull()); + QCOMPARE(image.textKeys().size(), 1); + QCOMPARE(image.textKeys().first(), "Description"); + // check if exif comment is read as utf-8 + QCOMPARE(image.text("Description"), QString::fromUtf8("some unicode chars: ÖÄÜ€@")); + + QByteArray ba; + { + QBuffer buf(&ba); + QVERIFY(buf.open(QIODevice::WriteOnly)); + QVERIFY(image.save(&buf, "JPG")); + } + QVERIFY(!ba.isEmpty()); + image = QImage(); + QCOMPARE(image.textKeys().size(), 0); + { + QBuffer buf(&ba); + QVERIFY(buf.open(QIODevice::ReadOnly)); + QVERIFY(image.load(&buf, "JPG")); + } + // compare written (and reread) description text + QCOMPARE(image.text("Description"), QString::fromUtf8("some unicode chars: ÖÄÜ€@")); +} + static void cleanupFunction(void* info) { bool *called = static_cast<bool*>(info); @@ -3458,5 +3496,108 @@ void tst_QImage::hugeQImage() #endif } +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +QT_BEGIN_NAMESPACE +Q_GUI_EXPORT HBITMAP qt_imageToWinHBITMAP(const QImage &p, int hbitmapFormat = 0); +Q_GUI_EXPORT QImage qt_imageFromWinHBITMAP(HBITMAP bitmap, int hbitmapFormat = 0); +QT_END_NAMESPACE + +static inline QColor COLORREFToQColor(COLORREF cr) +{ + return QColor(GetRValue(cr), GetGValue(cr), GetBValue(cr)); +} + +void tst_QImage::toWinHBITMAP_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QColor>("color"); + QTest::addColumn<QColor>("bottomRightColor"); + + const QColor red(Qt::red); + const QColor green(Qt::green); + const QColor blue(Qt::blue); + const QColor gray(Qt::gray); + const QColor gray555(0x5a, 0x5a, 0x5a); // Note: Interpolation 8<->5 bit occurs. + const QColor white(Qt::white); + const QColor black(Qt::black); + + QTest::newRow("argb32p-red") << QImage::Format_ARGB32_Premultiplied << red << gray; + QTest::newRow("argb32p-green") << QImage::Format_ARGB32_Premultiplied << green << gray; + QTest::newRow("argb32p-blue") << QImage::Format_ARGB32_Premultiplied << blue << gray; + QTest::newRow("rgb888-red") << QImage::Format_RGB888 << red << gray; + QTest::newRow("rgb888-green") << QImage::Format_RGB888 << green << gray; + QTest::newRow("rgb888-blue") << QImage::Format_RGB888 << blue << gray; + QTest::newRow("indexed8-red") << QImage::Format_Indexed8 << red << gray; + QTest::newRow("indexed8-green") << QImage::Format_Indexed8 << green << gray; + QTest::newRow("indexed8-blue") << QImage::Format_Indexed8 << blue << gray; + QTest::newRow("rgb555-red") << QImage::Format_RGB555 << red << gray555; + QTest::newRow("rgb555-green") << QImage::Format_RGB555 << green << gray555; + QTest::newRow("rgb555-blue") << QImage::Format_RGB555 << blue << gray555; + QTest::newRow("mono") << QImage::Format_Mono << white << black; +} + +// Test image filled with color, black pixel at botttom right corner. +static inline QImage createTestImage(QImage::Format format, int width, int height, + const QColor &fillColor, const QColor &bottomRightColor) +{ + QImage image(QSize(width, height), format); + image.fill(fillColor); + QPainter painter(&image); + QPen pen = painter.pen(); + pen.setColor(bottomRightColor); + painter.setPen(pen); + painter.drawPoint(width -1, height - 1); + return image; +} + +void tst_QImage::toWinHBITMAP() +{ + static const int width = 73; + static const int height = 57; + + QFETCH(QImage::Format, format); + QFETCH(QColor, color); + QFETCH(QColor, bottomRightColor); + + // Cannot paint on indexed/mono images. + const QImage image = format == QImage::Format_Indexed8 || format == QImage::Format_Mono + ? createTestImage(QImage::Format_RGB32, width, height, color, bottomRightColor).convertToFormat(format) + : createTestImage(format, width, height, color, bottomRightColor); + + const HBITMAP bitmap = qt_imageToWinHBITMAP(image); + + QVERIFY(bitmap != 0); + + // Verify size + BITMAP bitmapInfo; + memset(&bitmapInfo, 0, sizeof(BITMAP)); + + const int res = GetObject(bitmap, sizeof(BITMAP), &bitmapInfo); + QVERIFY(res); + QCOMPARE(width, int(bitmapInfo.bmWidth)); + QCOMPARE(height, int(bitmapInfo.bmHeight)); + + const HDC displayDc = GetDC(0); + const HDC bitmapDc = CreateCompatibleDC(displayDc); + + const HBITMAP nullBitmap = static_cast<HBITMAP>(SelectObject(bitmapDc, bitmap)); + + QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, 0, 0)), color); + QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, width - 1, 3)), color); + QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, 3, height - 1)), color); + QCOMPARE(COLORREFToQColor(GetPixel(bitmapDc, width - 1, height - 1)), bottomRightColor); + + const QImage convertedBack = qt_imageFromWinHBITMAP(bitmap); + QCOMPARE(convertedBack.convertToFormat(QImage::Format_ARGB32_Premultiplied), + image.convertToFormat(QImage::Format_ARGB32_Premultiplied)); + + // Clean up + SelectObject(bitmapDc, nullBitmap); + DeleteObject(bitmap); + DeleteDC(bitmapDc); + ReleaseDC(0, displayDc); +} +#endif // Q_OS_WIN && !Q_OS_WINRT + QTEST_GUILESS_MAIN(tst_QImage) #include "tst_qimage.moc" diff --git a/tests/auto/gui/image/qimagereader/qimagereader.pro b/tests/auto/gui/image/qimagereader/qimagereader.pro index b06f56dddf..623d45ffe2 100644 --- a/tests/auto/gui/image/qimagereader/qimagereader.pro +++ b/tests/auto/gui/image/qimagereader/qimagereader.pro @@ -3,7 +3,8 @@ TARGET = tst_qimagereader SOURCES += tst_qimagereader.cpp MOC_DIR=tmp QT += core-private gui-private network testlib -RESOURCES += qimagereader.qrc + +RESOURCES += $$files(images/*) android:!android-embedded { RESOURCES += android_testdata.qrc diff --git a/tests/auto/gui/image/qimagereader/qimagereader.qrc b/tests/auto/gui/image/qimagereader/qimagereader.qrc deleted file mode 100644 index 2522154b1f..0000000000 --- a/tests/auto/gui/image/qimagereader/qimagereader.qrc +++ /dev/null @@ -1,69 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>images/16bpp.bmp</file> - <file>images/4bpp-rle.bmp</file> - <file>images/YCbCr_cmyk.jpg</file> - <file>images/YCbCr_cmyk.png</file> - <file>images/YCbCr_rgb.jpg</file> - <file>images/away.png</file> - <file>images/bat1.gif</file> - <file>images/bat2.gif</file> - <file>images/beavis.jpg</file> - <file>images/black.png</file> - <file>images/black.xpm</file> - <file>images/colorful.bmp</file> - <file>images/corrupt-colors.xpm</file> - <file>images/corrupt-pixels.xpm</file> - <file>images/corrupt.bmp</file> - <file>images/corrupt.gif</file> - <file>images/corrupt.jpg</file> - <file>images/corrupt.png</file> - <file>images/corrupt.xbm</file> - <file>images/crash-signed-char.bmp</file> - <file>images/earth.gif</file> - <file>images/font.bmp</file> - <file>images/gnus.xbm</file> - <file>images/image.pbm</file> - <file>images/image.pgm</file> - <file>images/image.png</file> - <file>images/image.ppm</file> - <file>images/kollada.png</file> - <file>images/marble.xpm</file> - <file>images/namedcolors.xpm</file> - <file>images/negativeheight.bmp</file> - <file>images/noclearcode.bmp</file> - <file>images/noclearcode.gif</file> - <file>images/nontransparent.xpm</file> - <file>images/rgb32bf.bmp</file> - <file>images/runners.ppm</file> - <file>images/teapot.ppm</file> - <file>images/test.ppm</file> - <file>images/test.xpm</file> - <file>images/test32bfv4.bmp</file> - <file>images/test32v5.bmp</file> - <file>images/tst7.bmp</file> - <file>images/tst7.png</file> - <file>images/transparent.xpm</file> - <file>images/trolltech.gif</file> - <file>images/qt.gif</file> - <file>images/qt1.gif</file> - <file>images/qt2.gif</file> - <file>images/qt3.gif</file> - <file>images/qt4.gif</file> - <file>images/qt5.gif</file> - <file>images/qt6.gif</file> - <file>images/qt7.gif</file> - <file>images/qt8.gif</file> - <file>images/endless-anim.gif</file> - <file>images/four-frames.gif</file> - <file>images/qt-gif-anim.gif</file> - <file>images/qt-gif-noanim.gif</file> - <file>images/rect.svg</file> - <file>images/rect.svgz</file> - <file>images/corrupt.svg</file> - <file>images/corrupt.svgz</file> - <file>images/qtbug13653-no_eoi.jpg</file> - <file>images/txts.jpg</file> - <file>images/txts.png</file> - </qresource> -</RCC> diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index e3bda6c2df..9a338ad55a 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -90,6 +90,7 @@ private slots: void mask(); void bitmapMask(); + void bitmapFromImageRvalue(); void setGetMask_data(); void setGetMask(); void cacheKey(); @@ -596,6 +597,27 @@ void tst_QPixmap::bitmapMask() QVERIFY(image.pixel(1, 1)); } +void tst_QPixmap::bitmapFromImageRvalue() +{ + auto makeImage = [](){ + QImage image(3, 3, QImage::Format_MonoLSB); + image.setColor(0, Qt::color0); + image.setColor(1, Qt::color1); + image.fill(Qt::color0); + image.setPixel(1, 1, Qt::color1); + image.setPixel(0, 0, Qt::color1); + return image; + }; + + auto image1 = makeImage(); + auto image2 = makeImage(); + auto bitmap1 = QBitmap::fromImage(image1); + auto bitmap2 = QBitmap::fromImage(std::move(image2)); + QCOMPARE(bitmap1.toImage(), bitmap2.toImage()); + QVERIFY(!image1.isNull()); + QVERIFY(image2.isNull()); +} + void tst_QPixmap::setGetMask_data() { QTest::addColumn<QPixmap>("pixmap"); diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp index 8a2a35f86c..158530428d 100644 --- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp @@ -92,6 +92,9 @@ void tst_QPixmapCache::cacheLimit() // it was between 2048 and 10240 last time I looked at it QVERIFY(originalCacheLimit >= 1024 && originalCacheLimit <= 20480); + QPixmapCache::setCacheLimit(std::numeric_limits<int>::max()); + QCOMPARE(QPixmapCache::cacheLimit(), std::numeric_limits<int>::max()); + QPixmapCache::setCacheLimit(100); QCOMPARE(QPixmapCache::cacheLimit(), 100); diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 722405377e..40d0f4f32a 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -97,6 +97,7 @@ private slots: void modalWindowPosition(); #ifndef QT_NO_CURSOR void modalWindowEnterEventOnHide_QTBUG35109(); + void spuriousMouseMove(); #endif void windowsTransientChildren(); void requestUpdate(); @@ -895,7 +896,7 @@ void tst_QWindow::isActive() QVERIFY(child.isActive()); } -class InputTestWindow : public QWindow +class InputTestWindow : public ColoredWindow { public: void keyPressEvent(QKeyEvent *event) { @@ -989,7 +990,9 @@ public: enterEventCount = leaveEventCount = 0; } - InputTestWindow() { + explicit InputTestWindow(const QColor &color = Qt::white, QWindow *parent = nullptr) + : ColoredWindow(color, parent) + { keyPressCode = keyReleaseCode = 0; mousePressButton = mouseReleaseButton = mouseMoveButton = 0; ignoreMouse = ignoreTouch = false; @@ -2213,7 +2216,53 @@ void tst_QWindow::modalWindowEnterEventOnHide_QTBUG35109() QTRY_COMPARE(root.enterEventCount, 1); } } -#endif + +// Verify that no spurious mouse move events are received. On Windows, there is +// no enter event, the OS sends mouse move events instead. Test that the QPA +// plugin properly suppresses those since they can interfere with tests. +// Simulate a main window setup with a modal dialog on top, keep the cursor +// in the center and check that no mouse events are recorded. +void tst_QWindow::spuriousMouseMove() +{ + const QString &platformName = QGuiApplication::platformName(); + if (platformName == QLatin1String("offscreen") || platformName == QLatin1String("cocoa")) + QSKIP("No enter events sent"); + if (isPlatformWayland()) + QSKIP("QCursor::setPos() is not supported on Wayland"); + const QRect screenGeometry = QGuiApplication::primaryScreen()->geometry(); + const QPoint center = screenGeometry.center(); + QCursor::setPos(center); + QRect windowGeometry(QPoint(), 2 * m_testWindowSize); + windowGeometry.moveCenter(center); + QTRY_COMPARE(QCursor::pos(), center); + InputTestWindow topLevel; + topLevel.setTitle(QTest::currentTestFunction()); + topLevel.setGeometry(windowGeometry); + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QTRY_VERIFY(topLevel.enterEventCount > 0); + InputTestWindow dialog(Qt::yellow); + dialog.setTransientParent(&topLevel); + dialog.setTitle("Dialog " + topLevel.title()); + dialog.setModality(Qt::ApplicationModal); + windowGeometry.setSize(m_testWindowSize); + windowGeometry.moveCenter(center); + dialog.setGeometry(windowGeometry); + dialog.show(); + QVERIFY(QTest::qWaitForWindowExposed(&dialog)); + QTRY_VERIFY(dialog.enterEventCount > 0); + dialog.setVisible(false); + QCOMPARE(dialog.mousePressedCount, 0); + QCOMPARE(dialog.mouseReleasedCount, 0); + QCOMPARE(dialog.mouseMovedCount, 0); + QCOMPARE(dialog.mouseDoubleClickedCount, 0); + topLevel.setVisible(false); + QCOMPARE(topLevel.mousePressedCount, 0); + QCOMPARE(topLevel.mouseReleasedCount, 0); + QCOMPARE(topLevel.mouseMovedCount, 0); + QCOMPARE(topLevel.mouseDoubleClickedCount, 0); +} +#endif // !QT_NO_CURSOR static bool isNativeWindowVisible(const QWindow *window) { diff --git a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp index fb92b5a20f..bbb90ec82a 100644 --- a/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp +++ b/tests/auto/gui/text/qtextodfwriter/tst_qtextodfwriter.cpp @@ -131,7 +131,7 @@ void tst_QTextOdfWriter::testWriteParagraph_data() QTest::newRow("misc2") << "\t \tFoo" << "<text:p text:style-name=\"p1\"><text:span text:style-name=\"c0\"><text:tab/> <text:s text:c=\"4\"/><text:tab/>Foo</text:span></text:p>"; QTest::newRow("linefeed") << (QStringLiteral("line1") + QChar(0x2028) + QStringLiteral("line2")) << - "<text:p text:style-name=\"p1\"><text:span text:style-name=\"c0\">line1<text:line-break/>line2</text:span></text:p>"; + "<text:p text:style-name=\"p1\"><text:span text:style-name=\"c0\">line1<text:tab/><text:line-break/>line2</text:span></text:p>"; QTest::newRow("spaces") << "The quick brown fox jumped over the lazy dog" << "<text:p text:style-name=\"p1\"><text:span text:style-name=\"c0\">The quick brown fox jumped over the lazy dog</text:span></text:p>"; } @@ -378,7 +378,7 @@ void tst_QTextOdfWriter::testWriteTable() odfWriter->writeFrame(*xmlWriter, document->rootFrame()); QString xml = QString::fromLatin1( "<text:p text:style-name=\"p1\"/>" - "<table:table>" + "<table:table table:style-name=\"Table2\">" "<table:table-column table:number-columns-repeated=\"3\"/>" "<table:table-row>" "<table:table-cell table:style-name=\"T3\">" diff --git a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp index 4705fc3ed7..012a7e2ce3 100644 --- a/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp +++ b/tests/auto/gui/util/qdoublevalidator/tst_qdoublevalidator.cpp @@ -155,6 +155,10 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data48") << "C" << 0.0 << 100.0 << 1 << QString("0.0") << ACC << ACC; QTest::newRow("data49") << "C" << 0.0 << 100.0 << 0 << QString(".") << ITM << ITM; QTest::newRow("data50") << "C" << 0.0 << 100.0 << 1 << QString(".") << ITM << ITM; + QTest::newRow("data51") << "C" << 0.0 << 2.0 << 2 << QString("9.99") << ITM << ITM; + QTest::newRow("data52") << "C" << 100.0 << 200.0 << 4 << QString("999.9999") << ITM << ITM; + QTest::newRow("data53") << "C" << 0.0 << 2.0 << 2 << QString("9.9999") << INV << INV; + QTest::newRow("data54") << "C" << 100.0 << 200.0 << 4 << QString("9999.9999") << ITM << INV; QTest::newRow("data_de0") << "de" << 0.0 << 100.0 << 1 << QString("50,0") << ACC << ACC; QTest::newRow("data_de1") << "de" << 00.0 << 100.0 << 1 << QString("500,0") << ITM << ITM; @@ -206,6 +210,10 @@ void tst_QDoubleValidator::validate_data() QTest::newRow("data_de43") << "de" << 0.01 << 0.09 << 2 << QString("0") << ITM << ITM; QTest::newRow("data_de44") << "de" << 0.0 << 10.0 << 1 << QString("11") << ITM << ITM; QTest::newRow("data_de45") << "de" << 0.0 << 10.0 << 2 << QString("11") << ITM << ITM; + QTest::newRow("data_de46") << "de" << 0.0 << 2.0 << 2 << QString("9,99") << ITM << ITM; + QTest::newRow("data_de47") << "de" << 100.0 << 200.0 << 4 << QString("999,9999") << ITM << ITM; + QTest::newRow("data_de48") << "de" << 0.0 << 2.0 << 2 << QString("9,9999") << INV << INV; + QTest::newRow("data_de49") << "de" << 100.0 << 200.0 << 4 << QString("9999,9999") << ITM << INV; QString arabicNum; arabicNum += QChar(1633); // "18.4" in arabic |