aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-06-13 14:14:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@digia.com>2014-06-16 16:13:07 +0200
commitb7e905eaa8769c7a4e21c43f20fb995bcd19d0ba (patch)
tree45cdc50ff29ba77eee9d599a1557e24896d95860 /tests
parentf2a0dbe9128d5fd6caa8711b8b7495eba570ba63 (diff)
Add QWinMime.
Add class QWinMime (equivalent to WindowsMime in Qt 4). [ChangeLog][QWinMime] Added abstract class QWinMime (equivalent to WindowsMime in Qt 4) for registering custom mime type conversions. Task-number: QTBUG-39559 Change-Id: Ie8ff4db6cd0ce64f65b83232dc91d771238663d1 Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro3
-rw-r--r--tests/auto/qwinmime/qwinmime.pro4
-rw-r--r--tests/auto/qwinmime/tst_qwinmime.cpp150
3 files changed, 156 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 12456c8..1e5d1ba 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -6,4 +6,5 @@ SUBDIRS += \
qpixmap \
qwintaskbarbutton \
qwintaskbarprogress \
- qwinjumplist
+ qwinjumplist \
+ qwinmime
diff --git a/tests/auto/qwinmime/qwinmime.pro b/tests/auto/qwinmime/qwinmime.pro
new file mode 100644
index 0000000..9a1563a
--- /dev/null
+++ b/tests/auto/qwinmime/qwinmime.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qwinmime
+QT += testlib winextras widgets
+SOURCES += tst_qwinmime.cpp
diff --git a/tests/auto/qwinmime/tst_qwinmime.cpp b/tests/auto/qwinmime/tst_qwinmime.cpp
new file mode 100644
index 0000000..a91a972
--- /dev/null
+++ b/tests/auto/qwinmime/tst_qwinmime.cpp
@@ -0,0 +1,150 @@
+/****************************************************************************
+**
+** 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 <QWinMime>
+#include <QtTest/QtTest>
+#include <QtGui/QClipboard>
+#include <QtGui/QPixmap>
+#include <QtCore/QVariant>
+
+class TestMime : public QWinMime
+{
+public:
+ TestMime(bool verbose = false) : formatsForMimeCalled(false), m_verbose(verbose) {}
+
+ bool canConvertFromMime(const FORMATETC &, const QMimeData *mimeData) const Q_DECL_OVERRIDE
+ {
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO << mimeData->formats();
+ return false;
+ }
+
+ bool convertFromMime(const FORMATETC &, const QMimeData *, STGMEDIUM *) const Q_DECL_OVERRIDE
+ {
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO;
+ return false;
+ }
+
+ QVector<FORMATETC> formatsForMime(const QString &mimeType, const QMimeData *mimeData) const Q_DECL_OVERRIDE
+ {
+ formatsForMimeCalled = true;
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO << mimeType << mimeData->formats();
+ return QVector<FORMATETC>();
+ }
+
+ bool canConvertToMime(const QString &mimeType, IDataObject *) const Q_DECL_OVERRIDE
+ {
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO << mimeType;
+ return false;
+ }
+
+ QVariant convertToMime(const QString &mimeType, IDataObject *, QVariant::Type preferredType) const Q_DECL_OVERRIDE
+ {
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO << mimeType << preferredType;
+ return QVariant();
+ }
+
+ QString mimeForFormat(const FORMATETC &) const Q_DECL_OVERRIDE
+ {
+ if (m_verbose)
+ qDebug() << Q_FUNC_INFO;
+ return QString();
+ }
+
+ mutable bool formatsForMimeCalled;
+
+private:
+ const bool m_verbose;
+};
+
+class tst_QWinMime : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testRegisterType();
+ void testWinMime_data();
+ void testWinMime();
+};
+
+void tst_QWinMime::testRegisterType()
+{
+ const int type = QWinMime::registerMimeType("foo/bar");
+ QVERIFY2(type >= 0, QByteArray::number(type));
+}
+
+void tst_QWinMime::testWinMime_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_QWinMime::testWinMime()
+{
+ QFETCH(QVariant, data);
+ // Basic smoke test for crashes, copy some text into clipboard and check whether
+ // the test implementation is called.
+ TestMime testMime;
+ QClipboard *clipboard = QApplication::clipboard();
+ switch (data.type()) {
+ case QMetaType::QString:
+ clipboard->setText(data.toString());
+ break;
+ case QMetaType::QPixmap:
+ clipboard->setPixmap(data.value<QPixmap>());
+ break;
+ default:
+ break;
+ }
+ QTRY_VERIFY(testMime.formatsForMimeCalled);
+}
+
+QTEST_MAIN(tst_QWinMime)
+
+#include "tst_qwinmime.moc"