diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qicon/tst_qicon.cpp | 59 | ||||
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 125 | ||||
-rw-r--r-- | tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 15 |
3 files changed, 144 insertions, 55 deletions
diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index 0f642bcc10..524f0a30ed 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -55,6 +55,7 @@ public: tst_QIcon(); private slots: + void initTestCase(); void actualSize_data(); // test with 1 pixmap void actualSize(); void actualSize2_data(); // test with 2 pixmaps with different aspect ratio @@ -79,6 +80,10 @@ private slots: private: bool haveImageFormat(QByteArray const&); + const QString m_pngImageFileName; + const QString m_pngRectFileName; + const QString m_sourceFileName; + const static QIcon staticIcon; }; @@ -92,9 +97,19 @@ bool tst_QIcon::haveImageFormat(QByteArray const& desiredFormat) } tst_QIcon::tst_QIcon() + : m_pngImageFileName(QFINDTESTDATA("image.png")) + , m_pngRectFileName(QFINDTESTDATA("rect.png")) + , m_sourceFileName(QFINDTESTDATA(__FILE__)) { } +void tst_QIcon::initTestCase() +{ + QVERIFY(!m_pngImageFileName.isEmpty()); + QVERIFY(!m_pngRectFileName.isEmpty()); + QVERIFY(!m_sourceFileName.isEmpty()); +} + void tst_QIcon::actualSize_data() { QTest::addColumn<QString>("source"); @@ -115,14 +130,13 @@ void tst_QIcon::actualSize_data() QTest::newRow("resource9") << ":/rect.png" << QSize( 15, 50) << QSize( 15, 30); QTest::newRow("resource10") << ":/rect.png" << QSize( 25, 50) << QSize( 20, 40); - const QString prefix = QFileInfo(QFINDTESTDATA("icons")).absolutePath() + "/"; - QTest::newRow("external0") << prefix + "image.png" << QSize(128, 128) << QSize(128, 128); - QTest::newRow("external1") << prefix + "image.png" << QSize( 64, 64) << QSize( 64, 64); - QTest::newRow("external2") << prefix + "image.png" << QSize( 32, 64) << QSize( 32, 32); - QTest::newRow("external3") << prefix + "image.png" << QSize( 16, 64) << QSize( 16, 16); - QTest::newRow("external4") << prefix + "image.png" << QSize( 16, 128) << QSize( 16, 16); - QTest::newRow("external5") << prefix + "image.png" << QSize( 128, 16) << QSize( 16, 16); - QTest::newRow("external6") << prefix + "image.png" << QSize( 150, 150) << QSize( 128, 128); + QTest::newRow("external0") << m_pngImageFileName << QSize(128, 128) << QSize(128, 128); + QTest::newRow("external1") << m_pngImageFileName << QSize( 64, 64) << QSize( 64, 64); + QTest::newRow("external2") << m_pngImageFileName << QSize( 32, 64) << QSize( 32, 32); + QTest::newRow("external3") << m_pngImageFileName << QSize( 16, 64) << QSize( 16, 16); + QTest::newRow("external4") << m_pngImageFileName << QSize( 16, 128) << QSize( 16, 16); + QTest::newRow("external5") << m_pngImageFileName << QSize(128, 16) << QSize( 16, 16); + QTest::newRow("external6") << m_pngImageFileName << QSize(150, 150) << QSize(128, 128); // rect image QTest::newRow("external7") << ":/rect.png" << QSize( 20, 40) << QSize( 20, 40); QTest::newRow("external8") << ":/rect.png" << QSize( 10, 20) << QSize( 10, 20); @@ -170,10 +184,8 @@ void tst_QIcon::actualSize2_data() void tst_QIcon::actualSize2() { QIcon icon; - const QString prefix = QFileInfo(QFINDTESTDATA("icons")).absolutePath() + "/"; - - icon.addPixmap(QPixmap(prefix + "image.png")); - icon.addPixmap(QPixmap(prefix + "rect.png")); + icon.addPixmap(m_pngImageFileName); + icon.addPixmap(m_pngRectFileName); QFETCH(QSize, argument); QFETCH(QSize, result); @@ -209,14 +221,13 @@ void tst_QIcon::isNull() { QVERIFY(!iconNoFileSuffix.isNull()); QVERIFY(!iconNoFileSuffix.actualSize(QSize(32, 32)).isValid()); - const QString prefix = QFileInfo(QFINDTESTDATA("icons")).absolutePath() + "/"; // test string constructor with existing file but unsupported format - QIcon iconUnsupportedFormat = QIcon(prefix + "tst_qicon.cpp"); + QIcon iconUnsupportedFormat = QIcon(m_sourceFileName); QVERIFY(!iconUnsupportedFormat.isNull()); QVERIFY(!iconUnsupportedFormat.actualSize(QSize(32, 32)).isValid()); // test string constructor with existing file and supported format - QIcon iconSupportedFormat = QIcon(prefix + "image.png"); + QIcon iconSupportedFormat = QIcon(m_pngImageFileName); QVERIFY(!iconSupportedFormat.isNull()); QVERIFY(iconSupportedFormat.actualSize(QSize(32, 32)).isValid()); } @@ -347,7 +358,7 @@ void tst_QIcon::bestMatch() void tst_QIcon::cacheKey() { - QIcon icon1("image.png"); + QIcon icon1(m_pngImageFileName); qint64 icon1_key = icon1.cacheKey(); QIcon icon2 = icon1; @@ -363,7 +374,7 @@ void tst_QIcon::detach() img.fill(0xffff0000); QIcon icon1(QPixmap::fromImage(img)); QIcon icon2 = icon1; - icon2.addFile(QFINDTESTDATA("image.png"), QSize(64, 64)); + icon2.addFile(m_pngImageFileName, QSize(64, 64)); QImage img1 = icon1.pixmap(64, 64).toImage(); QImage img2 = icon2.pixmap(64, 64).toImage(); @@ -415,11 +426,11 @@ void tst_QIcon::availableSizes() { { QIcon icon; - icon.addFile("image.png", QSize(32,32)); - icon.addFile("image.png", QSize(64,64)); - icon.addFile("image.png", QSize(128,128)); - icon.addFile("image.png", QSize(256,256), QIcon::Disabled); - icon.addFile("image.png", QSize(16,16), QIcon::Normal, QIcon::On); + icon.addFile(m_pngImageFileName, QSize(32,32)); + icon.addFile(m_pngImageFileName, QSize(64,64)); + icon.addFile(m_pngImageFileName, QSize(128,128)); + icon.addFile(m_pngImageFileName, QSize(256,256), QIcon::Disabled); + icon.addFile(m_pngImageFileName, QSize(16,16), QIcon::Normal, QIcon::On); QList<QSize> availableSizes = icon.availableSizes(); QCOMPARE(availableSizes.size(), 3); @@ -542,7 +553,7 @@ static inline bool operator<(const QSize &lhs, const QSize &rhs) #ifndef QT_NO_WIDGETS void tst_QIcon::task184901_badCache() { - QPixmap pm(QFINDTESTDATA("image.png")); + QPixmap pm(m_pngImageFileName); QIcon icon(pm); //the disabled icon must have an effect (grayed) diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index d2072e0e56..0a4456e22a 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -146,6 +146,9 @@ private slots: void fillRGB888(); + void fillPixel_data(); + void fillPixel(); + void rgbSwapped_data(); void rgbSwapped(); @@ -2058,6 +2061,42 @@ void tst_QImage::fillRGB888() } } +void tst_QImage::fillPixel_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<uint>("color"); + QTest::addColumn<uint>("pixelValue"); + + QTest::newRow("RGB16, transparent") << QImage::Format_RGB16 << 0x0u << 0xff000000u; + QTest::newRow("RGB32, transparent") << QImage::Format_RGB32 << 0x0u << 0xff000000u; + QTest::newRow("RGBx8888, transparent") << QImage::Format_RGBX8888 << 0x0u << 0xff000000u; + QTest::newRow("ARGB32, transparent") << QImage::Format_ARGB32 << 0x0u << 0x00000000u; + QTest::newRow("ARGB32pm, transparent") << QImage::Format_ARGB32_Premultiplied << 0x0u << 0x00000000u; + QTest::newRow("RGBA8888pm, transparent") << QImage::Format_RGBA8888_Premultiplied << 0x0u << 0x00000000u; + + QTest::newRow("RGB16, red") << QImage::Format_RGB16 << (uint)qConvertRgb32To16(0xffff0000) << 0xffff0000u; + QTest::newRow("RGB32, red") << QImage::Format_RGB32 << 0xffff0000u << 0xffff0000u; + QTest::newRow("ARGB32, red") << QImage::Format_ARGB32 << 0xffff0000u << 0xffff0000u; + QTest::newRow("RGBA8888, red") << QImage::Format_RGBA8888 << 0xff0000ffu << 0xffff0000u; + + QTest::newRow("RGB32, semi-red") << QImage::Format_RGB32 << 0x80ff0000u << 0xffff0000u; + QTest::newRow("ARGB32, semi-red") << QImage::Format_ARGB32 << 0x80ff0000u << 0x80ff0000u; + QTest::newRow("ARGB32pm, semi-red") << QImage::Format_ARGB32 << 0x80800000u << 0x80800000u; + QTest::newRow("RGBA8888pm, semi-red") << QImage::Format_RGBA8888_Premultiplied << 0x80000080u << 0x80800000u; +} + +void tst_QImage::fillPixel() +{ + QFETCH(QImage::Format, format); + QFETCH(uint, color); + QFETCH(uint, pixelValue); + + QImage image(1, 1, format); + + image.fill(color); + QCOMPARE(image.pixel(0, 0), pixelValue); +} + void tst_QImage::rgbSwapped_data() { QTest::addColumn<QImage::Format>("format"); @@ -2128,35 +2167,56 @@ void tst_QImage::mirrored_data() QTest::addColumn<QImage::Format>("format"); QTest::addColumn<bool>("swap_vertical"); QTest::addColumn<bool>("swap_horizontal"); - - QTest::newRow("Format_RGB32, vertical") << QImage::Format_RGB32 << true << false; - QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false; - QTest::newRow("Format_ARGB32_Premultiplied, vertical") << QImage::Format_ARGB32_Premultiplied << true << false; - QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << true << false; - QTest::newRow("Format_ARGB8565_Premultiplied, vertical") << QImage::Format_ARGB8565_Premultiplied << true << false; - QTest::newRow("Format_ARGB6666_Premultiplied, vertical") << QImage::Format_ARGB6666_Premultiplied << true << false; - QTest::newRow("Format_ARGB4444_Premultiplied, vertical") << QImage::Format_ARGB4444_Premultiplied << true << false; - QTest::newRow("Format_RGB666, vertical") << QImage::Format_RGB666 << true << false; - QTest::newRow("Format_RGB555, vertical") << QImage::Format_RGB555 << true << false; - QTest::newRow("Format_ARGB8555_Premultiplied, vertical") << QImage::Format_ARGB8555_Premultiplied << true << false; - QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << true << false; - QTest::newRow("Format_RGB444, vertical") << QImage::Format_RGB444 << true << false; - QTest::newRow("Format_RGBX8888, vertical") << QImage::Format_RGBX8888 << true << false; - QTest::newRow("Format_RGBA8888_Premultiplied, vertical") << QImage::Format_RGBA8888_Premultiplied << true << false; - QTest::newRow("Format_Indexed8, vertical") << QImage::Format_Indexed8 << true << false; - QTest::newRow("Format_Mono, vertical") << QImage::Format_Mono << true << false; - - QTest::newRow("Format_ARGB32_Premultiplied, horizontal") << QImage::Format_ARGB32_Premultiplied << false << true; - QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << false << true; - QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << false << true; - QTest::newRow("Format_Indexed8, horizontal") << QImage::Format_Indexed8 << false << true; - QTest::newRow("Format_Mono, horizontal") << QImage::Format_Mono << false << true; - - QTest::newRow("Format_ARGB32_Premultiplied, horizontal+vertical") << QImage::Format_ARGB32_Premultiplied << true << true; - QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << true << true; - QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << true << true; - QTest::newRow("Format_Indexed8, horizontal+vertical") << QImage::Format_Indexed8 << true << true; - QTest::newRow("Format_Mono, horizontal+vertical") << QImage::Format_Mono << true << true; + QTest::addColumn<int>("width"); + QTest::addColumn<int>("height"); + + QTest::newRow("Format_RGB32, vertical") << QImage::Format_RGB32 << true << false << 16 << 16; + QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false << 16 << 16; + QTest::newRow("Format_ARGB32_Premultiplied, vertical") << QImage::Format_ARGB32_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << true << false << 16 << 16; + QTest::newRow("Format_ARGB8565_Premultiplied, vertical") << QImage::Format_ARGB8565_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_ARGB6666_Premultiplied, vertical") << QImage::Format_ARGB6666_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_ARGB4444_Premultiplied, vertical") << QImage::Format_ARGB4444_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_RGB666, vertical") << QImage::Format_RGB666 << true << false << 16 << 16; + QTest::newRow("Format_RGB555, vertical") << QImage::Format_RGB555 << true << false << 16 << 16; + QTest::newRow("Format_ARGB8555_Premultiplied, vertical") << QImage::Format_ARGB8555_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << true << false << 16 << 16; + QTest::newRow("Format_RGB444, vertical") << QImage::Format_RGB444 << true << false << 16 << 16; + QTest::newRow("Format_RGBX8888, vertical") << QImage::Format_RGBX8888 << true << false << 16 << 16; + QTest::newRow("Format_RGBA8888_Premultiplied, vertical") << QImage::Format_RGBA8888_Premultiplied << true << false << 16 << 16; + QTest::newRow("Format_Indexed8, vertical") << QImage::Format_Indexed8 << true << false << 16 << 16; + QTest::newRow("Format_Mono, vertical") << QImage::Format_Mono << true << false << 16 << 16; + QTest::newRow("Format_MonoLSB, vertical") << QImage::Format_MonoLSB << true << false << 16 << 16; + + QTest::newRow("Format_ARGB32_Premultiplied, horizontal") << QImage::Format_ARGB32_Premultiplied << false << true << 16 << 16; + QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << false << true << 16 << 16; + QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << false << true << 16 << 16; + QTest::newRow("Format_Indexed8, horizontal") << QImage::Format_Indexed8 << false << true << 16 << 16; + QTest::newRow("Format_Mono, horizontal") << QImage::Format_Mono << false << true << 16 << 16; + QTest::newRow("Format_MonoLSB, horizontal") << QImage::Format_MonoLSB << false << true << 16 << 16; + + QTest::newRow("Format_ARGB32_Premultiplied, horizontal+vertical") << QImage::Format_ARGB32_Premultiplied << true << true << 16 << 16; + QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << true << true << 16 << 16; + QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << true << true << 16 << 16; + QTest::newRow("Format_Indexed8, horizontal+vertical") << QImage::Format_Indexed8 << true << true << 16 << 16; + QTest::newRow("Format_Mono, horizontal+vertical") << QImage::Format_Mono << true << true << 16 << 16; + QTest::newRow("Format_MonoLSB, horizontal+vertical") << QImage::Format_MonoLSB << true << true << 16 << 16; + + QTest::newRow("Format_RGB32, vertical") << QImage::Format_RGB32 << true << false << 8 << 16; + QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false << 16 << 8; + QTest::newRow("Format_Mono, vertical, non-aligned") << QImage::Format_Mono << true << false << 19 << 25; + QTest::newRow("Format_MonoLSB, vertical, non-aligned") << QImage::Format_MonoLSB << true << false << 19 << 25; + + // Non-aligned horizontal 1-bit needs special handling so test this. + QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 13 << 17; + QTest::newRow("Format_Mono, horizontal, non-aligned") << QImage::Format_Mono << false << true << 19 << 25; + QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 25 << 47; + QTest::newRow("Format_Mono, horizontal+vertical, non-aligned") << QImage::Format_Mono << true << true << 21 << 16; + + QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 13 << 17; + QTest::newRow("Format_MonoLSB, horizontal, non-aligned") << QImage::Format_MonoLSB << false << true << 19 << 25; + QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 25 << 47; + QTest::newRow("Format_MonoLSB, horizontal+vertical, non-aligned") << QImage::Format_MonoLSB << true << true << 21 << 16; } void tst_QImage::mirrored() @@ -2164,11 +2224,14 @@ void tst_QImage::mirrored() QFETCH(QImage::Format, format); QFETCH(bool, swap_vertical); QFETCH(bool, swap_horizontal); + QFETCH(int, width); + QFETCH(int, height); - QImage image(16, 16, format); + QImage image(width, height, format); switch (format) { case QImage::Format_Mono: + case QImage::Format_MonoLSB: for (int i = 0; i < image.height(); ++i) { ushort* scanLine = (ushort*)image.scanLine(i); *scanLine = (i % 2) ? 0x5555U : 0xCCCCU; @@ -2205,7 +2268,7 @@ void tst_QImage::mirrored() QCOMPARE(image, imageMirroredTwice); - if (format != QImage::Format_Mono) + if (format != QImage::Format_Mono && format != QImage::Format_MonoLSB) QCOMPARE(memcmp(image.constBits(), imageMirroredTwice.constBits(), image.byteCount()), 0); else { for (int i = 0; i < image.height(); ++i) diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 79dc3f311a..b9d0adcd21 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -91,6 +91,7 @@ private slots: void convertFromImage_data(); void convertFromImage(); + void convertFromImageShouldDetach(); void testMetrics(); @@ -343,6 +344,20 @@ void tst_QPixmap::convertFromImage() QCOMPARE(pix, res); } +void tst_QPixmap::convertFromImageShouldDetach() +{ + const QString prefix = QFINDTESTDATA("convertFromImage"); + QImage img1; + QImage img2; + QVERIFY(img1.load(prefix + "/task31722_0/img1.png")); + QVERIFY(img2.load(prefix + "/task31722_0/img2.png")); + QPixmap pix = QPixmap::fromImage(img1); + QPixmap pix1 = pix; + pix.convertFromImage(img2); + QCOMPARE(pix, QPixmap::fromImage(img2)); + QCOMPARE(pix1, QPixmap::fromImage(img1)); // unchanged +} + void tst_QPixmap::scroll_data() { QTest::addColumn<QImage>("input"); |