diff options
author | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-04-13 13:54:20 +0200 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-05-04 12:49:28 +0000 |
commit | c07f5b801bd6a94fe862073eb1f1965115a56385 (patch) | |
tree | 13fbe91bc46fed866abdd8a22aa27529a6f550b1 /tests/auto | |
parent | bd15b23987e9d6d1f42fa8987e5c1ff5a1eeee8b (diff) |
QStateMachine: add internal transitions.
The behavior of "external" and "internal" transitions is identical,
except in the case of a transition whose source state is a compound
state and whose target(s) is a descendant of the source. In such a case,
an internal transition will not exit and re-enter its source state,
while an external one will.
[ChangeLog][State machine] Added support for internal transitions.
Change-Id: I9efb1e7368ee52aa2544eb84709a00ae3d5350d3
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 9fb2e40cb8..6ddfb828e8 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -247,6 +247,7 @@ private slots: void qtbug_44963(); void qtbug_44783(); + void internalTransition(); }; class TestState : public QState @@ -6338,5 +6339,48 @@ void tst_QStateMachine::qtbug_44783() QVERIFY(machine.isRunning()); } +void tst_QStateMachine::internalTransition() +{ + SignalEmitter emitter; + + QStateMachine machine; + QState *s = new QState(&machine); + QState *s1 = new QState(s); + QState *s11 = new QState(s1); + + DEFINE_ACTIVE_SPY(s); + DEFINE_ACTIVE_SPY(s1); + DEFINE_ACTIVE_SPY(s11); + + machine.setInitialState(s); + s->setInitialState(s1); + s1->setInitialState(s11); + QSignalTransition *t = s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s11); + t->setObjectName("s1->s11"); + t->setTransitionType(QAbstractTransition::InternalTransition); + + s->setObjectName("s"); + s1->setObjectName("s1"); + s11->setObjectName("s11"); + + machine.start(); + + QTRY_COMPARE(machine.configuration().contains(s), true); + QTRY_COMPARE(machine.configuration().contains(s1), true); + QTRY_COMPARE(machine.configuration().contains(s11), true); + TEST_ACTIVE_CHANGED(s, 1); + TEST_ACTIVE_CHANGED(s1, 1); + TEST_ACTIVE_CHANGED(s11, 1); + + emitter.emitSignalWithNoArg(); + + QTRY_COMPARE(machine.configuration().contains(s), true); + QTRY_COMPARE(machine.configuration().contains(s1), true); + QTRY_COMPARE(machine.configuration().contains(s11), true); + TEST_ACTIVE_CHANGED(s11, 3); + TEST_ACTIVE_CHANGED(s1, 1); // external transitions will return 3, internal transitions should return 1. + TEST_ACTIVE_CHANGED(s, 1); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" |