diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-05-06 17:24:23 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-15 15:31:07 +0200 |
commit | 6a61a00ddb21e79412e82069dfef50192bfd724d (patch) | |
tree | e922d83a1d27c4a00390d4f0e2a6c4b459c5a544 /tests/auto | |
parent | f618dbdd04d1efa087dfa9a5aa792c315a5bc500 (diff) |
Windows: Use new clipboard API for listening to changes.
The currently used clipboard chain API has various problems with non-
responsive applications and requires checks for hung/debugged applications when
sending on notifications.
The new clipboard format listener API available from Windows Vista onwards
requires less code and does not have these problems, however the change
notifications now arrive asynchronously.
Change the tst_qclipboard to be able to deal with asynchronous change
notifications.
Task-number: QTBUG-38670
Task-number: QTBUG-33492
Change-Id: I3c49e346a34310431c20f3051d12eaabf330a3ad
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
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() |