summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-10 10:27:55 +0100
committerLiang Qi <liang.qi@qt.io>2017-03-10 10:27:55 +0100
commit8ce3ea59e86f349d2505c97de28f817bccc11480 (patch)
tree8fa5418b83a7fc9addd1c9c2fbeaf2db9353144f /tests
parentdf59576f11705e0075d004ffcc0ac77e53475a3c (diff)
parente49fd45c0947d1b24937517c2d170283eadfc501 (diff)
Merge remote-tracking branch 'origin/5.8' into 5.9
Diffstat (limited to 'tests')
-rw-r--r--tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.json7
-rw-r--r--tests/3rdparty/scion-tests/scxml-test-framework/test/content-expr-in-send/test0.txml.scxml16
-rw-r--r--tests/auto/scion/tst_scion.cpp103
3 files changed, 119 insertions, 7 deletions
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);
}
}