summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2016-04-06 13:44:13 +0200
committerUlf Hermann <ulf.hermann@theqtcompany.com>2016-04-18 08:07:17 +0000
commit382aac3e7877c151eaef5f7bb3fedefc10a8f284 (patch)
tree3123ddc4f55b37ad9c6b924345f667520eceb421
parent8dee4c71a563c39fb622e054f5cdacdd797f41fb (diff)
Don't crash when trying to execute things in the null data model
Rather raise error.execution, as mandated by the standard (in most of those cases). Change-Id: If2e200693198b70b4bf067011318f0d78c44653b Reviewed-by: Jarek Kobus <jaroslaw.kobus@theqtcompany.com>
-rw-r--r--src/scxml/qscxmlnulldatamodel.cpp30
-rw-r--r--tests/auto/compiled/compiled.pro3
-rw-r--r--tests/auto/compiled/datainnulldatamodel.scxml7
-rw-r--r--tests/auto/compiled/tst_compiled.cpp8
4 files changed, 37 insertions, 11 deletions
diff --git a/src/scxml/qscxmlnulldatamodel.cpp b/src/scxml/qscxmlnulldatamodel.cpp
index c888708..a2d8a14 100644
--- a/src/scxml/qscxmlnulldatamodel.cpp
+++ b/src/scxml/qscxmlnulldatamodel.cpp
@@ -164,38 +164,48 @@ bool QScxmlNullDataModel::evaluateToBool(QScxmlExecutableContent::EvaluatorId id
QVariant QScxmlNullDataModel::evaluateToVariant(QScxmlExecutableContent::EvaluatorId id, bool *ok)
{
Q_UNUSED(id);
- Q_UNUSED(ok);
- Q_UNREACHABLE();
+ *ok = false;
+ QScxmlStateMachinePrivate::get(stateMachine())->submitError(
+ QStringLiteral("error.execution"),
+ QStringLiteral("Cannot evaluate expressions on a null data model"));
return QVariant();
}
void QScxmlNullDataModel::evaluateToVoid(QScxmlExecutableContent::EvaluatorId id, bool *ok)
{
Q_UNUSED(id);
- Q_UNUSED(ok);
- Q_UNREACHABLE();
+ *ok = false;
+ QScxmlStateMachinePrivate::get(stateMachine())->submitError(
+ QStringLiteral("error.execution"),
+ QStringLiteral("Cannot evaluate expressions on a null data model"));
}
void QScxmlNullDataModel::evaluateAssignment(QScxmlExecutableContent::EvaluatorId id, bool *ok)
{
Q_UNUSED(id);
- Q_UNUSED(ok);
- Q_UNREACHABLE();
+ *ok = false;
+ QScxmlStateMachinePrivate::get(stateMachine())->submitError(
+ QStringLiteral("error.execution"),
+ QStringLiteral("Cannot assign values on a null data model"));
}
void QScxmlNullDataModel::evaluateInitialization(QScxmlExecutableContent::EvaluatorId id, bool *ok)
{
Q_UNUSED(id);
- Q_UNUSED(ok);
- Q_UNREACHABLE();
+ *ok = false;
+ QScxmlStateMachinePrivate::get(stateMachine())->submitError(
+ QStringLiteral("error.execution"),
+ QStringLiteral("Cannot initialize values on a null data model"));
}
bool QScxmlNullDataModel::evaluateForeach(QScxmlExecutableContent::EvaluatorId id, bool *ok, ForeachLoopBody *body)
{
Q_UNUSED(id);
- Q_UNUSED(ok);
Q_UNUSED(body);
- Q_UNREACHABLE();
+ *ok = false;
+ QScxmlStateMachinePrivate::get(stateMachine())->submitError(
+ QStringLiteral("error.execution"),
+ QStringLiteral("Cannot run foreach on a null data model"));
return false;
}
diff --git a/tests/auto/compiled/compiled.pro b/tests/auto/compiled/compiled.pro
index 7dc62ba..53dcd8c 100644
--- a/tests/auto/compiled/compiled.pro
+++ b/tests/auto/compiled/compiled.pro
@@ -16,6 +16,7 @@ STATECHARTS = \
eventnames2.scxml \
statemachineunicodename.scxml \
anonymousstate.scxml \
- submachineunicodename.scxml
+ submachineunicodename.scxml \
+ datainnulldatamodel.scxml
load(qscxmlc)
diff --git a/tests/auto/compiled/datainnulldatamodel.scxml b/tests/auto/compiled/datainnulldatamodel.scxml
new file mode 100644
index 0000000..c8cc7fb
--- /dev/null
+++ b/tests/auto/compiled/datainnulldatamodel.scxml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scxml name="DataInNullDataModel" xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="a">
+ <datamodel>
+ <data id="x" expr="2"/>
+ </datamodel>
+ <state id="a"></state>
+</scxml>
diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp
index 9c4c1e4..ca9b7b3 100644
--- a/tests/auto/compiled/tst_compiled.cpp
+++ b/tests/auto/compiled/tst_compiled.cpp
@@ -33,6 +33,7 @@
#include <QtScxml/qscxmlstatemachine.h>
#include "ids1.h"
#include "statemachineunicodename.h"
+#include "datainnulldatamodel.h"
Q_DECLARE_METATYPE(QScxmlError);
@@ -44,6 +45,7 @@ class tst_Compiled: public QObject
private Q_SLOTS:
void stateNames();
+ void nullDataInit();
};
void tst_Compiled::stateNames()
@@ -81,6 +83,12 @@ void tst_Compiled::stateNames()
QCOMPARE(stateMachine3.stateNames(false), calculatorStates);
}
+void tst_Compiled::nullDataInit()
+{
+ DataInNullDataModel nullData;
+ QVERIFY(!nullData.init()); // raises an error, but doesn't crash
+}
+
QTEST_MAIN(tst_Compiled)
#include "tst_compiled.moc"