| 25 | using namespace GammaRay; |
| 26 | |
| 27 | class MetaObjectTest : public QObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | private slots: |
| 31 | void initTestCase() |
| 32 | { |
| 33 | EnumRepositoryServer::create(this); |
| 34 | } |
| 35 | |
| 36 | static void testMetaObject() |
| 37 | { |
| 38 | QVERIFY(MetaObjectRepository::instance()->hasMetaObject(QStringLiteral("QThread"))); |
| 39 | auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QThread")); |
| 40 | |
| 41 | QVERIFY(mo); |
| 42 | QCOMPARE(mo->className(), QStringLiteral("QThread")); |
| 43 | QVERIFY(mo->inherits(QStringLiteral("QObject"))); |
| 44 | |
| 45 | auto *superMo = mo->superClass(0); |
| 46 | QVERIFY(superMo); |
| 47 | QCOMPARE(superMo->className(), QStringLiteral("QObject")); |
| 48 | |
| 49 | QVERIFY(!mo->superClass(1)); |
| 50 | QVERIFY(!superMo->superClass(0)); |
| 51 | } |
| 52 | |
| 53 | static void testMemberProperty() |
| 54 | { |
| 55 | auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QThread")); |
| 56 | QVERIFY(mo->propertyCount() >= 7); // depends on Qt version |
| 57 | |
| 58 | MetaProperty *prop = nullptr; |
| 59 | for (int i = 0; i < mo->propertyCount(); ++i) { |
| 60 | prop = mo->propertyAt(i); |
| 61 | QVERIFY(prop); |
| 62 | if (strcmp(prop->name(), "priority") == 0) |
| 63 | break; |
| 64 | } |
| 65 | |
| 66 | QVERIFY(prop); |
| 67 | if (!prop) |
| 68 | return; // to silence clang-tidy |
| 69 | |
| 70 | QCOMPARE(prop->name(), "priority"); |
| 71 | QCOMPARE(prop->typeName(), "QThread::Priority"); |
| 72 | |
| 73 | QThread t; |
| 74 | QCOMPARE(prop->value(&t).value<QThread::Priority>(), t.priority()); |
| 75 | QCOMPARE(prop->isReadOnly(), false); |
| 76 | } |
| 77 | |
| 78 | static void testStaticProperty() |
| 79 | { |
| 80 | auto *mo = MetaObjectRepository::instance()->metaObject(QStringLiteral("QCoreApplication")); |
| 81 | QVERIFY(mo); |
| 82 | QVERIFY(mo->propertyCount() >= 8); // depends on Qt version |
| 83 | |
| 84 | MetaProperty *prop = nullptr; |
nothing calls this directly
no test coverage detected