diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2018-02-22 13:38:26 +0200 |
---|---|---|
committer | Ivo van Dongen <ivovandongen@users.noreply.github.com> | 2018-06-04 12:09:32 +0300 |
commit | d928908ec849097440fd028454c538f1c1632a1e (patch) | |
tree | 9b436f4cdaf247d017fa7925d0421f1c36dceed9 /test | |
parent | 4146d8d9be3a732a626b0e537ed1490af9bc0427 (diff) | |
download | qtlocation-mapboxgl-d928908ec849097440fd028454c538f1c1632a1e.tar.gz |
[core] offline database - batch region resource inserts
Diffstat (limited to 'test')
-rw-r--r-- | test/storage/offline_database.test.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 656231eebe..f315e9d1a2 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -598,6 +598,60 @@ TEST(OfflineDatabase, OfflineMapboxTileCount) { EXPECT_EQ(0u, db.getOfflineMapboxTileCount()); } + +TEST(OfflineDatabase, BatchInsertion) { + using namespace mbgl; + + OfflineDatabase db(":memory:", 1024 * 100); + OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineRegion region = db.createRegion(definition, OfflineRegionMetadata()); + + Response response; + response.data = randomString(1024); + std::list<std::tuple<Resource, Response>> resources; + + for (uint32_t i = 1; i <= 100; i++) { + resources.emplace_back(Resource::style("http://example.com/"s + util::toString(i)), response); + } + + OfflineRegionStatus status; + db.putRegionResources(region.getID(), resources, status); + + for (uint32_t i = 1; i <= 100; i++) { + EXPECT_TRUE(bool(db.get(Resource::style("http://example.com/"s + util::toString(i))))); + } +} + +TEST(OfflineDatabase, BatchInsertionMapboxTileCountExceeded) { + using namespace mbgl; + + OfflineDatabase db(":memory:", 1024 * 100); + db.setOfflineMapboxTileCountLimit(1); + OfflineRegionDefinition definition { "", LatLngBounds::world(), 0, INFINITY, 1.0 }; + OfflineRegion region = db.createRegion(definition, OfflineRegionMetadata()); + + Response response; + response.data = randomString(1024); + std::list<std::tuple<Resource, Response>> resources; + + resources.emplace_back(Resource::style("http://example.com/"), response); + resources.emplace_back(Resource::tile("mapbox://tiles/1", 1.0, 0, 0, 0, Tileset::Scheme::XYZ), response); + resources.emplace_back(Resource::tile("mapbox://tiles/2", 1.0, 0, 0, 0, Tileset::Scheme::XYZ), response); + + OfflineRegionStatus status; + try { + db.putRegionResources(region.getID(), resources, status); + EXPECT_FALSE(true); + } catch (MapboxTileLimitExceededException) { + // Expected + } + + EXPECT_EQ(status.completedTileCount, 1u); + EXPECT_EQ(status.completedResourceCount, 2u); + EXPECT_EQ(db.getRegionCompletedStatus(region.getID()).completedTileCount, 1u); + EXPECT_EQ(db.getRegionCompletedStatus(region.getID()).completedResourceCount, 2u); +} + static int databasePageCount(const std::string& path) { mapbox::sqlite::Database db = mapbox::sqlite::Database::open(path, mapbox::sqlite::ReadOnly); mapbox::sqlite::Statement stmt{ db, "pragma page_count" }; |