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>
This commit is contained in:
Frederik Gladhorn 2015-06-25 18:09:27 +02:00
parent 99afd9dd4c
commit 290e875fd9

View File

@ -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"