aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmldiskcache
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2018-07-20 09:22:47 -0700
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-27 04:56:14 +0000
commit447e2e024609a22fe052cf458c27efdef2e3d3eb (patch)
treef2665cfdea84b9d85044a3221658eb8ce10e7d9a /tests/auto/qml/qmldiskcache
parent65fd9165162a8498c5bbe71e5372b65770c240b0 (diff)
Try to load QML cache from CacheLocation if side-by-side fails
This could happen if the .qmlc file is stale or corrupt for some reason. In that case, we should try to load a cache file from the user's CacheLocation. Change-Id: Id2be776c7ae0467c9d9ffffd1543204272a531d1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmldiskcache')
-rw-r--r--tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp42
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 d363180c06..284a324227 100644
--- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
+++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
@@ -48,6 +48,7 @@ class tst_qmldiskcache: public QObject
private slots:
void initTestCase();
+ void loadLocalAsFallback();
void regenerateAfterChange();
void registerImportForImplicitComponent();
void basicVersionChecks();
@@ -204,6 +205,47 @@ struct TestCompiler
void tst_qmldiskcache::initTestCase()
{
qputenv("QML_FORCE_DISK_CACHE", "1");
+ QStandardPaths::setTestModeEnabled(true);
+}
+
+void tst_qmldiskcache::loadLocalAsFallback()
+{
+ QQmlEngine engine;
+ TestCompiler testCompiler(&engine);
+
+ QVERIFY(testCompiler.tempDir.isValid());
+
+ const QByteArray contents = QByteArrayLiteral("import QtQml 2.0\n"
+ "QtObject {\n"
+ " property string blah: Qt.platform;\n"
+ "}");
+
+ QVERIFY2(testCompiler.compile(contents), qPrintable(testCompiler.lastErrorString));
+
+ // Create an invalid side-by-side .qmlc
+ {
+ QFile f(testCompiler.tempDir.path() + "/test.qmlc");
+ QVERIFY(f.open(QIODevice::WriteOnly | QIODevice::Truncate));
+ QV4::CompiledData::Unit unit = {};
+ memcpy(unit.magic, QV4::CompiledData::magic_str, sizeof(unit.magic));
+ unit.version = QV4_DATA_STRUCTURE_VERSION;
+ unit.qtVersion = QT_VERSION;
+ unit.sourceTimeStamp = testCompiler.mappedFile.fileTime(QFile::FileModificationTime).toMSecsSinceEpoch();
+ unit.unitSize = ~0U; // make the size a silly number
+ // write something to the library hash that should cause it not to be loaded
+ memset(unit.libraryVersionHash, 'z', sizeof(unit.libraryVersionHash));
+ memset(unit.md5Checksum, 0, sizeof(unit.md5Checksum));
+
+ // leave the other fields unset, since they don't matter
+
+ f.write(reinterpret_cast<const char *>(&unit), sizeof(unit));
+ }
+
+ QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit = QV4::Compiler::Codegen::createUnitForLoading();
+ bool loaded = unit->loadFromDisk(QUrl::fromLocalFile(testCompiler.testFilePath), QFileInfo(testCompiler.testFilePath).lastModified(),
+ &testCompiler.lastErrorString);
+ QVERIFY2(loaded, qPrintable(testCompiler.lastErrorString));
+ QCOMPARE(unit->objectCount(), 1);
}
void tst_qmldiskcache::regenerateAfterChange()