diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2012-07-04 23:17:49 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-10 06:21:01 +0200 |
commit | d219ea1ebcd8dee171dab279498961d68dac8812 (patch) | |
tree | 0e2ea598fa50982e10dfe5560732c7ba7de84874 /tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | |
parent | d2a6f8e6dd96b015e2fe5c098331f0fd6387ce43 (diff) |
statemachine: Don't assign properties for transitions with no targets
If the transition has no target states, that means the current state
won't change; hence, property assignments should not be performed.
In particular, properties should not be restored to the values they
had before the state was entered.
Change-Id: I237bbb541f939c272777e70c5f26c886ec457a17
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.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 0a1d0ea35f..6598a74e31 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -191,6 +191,8 @@ private slots: void deletePropertyAssignmentObjectBeforeRestore(); void deleteInitialState(); void setPropertyAfterRestore(); + void transitionWithNoTarget_data(); + void transitionWithNoTarget(); }; class TestState : public QState @@ -4132,5 +4134,58 @@ void tst_QStateMachine::setPropertyAfterRestore() delete object; } +void tst_QStateMachine::transitionWithNoTarget_data() +{ + QTest::addColumn<int>("restorePolicy"); + QTest::newRow("DontRestoreProperties") << int(QStateMachine::DontRestoreProperties); + QTest::newRow("RestoreProperties") << int(QStateMachine::RestoreProperties); +} + +void tst_QStateMachine::transitionWithNoTarget() +{ + QFETCH(int, restorePolicy); + + QStateMachine machine; + machine.setGlobalRestorePolicy(static_cast<QStateMachine::RestorePolicy>(restorePolicy)); + + QObject *object = new QObject; + object->setProperty("a", 1); + + QState *s1 = new QState(&machine); + machine.setInitialState(s1); + s1->assignProperty(object, "a", 2); + EventTransition *t1 = new EventTransition(QEvent::User, /*target=*/0); + s1->addTransition(t1); + + QSignalSpy s1EnteredSpy(s1, SIGNAL(entered())); + QSignalSpy s1ExitedSpy(s1, SIGNAL(exited())); + QSignalSpy t1TriggeredSpy(t1, SIGNAL(triggered())); + + machine.start(); + QTRY_VERIFY(machine.configuration().contains(s1)); + QCOMPARE(s1EnteredSpy.count(), 1); + QCOMPARE(s1ExitedSpy.count(), 0); + QCOMPARE(t1TriggeredSpy.count(), 0); + QCOMPARE(object->property("a").toInt(), 2); + + object->setProperty("a", 3); + + machine.postEvent(new QEvent(QEvent::User)); + QTRY_COMPARE(t1TriggeredSpy.count(), 1); + QCOMPARE(s1EnteredSpy.count(), 1); + QCOMPARE(s1ExitedSpy.count(), 0); + // the assignProperty should not be re-executed, nor should the old value + // be restored + QCOMPARE(object->property("a").toInt(), 3); + + machine.postEvent(new QEvent(QEvent::User)); + QTRY_COMPARE(t1TriggeredSpy.count(), 2); + QCOMPARE(s1EnteredSpy.count(), 1); + QCOMPARE(s1ExitedSpy.count(), 0); + QCOMPARE(object->property("a").toInt(), 3); + + delete object; +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" |