From 7323cd8dc29011dff49267bbf8f41f31eaf0a112 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Fri, 16 Jun 2017 10:54:53 +0200 Subject: testlib: add key sequence function [ChangeLog][Qt Test] Added keySequence() function. Task-number: QTBUG-53381 Change-Id: Ib7c3f966fe607f00475ae74aaf070cb988d00141 Reviewed-by: Edward Welbourne Reviewed-by: Mitch Curtis Reviewed-by: J-P Nurmi --- tests/auto/widgets/kernel/qaction/tst_qaction.cpp | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests/auto/widgets/kernel/qaction/tst_qaction.cpp') diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index 83e1850524..ac6362168e 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -62,6 +62,7 @@ private slots: void task229128TriggeredSignalWithoutActiongroup(); void task229128TriggeredSignalWhenInActiongroup(); void repeat(); + void keysequence(); // QTBUG-53381 private: int m_lastEventType; @@ -276,6 +277,40 @@ void tst_QAction::alternateShortcuts() QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier); } +void tst_QAction::keysequence() +{ + MyWidget testWidget(this); + testWidget.show(); + QApplication::setActiveWindow(&testWidget); + + { + QAction act(&testWidget); + testWidget.addAction(&act); + + QKeySequence ks(QKeySequence::SelectAll); + + act.setShortcut(ks); + + QSignalSpy spy(&act, &QAction::triggered); + + act.setAutoRepeat(true); + QTest::keySequence(&testWidget, ks); + QCoreApplication::processEvents(); + QCOMPARE(spy.count(), 1); // act should have been triggered + + act.setAutoRepeat(false); + QTest::keySequence(&testWidget, ks); + QCoreApplication::processEvents(); + QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time + + // end of the scope of the action, it will be destroyed and removed from widget + // This action should also unregister its shortcuts + } + + // this tests a crash (if the action did not unregister its alternate shortcuts) + QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier); +} + void tst_QAction::enabledVisibleInteraction() { MyWidget testWidget(this); -- cgit v1.2.3