diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qstatemachine/tst_qstatemachine.cpp | 188 |
1 files changed, 124 insertions, 64 deletions
diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 05c45ca..40c01bd 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -931,6 +931,7 @@ void tst_QStateMachine::customErrorStateNotInGraph() void tst_QStateMachine::restoreProperties() { QStateMachine machine; + QCOMPARE(machine.globalRestorePolicy(), QStateMachine::DoNotRestoreProperties); machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties); QObject *object = new QObject(&machine); @@ -1094,6 +1095,12 @@ void tst_QStateMachine::stateEntryAndExit() QVERIFY(trans != 0); QCOMPARE(trans->sourceState(), (QAbstractState*)s2); QCOMPARE(trans->targetState(), (QAbstractState*)s3); + { + char warning[256]; + sprintf(warning, "QState::removeTransition: transition %p's source state (%p) is different from this state (%p)", trans, s2, s1); + QTest::ignoreMessage(QtWarningMsg, warning); + s1->removeTransition(trans); + } s2->removeTransition(trans); QCOMPARE(trans->sourceState(), (QAbstractState*)0); QCOMPARE(trans->targetState(), (QAbstractState*)s3); @@ -1106,6 +1113,13 @@ void tst_QStateMachine::stateEntryAndExit() QSignalSpy finishedSpy(&machine, SIGNAL(finished())); machine.setInitialState(s1); QCOMPARE(machine.initialState(), (QAbstractState*)s1); + { + char warning[256]; + sprintf(warning, "QState::setInitialState: state %p is not a child of this state (%p)", machine.rootState(), machine.rootState()); + QTest::ignoreMessage(QtWarningMsg, warning); + machine.setInitialState(machine.rootState()); + QCOMPARE(machine.initialState(), (QAbstractState*)s1); + } QVERIFY(machine.configuration().isEmpty()); globalTick = 0; QVERIFY(!machine.isRunning()); @@ -1238,6 +1252,11 @@ void tst_QStateMachine::assignPropertyWithAnimation() // Single animation { QStateMachine machine; + QVERIFY(machine.animationsEnabled()); + machine.setAnimationsEnabled(false); + QVERIFY(!machine.animationsEnabled()); + machine.setAnimationsEnabled(true); + QVERIFY(machine.animationsEnabled()); QObject obj; obj.setProperty("foo", 321); obj.setProperty("bar", 654); @@ -1338,6 +1357,10 @@ void tst_QStateMachine::assignPropertyWithAnimation() obj.setProperty("bar", 654); QState *s1 = new QState(machine.rootState()); QCOMPARE(s1->childMode(), QState::ExclusiveStates); + s1->setChildMode(QState::ParallelStates); + QCOMPARE(s1->childMode(), QState::ParallelStates); + s1->setChildMode(QState::ExclusiveStates); + QCOMPARE(s1->childMode(), QState::ExclusiveStates); QCOMPARE(s1->initialState(), (QAbstractState*)0); s1->setObjectName("s1"); s1->assignProperty(&obj, "foo", 123); @@ -1411,47 +1434,59 @@ class StringEventPoster : public QState { public: StringEventPoster(QStateMachine *machine, const QString &value, QState *parent = 0) - : QState(parent), m_machine(machine), m_value(value) {} + : QState(parent), m_machine(machine), m_value(value), m_delay(0) {} void setString(const QString &value) { m_value = value; } + void setDelay(int delay) + { m_delay = delay; } protected: virtual void onEntry(QEvent *) { - m_machine->postEvent(new StringEvent(m_value)); + m_machine->postEvent(new StringEvent(m_value), m_delay); } virtual void onExit(QEvent *) {} private: QStateMachine *m_machine; QString m_value; + int m_delay; }; void tst_QStateMachine::postEvent() { - QStateMachine machine; - StringEventPoster *s1 = new StringEventPoster(&machine, "a"); - QFinalState *s2 = new QFinalState; - s1->addTransition(new StringTransition("a", s2)); - machine.addState(s1); - machine.addState(s2); - machine.setInitialState(s1); - QSignalSpy finishedSpy(&machine, SIGNAL(finished())); - machine.start(); - QTRY_COMPARE(finishedSpy.count(), 1); - QCOMPARE(machine.configuration().size(), 1); - QVERIFY(machine.configuration().contains(s2)); + for (int x = 0; x < 2; ++x) { + QStateMachine machine; + { + QEvent e(QEvent::None); + QTest::ignoreMessage(QtWarningMsg, "QStateMachine::postEvent: cannot post event when the state machine is not running"); + machine.postEvent(&e); + } + StringEventPoster *s1 = new StringEventPoster(&machine, "a"); + if (x == 1) + s1->setDelay(100); + QFinalState *s2 = new QFinalState; + s1->addTransition(new StringTransition("a", s2)); + machine.addState(s1); + machine.addState(s2); + machine.setInitialState(s1); + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.start(); + QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s2)); - s1->setString("b"); - QFinalState *s3 = new QFinalState(); - machine.addState(s3); - s1->addTransition(new StringTransition("b", s3)); - finishedSpy.clear(); - machine.start(); - QTRY_COMPARE(finishedSpy.count(), 1); - QCOMPARE(machine.configuration().size(), 1); - QVERIFY(machine.configuration().contains(s3)); + s1->setString("b"); + QFinalState *s3 = new QFinalState(); + machine.addState(s3); + s1->addTransition(new StringTransition("b", s3)); + finishedSpy.clear(); + machine.start(); + QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s3)); + } } void tst_QStateMachine::stateFinished() @@ -1488,6 +1523,12 @@ void tst_QStateMachine::parallelStates() QFinalState *s1_2_f = new QFinalState(s1_2); s1_2_1->addTransition(s1_2_f); s1_2->setInitialState(s1_2_1); + { + char warning[256]; + sprintf(warning, "QState::setInitialState: ignoring attempt to set initial state of parallel state group %p", s1); + QTest::ignoreMessage(QtWarningMsg, warning); + s1->setInitialState(0); + } machine.addState(s1); QFinalState *s2 = new QFinalState(); @@ -1955,53 +1996,72 @@ void tst_QStateMachine::eventTransitions() void tst_QStateMachine::historyStates() { - QStateMachine machine; - QState *root = machine.rootState(); - QState *s0 = new QState(root); - QState *s00 = new QState(s0); - QState *s01 = new QState(s0); - QHistoryState *s0h = new QHistoryState(s0); - QState *s1 = new QState(root); - QFinalState *s2 = new QFinalState(root); - - s00->addTransition(new StringTransition("a", s01)); - s0->addTransition(new StringTransition("b", s1)); - s1->addTransition(new StringTransition("c", s0h)); - s0->addTransition(new StringTransition("d", s2)); - - root->setInitialState(s0); - s0->setInitialState(s00); + for (int x = 0; x < 2; ++x) { + QStateMachine machine; + QState *root = machine.rootState(); + QState *s0 = new QState(root); + QState *s00 = new QState(s0); + QState *s01 = new QState(s0); + QHistoryState *s0h; + if (x == 0) { + s0h = new QHistoryState(s0); + QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory); + s0h->setHistoryType(QHistoryState::DeepHistory); + } else { + s0h = new QHistoryState(QHistoryState::DeepHistory, s0); + } + QCOMPARE(s0h->historyType(), QHistoryState::DeepHistory); + s0h->setHistoryType(QHistoryState::ShallowHistory); + QCOMPARE(s0h->historyType(), QHistoryState::ShallowHistory); + QCOMPARE(s0h->defaultState(), (QAbstractState*)0); + s0h->setDefaultState(s00); + QCOMPARE(s0h->defaultState(), (QAbstractState*)s00); + char warning[256]; + sprintf(warning, "QHistoryState::setDefaultState: state %p does not belong to this history state's group (%p)", s0, s0); + QTest::ignoreMessage(QtWarningMsg, warning); + s0h->setDefaultState(s0); + QState *s1 = new QState(root); + QFinalState *s2 = new QFinalState(root); + + s00->addTransition(new StringTransition("a", s01)); + s0->addTransition(new StringTransition("b", s1)); + s1->addTransition(new StringTransition("c", s0h)); + s0->addTransition(new StringTransition("d", s2)); + + root->setInitialState(s0); + s0->setInitialState(s00); - QSignalSpy finishedSpy(&machine, SIGNAL(finished())); - machine.start(); - QCoreApplication::processEvents(); - QCOMPARE(machine.configuration().size(), 2); - QVERIFY(machine.configuration().contains(s0)); - QVERIFY(machine.configuration().contains(s00)); + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.start(); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 2); + QVERIFY(machine.configuration().contains(s0)); + QVERIFY(machine.configuration().contains(s00)); - machine.postEvent(new StringEvent("a")); - QCoreApplication::processEvents(); - QCOMPARE(machine.configuration().size(), 2); - QVERIFY(machine.configuration().contains(s0)); - QVERIFY(machine.configuration().contains(s01)); + machine.postEvent(new StringEvent("a")); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 2); + QVERIFY(machine.configuration().contains(s0)); + QVERIFY(machine.configuration().contains(s01)); - machine.postEvent(new StringEvent("b")); - QCoreApplication::processEvents(); - QCOMPARE(machine.configuration().size(), 1); - QVERIFY(machine.configuration().contains(s1)); + machine.postEvent(new StringEvent("b")); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); - machine.postEvent(new StringEvent("c")); - QCoreApplication::processEvents(); - QCOMPARE(machine.configuration().size(), 2); - QVERIFY(machine.configuration().contains(s0)); - QVERIFY(machine.configuration().contains(s01)); + machine.postEvent(new StringEvent("c")); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 2); + QVERIFY(machine.configuration().contains(s0)); + QVERIFY(machine.configuration().contains(s01)); - machine.postEvent(new StringEvent("d")); - QCoreApplication::processEvents(); - QCOMPARE(machine.configuration().size(), 1); - QVERIFY(machine.configuration().contains(s2)); + machine.postEvent(new StringEvent("d")); + QCoreApplication::processEvents(); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s2)); - QTRY_COMPARE(finishedSpy.count(), 1); + QTRY_COMPARE(finishedSpy.count(), 1); + } } void tst_QStateMachine::startAndStop() |