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
|
#include "QuickStreamer/item.h"
#include <gst/gst.h>
#include <QCoreApplication>
#include <QQmlParserStatus>
#include <QtTest>
using QQuickStreamer::Item;
class MetaObjectTest : public QObject
{
Q_OBJECT
public:
MetaObjectTest()
{
}
private slots:
void init()
{
gst_init(Q_NULLPTR, Q_NULLPTR);
QVERIFY(Item::registerObjectClass(GST_TYPE_PIPELINE));
}
void testClassName()
{
Item item(GST_OBJECT(gst_pipeline_new(Q_NULLPTR)));
QCOMPARE(item.metaObject()->className(), "GstPipeline");
}
void testProperties_data()
{
QTest::addColumn<QByteArray>("name");
QTest::addColumn<QByteArray>("type");
QTest::addColumn<bool>("readable");
QTest::addColumn<bool>("writable");
QTest::newRow("name")
<< QByteArrayLiteral("name")
<< QByteArrayLiteral("QString")
<< true << true;
QTest::newRow("children")
<< QByteArrayLiteral("children")
<< QByteArrayLiteral("QQmlListProperty<QQuickStreamer::Item>")
<< true << false;
}
void testProperties()
{
QFETCH(QByteArray, name);
QFETCH(QByteArray, type);
QFETCH(bool, readable);
QFETCH(bool, writable);
Item item(GST_OBJECT(gst_pipeline_new(Q_NULLPTR)));
const int propertyIndex = item.metaObject()->indexOfProperty(name.constData());
QVERIFY(propertyIndex >= 0);
const auto &property = item.metaObject()->property(propertyIndex);
QCOMPARE(property.isReadable(), readable);
QCOMPARE(property.isWritable(), writable);
QVERIFY(property.hasNotifySignal());
QCOMPARE(property.typeName(), type.constData());
QVERIFY(QMetaType::type(type.constData()) != 0);
QCOMPARE(property.name(), name.constData());
}
void testQObjectCast()
{
Item item(GST_OBJECT(gst_pipeline_new(Q_NULLPTR)));
QCOMPARE(qobject_cast<QQmlParserStatus *>(&item), &item);
}
/*
void testCoerce()
{
}
bool QQmlCompiler::canCoerce(int to, QQmlScript::Object *from)
{
QQmlPropertyCache *toMo = enginePrivate->rawPropertyCacheForType(to);
QQmlPropertyCache *fromMo = from->metatype;
while (fromMo) {
if (fromMo == toMo)
return true;
fromMo = fromMo->parent();
}
return false;
}
*/
};
QTEST_MAIN(MetaObjectTest)
#include "tst_metaobjecttest.moc"
|