From: Kent Hansen Date: Thu, 31 May 2012 10:17:02 +0000 (+0200) Subject: Fix typos in QState sorting functions X-Git-Tag: 071012110112~618 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=268216570881cfc7d066d8183047d05829e1248b;p=profile%2Fivi%2Fqtbase.git 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 --- diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 21c3ab5..fd190ab 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 beca75b..df6ac88 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()