summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-05-31 12:17:02 +0200
committerQt by Nokia <qt-info@nokia.com>2012-06-04 16:50:24 +0200
commit268216570881cfc7d066d8183047d05829e1248b (patch)
tree3f5fd5b80a0d25fa7ebbfb1e72a1bfea9c3ffc74
parent939aa5113859768f058ed663a10e26f82a5db287 (diff)
Fix typos in QState sorting functions
A QObject can't be a child of itself, so the comparison always returned false. In practice, this was causing the entry/exit order of parallel states to be random. QObject::children() is documented to contain the children in the order in which they were added, so this fix actually achieves deterministic behavior. Task-number: QTBUG-25959 Change-Id: Id3f12d6bfbc249f1d4fed0bafb7d0217093e458e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
-rw-r--r--src/corelib/statemachine/qstatemachine.cpp8
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp19
2 files changed, 21 insertions, 6 deletions
diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp
index 21c3ab50b5..fd190abc01 100644
--- a/src/corelib/statemachine/qstatemachine.cpp
+++ b/src/corelib/statemachine/qstatemachine.cpp
@@ -252,8 +252,8 @@ static int indexOfDescendant(QState *s, QAbstractState *desc)
bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState *s2)
{
if (s1->parent() == s2->parent()) {
- return s1->children().indexOf(s1)
- < s2->children().indexOf(s2);
+ return s1->parent()->children().indexOf(s1)
+ < s2->parent()->children().indexOf(s2);
} else if (isDescendantOf(s1, s2)) {
return false;
} else if (isDescendantOf(s2, s1)) {
@@ -270,8 +270,8 @@ bool QStateMachinePrivate::stateEntryLessThan(QAbstractState *s1, QAbstractState
bool QStateMachinePrivate::stateExitLessThan(QAbstractState *s1, QAbstractState *s2)
{
if (s1->parent() == s2->parent()) {
- return s1->children().indexOf(s1)
- < s2->children().indexOf(s2);
+ return s1->parent()->children().indexOf(s1)
+ < s2->parent()->children().indexOf(s2);
} else if (isDescendantOf(s1, s2)) {
return true;
} else if (isDescendantOf(s2, s1)) {
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index beca75b9fc..df6ac88f47 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -1771,12 +1771,12 @@ void tst_QStateMachine::parallelStates()
QState *s1 = new QState(QState::ParallelStates);
QCOMPARE(s1->childMode(), QState::ParallelStates);
- QState *s1_1 = new QState(s1);
+ TestState *s1_1 = new TestState(s1);
QState *s1_1_1 = new QState(s1_1);
QFinalState *s1_1_f = new QFinalState(s1_1);
s1_1_1->addTransition(s1_1_f);
s1_1->setInitialState(s1_1_1);
- QState *s1_2 = new QState(s1);
+ TestState *s1_2 = new TestState(s1);
QState *s1_2_1 = new QState(s1_2);
QFinalState *s1_2_f = new QFinalState(s1_2);
s1_2_1->addTransition(s1_2_f);
@@ -1797,10 +1797,25 @@ void tst_QStateMachine::parallelStates()
machine.setInitialState(s1);
QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
QVERIFY(finishedSpy.isValid());
+ globalTick = 0;
machine.start();
QTRY_COMPARE(finishedSpy.count(), 1);
QCOMPARE(machine.configuration().size(), 1);
QVERIFY(machine.configuration().contains(s2));
+
+ // s1_1 is entered
+ QCOMPARE(s1_1->events.count(), 2);
+ QCOMPARE(s1_1->events.at(0).first, 0);
+ QCOMPARE(s1_1->events.at(0).second, TestState::Entry);
+ // s1_2 is entered
+ QCOMPARE(s1_2->events.at(0).first, 1);
+ QCOMPARE(s1_2->events.at(0).second, TestState::Entry);
+ // s1_1 is exited
+ QCOMPARE(s1_1->events.at(1).first, 2);
+ QCOMPARE(s1_1->events.at(1).second, TestState::Exit);
+ // s1_2 is exited
+ QCOMPARE(s1_2->events.at(1).first, 3);
+ QCOMPARE(s1_2->events.at(1).second, TestState::Exit);
}
void tst_QStateMachine::parallelRootState()