mirror of https://github.com/qt/qtbase.git
tst_QAction(Group): Brush up the tests
- Use nullptr - Use Qt 5 connection syntax - Remove C-Style casts Task-number: QTBUG-69478 Change-Id: Icf8faf3433ff3bff667db050e79b560b221867b0 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
e65ea36018
commit
4b63288a60
|
@ -70,7 +70,7 @@ private slots:
|
||||||
void shortcutFromKeyEvent(); // QTBUG-48325
|
void shortcutFromKeyEvent(); // QTBUG-48325
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_lastEventType;
|
QEvent::Type m_lastEventType;
|
||||||
const int m_keyboardScheme;
|
const int m_keyboardScheme;
|
||||||
QAction *m_lastAction;
|
QAction *m_lastAction;
|
||||||
};
|
};
|
||||||
|
@ -82,7 +82,7 @@ tst_QAction::tst_QAction()
|
||||||
|
|
||||||
void tst_QAction::init()
|
void tst_QAction::init()
|
||||||
{
|
{
|
||||||
m_lastEventType = 0;
|
m_lastEventType = QEvent::None;
|
||||||
m_lastAction = nullptr;
|
m_lastAction = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,23 +94,23 @@ void tst_QAction::cleanup()
|
||||||
// Testing get/set functions
|
// Testing get/set functions
|
||||||
void tst_QAction::getSetCheck()
|
void tst_QAction::getSetCheck()
|
||||||
{
|
{
|
||||||
QAction obj1(0);
|
QAction obj1(nullptr);
|
||||||
// QActionGroup * QAction::actionGroup()
|
// QActionGroup * QAction::actionGroup()
|
||||||
// void QAction::setActionGroup(QActionGroup *)
|
// void QAction::setActionGroup(QActionGroup *)
|
||||||
QActionGroup *var1 = new QActionGroup(0);
|
QActionGroup *var1 = new QActionGroup(nullptr);
|
||||||
obj1.setActionGroup(var1);
|
obj1.setActionGroup(var1);
|
||||||
QCOMPARE(var1, obj1.actionGroup());
|
QCOMPARE(var1, obj1.actionGroup());
|
||||||
obj1.setActionGroup((QActionGroup *)0);
|
obj1.setActionGroup(nullptr);
|
||||||
QCOMPARE((QActionGroup *)0, obj1.actionGroup());
|
QCOMPARE(obj1.actionGroup(), nullptr);
|
||||||
delete var1;
|
delete var1;
|
||||||
|
|
||||||
// QMenu * QAction::menu()
|
// QMenu * QAction::menu()
|
||||||
// void QAction::setMenu(QMenu *)
|
// void QAction::setMenu(QMenu *)
|
||||||
QMenu *var2 = new QMenu(0);
|
QMenu *var2 = new QMenu(nullptr);
|
||||||
obj1.setMenu(var2);
|
obj1.setMenu(var2);
|
||||||
QCOMPARE(var2, obj1.menu());
|
QCOMPARE(var2, obj1.menu());
|
||||||
obj1.setMenu((QMenu *)0);
|
obj1.setMenu(nullptr);
|
||||||
QCOMPARE((QMenu *)0, obj1.menu());
|
QCOMPARE(obj1.menu(), nullptr);
|
||||||
delete var2;
|
delete var2;
|
||||||
|
|
||||||
QCOMPARE(obj1.priority(), QAction::NormalPriority);
|
QCOMPARE(obj1.priority(), QAction::NormalPriority);
|
||||||
|
@ -148,7 +148,7 @@ void tst_QAction::setText()
|
||||||
{
|
{
|
||||||
QFETCH(QString, text);
|
QFETCH(QString, text);
|
||||||
|
|
||||||
QAction action(0);
|
QAction action(nullptr);
|
||||||
action.setText(text);
|
action.setText(text);
|
||||||
|
|
||||||
QCOMPARE(action.text(), text);
|
QCOMPARE(action.text(), text);
|
||||||
|
@ -161,7 +161,7 @@ void tst_QAction::setIconText()
|
||||||
{
|
{
|
||||||
QFETCH(QString, iconText);
|
QFETCH(QString, iconText);
|
||||||
|
|
||||||
QAction action(0);
|
QAction action(nullptr);
|
||||||
action.setIconText(iconText);
|
action.setIconText(iconText);
|
||||||
QCOMPARE(action.iconText(), iconText);
|
QCOMPARE(action.iconText(), iconText);
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ void tst_QAction::setIconText()
|
||||||
|
|
||||||
void tst_QAction::setUnknownFont() // QTBUG-42728
|
void tst_QAction::setUnknownFont() // QTBUG-42728
|
||||||
{
|
{
|
||||||
QAction action(0);
|
QAction action(nullptr);
|
||||||
QFont font("DoesNotExist", 11);
|
QFont font("DoesNotExist", 11);
|
||||||
action.setFont(font);
|
action.setFont(font);
|
||||||
|
|
||||||
|
@ -182,17 +182,17 @@ void tst_QAction::setUnknownFont() // QTBUG-42728
|
||||||
void tst_QAction::updateState(QActionEvent *e)
|
void tst_QAction::updateState(QActionEvent *e)
|
||||||
{
|
{
|
||||||
if (!e) {
|
if (!e) {
|
||||||
m_lastEventType = 0;
|
m_lastEventType = QEvent::None;
|
||||||
m_lastAction = 0;
|
m_lastAction = nullptr;
|
||||||
} else {
|
} else {
|
||||||
m_lastEventType = (int)e->type();
|
m_lastEventType = e->type();
|
||||||
m_lastAction = e->action();
|
m_lastAction = e->action();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QAction::actionEvent()
|
void tst_QAction::actionEvent()
|
||||||
{
|
{
|
||||||
QAction a(0);
|
QAction a(nullptr);
|
||||||
a.setText("action text");
|
a.setText("action text");
|
||||||
|
|
||||||
// add action
|
// add action
|
||||||
|
@ -202,33 +202,33 @@ void tst_QAction::actionEvent()
|
||||||
testWidget.addAction(&a);
|
testWidget.addAction(&a);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
QCOMPARE(m_lastEventType, (int)QEvent::ActionAdded);
|
QCOMPARE(m_lastEventType, QEvent::ActionAdded);
|
||||||
QCOMPARE(m_lastAction, &a);
|
QCOMPARE(m_lastAction, &a);
|
||||||
|
|
||||||
// change action
|
// change action
|
||||||
a.setText("new action text");
|
a.setText("new action text");
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
QCOMPARE(m_lastEventType, (int)QEvent::ActionChanged);
|
QCOMPARE(m_lastEventType, QEvent::ActionChanged);
|
||||||
QCOMPARE(m_lastAction, &a);
|
QCOMPARE(m_lastAction, &a);
|
||||||
|
|
||||||
// remove action
|
// remove action
|
||||||
testWidget.removeAction(&a);
|
testWidget.removeAction(&a);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
QCOMPARE(m_lastEventType, (int)QEvent::ActionRemoved);
|
QCOMPARE(m_lastEventType, QEvent::ActionRemoved);
|
||||||
QCOMPARE(m_lastAction, &a);
|
QCOMPARE(m_lastAction, &a);
|
||||||
}
|
}
|
||||||
|
|
||||||
//basic testing of standard keys
|
//basic testing of standard keys
|
||||||
void tst_QAction::setStandardKeys()
|
void tst_QAction::setStandardKeys()
|
||||||
{
|
{
|
||||||
QAction act(0);
|
QAction act(nullptr);
|
||||||
act.setShortcut(QKeySequence("CTRL+L"));
|
act.setShortcut(QKeySequence("CTRL+L"));
|
||||||
QList<QKeySequence> list;
|
QList<QKeySequence> list;
|
||||||
act.setShortcuts(list);
|
act.setShortcuts(list);
|
||||||
act.setShortcuts(QKeySequence::Copy);
|
act.setShortcuts(QKeySequence::Copy);
|
||||||
QCOMPARE(act.shortcut(), act.shortcuts().first());
|
QCOMPARE(act.shortcut(), act.shortcuts().constFirst());
|
||||||
|
|
||||||
QList<QKeySequence> expected;
|
QList<QKeySequence> expected;
|
||||||
const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
|
const QKeySequence ctrlC = QKeySequence(QStringLiteral("CTRL+C"));
|
||||||
|
@ -263,7 +263,7 @@ void tst_QAction::alternateShortcuts()
|
||||||
QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
|
QList<QKeySequence> shlist = QList<QKeySequence>() << QKeySequence("CTRL+P") << QKeySequence("CTRL+A");
|
||||||
act.setShortcuts(shlist);
|
act.setShortcuts(shlist);
|
||||||
|
|
||||||
QSignalSpy spy(&act, SIGNAL(triggered()));
|
QSignalSpy spy(&act, &QAction::triggered);
|
||||||
|
|
||||||
act.setAutoRepeat(true);
|
act.setAutoRepeat(true);
|
||||||
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
|
||||||
|
@ -322,7 +322,7 @@ void tst_QAction::enabledVisibleInteraction()
|
||||||
testWidget.show();
|
testWidget.show();
|
||||||
QApplication::setActiveWindow(&testWidget);
|
QApplication::setActiveWindow(&testWidget);
|
||||||
|
|
||||||
QAction act(0);
|
QAction act(nullptr);
|
||||||
// check defaults
|
// check defaults
|
||||||
QVERIFY(act.isEnabled());
|
QVERIFY(act.isEnabled());
|
||||||
QVERIFY(act.isVisible());
|
QVERIFY(act.isVisible());
|
||||||
|
@ -370,7 +370,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
|
||||||
{
|
{
|
||||||
// test without a group
|
// test without a group
|
||||||
const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr));
|
const QScopedPointer<QAction> actionWithoutGroup(new QAction("Test", nullptr));
|
||||||
QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), SIGNAL(triggered(bool)));
|
QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), QOverload<bool>::of(&QAction::triggered));
|
||||||
QCOMPARE(spyWithoutGroup.count(), 0);
|
QCOMPARE(spyWithoutGroup.count(), 0);
|
||||||
actionWithoutGroup->trigger();
|
actionWithoutGroup->trigger();
|
||||||
// signal should be emitted
|
// signal should be emitted
|
||||||
|
@ -388,7 +388,7 @@ void tst_QAction::task229128TriggeredSignalWithoutActiongroup()
|
||||||
|
|
||||||
void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
|
void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
|
||||||
{
|
{
|
||||||
QActionGroup ag(0);
|
QActionGroup ag(nullptr);
|
||||||
QAction *action = new QAction("Test", &ag);
|
QAction *action = new QAction("Test", &ag);
|
||||||
QAction *checkedAction = new QAction("Test 2", &ag);
|
QAction *checkedAction = new QAction("Test 2", &ag);
|
||||||
ag.addAction(action);
|
ag.addAction(action);
|
||||||
|
@ -397,8 +397,8 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup()
|
||||||
checkedAction->setCheckable(true);
|
checkedAction->setCheckable(true);
|
||||||
checkedAction->setChecked(true);
|
checkedAction->setChecked(true);
|
||||||
|
|
||||||
QSignalSpy actionSpy(checkedAction, SIGNAL(triggered(bool)));
|
QSignalSpy actionSpy(checkedAction, QOverload<bool>::of(&QAction::triggered));
|
||||||
QSignalSpy actionGroupSpy(&ag, SIGNAL(triggered(QAction*)));
|
QSignalSpy actionGroupSpy(&ag, QOverload<QAction*>::of(&QActionGroup::triggered));
|
||||||
QCOMPARE(actionGroupSpy.count(), 0);
|
QCOMPARE(actionGroupSpy.count(), 0);
|
||||||
QCOMPARE(actionSpy.count(), 0);
|
QCOMPARE(actionSpy.count(), 0);
|
||||||
checkedAction->trigger();
|
checkedAction->trigger();
|
||||||
|
@ -513,10 +513,10 @@ void tst_QAction::disableShortcutsWithBlockedWidgets()
|
||||||
class ShortcutOverrideWidget : public QWidget
|
class ShortcutOverrideWidget : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShortcutOverrideWidget(QWidget *parent = 0) : QWidget(parent), shortcutOverrideCount(0) {}
|
using QWidget::QWidget;
|
||||||
int shortcutOverrideCount;
|
int shortcutOverrideCount = 0;
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *e)
|
bool event(QEvent *e) override
|
||||||
{
|
{
|
||||||
if (e->type() == QEvent::ShortcutOverride)
|
if (e->type() == QEvent::ShortcutOverride)
|
||||||
++shortcutOverrideCount;
|
++shortcutOverrideCount;
|
||||||
|
|
|
@ -49,11 +49,11 @@ private slots:
|
||||||
|
|
||||||
void tst_QActionGroup::enabledPropagation()
|
void tst_QActionGroup::enabledPropagation()
|
||||||
{
|
{
|
||||||
QActionGroup testActionGroup( 0 );
|
QActionGroup testActionGroup(nullptr);
|
||||||
|
|
||||||
QAction* childAction = new QAction( &testActionGroup );
|
QAction* childAction = new QAction( &testActionGroup );
|
||||||
QAction* anotherChildAction = new QAction( &testActionGroup );
|
QAction* anotherChildAction = new QAction( &testActionGroup );
|
||||||
QAction* freeAction = new QAction(0);
|
QAction* freeAction = new QAction(nullptr);
|
||||||
|
|
||||||
QVERIFY( testActionGroup.isEnabled() );
|
QVERIFY( testActionGroup.isEnabled() );
|
||||||
QVERIFY( childAction->isEnabled() );
|
QVERIFY( childAction->isEnabled() );
|
||||||
|
@ -88,11 +88,11 @@ void tst_QActionGroup::enabledPropagation()
|
||||||
|
|
||||||
void tst_QActionGroup::visiblePropagation()
|
void tst_QActionGroup::visiblePropagation()
|
||||||
{
|
{
|
||||||
QActionGroup testActionGroup( 0 );
|
QActionGroup testActionGroup(nullptr);
|
||||||
|
|
||||||
QAction* childAction = new QAction( &testActionGroup );
|
QAction* childAction = new QAction( &testActionGroup );
|
||||||
QAction* anotherChildAction = new QAction( &testActionGroup );
|
QAction* anotherChildAction = new QAction( &testActionGroup );
|
||||||
QAction* freeAction = new QAction(0);
|
QAction* freeAction = new QAction(nullptr);
|
||||||
|
|
||||||
QVERIFY( testActionGroup.isVisible() );
|
QVERIFY( testActionGroup.isVisible() );
|
||||||
QVERIFY( childAction->isVisible() );
|
QVERIFY( childAction->isVisible() );
|
||||||
|
@ -125,7 +125,7 @@ void tst_QActionGroup::visiblePropagation()
|
||||||
|
|
||||||
void tst_QActionGroup::exclusive()
|
void tst_QActionGroup::exclusive()
|
||||||
{
|
{
|
||||||
QActionGroup group(0);
|
QActionGroup group(nullptr);
|
||||||
group.setExclusive(false);
|
group.setExclusive(false);
|
||||||
QVERIFY( !group.isExclusive() );
|
QVERIFY( !group.isExclusive() );
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ void tst_QActionGroup::separators()
|
||||||
|
|
||||||
menu.addActions(actGroup.actions());
|
menu.addActions(actGroup.actions());
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 2);
|
QCOMPARE(menu.actions().size(), 2);
|
||||||
|
|
||||||
const auto removeActions = [&menu](const QList<QAction *> &actions) {
|
const auto removeActions = [&menu](const QList<QAction *> &actions) {
|
||||||
for (QAction *action : actions)
|
for (QAction *action : actions)
|
||||||
|
@ -223,14 +223,14 @@ void tst_QActionGroup::separators()
|
||||||
};
|
};
|
||||||
removeActions(actGroup.actions());
|
removeActions(actGroup.actions());
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 0);
|
QCOMPARE(menu.actions().size(), 0);
|
||||||
|
|
||||||
action = new QAction(&actGroup);
|
action = new QAction(&actGroup);
|
||||||
action->setText("test two");
|
action->setText("test two");
|
||||||
|
|
||||||
menu.addActions(actGroup.actions());
|
menu.addActions(actGroup.actions());
|
||||||
|
|
||||||
QCOMPARE((int)menu.actions().size(), 3);
|
QCOMPARE(menu.actions().size(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QActionGroup::testActionInTwoQActionGroup()
|
void tst_QActionGroup::testActionInTwoQActionGroup()
|
||||||
|
@ -250,7 +250,7 @@ void tst_QActionGroup::testActionInTwoQActionGroup()
|
||||||
|
|
||||||
void tst_QActionGroup::unCheckCurrentAction()
|
void tst_QActionGroup::unCheckCurrentAction()
|
||||||
{
|
{
|
||||||
QActionGroup group(0);
|
QActionGroup group(nullptr);
|
||||||
QAction action1(&group) ,action2(&group);
|
QAction action1(&group) ,action2(&group);
|
||||||
action1.setCheckable(true);
|
action1.setCheckable(true);
|
||||||
action2.setCheckable(true);
|
action2.setCheckable(true);
|
||||||
|
|
Loading…
Reference in New Issue