summaryrefslogtreecommitdiffstats
path: root/tests/auto/qstatemachine
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-04-30 07:49:09 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-04-30 07:49:09 (GMT)
commit9e6311a7fd23a9fb7bb3a8a8edc78cddddc3f807 (patch)
treeecc66b0e452f785fb091a2d45245d2911a481b0c /tests/auto/qstatemachine
parent0d33e6e464c324d1b43b08ce7ac0dcd4c216d17e (diff)
downloadQt-9e6311a7fd23a9fb7bb3a8a8edc78cddddc3f807.zip
Qt-9e6311a7fd23a9fb7bb3a8a8edc78cddddc3f807.tar.gz
Qt-9e6311a7fd23a9fb7bb3a8a8edc78cddddc3f807.tar.bz2
The intuitive interpretation of RestoreProperties is that a value is
potentially restored once the state that set it is exited. So if you have a parent state P which sets 'foo' and then several child states of P, the property should not be restored as long as P is active, regardless of which transitions are taken inside P and what properties are being assigned there. Before, we would restore the property when we entered a state that did not assign it, ignoring what properties where being assigned in the parent.
Diffstat (limited to 'tests/auto/qstatemachine')
-rw-r--r--tests/auto/qstatemachine/tst_qstatemachine.cpp56
1 files changed, 55 insertions, 1 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp
index 7f0d39b..fa4c233 100644
--- a/tests/auto/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp
@@ -140,6 +140,7 @@ private slots:
void transitionsFromParallelStateWithNoChildren();
void parallelStateTransition();
void parallelStateAssignmentsDone();
+ void nestedRestoreProperties();
void simpleAnimation();
void twoAnimations();
@@ -3045,7 +3046,7 @@ void tst_QStateMachine::transitionsFromParallelStateWithNoChildren()
{
QStateMachine machine;
- QState *parallelState = new QState(QState::ParallelGroup, machine.rootState());
+ QState *parallelState = new QState(QState::ParallelStates, machine.rootState());
machine.setInitialState(parallelState);
QState *s1 = new QState(machine.rootState());
@@ -3109,6 +3110,59 @@ void tst_QStateMachine::parallelStateTransition()
}
+void tst_QStateMachine::nestedRestoreProperties()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *propertyHolder = new QObject(&machine);
+ propertyHolder->setProperty("foo", 1);
+ propertyHolder->setProperty("bar", 2);
+
+ QState *s1 = new QState(machine.rootState());
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(machine.rootState());
+ s2->assignProperty(propertyHolder, "foo", 3);
+
+ QState *s21 = new QState(s2);
+ s21->assignProperty(propertyHolder, "bar", 4);
+ s2->setInitialState(s21);
+
+ QState *s22 = new QState(s2);
+ s22->assignProperty(propertyHolder, "bar", 5);
+
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+ s21->addTransition(new EventTransition(QEvent::User, s22));
+
+ machine.start();
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 1);
+ QVERIFY(machine.configuration().contains(s1));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 1);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s21));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QCoreApplication::processEvents();
+
+ QCOMPARE(machine.configuration().size(), 2);
+ QVERIFY(machine.configuration().contains(s2));
+ QVERIFY(machine.configuration().contains(s22));
+ QCOMPARE(propertyHolder->property("foo").toInt(), 3);
+ QCOMPARE(propertyHolder->property("bar").toInt(), 5);
+}
+
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"