diff options
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/image/qpicture/tst_qpicture.cpp | 31 | ||||
-rw-r--r-- | tests/auto/gui/kernel/kernel.pro | 13 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiaction/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiaction/qguiaction.pro | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp | 210 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiactiongroup/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp | 235 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp | 26 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguishortcut/qguishortcut.pro | 4 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qguishortcut/tst_qguishortcut.cpp | 82 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp | 6 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qpalette/tst_qpalette.cpp | 89 | ||||
-rw-r--r-- | tests/auto/gui/painting/qcolor/tst_qcolor.cpp | 37 |
16 files changed, 690 insertions, 57 deletions
diff --git a/tests/auto/gui/image/qpicture/tst_qpicture.cpp b/tests/auto/gui/image/qpicture/tst_qpicture.cpp index ec6bb8dcee..6287960457 100644 --- a/tests/auto/gui/image/qpicture/tst_qpicture.cpp +++ b/tests/auto/gui/image/qpicture/tst_qpicture.cpp @@ -37,6 +37,8 @@ #include <qscreen.h> #include <limits.h> +#ifndef QT_NO_PICTURE + class tst_QPicture : public QObject { Q_OBJECT @@ -45,7 +47,6 @@ public: tst_QPicture(); private slots: - void getSetCheck(); void devType(); void paintingActive(); void boundingRect(); @@ -56,31 +57,6 @@ private slots: void boundaryValues(); }; -// Testing get/set functions -void tst_QPicture::getSetCheck() -{ - QPictureIO obj1; - // const QPicture & QPictureIO::picture() - // void QPictureIO::setPicture(const QPicture &) - // const char * QPictureIO::format() - // void QPictureIO::setFormat(const char *) - const char var2[] = "PNG"; - obj1.setFormat(var2); - QCOMPARE(var2, obj1.format()); - obj1.setFormat((char *)0); - // The format is stored internally in a QString, so return is always a valid char * - QVERIFY(QString(obj1.format()).isEmpty()); - - // const char * QPictureIO::parameters() - // void QPictureIO::setParameters(const char *) - const char var3[] = "Bogus data"; - obj1.setParameters(var3); - QCOMPARE(var3, obj1.parameters()); - obj1.setParameters((char *)0); - // The format is stored internally in a QString, so return is always a valid char * - QVERIFY(QString(obj1.parameters()).isEmpty()); -} - tst_QPicture::tst_QPicture() { } @@ -316,6 +292,7 @@ void tst_QPicture::boundaryValues() painter.end(); } - QTEST_MAIN(tst_QPicture) #include "tst_qpicture.moc" + +#endif // QT_NO_PICTURE diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 42135dae24..106e9050b8 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -4,11 +4,14 @@ SUBDIRS=\ qclipboard \ qcursor \ qdrag \ + qguiaction \ + qguiactiongroup \ qevent \ qfileopenevent \ qguieventdispatcher \ qguieventloop \ qguimetatype \ + qguishortcut \ qguitimer \ qguivariant \ qhighdpiscaling \ @@ -29,6 +32,12 @@ SUBDIRS=\ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop +!qtConfig(shortcut): SUBDIRS -= \ + qkeysequence \ + qguishortcut \ + qguimetatype \ + qguivariant + !qtHaveModule(widgets): SUBDIRS -= \ qmouseevent_modal \ qtouchevent @@ -36,6 +45,10 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop !qtHaveModule(network): SUBDIRS -= \ qguieventloop +!qtConfig(action): SUBDIRS -= \ + qguiaction \ + qguiactiongroup + !qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling !qtConfig(opengl): SUBDIRS -= qopenglwindow diff --git a/tests/auto/gui/kernel/qguiaction/.gitignore b/tests/auto/gui/kernel/qguiaction/.gitignore new file mode 100644 index 0000000000..bf81f5bf2c --- /dev/null +++ b/tests/auto/gui/kernel/qguiaction/.gitignore @@ -0,0 +1 @@ +tst_qaction diff --git a/tests/auto/gui/kernel/qguiaction/qguiaction.pro b/tests/auto/gui/kernel/qguiaction/qguiaction.pro new file mode 100644 index 0000000000..2a39636119 --- /dev/null +++ b/tests/auto/gui/kernel/qguiaction/qguiaction.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qguiaction +QT += gui-private core-private testlib +SOURCES += tst_qguiaction.cpp diff --git a/tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp b/tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp new file mode 100644 index 0000000000..9d45d4ae14 --- /dev/null +++ b/tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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> + +#include <qguiapplication.h> +#include <qevent.h> +#include <qguiaction.h> +#include <qguiactiongroup.h> +#include <qpa/qplatformtheme.h> + +#include <private/qguiapplication_p.h> + +class tst_QGuiAction : public QObject +{ + Q_OBJECT + +public: + tst_QGuiAction(); + +private slots: + void cleanup(); + void getSetCheck(); + void setText_data(); + void setText(); + void setIconText_data() { setText_data(); } + void setIconText(); +#if QT_CONFIG(shortcut) + void setStandardKeys(); + void task200823_tooltip(); +#endif + void task229128TriggeredSignalWithoutActiongroup(); + void setData(); + +private: + const int m_keyboardScheme; +}; + +tst_QGuiAction::tst_QGuiAction() + : m_keyboardScheme(QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::KeyboardScheme).toInt()) +{ +} + +void tst_QGuiAction::cleanup() +{ + QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); +} + +// Testing get/set functions +void tst_QGuiAction::getSetCheck() +{ + QGuiAction obj1(nullptr); + // QActionGroup * QAction::actionGroup() + // void QAction::setActionGroup(QActionGroup *) + auto var1 = new QGuiActionGroup(nullptr); + obj1.setActionGroup(var1); + QCOMPARE(var1, obj1.guiActionGroup()); + obj1.setActionGroup(nullptr); + QCOMPARE(obj1.guiActionGroup(), nullptr); + delete var1; + + QCOMPARE(obj1.priority(), QGuiAction::NormalPriority); + obj1.setPriority(QGuiAction::LowPriority); + QCOMPARE(obj1.priority(), QGuiAction::LowPriority); +} + +void tst_QGuiAction::setText_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("iconText"); + QTest::addColumn<QString>("textFromIconText"); + + //next we fill it with data + QTest::newRow("Normal") << "Action" << "Action" << "Action"; + QTest::newRow("Ampersand") << "Search && Destroy" << "Search & Destroy" << "Search && Destroy"; + QTest::newRow("Mnemonic and ellipsis") << "O&pen File ..." << "Open File" << "Open File"; +} + +void tst_QGuiAction::setText() +{ + QFETCH(QString, text); + + QGuiAction action(nullptr); + action.setText(text); + + QCOMPARE(action.text(), text); + + QFETCH(QString, iconText); + QCOMPARE(action.iconText(), iconText); +} + +void tst_QGuiAction::setIconText() +{ + QFETCH(QString, iconText); + + QGuiAction action(nullptr); + action.setIconText(iconText); + QCOMPARE(action.iconText(), iconText); + + QFETCH(QString, textFromIconText); + QCOMPARE(action.text(), textFromIconText); +} + +#if QT_CONFIG(shortcut) + +//basic testing of standard keys +void tst_QGuiAction::setStandardKeys() +{ + QGuiAction act(nullptr); + act.setShortcut(QKeySequence("CTRL+L")); + QList<QKeySequence> list; + act.setShortcuts(list); + act.setShortcuts(QKeySequence::Copy); + QCOMPARE(act.shortcut(), act.shortcuts().constFirst()); + + QList<QKeySequence> expected; + const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C")); + const QKeySequence ctrlInsert = QKeySequence(QStringLiteral("CTRL+INSERT")); + switch (m_keyboardScheme) { + case QPlatformTheme::MacKeyboardScheme: + expected << ctrlC; + break; + case QPlatformTheme::WindowsKeyboardScheme: + expected << ctrlC << ctrlInsert; + break; + default: // X11 + expected << ctrlC << ctrlInsert << QKeySequence(QStringLiteral("F16")); + break; + } + + QCOMPARE(act.shortcuts(), expected); +} + +void tst_QGuiAction::task200823_tooltip() +{ + const QScopedPointer<QGuiAction> action(new QGuiAction("foo", nullptr)); + QString shortcut("ctrl+o"); + action->setShortcut(shortcut); + + // we want a non-standard tooltip that shows the shortcut + action->setToolTip(action->text() + QLatin1String(" (") + action->shortcut().toString() + QLatin1Char(')')); + + QString ref = QLatin1String("foo (") + QKeySequence(shortcut).toString() + QLatin1Char(')'); + QCOMPARE(action->toolTip(), ref); +} + +#endif // QT_CONFIG(shortcut) + +void tst_QGuiAction::task229128TriggeredSignalWithoutActiongroup() +{ + // test without a group + const QScopedPointer<QGuiAction> actionWithoutGroup(new QGuiAction("Test", nullptr)); + QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QGuiAction::triggered)); + QCOMPARE(spyWithoutGroup.count(), 0); + actionWithoutGroup->trigger(); + // signal should be emitted + QCOMPARE(spyWithoutGroup.count(), 1); + + // it is now a checkable checked action + actionWithoutGroup->setCheckable(true); + actionWithoutGroup->setChecked(true); + spyWithoutGroup.clear(); + QCOMPARE(spyWithoutGroup.count(), 0); + actionWithoutGroup->trigger(); + // signal should be emitted + QCOMPARE(spyWithoutGroup.count(), 1); +} + +void tst_QGuiAction::setData() // QTBUG-62006 +{ + QGuiAction act(nullptr); + QSignalSpy spy(&act, &QGuiAction::changed); + QCOMPARE(act.data(), QVariant()); + QCOMPARE(spy.count(), 0); + act.setData(QVariant()); + QCOMPARE(spy.count(), 0); + + act.setData(-1); + QCOMPARE(spy.count(), 1); + act.setData(-1); + QCOMPARE(spy.count(), 1); +} + +QTEST_MAIN(tst_QGuiAction) +#include "tst_qguiaction.moc" diff --git a/tests/auto/gui/kernel/qguiactiongroup/.gitignore b/tests/auto/gui/kernel/qguiactiongroup/.gitignore new file mode 100644 index 0000000000..daba003e96 --- /dev/null +++ b/tests/auto/gui/kernel/qguiactiongroup/.gitignore @@ -0,0 +1 @@ +tst_qactiongroup diff --git a/tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro b/tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro new file mode 100644 index 0000000000..7fd64e70f1 --- /dev/null +++ b/tests/auto/gui/kernel/qguiactiongroup/qguiactiongroup.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qactiongroup +QT += testlib +SOURCES += tst_qguiactiongroup.cpp diff --git a/tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp b/tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp new file mode 100644 index 0000000000..1ac14280fb --- /dev/null +++ b/tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp @@ -0,0 +1,235 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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> + +#include <qguiaction.h> +#include <qguiactiongroup.h> + +class tst_QGuiActionGroup : public QObject +{ + Q_OBJECT + +private slots: + void cleanup() { QVERIFY(QGuiApplication::topLevelWindows().isEmpty()); } + void enabledPropagation(); + void visiblePropagation(); + void exclusive(); + void exclusiveOptional(); + void testActionInTwoQActionGroup(); + void unCheckCurrentAction(); +}; + +void tst_QGuiActionGroup::enabledPropagation() +{ + QGuiActionGroup testActionGroup(nullptr); + + auto childAction = new QGuiAction( &testActionGroup ); + auto anotherChildAction = new QGuiAction( &testActionGroup ); + auto freeAction = new QGuiAction(nullptr); + + QVERIFY( testActionGroup.isEnabled() ); + QVERIFY( childAction->isEnabled() ); + + testActionGroup.setEnabled( false ); + QVERIFY( !testActionGroup.isEnabled() ); + QVERIFY( !childAction->isEnabled() ); + QVERIFY( !anotherChildAction->isEnabled() ); + + childAction->setEnabled(true); + QVERIFY( !childAction->isEnabled()); + + anotherChildAction->setEnabled( false ); + + testActionGroup.setEnabled( true ); + QVERIFY( testActionGroup.isEnabled() ); + QVERIFY( childAction->isEnabled() ); + QVERIFY( !anotherChildAction->isEnabled() ); + + testActionGroup.setEnabled( false ); + auto lastChildAction = new QGuiAction(&testActionGroup); + + QVERIFY(!lastChildAction->isEnabled()); + testActionGroup.setEnabled( true ); + QVERIFY(lastChildAction->isEnabled()); + + freeAction->setEnabled(false); + testActionGroup.addAction(freeAction); + QVERIFY(!freeAction->isEnabled()); + delete freeAction; +} + +void tst_QGuiActionGroup::visiblePropagation() +{ + QGuiActionGroup testActionGroup(nullptr); + + auto childAction = new QGuiAction( &testActionGroup ); + auto anotherChildAction = new QGuiAction( &testActionGroup ); + auto freeAction = new QGuiAction(nullptr); + + QVERIFY( testActionGroup.isVisible() ); + QVERIFY( childAction->isVisible() ); + + testActionGroup.setVisible( false ); + QVERIFY( !testActionGroup.isVisible() ); + QVERIFY( !childAction->isVisible() ); + QVERIFY( !anotherChildAction->isVisible() ); + + anotherChildAction->setVisible(false); + + testActionGroup.setVisible( true ); + QVERIFY( testActionGroup.isVisible() ); + QVERIFY( childAction->isVisible() ); + + QVERIFY( !anotherChildAction->isVisible() ); + + testActionGroup.setVisible( false ); + auto lastChildAction = new QGuiAction(&testActionGroup); + + QVERIFY(!lastChildAction->isVisible()); + testActionGroup.setVisible( true ); + QVERIFY(lastChildAction->isVisible()); + + freeAction->setVisible(false); + testActionGroup.addAction(freeAction); + QVERIFY(!freeAction->isVisible()); + delete freeAction; +} + +void tst_QGuiActionGroup::exclusive() +{ + QGuiActionGroup group(nullptr); + group.setExclusive(false); + QVERIFY( !group.isExclusive() ); + + auto actOne = new QGuiAction(&group); + actOne->setCheckable( true ); + auto actTwo = new QGuiAction(&group); + actTwo->setCheckable( true ); + auto actThree = new QGuiAction(&group); + actThree->setCheckable( true ); + + group.setExclusive( true ); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->setChecked( true ); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->setChecked( true ); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + +void tst_QGuiActionGroup::exclusiveOptional() +{ + QGuiActionGroup group(0); + group.setExclusive(true); + QVERIFY( group.isExclusive() ); + + auto actOne = new QGuiAction(&group); + actOne->setCheckable( true ); + auto actTwo = new QGuiAction(&group); + actTwo->setCheckable( true ); + auto actThree = new QGuiAction(&group); + actThree->setCheckable( true ); + + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actOne->trigger(); + QVERIFY( actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + group.setExclusionPolicy(QGuiActionGroup::ExclusionPolicy::ExclusiveOptional); + QVERIFY( group.isExclusive() ); + + actOne->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); + + actTwo->trigger(); + QVERIFY( !actOne->isChecked() ); + QVERIFY( !actTwo->isChecked() ); + QVERIFY( !actThree->isChecked() ); +} + +void tst_QGuiActionGroup::testActionInTwoQActionGroup() +{ + QGuiAction action1("Action 1", this); + + QGuiActionGroup group1(this); + QGuiActionGroup group2(this); + + group1.addAction(&action1); + group2.addAction(&action1); + + QCOMPARE(action1.guiActionGroup(), &group2); + QCOMPARE(group2.guiActions().constFirst(), &action1); + QCOMPARE(group1.guiActions().isEmpty(), true); +} + +void tst_QGuiActionGroup::unCheckCurrentAction() +{ + QGuiActionGroup group(nullptr); + QGuiAction action1(&group) ,action2(&group); + action1.setCheckable(true); + action2.setCheckable(true); + QVERIFY(!action1.isChecked()); + QVERIFY(!action2.isChecked()); + action1.setChecked(true); + QVERIFY(action1.isChecked()); + QVERIFY(!action2.isChecked()); + auto current = group.checkedGuiAction(); + QCOMPARE(current, &action1); + current->setChecked(false); + QVERIFY(!action1.isChecked()); + QVERIFY(!action2.isChecked()); + QVERIFY(!group.checkedGuiAction()); +} + + +QTEST_MAIN(tst_QGuiActionGroup) +#include "tst_qguiactiongroup.moc" diff --git a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp index 3ce65a6785..2645bb111e 100644 --- a/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp +++ b/tests/auto/gui/kernel/qguimetatype/tst_qguimetatype.cpp @@ -181,9 +181,13 @@ template<> struct TestValueFactory<QMetaType::QCursor> { static QCursor *create() { return new QCursor(Qt::WaitCursor); } }; #endif + +#if QT_CONFIG(shortcut) template<> struct TestValueFactory<QMetaType::QKeySequence> { static QKeySequence *create() { return new QKeySequence(QKeySequence::Close); } }; +#endif + template<> struct TestValueFactory<QMetaType::QPen> { static QPen *create() { return new QPen(Qt::DashDotDotLine); } }; @@ -312,30 +316,10 @@ void tst_QGuiMetaType::sizeOf() QCOMPARE(QMetaType::sizeOf(type), size); } -#ifndef Q_ALIGNOF -template<uint N> -struct RoundToNextHighestPowerOfTwo -{ -private: - enum { V1 = N-1 }; - enum { V2 = V1 | (V1 >> 1) }; - enum { V3 = V2 | (V2 >> 2) }; - enum { V4 = V3 | (V3 >> 4) }; - enum { V5 = V4 | (V4 >> 8) }; - enum { V6 = V5 | (V5 >> 16) }; -public: - enum { Value = V6 + 1 }; -}; -#endif - template<class T> struct TypeAlignment { -#ifdef Q_ALIGNOF - enum { Value = Q_ALIGNOF(T) }; -#else - enum { Value = RoundToNextHighestPowerOfTwo<sizeof(T)>::Value }; -#endif + enum { Value = alignof(T) }; }; void tst_QGuiMetaType::flags_data() diff --git a/tests/auto/gui/kernel/qguishortcut/qguishortcut.pro b/tests/auto/gui/kernel/qguishortcut/qguishortcut.pro new file mode 100644 index 0000000000..1417dee213 --- /dev/null +++ b/tests/auto/gui/kernel/qguishortcut/qguishortcut.pro @@ -0,0 +1,4 @@ +CONFIG += testcase +TARGET = tst_qguishortcut +QT += testlib +SOURCES += tst_qguishortcut.cpp diff --git a/tests/auto/gui/kernel/qguishortcut/tst_qguishortcut.cpp b/tests/auto/gui/kernel/qguishortcut/tst_qguishortcut.cpp new file mode 100644 index 0000000000..bc3fb9862d --- /dev/null +++ b/tests/auto/gui/kernel/qguishortcut/tst_qguishortcut.cpp @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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> +#include <QtGui/qguiapplication.h> +#include <QtGui/qguishortcut.h> +#include <QtGui/qpainter.h> +#include <QtGui/qrasterwindow.h> +#include <QtGui/qscreen.h> +#include <QtGui/qwindow.h> + +class tst_QGuiShortcut : public QObject +{ + Q_OBJECT +public: + +private slots: + void trigger(); +}; + +class ColoredWindow : public QRasterWindow { +public: + ColoredWindow(QColor c) : m_color(c) {} + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + const QColor m_color; +}; + +void ColoredWindow::paintEvent(QPaintEvent *) +{ + QPainter p(this); + p.fillRect(QRect(QPoint(), size()), m_color); +} + +static void sendKey(QWindow *target, Qt::Key k, char c, Qt::KeyboardModifiers modifiers) +{ + QTest::sendKeyEvent(QTest::Press, target, k, c, modifiers); + QTest::sendKeyEvent(QTest::Release, target, k, c, modifiers); +} + +void tst_QGuiShortcut::trigger() +{ + ColoredWindow w(Qt::yellow); + w.setTitle(QTest::currentTestFunction()); + w.resize(QGuiApplication::primaryScreen()->size() / 4); + new QGuiShortcut(Qt::CTRL + Qt::Key_Q, &w, SLOT(close())); + w.show(); + QVERIFY(QTest::qWaitForWindowExposed(&w)); + sendKey(&w, Qt::Key_Q, 'q', Qt::ControlModifier); + QTRY_VERIFY(!w.isVisible()); +} + +QTEST_MAIN(tst_QGuiShortcut) +#include "tst_qguishortcut.moc" diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index 87a47bd93b..6a928cac7a 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -64,8 +64,10 @@ public: private slots: void basicEventDelivery(); +#if QT_CONFIG(shortcut) void modifiers_data(); void modifiers(); +#endif }; tst_QKeyEvent::tst_QKeyEvent() @@ -128,6 +130,8 @@ static QByteArray modifiersTestRowName(const QString &keySequence) return result; } +#if QT_CONFIG(shortcut) + void tst_QKeyEvent::modifiers_data() { struct Modifier @@ -198,5 +202,7 @@ void tst_QKeyEvent::modifiers() } } +#endif // QT_CONFIG(shortcut) + QTEST_MAIN(tst_QKeyEvent) #include "tst_qkeyevent.moc" diff --git a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro index 759b608c93..28b12f0677 100644 --- a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro +++ b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro @@ -1,6 +1,6 @@ CONFIG += testcase TARGET = tst_qopenglwindow -QT += core-private gui-private testlib +QT += opengl core-private gui-private testlib SOURCES += tst_qopenglwindow.cpp diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp index 9c36b6898a..2785d57a42 100644 --- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp +++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include <QtGui/QOpenGLWindow> +#include <QtOpenGL/QOpenGLWindow> #include <QtTest/QtTest> #include <QtGui/QOpenGLFunctions> #include <QtGui/QOpenGLContext> diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp index 6ce6422f48..04343727bb 100644 --- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp +++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp @@ -41,6 +41,12 @@ private Q_SLOTS: void copySemantics(); void moveSemantics(); void setBrush(); + + void isBrushSet(); + void setAllPossibleBrushes(); + void noBrushesSetForDefaultPalette(); + void cannotCheckIfInvalidBrushSet(); + void checkIfBrushForCurrentGroupSet(); }; void tst_QPalette::roleValues_data() @@ -118,23 +124,35 @@ void tst_QPalette::resolve() QVERIFY(p2ResolvedTo1 != p2); } + +static void compareAllPaletteData(const QPalette &firstPalette, const QPalette &secondPalette) +{ + QCOMPARE(firstPalette, secondPalette); + + // For historical reasons, operator== compares only brushes, but it's not enough for proper + // comparison after move/copy, because some additional data can also be moved/copied. + // Let's compare this data here. + QCOMPARE(firstPalette.resolve(), secondPalette.resolve()); + QCOMPARE(firstPalette.currentColorGroup(), secondPalette.currentColorGroup()); +} + void tst_QPalette::copySemantics() { QPalette src(Qt::red), dst; const QPalette control = src; // copy construction QVERIFY(src != dst); QVERIFY(!src.isCopyOf(dst)); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(src.isCopyOf(control)); dst = src; // copy assignment - QCOMPARE(dst, src); - QCOMPARE(dst, control); + compareAllPaletteData(dst, src); + compareAllPaletteData(dst, control); QVERIFY(dst.isCopyOf(src)); dst = QPalette(Qt::green); QVERIFY(dst != src); QVERIFY(dst != control); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(src.isCopyOf(control)); } @@ -144,13 +162,13 @@ void tst_QPalette::moveSemantics() QPalette src(Qt::red), dst; const QPalette control = src; QVERIFY(src != dst); - QCOMPARE(src, control); + compareAllPaletteData(src, control); QVERIFY(!dst.isCopyOf(src)); QVERIFY(!dst.isCopyOf(control)); dst = std::move(src); // move assignment QVERIFY(!dst.isCopyOf(src)); // isCopyOf() works on moved-from palettes, too QVERIFY(dst.isCopyOf(control)); - QCOMPARE(dst, control); + compareAllPaletteData(dst, control); src = control; // check moved-from 'src' can still be assigned to (doesn't crash) QVERIFY(src.isCopyOf(dst)); QVERIFY(src.isCopyOf(control)); @@ -158,7 +176,7 @@ void tst_QPalette::moveSemantics() QVERIFY(!src.isCopyOf(dst)); QVERIFY(!src.isCopyOf(dst2)); QVERIFY(!src.isCopyOf(control)); - QCOMPARE(dst2, control); + compareAllPaletteData(dst2, control); QVERIFY(dst2.isCopyOf(dst)); QVERIFY(dst2.isCopyOf(control)); // check moved-from 'src' can still be destroyed (doesn't crash) @@ -194,5 +212,62 @@ void tst_QPalette::setBrush() QVERIFY(pp.isCopyOf(p)); } +void tst_QPalette::isBrushSet() +{ + QPalette p; + + // Set only one color group + p.setBrush(QPalette::Active, QPalette::Mid, QBrush(Qt::red)); + QVERIFY(p.isBrushSet(QPalette::Active, QPalette::Mid)); + QVERIFY(!p.isBrushSet(QPalette::Inactive, QPalette::Mid)); + QVERIFY(!p.isBrushSet(QPalette::Disabled, QPalette::Mid)); + + // Set all color groups + p.setBrush(QPalette::LinkVisited, QBrush(Qt::green)); + QVERIFY(p.isBrushSet(QPalette::Active, QPalette::LinkVisited)); + QVERIFY(p.isBrushSet(QPalette::Inactive, QPalette::LinkVisited)); + QVERIFY(p.isBrushSet(QPalette::Disabled, QPalette::LinkVisited)); +} + +void tst_QPalette::setAllPossibleBrushes() +{ + QPalette p; + + QCOMPARE(p.resolve(), QPalette::ResolveMask(0)); + + for (int r = 0; r < QPalette::NColorRoles; ++r) { + p.setBrush(QPalette::All, QPalette::ColorRole(r), Qt::red); + } + + for (int r = 0; r < QPalette::NColorRoles; ++r) { + for (int g = 0; g < QPalette::NColorGroups; ++g) { + QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r))); + } + } +} + +void tst_QPalette::noBrushesSetForDefaultPalette() +{ + QCOMPARE(QPalette().resolve(), QPalette::ResolveMask(0)); +} + +void tst_QPalette::cannotCheckIfInvalidBrushSet() +{ + QPalette p(Qt::red); + + QVERIFY(!p.isBrushSet(QPalette::All, QPalette::LinkVisited)); + QVERIFY(!p.isBrushSet(QPalette::Active, QPalette::NColorRoles)); +} + +void tst_QPalette::checkIfBrushForCurrentGroupSet() +{ + QPalette p; + + p.setCurrentColorGroup(QPalette::Disabled); + p.setBrush(QPalette::Current, QPalette::Link, QBrush(Qt::yellow)); + + QVERIFY(p.isBrushSet(QPalette::Current, QPalette::Link)); +} + QTEST_MAIN(tst_QPalette) #include "tst_qpalette.moc" diff --git a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp index 07c820dc86..f8502c1e2f 100644 --- a/tests/auto/gui/painting/qcolor/tst_qcolor.cpp +++ b/tests/auto/gui/painting/qcolor/tst_qcolor.cpp @@ -1032,6 +1032,15 @@ void tst_QColor::setRgbF() QCOMPARE(qfloat16(b2), qfloat16(b)); } } + QVERIFY(color.isValid()); + QColor invalidRgb = color; + QColor invalidRgbF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range"); + invalidRgb.setRgb(-1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setRgb: RGB parameters out of range"); + invalidRgbF.setRgb(-1, -1, -1, -1); + QVERIFY(!invalidRgb.isValid()); + QVERIFY(!invalidRgbF.isValid()); } void tst_QColor::setRgba() @@ -1146,6 +1155,16 @@ void tst_QColor::setHsv() QCOMPARE(v2, v); } } + QVERIFY(color.isValid()); + QVERIFY(color.isValid()); + QColor invalidHsv = color; + QColor invalidHsvF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsv: HSV parameters out of range"); + invalidHsv.setHsv(-1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsvF: HSV parameters out of range"); + invalidHsvF.setHsvF(-1, -1, -1); + QVERIFY(!invalidHsv.isValid()); + QVERIFY(!invalidHsvF.isValid()); } void tst_QColor::setCmyk() @@ -1271,6 +1290,15 @@ void tst_QColor::setCmyk() QCOMPARE(k2, k); } } + QVERIFY(color.isValid()); + QColor invalidCmyk = color; + QColor invalidCmykF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setCmyk: CMYK parameters out of range"); + invalidCmyk.setCmyk(-1, -1, -1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setCmykF: CMYK parameters out of range"); + invalidCmykF.setCmykF(-1, -1, -1, -1, -1); + QVERIFY(!invalidCmyk.isValid()); + QVERIFY(!invalidCmykF.isValid()); } void tst_QColor::setHsl() @@ -1372,6 +1400,15 @@ void tst_QColor::setHsl() QCOMPARE(l2, l); } } + QVERIFY(color.isValid()); + QColor invalidHsl = color; + QColor invalidHslF = color; + QTest::ignoreMessage(QtWarningMsg, "QColor::setHsl: HSL parameters out of range"); + invalidHsl.setHsl(-1, -1, -1, -1); + QTest::ignoreMessage(QtWarningMsg, "QColor::setHslF: HSL parameters out of range"); + invalidHslF.setHslF(-1, -1, -1, -1); + QVERIFY(!invalidHsl.isValid()); + QVERIFY(!invalidHslF.isValid()); } void tst_QColor::toRgb_data() |