From 11638dad106cee87eec2f6cafbfd6c7879c5e689 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 30 Oct 2015 12:56:24 +0100 Subject: [PATCH] Add a test case for conflicting transitions This tests a fix: ff3ba1045e8322caa0293b05aecbff4411963ea2 Change-Id: I623b4e270c7eba1af0c4c023e83b6eea50fb45a1 Reviewed-by: Simon Hausmann --- .../qstatemachine/tst_qstatemachine.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 28df7cce7b..cfbb88a123 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -249,6 +249,7 @@ private slots: void qtbug_44783(); void internalTransition(); void conflictingTransition(); + void conflictingTransition2(); void qtbug_46059(); void qtbug_46703(); }; @@ -6448,6 +6449,71 @@ void tst_QStateMachine::conflictingTransition() QVERIFY(machine.isRunning()); } +void tst_QStateMachine::conflictingTransition2() +{ + SignalEmitter emitter; + + QStateMachine machine; + QState s0(&machine); + QState p0(QState::ParallelStates, &s0); + QState p0s1(&p0); + QState p0s2(&p0); + QState p0s3(&p0); + QState s1(&machine); + + machine.setInitialState(&s0); + s0.setInitialState(&p0); + + QSignalTransition *t1 = new QSignalTransition(&emitter, SIGNAL(signalWithNoArg())); + p0s1.addTransition(t1); + QSignalTransition *t2 = p0s2.addTransition(&emitter, SIGNAL(signalWithNoArg()), &p0s1); + QSignalTransition *t3 = p0s3.addTransition(&emitter, SIGNAL(signalWithNoArg()), &s1); + QSignalSpy t1Spy(t1, &QAbstractTransition::triggered); + QSignalSpy t2Spy(t2, &QAbstractTransition::triggered); + QSignalSpy t3Spy(t3, &QAbstractTransition::triggered); + QVERIFY(t1Spy.isValid()); + QVERIFY(t2Spy.isValid()); + QVERIFY(t3Spy.isValid()); + + s0.setObjectName("s0"); + p0.setObjectName("p0"); + p0s1.setObjectName("p0s1"); + p0s2.setObjectName("p0s2"); + p0s3.setObjectName("p0s3"); + s1.setObjectName("s1"); + t1->setObjectName("p0s1->p0s1"); + t2->setObjectName("p0s2->p0s1"); + t3->setObjectName("p0s3->s1"); + + machine.start(); + + QTRY_COMPARE(machine.configuration().contains(&s0), true); + QTRY_COMPARE(machine.configuration().contains(&p0), true); + QTRY_COMPARE(machine.configuration().contains(&p0s1), true); + QTRY_COMPARE(machine.configuration().contains(&p0s2), true); + QTRY_COMPARE(machine.configuration().contains(&p0s3), true); + QTRY_COMPARE(machine.configuration().contains(&s1), false); + + QCOMPARE(t1Spy.count(), 0); + QCOMPARE(t2Spy.count(), 0); + QCOMPARE(t3Spy.count(), 0); + + emitter.emitSignalWithNoArg(); + + QTRY_COMPARE(machine.configuration().contains(&s0), true); + QTRY_COMPARE(machine.configuration().contains(&p0), true); + QTRY_COMPARE(machine.configuration().contains(&p0s1), true); + QTRY_COMPARE(machine.configuration().contains(&p0s2), true); + QTRY_COMPARE(machine.configuration().contains(&p0s3), true); + QTRY_COMPARE(machine.configuration().contains(&s1), false); + + QCOMPARE(t1Spy.count(), 1); + QCOMPARE(t2Spy.count(), 1); + QCOMPARE(t3Spy.count(), 0); // t3 got preempted by t2 + + QVERIFY(machine.isRunning()); +} + void tst_QStateMachine::qtbug_46059() { QStateMachine machine;