summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan.vatra.ford@kdab.com>2014-07-21 09:39:06 +0300
committerBogDan Vatra <bogdan@kde.org>2014-07-29 11:27:09 +0200
commitf5edb62cc225c5f85c786f0db8cff424a62f0931 (patch)
tree1463422e1dce70ef385a8224834b861eda7d00d8 /tests/auto/corelib/statemachine
parentc67f7c0f0fc34887a4922a269815c460cbe3ccf8 (diff)
Export QAbstractState active property.
It is needed to check if a State is active. Change-Id: I8aa0230b8cd96fb9b95b86b2ce118fe280f9ce97 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/corelib/statemachine')
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp904
1 files changed, 888 insertions, 16 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index e8d4fe51a8..67f3477eee 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -92,6 +92,22 @@ static int globalTick;
QCOMPARE(machine.isRunning(), runningArgs.at(0).toBool()); \
}
+#define DEFINE_ACTIVE_SPY(VAR) \
+ QSignalSpy VAR##_activeSpy(VAR, &QState::activeChanged); \
+ QVERIFY(VAR##_activeSpy.isValid());
+
+#define TEST_ACTIVE_CHANGED(VAR, COUNT) \
+{ \
+ QTRY_COMPARE(VAR##_activeSpy.count(), COUNT); \
+ bool active = true; \
+ foreach (const QList<QVariant> &activeArgs, static_cast<QList<QList<QVariant> > >(VAR##_activeSpy)) { \
+ QVERIFY(activeArgs.at(0).type() == QVariant::Bool); \
+ QVERIFY(activeArgs.at(0).toBool() == active); \
+ active = !active; \
+ } \
+ QCOMPARE(VAR->active(), !active); \
+}
+
class SignalEmitter : public QObject
{
Q_OBJECT
@@ -299,6 +315,7 @@ void tst_QStateMachine::transitionToRootState()
machine.setObjectName("machine");
QState *initialState = new QState();
+ DEFINE_ACTIVE_SPY(initialState);
initialState->setObjectName("initial");
machine.addState(initialState);
machine.setInitialState(initialState);
@@ -313,12 +330,14 @@ void tst_QStateMachine::transitionToRootState()
QCOMPARE(machine.configuration().count(), 1);
QVERIFY(machine.configuration().contains(initialState));
+ TEST_ACTIVE_CHANGED(initialState, 1);
machine.postEvent(new QEvent(QEvent::User));
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 'initial'");
QCoreApplication::processEvents();
QVERIFY(machine.configuration().isEmpty());
QVERIFY(!machine.isRunning());
+ TEST_ACTIVE_CHANGED(initialState, 2);
}
void tst_QStateMachine::transitionFromRootState()
@@ -1120,11 +1139,15 @@ void tst_QStateMachine::rootState()
QCOMPARE(machine.machine(), (QStateMachine*)0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QCOMPARE(s1->parentState(), static_cast<QState*>(&machine));
QState *s2 = new QState();
+ DEFINE_ACTIVE_SPY(s2);
s2->setParent(&machine);
QCOMPARE(s2->parentState(), static_cast<QState*>(&machine));
+ TEST_ACTIVE_CHANGED(s1, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
}
void tst_QStateMachine::machineWithParent()
@@ -1398,6 +1421,7 @@ void tst_QStateMachine::assignProperty()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QTest::ignoreMessage(QtWarningMsg, "QState::assignProperty: cannot assign property 'foo' of null object");
s1->assignProperty(0, "foo", QVariant());
@@ -1408,32 +1432,39 @@ void tst_QStateMachine::assignProperty()
machine.setInitialState(s1);
machine.start();
QTRY_COMPARE(s1->objectName(), QString::fromLatin1("s1"));
+ TEST_ACTIVE_CHANGED(s1, 2);
s1->assignProperty(s1, "objectName", "foo");
machine.start();
QTRY_COMPARE(s1->objectName(), QString::fromLatin1("foo"));
+ TEST_ACTIVE_CHANGED(s1, 4);
s1->assignProperty(s1, "noSuchProperty", 123);
machine.start();
QTRY_COMPARE(s1->dynamicPropertyNames().size(), 1);
QCOMPARE(s1->dynamicPropertyNames().at(0), QByteArray("noSuchProperty"));
QCOMPARE(s1->objectName(), QString::fromLatin1("foo"));
+ TEST_ACTIVE_CHANGED(s1, 6);
{
QSignalSpy propertiesAssignedSpy(s1, &QState::propertiesAssigned);
QVERIFY(propertiesAssignedSpy.isValid());
machine.start();
QTRY_COMPARE(propertiesAssignedSpy.count(), 1);
+ TEST_ACTIVE_CHANGED(s1, 8);
}
// nested states
{
QState *s11 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s11);
QString str = QString::fromLatin1("set by nested state");
s11->assignProperty(s11, "objectName", str);
s1->setInitialState(s11);
machine.start();
QTRY_COMPARE(s11->objectName(), str);
+ TEST_ACTIVE_CHANGED(s1, 10);
+ TEST_ACTIVE_CHANGED(s11, 2);
}
}
@@ -1451,8 +1482,10 @@ void tst_QStateMachine::assignPropertyWithAnimation()
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(&obj, "foo", 123);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 789);
QAbstractTransition *trans = s1->addTransition(s2);
@@ -1485,6 +1518,8 @@ void tst_QStateMachine::assignPropertyWithAnimation()
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QCOMPARE(obj.property("foo").toInt(), 456);
QCOMPARE(obj.property("bar").toInt(), 789);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
}
// Two animations
{
@@ -1493,8 +1528,10 @@ void tst_QStateMachine::assignPropertyWithAnimation()
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(&obj, "foo", 123);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 789);
QAbstractTransition *trans = s1->addTransition(s2);
@@ -1517,6 +1554,8 @@ void tst_QStateMachine::assignPropertyWithAnimation()
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QCOMPARE(obj.property("foo").toInt(), 456);
QCOMPARE(obj.property("bar").toInt(), 789);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
}
// Animation group
{
@@ -1525,9 +1564,11 @@ void tst_QStateMachine::assignPropertyWithAnimation()
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(&obj, "foo", 123);
s1->assignProperty(&obj, "bar", 321);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 654);
s2->assignProperty(&obj, "baz", 789);
@@ -1550,6 +1591,8 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QCOMPARE(obj.property("foo").toInt(), 456);
QCOMPARE(obj.property("bar").toInt(), 654);
QCOMPARE(obj.property("baz").toInt(), 789);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
}
// Nested states
{
@@ -1558,6 +1601,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
obj.setProperty("foo", 321);
obj.setProperty("bar", 654);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QCOMPARE(s1->childMode(), QState::ExclusiveStates);
s1->setChildMode(QState::ParallelStates);
QCOMPARE(s1->childMode(), QState::ParallelStates);
@@ -1568,12 +1612,15 @@ void tst_QStateMachine::assignPropertyWithAnimation()
s1->assignProperty(&obj, "foo", 123);
s1->assignProperty(&obj, "bar", 456);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->setObjectName("s2");
s2->assignProperty(&obj, "foo", 321);
QState *s21 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s21);
s21->setObjectName("s21");
s21->assignProperty(&obj, "bar", 654);
QState *s22 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s22);
s22->setObjectName("s22");
s22->assignProperty(&obj, "bar", 789);
s2->setInitialState(s21);
@@ -1602,6 +1649,10 @@ void tst_QStateMachine::assignPropertyWithAnimation()
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QCOMPARE(obj.property("foo").toInt(), 321);
QCOMPARE(obj.property("bar").toInt(), 789);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s21, 2);
+ TEST_ACTIVE_CHANGED(s22, 2);
}
// Aborted animation
{
@@ -1612,9 +1663,11 @@ void tst_QStateMachine::assignPropertyWithAnimation()
obj.setProperty("bar", 654);
QState *group = new QState(&machine);
QState *s1 = new QState(group);
+ DEFINE_ACTIVE_SPY(s1);
group->setInitialState(s1);
s1->assignProperty(&obj, "foo", 123);
QState *s2 = new QState(group);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(&obj, "foo", 456);
s2->assignProperty(&obj, "bar", 789);
QAbstractTransition *trans = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
@@ -1625,6 +1678,7 @@ void tst_QStateMachine::assignPropertyWithAnimation()
anim2.setDuration(8000);
trans->addAnimation(&anim2);
QState *s3 = new QState(group);
+ DEFINE_ACTIVE_SPY(s3);
s3->assignProperty(&obj, "foo", 911);
s2->addTransition(&emitter, SIGNAL(signalWithNoArg()), s3);
@@ -1641,6 +1695,10 @@ void tst_QStateMachine::assignPropertyWithAnimation()
QVERIFY(propertiesAssignedSpy.isEmpty());
QCOMPARE(obj.property("foo").toInt(), 911);
QCOMPARE(obj.property("bar").toInt(), 789);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
}
}
@@ -1712,6 +1770,7 @@ void tst_QStateMachine::postEvent()
machine.postEvent(&e);
}
StringEventPoster *s1 = new StringEventPoster("a");
+ DEFINE_ACTIVE_SPY(s1);
if (x == 1)
s1->setDelay(100);
QFinalState *s2 = new QFinalState;
@@ -1728,6 +1787,7 @@ void tst_QStateMachine::postEvent()
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
+ TEST_ACTIVE_CHANGED(s1, 2);
s1->setString("b");
QFinalState *s3 = new QFinalState();
@@ -1738,6 +1798,7 @@ void tst_QStateMachine::postEvent()
QTRY_COMPARE(finishedSpy.count(), 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s3));
+ TEST_ACTIVE_CHANGED(s1, 4);
}
}
@@ -1748,6 +1809,7 @@ void tst_QStateMachine::cancelDelayedEvent()
QVERIFY(!machine.cancelDelayedEvent(-1));
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *s2 = new QFinalState(&machine);
s1->addTransition(new StringTransition("a", s2));
machine.setInitialState(s1);
@@ -1759,9 +1821,9 @@ void tst_QStateMachine::cancelDelayedEvent()
machine.start();
QTRY_COMPARE(startedSpy.count(), 1);
TEST_RUNNING_CHANGED(true);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
-
int id1 = machine.postDelayedEvent(new StringEvent("c"), 50000);
QVERIFY(id1 != -1);
int id2 = machine.postDelayedEvent(new StringEvent("b"), 25000);
@@ -1779,6 +1841,7 @@ void tst_QStateMachine::cancelDelayedEvent()
QVERIFY(finishedSpy.isValid());
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
}
@@ -1787,6 +1850,7 @@ void tst_QStateMachine::postDelayedEventAndStop()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *s2 = new QFinalState(&machine);
s1->addTransition(new StringTransition("a", s2));
machine.setInitialState(s1);
@@ -1798,6 +1862,7 @@ void tst_QStateMachine::postDelayedEventAndStop()
machine.start();
QTRY_COMPARE(startedSpy.count(), 1);
TEST_RUNNING_CHANGED(true);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
@@ -1808,12 +1873,14 @@ void tst_QStateMachine::postDelayedEventAndStop()
machine.stop();
QTRY_COMPARE(stoppedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
machine.start();
QTRY_COMPARE(startedSpy.count(), 2);
TEST_RUNNING_CHANGED(true);
+ TEST_ACTIVE_CHANGED(s1, 3);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
@@ -1822,12 +1889,15 @@ void tst_QStateMachine::postDelayedEventAndStop()
machine.stop();
QTRY_COMPARE(stoppedSpy.count(), 2);
TEST_RUNNING_CHANGED(false);
+ TEST_ACTIVE_CHANGED(s1, 3);
machine.start();
QTRY_COMPARE(startedSpy.count(), 3);
TEST_RUNNING_CHANGED(true);
QTestEventLoop::instance().enterLoop(2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
+ TEST_ACTIVE_CHANGED(s1, 5);
+ QVERIFY(machine.isRunning());
}
class DelayedEventPosterThread : public QThread
@@ -1864,6 +1934,7 @@ void tst_QStateMachine::postDelayedEventFromThread()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *f = new QFinalState(&machine);
s1->addTransition(new EventTransition(QEvent::User, f));
machine.setInitialState(s1);
@@ -1878,6 +1949,7 @@ void tst_QStateMachine::postDelayedEventFromThread()
machine.start();
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s1, 2);
QVERIFY(poster.firstEventWasCancelled);
}
@@ -1885,6 +1957,7 @@ void tst_QStateMachine::stopAndPostEvent()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QSignalSpy runningSpy(&machine, &QStateMachine::runningChanged);
QVERIFY(runningSpy.isValid());
@@ -1893,6 +1966,7 @@ void tst_QStateMachine::stopAndPostEvent()
machine.start();
QTRY_COMPARE(startedSpy.count(), 1);
TEST_RUNNING_CHANGED(true);
+ TEST_ACTIVE_CHANGED(s1, 1);
QSignalSpy stoppedSpy(&machine, &QStateMachine::stopped);
QVERIFY(stoppedSpy.isValid());
machine.stop();
@@ -1900,6 +1974,7 @@ void tst_QStateMachine::stopAndPostEvent()
machine.postEvent(new QEvent(QEvent::User));
QTRY_COMPARE(stoppedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCoreApplication::processEvents();
}
@@ -1907,7 +1982,9 @@ void tst_QStateMachine::stateFinished()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s1_1 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s1_1);
QFinalState *s1_2 = new QFinalState(s1);
s1_1->addTransition(s1_2);
s1->setInitialState(s1_1);
@@ -1921,6 +1998,8 @@ void tst_QStateMachine::stateFinished()
machine.start();
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s1_1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
}
@@ -1997,9 +2076,11 @@ void tst_QStateMachine::parallelRootState()
QCOMPARE(root->childMode(), QState::ParallelStates);
QState *s1 = new QState(root);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *s1_f = new QFinalState(s1);
s1->setInitialState(s1_f);
QState *s2 = new QState(root);
+ DEFINE_ACTIVE_SPY(s2);
QFinalState *s2_f = new QFinalState(s2);
s2->setInitialState(s2_f);
@@ -2018,22 +2099,31 @@ void tst_QStateMachine::parallelRootState()
QVERIFY(machine.configuration().contains(s2_f));
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ QVERIFY(!machine.isRunning());
}
void tst_QStateMachine::allSourceToTargetConfigurations()
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
s0->setObjectName("s0");
QState *s1 = new QState(s0);
+ DEFINE_ACTIVE_SPY(s1);
s1->setObjectName("s1");
QState *s11 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s11);
s11->setObjectName("s11");
QState *s2 = new QState(s0);
+ DEFINE_ACTIVE_SPY(s2);
s2->setObjectName("s2");
QState *s21 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s21);
s21->setObjectName("s21");
QState *s211 = new QState(s21);
+ DEFINE_ACTIVE_SPY(s211);
s211->setObjectName("s211");
QFinalState *f = new QFinalState(&machine);
f->setObjectName("f");
@@ -2064,23 +2154,84 @@ void tst_QStateMachine::allSourceToTargetConfigurations()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s211, 0);
machine.postEvent(new StringEvent("a"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 3);
+ TEST_ACTIVE_CHANGED(s11, 3);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s211, 0);
+
machine.postEvent(new StringEvent("b"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 5);
+ TEST_ACTIVE_CHANGED(s11, 5);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s211, 0);
+
machine.postEvent(new StringEvent("c"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 6);
+ TEST_ACTIVE_CHANGED(s11, 6);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 1);
+ TEST_ACTIVE_CHANGED(s211, 1);
+
machine.postEvent(new StringEvent("d"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 6);
+ TEST_ACTIVE_CHANGED(s11, 6);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 3);
+ TEST_ACTIVE_CHANGED(s211, 3);
+
machine.postEvent(new StringEvent("e"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 6);
+ TEST_ACTIVE_CHANGED(s11, 6);
+ TEST_ACTIVE_CHANGED(s2, 3);
+ TEST_ACTIVE_CHANGED(s21, 5);
+ TEST_ACTIVE_CHANGED(s211, 5);
+
machine.postEvent(new StringEvent("f"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 7);
+ TEST_ACTIVE_CHANGED(s11, 7);
+ TEST_ACTIVE_CHANGED(s2, 4);
+ TEST_ACTIVE_CHANGED(s21, 6);
+ TEST_ACTIVE_CHANGED(s211, 6);
+
machine.postEvent(new StringEvent("g"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 8);
+ TEST_ACTIVE_CHANGED(s11, 8);
+ TEST_ACTIVE_CHANGED(s2, 5);
+ TEST_ACTIVE_CHANGED(s21, 7);
+ TEST_ACTIVE_CHANGED(s211, 7);
+
machine.postEvent(new StringEvent("h"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 4);
+ TEST_ACTIVE_CHANGED(s1, 8);
+ TEST_ACTIVE_CHANGED(s11, 8);
+ TEST_ACTIVE_CHANGED(s2, 6);
+ TEST_ACTIVE_CHANGED(s21, 8);
+ TEST_ACTIVE_CHANGED(s211, 8);
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
@@ -2149,6 +2300,7 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QTest::ignoreMessage(QtWarningMsg, "QState::addTransition: sender cannot be null");
QCOMPARE(s0->addTransition(0, SIGNAL(noSuchSignal()), 0), (QSignalTransition*)0);
@@ -2182,7 +2334,7 @@ void tst_QStateMachine::signalTransitions()
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
-
+ TEST_ACTIVE_CHANGED(s0, 2);
emitter.emitSignalWithNoArg();
trans->setSignal(SIGNAL(signalWithIntArg(int)));
@@ -2192,6 +2344,7 @@ void tst_QStateMachine::signalTransitions()
emitter.emitSignalWithIntArg(123);
QTRY_COMPARE(finishedSpy.count(), 2);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 4);
machine.start();
QCoreApplication::processEvents();
@@ -2200,6 +2353,7 @@ void tst_QStateMachine::signalTransitions()
emitter.emitSignalWithNoArg();
QTRY_COMPARE(finishedSpy.count(), 3);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 6);
SignalEmitter emitter2;
machine.start();
@@ -2208,6 +2362,7 @@ void tst_QStateMachine::signalTransitions()
emitter2.emitSignalWithNoArg();
QTRY_COMPARE(finishedSpy.count(), 4);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 8);
machine.start();
QCoreApplication::processEvents();
@@ -2215,10 +2370,13 @@ void tst_QStateMachine::signalTransitions()
trans->setSignal(SIGNAL(noSuchSignal()));
QCOMPARE(trans->signal(), QByteArray(SIGNAL(noSuchSignal())));
TEST_RUNNING_CHANGED(true);
+ TEST_ACTIVE_CHANGED(s0, 9);
+ QVERIFY(machine.isRunning());
}
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
QSignalTransition *trans = s0->addTransition(&emitter, "signalWithNoArg()", s1);
@@ -2235,23 +2393,27 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
-
+ TEST_ACTIVE_CHANGED(s0, 1);
emitter.emitSignalWithNoArg();
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 2);
trans->setSignal("signalWithIntArg(int)");
QCOMPARE(trans->signal(), QByteArray("signalWithIntArg(int)"));
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
emitter.emitSignalWithIntArg(123);
QTRY_COMPARE(finishedSpy.count(), 2);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 4);
}
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithIntArg(int)), s1);
@@ -2264,11 +2426,12 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
-
+ TEST_ACTIVE_CHANGED(s0, 1);
emitter.emitSignalWithIntArg(123);
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 2);
QCOMPARE(trans->eventTestSenderReceived(), (QObject*)&emitter);
QCOMPARE(trans->eventTestSignalIndexReceived(), emitter.metaObject()->indexOfSignal("signalWithIntArg(int)"));
QCOMPARE(trans->eventTestArgumentsReceived().size(), 1);
@@ -2281,6 +2444,7 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
SignalEmitter emitter;
TestSignalTransition *trans = new TestSignalTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s1);
@@ -2293,12 +2457,14 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
QString testString = QString::fromLatin1("hello");
emitter.emitSignalWithStringArg(testString);
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 2);
QCOMPARE(trans->eventTestSenderReceived(), (QObject*)&emitter);
QCOMPARE(trans->eventTestSignalIndexReceived(), emitter.metaObject()->indexOfSignal("signalWithStringArg(QString)"));
QCOMPARE(trans->eventTestArgumentsReceived().size(), 1);
@@ -2311,6 +2477,7 @@ void tst_QStateMachine::signalTransitions()
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
TestSignalTransition *trans = new TestSignalTransition();
@@ -2332,18 +2499,22 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
emitter.emitSignalWithNoArg();
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s0, 2);
}
// Multiple transitions for same (object,signal)
{
QStateMachine machine;
SignalEmitter emitter;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
QSignalTransition *t1 = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s0);
@@ -2352,28 +2523,38 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 0);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s0));
emitter.emitSignalWithNoArg();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
s0->removeTransition(t0);
emitter.emitSignalWithNoArg();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s0));
emitter.emitSignalWithNoArg();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s0));
s1->removeTransition(t1);
emitter.emitSignalWithNoArg();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s0));
@@ -2381,6 +2562,9 @@ void tst_QStateMachine::signalTransitions()
s1->addTransition(t1);
emitter.emitSignalWithNoArg();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 4);
+ TEST_ACTIVE_CHANGED(s1, 3);
+ QVERIFY(machine.isRunning());
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
}
@@ -2389,6 +2573,7 @@ void tst_QStateMachine::signalTransitions()
QStateMachine machine;
SignalEmitter emitter;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
QFinalState *s2 = new QFinalState(&machine);
@@ -2405,27 +2590,34 @@ void tst_QStateMachine::signalTransitions()
machine.setInitialState(s0);
machine.start();
+ TEST_ACTIVE_CHANGED(s0, 1);
QTRY_COMPARE(startedSpy.count(), 1);
TEST_RUNNING_CHANGED(true);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s0, 2);
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
machine.start();
+ TEST_ACTIVE_CHANGED(s0, 3);
QTRY_COMPARE(startedSpy.count(), 2);
TEST_RUNNING_CHANGED(true);
emitter.emitSignalWithIntArg(123);
+ TEST_ACTIVE_CHANGED(s0, 4);
QTRY_COMPARE(finishedSpy.count(), 2);
TEST_RUNNING_CHANGED(false);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
machine.start();
+ QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 5);
QTRY_COMPARE(startedSpy.count(), 3);
TEST_RUNNING_CHANGED(true);
emitter.emitSignalWithStringArg("hello");
+ TEST_ACTIVE_CHANGED(s0, 6);
QTRY_COMPARE(finishedSpy.count(), 3);
TEST_RUNNING_CHANGED(false);
QCOMPARE(machine.configuration().size(), 1);
@@ -2436,6 +2628,7 @@ void tst_QStateMachine::signalTransitions()
QStateMachine machine;
SignalEmitter emitter;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
QFinalState *s1 = new QFinalState(&machine);
QSignalTransition *t0 = s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
QVERIFY(t0 != 0);
@@ -2453,12 +2646,15 @@ void tst_QStateMachine::signalTransitions()
QVERIFY(runningSpy.isValid());
machine.setInitialState(s0);
machine.start();
+ QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(finishedSpy.count(), 0);
TEST_RUNNING_CHANGED(true);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s0, 2);
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
}
@@ -2848,8 +3044,11 @@ void tst_QStateMachine::historyStates()
QStateMachine machine;
QState *root = &machine;
QState *s0 = new QState(root);
+ DEFINE_ACTIVE_SPY(s0);
QState *s00 = new QState(s0);
+ DEFINE_ACTIVE_SPY(s00);
QState *s01 = new QState(s0);
+ DEFINE_ACTIVE_SPY(s01);
QHistoryState *s0h;
if (x == 0) {
s0h = new QHistoryState(s0);
@@ -2869,6 +3068,7 @@ void tst_QStateMachine::historyStates()
QTest::ignoreMessage(QtWarningMsg, qPrintable(warning));
s0h->setDefaultState(s0);
QState *s1 = new QState(root);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *s2 = new QFinalState(root);
s00->addTransition(new StringTransition("a", s01));
@@ -2885,29 +3085,49 @@ void tst_QStateMachine::historyStates()
QVERIFY(finishedSpy.isValid());
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s00, 1);
+ TEST_ACTIVE_CHANGED(s01, 0);
+ TEST_ACTIVE_CHANGED(s1, 0);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s0));
QVERIFY(machine.configuration().contains(s00));
machine.postEvent(new StringEvent("a"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s00, 2);
+ TEST_ACTIVE_CHANGED(s01, 1);
+ TEST_ACTIVE_CHANGED(s1, 0);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s0));
QVERIFY(machine.configuration().contains(s01));
machine.postEvent(new StringEvent("b"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s00, 2);
+ TEST_ACTIVE_CHANGED(s01, 2);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
machine.postEvent(new StringEvent("c"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 3);
+ TEST_ACTIVE_CHANGED(s00, 2);
+ TEST_ACTIVE_CHANGED(s01, 3);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s0));
QVERIFY(machine.configuration().contains(s01));
machine.postEvent(new StringEvent("d"));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s0, 4);
+ TEST_ACTIVE_CHANGED(s00, 2);
+ TEST_ACTIVE_CHANGED(s01, 4);
+ TEST_ACTIVE_CHANGED(s1, 2);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
@@ -2944,8 +3164,10 @@ void tst_QStateMachine::startAndStop()
QCOMPARE(runningSpy.count(), 0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_COMPARE(machine.isRunning(), true);
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(stoppedSpy.count(), 0);
@@ -2959,6 +3181,7 @@ void tst_QStateMachine::startAndStop()
QCOMPARE(runningSpy.count(), 0);
machine.stop();
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_COMPARE(machine.isRunning(), false);
QTRY_COMPARE(stoppedSpy.count(), 1);
QCOMPARE(startedSpy.count(), 1);
@@ -2969,9 +3192,11 @@ void tst_QStateMachine::startAndStop()
QVERIFY(machine.configuration().contains(s1));
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 3);
machine.stop();
+ TEST_ACTIVE_CHANGED(s1, 3);
QTRY_COMPARE(startedSpy.count(), 2);
- QCOMPARE(stoppedSpy.count(), 2);
+ QTRY_COMPARE(stoppedSpy.count(), 2);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
}
@@ -3003,8 +3228,10 @@ void tst_QStateMachine::setRunning()
QCOMPARE(runningSpy.count(), 0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.setRunning(true);
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_COMPARE(machine.isRunning(), true);
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(stoppedSpy.count(), 0);
@@ -3015,9 +3242,11 @@ void tst_QStateMachine::setRunning()
QTest::ignoreMessage(QtWarningMsg, "QStateMachine::start(): already running");
machine.setRunning(true);
+ TEST_ACTIVE_CHANGED(s1, 1);
QCOMPARE(runningSpy.count(), 0);
machine.setRunning(false);
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_COMPARE(machine.isRunning(), false);
QTRY_COMPARE(stoppedSpy.count(), 1);
QCOMPARE(startedSpy.count(), 1);
@@ -3028,11 +3257,14 @@ void tst_QStateMachine::setRunning()
machine.setRunning(false);
QCOMPARE(runningSpy.count(), 0);
+ TEST_ACTIVE_CHANGED(s1, 1);
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 3);
machine.setRunning(false);
+ TEST_ACTIVE_CHANGED(s1, 3);
QTRY_COMPARE(startedSpy.count(), 2);
- QCOMPARE(stoppedSpy.count(), 2);
+ QTRY_COMPARE(stoppedSpy.count(), 2);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QState *s1_1 = new QState(s1);
QFinalState *s1_2 = new QFinalState(s1);
@@ -3043,6 +3275,7 @@ void tst_QStateMachine::setRunning()
machine.setRunning(false);
QCOMPARE(runningSpy.count(), 0);
machine.setRunning(true);
+ TEST_ACTIVE_CHANGED(s1, 6);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QTRY_COMPARE(startedSpy.count(), 3);
QCOMPARE(stoppedSpy.count(), 2);
@@ -3053,6 +3286,7 @@ void tst_QStateMachine::targetStateWithNoParent()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->setObjectName("s1");
QState s2;
s1->addTransition(&s2);
@@ -3069,6 +3303,7 @@ void tst_QStateMachine::targetStateWithNoParent()
machine.start();
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: No common ancestor for targets and source of transition from state 's1'");
+ TEST_ACTIVE_CHANGED(s1, 2);
QTRY_COMPARE(startedSpy.count(), 1);
QCOMPARE(machine.isRunning(), false);
QCOMPARE(stoppedSpy.count(), 1);
@@ -3098,12 +3333,15 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
propertyHolder->setProperty("b", 2);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(propertyHolder, "a", 3);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "b", 4);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -3112,18 +3350,28 @@ void tst_QStateMachine::defaultGlobalRestorePolicy()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
@@ -3133,17 +3381,20 @@ void tst_QStateMachine::noInitialStateForInitialState()
QStateMachine machine;
QState *initialState = new QState(&machine);
+ DEFINE_ACTIVE_SPY(initialState);
initialState->setObjectName("initialState");
machine.setInitialState(initialState);
QState *childState = new QState(initialState);
+ DEFINE_ACTIVE_SPY(childState);
(void)childState;
QTest::ignoreMessage(QtWarningMsg, "Unrecoverable error detected in running state machine: "
"Missing initial state in compound state 'initialState'");
machine.start();
QCoreApplication::processEvents();
-
+ TEST_ACTIVE_CHANGED(initialState, 1);
+ TEST_ACTIVE_CHANGED(childState, 0);
QCOMPARE(machine.isRunning(), false);
QCOMPARE(int(machine.error()), int(QStateMachine::NoInitialStateError));
}
@@ -3158,12 +3409,15 @@ void tst_QStateMachine::globalRestorePolicySetToDontRestore()
propertyHolder->setProperty("b", 2);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(propertyHolder, "a", 3);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "b", 4);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -3172,18 +3426,28 @@ void tst_QStateMachine::globalRestorePolicySetToDontRestore()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
}
@@ -3198,12 +3462,15 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
propertyHolder->setProperty("b", 2);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(propertyHolder, "a", 3);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "b", 4);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s1->addTransition(new EventTransition(QEvent::User, s2));
s2->addTransition(new EventTransition(QEvent::User, s3));
@@ -3212,18 +3479,28 @@ void tst_QStateMachine::globalRestorePolicySetToRestore()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 3);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("a").toInt(), 1);
QCOMPARE(propertyHolder->property("b").toInt(), 4);
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(propertyHolder->property("a").toInt(), 1);
QCOMPARE(propertyHolder->property("b").toInt(), 2);
}
@@ -3248,7 +3525,9 @@ void tst_QStateMachine::simpleAnimation()
object->setProperty("fooBar", 1.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "fooBar", 2.0);
EventTransition *et = new EventTransition(QEvent::User, s2);
@@ -3257,16 +3536,24 @@ void tst_QStateMachine::simpleAnimation()
s1->addTransition(et);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s2->addTransition(animation, SIGNAL(finished()), s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("fooBar").toDouble(), 2.0);
}
@@ -3292,7 +3579,9 @@ void tst_QStateMachine::twoAnimations()
object->setProperty("bar", 3.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
s2->assignProperty(object, "bar", 10.0);
@@ -3310,15 +3599,23 @@ void tst_QStateMachine::twoAnimations()
s1->addTransition(et);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(s2, SIGNAL(propertiesAssigned()), s3);
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 2.0);
@@ -3335,8 +3632,10 @@ void tst_QStateMachine::twoAnimatedTransitions()
object->setProperty("foo", 1.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 5.0);
QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
EventTransition *trans = new EventTransition(QEvent::User, s2);
@@ -3344,10 +3643,12 @@ void tst_QStateMachine::twoAnimatedTransitions()
trans->addAnimation(fooAnimation);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
s4->assignProperty(object, "foo", 2.0);
QPropertyAnimation *fooAnimation2 = new QPropertyAnimation(object, "foo", s4);
trans = new EventTransition(QEvent::User, s4);
@@ -3355,22 +3656,39 @@ void tst_QStateMachine::twoAnimatedTransitions()
trans->addAnimation(fooAnimation2);
QState *s5 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s5);
QObject::connect(s5, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation2, SIGNAL(finished()), s5);
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 5.0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 2);
+ TEST_ACTIVE_CHANGED(s5, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s5));
QCOMPARE(object->property("foo").toDouble(), 2.0);
}
@@ -3383,8 +3701,10 @@ void tst_QStateMachine::playAnimationTwice()
object->setProperty("foo", 1.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 5.0);
QPropertyAnimation *fooAnimation = new QPropertyAnimation(object, "foo", s2);
EventTransition *trans = new EventTransition(QEvent::User, s2);
@@ -3392,16 +3712,19 @@ void tst_QStateMachine::playAnimationTwice()
trans->addAnimation(fooAnimation);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(fooAnimation, SIGNAL(finished()), s3);
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
s4->assignProperty(object, "foo", 2.0);
trans = new EventTransition(QEvent::User, s4);
s3->addTransition(trans);
trans->addAnimation(fooAnimation);
QState *s5 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s5);
QObject::connect(s5, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s4->addTransition(fooAnimation, SIGNAL(finished()), s5);
@@ -3409,15 +3732,31 @@ void tst_QStateMachine::playAnimationTwice()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 5.0);
machine.postEvent(new QEvent(QEvent::User));
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 2);
+ TEST_ACTIVE_CHANGED(s5, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s5));
QCOMPARE(object->property("foo").toDouble(), 2.0);
}
@@ -3433,15 +3772,19 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
SlotCalledCounter counter;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QState *s2Child = new QState(s2);
+ DEFINE_ACTIVE_SPY(s2Child);
s2Child->assignProperty(object, "bar", 10.0);
s2->setInitialState(s2Child);
QState *s2Child2 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s2Child2);
s2Child2->assignProperty(object, "bar", 11.0);
QAbstractTransition *at = new EventTransition(QEvent::User, s2Child2);
s2Child->addTransition(at);
@@ -3463,6 +3806,7 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
at->addAnimation(animation);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s2->addTransition(s2Child, SIGNAL(propertiesAssigned()), s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
@@ -3470,10 +3814,27 @@ void tst_QStateMachine::nestedTargetStateForAnimation()
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s2Child, 0);
+ TEST_ACTIVE_CHANGED(s2Child2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s2Child, 1);
+ TEST_ACTIVE_CHANGED(s2Child2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s2Child, 2);
+ TEST_ACTIVE_CHANGED(s2Child2, 0);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 2.0);
QCOMPARE(object->property("bar").toDouble(), 10.0);
@@ -3487,10 +3848,13 @@ void tst_QStateMachine::propertiesAssignedSignalTransitionsReuseAnimationGroup()
object->setProperty("foo", 0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(object, "foo", 123);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 456);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s3->assignProperty(object, "foo", 789);
QFinalState *s4 = new QFinalState(&machine);
@@ -3508,13 +3872,17 @@ void tst_QStateMachine::propertiesAssignedSignalTransitionsReuseAnimationGroup()
QSignalSpy machineFinishedSpy(&machine, &QStateMachine::finished);
QVERIFY(machineFinishedSpy.isValid());
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
QTRY_COMPARE(machineFinishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ QVERIFY(!machine.isRunning());
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s4));
QCOMPARE(object->property("foo").toInt(), 789);
-
QCOMPARE(animationFinishedSpy.count(), 2);
+
}
void tst_QStateMachine::animatedGlobalRestoreProperty()
@@ -3528,12 +3896,16 @@ void tst_QStateMachine::animatedGlobalRestoreProperty()
SlotCalledCounter counter;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
QObject::connect(s4, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = new EventTransition(QEvent::User, s2);
@@ -3555,11 +3927,24 @@ void tst_QStateMachine::animatedGlobalRestoreProperty()
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s4));
QCOMPARE(object->property("foo").toDouble(), 1.0);
QCOMPARE(counter.counter, 2);
@@ -3573,8 +3958,10 @@ void tst_QStateMachine::specificTargetValueOfAnimation()
object->setProperty("foo", 1.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QPropertyAnimation *anim = new QPropertyAnimation(object, "foo");
@@ -3584,16 +3971,28 @@ void tst_QStateMachine::specificTargetValueOfAnimation()
trans->addAnimation(anim);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s2->addTransition(anim, SIGNAL(finished()), s3);
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 2.0);
QCOMPARE(anim->endValue().toDouble(), 10.0);
@@ -3609,11 +4008,14 @@ void tst_QStateMachine::addDefaultAnimation()
object->setProperty("foo", 1.0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3625,10 +4027,21 @@ void tst_QStateMachine::addDefaultAnimation()
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 2.0);
@@ -3646,11 +4059,14 @@ void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
SlotCalledCounter counter;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3667,10 +4083,21 @@ void tst_QStateMachine::addDefaultAnimationWithUnusedAnimation()
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("foo").toDouble(), 2.0);
QCOMPARE(counter.counter, 1);
@@ -3727,12 +4154,15 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
SlotCalledCounter counter;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(object, "foo", 2.0);
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QObject::connect(s3, SIGNAL(entered()), QCoreApplication::instance(), SLOT(quit()));
QAbstractTransition *at = new EventTransition(QEvent::User, s2);
@@ -3750,10 +4180,21 @@ void tst_QStateMachine::overrideDefaultAnimationWithSpecific()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+
QCOREAPPLICATION_EXEC(5000);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QVERIFY(machine.configuration().contains(s3));
QCOMPARE(counter.counter, 2); // specific animation started and stopped
@@ -3771,20 +4212,26 @@ void tst_QStateMachine::parallelStateAssignmentsDone()
propertyHolder->setProperty("zoot", 789);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *parallelState = new QState(QState::ParallelStates, &machine);
parallelState->assignProperty(propertyHolder, "foo", 321);
QState *s2 = new QState(parallelState);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "bar", 654);
QState *s3 = new QState(parallelState);
+ DEFINE_ACTIVE_SPY(s3);
s3->assignProperty(propertyHolder, "zoot", 987);
s1->addTransition(new EventTransition(QEvent::User, parallelState));
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QCOMPARE(propertyHolder->property("foo").toInt(), 123);
QCOMPARE(propertyHolder->property("bar").toInt(), 456);
@@ -3793,6 +4240,10 @@ void tst_QStateMachine::parallelStateAssignmentsDone()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(propertyHolder->property("foo").toInt(), 321);
QCOMPARE(propertyHolder->property("bar").toInt(), 654);
QCOMPARE(propertyHolder->property("zoot").toInt(), 987);
@@ -3803,21 +4254,27 @@ void tst_QStateMachine::transitionsFromParallelStateWithNoChildren()
QStateMachine machine;
QState *parallelState = new QState(QState::ParallelStates, &machine);
+ DEFINE_ACTIVE_SPY(parallelState);
machine.setInitialState(parallelState);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
parallelState->addTransition(new EventTransition(QEvent::User, s1));
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(parallelState, 1);
+ TEST_ACTIVE_CHANGED(s1, 0);
QCOMPARE(1, machine.configuration().size());
QVERIFY(machine.configuration().contains(parallelState));
machine.postEvent(new QEvent(QEvent::User));
-
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(parallelState, 2);
+ TEST_ACTIVE_CHANGED(s1, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(1, machine.configuration().size());
QVERIFY(machine.configuration().contains(s1));
}
@@ -3827,23 +4284,35 @@ void tst_QStateMachine::parallelStateTransition()
QStateMachine machine;
QState *parallelState = new QState(QState::ParallelStates, &machine);
+ DEFINE_ACTIVE_SPY(parallelState);
machine.setInitialState(parallelState);
QState *s1 = new QState(parallelState);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(parallelState);
+ DEFINE_ACTIVE_SPY(s2);
QState *s1InitialChild = new QState(s1);
+ DEFINE_ACTIVE_SPY(s1InitialChild);
s1->setInitialState(s1InitialChild);
QState *s2InitialChild = new QState(s2);
+ DEFINE_ACTIVE_SPY(s2InitialChild);
s2->setInitialState(s2InitialChild);
QState *s1OtherChild = new QState(s1);
+ DEFINE_ACTIVE_SPY(s1OtherChild);
s1->addTransition(new EventTransition(QEvent::User, s1OtherChild));
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(parallelState, 1);
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s1InitialChild, 1);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s2InitialChild, 1);
+ TEST_ACTIVE_CHANGED(s1OtherChild, 0);
QVERIFY(machine.configuration().contains(parallelState));
QVERIFY(machine.configuration().contains(s1));
@@ -3855,10 +4324,17 @@ void tst_QStateMachine::parallelStateTransition()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(parallelState, 1);
+ TEST_ACTIVE_CHANGED(s1, 3);
+ TEST_ACTIVE_CHANGED(s1InitialChild, 2);
+ TEST_ACTIVE_CHANGED(s2, 3);
+ TEST_ACTIVE_CHANGED(s2InitialChild, 3);
+ TEST_ACTIVE_CHANGED(s1OtherChild, 1);
+ QVERIFY(machine.isRunning());
+
QVERIFY(machine.configuration().contains(parallelState));
QVERIFY(machine.configuration().contains(s1));
-
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s1OtherChild));
QVERIFY(machine.configuration().contains(s2InitialChild));
@@ -3876,16 +4352,20 @@ void tst_QStateMachine::nestedRestoreProperties()
propertyHolder->setProperty("bar", 2);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "foo", 3);
QState *s21 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s21);
s21->assignProperty(propertyHolder, "bar", 4);
s2->setInitialState(s21);
QState *s22 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s22);
s22->assignProperty(propertyHolder, "bar", 5);
s1->addTransition(new EventTransition(QEvent::User, s2));
@@ -3894,6 +4374,10 @@ void tst_QStateMachine::nestedRestoreProperties()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s22, 0);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
QCOMPARE(propertyHolder->property("foo").toInt(), 1);
@@ -3902,6 +4386,10 @@ void tst_QStateMachine::nestedRestoreProperties()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 1);
+ TEST_ACTIVE_CHANGED(s22, 0);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s21));
@@ -3911,6 +4399,11 @@ void tst_QStateMachine::nestedRestoreProperties()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 2);
+ TEST_ACTIVE_CHANGED(s22, 1);
+ QVERIFY(machine.isRunning());
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s22));
@@ -3928,16 +4421,20 @@ void tst_QStateMachine::nestedRestoreProperties2()
propertyHolder->setProperty("bar", 2);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(propertyHolder, "foo", 3);
QState *s21 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s21);
s21->assignProperty(propertyHolder, "bar", 4);
s2->setInitialState(s21);
QState *s22 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s22);
s22->assignProperty(propertyHolder, "foo", 6);
s22->assignProperty(propertyHolder, "bar", 5);
@@ -3948,6 +4445,10 @@ void tst_QStateMachine::nestedRestoreProperties2()
machine.start();
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s22, 0);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
QCOMPARE(propertyHolder->property("foo").toInt(), 1);
@@ -3956,6 +4457,10 @@ void tst_QStateMachine::nestedRestoreProperties2()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 1);
+ TEST_ACTIVE_CHANGED(s22, 0);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s21));
@@ -3965,6 +4470,10 @@ void tst_QStateMachine::nestedRestoreProperties2()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 2);
+ TEST_ACTIVE_CHANGED(s22, 1);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s22));
@@ -3974,6 +4483,10 @@ void tst_QStateMachine::nestedRestoreProperties2()
machine.postEvent(new QEvent(QEvent::User));
QCoreApplication::processEvents();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 3);
+ TEST_ACTIVE_CHANGED(s22, 2);
QCOMPARE(machine.configuration().size(), 2);
QVERIFY(machine.configuration().contains(s2));
QVERIFY(machine.configuration().contains(s21));
@@ -3986,6 +4499,7 @@ void tst_QStateMachine::nestedStateMachines()
{
QStateMachine machine;
QState *group = new QState(&machine);
+ DEFINE_ACTIVE_SPY(group);
group->setChildMode(QState::ParallelStates);
QStateMachine *subMachines[3];
for (int i = 0; i < 3; ++i) {
@@ -4021,12 +4535,14 @@ void tst_QStateMachine::nestedStateMachines()
QVERIFY(machine.configuration().contains(subMachines[i]));
QCoreApplication::processEvents(); // starts the submachines
+ TEST_ACTIVE_CHANGED(group, 1);
for (int i = 0; i < 3; ++i)
subMachines[i]->postEvent(new QEvent(QEvent::User));
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED(false);
+ TEST_ACTIVE_CHANGED(group, 2);
}
void tst_QStateMachine::goToState()
@@ -4119,7 +4635,9 @@ void tst_QStateMachine::clonedSignals()
SignalEmitter emitter;
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
CloneSignalTransition *t1 = new CloneSignalTransition(&emitter, SIGNAL(signalWithDefaultArg()), s2);
s1->addTransition(t1);
@@ -4130,6 +4648,9 @@ void tst_QStateMachine::clonedSignals()
emitter.emitSignalWithDefaultArg();
QTest::qWait(1);
QCOMPARE(t1->eventSignalIndex, emitter.metaObject()->indexOfSignal("signalWithDefaultArg()"));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ QVERIFY(machine.isRunning());
}
class EventPosterThread : public QThread
@@ -4228,6 +4749,7 @@ void tst_QStateMachine::stopInTransitionToFinalState()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
QFinalState *s2 = new QFinalState(&machine);
QAbstractTransition *t1 = s1->addTransition(s2);
machine.setInitialState(s1);
@@ -4242,7 +4764,6 @@ void tst_QStateMachine::stopInTransitionToFinalState()
QVERIFY(s2EnteredSpy.isValid());
QVERIFY(runningSpy.isValid());
machine.start();
-
// Stopping should take precedence over finished.
QTRY_COMPARE(stoppedSpy.count(), 1);
QCOMPARE(finishedSpy.count(), 0);
@@ -4250,6 +4771,7 @@ void tst_QStateMachine::stopInTransitionToFinalState()
TEST_RUNNING_CHANGED_STARTED_STOPPED;
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
+ TEST_ACTIVE_CHANGED(s1, 2);
}
class StopInEventTestTransition : public QAbstractTransition
@@ -4278,6 +4800,7 @@ void tst_QStateMachine::stopInEventTest()
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->addTransition(new StopInEventTestTransition());
machine.setInitialState(s1);
@@ -4286,6 +4809,7 @@ void tst_QStateMachine::stopInEventTest()
QSignalSpy startedSpy(&machine, &QStateMachine::started);
QVERIFY(startedSpy.isValid());
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_COMPARE(startedSpy.count(), 1);
TEST_RUNNING_CHANGED(true);
@@ -4300,6 +4824,7 @@ void tst_QStateMachine::stopInEventTest()
TEST_RUNNING_CHANGED(false);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s1));
+ TEST_ACTIVE_CHANGED(s1, 1);
}
class IncrementReceiversTest : public QObject
@@ -4320,6 +4845,7 @@ void tst_QStateMachine::testIncrementReceivers()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QFinalState *s2 = new QFinalState(&machine);
@@ -4338,12 +4864,14 @@ void tst_QStateMachine::testIncrementReceivers()
TEST_RUNNING_CHANGED(false);
QCOMPARE(testObject.signalList.size(), 1);
QCOMPARE(testObject.signalList.at(0), QMetaMethod::fromSignal(&IncrementReceiversTest::mySignal));
+ TEST_ACTIVE_CHANGED(s1, 2);
}
void tst_QStateMachine::initialStateIsEnteredBeforeStartedEmitted()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QFinalState *s2 = new QFinalState(&machine);
@@ -4357,12 +4885,14 @@ void tst_QStateMachine::initialStateIsEnteredBeforeStartedEmitted()
machine.start();
QTRY_COMPARE(finishedSpy.count(), 1);
TEST_RUNNING_CHANGED_STARTED_STOPPED;
+ TEST_ACTIVE_CHANGED(s1, 2);
}
void tst_QStateMachine::deletePropertyAssignmentObjectBeforeEntry()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QObject *o1 = new QObject;
@@ -4377,6 +4907,8 @@ void tst_QStateMachine::deletePropertyAssignmentObjectBeforeEntry()
QCOMPARE(o2->objectName(), QString::fromLatin1("bar"));
delete o2;
+ TEST_ACTIVE_CHANGED(s1, 1);
+ QVERIFY(machine.isRunning());
}
void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
@@ -4384,8 +4916,10 @@ void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
QStateMachine machine;
machine.setGlobalRestorePolicy(QState::RestoreProperties);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s1->addTransition(new EventTransition(QEvent::User, s2));
QObject *o1 = new QObject;
@@ -4396,6 +4930,8 @@ void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
QVERIFY(o1->objectName().isEmpty());
QVERIFY(o2->objectName().isEmpty());
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOMPARE(o1->objectName(), QString::fromLatin1("foo"));
QCOMPARE(o2->objectName(), QString::fromLatin1("bar"));
@@ -4407,6 +4943,9 @@ void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
QVERIFY(o2->objectName().isEmpty());
delete o2;
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ QVERIFY(machine.isRunning());
}
void tst_QStateMachine::deleteInitialState()
@@ -4430,24 +4969,36 @@ void tst_QStateMachine::setPropertyAfterRestore()
object->setProperty("a", 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
s1->assignProperty(object, "a", 2);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s1->addTransition(new EventTransition(QEvent::User, s2));
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s3->assignProperty(object, "a", 4);
s2->addTransition(new EventTransition(QEvent::User, s3));
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
s3->addTransition(new EventTransition(QEvent::User, s4));
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOMPARE(object->property("a").toInt(), 2);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(object->property("a").toInt(), 1); // restored
@@ -4456,10 +5007,19 @@ void tst_QStateMachine::setPropertyAfterRestore()
object->setProperty("a", 3);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ TEST_ACTIVE_CHANGED(s4, 0);
QTRY_VERIFY(machine.configuration().contains(s3));
QCOMPARE(object->property("a").toInt(), 4);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 1);
+ QVERIFY(machine.isRunning());
QTRY_VERIFY(machine.configuration().contains(s4));
QCOMPARE(object->property("a").toInt(), 3); // restored
@@ -4484,6 +5044,7 @@ void tst_QStateMachine::transitionWithNoTarget()
object->setProperty("a", 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
s1->assignProperty(object, "a", 2);
EventTransition *t1 = new EventTransition(QEvent::User, /*target=*/0);
@@ -4517,6 +5078,8 @@ void tst_QStateMachine::transitionWithNoTarget()
QCOMPARE(object->property("a").toInt(), 3);
delete object;
+ TEST_ACTIVE_CHANGED(s1, 1);
+ QVERIFY(machine.isRunning());
}
void tst_QStateMachine::initialStateIsFinal()
@@ -4559,53 +5122,95 @@ void tst_QStateMachine::restorePropertiesSimple()
QCOMPARE(po->propWriteCount(), 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(po, "prop", 4);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s1->addTransition(new EventTransition(QEvent::User, s2));
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s3->assignProperty(po, "prop", 6);
s2->addTransition(new EventTransition(QEvent::User, s3));
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
s4->assignProperty(po, "prop", 8);
s3->addTransition(new EventTransition(QEvent::User, s4));
QState *s5 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s5);
s4->addTransition(new EventTransition(QEvent::User, s5));
QState *s6 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s6);
s5->addTransition(new EventTransition(QEvent::User, s6));
machine.start();
-
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
+ TEST_ACTIVE_CHANGED(s6, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOMPARE(po->propWriteCount(), 2);
QCOMPARE(po->prop(), 4);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
+ TEST_ACTIVE_CHANGED(s6, 0);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(po->propWriteCount(), 3);
QCOMPARE(po->prop(), 2); // restored
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ TEST_ACTIVE_CHANGED(s4, 0);
+ TEST_ACTIVE_CHANGED(s5, 0);
+ TEST_ACTIVE_CHANGED(s6, 0);
QTRY_VERIFY(machine.configuration().contains(s3));
QCOMPARE(po->propWriteCount(), 4);
QCOMPARE(po->prop(), 6);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 1);
+ TEST_ACTIVE_CHANGED(s5, 0);
+ TEST_ACTIVE_CHANGED(s6, 0);
QTRY_VERIFY(machine.configuration().contains(s4));
QCOMPARE(po->propWriteCount(), 5);
QCOMPARE(po->prop(), 8);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 2);
+ TEST_ACTIVE_CHANGED(s5, 1);
+ TEST_ACTIVE_CHANGED(s6, 0);
QTRY_VERIFY(machine.configuration().contains(s5));
QCOMPARE(po->propWriteCount(), 6);
QCOMPARE(po->prop(), 2); // restored
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 2);
+ TEST_ACTIVE_CHANGED(s5, 2);
+ TEST_ACTIVE_CHANGED(s6, 1);
+ QVERIFY(machine.isRunning());
QTRY_VERIFY(machine.configuration().contains(s6));
QCOMPARE(po->propWriteCount(), 6);
@@ -4622,76 +5227,158 @@ void tst_QStateMachine::restoreProperties2()
QCOMPARE(po->propWriteCount(), 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(po, "prop", 4);
machine.setInitialState(s1);
QState *s11 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s11);
s1->setInitialState(s11);
QState *s12 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s12);
s11->addTransition(new EventTransition(QEvent::User, s12));
QState *s13 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s13);
s13->assignProperty(po, "prop", 6);
s12->addTransition(new EventTransition(QEvent::User, s13));
QState *s14 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s14);
s14->assignProperty(po, "prop", 8);
s13->addTransition(new EventTransition(QEvent::User, s14));
QState *s15 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s15);
s14->addTransition(new EventTransition(QEvent::User, s15));
QState *s16 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s16);
s15->addTransition(new EventTransition(QEvent::User, s16));
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(po, "prop", 10);
s16->addTransition(new EventTransition(QEvent::User, s2));
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
s2->addTransition(new EventTransition(QEvent::User, s3));
machine.start();
-
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s12, 0);
+ TEST_ACTIVE_CHANGED(s13, 0);
+ TEST_ACTIVE_CHANGED(s14, 0);
+ TEST_ACTIVE_CHANGED(s15, 0);
+ TEST_ACTIVE_CHANGED(s16, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s11));
QCOMPARE(po->propWriteCount(), 2);
QCOMPARE(po->prop(), 4);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 1);
+ TEST_ACTIVE_CHANGED(s13, 0);
+ TEST_ACTIVE_CHANGED(s14, 0);
+ TEST_ACTIVE_CHANGED(s15, 0);
+ TEST_ACTIVE_CHANGED(s16, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s12));
QCOMPARE(po->propWriteCount(), 2);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 1);
+ TEST_ACTIVE_CHANGED(s14, 0);
+ TEST_ACTIVE_CHANGED(s15, 0);
+ TEST_ACTIVE_CHANGED(s16, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s13));
QCOMPARE(po->propWriteCount(), 3);
QCOMPARE(po->prop(), 6);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s14, 1);
+ TEST_ACTIVE_CHANGED(s15, 0);
+ TEST_ACTIVE_CHANGED(s16, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s14));
QCOMPARE(po->propWriteCount(), 4);
QCOMPARE(po->prop(), 8);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s14, 2);
+ TEST_ACTIVE_CHANGED(s15, 1);
+ TEST_ACTIVE_CHANGED(s16, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s15));
QCOMPARE(po->propWriteCount(), 5);
QCOMPARE(po->prop(), 4); // restored s1
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s14, 2);
+ TEST_ACTIVE_CHANGED(s15, 2);
+ TEST_ACTIVE_CHANGED(s16, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s16));
QCOMPARE(po->propWriteCount(), 5);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s14, 2);
+ TEST_ACTIVE_CHANGED(s15, 2);
+ TEST_ACTIVE_CHANGED(s16, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s3, 0);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(po->propWriteCount(), 6);
QCOMPARE(po->prop(), 10);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s14, 2);
+ TEST_ACTIVE_CHANGED(s15, 2);
+ TEST_ACTIVE_CHANGED(s16, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
+ QVERIFY(machine.isRunning());
QTRY_VERIFY(machine.configuration().contains(s3));
QCOMPARE(po->propWriteCount(), 7);
QCOMPARE(po->prop(), 2); // restored original
delete po;
+
}
void tst_QStateMachine::restoreProperties3()
@@ -4704,40 +5391,66 @@ void tst_QStateMachine::restoreProperties3()
QCOMPARE(po->propWriteCount(), 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(po, "prop", 4);
machine.setInitialState(s1);
QState *s11 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s11);
s11->assignProperty(po, "prop", 6);
s1->setInitialState(s11);
QState *s12 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s12);
s11->addTransition(new EventTransition(QEvent::User, s12));
QState *s13 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s13);
s13->assignProperty(po, "prop", 8);
s12->addTransition(new EventTransition(QEvent::User, s13));
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s13->addTransition(new EventTransition(QEvent::User, s2));
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s12, 0);
+ TEST_ACTIVE_CHANGED(s13, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s11));
QCOMPARE(po->propWriteCount(), 3);
QCOMPARE(po->prop(), 6); // s11
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 1);
+ TEST_ACTIVE_CHANGED(s13, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s12));
QCOMPARE(po->propWriteCount(), 4);
QCOMPARE(po->prop(), 4); // restored s1
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s13));
QCOMPARE(po->propWriteCount(), 5);
QCOMPARE(po->prop(), 8);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s13, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ QVERIFY(machine.isRunning());
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(po->propWriteCount(), 6);
QCOMPARE(po->prop(), 2); // restored original
@@ -4759,31 +5472,47 @@ void tst_QStateMachine::restoreProperties4()
QCOMPARE(po2->propWriteCount(), 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->setChildMode(QState::ParallelStates);
machine.setInitialState(s1);
QState *s11 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s11);
QState *s111 = new QState(s11);
+ DEFINE_ACTIVE_SPY(s111);
s111->assignProperty(po1, "prop", 6);
s11->setInitialState(s111);
QState *s112 = new QState(s11);
+ DEFINE_ACTIVE_SPY(s112);
s112->assignProperty(po1, "prop", 8);
s111->addTransition(new EventTransition(QEvent::User, s112));
QState *s12 = new QState(s1);
+ DEFINE_ACTIVE_SPY(s12);
QState *s121 = new QState(s12);
+ DEFINE_ACTIVE_SPY(s121);
s121->assignProperty(po2, "prop", 10);
s12->setInitialState(s121);
QState *s122 = new QState(s12);
+ DEFINE_ACTIVE_SPY(s122);
s122->assignProperty(po2, "prop", 12);
s121->addTransition(new EventTransition(static_cast<QEvent::Type>(QEvent::User+1), s122));
QState *s2 = new QState(&machine);
s112->addTransition(new EventTransition(QEvent::User, s2));
+ DEFINE_ACTIVE_SPY(s2);
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s111, 1);
+ TEST_ACTIVE_CHANGED(s112, 0);
+ TEST_ACTIVE_CHANGED(s12, 1);
+ TEST_ACTIVE_CHANGED(s121, 1);
+ TEST_ACTIVE_CHANGED(s122, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QVERIFY(machine.configuration().contains(s11));
@@ -4796,18 +5525,42 @@ void tst_QStateMachine::restoreProperties4()
QCOMPARE(po2->prop(), 10);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s111, 2);
+ TEST_ACTIVE_CHANGED(s112, 1);
+ TEST_ACTIVE_CHANGED(s12, 1);
+ TEST_ACTIVE_CHANGED(s121, 1);
+ TEST_ACTIVE_CHANGED(s122, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s112));
QCOMPARE(po1->propWriteCount(), 3);
QCOMPARE(po1->prop(), 8);
QCOMPARE(po2->propWriteCount(), 2);
machine.postEvent(new QEvent(static_cast<QEvent::Type>(QEvent::User+1)));
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s11, 1);
+ TEST_ACTIVE_CHANGED(s111, 2);
+ TEST_ACTIVE_CHANGED(s112, 1);
+ TEST_ACTIVE_CHANGED(s12, 1);
+ TEST_ACTIVE_CHANGED(s121, 2);
+ TEST_ACTIVE_CHANGED(s122, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s122));
QCOMPARE(po1->propWriteCount(), 3);
QCOMPARE(po2->propWriteCount(), 3);
QCOMPARE(po2->prop(), 12);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s11, 2);
+ TEST_ACTIVE_CHANGED(s111, 2);
+ TEST_ACTIVE_CHANGED(s112, 2);
+ TEST_ACTIVE_CHANGED(s12, 2);
+ TEST_ACTIVE_CHANGED(s121, 2);
+ TEST_ACTIVE_CHANGED(s122, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(po1->propWriteCount(), 4);
QCOMPARE(po1->prop(), 2); // restored original
@@ -4828,27 +5581,37 @@ void tst_QStateMachine::restorePropertiesSelfTransition()
QCOMPARE(po->propWriteCount(), 1);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(po, "prop", 4);
s1->addTransition(new EventTransition(QEvent::User, s1));
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s1->addTransition(new EventTransition(static_cast<QEvent::Type>(QEvent::User+1), s2));
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOMPARE(po->propWriteCount(), 2);
QCOMPARE(po->prop(), 4);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 3);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_COMPARE(po->propWriteCount(), 3);
QCOMPARE(po->prop(), 4);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 5);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_COMPARE(po->propWriteCount(), 4);
QCOMPARE(po->prop(), 4);
machine.postEvent(new QEvent(static_cast<QEvent::Type>(QEvent::User+1)));
+ TEST_ACTIVE_CHANGED(s1, 6);
+ TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(po->propWriteCount(), 5);
QCOMPARE(po->prop(), 2); // restored
@@ -4867,12 +5630,15 @@ void tst_QStateMachine::changeStateWhileAnimatingProperty()
o2->setProperty("y", 20.);
QState *group = new QState(&machine);
+ DEFINE_ACTIVE_SPY(group);
machine.setInitialState(group);
QState *s0 = new QState(group);
+ DEFINE_ACTIVE_SPY(s0);
group->setInitialState(s0);
QState *s1 = new QState(group);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(o1, "x", 15.);
QPropertyAnimation *a1 = new QPropertyAnimation(o1, "x", s1);
a1->setDuration(800);
@@ -4880,6 +5646,7 @@ void tst_QStateMachine::changeStateWhileAnimatingProperty()
group->addTransition(new EventTransition(QEvent::User, s1));
QState *s2 = new QState(group);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(o2, "y", 25.);
QPropertyAnimation *a2 = new QPropertyAnimation(o2, "y", s2);
a2->setDuration(800);
@@ -4887,23 +5654,46 @@ void tst_QStateMachine::changeStateWhileAnimatingProperty()
group->addTransition(new EventTransition(static_cast<QEvent::Type>(QEvent::User+1), s2));
machine.start();
+ TEST_ACTIVE_CHANGED(group, 1);
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 0);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s0));
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(group, 3);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOREAPPLICATION_EXEC(400);
machine.postEvent(new QEvent(static_cast<QEvent::Type>(QEvent::User+1)));
+ TEST_ACTIVE_CHANGED(group, 5);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOREAPPLICATION_EXEC(300);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(group, 7);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 3);
+ TEST_ACTIVE_CHANGED(s2, 2);
QTRY_VERIFY(machine.configuration().contains(s1));
QCOREAPPLICATION_EXEC(200);
machine.postEvent(new QEvent(static_cast<QEvent::Type>(QEvent::User+1)));
+ TEST_ACTIVE_CHANGED(group, 9);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 4);
+ TEST_ACTIVE_CHANGED(s2, 3);
QTRY_VERIFY(machine.configuration().contains(s2));
QCOREAPPLICATION_EXEC(100);
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(group, 11);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 5);
+ TEST_ACTIVE_CHANGED(s2, 4);
QTRY_VERIFY(machine.configuration().contains(s1));
-
QTRY_COMPARE(o1->property("x").toDouble(), 15.);
QTRY_COMPARE(o2->property("y").toDouble(), 20.);
@@ -4945,15 +5735,19 @@ void tst_QStateMachine::propertiesAreAssignedBeforeEntryCallbacks()
machine.setGlobalRestorePolicy(static_cast<QState::RestorePolicy>(restorePolicy));
AssignPropertyTestState *s1 = new AssignPropertyTestState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
s1->assignProperty(s1, "wasAssigned", true);
machine.setInitialState(s1);
AssignPropertyTestState *s2 = new AssignPropertyTestState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s2->assignProperty(s2, "wasAssigned", true);
s1->addTransition(new EventTransition(QEvent::User, s2));
QVERIFY(!s1->property("wasAssigned").toBool());
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QVERIFY(s1->onEntryPassed);
@@ -4961,6 +5755,8 @@ void tst_QStateMachine::propertiesAreAssignedBeforeEntryCallbacks()
QVERIFY(!s2->property("wasAssigned").toBool());
machine.postEvent(new QEvent(QEvent::User));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
QVERIFY(s2->onEntryPassed);
@@ -4972,18 +5768,26 @@ void tst_QStateMachine::multiTargetTransitionInsideParallelStateGroup()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(QState::ParallelStates, &machine);
+ DEFINE_ACTIVE_SPY(s2);
QState *s21 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s21);
QState *s211 = new QState(s21);
+ DEFINE_ACTIVE_SPY(s211);
QState *s212 = new QState(s21);
+ DEFINE_ACTIVE_SPY(s212);
s21->setInitialState(s212);
QState *s22 = new QState(s2);
+ DEFINE_ACTIVE_SPY(s22);
QState *s221 = new QState(s22);
+ DEFINE_ACTIVE_SPY(s221);
QState *s222 = new QState(s22);
+ DEFINE_ACTIVE_SPY(s222);
s22->setInitialState(s222);
QAbstractTransition *t1 = new EventTransition(QEvent::User, QList<QAbstractState *>() << s211 << s221);
@@ -4991,7 +5795,14 @@ void tst_QStateMachine::multiTargetTransitionInsideParallelStateGroup()
machine.start();
QTRY_VERIFY(machine.configuration().contains(s1));
-
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
+ TEST_ACTIVE_CHANGED(s21, 0);
+ TEST_ACTIVE_CHANGED(s211, 0);
+ TEST_ACTIVE_CHANGED(s212, 0);
+ TEST_ACTIVE_CHANGED(s22, 0);
+ TEST_ACTIVE_CHANGED(s221, 0);
+ TEST_ACTIVE_CHANGED(s222, 0);
machine.postEvent(new QEvent(QEvent::User));
QTRY_VERIFY(machine.configuration().contains(s2));
QCOMPARE(machine.configuration().size(), 5);
@@ -4999,19 +5810,31 @@ void tst_QStateMachine::multiTargetTransitionInsideParallelStateGroup()
QVERIFY(machine.configuration().contains(s211));
QVERIFY(machine.configuration().contains(s22));
QVERIFY(machine.configuration().contains(s221));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
+ TEST_ACTIVE_CHANGED(s21, 1);
+ TEST_ACTIVE_CHANGED(s211, 1);
+ TEST_ACTIVE_CHANGED(s212, 0);
+ TEST_ACTIVE_CHANGED(s22, 1);
+ TEST_ACTIVE_CHANGED(s221, 1);
+ TEST_ACTIVE_CHANGED(s222, 0);
}
void tst_QStateMachine::signalTransitionNormalizeSignature()
{
QStateMachine machine;
QState *s0 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s0);
machine.setInitialState(s0);
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
SignalEmitter emitter;
TestSignalTransition *t0 = new TestSignalTransition(&emitter, SIGNAL(signalWithNoArg()), s1);
s0->addTransition(t0);
machine.start();
+ TEST_ACTIVE_CHANGED(s0, 1);
+ TEST_ACTIVE_CHANGED(s1, 0);
QTRY_VERIFY(machine.configuration().contains(s0));
emitter.emitSignalWithNoArg();
QTRY_VERIFY(machine.configuration().contains(s1));
@@ -5022,44 +5845,60 @@ void tst_QStateMachine::signalTransitionNormalizeSignature()
QCOMPARE(t0->transitionSenderReceived(), (QObject*)&emitter);
QCOMPARE(t0->transitionSignalIndexReceived(), emitter.metaObject()->indexOfSignal("signalWithNoArg()"));
QCOMPARE(t0->transitionArgumentsReceived().size(), 0);
+ TEST_ACTIVE_CHANGED(s0, 2);
+ TEST_ACTIVE_CHANGED(s1, 1);
}
void tst_QStateMachine::createSignalTransitionWhenRunning()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_VERIFY(machine.configuration().contains(s1));
-
// Create by addTransition()
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
SignalEmitter emitter;
QAbstractTransition *t1 = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
QCOMPARE(t1->sourceState(), s1);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 1);
QTRY_VERIFY(machine.configuration().contains(s2));
// Create by constructor that takes sender, signal, source (parent) state
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QSignalTransition *t2 = new QSignalTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
QCOMPARE(t2->sourceState(), s2);
t2->setTargetState(s3);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 1);
QTRY_VERIFY(machine.configuration().contains(s3));
// Create by constructor that takes source (parent) state
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
QSignalTransition *t3 = new QSignalTransition(s3);
QCOMPARE(t3->sourceState(), s3);
t3->setSenderObject(&emitter);
t3->setSignal(SIGNAL(signalWithNoArg()));
t3->setTargetState(s4);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 1);
QTRY_VERIFY(machine.configuration().contains(s4));
// Create by constructor without parent, then set the parent
QState *s5 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s5);
QSignalTransition *t4 = new QSignalTransition();
t4->setSenderObject(&emitter);
t4->setParent(s4);
@@ -5067,6 +5906,11 @@ void tst_QStateMachine::createSignalTransitionWhenRunning()
t4->setSignal(SIGNAL(signalWithNoArg()));
t4->setTargetState(s5);
emitter.emitSignalWithNoArg();
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 2);
+ TEST_ACTIVE_CHANGED(s5, 1);
QTRY_VERIFY(machine.configuration().contains(s5));
}
@@ -5074,12 +5918,15 @@ void tst_QStateMachine::createEventTransitionWhenRunning()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
QTRY_VERIFY(machine.configuration().contains(s1));
// Create by constructor that takes event source, type, source (parent) state
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
QObject object;
QEventTransition *t1 = new QEventTransition(&object, QEvent::Timer, s1);
QCOMPARE(t1->sourceState(), s1);
@@ -5090,6 +5937,7 @@ void tst_QStateMachine::createEventTransitionWhenRunning()
// Create by constructor that takes source (parent) state
QState *s3 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s3);
QEventTransition *t2 = new QEventTransition(s2);
QCOMPARE(t2->sourceState(), s2);
t2->setEventSource(&object);
@@ -5099,6 +5947,7 @@ void tst_QStateMachine::createEventTransitionWhenRunning()
// Create by constructor without parent, then set the parent
QState *s4 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s4);
QEventTransition *t3 = new QEventTransition();
t3->setEventSource(&object);
t3->setParent(s3);
@@ -5106,6 +5955,10 @@ void tst_QStateMachine::createEventTransitionWhenRunning()
t3->setEventType(QEvent::Timer);
t3->setTargetState(s4);
QTRY_VERIFY(machine.configuration().contains(s4));
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ TEST_ACTIVE_CHANGED(s3, 2);
+ TEST_ACTIVE_CHANGED(s4, 1);
}
class SignalEmitterThread : public QThread
@@ -5135,10 +5988,12 @@ void tst_QStateMachine::signalTransitionSenderInDifferentThread()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
SignalEmitterThread thread;
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
s1->addTransition(&thread, SIGNAL(signal1()), s2);
QFinalState *s3 = new QFinalState(&machine);
@@ -5148,29 +6003,41 @@ void tst_QStateMachine::signalTransitionSenderInDifferentThread()
QTRY_VERIFY(thread.isRunning());
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 1);
+ TEST_ACTIVE_CHANGED(s2, 0);
QTRY_VERIFY(machine.configuration().contains(s1));
QMetaObject::invokeMethod(&thread, "emitSignals");
// thread emits both signal1() and signal2(), so we should end in s3
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
+ QTRY_VERIFY(!machine.isRunning());
QTRY_VERIFY(machine.configuration().contains(s3));
// Run the machine again; transitions should still be registered
machine.start();
+ TEST_ACTIVE_CHANGED(s1, 3);
+ TEST_ACTIVE_CHANGED(s2, 2);
QTRY_VERIFY(machine.configuration().contains(s1));
QMetaObject::invokeMethod(&thread, "emitSignals");
QTRY_VERIFY(machine.configuration().contains(s3));
thread.quit();
QTRY_VERIFY(thread.wait());
+ TEST_ACTIVE_CHANGED(s1, 4);
+ TEST_ACTIVE_CHANGED(s2, 4);
+ QVERIFY(!machine.isRunning());
}
void tst_QStateMachine::signalTransitionSenderInDifferentThread2()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
QState *s2 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s2);
SignalEmitter emitter;
// At the time of the transition creation, the machine and the emitter
// are both in the same thread.
@@ -5203,6 +6070,8 @@ void tst_QStateMachine::signalTransitionSenderInDifferentThread2()
thread.quit();
QTRY_VERIFY(thread.wait());
+ TEST_ACTIVE_CHANGED(s1, 2);
+ TEST_ACTIVE_CHANGED(s2, 2);
}
class SignalTransitionMutatorThread : public QThread
@@ -5228,6 +6097,7 @@ void tst_QStateMachine::signalTransitionRegistrationThreadSafety()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
+ DEFINE_ACTIVE_SPY(s1);
machine.setInitialState(s1);
machine.start();
QTRY_VERIFY(machine.configuration().contains(s1));
@@ -5252,6 +6122,8 @@ void tst_QStateMachine::signalTransitionRegistrationThreadSafety()
thread.quit();
QTRY_VERIFY(thread.wait());
+ TEST_ACTIVE_CHANGED(s1, 1);
+ QVERIFY(machine.isRunning());
}
void tst_QStateMachine::childModeConstructor()