summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-07-02 20:45:49 +0200
committerQt by Nokia <qt-info@nokia.com>2012-07-10 06:20:07 +0200
commitba87568655dad3e830e692109b5e571ae78b71a0 (patch)
treec9fb40d7ebdd75d8787794b6ae31f7b7f0ab610f /tests/auto/corelib/statemachine
parent482205d847a15e2afc7988c1792aaeb37e71505f (diff)
statemachine: Don't crash if property assignment target is deleted
Do like QPropertyAnimation and store the QObject in a QPointer. Purge the assignments list upon state entry and property restore. Change-Id: I54a56885a2905178ab6aa5cf292b3d25c86b7a97 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'tests/auto/corelib/statemachine')
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index 862ff96760..6fde415f2a 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -187,6 +187,8 @@ private slots:
void testIncrementReceivers();
void initialStateIsEnteredBeforeStartedEmitted();
+ void deletePropertyAssignmentObjectBeforeEntry();
+ void deletePropertyAssignmentObjectBeforeRestore();
};
class TestState : public QState
@@ -4021,5 +4023,55 @@ void tst_QStateMachine::initialStateIsEnteredBeforeStartedEmitted()
QTRY_COMPARE(finishedSpy.count(), 1);
}
+void tst_QStateMachine::deletePropertyAssignmentObjectBeforeEntry()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(&machine);
+ machine.setInitialState(s1);
+
+ QObject *o1 = new QObject;
+ s1->assignProperty(o1, "objectName", "foo");
+ delete o1;
+ QObject *o2 = new QObject;
+ s1->assignProperty(o2, "objectName", "bar");
+
+ machine.start();
+ // Shouldn't crash
+ QTRY_VERIFY(machine.configuration().contains(s1));
+
+ QCOMPARE(o2->objectName(), QString::fromLatin1("bar"));
+ delete o2;
+}
+
+void tst_QStateMachine::deletePropertyAssignmentObjectBeforeRestore()
+{
+ QStateMachine machine;
+ machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
+ QState *s1 = new QState(&machine);
+ machine.setInitialState(s1);
+ QState *s2 = new QState(&machine);
+ s1->addTransition(new EventTransition(QEvent::User, s2));
+
+ QObject *o1 = new QObject;
+ s1->assignProperty(o1, "objectName", "foo");
+ QObject *o2 = new QObject;
+ s1->assignProperty(o2, "objectName", "bar");
+
+ QVERIFY(o1->objectName().isEmpty());
+ QVERIFY(o2->objectName().isEmpty());
+ machine.start();
+ QTRY_VERIFY(machine.configuration().contains(s1));
+ QCOMPARE(o1->objectName(), QString::fromLatin1("foo"));
+ QCOMPARE(o2->objectName(), QString::fromLatin1("bar"));
+
+ delete o1;
+ machine.postEvent(new QEvent(QEvent::User));
+ // Shouldn't crash
+ QTRY_VERIFY(machine.configuration().contains(s2));
+
+ QVERIFY(o2->objectName().isEmpty());
+ delete o2;
+}
+
QTEST_MAIN(tst_QStateMachine)
#include "tst_qstatemachine.moc"