diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2016-07-07 13:11:08 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2016-07-15 06:43:39 +0000 |
commit | 80a024081a8b04bb789a242fc7949af3110105d7 (patch) | |
tree | a31c602eb66489f7a76d17a19416707505d36b8d /tests | |
parent | d5bda1e25ea8866851cec109ff630cad44804e53 (diff) |
Clean up implicit component registration
When assigning an object to a property that is a QQmlComponent, we implicitly
"wrap" a Component {} around the object declaration. In the QML IR this is only
half-heartedly represented. In order to correctly determine dependencies later
when saving and to support QML files that use implicit components but don't
import QtQml or QtQuick explicitly, we must also extend the file imports
accordingly. This is now done (and tested) by emulating a "import QtQml 2.0 as
QmlInternals" and then using "QmlInternals.Component".
Change-Id: I26f4f53a35675b52d4bd39f23359b0ac8f9678c5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index 186a9e7cf7..b4697a4a3b 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -40,6 +40,7 @@ private slots: void initTestCase(); void regenerateAfterChange(); + void registerImportForImplicitComponent(); }; struct TestCompiler @@ -177,6 +178,47 @@ void tst_qmldiskcache::regenerateAfterChange() } } +void tst_qmldiskcache::registerImportForImplicitComponent() +{ + QQmlEngine engine; + + TestCompiler testCompiler(&engine); + QVERIFY(testCompiler.tempDir.isValid()); + + const QByteArray contents = QByteArrayLiteral("import QtQuick 2.0\n" + "Loader {\n" + " sourceComponent: Item {}\n" + "}"); + + QVERIFY2(testCompiler.compile(contents), qPrintable(testCompiler.lastErrorString)); +#ifdef V4_ENABLE_JIT + { + const QV4::CompiledData::Unit *testUnit = testCompiler.mapUnit(); + QVERIFY2(testUnit, qPrintable(testCompiler.lastErrorString)); + + QCOMPARE(quint32(testUnit->nImports), quint32(2)); + QCOMPARE(testUnit->stringAt(testUnit->importAt(0)->uriIndex), QStringLiteral("QtQuick")); + + QQmlType *componentType = QQmlMetaType::qmlType(&QQmlComponent::staticMetaObject); + + QCOMPARE(testUnit->stringAt(testUnit->importAt(1)->uriIndex), QString(componentType->module())); + QCOMPARE(testUnit->stringAt(testUnit->importAt(1)->qualifierIndex), QStringLiteral("QmlInternals")); + + QCOMPARE(quint32(testUnit->nObjects), quint32(3)); + + const QV4::CompiledData::Object *obj = testUnit->objectAt(0); + QCOMPARE(quint32(obj->nBindings), quint32(1)); + QCOMPARE(quint32(obj->bindingTable()->type), quint32(QV4::CompiledData::Binding::Type_Object)); + + const QV4::CompiledData::Object *implicitComponent = testUnit->objectAt(obj->bindingTable()->value.objectIndex); + QCOMPARE(testUnit->stringAt(implicitComponent->inheritedTypeNameIndex), QStringLiteral("QmlInternals.") + componentType->elementName()); + } +#else + QVERIFY(!testCompiler.mapUnit()); + return; +#endif +} + QTEST_MAIN(tst_qmldiskcache) #include "tst_qmldiskcache.moc" |