aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmlcachegen
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-27 17:10:29 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-31 07:28:03 +0000
commit8e45393d10ca649c46a82eb8c125bd38cc5b5615 (patch)
treee63fdc8496060347e24cf4b1ed88f530227b5027 /tests/auto/qml/qmlcachegen
parente56eeee9902ffc341506040e637654b2b0451209 (diff)
Fix import of precompiled .js files
Loading those must not fail the file relocation test, so set the source file names to empty, as we also do for .qml files. Also added tests for all the scenarios: no embedded file paths for AOT files but absolute paths for run-time created cache files. Change-Id: I3fc92e89cfd0da512afeac22bd0da3e915ec46ea Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlcachegen')
-rw-r--r--tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp74
1 files changed, 72 insertions, 2 deletions
diff --git a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
index cba5d2588e..c9e831a6c1 100644
--- a/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
+++ b/tests/auto/qml/qmlcachegen/tst_qmlcachegen.cpp
@@ -57,9 +57,12 @@ private slots:
void trickyPaths_data();
void trickyPaths();
- void scriptImport();
+ void qrcScriptImport();
+ void fsScriptImport();
void enums();
+
+ void sourceFileIndices();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -145,6 +148,7 @@ void tst_qmlcachegen::loadGeneratedFile()
QVERIFY(cacheUnit);
QVERIFY(cacheUnit->flags & QV4::CompiledData::Unit::StaticData);
QVERIFY(cacheUnit->flags & QV4::CompiledData::Unit::PendingTypeCompilation);
+ QCOMPARE(uint(cacheUnit->sourceFileIndex), uint(0));
}
QVERIFY(QFile::remove(testFilePath));
@@ -443,7 +447,7 @@ void tst_qmlcachegen::trickyPaths()
QCOMPARE(obj->property("success").toInt(), 42);
}
-void tst_qmlcachegen::scriptImport()
+void tst_qmlcachegen::qrcScriptImport()
{
QQmlEngine engine;
CleanlyLoadingComponent component(&engine, QUrl("qrc:///jsimport.qml"));
@@ -452,6 +456,60 @@ void tst_qmlcachegen::scriptImport()
QTRY_COMPARE(obj->property("value").toInt(), 42);
}
+void tst_qmlcachegen::fsScriptImport()
+{
+ QTemporaryDir tempDir;
+ QVERIFY(tempDir.isValid());
+
+ const auto writeTempFile = [&tempDir](const QString &fileName, const char *contents) {
+ QFile f(tempDir.path() + '/' + fileName);
+ const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate);
+ Q_ASSERT(ok);
+ f.write(contents);
+ return f.fileName();
+ };
+
+ const QString testFilePath = writeTempFile(
+ "test.qml",
+ "import QtQml 2.0\n"
+ "import \"test.js\" as ScriptTest\n"
+ "QtObject {\n"
+ " property int value: ScriptTest.value\n"
+ "}\n");
+
+ const QString scriptFilePath = writeTempFile(
+ "test.js",
+ "var value = 42"
+ );
+
+ QVERIFY(generateCache(scriptFilePath));
+ QVERIFY(generateCache(testFilePath));
+
+ const QString scriptCacheFilePath = scriptFilePath + QLatin1Char('c');
+ QVERIFY(QFile::exists(scriptFilePath));
+
+ {
+ QFile cache(scriptCacheFilePath);
+ QVERIFY(cache.open(QIODevice::ReadOnly));
+ const QV4::CompiledData::Unit *cacheUnit = reinterpret_cast<const QV4::CompiledData::Unit *>(cache.map(/*offset*/0, sizeof(QV4::CompiledData::Unit)));
+ QVERIFY(cacheUnit);
+ QVERIFY(cacheUnit->flags & QV4::CompiledData::Unit::StaticData);
+ QVERIFY(!(cacheUnit->flags & QV4::CompiledData::Unit::PendingTypeCompilation));
+ QCOMPARE(uint(cacheUnit->sourceFileIndex), uint(0));
+ }
+
+ // Remove source code to make sure that when loading succeeds, it is because we loaded
+ // the existing cache files.
+ QVERIFY(QFile::remove(testFilePath));
+ QVERIFY(QFile::remove(scriptFilePath));
+
+ QQmlEngine engine;
+ CleanlyLoadingComponent component(&engine, QUrl::fromLocalFile(testFilePath));
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("value").toInt(), 42);
+}
+
void tst_qmlcachegen::enums()
{
QQmlEngine engine;
@@ -461,6 +519,18 @@ void tst_qmlcachegen::enums()
QTRY_COMPARE(obj->property("value").toInt(), 200);
}
+void tst_qmlcachegen::sourceFileIndices()
+{
+ QVERIFY(QFile::exists(":/versionchecks.qml"));
+ QCOMPARE(QFileInfo(":/versionchecks.qml").size(), 0);
+
+ QQmlMetaType::CachedUnitLookupError error = QQmlMetaType::CachedUnitLookupError::NoError;
+ const QV4::CompiledData::Unit *unitFromResources = QQmlMetaType::findCachedCompilationUnit(QUrl("qrc:/versionchecks.qml"), &error);
+ QVERIFY(unitFromResources);
+ QVERIFY(unitFromResources->flags & QV4::CompiledData::Unit::PendingTypeCompilation);
+ QCOMPARE(uint(unitFromResources->sourceFileIndex), uint(0));
+}
+
QTEST_GUILESS_MAIN(tst_qmlcachegen)
#include "tst_qmlcachegen.moc"