diff options
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r-- | tests/auto/gui/kernel/kernel.pro | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp | 46 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/icons/appicon.png | bin | 0 -> 175 bytes | |||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/icons/usericon.png | bin | 0 -> 14743 bytes | |||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/qguiapplication.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp | 19 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc | 6 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpixelformat/qpixelformat.pro | 6 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp | 243 |
9 files changed, 318 insertions, 5 deletions
diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index e4d9ce9d27..bbcdd91ea3 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -20,6 +20,7 @@ SUBDIRS=\ qtouchevent \ qwindow \ qguiapplication \ + qpixelformat \ !qtHaveModule(widgets): SUBDIRS -= \ qmouseevent_modal \ diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp index cf786c1dca..8a2009a601 100644 --- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp +++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.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. @@ -134,6 +134,29 @@ void tst_QClipboard::modes() } } +// A predicate to be used with a QSignalSpy / QTRY_VERIFY to ensure all delayed +// notifications are eaten. It waits at least one cycle and returns true when +// no new signals arrive. +class EatSignalSpyNotificationsPredicate +{ +public: + explicit EatSignalSpyNotificationsPredicate(QSignalSpy &spy) : m_spy(spy) { reset(); } + + operator bool() const + { + if (m_timer.elapsed() && !m_spy.count()) + return true; + m_spy.clear(); + return false; + } + + inline void reset() { m_timer.start(); } + +private: + QSignalSpy &m_spy; + QElapsedTimer m_timer; +}; + /* Test that the appropriate signals are emitted when the clipboard contents is changed by calling the qt functions. @@ -149,6 +172,13 @@ void tst_QClipboard::testSignals() QSignalSpy changedSpy(clipboard, SIGNAL(changed(QClipboard::Mode))); QSignalSpy dataChangedSpy(clipboard, SIGNAL(dataChanged())); + // Clipboard notifications are asynchronous with the new AddClipboardFormatListener + // in Windows Vista (5.4). Eat away all signals to ensure they don't interfere + // with the QTRY_COMPARE below. + EatSignalSpyNotificationsPredicate noLeftOverDataChanges(dataChangedSpy); + EatSignalSpyNotificationsPredicate noLeftOverChanges(changedSpy); + QTRY_VERIFY(noLeftOverChanges && noLeftOverDataChanges); + QSignalSpy searchChangedSpy(clipboard, SIGNAL(findBufferChanged())); QSignalSpy selectionChangedSpy(clipboard, SIGNAL(selectionChanged())); @@ -156,7 +186,7 @@ void tst_QClipboard::testSignals() // Test the default mode signal. clipboard->setText(text); - QCOMPARE(dataChangedSpy.count(), 1); + QTRY_COMPARE(dataChangedSpy.count(), 1); QCOMPARE(searchChangedSpy.count(), 0); QCOMPARE(selectionChangedSpy.count(), 0); QCOMPARE(changedSpy.count(), 1); @@ -296,6 +326,11 @@ void tst_QClipboard::setMimeData() QSignalSpy spySelection(QGuiApplication::clipboard(), SIGNAL(selectionChanged())); QSignalSpy spyData(QGuiApplication::clipboard(), SIGNAL(dataChanged())); + // Clipboard notifications are asynchronous with the new AddClipboardFormatListener + // in Windows Vista (5.4). Eat away all signals to ensure they don't interfere + // with the QTRY_COMPARE below. + EatSignalSpyNotificationsPredicate noLeftOverDataChanges(spyData); + QTRY_VERIFY(noLeftOverDataChanges); QSignalSpy spyFindBuffer(QGuiApplication::clipboard(), SIGNAL(findBufferChanged())); QGuiApplication::clipboard()->clear(QClipboard::Clipboard); @@ -312,7 +347,7 @@ void tst_QClipboard::setMimeData() else QCOMPARE(spyFindBuffer.count(), 0); - QCOMPARE(spyData.count(), 1); + QTRY_COMPARE(spyData.count(), 1); // an other crash test data = new QMimeData; @@ -326,7 +361,8 @@ void tst_QClipboard::setMimeData() newData->setText("bar"); spySelection.clear(); - spyData.clear(); + noLeftOverDataChanges.reset(); + QTRY_VERIFY(noLeftOverDataChanges); spyFindBuffer.clear(); QGuiApplication::clipboard()->setMimeData(newData, QClipboard::Clipboard); @@ -343,7 +379,7 @@ void tst_QClipboard::setMimeData() else QCOMPARE(spyFindBuffer.count(), 0); - QCOMPARE(spyData.count(), 1); + QTRY_COMPARE(spyData.count(), 1); } void tst_QClipboard::clearBeforeSetText() diff --git a/tests/auto/gui/kernel/qguiapplication/icons/appicon.png b/tests/auto/gui/kernel/qguiapplication/icons/appicon.png Binary files differnew file mode 100644 index 0000000000..b5d3ecbddf --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/icons/appicon.png diff --git a/tests/auto/gui/kernel/qguiapplication/icons/usericon.png b/tests/auto/gui/kernel/qguiapplication/icons/usericon.png Binary files differnew file mode 100644 index 0000000000..8d703640c1 --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/icons/usericon.png diff --git a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro index cd363bab31..895c2a0307 100644 --- a/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro +++ b/tests/auto/gui/kernel/qguiapplication/qguiapplication.pro @@ -7,3 +7,5 @@ INCLUDEPATH += $$CORE_TEST_PATH TARGET = tst_qguiapplication QT += gui-private SOURCES += tst_qguiapplication.cpp + +RESOURCES = tst_qguiapplication.qrc diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp index e551d99959..e1cdb8db45 100644 --- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp @@ -65,6 +65,7 @@ class tst_QGuiApplication: public tst_QCoreApplication private slots: void displayName(); void firstWindowTitle(); + void windowIcon(); void focusObject(); void allWindows(); void topLevelWindows(); @@ -99,6 +100,24 @@ void tst_QGuiApplication::firstWindowTitle() QCOMPARE(window.title(), QString("User Title")); } +void tst_QGuiApplication::windowIcon() +{ + int argc = 3; + char *argv[] = { const_cast<char*>("tst_qguiapplication"), const_cast<char*>("-qwindowicon"), const_cast<char*>(":/icons/usericon.png") }; + QGuiApplication app(argc, argv); + QIcon appIcon(":/icons/appicon.png"); + app.setWindowIcon(appIcon); + + QWindow window; + window.show(); + + QIcon userIcon(":/icons/usericon.png"); + // Comparing icons is hard. cacheKey() differs because the icon was independently loaded. + // So we use availableSizes, after making sure that the app and user icons do have different sizes. + QVERIFY(userIcon.availableSizes() != appIcon.availableSizes()); + QCOMPARE(window.icon().availableSizes(), userIcon.availableSizes()); +} + class DummyWindow : public QWindow { public: diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc new file mode 100644 index 0000000000..b26fba37b9 --- /dev/null +++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource prefix="/"> + <file>icons/usericon.png</file> + <file>icons/appicon.png</file> +</qresource> +</RCC> diff --git a/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro new file mode 100644 index 0000000000..970e5c7c2d --- /dev/null +++ b/tests/auto/gui/kernel/qpixelformat/qpixelformat.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +TARGET = tst_qpixelformat + +QT += gui testlib + +SOURCES += tst_qpixelformat.cpp diff --git a/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp new file mode 100644 index 0000000000..c3b19a3b44 --- /dev/null +++ b/tests/auto/gui/kernel/qpixelformat/tst_qpixelformat.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** 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. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtTest/QtTest> + +#include <QtGui/qpixelformat.h> + +class tst_QPixelFormat : public QObject +{ + Q_OBJECT + +private slots: + void testOperators(); + void testQVectorOfFormats(); + void testRGB(); + void testCMYK(); + void testHSLandHSV(); + void testYUV_data(); + void testYUV(); + void testEnums(); +}; + +void tst_QPixelFormat::testOperators() +{ + QPixelFormat first = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied); + QPixelFormat second = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtBeginning, QPixelFormat::Premultiplied); + QVERIFY(first == second); + + QPixelFormat third = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha, QPixelFormat::AtEnd, QPixelFormat::NotPremultiplied); + QVERIFY(first != third); +} + +void tst_QPixelFormat::testQVectorOfFormats() +{ + QVector<QPixelFormat> reallocedVector; + QVector<QPixelFormat> reservedVector; + reservedVector.reserve(QImage::NImageFormats); + for (int i = 0; i < QImage::NImageFormats; i++) { + if (i == 0 || i == 2) // skip invalid and monolsb + continue; + QImage::Format image_format = static_cast<QImage::Format>(i); + QPixelFormat format = QImage::toPixelFormat(image_format); + reallocedVector.append(format); + reservedVector.append(format); + } + + for (int i = 0; i < reallocedVector.size(); i++) { + QCOMPARE(reallocedVector.at(i), reservedVector.at(i)); + } +} + +void tst_QPixelFormat::testRGB() +{ + QPixelFormat argb8888 = QPixelFormatRgb(8,8,8,8,QPixelFormat::UsesAlpha,QPixelFormat::AtBeginning, QPixelFormat::Premultiplied); + QCOMPARE(argb8888.redSize(), uchar(8)); + QCOMPARE(argb8888.greenSize(), uchar(8)); + QCOMPARE(argb8888.blueSize(), uchar(8)); + QCOMPARE(argb8888.alphaSize(), uchar(8)); + + QPixelFormat rgb565 = QPixelFormatRgb(5,6,5,0,QPixelFormat::IgnoresAlpha,QPixelFormat::AtBeginning, QPixelFormat::NotPremultiplied); + QCOMPARE(rgb565.redSize(), uchar(5)); + QCOMPARE(rgb565.greenSize(), uchar(6)); + QCOMPARE(rgb565.blueSize(), uchar(5)); + QCOMPARE(rgb565.alphaSize(), uchar(0)); + QCOMPARE(rgb565.bitsPerPixel(), uchar(16)); + + QPixelFormat rgba1235 = QPixelFormatRgb(1,2,3,5,QPixelFormat::IgnoresAlpha, QPixelFormat::AtEnd, QPixelFormat::Premultiplied); + QCOMPARE(rgba1235.redSize(), uchar(1)); + QCOMPARE(rgba1235.greenSize(), uchar(2)); + QCOMPARE(rgba1235.blueSize(), uchar(3)); + QCOMPARE(rgba1235.alphaSize(), uchar(5)); + QCOMPARE(rgba1235.bitsPerPixel(), uchar(1 + 2 + 3 + 5)); +} + +void tst_QPixelFormat::testCMYK() +{ + QPixelFormat cmyk6 = QPixelFormatCmyk(6); + QCOMPARE(cmyk6.cyanSize(), uchar(6)); + QCOMPARE(cmyk6.magentaSize(), uchar(6)); + QCOMPARE(cmyk6.yellowSize(), uchar(6)); + QCOMPARE(cmyk6.blackSize(), uchar(6)); + QCOMPARE(cmyk6.bitsPerPixel(), uchar(6*4)); + + QPixelFormat cmykWithAlpha = QPixelFormatCmyk(8,8); + QCOMPARE(cmykWithAlpha.bitsPerPixel(), uchar(8*5)); +} +void tst_QPixelFormat::testHSLandHSV() +{ + QPixelFormat hsl = QPixelFormatHsl(3,5); + + QCOMPARE(hsl.hueSize(), uchar(3)); + QCOMPARE(hsl.saturationSize(), uchar(3)); + QCOMPARE(hsl.lightnessSize(), uchar(3)); + QCOMPARE(hsl.bitsPerPixel(), uchar(3 * 3 + 5)); + + QPixelFormat hsv = QPixelFormatHsv(5,7); + + QCOMPARE(hsv.hueSize(), uchar(5)); + QCOMPARE(hsv.saturationSize(), uchar(5)); + QCOMPARE(hsv.brightnessSize(), uchar(5)); + QCOMPARE(hsv.bitsPerPixel(), uchar(5 * 3 + 7)); +} + +Q_DECLARE_METATYPE(QPixelFormat::YUVLayout) +void tst_QPixelFormat::testYUV_data() +{ + QTest::addColumn<QPixelFormat::YUVLayout>("yuv_layout"); + QTest::newRow("YUV Layout YUV444") << QPixelFormat::YUV444; + QTest::newRow("YUV Layout YUV422") << QPixelFormat::YUV422; + QTest::newRow("YUV Layout YUV411") << QPixelFormat::YUV411; + QTest::newRow("YUV Layout YUV420P") << QPixelFormat::YUV420P; + QTest::newRow("YUV Layout YUV420SP") << QPixelFormat::YUV420SP; + QTest::newRow("YUV Layout YV12") << QPixelFormat::YV12; + QTest::newRow("YUV Layout UYVY") << QPixelFormat::UYVY; + QTest::newRow("YUV Layout YUYV") << QPixelFormat::YUYV; + QTest::newRow("YUV Layout NV12") << QPixelFormat::NV12; + QTest::newRow("YUV Layout NV21") << QPixelFormat::NV21; + QTest::newRow("YUV Layout IMC1") << QPixelFormat::IMC1; + QTest::newRow("YUV Layout IMC2") << QPixelFormat::IMC2; + QTest::newRow("YUV Layout IMC3") << QPixelFormat::IMC3; + QTest::newRow("YUV Layout IMC4") << QPixelFormat::IMC4; + QTest::newRow("YUV Layout Y8") << QPixelFormat::Y8; + QTest::newRow("YUV Layout Y16") << QPixelFormat::Y16; +} + +void tst_QPixelFormat::testYUV() +{ + QFETCH(QPixelFormat::YUVLayout, yuv_layout); + + QPixelFormat format = QPixelFormatYuv(yuv_layout, 0); + + switch (yuv_layout) { + case QPixelFormat::YUV444: + QCOMPARE(format.bitsPerPixel(), uchar(24)); + break; + case QPixelFormat::YUV422: + QCOMPARE(format.bitsPerPixel(), uchar(16)); + break; + case QPixelFormat::YUV411: + case QPixelFormat::YUV420P: + case QPixelFormat::YUV420SP: + case QPixelFormat::YV12: + QCOMPARE(format.bitsPerPixel(), uchar(12)); + break; + case QPixelFormat::UYVY: + case QPixelFormat::YUYV: + QCOMPARE(format.bitsPerPixel(), uchar(16)); + break; + case QPixelFormat::NV12: + case QPixelFormat::NV21: + QCOMPARE(format.bitsPerPixel(), uchar(12)); + break; + case QPixelFormat::IMC1: + case QPixelFormat::IMC2: + case QPixelFormat::IMC3: + case QPixelFormat::IMC4: + QCOMPARE(format.bitsPerPixel(), uchar(12)); + break; + case QPixelFormat::Y8: + QCOMPARE(format.bitsPerPixel(), uchar(8)); + break; + case QPixelFormat::Y16: + QCOMPARE(format.bitsPerPixel(), uchar(16)); + break; + default: + QVERIFY(!"the value stored for the yuvLayout is wrong!"); + } + +} + +void tst_QPixelFormat::testEnums() +{ + QPixelFormat allSet = QPixelFormat(QPixelFormat::BGR,1,2,3,4,5,6, + QPixelFormat::UsesAlpha, + QPixelFormat::AtEnd, + QPixelFormat::Premultiplied, + QPixelFormat::FloatingPoint, + QPixelFormat::BigEndian, + (1 << 6) - 1); + + QCOMPARE(allSet.alphaUsage(), QPixelFormat::UsesAlpha); + QCOMPARE(allSet.alphaPosition(), QPixelFormat::AtEnd); + QCOMPARE(allSet.premultiplied(), QPixelFormat::Premultiplied); + QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian); + QCOMPARE(allSet.typeInterpretation(), QPixelFormat::FloatingPoint); + QCOMPARE(allSet.byteOrder(), QPixelFormat::BigEndian); + QCOMPARE(allSet.subEnum(), uchar(63)); + + QPixelFormat nonSet = QPixelFormat(QPixelFormat::RGB,6,5,4,3,2,1, + QPixelFormat::IgnoresAlpha, + QPixelFormat::AtBeginning, + QPixelFormat::NotPremultiplied, + QPixelFormat::UnsignedInteger, + QPixelFormat::LittleEndian); + + QCOMPARE(nonSet.alphaUsage(), QPixelFormat::IgnoresAlpha); + QCOMPARE(nonSet.alphaPosition(), QPixelFormat::AtBeginning); + QCOMPARE(nonSet.premultiplied(), QPixelFormat::NotPremultiplied); + QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian); + QCOMPARE(nonSet.typeInterpretation(), QPixelFormat::UnsignedInteger); + QCOMPARE(nonSet.byteOrder(), QPixelFormat::LittleEndian); + QCOMPARE(nonSet.subEnum(), uchar(0)); +} + +#include <tst_qpixelformat.moc> +QTEST_MAIN(tst_QPixelFormat); |