diff options
Diffstat (limited to 'tests/auto/gui/kernel/qclipboard')
15 files changed, 93 insertions, 236 deletions
diff --git a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt index 05eba972d6..b7a0467758 100644 --- a/tests/auto/gui/kernel/qclipboard/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qclipboard.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qclipboard LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() add_subdirectory(copier) add_subdirectory(paster) diff --git a/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt deleted file mode 100644 index 69e313b1d1..0000000000 --- a/tests/auto/gui/kernel/qclipboard/copier/.prev_CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Generated from copier.pro. - -##################################################################### -## copier Binary: -##################################################################### - -qt_internal_add_executable(copier - SOURCES - main.cpp - PUBLIC_LIBRARIES - Qt::Gui -) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:copier.pro:WIN32: -# DESTDIR = "../copier" diff --git a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt index ef599b121e..ea7def8c0d 100644 --- a/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/copier/CMakeLists.txt @@ -1,23 +1,16 @@ -# Generated from copier.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## copier Binary: ##################################################################### -# special case begin set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -# special case end qt_internal_add_executable(copier - ${args} # special case + ${args} SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:copier.pro:WIN32: -# DESTDIR = "../copier" diff --git a/tests/auto/gui/kernel/qclipboard/copier/copier.pro b/tests/auto/gui/kernel/qclipboard/copier/copier.pro deleted file mode 100644 index def50b6476..0000000000 --- a/tests/auto/gui/kernel/qclipboard/copier/copier.pro +++ /dev/null @@ -1,4 +0,0 @@ -CONFIG -= app_bundle -win32: DESTDIR = ../copier - -SOURCES += main.cpp diff --git a/tests/auto/gui/kernel/qclipboard/copier/main.cpp b/tests/auto/gui/kernel/qclipboard/copier/main.cpp index 32e91a9939..362ede38b7 100644 --- a/tests/auto/gui/kernel/qclipboard/copier/main.cpp +++ b/tests/auto/gui/kernel/qclipboard/copier/main.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 <QtGui/QGuiApplication> #include <QtGui/QClipboard> #include <QtCore/QStringList> diff --git a/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt deleted file mode 100644 index fa0b9bc4a6..0000000000 --- a/tests/auto/gui/kernel/qclipboard/paster/.prev_CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Generated from paster.pro. - -##################################################################### -## paster Binary: -##################################################################### - -qt_internal_add_executable(paster - SOURCES - main.cpp - PUBLIC_LIBRARIES - Qt::Gui -) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:paster.pro:WIN32: -# DESTDIR = "../paster" diff --git a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt index 571ae4944e..9bc1985ee4 100644 --- a/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/paster/CMakeLists.txt @@ -1,23 +1,16 @@ -# Generated from paster.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## paster Binary: ##################################################################### -# special case begin set(args OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") -# special case end qt_internal_add_executable(paster - ${args} # special case + ${args} SOURCES main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui ) - -## Scopes: -##################################################################### - -#### Keys ignored in scope 2:.:.:paster.pro:WIN32: -# DESTDIR = "../paster" diff --git a/tests/auto/gui/kernel/qclipboard/paster/main.cpp b/tests/auto/gui/kernel/qclipboard/paster/main.cpp index 7fca8af1cb..bf47b10ba6 100644 --- a/tests/auto/gui/kernel/qclipboard/paster/main.cpp +++ b/tests/auto/gui/kernel/qclipboard/paster/main.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 <QtGui/QGuiApplication> #include <QtGui/QClipboard> #include <QtGui/QImage> diff --git a/tests/auto/gui/kernel/qclipboard/paster/paster.pro b/tests/auto/gui/kernel/qclipboard/paster/paster.pro deleted file mode 100644 index ef91e77b6e..0000000000 --- a/tests/auto/gui/kernel/qclipboard/paster/paster.pro +++ /dev/null @@ -1,4 +0,0 @@ -win32: DESTDIR = ../paster -CONFIG -= app_bundle - -SOURCES += main.cpp diff --git a/tests/auto/gui/kernel/qclipboard/qclipboard.pro b/tests/auto/gui/kernel/qclipboard/qclipboard.pro deleted file mode 100644 index d97c58dea0..0000000000 --- a/tests/auto/gui/kernel/qclipboard/qclipboard.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = copier paster -test.depends += $$SUBDIRS -SUBDIRS += test diff --git a/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt deleted file mode 100644 index 0e9fa8f40d..0000000000 --- a/tests/auto/gui/kernel/qclipboard/test/.prev_CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# Generated from test.pro. - -##################################################################### -## tst_qclipboard Test: -##################################################################### - -qt_internal_add_test(tst_qclipboard - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" - SOURCES - ../tst_qclipboard.cpp - PUBLIC_LIBRARIES - Qt::Gui - Qt::GuiPrivate -) - -## Scopes: -##################################################################### - -qt_internal_extend_target(tst_qclipboard CONDITION MACOS - PUBLIC_LIBRARIES - ${FWAppKit} -) - -#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID: -# TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster" diff --git a/tests/auto/gui/kernel/qclipboard/test/BLACKLIST b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST new file mode 100644 index 0000000000..3ca7791b37 --- /dev/null +++ b/tests/auto/gui/kernel/qclipboard/test/BLACKLIST @@ -0,0 +1,5 @@ +# QTBUG-87429 +[testSignals] +android +[setMimeData] +android diff --git a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt index 0e9fa8f40d..fad30c16fd 100644 --- a/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt +++ b/tests/auto/gui/kernel/qclipboard/test/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from test.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qclipboard Test: @@ -8,7 +9,7 @@ qt_internal_add_test(tst_qclipboard OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_qclipboard.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::GuiPrivate ) @@ -17,9 +18,8 @@ qt_internal_add_test(tst_qclipboard ##################################################################### qt_internal_extend_target(tst_qclipboard CONDITION MACOS - PUBLIC_LIBRARIES + LIBRARIES ${FWAppKit} ) -#### Keys ignored in scope 6:.:.:test.pro:NOT ANDROID: # TEST_HELPER_INSTALLS = "../copier/copier" "../paster/paster" diff --git a/tests/auto/gui/kernel/qclipboard/test/test.pro b/tests/auto/gui/kernel/qclipboard/test/test.pro deleted file mode 100644 index 8ccdecd405..0000000000 --- a/tests/auto/gui/kernel/qclipboard/test/test.pro +++ /dev/null @@ -1,18 +0,0 @@ -CONFIG += testcase -SOURCES += ../tst_qclipboard.cpp -TARGET = ../tst_qclipboard -QT += testlib gui-private - -osx: LIBS += -framework AppKit - -win32 { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qclipboard -} else { - TARGET = ../../release/tst_qclipboard - } -} - -!android: TEST_HELPER_INSTALLS = \ - ../copier/copier \ - ../paster/paster diff --git a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp index 790b53ff9f..30366c6aa1 100644 --- a/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp +++ b/tests/auto/gui/kernel/qclipboard/tst_qclipboard.cpp @@ -1,33 +1,13 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> +#include <QMimeData> +#include <QSignalSpy> +#if QT_CONFIG(process) +#include <QProcess> +#endif #include <QtCore/QDebug> #include <QtCore/QFileInfo> #include <QtCore/QDir> @@ -41,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 @@ -61,6 +42,7 @@ private slots: void testSignals(); void setMimeData(); void clearBeforeSetText(); + void getTextFromHTMLMimeType(); # ifdef Q_OS_WIN void testWindowsMimeRegisterType(); void testWindowsMime_data(); @@ -81,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 @@ -144,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; @@ -186,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(); @@ -198,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) @@ -360,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; @@ -396,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() @@ -444,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 @@ -514,11 +514,11 @@ void tst_QClipboard::testWindowsMime() nativeWindowsApp->registerMime(&testMime); auto clipboard = QGuiApplication::clipboard(); - switch (data.type()) { - case QVariant::String: + switch (data.metaType().id()) { + case QMetaType::QString: clipboard->setText(data.toString()); break; - case QVariant::Pixmap: + case QMetaType::QPixmap: clipboard->setPixmap(data.value<QPixmap>()); break; default: |