summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp')
-rw-r--r--tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp83
1 files changed, 46 insertions, 37 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
index d3f10ed815..18e4e2a4a9 100644
--- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
+++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -67,6 +42,8 @@ private slots:
void cleanupTestCase();
+ void ownMetaTypeNoProperties();
+
private:
static bool checkForSideEffects
(const QMetaObjectBuilder& builder,
@@ -97,7 +74,7 @@ class SomethingOfEverything : public QObject
Q_PROPERTY(SomethingFlagEnum fprop READ fprop)
Q_PROPERTY(QLocale::Language language READ language)
Q_ENUMS(SomethingEnum)
- Q_FLAGS(SomethingFlagEnum)
+ Q_FLAGS(SomethingFlag)
public:
Q_INVOKABLE SomethingOfEverything() {}
~SomethingOfEverything() {}
@@ -113,6 +90,7 @@ public:
XYZ = 1,
UVW = 8
};
+ Q_DECLARE_FLAGS(SomethingFlag, SomethingFlagEnum)
Q_INVOKABLE Q_SCRIPTABLE void method1() {}
@@ -801,6 +779,26 @@ void tst_QMetaObjectBuilder::notifySignal()
void tst_QMetaObjectBuilder::enumerator()
{
+ static const QtPrivate::QMetaTypeInterface fooFlagMetaType = {
+ 0,
+ 8,
+ 8,
+ QMetaType::IsEnumeration | QMetaType::IsUnsignedEnumeration | QMetaType::RelocatableType,
+ {},
+ nullptr,
+ "fooFlag",
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ nullptr,
+ };
+
QMetaObjectBuilder builder;
// Add an enumerator and check its attributes.
@@ -832,6 +830,7 @@ void tst_QMetaObjectBuilder::enumerator()
enum1.setIsFlag(true);
enum1.setIsScoped(true);
enum1.setEnumName(QByteArrayLiteral("fooFlag"));
+ enum1.setMetaType(QMetaType(&fooFlagMetaType));
QCOMPARE(enum1.addKey("ABC", 0), 0);
QCOMPARE(enum1.addKey("DEF", 1), 1);
QCOMPARE(enum1.addKey("GHI", -1), 2);
@@ -841,6 +840,7 @@ void tst_QMetaObjectBuilder::enumerator()
QVERIFY(enum1.isFlag());
QVERIFY(enum1.isScoped());
QCOMPARE(enum1.enumName(), QByteArray("fooFlag"));
+ QCOMPARE(enum1.metaType(), QMetaType(&fooFlagMetaType));
QCOMPARE(enum1.keyCount(), 3);
QCOMPARE(enum1.index(), 0);
QCOMPARE(enum1.key(0), QByteArray("ABC"));
@@ -1481,9 +1481,7 @@ int TestObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < ownMethodCount)
qt_static_metacall(this, _c, _id, _a);
_id -= ownMethodCount;
- }
-#ifndef QT_NO_PROPERTIES
- else if (_c == QMetaObject::ReadProperty) {
+ } else if (_c == QMetaObject::ReadProperty) {
void *_v = _a[0];
switch (_id) {
case 0: *reinterpret_cast< int*>(_v) = intProp(); break;
@@ -1506,7 +1504,6 @@ int TestObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
} else if (_c == QMetaObject::ResetProperty) {
_id -= ownPropertyCount;
}
-#endif // QT_NO_PROPERTIES
return _id;
}
@@ -1524,8 +1521,8 @@ void tst_QMetaObjectBuilder::usage_signal()
QSignalSpy propChangedSpy(testObject.data(), &TestObject::intPropChanged);
testObject->emitIntPropChanged();
- QCOMPARE(propChangedSpy.count(), 1);
- QCOMPARE(propChangedSpy.at(0).count(), 1);
+ QCOMPARE(propChangedSpy.size(), 1);
+ QCOMPARE(propChangedSpy.at(0).size(), 1);
QCOMPARE(propChangedSpy.at(0).at(0).toInt(), testObject->intProp());
}
@@ -1540,7 +1537,7 @@ void tst_QMetaObjectBuilder::usage_property()
QSignalSpy propChangedSpy(testObject.data(), &TestObject::intPropChanged);
QVERIFY(testObject->intProp() != 123);
testObject->setProperty("intProp", 123);
- QCOMPARE(propChangedSpy.count(), 1);
+ QCOMPARE(propChangedSpy.size(), 1);
prop = testObject->property("intProp");
QCOMPARE(prop.metaType(), QMetaType(QMetaType::Int));
QCOMPARE(prop.toInt(), 123);
@@ -1641,23 +1638,35 @@ void tst_QMetaObjectBuilder::classNameFirstInStringData()
}
struct MyFoo {};
+struct myParameter {};
void tst_QMetaObjectBuilder::propertyMetaType()
{
+ qRegisterMetaType<myParameter>();
QMetaType meta = QMetaType::fromType<MyFoo>();
auto metaId = meta.id();
QMetaObjectBuilder builder;
builder.setClassName("Test");
- builder.addProperty("test", "MyFoo");
+ builder.addProperty("myParameter", "MyFoo");
auto mo = builder.toMetaObject();
- QMetaProperty metaProp = mo->property(mo->indexOfProperty("test"));
+ QMetaProperty metaProp = mo->property(mo->indexOfProperty("myParameter"));
QCOMPARE(metaProp.typeName(), meta.name());
QCOMPARE(metaProp.typeId(), metaId);
QCOMPARE(metaProp.metaType(), meta);
free(mo);
}
+void tst_QMetaObjectBuilder::ownMetaTypeNoProperties()
+{
+ QMetaObjectBuilder builder;
+ builder.setClassName("NoProperties");
+ auto mo = builder.toMetaObject();
+ auto cleanup = qScopeGuard([&](){ free(mo); });
+ // own metatype should be invalid, as the dynamic metaobject has not been registered
+ QVERIFY(!mo->metaType().isValid());// should not crash
+}
+
void tst_QMetaObjectBuilder::cleanupTestCase()
{
for (QMetaObject *obj: dynamicMetaObjectsPendingFree)