aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmldiskcache
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2016-08-07 14:53:57 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-08-12 16:54:38 +0000
commitb40d005544cf4b991b797b0058a23dc61e8de5c2 (patch)
tree9ab3cbda9f719ffa2e8f68ecc140738b8879cae6 /tests/auto/qml/qmldiskcache
parentf5a05313757e234c35455b2e1d6fbba43bc9ace2 (diff)
Enable disk cache for files coming from resources
By storing the cached data in QStandardPaths::CacheDir + "/qmlcache/" + sha1(filename) Change-Id: I6a8b4ca701019204fff362504697c3dac9f54bf1 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qmldiskcache')
-rw-r--r--tests/auto/qml/qmldiskcache/qmldiskcache.pro2
-rw-r--r--tests/auto/qml/qmldiskcache/test.qml4
-rw-r--r--tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp28
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qmldiskcache/qmldiskcache.pro b/tests/auto/qml/qmldiskcache/qmldiskcache.pro
index f2d1a04780..f98a157b6a 100644
--- a/tests/auto/qml/qmldiskcache/qmldiskcache.pro
+++ b/tests/auto/qml/qmldiskcache/qmldiskcache.pro
@@ -4,4 +4,6 @@ osx:CONFIG -= app_bundle
SOURCES += tst_qmldiskcache.cpp
+RESOURCES += test.qml
+
QT += core-private qml-private testlib
diff --git a/tests/auto/qml/qmldiskcache/test.qml b/tests/auto/qml/qmldiskcache/test.qml
new file mode 100644
index 0000000000..d632422616
--- /dev/null
+++ b/tests/auto/qml/qmldiskcache/test.qml
@@ -0,0 +1,4 @@
+import QtQml 2.0
+QtObject {
+ property int value: 20
+}
diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
index dd23dfca07..8ccf4714ba 100644
--- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
+++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp
@@ -38,6 +38,9 @@
#include <QQmlEngine>
#include <QQmlFileSelector>
#include <QThread>
+#include <QCryptographicHash>
+#include <QStandardPaths>
+#include <QDirIterator>
class tst_qmldiskcache: public QObject
{
@@ -52,6 +55,7 @@ private slots:
void recompileAfterChange();
void fileSelectors();
void localAliases();
+ void cacheResources();
};
// A wrapper around QQmlComponent to ensure the temporary reference counts
@@ -529,6 +533,30 @@ void tst_qmldiskcache::localAliases()
}
}
+void tst_qmldiskcache::cacheResources()
+{
+ const QString cacheDirectory = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
+ QVERIFY(QDir::root().mkpath(cacheDirectory));
+
+ const QString qmlCacheDirectory = cacheDirectory + QLatin1String("/qmlcache/");
+ QVERIFY(QDir(qmlCacheDirectory).removeRecursively());
+ QVERIFY(QDir::root().mkpath(qmlCacheDirectory));
+ QVERIFY(QDir(qmlCacheDirectory).entryList(QDir::NoDotAndDotDot).isEmpty());
+
+
+ QQmlEngine engine;
+
+ {
+ CleanlyLoadingComponent component(&engine, QUrl("qrc:/test.qml"));
+ qDebug() << component.errorString();
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY(!obj.isNull());
+ QCOMPARE(obj->property("value").toInt(), 20);
+ }
+
+ QCOMPARE(QDir(qmlCacheDirectory).entryList(QDir::NoDotAndDotDot | QDir::Files).count(), 1);
+}
+
QTEST_MAIN(tst_qmldiskcache)
#include "tst_qmldiskcache.moc"