diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-06-25 18:09:27 +0200 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-07-07 22:26:31 +0000 |
commit | 290e875fd99db4076b642ab2c53adecd32a8ced5 (patch) | |
tree | 35c67db50b2ed471434b59420b2d5196dbe115bf /tests/auto | |
parent | 99afd9dd4c6670f1010153a97efdcfa1014042a0 (diff) |
Test QAction::autoRepeat
Sending several key presses with repeat=true should trigger the action
several times, unless autoRepeat is set to false.
Change-Id: I6469bbd78a608a87852554882c1632ce34422662
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/kernel/qaction/tst_qaction.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index be1fed2be3..897128d40e 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -69,6 +69,7 @@ private slots: void task200823_tooltip(); void task229128TriggeredSignalWithoutActiongroup(); void task229128TriggeredSignalWhenInActiongroup(); + void repeat(); private: int m_lastEventType; @@ -380,5 +381,42 @@ void tst_QAction::task229128TriggeredSignalWhenInActiongroup() QCOMPARE(actionSpy.count(), 1); } +void tst_QAction::repeat() +{ + QWidget *wid = m_tstWidget; + QAction act(wid); + wid->addAction(&act); + act.setShortcut(QKeySequence(Qt::Key_F)); + QSignalSpy spy(&act, SIGNAL(triggered())); + + act.setAutoRepeat(true); + QTest::keyPress(wid, Qt::Key_F); + QTest::keyRelease(wid, Qt::Key_F); + QCOMPARE(spy.count(), 1); + + spy.clear(); + QTest::keyPress(wid, Qt::Key_F); + // repeat event + QTest::simulateEvent(wid, true, Qt::Key_F, Qt::NoModifier, QString("f"), true); + QTest::simulateEvent(wid, true, Qt::Key_F, Qt::NoModifier, QString("f"), true); + QTest::keyRelease(wid, Qt::Key_F); + QCOMPARE(spy.count(), 3); + + spy.clear(); + act.setAutoRepeat(false); + QTest::keyPress(wid, Qt::Key_F); + QTest::simulateEvent(wid, true, Qt::Key_F, Qt::NoModifier, QString("f"), true); + QTest::simulateEvent(wid, true, Qt::Key_F, Qt::NoModifier, QString("f"), true); + QTest::keyRelease(wid, Qt::Key_F); + QCOMPARE(spy.count(), 1); + + spy.clear(); + act.setAutoRepeat(true); + QTest::keyPress(wid, Qt::Key_F); + QTest::simulateEvent(wid, true, Qt::Key_F, Qt::NoModifier, QString("f"), true); + QTest::keyRelease(wid, Qt::Key_F); + QCOMPARE(spy.count(), 2); +} + QTEST_MAIN(tst_QAction) #include "tst_qaction.moc" |