Split tests of QGuiAction(Group)
Fixes: QTBUG-69478 Change-Id: I3f5a4b859f06a0f89b2d344c36b75da4647aedce Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
4b0af2cdbf
commit
c92cb78b6d
@ -4,6 +4,8 @@ SUBDIRS=\
|
||||
qclipboard \
|
||||
qcursor \
|
||||
qdrag \
|
||||
qguiaction \
|
||||
qguiactiongroup \
|
||||
qevent \
|
||||
qfileopenevent \
|
||||
qguieventdispatcher \
|
||||
@ -41,6 +43,10 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop
|
||||
!qtHaveModule(network): SUBDIRS -= \
|
||||
qguieventloop
|
||||
|
||||
!qtConfig(action): SUBDIRS -= \
|
||||
qguiaction \
|
||||
qguiactiongroup
|
||||
|
||||
!qtConfig(highdpiscaling): SUBDIRS -= qhighdpiscaling
|
||||
|
||||
!qtConfig(opengl): SUBDIRS -= qopenglwindow
|
||||
|
4
tests/auto/gui/kernel/qguiaction/qguiaction.pro
Normal file
4
tests/auto/gui/kernel/qguiaction/qguiaction.pro
Normal file
@ -0,0 +1,4 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qguiaction
|
||||
QT += gui-private core-private testlib
|
||||
SOURCES += tst_qguiaction.cpp
|
210
tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp
Normal file
210
tests/auto/gui/kernel/qguiaction/tst_qguiaction.cpp
Normal file
@ -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"
|
1
tests/auto/gui/kernel/qguiactiongroup/.gitignore
vendored
Normal file
1
tests/auto/gui/kernel/qguiactiongroup/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
tst_qactiongroup
|
@ -0,0 +1,4 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qactiongroup
|
||||
QT += testlib
|
||||
SOURCES += tst_qguiactiongroup.cpp
|
235
tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp
Normal file
235
tests/auto/gui/kernel/qguiactiongroup/tst_qguiactiongroup.cpp
Normal file
@ -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"
|
@ -50,26 +50,15 @@ public:
|
||||
private slots:
|
||||
void init();
|
||||
void cleanup();
|
||||
void getSetCheck();
|
||||
void setText_data();
|
||||
void setText();
|
||||
void setIconText_data() { setText_data(); }
|
||||
void setIconText();
|
||||
void setUnknownFont();
|
||||
void actionEvent();
|
||||
#if QT_CONFIG(shortcut)
|
||||
void setStandardKeys();
|
||||
void alternateShortcuts();
|
||||
void enabledVisibleInteraction();
|
||||
void task200823_tooltip();
|
||||
#endif
|
||||
void task229128TriggeredSignalWithoutActiongroup();
|
||||
void task229128TriggeredSignalWhenInActiongroup();
|
||||
#if QT_CONFIG(shortcut)
|
||||
void repeat();
|
||||
#endif
|
||||
void setData();
|
||||
#if QT_CONFIG(shortcut)
|
||||
void keysequence(); // QTBUG-53381
|
||||
void disableShortcutsWithBlockedWidgets_data();
|
||||
void disableShortcutsWithBlockedWidgets();
|
||||
@ -98,33 +87,6 @@ void tst_QAction::cleanup()
|
||||
QVERIFY(QApplication::topLevelWidgets().isEmpty());
|
||||
}
|
||||
|
||||
// Testing get/set functions
|
||||
void tst_QAction::getSetCheck()
|
||||
{
|
||||
QAction obj1(nullptr);
|
||||
// QActionGroup * QAction::actionGroup()
|
||||
// void QAction::setActionGroup(QActionGroup *)
|
||||
QActionGroup *var1 = new QActionGroup(nullptr);
|
||||
obj1.setActionGroup(var1);
|
||||
QCOMPARE(var1, obj1.actionGroup());
|
||||
obj1.setActionGroup(nullptr);
|
||||
QCOMPARE(obj1.actionGroup(), nullptr);
|
||||
delete var1;
|
||||
|
||||
// QMenu * QAction::menu()
|
||||
// void QAction::setMenu(QMenu *)
|
||||
QMenu *var2 = new QMenu(nullptr);
|
||||
obj1.setMenu(var2);
|
||||
QCOMPARE(var2, obj1.menu());
|
||||
obj1.setMenu(nullptr);
|
||||
QCOMPARE(obj1.menu(), nullptr);
|
||||
delete var2;
|
||||
|
||||
QCOMPARE(obj1.priority(), QAction::NormalPriority);
|
||||
obj1.setPriority(QAction::LowPriority);
|
||||
QCOMPARE(obj1.priority(), QAction::LowPriority);
|
||||
}
|
||||
|
||||
class MyWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -139,43 +101,6 @@ private:
|
||||
tst_QAction *m_test;
|
||||
};
|
||||
|
||||
void tst_QAction::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_QAction::setText()
|
||||
{
|
||||
QFETCH(QString, text);
|
||||
|
||||
QAction action(nullptr);
|
||||
action.setText(text);
|
||||
|
||||
QCOMPARE(action.text(), text);
|
||||
|
||||
QFETCH(QString, iconText);
|
||||
QCOMPARE(action.iconText(), iconText);
|
||||
}
|
||||
|
||||
void tst_QAction::setIconText()
|
||||
{
|
||||
QFETCH(QString, iconText);
|
||||
|
||||
QAction action(nullptr);
|
||||
action.setIconText(iconText);
|
||||
QCOMPARE(action.iconText(), iconText);
|
||||
|
||||
QFETCH(QString, textFromIconText);
|
||||
QCOMPARE(action.text(), textFromIconText);
|
||||
}
|
||||
|
||||
void tst_QAction::setUnknownFont() // QTBUG-42728
|
||||
{
|
||||
QAction action(nullptr);
|
||||
@ -229,35 +154,6 @@ void tst_QAction::actionEvent()
|
||||
|
||||
#if QT_CONFIG(shortcut)
|
||||
|
||||
//basic testing of standard keys
|
||||
void tst_QAction::setStandardKeys()
|
||||
{
|
||||
QAction 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_QAction::alternateShortcuts()
|
||||
{
|
||||
//test the alternate shortcuts (by adding more than 1 shortcut)
|
||||
@ -362,41 +258,8 @@ void tst_QAction::enabledVisibleInteraction()
|
||||
QCOMPARE(spy.count(), 1); //act is visible and enabled, so trigger
|
||||
}
|
||||
|
||||
void tst_QAction::task200823_tooltip()
|
||||
{
|
||||
const QScopedPointer<QAction> action(new QAction("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_QAction::task229128TriggeredSignalWithoutActiongroup()
|
||||
{
|
||||
// test without a group
|
||||
const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr));
|
||||
QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::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_QAction::task229128TriggeredSignalWhenInActiongroup()
|
||||
{
|
||||
QActionGroup ag(nullptr);
|
||||
@ -464,25 +327,6 @@ void tst_QAction::repeat()
|
||||
QCOMPARE(spy.count(), 2);
|
||||
}
|
||||
|
||||
#endif // QT_CONFIG(shortcut)
|
||||
|
||||
void tst_QAction::setData() // QTBUG-62006
|
||||
{
|
||||
QAction act(nullptr);
|
||||
QSignalSpy spy(&act, &QAction::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);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(shortcut)
|
||||
|
||||
void tst_QAction::disableShortcutsWithBlockedWidgets_data()
|
||||
{
|
||||
QTest::addColumn<Qt::ShortcutContext>("shortcutContext");
|
||||
|
@ -38,166 +38,9 @@ class tst_QActionGroup : public QObject
|
||||
|
||||
private slots:
|
||||
void cleanup() { QVERIFY(QApplication::topLevelWidgets().isEmpty()); }
|
||||
void enabledPropagation();
|
||||
void visiblePropagation();
|
||||
void exclusive();
|
||||
void exclusiveOptional();
|
||||
void separators();
|
||||
void testActionInTwoQActionGroup();
|
||||
void unCheckCurrentAction();
|
||||
};
|
||||
|
||||
void tst_QActionGroup::enabledPropagation()
|
||||
{
|
||||
QActionGroup testActionGroup(nullptr);
|
||||
|
||||
QAction* childAction = new QAction( &testActionGroup );
|
||||
QAction* anotherChildAction = new QAction( &testActionGroup );
|
||||
QAction* freeAction = new QAction(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 );
|
||||
QAction *lastChildAction = new QAction(&testActionGroup);
|
||||
|
||||
QVERIFY(!lastChildAction->isEnabled());
|
||||
testActionGroup.setEnabled( true );
|
||||
QVERIFY(lastChildAction->isEnabled());
|
||||
|
||||
freeAction->setEnabled(false);
|
||||
testActionGroup.addAction(freeAction);
|
||||
QVERIFY(!freeAction->isEnabled());
|
||||
delete freeAction;
|
||||
}
|
||||
|
||||
void tst_QActionGroup::visiblePropagation()
|
||||
{
|
||||
QActionGroup testActionGroup(nullptr);
|
||||
|
||||
QAction* childAction = new QAction( &testActionGroup );
|
||||
QAction* anotherChildAction = new QAction( &testActionGroup );
|
||||
QAction* freeAction = new QAction(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 );
|
||||
QAction *lastChildAction = new QAction(&testActionGroup);
|
||||
|
||||
QVERIFY(!lastChildAction->isVisible());
|
||||
testActionGroup.setVisible( true );
|
||||
QVERIFY(lastChildAction->isVisible());
|
||||
|
||||
freeAction->setVisible(false);
|
||||
testActionGroup.addAction(freeAction);
|
||||
QVERIFY(!freeAction->isVisible());
|
||||
delete freeAction;
|
||||
}
|
||||
|
||||
void tst_QActionGroup::exclusive()
|
||||
{
|
||||
QActionGroup group(nullptr);
|
||||
group.setExclusive(false);
|
||||
QVERIFY( !group.isExclusive() );
|
||||
|
||||
QAction* actOne = new QAction( &group );
|
||||
actOne->setCheckable( true );
|
||||
QAction* actTwo = new QAction( &group );
|
||||
actTwo->setCheckable( true );
|
||||
QAction* actThree = new QAction( &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_QActionGroup::exclusiveOptional()
|
||||
{
|
||||
QActionGroup group(0);
|
||||
group.setExclusive(true);
|
||||
QVERIFY( group.isExclusive() );
|
||||
|
||||
QAction* actOne = new QAction( &group );
|
||||
actOne->setCheckable( true );
|
||||
QAction* actTwo = new QAction( &group );
|
||||
actTwo->setCheckable( true );
|
||||
QAction* actThree = new QAction( &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( QActionGroup::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_QActionGroup::separators()
|
||||
{
|
||||
QMainWindow mw;
|
||||
@ -233,40 +76,5 @@ void tst_QActionGroup::separators()
|
||||
QCOMPARE(menu.actions().size(), 3);
|
||||
}
|
||||
|
||||
void tst_QActionGroup::testActionInTwoQActionGroup()
|
||||
{
|
||||
QAction action1("Action 1", this);
|
||||
|
||||
QActionGroup group1(this);
|
||||
QActionGroup group2(this);
|
||||
|
||||
group1.addAction(&action1);
|
||||
group2.addAction(&action1);
|
||||
|
||||
QCOMPARE(action1.actionGroup(), &group2);
|
||||
QCOMPARE(group2.actions().first(), &action1);
|
||||
QCOMPARE(group1.actions().isEmpty(), true);
|
||||
}
|
||||
|
||||
void tst_QActionGroup::unCheckCurrentAction()
|
||||
{
|
||||
QActionGroup group(nullptr);
|
||||
QAction 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.checkedAction();
|
||||
QCOMPARE(current, &action1);
|
||||
current->setChecked(false);
|
||||
QVERIFY(!action1.isChecked());
|
||||
QVERIFY(!action2.isChecked());
|
||||
QVERIFY(!group.checkedAction());
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QActionGroup)
|
||||
#include "tst_qactiongroup.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user