diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-28 06:11:31 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-07-28 13:20:23 +0200 |
commit | 2405aa9d6797dcfb2e47f45f113ee1ebbc201dda (patch) | |
tree | ea2b49501545cc98d63304b2751c2840bcf1dffd /tests | |
parent | 904eaec9de3ed9efd446f2ef83c15055d2b2a871 (diff) |
Windows QPA: Move mime-type related classes to the new interface
Move QWindowsMime (which was a public class in Qt 4 and moved to the QPA
plugin in Qt 5) to the platform namespace and add register functions to the
native application.
Move in test code from QtWinExtras.
Task-number: QTBUG-83252
Change-Id: Iaac440e2d5cb370110919921b1eeb779600b5b65
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/test/test.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp | 102 |
3 files changed, 103 insertions, 2 deletions
diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt index dfacb03517..1e2c89e538 100644 --- a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt @@ -10,6 +10,7 @@ qt_add_test(tst_qclipboard ../tst_qclipboard.cpp PUBLIC_LIBRARIES Qt::Gui + Qt::GuiPrivate ) ## Scopes: diff --git a/tests/auto/gui/kernel/qclipboard/test/test.pro b/tests/auto/gui/kernel/qclipboard/test/test.pro index 3a4ed3a7bc..8ccdecd405 100644 --- a/tests/auto/gui/kernel/qclipboard/test/test.pro +++ b/tests/auto/gui/kernel/qclipboard/test/test.pro @@ -1,7 +1,7 @@ CONFIG += testcase SOURCES += ../tst_qclipboard.cpp TARGET = ../tst_qclipboard -QT += testlib +QT += testlib gui-private osx: LIBS += -framework AppKit diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp index d6ce37438b..d4917899db 100644 --- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp +++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp @@ -31,12 +31,20 @@ #include <QtCore/QDebug> #include <QtCore/QFileInfo> #include <QtCore/QDir> +#include <QtCore/QVariant> #include <QtGui/QGuiApplication> #include <QtGui/QClipboard> #include <QtGui/QImage> +#include <QtGui/QPixmap> #include <QtGui/QColor> #include "../../../shared/platformclipboard.h" +#ifdef Q_OS_WIN +# include <QtGui/private/qguiapplication_p.h> +# include <QtGui/private/qwindowsmime_p.h> +# include <QtGui/qpa/qplatformintegration.h> +#endif + class tst_QClipboard : public QObject { Q_OBJECT @@ -53,7 +61,12 @@ private slots: void testSignals(); void setMimeData(); void clearBeforeSetText(); -#endif +# ifdef Q_OS_WIN + void testWindowsMimeRegisterType(); + void testWindowsMime_data(); + void testWindowsMime(); +# endif // Q_OS_WIN +#endif // clipboard }; void tst_QClipboard::initTestCase() @@ -431,6 +444,93 @@ void tst_QClipboard::clearBeforeSetText() QCOMPARE(QGuiApplication::clipboard()->text(), text); } +# ifdef Q_OS_WIN + +using QWindowsMime = QPlatformInterface::Private::QWindowsMime; +using QWindowsApplication = QPlatformInterface::Private::QWindowsApplication; + +class TestMime : public QWindowsMime +{ +public: + bool canConvertFromMime(const FORMATETC &, const QMimeData *) const override + { + return false; + } + + bool convertFromMime(const FORMATETC &, const QMimeData *, STGMEDIUM *) const override + { + return false; + } + + QList<FORMATETC> formatsForMime(const QString &, const QMimeData *) const override + { + formatsForMimeCalled = true; + return {}; + } + + bool canConvertToMime(const QString &, IDataObject *) const override + { + return false; + } + + QVariant convertToMime(const QString &, IDataObject *, QVariant::Type) const override + { + return QVariant(); + } + + QString mimeForFormat(const FORMATETC &) const override + { + return {}; + } + + mutable bool formatsForMimeCalled = false; +}; + +void tst_QClipboard::testWindowsMimeRegisterType() +{ + auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()); + QVERIFY(nativeWindowsApp); + const int type = nativeWindowsApp->registerMimeType("foo/bar"); + QVERIFY2(type >= 0, QByteArray::number(type)); +} + +void tst_QClipboard::testWindowsMime_data() +{ + QTest::addColumn<QVariant>("data"); + QTest::newRow("string") << QVariant(QStringLiteral("bla")); + QPixmap pm(10, 10); + pm.fill(Qt::black); + QTest::newRow("pixmap") << QVariant(pm); +} + +void tst_QClipboard::testWindowsMime() +{ + QFETCH(QVariant, data); + // Basic smoke test for crashes, copy some text into clipboard and check whether + // the test implementation is called. + TestMime testMime; + auto nativeWindowsApp = dynamic_cast<QWindowsApplication *>(QGuiApplicationPrivate::platformIntegration()); + QVERIFY(nativeWindowsApp); + nativeWindowsApp->registerMime(&testMime); + + auto clipboard = QGuiApplication::clipboard(); + switch (data.type()) { + case QVariant::String: + clipboard->setText(data.toString()); + break; + case QVariant::Pixmap: + clipboard->setPixmap(data.value<QPixmap>()); + break; + default: + break; + } + QTRY_VERIFY(testMime.formatsForMimeCalled); + + nativeWindowsApp->unregisterMime(&testMime); +} + +# endif // Q_OS_WIN + #endif // QT_CONFIG(clipboard) QTEST_MAIN(tst_QClipboard) |