summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstatemachine
diff options
context:
space:
mode:
authorKent Hansen <khansen@trolltech.com>2009-05-07 10:40:38 (GMT)
committerKent Hansen <khansen@trolltech.com>2009-05-07 10:41:11 (GMT)
commit81eebfbe01edb002d55c3504cc2558689cf0f936 (patch)
tree1cee50ade6cfd167cf503182b7f67afe5081fe56 /tests/auto/qstatemachine
parent1e404bcb6df5127a1d0e24ed11cce1c0260a57e9 (diff)
downloadQt-81eebfbe01edb002d55c3504cc2558689cf0f936.zip
Qt-81eebfbe01edb002d55c3504cc2558689cf0f936.tar.gz
Qt-81eebfbe01edb002d55c3504cc2558689cf0f936.tar.bz2
add QStateMachine::isRunning()
Diffstat (limited to 'tests/auto/qstatemachine')
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 3876a20..edd6459 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -104,6 +104,7 @@ private slots:
void signalTransitions();
void eventTransitions();
void historyStates();
+ void startAndStop();
void transitionToRootState();
void transitionEntersParent();
@@ -1094,14 +1095,17 @@ void tst_QStateMachine::stateEntryAndExit()
s2->addTransition(s3);
QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
machine.setInitialState(s1);
QVERIFY(machine.configuration().isEmpty());
globalTick = 0;
+ QVERIFY(!machine.isRunning());
machine.start();
QTRY_COMPARE(startedSpy.count(), 1);
QTRY_COMPARE(finishedSpy.count(), 1);
+ QTRY_COMPARE(stoppedSpy.count(), 0);
QCOMPARE(machine.configuration().count(), 1);
QVERIFY(machine.configuration().contains(s3));
@@ -1826,6 +1830,44 @@ void tst_QStateMachine::historyStates()
QTRY_COMPARE(finishedSpy.count(), 1);
}
+void tst_QStateMachine::startAndStop()
+{
+ QStateMachine machine;
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy stoppedSpy(&machine, SIGNAL(stopped()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ QVERIFY(!machine.isRunning());
+ QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start: No initial state set for machine. Refusing to start.");
+ machine.start();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QVERIFY(!machine.isRunning());
+ machine.stop();
+ QCOMPARE(startedSpy.count(), 0);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+ machine.start();
+ QTRY_COMPARE(machine.isRunning(), true);
+ QTRY_COMPARE(startedSpy.count(), 1);
+ QCOMPARE(stoppedSpy.count(), 0);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+
+ machine.stop();
+ QTRY_COMPARE(machine.isRunning(), false);
+ QTRY_COMPARE(stoppedSpy.count(), 1);
+ QCOMPARE(startedSpy.count(), 1);
+ QCOMPARE(finishedSpy.count(), 0);
+
+ QCOMPARE(machine.configuration().count(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+}
+
void tst_QStateMachine::defaultGlobalRestorePolicy()
{
QStateMachine machine;