summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2018-11-13 13:01:11 +0100
committerUlf Hermann <ulf.hermann@qt.io>2018-11-14 08:45:42 +0000
commitbde8d341cc095a3877e4ecc80b02c267bb651d4b (patch)
tree4f07bcac22742f8ce19374c73ee40f6f84990a90
parentd5396ed00589374aed8e44f8f2e3217a3fb768df (diff)
Don't suppress <log> tags with missing or bad expr
Rather, output an empty string as message in this case. Ignoring log instructions is highly confusing. Change-Id: Iebb30ffd3ade33f1277f3073f015127a99170e40 Task-number: QTBUG-71746 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
-rw-r--r--src/scxml/qscxmlexecutablecontent.cpp22
-rw-r--r--tests/auto/statemachine/emptylog.scxml8
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp12
-rw-r--r--tests/auto/statemachine/tst_statemachine.qrc1
4 files changed, 33 insertions, 10 deletions
diff --git a/src/scxml/qscxmlexecutablecontent.cpp b/src/scxml/qscxmlexecutablecontent.cpp
index 206809c..45079d7 100644
--- a/src/scxml/qscxmlexecutablecontent.cpp
+++ b/src/scxml/qscxmlexecutablecontent.cpp
@@ -434,18 +434,20 @@ const InstructionId *QScxmlExecutionEngine::step(const InstructionId *ip, bool *
qCDebug(qscxmlLog) << stateMachine << "Executing log step";
const Log *log = reinterpret_cast<const Log *>(instr);
ip += log->size();
+ QString str;
if (log->expr != NoEvaluator) {
- const QString str = dataModel->evaluateToString(log->expr, ok);
- if (*ok) {
- const QString label = tableData->string(log->label);
- qCDebug(scxmlLog) << label << ":" << str;
- QMetaObject::invokeMethod(stateMachine,
- "log",
- Qt::QueuedConnection,
- Q_ARG(QString, label),
- Q_ARG(QString, str));
- }
+ str = dataModel->evaluateToString(log->expr, ok);
+ if (!*ok)
+ qCWarning(qscxmlLog) << stateMachine << "Could not evaluate <log> expr to string.";
}
+
+ const QString label = tableData->string(log->label);
+ qCDebug(scxmlLog) << label << ":" << str;
+ QMetaObject::invokeMethod(stateMachine,
+ "log",
+ Qt::QueuedConnection,
+ Q_ARG(QString, label),
+ Q_ARG(QString, str));
return ip;
}
diff --git a/tests/auto/statemachine/emptylog.scxml b/tests/auto/statemachine/emptylog.scxml
new file mode 100644
index 0000000..e31f925
--- /dev/null
+++ b/tests/auto/statemachine/emptylog.scxml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="qtbug71746.scxml">
+ <state id="failing">
+ <onentry>
+ <log label="Hi2"/>
+ </onentry>
+ </state>
+</scxml>
diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp
index 94b1d6f..4bd4ef2 100644
--- a/tests/auto/statemachine/tst_statemachine.cpp
+++ b/tests/auto/statemachine/tst_statemachine.cpp
@@ -56,6 +56,7 @@ private Q_SLOTS:
void invokeStateMachine();
void multipleInvokableServices(); // QTBUG-61484
+ void logWithoutExpr();
};
void tst_StateMachine::stateNames_data()
@@ -443,6 +444,17 @@ void tst_StateMachine::multipleInvokableServices()
QVERIFY(stateMachine->activeStateNames(true).contains(QLatin1String("success")));
}
+void tst_StateMachine::logWithoutExpr()
+{
+ QScopedPointer<QScxmlStateMachine> stateMachine(
+ QScxmlStateMachine::fromFile(QString(":/tst_statemachine/emptylog.scxml")));
+ QVERIFY(!stateMachine.isNull());
+ QTest::ignoreMessage(QtDebugMsg, "\"Hi2\" : \"\"");
+ stateMachine->start();
+ QSignalSpy logSpy(stateMachine.data(), SIGNAL(log(QString,QString)));
+ QTRY_COMPARE(logSpy.count(), 1);
+}
+
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 0bd68ff..599ba29 100644
--- a/tests/auto/statemachine/tst_statemachine.qrc
+++ b/tests/auto/statemachine/tst_statemachine.qrc
@@ -8,5 +8,6 @@
<file>invoke.scxml</file>
<file>historystate.scxml</file>
<file>multipleinvokableservices.scxml</file>
+ <file>emptylog.scxml</file>
</qresource>
</RCC>