summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-07 12:06:39 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2020-02-07 14:39:03 +0200
commit2365cab58cc8f818b60db81f7cda815ae621c817 (patch)
tree8fdc044ff323e1e4b439d9d1783eadca589b1aba /test/storage
parentc04551a4e3e1fd2d04b884d3a9b78caef93d1a9d (diff)
downloadqtlocation-mapboxgl-2365cab58cc8f818b60db81f7cda815ae621c817.tar.gz
Add OfflineDatabase.PutResourceReadOnlyMode unit test
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/offline_database.test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp
index ef7ad257d7..a0b780a4ea 100644
--- a/test/storage/offline_database.test.cpp
+++ b/test/storage/offline_database.test.cpp
@@ -1875,3 +1875,30 @@ TEST(OfflineDatabase, ResetDatabase) {
EXPECT_EQ(1u, log.count({ EventSeverity::Warning, Event::Database, -1, "Removing existing incompatible offline database" }));
EXPECT_EQ(0u, log.uncheckedCount());
}
+
+TEST(OfflineDatabase, PutResourceReadOnlyMode) {
+ FixtureLog log;
+ OfflineDatabase db(":memory:");
+
+ Resource resource{Resource::Style, "http://example.com/"};
+ Response response;
+ response.data = std::make_shared<std::string>("success");
+
+ // In read-only mode put() is a no-op
+ db.reopenDatabaseReadOnly(true /*readOnly*/);
+ auto failedPutResult = db.put(resource, response);
+ EXPECT_FALSE(failedPutResult.first);
+ EXPECT_EQ(0u, failedPutResult.second);
+
+ // put() works, if read-only mode is disabled
+ db.reopenDatabaseReadOnly(false /*readOnly*/);
+ auto succeededPutResult = db.put(resource, response);
+ EXPECT_TRUE(succeededPutResult.first);
+ EXPECT_EQ(7u, succeededPutResult.second);
+
+ auto getResult = db.get(resource);
+ EXPECT_EQ(nullptr, getResult->error);
+ EXPECT_EQ("success", *getResult->data);
+
+ EXPECT_EQ(0u, log.uncheckedCount());
+}