summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-02-23 16:02:31 +0100
committerUlf Hermann <ulf.hermann@qt.io>2017-02-24 12:32:36 +0000
commit63904309552bc6dd39fcfda086b81c1b9bee0a08 (patch)
tree2c477e454aa26cec911c48dff6850d940124a164 /tests
parent06ee4237c07faef95ac76648ecfd12df144a1e4d (diff)
Make QScxmlScxmlService::stateMachine a Q_PROPERTY
Without this, the invoke example doesn't work. Change-Id: I8c4ae9b21e1164946f2a60777b9e9905f2b51237 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/statemachine/invoke.scxml73
-rw-r--r--tests/auto/statemachine/tst_statemachine.cpp22
-rw-r--r--tests/auto/statemachine/tst_statemachine.qrc1
3 files changed, 96 insertions, 0 deletions
diff --git a/tests/auto/statemachine/invoke.scxml b/tests/auto/statemachine/invoke.scxml
new file mode 100644
index 0000000..1bac47a
--- /dev/null
+++ b/tests/auto/statemachine/invoke.scxml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtScxml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+-->
+<scxml
+ xmlns="http://www.w3.org/2005/07/scxml"
+ version="1.0"
+ name="Directions"
+ initial="anyplace"
+>
+ <state id="anyplace">
+ <invoke type="http://www.w3.org/TR/scxml/">
+ <content>
+ <scxml name="anywhere" version="1.0">
+ <state id="here">
+ <transition event="goThere" target="there"/>
+ </state>
+ <state id="there">
+ <transition event="goHere" target="here"/>
+ </state>
+ </scxml>
+ </content>
+ </invoke>
+ </state>
+</scxml>
diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp
index 99d6661..ed1f424 100644
--- a/tests/auto/statemachine/tst_statemachine.cpp
+++ b/tests/auto/statemachine/tst_statemachine.cpp
@@ -31,6 +31,7 @@
#include <QXmlStreamReader>
#include <QtScxml/qscxmlcompiler.h>
#include <QtScxml/qscxmlstatemachine.h>
+#include <QtScxml/qscxmlinvokableservice.h>
#include <QtScxml/private/qscxmlstatemachine_p.h>
Q_DECLARE_METATYPE(QScxmlError);
@@ -52,6 +53,8 @@ private Q_SLOTS:
void doneDotStateEvent();
void running();
+
+ void invokeStateMachine();
};
void tst_StateMachine::stateNames_data()
@@ -387,6 +390,25 @@ void tst_StateMachine::running()
QCOMPARE(stateMachine->isRunning(), false);
}
+void tst_StateMachine::invokeStateMachine()
+{
+ QScopedPointer<QScxmlStateMachine> stateMachine(
+ QScxmlStateMachine::fromFile(QString(":/tst_statemachine/invoke.scxml")));
+ QVERIFY(!stateMachine.isNull());
+
+ stateMachine->start();
+ QCOMPARE(stateMachine->isRunning(), true);
+ QTRY_VERIFY(stateMachine->activeStateNames().contains(QString("anyplace")));
+
+ QVector<QScxmlInvokableService *> services = stateMachine->invokedServices();
+ QCOMPARE(services.length(), 1);
+ QVariant subMachineVariant = services[0]->property("stateMachine");
+ QVERIFY(subMachineVariant.isValid());
+ QScxmlStateMachine *subMachine = qvariant_cast<QScxmlStateMachine *>(subMachineVariant);
+ QVERIFY(subMachine);
+ QTRY_VERIFY(subMachine->activeStateNames().contains("here"));
+}
+
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 9ded2d0..c31fe4c 100644
--- a/tests/auto/statemachine/tst_statemachine.qrc
+++ b/tests/auto/statemachine/tst_statemachine.qrc
@@ -5,5 +5,6 @@
<file>statenamesnested.scxml</file>
<file>ids1.scxml</file>
<file>stateDotDoneEvent.scxml</file>
+ <file>invoke.scxml</file>
</qresource>
</RCC>