From d19ed9d337b79a3dc88690db66a8ea8d4482cddd Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 22 May 2009 16:41:41 +0200 Subject: add tests for multiple signal/event transitions from same source --- tests/auto/qstatemachine/tst_qstatemachine.cpp | 68 ++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/auto/qstatemachine/tst_qstatemachine.cpp b/tests/auto/qstatemachine/tst_qstatemachine.cpp index 6de7e1a..c01d077 100644 --- a/tests/auto/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/qstatemachine/tst_qstatemachine.cpp @@ -1815,6 +1815,43 @@ void tst_QStateMachine::signalTransitions() QCOMPARE(machine.configuration().size(), 1); QVERIFY(machine.configuration().contains(s1)); } + // multiple signal transitions from same source + { + QStateMachine machine; + SignalEmitter emitter; + QState *s0 = new QState(machine.rootState()); + QFinalState *s1 = new QFinalState(machine.rootState()); + s0->addTransition(&emitter, SIGNAL(signalWithNoArg()), s1); + QFinalState *s2 = new QFinalState(machine.rootState()); + s0->addTransition(&emitter, SIGNAL(signalWithIntArg(int)), s2); + QFinalState *s3 = new QFinalState(machine.rootState()); + s0->addTransition(&emitter, SIGNAL(signalWithStringArg(QString)), s3); + + QSignalSpy startedSpy(&machine, SIGNAL(started())); + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.setInitialState(s0); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + emitter.emitSignalWithNoArg(); + QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 2); + emitter.emitSignalWithIntArg(123); + QTRY_COMPARE(finishedSpy.count(), 2); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s2)); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 3); + emitter.emitSignalWithStringArg("hello"); + QTRY_COMPARE(finishedSpy.count(), 3); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s3)); + } } void tst_QStateMachine::eventTransitions() @@ -2024,6 +2061,37 @@ void tst_QStateMachine::eventTransitions() QCOMPARE(machine.configuration().size(), 1); QVERIFY(machine.configuration().contains(s1)); } + // multiple event transitions from same source + { + QStateMachine machine; + QState *s0 = new QState(machine.rootState()); + QFinalState *s1 = new QFinalState(machine.rootState()); + QFinalState *s2 = new QFinalState(machine.rootState()); + QEventTransition *t0 = new QEventTransition(&button, QEvent::MouseButtonPress); + t0->setTargetState(s1); + s0->addTransition(t0); + QEventTransition *t1 = new QEventTransition(&button, QEvent::MouseButtonRelease); + t1->setTargetState(s2); + s0->addTransition(t1); + + QSignalSpy startedSpy(&machine, SIGNAL(started())); + QSignalSpy finishedSpy(&machine, SIGNAL(finished())); + machine.setInitialState(s0); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 1); + QTest::mousePress(&button, Qt::LeftButton); + QTRY_COMPARE(finishedSpy.count(), 1); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s1)); + + machine.start(); + QTRY_COMPARE(startedSpy.count(), 2); + QTest::mouseRelease(&button, Qt::LeftButton); + QTRY_COMPARE(finishedSpy.count(), 2); + QCOMPARE(machine.configuration().size(), 1); + QVERIFY(machine.configuration().contains(s2)); + } } void tst_QStateMachine::historyStates() -- cgit v0.12