diff options
author | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2016-03-10 17:07:06 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2016-05-18 11:24:30 +0000 |
commit | b5a179fba6f08e29f777cf10d0972d60b61637ad (patch) | |
tree | f9f896c3bf14a289dce067a93e54cf336f970dda | |
parent | 14a54e65bfa23620074563821f030d78550b42ba (diff) |
Add a test checking dynamic meta object content of the state machine
Change-Id: I4754fc96d34723bd849ff72c4c746f5dee4b1362
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | tests/auto/auto.pro | 8 | ||||
-rw-r--r-- | tests/auto/dynamicmetaobject/dynamicmetaobject.pro | 15 | ||||
-rw-r--r-- | tests/auto/dynamicmetaobject/mediaplayer.scxml | 93 | ||||
-rw-r--r-- | tests/auto/dynamicmetaobject/test1.scxml | 41 | ||||
-rw-r--r-- | tests/auto/dynamicmetaobject/tst_dynamicmetaobject.cpp | 143 | ||||
-rw-r--r-- | tests/auto/dynamicmetaobject/tst_dynamicmetaobject.qrc | 6 |
6 files changed, 305 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3b89fa0..a6dd3ae 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,2 +1,8 @@ TEMPLATE = subdirs -SUBDIRS = cmake parser scion statemachine qscxmlc compiled +SUBDIRS = cmake\ + compiled\ + dynamicmetaobject\ + parser\ + qscxmlc\ + scion\ + statemachine diff --git a/tests/auto/dynamicmetaobject/dynamicmetaobject.pro b/tests/auto/dynamicmetaobject/dynamicmetaobject.pro new file mode 100644 index 0000000..f78e5ac --- /dev/null +++ b/tests/auto/dynamicmetaobject/dynamicmetaobject.pro @@ -0,0 +1,15 @@ +QT = core gui qml testlib scxml +CONFIG += testcase + +TARGET = tst_dynamicmetaobject +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + +RESOURCES += tst_dynamicmetaobject.qrc + +SOURCES += \ + tst_dynamicmetaobject.cpp + +load(qscxmlc) diff --git a/tests/auto/dynamicmetaobject/mediaplayer.scxml b/tests/auto/dynamicmetaobject/mediaplayer.scxml new file mode 100644 index 0000000..025245a --- /dev/null +++ b/tests/auto/dynamicmetaobject/mediaplayer.scxml @@ -0,0 +1,93 @@ +<?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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + name="MediaPlayerStateMachine" + initial="stopped" + datamodel="ecmascript" +> + <datamodel> + <data id="media"/> + </datamodel> + + <script> + function isValidMedia() { + var m = _event.data.media + return (m + "").length > 0 + } + </script> + + <state id="stopped"> + <transition event="tap" cond="isValidMedia()" target="playing"/> + </state> + + <state id="playing"> + <onentry> + <assign location="media" expr="_event.data.media"/> + <send type="qt:signal" event="playbackStarted"> + <param name="media" expr="media"/> + </send> + </onentry> + + <onexit> + <send type="qt:signal" event="playbackStopped"> + <param name="media" expr="media"/> + </send> + </onexit> + + <transition event="tap" cond="!isValidMedia() || media === _event.data.media" target="stopped"/> + <transition event="tap" cond="isValidMedia() && media !== _event.data.media" target="playing"/> + </state> +</scxml> diff --git a/tests/auto/dynamicmetaobject/test1.scxml b/tests/auto/dynamicmetaobject/test1.scxml new file mode 100644 index 0000000..72fd592 --- /dev/null +++ b/tests/auto/dynamicmetaobject/test1.scxml @@ -0,0 +1,41 @@ +<?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="test1" datamodel="ecmascript"> + <state id="a"> + <transition event="foo"/> + </state> + <state id="b"> + <transition event="foo"/> + <transition event="foo" cond="1==1" target="a"/> + </state> + <transition event="foo"/> +</scxml> diff --git a/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.cpp b/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.cpp new file mode 100644 index 0000000..7610dd7 --- /dev/null +++ b/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtTest> +#include <QObject> +#include <QXmlStreamReader> +#include <QtScxml/qscxmlstatemachine.h> + +class tst_DynamicMetaObject: public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void dynamicPartCheck_data(); + void dynamicPartCheck(); +}; + +void tst_DynamicMetaObject::dynamicPartCheck_data() +{ + QTest::addColumn<QString>("scxmlFileName"); + QTest::addColumn<QStringList>("expectedProperties"); + QTest::addColumn<QStringList>("expectedMethods"); + QTest::addColumn<QStringList>("expectedSignals"); + QTest::addColumn<QStringList>("expectedSlots"); + + { // test1.scxml + + const QStringList expectedProperties = { QLatin1String("a"), QLatin1String("b") }; + const QStringList expectedMethods = { }; + const QStringList expectedSignals = { QLatin1String("aChanged(bool)"), + QLatin1String("bChanged(bool)") }; + const QStringList expectedSlots = { }; + + QTest::newRow("test1") << QString(":/tst_dynamicmetaobject/test1.scxml") + << expectedProperties + << expectedMethods + << expectedSignals + << expectedSlots; + } + + { // mediaplayer.scxml + + const QStringList expectedProperties = { QLatin1String("stopped"), QLatin1String("playing") }; + const QStringList expectedMethods = { }; + const QStringList expectedSignals = { QLatin1String("stoppedChanged(bool)"), + QLatin1String("playingChanged(bool)"), + QLatin1String("playbackStarted(QVariant)"), + QLatin1String("playbackStopped(QVariant)") }; + const QStringList expectedSlots = { QLatin1String("tap()"), + QLatin1String("tap(QVariant)") }; + + QTest::newRow("mediaplayer") << QString(":/tst_dynamicmetaobject/mediaplayer.scxml") + << expectedProperties + << expectedMethods + << expectedSignals + << expectedSlots; + } +} + +void tst_DynamicMetaObject::dynamicPartCheck() +{ + QFETCH(QString, scxmlFileName); + QFETCH(QStringList, expectedProperties); + QFETCH(QStringList, expectedMethods); + QFETCH(QStringList, expectedSignals); + QFETCH(QStringList, expectedSlots); + + QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(scxmlFileName)); + QVERIFY(!stateMachine.isNull()); + QVERIFY(!stateMachine->parseErrors().count()); + + const QMetaObject *metaObject = stateMachine->metaObject(); + + QStringList dynamicProperties; + for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) { + QMetaProperty metaProperty = metaObject->property(i); + dynamicProperties << metaProperty.name(); + } + + QStringList dynamicMethods, dynamicSignals, dynamicSlots; + for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); i++) { + QMetaMethod metaMethod = metaObject->method(i); + switch (metaMethod.methodType()) { + case QMetaMethod::Method: + dynamicMethods << metaMethod.methodSignature(); + break; + case QMetaMethod::Signal: + dynamicSignals << metaMethod.methodSignature(); + break; + case QMetaMethod::Slot: + dynamicSlots << metaMethod.methodSignature(); + break; + default: + break; + } + } + + // TODO: remove sorting when we drop QSet internally + expectedProperties.sort(); + expectedMethods.sort(); + expectedSignals.sort(); + expectedSlots.sort(); + dynamicProperties.sort(); + dynamicMethods.sort(); + dynamicSignals.sort(); + dynamicSlots.sort(); + + QCOMPARE(dynamicProperties, expectedProperties); + QCOMPARE(dynamicMethods, expectedMethods); + QCOMPARE(dynamicSignals, expectedSignals); + QCOMPARE(dynamicSlots, expectedSlots); +} + +QTEST_MAIN(tst_DynamicMetaObject) + +#include "tst_dynamicmetaobject.moc" + + diff --git a/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.qrc b/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.qrc new file mode 100644 index 0000000..dbc6d9a --- /dev/null +++ b/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/tst_dynamicmetaobject"> + <file>test1.scxml</file> + <file>mediaplayer.scxml</file> + </qresource> +</RCC> |