diff options
author | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-02-22 11:33:03 +0100 |
---|---|---|
committer | Thiago Marcos P. Santos <tmpsantos@gmail.com> | 2018-02-25 11:05:45 +0200 |
commit | cab6f9779182c1983ef28dd259f721a6379cff6f (patch) | |
tree | 38a48d7651b4683f92aed0b5cf64d5f7b5676bdb | |
parent | 831d51ef23a3d8dee67378d613a1c185e14abd8c (diff) | |
download | qtlocation-mapboxgl-upstream/tmpsantos-qt_offline.tar.gz |
[tests] Added a test for getting resources from the databaseupstream/tmpsantos-qt_offline
This test would have flagged the Qt regression.
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | test/fixtures/offline_database/satellite_test.db | bin | 0 -> 114688 bytes | |||
-rw-r--r-- | test/storage/offline_database.test.cpp | 34 |
3 files changed, 37 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore index 0f4fa77858..b32baaac09 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ xcuserdata /test/fixtures/api/2.png /test/fixtures/offline_database/offline.db /test/fixtures/offline_database/offline.db-* +/test/fixtures/offline_database/satellite.db +/test/fixtures/offline_database/satellite.db-* /test/fixtures/offline_database/invalid.db /test/fixtures/offline_database/invalid.db-* /test/fixtures/offline_database/migrated.db @@ -38,4 +40,4 @@ test/fixtures/storage/assets.zip # Generated list files from code generation /scripts/generate-cmake-files.list /scripts/generate-shaders.list -/scripts/generate-style-code.list
\ No newline at end of file +/scripts/generate-style-code.list diff --git a/test/fixtures/offline_database/satellite_test.db b/test/fixtures/offline_database/satellite_test.db Binary files differnew file mode 100644 index 0000000000..95dd8617ff --- /dev/null +++ b/test/fixtures/offline_database/satellite_test.db diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 94daf59c02..23117173d1 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -38,6 +38,10 @@ void writeFile(const char* name, const std::string& data) { mbgl::util::write_file(name, data); } +void copyFile(const char* orig, const char* dest) { + mbgl::util::write_file(dest, mbgl::util::read_file(orig)); +} + } // namespace TEST(OfflineDatabase, TEST_REQUIRES_WRITE(Create)) { @@ -143,6 +147,36 @@ TEST(OfflineDatabase, PutResource) { EXPECT_EQ("second", *updateGetResult->data); } +TEST(OfflineDatabase, TEST_REQUIRES_WRITE(GetResourceFromOfflineRegion)) { + using namespace mbgl; + + createDir("test/fixtures/offline_database"); + deleteFile("test/fixtures/offline_database/satellite.db"); + copyFile("test/fixtures/offline_database/satellite_test.db", "test/fixtures/offline_database/satellite.db"); + + OfflineDatabase db("test/fixtures/offline_database/satellite.db", mapbox::sqlite::ReadOnly); + + Resource resource = Resource::style("mapbox://styles/mapbox/satellite-v9"); + ASSERT_TRUE(db.get(resource)); +} + +TEST(OfflineDatabase, PutAndGetResource) { + using namespace mbgl; + + OfflineDatabase db(":memory:"); + + Response response1; + response1.data = std::make_shared<std::string>("foobar"); + + Resource resource = Resource::style("mapbox://example.com/style"); + + db.put(resource, response1); + + auto response2 = db.get(resource); + + ASSERT_EQ(*response1.data, *(*response2).data); +} + TEST(OfflineDatabase, PutTile) { using namespace mbgl; |