1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/*
metaobjecttest.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Volker Krause <volker.krause@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include <core/metaobjectrepository.h>
#include <core/enumrepositoryserver.h>
#include <core/metaobject.h>
#include <QDebug>
#include <QObject>
#include <QThread>
#include <QTest>
Q_DECLARE_METATYPE(QThread::Priority)
using namespace GammaRay;
class MetaObjectTest : public QObject
{
Q_OBJECT
private slots:
void initTestCase()
{
EnumRepositoryServer::create(this);
}
static void testMetaObject()
{
QVERIFY(MetaObjectRepository::instance()->hasMetaObject(QStringLiteral("QThread")));
auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QThread"));
QVERIFY(mo);
QCOMPARE(mo->className(), QStringLiteral("QThread"));
QVERIFY(mo->inherits(QStringLiteral("QObject")));
auto *superMo = mo->superClass(0);
QVERIFY(superMo);
QCOMPARE(superMo->className(), QStringLiteral("QObject"));
QVERIFY(!mo->superClass(1));
QVERIFY(!superMo->superClass(0));
}
static void testMemberProperty()
{
auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QThread"));
QVERIFY(mo->propertyCount() >= 7); // depends on Qt version
MetaProperty *prop = nullptr;
for (int i = 0; i < mo->propertyCount(); ++i) {
prop = mo->propertyAt(i);
QVERIFY(prop);
if (strcmp(prop->name(), "priority") == 0)
break;
}
QVERIFY(prop);
if (!prop)
return; // to silence clang-tidy
QCOMPARE(prop->name(), "priority");
QCOMPARE(prop->typeName(), "QThread::Priority");
QThread t;
QCOMPARE(prop->value(&t).value<QThread::Priority>(), t.priority());
QCOMPARE(prop->isReadOnly(), false);
}
static void testStaticProperty()
{
auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QCoreApplication"));
QVERIFY(mo);
QVERIFY(mo->propertyCount() >= 8); // depends on Qt version
MetaProperty *prop = nullptr;
for (int i = 0; i < mo->propertyCount(); ++i) {
prop = mo->propertyAt(i);
QVERIFY(prop);
if (strcmp(prop->name(), "libraryPaths") == 0)
break;
}
QVERIFY(prop);
if (!prop)
return; // to silence clang-tidy
QCOMPARE(prop->name(), "libraryPaths");
QCOMPARE(prop->typeName(), "QStringList");
QCOMPARE(prop->isReadOnly(), true);
QCOMPARE(prop->value(nullptr).toStringList(), QCoreApplication::libraryPaths());
}
};
QTEST_MAIN(MetaObjectTest)
#include "metaobjecttest.moc"
|