diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-09-29 14:40:48 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-09-29 14:42:15 (GMT) |
commit | 544f06f1fe29e986cd2b3fd1fd7198d688275969 (patch) | |
tree | 015c0c61ecd2141d949a7d6cefd8c31327e3bd1f /tests/auto/qstatemachine | |
parent | 86a30b667e189b8659fab384d93022e55a67b81e (diff) | |
download | Qt-544f06f1fe29e986cd2b3fd1fd7198d688275969.zip Qt-544f06f1fe29e986cd2b3fd1fd7198d688275969.tar.gz Qt-544f06f1fe29e986cd2b3fd1fd7198d688275969.tar.bz2 |
Make sure delayed events are cancelled when a state machine halts
Otherwise the events might creep into the event loop if the state
machine is restarted.
Reviewed-by: Eskil Abrahamsen Blomfeldt
Diffstat (limited to 'tests/auto/qstatemachine')
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 463dbf6..b808f7f 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -120,6 +120,7 @@ private slots: void assignPropertyWithAnimation(); void postEvent(); void cancelDelayedEvent(); + void postDelayedEventAndStop(); void stateFinished(); void parallelStates(); void parallelRootState(); @@ -1638,6 +1639,44 @@ void tst_QStateMachine::cancelDelayedEvent() QVERIFY(machine.configuration().contains(s2)); } +void tst_QStateMachine::postDelayedEventAndStop() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + QFinalState *s2 = new QFinalState(&machine); + s1->addTransition(new StringTransition("a", s2)); + machine.setInitialState(s1); + + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + int id1 = machine.postDelayedEvent(new StringEvent("a"), 0); + QVERIFY(id1 != -1); + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QTRY_COMPARE(stoppedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 2); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + int id2 = machine.postDelayedEvent(new StringEvent("a"), 1000); + QVERIFY(id2 != -1); + machine.stop(); + QTRY_COMPARE(stoppedSpy.count(), 2); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 3); + QTestEventLoop::instance().enterLoop(2); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); +} + void tst_QStateMachine::stateFinished() { QStateMachine machine; |