summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-07-04 13:03:48 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-10 06:20:31 +0200
commit2f18e7276298451a48593e7e5bb71a9e9deaffcf (patch)
tree513732d6b350522494373178b4cd2bba11f91b17 /tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
parentbc5a4d28afbd273adeaae75ebd4aeb97337df6ed (diff)
statemachine: Purge restorable properties when they are restored
Previously, a registered restorable property would only be unregistered if the property was animated (see QStateMachinePrivate::_q_animationFinished()). But if a property is set directly, it should also be unregistered; otherwise, the state machine would use the previously saved (stale) value the next time that property should be restored. Change-Id: I5d246aa5355ddd0ba5f81b0186a9f0e4f3bbaa3f Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp')
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index 102f96b1dc..0a1d0ea35f 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -190,6 +190,7 @@ private slots:
void deletePropertyAssignmentObjectBeforeEntry();
void deletePropertyAssignmentObjectBeforeRestore();
void deleteInitialState();
+ void setPropertyAfterRestore();
};
class TestState : public QState
@@ -4086,5 +4087,50 @@ void tst_QStateMachine::deleteInitialState()
QCoreApplication::processEvents();
}
+void tst_QStateMachine::setPropertyAfterRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+
+ QObject *object = new QObject(&machine);
+ object->setProperty("a", 1);
+
+ QState *s1 = new QState(&machine);
+ machine.setInitialState(s1);
+ s1->assignProperty(object, "a", 2);
+
+ QState *s2 = new QState(&machine);
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QState *s3 = new QState(&machine);
+ s3->assignProperty(object, "a", 4);
+ s2->addTransition(new EventTransition(QEvent::User, s3));
+
+ QState *s4 = new QState(&machine);
+ s3->addTransition(new EventTransition(QEvent::User, s4));
+
+ machine.start();
+ QTRY_VERIFY(machine.configuration().contains(s1));
+ QCOMPARE(object->property("a").toInt(), 2);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QTRY_VERIFY(machine.configuration().contains(s2));
+ QCOMPARE(object->property("a").toInt(), 1); // restored
+
+ // Set property outside of state machine; this is the value
+ // that should be remembered in the next transition
+ object->setProperty("a", 3);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QTRY_VERIFY(machine.configuration().contains(s3));
+ QCOMPARE(object->property("a").toInt(), 4);
+
+ machine.postEvent(new QEvent(QEvent::User));
+ QTRY_VERIFY(machine.configuration().contains(s4));
+ QCOMPARE(object->property("a").toInt(), 3); // restored
+
+ delete object;
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"