From 414d5550f9ffe46faf1ee81b1a364683f2b2f066 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Wed, 28 Oct 2009 18:21:05 +0100 Subject: Test that we gracefully handle event posting after the state machine is stopped The internal slot _q_process() should never be called if the machine is not in the Running state. --- tests/auto/qstatemachine/tst_qstatemachine.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 1516346..346afc9 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -124,6 +124,7 @@ private slots: void postEvent(); void cancelDelayedEvent(); void postDelayedEventAndStop(); + void stopAndPostEvent(); void stateFinished(); void parallelStates(); void parallelRootState(); @@ -1681,6 +1682,22 @@ void tst_QStateMachine::postDelayedEventAndStop() QVERIFY(machine.configuration().contains(s1)); } +void tst_QStateMachine::stopAndPostEvent() +{ + QStateMachine machine; + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + QSignalSpy startedSpy(&machine, SIGNAL(started())); + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QSignalSpy stoppedSpy(&machine, SIGNAL(stopped())); + machine.stop(); + QCOMPARE(stoppedSpy.count(), 0); + machine.postEvent(new QEvent(QEvent::User)); + QTRY_COMPARE(stoppedSpy.count(), 1); + QCoreApplication::processEvents(); +} + void tst_QStateMachine::stateFinished() { QStateMachine machine; -- cgit v0.12