summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2017-08-15 13:04:54 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2017-08-15 13:53:59 +0000
commit5a4550879d30d1897e9b62e4fb73e7392c4182b8 (patch)
tree18f55796e870b03ce268bb50c589c5f38097d3c8
parent8af8db3810ec2d8d2d923f39e23512d30ae234d9 (diff)
Fix the crash when sending an event into not running sevice
Task-number: QTBUG-61484 Change-Id: I3cebb3378a73d16901b18ec9465bcacf2e5ad486 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/scxml/qscxmlstatemachine.cpp2
-rw-r--r--tests/auto/statemachine/multipleinvokableservices.scxml48
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp19
-rw-r--r--tests/auto/statemachine/tst_statemachine.qrc1
4 files changed, 68 insertions, 2 deletions
diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp
index 9767a03..cc190fb 100644
--- a/src/scxml/qscxmlstatemachine.cpp
+++ b/src/scxml/qscxmlstatemachine.cpp
@@ -2198,7 +2198,7 @@ bool QScxmlStateMachine::isDispatchableTarget(const QString &target) const
if (target.startsWith(QStringLiteral("#_"))) {
QStringRef targetId = target.midRef(2);
for (auto invokedService : d->m_invokedServices) {
- if (invokedService.service->id() == targetId)
+ if (invokedService.service && invokedService.service->id() == targetId)
return true;
}
}
diff --git a/tests/auto/statemachine/multipleinvokableservices.scxml b/tests/auto/statemachine/multipleinvokableservices.scxml
new file mode 100644
index 0000000..8b20695
--- /dev/null
+++ b/tests/auto/statemachine/multipleinvokableservices.scxml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="MultipleInvokableServices.scxml" datamodel="ecmascript" initial="TopState">
+ <datamodel>
+ <data id="Var"/>
+ </datamodel>
+ <state id="TopState">
+ <state id="State1">
+ <invoke id="invoke1">
+ <content>
+ <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="anywhere">
+ <state id="foo">
+ <onentry>
+ <send target="#_parent" event="running1"/>
+ </onentry>
+ <transition event="toChild">
+ <send target="#_parent" event="received1"/>
+ </transition>
+ </state>
+ </scxml>
+ </content>
+ </invoke>
+ </state>
+ <state id="State2">
+ <invoke id="invoke2">
+ <content>
+ <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" binding="early" name="anywhere">
+ <state id="foo">
+ <onentry>
+ <send target="#_parent" event="running2"/>
+ </onentry>
+ </state>
+ </scxml>
+ </content>
+ </invoke>
+ </state>
+ <transition event="running1">
+ <send event="toChild" target="#_invoke1"/>
+ </transition>
+ <transition event="received1">
+ <assign location="Var" expr="1"/>
+ <send event="toChild" target="#_invoke2"/>
+ </transition>
+ <transition event="error.communication" cond="Var == 1" target="success"/>
+ <transition event="*" target="failure"/>
+ </state>
+ <final id="success"/>
+ <final id="failure"/>
+</scxml>
diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp
index 69d38b6..4575737 100644
--- a/tests/auto/statemachine/tst_statemachine.cpp
+++ b/tests/auto/statemachine/tst_statemachine.cpp
@@ -56,6 +56,8 @@ private Q_SLOTS:
void running();
void invokeStateMachine();
+
+ void multipleInvokableServices(); // QTBUG-61484
};
void tst_StateMachine::stateNames_data()
@@ -384,7 +386,6 @@ void tst_StateMachine::doneDotStateEvent()
finishedSpy.wait(5000);
QCOMPARE(finishedSpy.count(), 1);
QCOMPARE(stateMachine->activeStateNames(true).size(), 1);
- qDebug() << stateMachine->activeStateNames(true);
QVERIFY(stateMachine->activeStateNames(true).contains(QLatin1String("success")));
}
@@ -428,6 +429,22 @@ void tst_StateMachine::invokeStateMachine()
QTRY_VERIFY(subMachine->activeStateNames().contains("here"));
}
+void tst_StateMachine::multipleInvokableServices()
+{
+ QScopedPointer<QScxmlStateMachine> stateMachine(
+ QScxmlStateMachine::fromFile(QString(":/tst_statemachine/multipleinvokableservices.scxml")));
+ QVERIFY(!stateMachine.isNull());
+
+ QSignalSpy finishedSpy(stateMachine.data(), SIGNAL(finished()));
+ stateMachine->start();
+ QCOMPARE(stateMachine->isRunning(), true);
+
+ finishedSpy.wait(5000);
+ QCOMPARE(finishedSpy.count(), 1);
+ QCOMPARE(stateMachine->activeStateNames(true).size(), 1);
+ QVERIFY(stateMachine->activeStateNames(true).contains(QLatin1String("success")));
+}
+
QTEST_MAIN(tst_StateMachine)
#include "tst_statemachine.moc"
diff --git a/tests/auto/statemachine/tst_statemachine.qrc b/tests/auto/statemachine/tst_statemachine.qrc
index 78c1f00..0bd68ff 100644
--- a/tests/auto/statemachine/tst_statemachine.qrc
+++ b/tests/auto/statemachine/tst_statemachine.qrc
@@ -7,5 +7,6 @@
<file>stateDotDoneEvent.scxml</file>
<file>invoke.scxml</file>
<file>historystate.scxml</file>
+ <file>multipleinvokableservices.scxml</file>
</qresource>
</RCC>