diff options
author | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2016-07-11 16:21:47 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-07-13 13:45:00 +0000 |
commit | e971720ccd51781ad93c74db94c72817a7cd2068 (patch) | |
tree | d623dedeaab31ea9c76c3fbb5676e82fe09c18d2 /tests | |
parent | d10dad4c9e89f781a10a50b3afd94e3f5c28e306 (diff) |
Add a test for connectToState()
Change-Id: I65a35eb193b683612647f17a556b4ad0254fa253
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/compiled/compiled.pro | 3 | ||||
-rw-r--r-- | tests/auto/compiled/connection.scxml | 42 | ||||
-rw-r--r-- | tests/auto/compiled/tst_compiled.cpp | 99 |
3 files changed, 143 insertions, 1 deletions
diff --git a/tests/auto/compiled/compiled.pro b/tests/auto/compiled/compiled.pro index 0fd3db9..4e8dfa9 100644 --- a/tests/auto/compiled/compiled.pro +++ b/tests/auto/compiled/compiled.pro @@ -18,6 +18,7 @@ STATECHARTS = \ anonymousstate.scxml \ submachineunicodename.scxml \ datainnulldatamodel.scxml \ - initialhistory.scxml + initialhistory.scxml \ + connection.scxml load(qscxmlc) diff --git a/tests/auto/compiled/connection.scxml b/tests/auto/compiled/connection.scxml new file mode 100644 index 0000000..c5654e5 --- /dev/null +++ b/tests/auto/compiled/connection.scxml @@ -0,0 +1,42 @@ +<?xml version="1.0" ?> +<!-- +/**************************************************************************** +** +** 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:GPL-EXCEPT$ +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +--> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" + name="Connection"> + <parallel id="top"> + <state id="a"> + <state id="a1"/> + <state id="a2"/> + </state> + <state id="b"> + <final id="final"/> + </state> + </parallel> +</scxml> diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp index 096e347..6ad8e47 100644 --- a/tests/auto/compiled/tst_compiled.cpp +++ b/tests/auto/compiled/tst_compiled.cpp @@ -36,6 +36,7 @@ #include "datainnulldatamodel.h" #include "submachineunicodename.h" #include "eventnames1.h" +#include "connection.h" Q_DECLARE_METATYPE(QScxmlError); @@ -50,6 +51,8 @@ private Q_SLOTS: void nullDataInit(); void subMachineUnicodeName(); void unicodeEventName(); + void connection(); + void myConnection(); }; void tst_Compiled::stateNames() @@ -117,6 +120,102 @@ void tst_Compiled::unicodeEventName() QCOMPARE(names.activeStateNames(), QStringList(QLatin1String("b"))); } +class Receiver : public QObject +{ + Q_OBJECT +public slots: + void receive(bool enabled) + { + received = received || enabled; + } +public: + bool received = false; +}; + +void tst_Compiled::connection() +{ + Connection stateMachine; + + Receiver receiverA; + Receiver receiverA1; + Receiver receiverA2; + Receiver receiverB; + Receiver receiverFinal; + + QMetaObject::Connection conA = stateMachine.connectToState("a", &receiverA, SLOT(receive(bool))); + QMetaObject::Connection conA1 = stateMachine.connectToState("a1", &receiverA1, SLOT(receive(bool))); + QMetaObject::Connection conA2 = stateMachine.connectToState("a2", &receiverA2, SLOT(receive(bool))); + QMetaObject::Connection conB = stateMachine.connectToState("b", &receiverB, SLOT(receive(bool))); + QMetaObject::Connection conFinal = stateMachine.connectToState("final", &receiverFinal, SLOT(receive(bool))); + + QVERIFY(conA); + QVERIFY(conA1); + QVERIFY(conA2); + QVERIFY(conB); + QVERIFY(conFinal); + + stateMachine.start(); + + QTRY_VERIFY(receiverA.received); + QTRY_VERIFY(receiverA1.received); + QTRY_VERIFY(!receiverA2.received); + QTRY_VERIFY(receiverB.received); + QTRY_VERIFY(receiverFinal.received); + + QVERIFY(disconnect(conA)); + QVERIFY(disconnect(conA1)); + QVERIFY(disconnect(conA2)); + QVERIFY(disconnect(conB)); + QVERIFY(disconnect(conFinal)); +} + +class MyConnection : public Connection +{ + Q_OBJECT +public: + MyConnection(QObject *parent = 0) + : Connection(parent) + {} +}; + +void tst_Compiled::myConnection() +{ + MyConnection stateMachine; + + Receiver receiverA; + Receiver receiverA1; + Receiver receiverA2; + Receiver receiverB; + Receiver receiverFinal; + + QMetaObject::Connection conA = stateMachine.connectToState("a", &receiverA, SLOT(receive(bool))); + QMetaObject::Connection conA1 = stateMachine.connectToState("a1", &receiverA1, SLOT(receive(bool))); + QMetaObject::Connection conA2 = stateMachine.connectToState("a2", &receiverA2, SLOT(receive(bool))); + QMetaObject::Connection conB = stateMachine.connectToState("b", &receiverB, SLOT(receive(bool))); + QMetaObject::Connection conFinal = stateMachine.connectToState("final", &receiverFinal, SLOT(receive(bool))); + + QVERIFY(conA); + QVERIFY(conA1); + QVERIFY(conA2); + QVERIFY(conB); + QVERIFY(conFinal); + + stateMachine.start(); + + QTRY_VERIFY(receiverA.received); + QTRY_VERIFY(receiverA1.received); + QTRY_VERIFY(!receiverA2.received); + QTRY_VERIFY(receiverB.received); + QTRY_VERIFY(receiverFinal.received); + + QVERIFY(disconnect(conA)); + QVERIFY(disconnect(conA1)); + QVERIFY(disconnect(conA2)); + QVERIFY(disconnect(conB)); + QVERIFY(disconnect(conFinal)); +} + + QTEST_MAIN(tst_Compiled) #include "tst_compiled.moc" |