aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlengine
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2017-01-09 17:06:25 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2017-02-02 13:19:57 +0000
commitf96b77bf46a29b1c09d6ebff2f18a475c7ca0b2f (patch)
tree3367d385eb85ba80bad41b155a48057a548c02e8 /tests/auto/qml/qqmlengine
parent6ba26317d0fc0573aca7638eda8bdb91e52d1ab3 (diff)
add QQmlEngine::offlineStorageDatabaseFilePath(db), use in LocalStorage
This is C++ API to get the actual storage path for a particular database. [ChangeLog][QtQml] Added QQmlEngine::offlineStorageDatabaseFilePath(dbName) to allow getting the actual storage path for a particular database. Task-number: QTBUG-52013 Change-Id: I1cbd9454c537f08c97f4dafc06fd6b14e81c51af Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlengine')
-rw-r--r--tests/auto/qml/qqmlengine/tst_qqmlengine.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
index 9c155eda5b..e170920486 100644
--- a/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
+++ b/tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
@@ -56,6 +56,7 @@ private slots:
void baseUrl();
void contextForObject();
void offlineStoragePath();
+ void offlineDatabaseStoragePath();
void clearComponentCache();
void trimComponentCache();
void trimComponentCache_data();
@@ -252,6 +253,34 @@ void tst_qqmlengine::offlineStoragePath()
QCOMPARE(engine.offlineStoragePath(), QDir::homePath());
}
+void tst_qqmlengine::offlineDatabaseStoragePath()
+{
+ // Without these set, QDesktopServices::storageLocation returns
+ // strings with extra "//" at the end. We set them to ignore this problem.
+ qApp->setApplicationName("tst_qqmlengine");
+ qApp->setOrganizationName("QtProject");
+ qApp->setOrganizationDomain("www.qt-project.org");
+
+ QQmlEngine engine;
+ QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+ const QString databaseName = QLatin1String("foo");
+ QString databaseLocation = engine.offlineStorageDatabaseFilePath(databaseName);
+ QCOMPARE(dataLocation.isEmpty(), databaseLocation.isEmpty());
+
+ QDir dir(dataLocation);
+ dir.mkpath("QML");
+ dir.cd("QML");
+ dir.mkpath("OfflineStorage");
+ dir.cd("OfflineStorage");
+ dir.mkpath("Databases");
+ dir.cd("Databases");
+ QCOMPARE(QFileInfo(databaseLocation).dir().path(), dir.path());
+
+ QCryptographicHash md5(QCryptographicHash::Md5);
+ md5.addData(databaseName.toUtf8());
+ QCOMPARE(databaseLocation, QDir::toNativeSeparators(dir.filePath(QLatin1String(md5.result().toHex()))));
+}
+
void tst_qqmlengine::clearComponentCache()
{
QQmlEngine engine;