aboutsummaryrefslogtreecommitdiffstats
path: root/tests
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
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')
-rw-r--r--tests/auto/qml/qqmllanguage/data/CompositeType5.qml2
-rw-r--r--tests/auto/qml/qqmllanguage/data/CompositeType6.qml2
-rw-r--r--tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml8
-rw-r--r--tests/auto/qml/qqmlmetatype/data/CompositeType.qml5
-rw-r--r--tests/auto/qml/qqmlmetatype/data/ImplicitType.qml5
-rw-r--r--tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml3
-rw-r--r--tests/auto/qml/qqmlmetatype/qqmlmetatype.pro3
-rw-r--r--tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp62
8 files changed, 89 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/CompositeType5.qml b/tests/auto/qml/qqmllanguage/data/CompositeType5.qml
new file mode 100644
index 0000000000..564468ce90
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/CompositeType5.qml
@@ -0,0 +1,2 @@
+CompositeType {
+}
diff --git a/tests/auto/qml/qqmllanguage/data/CompositeType6.qml b/tests/auto/qml/qqmllanguage/data/CompositeType6.qml
new file mode 100644
index 0000000000..a8a2af9318
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/CompositeType6.qml
@@ -0,0 +1,2 @@
+CompositeType2 {
+}
diff --git a/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml b/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml
index 717cd84536..4034849df8 100644
--- a/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml
+++ b/tests/auto/qml/qqmllanguage/data/assignCompositeToType.qml
@@ -8,6 +8,10 @@ QtObject {
property QtObject myProperty4
property MyQmlObject myProperty5
property MyQmlObject myProperty6
+ property CompositeType myProperty7
+ property CompositeType myProperty8
+ property CompositeType2 myProperty9
+ property CompositeType2 myPropertyA
myProperty: CompositeType {}
myProperty2: CompositeType2 {}
@@ -15,4 +19,8 @@ QtObject {
myProperty4: CompositeType4 {}
myProperty5: CompositeType2 {}
myProperty6: CompositeType4 {}
+ myProperty7: CompositeType {}
+ myProperty8: CompositeType5 {}
+ myProperty9: CompositeType2 {}
+ myPropertyA: CompositeType6 {}
}
diff --git a/tests/auto/qml/qqmlmetatype/data/CompositeType.qml b/tests/auto/qml/qqmlmetatype/data/CompositeType.qml
new file mode 100644
index 0000000000..bc2abca42b
--- /dev/null
+++ b/tests/auto/qml/qqmlmetatype/data/CompositeType.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+ property int foo
+}
diff --git a/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml b/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml
new file mode 100644
index 0000000000..ca2bcef5bf
--- /dev/null
+++ b/tests/auto/qml/qqmlmetatype/data/ImplicitType.qml
@@ -0,0 +1,5 @@
+import QtQml 2.0
+
+QtObject {
+ property int bar
+}
diff --git a/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml b/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml
new file mode 100644
index 0000000000..f838c6995f
--- /dev/null
+++ b/tests/auto/qml/qqmlmetatype/data/testImplicitComposite.qml
@@ -0,0 +1,3 @@
+import "."
+
+ImplicitType{}
diff --git a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
index b24f006bad..a9a6a32a2b 100644
--- a/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
+++ b/tests/auto/qml/qqmlmetatype/qqmlmetatype.pro
@@ -3,6 +3,9 @@ TARGET = tst_qqmlmetatype
SOURCES += tst_qqmlmetatype.cpp
macx:CONFIG -= app_bundle
+TESTDATA = data/*
+include (../../shared/util.pri)
+
CONFIG += parallel_test
QT += core-private gui-private qml-private testlib v8-private
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
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"