summaryrefslogtreecommitdiff
path: root/test/storage
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-03-30 17:01:54 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-03-30 17:43:37 -0700
commit5eda74a514964d1cac684483bafa08d458175f9a (patch)
treea38f886f5742d52a915c3c72959a5eba50b9fa0e /test/storage
parentb6a181097c3e7c3168be3575d5d7e95820fc74ba (diff)
parent7b5a1ca1670a0346cdbf2af689fabde4e70ed561 (diff)
downloadqtlocation-mapboxgl-5eda74a514964d1cac684483bafa08d458175f9a.tar.gz
Merge branch 'release-ios-3.2.0-android-4.0.0'
Diffstat (limited to 'test/storage')
-rw-r--r--test/storage/offline_database.cpp36
-rw-r--r--test/storage/offline_download.cpp64
2 files changed, 96 insertions, 4 deletions
diff --git a/test/storage/offline_database.cpp b/test/storage/offline_database.cpp
index 455c564dc9..a9081d2b3f 100644
--- a/test/storage/offline_database.cpp
+++ b/test/storage/offline_database.cpp
@@ -8,6 +8,7 @@
#include <mbgl/util/string.hpp>
#include <gtest/gtest.h>
+#include <sqlite3.hpp>
#include <sqlite3.h>
#include <thread>
#include <random>
@@ -654,3 +655,38 @@ TEST(OfflineDatabase, OfflineMapboxTileCount) {
db.deleteRegion(std::move(region1));
EXPECT_EQ(0, db.getOfflineMapboxTileCount());
}
+
+static int databasePageCount(const std::string& path) {
+ mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly);
+ mapbox::sqlite::Statement stmt = db.prepare("pragma page_count");
+ stmt.run();
+ return stmt.get<int>(0);
+}
+
+static int databaseUserVersion(const std::string& path) {
+ mapbox::sqlite::Database db(path, mapbox::sqlite::ReadOnly);
+ mapbox::sqlite::Statement stmt = db.prepare("pragma user_version");
+ stmt.run();
+ return stmt.get<int>(0);
+}
+
+TEST(OfflineDatabase, MigrateFromV2Schema) {
+ using namespace mbgl;
+
+ // v2.db is a v2 database containing a single offline region with a small number of resources.
+
+ deleteFile("test/fixtures/offline/v3.db");
+ writeFile("test/fixtures/offline/v3.db", util::read_file("test/fixtures/offline/v2.db"));
+
+ {
+ OfflineDatabase db("test/fixtures/offline/v3.db", 0);
+ auto regions = db.listRegions();
+ for (auto& region : regions) {
+ db.deleteRegion(std::move(region));
+ }
+ }
+
+ EXPECT_EQ(3, databaseUserVersion("test/fixtures/offline/v3.db"));
+ EXPECT_LT(databasePageCount("test/fixtures/offline/v3.db"),
+ databasePageCount("test/fixtures/offline/v2.db"));
+}
diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp
index f7fe0b4064..0898043232 100644
--- a/test/storage/offline_download.cpp
+++ b/test/storage/offline_download.cpp
@@ -364,7 +364,7 @@ TEST(OfflineDownload, RequestErrorsAreRetried) {
test.loop.run();
}
-TEST(OfflineDownload, TileCountLimitExceeded) {
+TEST(OfflineDownload, TileCountLimitExceededNoTileResponse) {
OfflineTest test;
OfflineRegion region = test.createRegion();
OfflineDownload download(
@@ -372,7 +372,9 @@ TEST(OfflineDownload, TileCountLimitExceeded) {
OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/offline/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
test.db, test.fileSource);
- test.db.setOfflineMapboxTileCountLimit(0);
+ uint64_t tileLimit = 0;
+
+ test.db.setOfflineMapboxTileCountLimit(tileLimit);
test.fileSource.styleResponse = [&] (const Resource& resource) {
EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url);
@@ -384,18 +386,72 @@ TEST(OfflineDownload, TileCountLimitExceeded) {
observer->mapboxTileCountLimitExceededFn = [&] (uint64_t limit) {
EXPECT_FALSE(mapboxTileCountLimitExceededCalled);
- EXPECT_EQ(0, limit);
+ EXPECT_EQ(tileLimit, limit);
mapboxTileCountLimitExceededCalled = true;
};
observer->statusChangedFn = [&] (OfflineRegionStatus status) {
- EXPECT_FALSE(status.complete());
+ if (!mapboxTileCountLimitExceededCalled) {
+ EXPECT_FALSE(status.complete());
+ EXPECT_EQ(OfflineRegionDownloadState::Active, status.downloadState);
+ } else {
+ EXPECT_EQ(OfflineRegionDownloadState::Inactive, status.downloadState);
+ test.loop.stop();
+ }
+ };
+
+ download.setObserver(std::move(observer));
+ download.setState(OfflineRegionDownloadState::Active);
+
+ test.loop.run();
+}
+
+TEST(OfflineDownload, TileCountLimitExceededWithTileResponse) {
+ OfflineTest test;
+ OfflineRegion region = test.createRegion();
+ OfflineDownload download(
+ region.getID(),
+ OfflineTilePyramidRegionDefinition("http://127.0.0.1:3000/offline/style.json", LatLngBounds::world(), 0.0, 0.0, 1.0),
+ test.db, test.fileSource);
+
+ uint64_t tileLimit = 1;
+
+ test.db.setOfflineMapboxTileCountLimit(tileLimit);
+
+ test.fileSource.styleResponse = [&] (const Resource& resource) {
+ EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url);
+ return test.response("offline/mapbox_source.style.json");
+ };
+
+ test.fileSource.tileResponse = [&] (const Resource& resource) {
+ const Resource::TileData& tile = *resource.tileData;
+ EXPECT_EQ("mapbox://{z}-{x}-{y}.vector.pbf", tile.urlTemplate);
+ EXPECT_EQ(1, tile.pixelRatio);
+ EXPECT_EQ(0, tile.x);
+ EXPECT_EQ(0, tile.y);
+ EXPECT_EQ(0, tile.z);
+ return test.response("offline/0-0-0.vector.pbf");
+ };
+
+ auto observer = std::make_unique<MockObserver>();
+ bool mapboxTileCountLimitExceededCalled = false;
+
+ observer->mapboxTileCountLimitExceededFn = [&] (uint64_t limit) {
+ EXPECT_FALSE(mapboxTileCountLimitExceededCalled);
+ EXPECT_EQ(tileLimit, limit);
+ mapboxTileCountLimitExceededCalled = true;
+ };
+
+ observer->statusChangedFn = [&] (OfflineRegionStatus status) {
if (!mapboxTileCountLimitExceededCalled) {
EXPECT_EQ(OfflineRegionDownloadState::Active, status.downloadState);
} else {
EXPECT_EQ(OfflineRegionDownloadState::Inactive, status.downloadState);
test.loop.stop();
}
+ if (status.completedResourceCount > tileLimit) {
+ test.loop.stop();
+ }
};
download.setObserver(std::move(observer));