aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
diff options
context:
space:
mode:
authorAlan Alpert <416365416c@gmail.com>2012-12-16 21:24:14 -0800
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-18 12:54:15 +0100
commit4d3a64c5e65a781acb4acf4ba641456da28bd1e4 (patch)
tree10d1374401131a7d22146cdf7029307aea9efe7b /tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp
parent58471eb3f267dbee728b1c13f87458f2ee509bfa (diff)
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 <chris.adams@jollamobile.com> Reviewed-by: Alan Alpert <aalpert@rim.com>
Diffstat (limited to 'tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp')
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp62
1 files changed, 61 insertions, 1 deletions
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 <qtest.h>
#include <qqml.h>
+#include <qqmlprivate.h>
+#include <qqmlengine.h>
+#include <qqmlcomponent.h>
#include <private/qqmlmetatype_p.h>
#include <private/qqmlpropertyvalueinterceptor_p.h>
#include <private/qhashedstring_p.h>
+#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<TestType>("Test", 1, 0, "TestType");
+ qmlRegisterSingletonType<TestType>("Test", 1, 0, "TestTypeSingleton", testTypeProvider);
qmlRegisterType<ParserStatusTestType>("Test", 1, 0, "ParserStatusTestType");
qmlRegisterType<ValueSourceTestType>("Test", 1, 0, "ValueSourceTestType");
qmlRegisterType<ValueInterceptorTestType>("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, &regStruct);
}
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"