summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp')
-rw-r--r--tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp111
1 files changed, 53 insertions, 58 deletions
diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
index 42af0dea2c..30366c6aa1 100644
--- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
+++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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 The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -46,8 +21,9 @@
#ifdef Q_OS_WIN
# include <QtGui/private/qguiapplication_p.h>
-# include <QtGui/private/qwindowsmime_p.h>
+# include <QtGui/qwindowsmimeconverter.h>
# include <QtGui/qpa/qplatformintegration.h>
+# include <QtCore/qt_windows.h>
#endif
class tst_QClipboard : public QObject
@@ -66,6 +42,7 @@ private slots:
void testSignals();
void setMimeData();
void clearBeforeSetText();
+ void getTextFromHTMLMimeType();
# ifdef Q_OS_WIN
void testWindowsMimeRegisterType();
void testWindowsMime_data();
@@ -86,7 +63,7 @@ void tst_QClipboard::initTestCase()
#if QT_CONFIG(clipboard)
void tst_QClipboard::init()
{
-#if QT_CONFIG(process)
+#if QT_CONFIG(process) && !defined(Q_OS_ANDROID)
const QString testdataDir = QFileInfo(QFINDTESTDATA("copier")).absolutePath();
QVERIFY2(QDir::setCurrent(testdataDir), qPrintable("Could not chdir to " + testdataDir));
#endif
@@ -149,7 +126,7 @@ public:
operator bool() const
{
- if (m_timer.elapsed() && !m_spy.count())
+ if (m_timer.elapsed() && !m_spy.size())
return true;
m_spy.clear();
return false;
@@ -191,11 +168,11 @@ void tst_QClipboard::testSignals()
// Test the default mode signal.
clipboard->setText(text);
- QTRY_COMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(searchChangedSpy.count(), 0);
- QCOMPARE(selectionChangedSpy.count(), 0);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QTRY_COMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(searchChangedSpy.size(), 0);
+ QCOMPARE(selectionChangedSpy.size(), 0);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Clipboard);
changedSpy.clear();
@@ -203,29 +180,29 @@ void tst_QClipboard::testSignals()
// Test the selection mode signal.
if (clipboard->supportsSelection()) {
clipboard->setText(text, QClipboard::Selection);
- QCOMPARE(selectionChangedSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(selectionChangedSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::Selection);
} else {
- QCOMPARE(selectionChangedSpy.count(), 0);
+ QCOMPARE(selectionChangedSpy.size(), 0);
}
- QCOMPARE(dataChangedSpy.count(), 1);
- QCOMPARE(searchChangedSpy.count(), 0);
+ QCOMPARE(dataChangedSpy.size(), 1);
+ QCOMPARE(searchChangedSpy.size(), 0);
changedSpy.clear();
// Test the search mode signal.
if (clipboard->supportsFindBuffer()) {
clipboard->setText(text, QClipboard::FindBuffer);
- QCOMPARE(searchChangedSpy.count(), 1);
- QCOMPARE(changedSpy.count(), 1);
- QCOMPARE(changedSpy.at(0).count(), 1);
+ QCOMPARE(searchChangedSpy.size(), 1);
+ QCOMPARE(changedSpy.size(), 1);
+ QCOMPARE(changedSpy.at(0).size(), 1);
QCOMPARE(qvariant_cast<QClipboard::Mode>(changedSpy.at(0).at(0)), QClipboard::FindBuffer);
} else {
- QCOMPARE(searchChangedSpy.count(), 0);
+ QCOMPARE(searchChangedSpy.size(), 0);
}
- QCOMPARE(dataChangedSpy.count(), 1);
+ QCOMPARE(dataChangedSpy.size(), 1);
}
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_QNX)
@@ -365,16 +342,16 @@ void tst_QClipboard::setMimeData()
QGuiApplication::clipboard()->clear(QClipboard::FindBuffer);
if (QGuiApplication::clipboard()->supportsSelection())
- QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spySelection.size(), 1);
else
- QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spySelection.size(), 0);
if (QGuiApplication::clipboard()->supportsFindBuffer())
- QCOMPARE(spyFindBuffer.count(), 1);
+ QCOMPARE(spyFindBuffer.size(), 1);
else
- QCOMPARE(spyFindBuffer.count(), 0);
+ QCOMPARE(spyFindBuffer.size(), 0);
- QTRY_COMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.size(), 1);
// an other crash test
data = new QMimeData;
@@ -401,16 +378,16 @@ void tst_QClipboard::setMimeData()
QGuiApplication::clipboard()->setMimeData(newData, QClipboard::FindBuffer);
if (QGuiApplication::clipboard()->supportsSelection())
- QCOMPARE(spySelection.count(), 1);
+ QCOMPARE(spySelection.size(), 1);
else
- QCOMPARE(spySelection.count(), 0);
+ QCOMPARE(spySelection.size(), 0);
if (QGuiApplication::clipboard()->supportsFindBuffer())
- QCOMPARE(spyFindBuffer.count(), 1);
+ QCOMPARE(spyFindBuffer.size(), 1);
else
- QCOMPARE(spyFindBuffer.count(), 0);
+ QCOMPARE(spyFindBuffer.size(), 0);
- QTRY_COMPARE(spyData.count(), 1);
+ QTRY_COMPARE(spyData.size(), 1);
}
void tst_QClipboard::clearBeforeSetText()
@@ -449,12 +426,30 @@ void tst_QClipboard::clearBeforeSetText()
QCOMPARE(QGuiApplication::clipboard()->text(), text);
}
+void tst_QClipboard::getTextFromHTMLMimeType()
+{
+ QClipboard * clipboard = QGuiApplication::clipboard();
+ QMimeData * mimeData = new QMimeData();
+ const QString testString("TEST");
+ const QString htmlString(QLatin1String("<html><body>") + testString + QLatin1String("</body></html>"));
+
+ mimeData->setText(testString);
+ mimeData->setHtml(htmlString);
+ clipboard->setMimeData(mimeData);
+
+ QCOMPARE(clipboard->text(), testString);
+ QVERIFY(clipboard->mimeData()->hasText());
+ QVERIFY(clipboard->mimeData()->hasHtml());
+ QCOMPARE(clipboard->mimeData()->text(), testString);
+ QCOMPARE(clipboard->mimeData()->html(), htmlString);
+}
+
# ifdef Q_OS_WIN
-using QWindowsMime = QNativeInterface::Private::QWindowsMime;
+using QWindowsMimeConverter = QWindowsMimeConverter;
using QWindowsApplication = QNativeInterface::Private::QWindowsApplication;
-class TestMime : public QWindowsMime
+class TestMime : public QWindowsMimeConverter
{
public:
bool canConvertFromMime(const FORMATETC &, const QMimeData *) const override