From 0cd34a0c39bf443f1ea6f6868ac6fbc0fc2c9e6d Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 19 Jun 2015 11:11:31 +0200 Subject: StateMachine: remove initial state for parallel states. A parallel state cannot have an initial state, as all children of the parallel state will be entered. Setting such an initial state on a QState marked as ParallelStates would already produce a warning and ignore the initial state. Now any initial state that has been set before changing the child-mode to ParallelStates will also produce a warning and remove the previously set initial state. Change-Id: Ie5fcd44b03516744f785f2d1880bf806918c44d4 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../corelib/statemachine/qstate/tst_qstate.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp index ac3374b6a3..c64d55671a 100644 --- a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp +++ b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp @@ -47,6 +47,7 @@ private slots: void historyInitialState(); void transitions(); void privateSignals(); + void parallelStateAndInitialState(); }; class TestClass: public QObject @@ -344,5 +345,35 @@ void tst_QState::privateSignals() } +void tst_QState::parallelStateAndInitialState() +{ + QStateMachine machine; + + { // setting an initial state on a parallel state: + QState a(QState::ParallelStates, &machine); + QState b(&a); + QVERIFY(!a.initialState()); + const QString warning + = QString::asprintf("QState::setInitialState: ignoring attempt to set initial state of parallel state group %p", &a); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + a.setInitialState(&b); // should produce a warning and do nothing. + QVERIFY(!a.initialState()); + } + + { // setting the child-mode from ExclusiveStates to ParallelStates should remove the initial state: + QState a(QState::ExclusiveStates, &machine); + QState b(&a); + a.setInitialState(&b); + QCOMPARE(a.initialState(), &b); + const QString warning + = QString::asprintf("QState::setChildMode: setting the child-mode of state %p to " + "parallel removes the initial state", &a); + QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); + a.setChildMode(QState::ParallelStates); // should produce a warning and remove the initial state + QVERIFY(!a.initialState()); + QCOMPARE(a.childMode(), QState::ParallelStates); + } +} + QTEST_MAIN(tst_QState) #include "tst_qstate.moc" -- cgit v1.2.3