diff options
Diffstat (limited to 'tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp | 79 |
1 files changed, 71 insertions, 8 deletions
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp index cf786c1dca..b677ee1ea4 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. @@ -46,6 +46,8 @@ #include <QtCore/QDir> #include <QtGui/QGuiApplication> #include <QtGui/QClipboard> +#include <QtGui/QImage> +#include <QtGui/QColor> #include "../../../shared/platformclipboard.h" class tst_QClipboard : public QObject @@ -59,6 +61,7 @@ private slots: void init(); #if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_QNX) void copy_exit_paste(); + void copyImage(); #endif void capabilityFunctions(); void modes(); @@ -134,6 +137,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 +175,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 +189,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); @@ -248,18 +281,42 @@ void tst_QClipboard::copy_exit_paste() // ### It's still possible to test copy/paste - just keep the apps running if (!PlatformClipboard::isAvailable()) QSKIP("Native clipboard not working in this setup"); - const QStringList stringArgument(QStringLiteral("Test string.")); + const QString stringArgument(QStringLiteral("Test string.")); QByteArray errorMessage; - QVERIFY2(runHelper(QStringLiteral("copier/copier"), stringArgument, &errorMessage), + QVERIFY2(runHelper(QStringLiteral("copier/copier"), QStringList(stringArgument), &errorMessage), errorMessage.constData()); #ifdef Q_OS_MAC // The Pasteboard needs a moment to breathe (at least on older Macs). QTest::qWait(100); #endif // Q_OS_MAC - QVERIFY2(runHelper(QStringLiteral("paster/paster"), stringArgument, &errorMessage), + QVERIFY2(runHelper(QStringLiteral("paster/paster"), + QStringList() << QStringLiteral("--text") << stringArgument, + &errorMessage), errorMessage.constData()); #endif // QT_NO_PROCESS } + +void tst_QClipboard::copyImage() +{ +#ifndef QT_NO_PROCESS + if (!PlatformClipboard::isAvailable()) + QSKIP("Native clipboard not working in this setup"); + QImage image(100, 100, QImage::Format_ARGB32); + image.fill(QColor(Qt::transparent)); + image.setPixel(QPoint(1, 0), QColor(Qt::blue).rgba()); + QGuiApplication::clipboard()->setImage(image); +#ifdef Q_OS_OSX + // The Pasteboard needs a moment to breathe (at least on older Macs). + QTest::qWait(100); +#endif // Q_OS_OSX + // paster will perform hard-coded checks on the copied image. + QByteArray errorMessage; + QVERIFY2(runHelper(QStringLiteral("paster/paster"), + QStringList(QStringLiteral("--image")), &errorMessage), + errorMessage.constData()); +#endif // QT_NO_PROCESS +} + #endif // Q_OS_WIN || Q_OS_MAC || Q_OS_QNX void tst_QClipboard::setMimeData() @@ -296,6 +353,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 +374,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 +388,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 +406,7 @@ void tst_QClipboard::setMimeData() else QCOMPARE(spyFindBuffer.count(), 0); - QCOMPARE(spyData.count(), 1); + QTRY_COMPARE(spyData.count(), 1); } void tst_QClipboard::clearBeforeSetText() |