diff options
author | Liang Qi <liang.qi@qt.io> | 2017-03-10 10:27:55 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-03-10 10:27:55 +0100 |
commit | 8ce3ea59e86f349d2505c97de28f817bccc11480 (patch) | |
tree | 8fa5418b83a7fc9addd1c9c2fbeaf2db9353144f | |
parent | df59576f11705e0075d004ffcc0ac77e53475a3c (diff) | |
parent | e49fd45c0947d1b24937517c2d170283eadfc501 (diff) |
Merge remote-tracking branch 'origin/5.8' into 5.9
Change-Id: I467bf942ab818d350a1c08c8567566b9bbfcb5a5
25 files changed, 175 insertions, 70 deletions
diff --git a/examples/scxml/ftpclient/main.cpp b/examples/scxml/ftpclient/main.cpp index 25102d2..8dd0c16 100644 --- a/examples/scxml/ftpclient/main.cpp +++ b/examples/scxml/ftpclient/main.cpp @@ -89,7 +89,8 @@ int main(int argc, char *argv[]) // Translate commands from the state machine into FTP control messages. ftpClient.connectToEvent("submit.cmd", &controlChannel, [&controlChannel](const QScxmlEvent &event) { - controlChannel.command(event.name().mid(11).toUtf8(), event.data().toByteArray()); + controlChannel.command(event.name().mid(11).toUtf8(), + event.data().toMap()["params"].toByteArray()); }); // Commands to be sent diff --git a/examples/scxml/ftpclient/simpleftp.scxml b/examples/scxml/ftpclient/simpleftp.scxml index 79eb7b9..7d57040 100644 --- a/examples/scxml/ftpclient/simpleftp.scxml +++ b/examples/scxml/ftpclient/simpleftp.scxml @@ -75,7 +75,7 @@ <state id="W"> <onentry> <send eventexpr=""submit." + _event.name"> - <content expr="_event.data"/> + <param name="params" expr="_event.data"/> </send> </onentry> diff --git a/src/imports/scxmlstatemachine/plugin.cpp b/src/imports/scxmlstatemachine/plugin.cpp index 6842846..b662491 100644 --- a/src/imports/scxmlstatemachine/plugin.cpp +++ b/src/imports/scxmlstatemachine/plugin.cpp @@ -43,7 +43,7 @@ #include "statemachineextended_p.h" #include "invokedservices_p.h" -#include <QQmlExtensionPlugin> +#include <qqmlextensionplugin.h> #include <qqml.h> QT_BEGIN_NAMESPACE @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE class QScxmlStateMachinePlugin : public QQmlExtensionPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Scxml/1.0") + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) public: void registerTypes(const char *uri) diff --git a/src/imports/scxmlstatemachine/statemachineloader.cpp b/src/imports/scxmlstatemachine/statemachineloader.cpp index 42048bf..f4c1740 100644 --- a/src/imports/scxmlstatemachine/statemachineloader.cpp +++ b/src/imports/scxmlstatemachine/statemachineloader.cpp @@ -40,11 +40,11 @@ #include "statemachineloader_p.h" #include <QtScxml/qscxmlstatemachine.h> -#include <QQmlContext> -#include <QQmlEngine> -#include <QQmlInfo> -#include <QQmlFile> -#include <QBuffer> +#include <qqmlcontext.h> +#include <qqmlengine.h> +#include <qqmlinfo.h> +#include <qqmlfile.h> +#include <qbuffer.h> /*! \qmltype StateMachineLoader diff --git a/src/imports/scxmlstatemachine/statemachineloader_p.h b/src/imports/scxmlstatemachine/statemachineloader_p.h index 6eaf6f4..a4ee3f1 100644 --- a/src/imports/scxmlstatemachine/statemachineloader_p.h +++ b/src/imports/scxmlstatemachine/statemachineloader_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include <QUrl> +#include <QtCore/qurl.h> #include <QtScxml/qscxmlstatemachine.h> #include <private/qqmlengine_p.h> diff --git a/src/scxml/doc/qtscxml-instantiating-state-machines.qdoc b/src/scxml/doc/qtscxml-instantiating-state-machines.qdoc index c431653..c8e08a6 100644 --- a/src/scxml/doc/qtscxml-instantiating-state-machines.qdoc +++ b/src/scxml/doc/qtscxml-instantiating-state-machines.qdoc @@ -50,7 +50,7 @@ StateMachineLoader { id: scxmlLoader - filename: "statemachine.scxml" + source: "statemachine.scxml" } } \endqml diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp index b8434c6..626015b 100644 --- a/src/scxml/qscxmlcompiler.cpp +++ b/src/scxml/qscxmlcompiler.cpp @@ -40,13 +40,13 @@ #include "qscxmlcompiler_p.h" #include "qscxmlexecutablecontent_p.h" -#include <QXmlStreamReader> -#include <QLoggingCategory> -#include <QJsonDocument> -#include <QJsonObject> -#include <QFile> -#include <QVector> -#include <QString> +#include <qxmlstream.h> +#include <qloggingcategory.h> +#include <qjsondocument.h> +#include <qjsonobject.h> +#include <qfile.h> +#include <qvector.h> +#include <qstring.h> #ifndef BUILD_QSCXMLC #include "qscxmlecmascriptdatamodel.h" @@ -56,12 +56,6 @@ #include "qscxmlstatemachine.h" #include "qscxmltabledata_p.h" -#include <QState> -#include <QHistoryState> -#include <QEventTransition> -#include <QSignalTransition> -#include <QJSValue> -#include <private/qabstracttransition_p.h> #include <private/qmetaobjectbuilder_p.h> #endif // BUILD_QSCXMLC diff --git a/src/scxml/qscxmlcompiler_p.h b/src/scxml/qscxmlcompiler_p.h index f74e282..d3e25df 100644 --- a/src/scxml/qscxmlcompiler_p.h +++ b/src/scxml/qscxmlcompiler_p.h @@ -53,13 +53,13 @@ #include "qscxmlcompiler.h" -#include <QDir> -#include <QFileInfo> -#include <QSet> -#include <QSharedPointer> -#include <QStringList> -#include <QString> -#include <QXmlStreamAttributes> +#include <QtCore/qdir.h> +#include <QtCore/qfileinfo.h> +#include <QtCore/qset.h> +#include <QtCore/qsharedpointer.h> +#include <QtCore/qstringlist.h> +#include <QtCore/qstring.h> +#include <QtCore/qxmlstream.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmldatamodel.h b/src/scxml/qscxmldatamodel.h index d34a84a..bb86c81 100644 --- a/src/scxml/qscxmldatamodel.h +++ b/src/scxml/qscxmldatamodel.h @@ -42,8 +42,8 @@ #include <QtScxml/qscxmlexecutablecontent.h> -#include <QVariant> -#include <QVector> +#include <QtCore/qvariant.h> +#include <QtCore/qvector.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlecmascriptdatamodel.cpp b/src/scxml/qscxmlecmascriptdatamodel.cpp index e517989..a12bb30 100644 --- a/src/scxml/qscxmlecmascriptdatamodel.cpp +++ b/src/scxml/qscxmlecmascriptdatamodel.cpp @@ -44,8 +44,8 @@ #include "qscxmlstatemachine_p.h" #include "qscxmldatamodel_p.h" -#include <QJSEngine> -#include <QJsonDocument> +#include <qjsengine.h> +#include <qjsondocument.h> #include <QtQml/private/qjsvalue_p.h> #include <QtQml/private/qv4scopedvalue_p.h> diff --git a/src/scxml/qscxmlecmascriptplatformproperties.cpp b/src/scxml/qscxmlecmascriptplatformproperties.cpp index 41e27b5..c4bb195 100644 --- a/src/scxml/qscxmlecmascriptplatformproperties.cpp +++ b/src/scxml/qscxmlecmascriptplatformproperties.cpp @@ -40,7 +40,7 @@ #include "qscxmlecmascriptplatformproperties_p.h" #include "qscxmlstatemachine.h" -#include <QJSEngine> +#include <qjsengine.h> QT_BEGIN_NAMESPACE class QScxmlPlatformProperties::Data diff --git a/src/scxml/qscxmlecmascriptplatformproperties_p.h b/src/scxml/qscxmlecmascriptplatformproperties_p.h index cf1c4a9..53babeb 100644 --- a/src/scxml/qscxmlecmascriptplatformproperties_p.h +++ b/src/scxml/qscxmlecmascriptplatformproperties_p.h @@ -53,8 +53,8 @@ #include "qscxmlglobals.h" -#include <QJSValue> -#include <QObject> +#include <QtQml/qjsvalue.h> +#include <QtCore/qobject.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlerror.h b/src/scxml/qscxmlerror.h index cae249e..cc8d53b 100644 --- a/src/scxml/qscxmlerror.h +++ b/src/scxml/qscxmlerror.h @@ -43,7 +43,7 @@ #include <QtScxml/qscxmlglobals.h> #include <QtCore/qobjectdefs.h> -#include <QString> +#include <QtCore/qstring.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlevent.cpp b/src/scxml/qscxmlevent.cpp index 6da52d7..d8c7c1d 100644 --- a/src/scxml/qscxmlevent.cpp +++ b/src/scxml/qscxmlevent.cpp @@ -41,8 +41,8 @@ #include "qscxmlevent_p.h" #include "qscxmlstatemachine_p.h" -#include <QJsonDocument> -#include <QJsonObject> +#include <qjsondocument.h> +#include <qjsonobject.h> QT_BEGIN_NAMESPACE @@ -67,7 +67,7 @@ QScxmlEvent *QScxmlEventBuilder::buildEvent() if (contentExpr == NoEvaluator) { data = contents; } else { - data = dataModel->evaluateToString(contentExpr, &ok); + data = dataModel->evaluateToVariant(contentExpr, &ok); } if (!ok) { // expr evaluation failure results in the data property of the event being set to null. See e.g. test528. diff --git a/src/scxml/qscxmlevent.h b/src/scxml/qscxmlevent.h index 267f5ec..e07da7a 100644 --- a/src/scxml/qscxmlevent.h +++ b/src/scxml/qscxmlevent.h @@ -42,8 +42,8 @@ #include <QtScxml/qscxmlglobals.h> -#include <QStringList> -#include <QVariantList> +#include <QtCore/qstringlist.h> +#include <QtCore/qvariant.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlevent_p.h b/src/scxml/qscxmlevent_p.h index 15bd6fa..f5f5164 100644 --- a/src/scxml/qscxmlevent_p.h +++ b/src/scxml/qscxmlevent_p.h @@ -58,7 +58,7 @@ #include <QtScxml/qscxmlstatemachine.h> #endif -#include <QAtomicInt> +#include <QtCore/qatomic.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlexecutablecontent_p.h b/src/scxml/qscxmlexecutablecontent_p.h index cfaec55..707e8cd 100644 --- a/src/scxml/qscxmlexecutablecontent_p.h +++ b/src/scxml/qscxmlexecutablecontent_p.h @@ -54,7 +54,7 @@ #include <QtScxml/qscxmlexecutablecontent.h> #include <QtScxml/private/qscxmltabledata_p.h> #include <QtScxml/private/qscxmlcompiler_p.h> -#include <QTextStream> +#include <QtCore/qtextstream.h> #ifndef BUILD_QSCXMLC #include <QtScxml/qscxmldatamodel.h> diff --git a/src/scxml/qscxmlglobals_p.h b/src/scxml/qscxmlglobals_p.h index 559636b..fac74dc 100644 --- a/src/scxml/qscxmlglobals_p.h +++ b/src/scxml/qscxmlglobals_p.h @@ -53,7 +53,7 @@ #include "qscxmlglobals.h" -#include <QLoggingCategory> +#include <QtCore/qloggingcategory.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmlstatemachine.cpp b/src/scxml/qscxmlstatemachine.cpp index df6f0f2..53d1bdd 100644 --- a/src/scxml/qscxmlstatemachine.cpp +++ b/src/scxml/qscxmlstatemachine.cpp @@ -43,15 +43,13 @@ #include "qscxmlinvokableservice.h" #include "qscxmldatamodel_p.h" -#include <QAbstractState> -#include <QAbstractTransition> -#include <QFile> -#include <QHash> -#include <QJSEngine> -#include <QLoggingCategory> -#include <QString> -#include <QTimer> -#include <QThread> +#include <qfile.h> +#include <qhash.h> +#include <qjsengine.h> +#include <qloggingcategory.h> +#include <qstring.h> +#include <qtimer.h> +#include <qthread.h> #include <functional> diff --git a/src/scxml/qscxmlstatemachine.h b/src/scxml/qscxmlstatemachine.h index d4435f7..e437eb2 100644 --- a/src/scxml/qscxmlstatemachine.h +++ b/src/scxml/qscxmlstatemachine.h @@ -46,11 +46,11 @@ #include <QtScxml/qscxmlevent.h> #include <QtScxml/qscxmlcompiler.h> -#include <QString> -#include <QVector> -#include <QUrl> -#include <QVariantList> -#include <QPointer> +#include <QtCore/qstring.h> +#include <QtCore/qvector.h> +#include <QtCore/qurl.h> +#include <QtCore/qvariant.h> +#include <QtCore/qpointer.h> #include <functional> diff --git a/src/scxml/qscxmlstatemachineinfo_p.h b/src/scxml/qscxmlstatemachineinfo_p.h index 7a8ca50..4fa0ca0 100644 --- a/src/scxml/qscxmlstatemachineinfo_p.h +++ b/src/scxml/qscxmlstatemachineinfo_p.h @@ -52,7 +52,7 @@ // #include <QtScxml/qscxmlglobals.h> -#include <QObject> +#include <QtCore/qobject.h> QT_BEGIN_NAMESPACE diff --git a/src/scxml/qscxmltabledata.h b/src/scxml/qscxmltabledata.h index 5fcabd1..5c0d345 100644 --- a/src/scxml/qscxmltabledata.h +++ b/src/scxml/qscxmltabledata.h @@ -41,7 +41,7 @@ #define QSCXMLTABLEDATA_H #include <QtScxml/qscxmlexecutablecontent.h> -#include <QString> +#include <QtCore/qstring.h> #ifndef Q_QSCXMLC_OUTPUT_REVISION #define Q_QSCXMLC_OUTPUT_REVISION 1 diff --git a/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.json b/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.json index 2b697c0..277863c 100644 --- a/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.json +++ b/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.json @@ -1,4 +1,9 @@ { "initialConfiguration" : ["pass"], - "events" : [] + "expectedEvents" : [ + { "data" : "blah" }, + { "name" : "timeout", "data" : {"p" : "v"} }, + { "data" : {"p" : "v"} }, + { "name" : "timeout" } + ] } diff --git a/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.scxml b/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.scxml index 4cfa34a..f62bc55 100644 --- a/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.scxml +++ b/tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.scxml @@ -3,24 +3,28 @@ name="content-expr-in-send" datamodel="ecmascript"> <state id="top"> <onentry> - <send event="timeout" delay="2s"/> - <send event="to_second"> + <send> <content>blah</content> </send> + <send event="timeout"> + <param name="p" expr="'v'"/> + </send> + </onentry> + <state id="first"> - <transition event="to_second" target="second"/> + <transition event="timeout" target="second"/> </state> <state id="second"> <onentry> - <send event="to_pass"> + <send> <content expr="_event.data"/> </send> + <send event="timeout"/> </onentry> + <transition event="timeout" target="pass"/> </state> - <transition event="to_pass" cond="_event.data=='blah'" target="pass"/> - <transition event="timeout" target="fail"/> </state> <final id="pass"><onentry><log label="Outcome" expr="'pass'"/></onentry></final> diff --git a/tests/auto/scion/tst_scion.cpp b/tests/auto/scion/tst_scion.cpp index a068005..296c63d 100644 --- a/tests/auto/scion/tst_scion.cpp +++ b/tests/auto/scion/tst_scion.cpp @@ -356,11 +356,112 @@ static bool playEvents(QScxmlStateMachine *stateMachine, const QJsonObject &test return true; } +QT_BEGIN_NAMESPACE +QDebug operator<<(QDebug debug, const QScxmlEvent &event) +{ + QJsonObject obj; + obj.insert(QLatin1String("name"), event.name()); + obj.insert(QLatin1String("type"), event.eventType()); + obj.insert(QLatin1String("data"), QJsonValue::fromVariant(event.data())); + obj.insert(QLatin1String("sendid"), event.sendId()); + obj.insert(QLatin1String("origin"), event.origin()); + obj.insert(QLatin1String("originType"), event.originType()); + obj.insert(QLatin1String("invokeid"), event.invokeId()); + return debug << obj; +} +QT_END_NAMESPACE + +static int verifyEvent(const QList<QScxmlEvent> &receivedEvents, const QJsonObject &event, + int position) { + QScxmlEvent::EventType eventType = QScxmlEvent::ExternalEvent; + const bool verifyEventType = event.contains(QLatin1String("type")); + if (verifyEventType) { + QString typeStr = event.value(QLatin1String("type")).toString(); + if (typeStr.compare(QLatin1String("external"), Qt::CaseInsensitive) == 0) + eventType = QScxmlEvent::InternalEvent; + else if (typeStr.compare(QLatin1String("platform"), Qt::CaseInsensitive) == 0) + eventType = QScxmlEvent::PlatformEvent; + else { + qWarning() << "unexpected event type in " << event; + return -1; + } + } + + const bool verifyName = event.contains(QLatin1String("name")); + const QString name = verifyName ? event.value(QLatin1String("name")).toString() : QString(); + + const bool verifyData = event.contains(QLatin1String("data")); + const QVariant data = verifyData ? event.value(QLatin1String("data")).toVariant() : QVariant(); + const bool verifySendId = event.contains(QLatin1String("sendid")); + const QString sendId = verifySendId ? event.value(QLatin1String("sendid")).toString() + : QString(); + const bool verifyOrigin = event.contains(QLatin1String("origin")); + const QString origin = verifyOrigin ? event.value(QLatin1String("origin")).toString() + : QString(); + const bool verifyOriginType = event.contains(QLatin1String("originType")); + const QString originType = verifyOriginType + ? event.value(QLatin1String("origintype")).toString() + : QString(); + const bool verifyInvokeId = event.contains(QLatin1String("invokeid")); + const QString invokeId = verifyInvokeId ? event.value(QLatin1String("invokeid")).toString() + : QString(); + + while (position < receivedEvents.length()) { + const QScxmlEvent &receivedEvent = receivedEvents[position]; + if ((verifyName && receivedEvent.name() != name) + || (verifyEventType && receivedEvent.eventType() != eventType) + || (verifyData && receivedEvent.data() != data) + || (verifySendId && receivedEvent.sendId() != sendId) + || (verifyOrigin && receivedEvent.origin() != origin) + || (verifyOriginType && receivedEvent.originType() != originType) + || (verifyInvokeId && receivedEvent.invokeId() != invokeId)) { + ++position; + } else { + return position; + } + } + + qWarning("Did not receive expected event:"); + qWarning() << event; + + return -1; // nothing found +} + +static bool verifyEvents(const QList<QScxmlEvent> &receivedEvents, + const QJsonObject &testDescription) +{ + auto jsonEvents = testDescription.value(QLatin1String("expectedEvents")); + if (jsonEvents.isNull()) + return true; + + auto eventsArray = jsonEvents.toArray(); + + int position = 0; + for (int i = 0, ei = eventsArray.size(); i != ei; ++i) { + position = verifyEvent(receivedEvents, eventsArray.at(i).toObject(), position); + if (position < 0) { + qWarning("received events:"); + qWarning() << receivedEvents; + qWarning("expected events"); + qWarning() << eventsArray; + return false; + } else { + ++position; // Don't use the same event twice. + } + } + return true; +} + bool TestScion::runTest(QScxmlStateMachine *stateMachine, const QJsonObject &testDescription) { MySignalSpy stableStateSpy(stateMachine, SIGNAL(reachedStableState())); MySignalSpy finishedSpy(stateMachine, SIGNAL(finished())); + QList<QScxmlEvent> receivedEvents; + stateMachine->connectToEvent(QLatin1String("*"), this, [&](const QScxmlEvent &event) { + receivedEvents.append(event); + }); + if (!stateMachine->init() && stateMachine->name() != QStringLiteral("test487")) { // test487 relies on a failing init to see if an error event gets posted. qWarning() << "init failed"; @@ -385,6 +486,8 @@ bool TestScion::runTest(QScxmlStateMachine *stateMachine, const QJsonObject &tes finishedSpy.fastWait(); // Some tests don't have a final state, so don't check for the // result } + if (!verifyEvents(receivedEvents, testDescription)) + return false; return verifyStates(stateMachine, testDescription, QLatin1String("initialConfiguration"), 0); } } |