From 4d3a64c5e65a781acb4acf4ba641456da28bd1e4 Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Sun, 16 Dec 2012 21:24:14 -0800 Subject: Add Composite Types to QQmlType When a composite type is loaded from a QML file, it now generates a QQmlType entry in QQmlMetaTypeData. Change-Id: I9b127dff7955456aacb25138fa6ea8efb7bb9221 Reviewed-by: Christopher Adams Reviewed-by: Alan Alpert --- tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp | 62 +++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp') diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index d5dd364e25..03d2f0beb0 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -41,12 +41,16 @@ #include #include +#include +#include +#include #include #include #include +#include "../../shared/util.h" -class tst_qqmlmetatype : public QObject +class tst_qqmlmetatype : public QQmlDataTest { Q_OBJECT public: @@ -60,6 +64,8 @@ private slots: void qmlPropertyValueInterceptorCast(); void qmlType(); void invalidQmlTypeName(); + void registrationType(); + void compositeType(); void isList(); @@ -77,6 +83,13 @@ public: }; QML_DECLARE_TYPE(TestType); +QObject *testTypeProvider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine); + Q_UNUSED(scriptEngine); + return new TestType(); +} + class ParserStatusTestType : public QObject, public QQmlParserStatus { Q_OBJECT @@ -108,10 +121,19 @@ QML_DECLARE_TYPE(ValueInterceptorTestType); void tst_qqmlmetatype::initTestCase() { + QQmlDataTest::initTestCase(); qmlRegisterType("Test", 1, 0, "TestType"); + qmlRegisterSingletonType("Test", 1, 0, "TestTypeSingleton", testTypeProvider); qmlRegisterType("Test", 1, 0, "ParserStatusTestType"); qmlRegisterType("Test", 1, 0, "ValueSourceTestType"); qmlRegisterType("Test", 1, 0, "ValueInterceptorTestType"); + + QUrl testTypeUrl(testFileUrl("CompositeType.qml")); + //TODO: Replace this with public API version when added + QQmlPrivate::RegisterCompositeType regStruct = { + testTypeUrl,"Test", 1, 0, "TestTypeComposite" + }; + QQmlPrivate::qmlregister(QQmlPrivate::CompositeRegistration, ®Struct); } void tst_qqmlmetatype::qmlParserStatusCast() @@ -228,6 +250,44 @@ void tst_qqmlmetatype::defaultObject() QCOMPARE(QString(QQmlMetaType::defaultProperty(&t).name()), QString("foo")); } +void tst_qqmlmetatype::registrationType() +{ + QQmlType *type = QQmlMetaType::qmlType(QString("TestType"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(!type->isSingleton()); + QVERIFY(!type->isComposite()); + + type = QQmlMetaType::qmlType(QString("TestTypeSingleton"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(type->isSingleton()); + QVERIFY(!type->isComposite()); + + type = QQmlMetaType::qmlType(QString("TestTypeComposite"), QString("Test"), 1, 0); + QVERIFY(type); + QVERIFY(!type->isInterface()); + QVERIFY(!type->isSingleton()); + QVERIFY(type->isComposite()); +} + +void tst_qqmlmetatype::compositeType() +{ + QQmlEngine engine; + + //Loading the test file also loads all composite types it imports + QQmlComponent c(&engine, testFileUrl("testImplicitComposite.qml")); + QObject* obj = c.create(); + QVERIFY(obj); + + QQmlType *type = QQmlMetaType::qmlType(QString("ImplicitType"), QString(""), 1, 0); + QVERIFY(type); + QVERIFY(type->module() == QLatin1String("")); + QVERIFY(type->elementName() == QLatin1String("ImplicitType")); + QCOMPARE(type->qmlTypeName(), QLatin1String("ImplicitType")); + QCOMPARE(type->sourceUrl(), testFileUrl("ImplicitType.qml")); +} + QTEST_MAIN(tst_qqmlmetatype) #include "tst_qqmlmetatype.moc" -- cgit v1.2.3