diff options
author | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2016-07-27 12:50:32 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2016-07-29 10:55:10 +0000 |
commit | b083929331fedc0b49b18c589e8a4a0d98c2eaf1 (patch) | |
tree | b545366c31fefcdaabd0b6ed6eaf1c304a149eb4 /tests | |
parent | 8fe54cfcf2fd1a3d2dfc44543d78450dafa01793 (diff) |
Provide API for access to all running sub state machines
Change-Id: Ia7209a79dfa0e49c5ec11132d8461d05070e073b
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/compiled/compiled.pro | 1 | ||||
-rw-r--r-- | tests/auto/compiled/topmachine.scxml | 13 | ||||
-rw-r--r-- | tests/auto/compiled/tst_compiled.cpp | 36 | ||||
-rw-r--r-- | tests/auto/compiled/tst_compiled.qrc | 7 |
4 files changed, 56 insertions, 1 deletions
diff --git a/tests/auto/compiled/compiled.pro b/tests/auto/compiled/compiled.pro index e621ee4..713f484 100644 --- a/tests/auto/compiled/compiled.pro +++ b/tests/auto/compiled/compiled.pro @@ -22,3 +22,4 @@ STATECHARTS = \ connection.scxml \ topmachine.scxml +RESOURCES = tst_compiled.qrc diff --git a/tests/auto/compiled/topmachine.scxml b/tests/auto/compiled/topmachine.scxml index 0040144..b733c6a 100644 --- a/tests/auto/compiled/topmachine.scxml +++ b/tests/auto/compiled/topmachine.scxml @@ -1,8 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> -<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="TopMachine"> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="TopMachine" datamodel="ecmascript"> + <datamodel> + <data id="doneCounter" expr="0"/> + </datamodel> <state id="topState"> <invoke type="scxml" id="submachine.1" src="file:submachineA.scxml"/> <invoke type="scxml" id="submachine.2" src="file:submachineA.scxml"/> <invoke type="scxml" id="submachine.3" src="file:submachineB.scxml"/> + <transition event="done.invoke"> + <assign location="doneCounter" expr="doneCounter + 1"/> + <if cond="doneCounter === 3"> + <send event="goToFinal" delay="1s"/> + </if> + </transition> + <transition event="goToFinal" target="finalState"/> </state> + <final id="finalState"/> </scxml> diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp index 6e1b4bf..117f2d9 100644 --- a/tests/auto/compiled/tst_compiled.cpp +++ b/tests/auto/compiled/tst_compiled.cpp @@ -55,6 +55,7 @@ private Q_SLOTS: void connection(); void myConnection(); void topMachine(); + void topMachineDynamic(); }; void tst_Compiled::stateNames() @@ -221,13 +222,48 @@ void tst_Compiled::topMachine() { TopMachine stateMachine; int doneCounter = 0; + int runningSubMachinesCount = 0; stateMachine.connectToEvent("done.invoke.submachine", [&doneCounter](const QScxmlEvent &) { ++doneCounter; }); + + QObject::connect(&stateMachine, &QScxmlStateMachine::runningSubStateMachinesChanged, + [&runningSubMachinesCount](const QVector<QScxmlStateMachine *> &subMachines) { + runningSubMachinesCount = subMachines.count(); + }); + stateMachine.start(); + QTRY_COMPARE(runningSubMachinesCount, 3); + QTRY_COMPARE(doneCounter, 3); + QCOMPARE(stateMachine.runningSubStateMachines().count(), 3); + QTRY_COMPARE(runningSubMachinesCount, 0); +} + +void tst_Compiled::topMachineDynamic() +{ + QScopedPointer<QScxmlStateMachine> stateMachine( + QScxmlStateMachine::fromFile(QString(":/topmachine.scxml"))); + QVERIFY(!stateMachine.isNull()); + int doneCounter = 0; + int runningSubMachinesCount = 0; + + stateMachine->connectToEvent("done.invoke.submachine", [&doneCounter](const QScxmlEvent &) { + ++doneCounter; + }); + + QObject::connect(stateMachine.data(), &QScxmlStateMachine::runningSubStateMachinesChanged, + [&runningSubMachinesCount](const QVector<QScxmlStateMachine *> &subMachines) { + runningSubMachinesCount = subMachines.count(); + }); + + stateMachine->start(); + + QTRY_COMPARE(runningSubMachinesCount, 3); QTRY_COMPARE(doneCounter, 3); + QCOMPARE(stateMachine->runningSubStateMachines().count(), 3); + QTRY_COMPARE(runningSubMachinesCount, 0); } QTEST_MAIN(tst_Compiled) diff --git a/tests/auto/compiled/tst_compiled.qrc b/tests/auto/compiled/tst_compiled.qrc new file mode 100644 index 0000000..43d355c --- /dev/null +++ b/tests/auto/compiled/tst_compiled.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>topmachine.scxml</file> + <file>submachineA.scxml</file> + <file>submachineB.scxml</file> + </qresource> +</RCC> |