1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtScxml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest>
30#include <QObject>
31#include <QXmlStreamReader>
32#include <QtScxml/qscxmlstatemachine.h>
33
34class tst_DynamicMetaObject: public QObject
35{
36 Q_OBJECT
37
38private Q_SLOTS:
39 void dynamicPartCheck_data();
40 void dynamicPartCheck();
41};
42
43void tst_DynamicMetaObject::dynamicPartCheck_data()
44{
45 QTest::addColumn<QString>(name: "scxmlFileName");
46 QTest::addColumn<QStringList>(name: "expectedProperties");
47 QTest::addColumn<QStringList>(name: "expectedSignals");
48
49 { // test1.scxml
50
51 const QStringList expectedProperties = { QLatin1String("a"), QLatin1String("b") };
52 const QStringList expectedSignals = { QLatin1String("aChanged(bool)"),
53 QLatin1String("bChanged(bool)") };
54
55 QTest::newRow(dataTag: "test1") << QString(":/tst_dynamicmetaobject/test1.scxml")
56 << expectedProperties
57 << expectedSignals;
58 }
59
60 { // mediaplayer.scxml
61
62 const QStringList expectedProperties = { QLatin1String("stopped"), QLatin1String("playing") };
63 const QStringList expectedSignals = { QLatin1String("stoppedChanged(bool)"),
64 QLatin1String("playingChanged(bool)") };
65
66 QTest::newRow(dataTag: "mediaplayer") << QString(":/tst_dynamicmetaobject/mediaplayer.scxml")
67 << expectedProperties
68 << expectedSignals;
69 }
70}
71
72void tst_DynamicMetaObject::dynamicPartCheck()
73{
74 QFETCH(QString, scxmlFileName);
75 QFETCH(QStringList, expectedProperties);
76 QFETCH(QStringList, expectedSignals);
77
78 QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(fileName: scxmlFileName));
79 QVERIFY(!stateMachine.isNull());
80 QVERIFY(!stateMachine->parseErrors().count());
81
82 const QMetaObject *metaObject = stateMachine->metaObject();
83
84 QStringList dynamicProperties;
85 for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); i++) {
86 const QMetaProperty metaProperty = metaObject->property(index: i);
87 dynamicProperties << metaProperty.name();
88 }
89
90 QStringList dynamicSignals;
91 for (int i = metaObject->methodOffset(); i < metaObject->methodCount(); i++) {
92 const QMetaMethod metaMethod = metaObject->method(index: i);
93 if (metaMethod.methodType() == QMetaMethod::Signal)
94 dynamicSignals << metaMethod.methodSignature();
95 }
96
97 // TODO: remove sorting when we drop QSet internally
98 expectedProperties.sort();
99 expectedSignals.sort();
100 dynamicProperties.sort();
101 dynamicSignals.sort();
102
103 QCOMPARE(dynamicProperties, expectedProperties);
104 QCOMPARE(dynamicSignals, expectedSignals);
105}
106
107QTEST_MAIN(tst_DynamicMetaObject)
108
109#include "tst_dynamicmetaobject.moc"
110
111
112

source code of qtscxml/tests/auto/dynamicmetaobject/tst_dynamicmetaobject.cpp