From eb9b4638417ddfb519cd278f25ad022500a9573a Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 4 Mar 2016 14:26:58 -0800 Subject: [core] Fix offline status reporting with pre-existing tiles (#4147) --- test/storage/offline_download.cpp | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'test') diff --git a/test/storage/offline_download.cpp b/test/storage/offline_download.cpp index fce081b8ab..15980e2fdc 100644 --- a/test/storage/offline_download.cpp +++ b/test/storage/offline_download.cpp @@ -380,3 +380,78 @@ TEST(OfflineDownload, TileCountLimitExceeded) { test.loop.run(); } + +TEST(OfflineDownload, WithPreviouslyExistingTile) { + 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); + + test.fileSource.styleResponse = [&] (const Resource& resource) { + EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url); + return test.response("offline/inline_source.style.json"); + }; + + test.db.put( + Resource::tile("http://127.0.0.1:3000/offline/{z}-{x}-{y}.vector.pbf", 1, 0, 0, 0), + test.response("offline/0-0-0.vector.pbf")); + + auto observer = std::make_unique(); + + observer->statusChangedFn = [&] (OfflineRegionStatus status) { + if (status.complete()) { + EXPECT_EQ(2, status.completedResourceCount); + EXPECT_EQ(test.size, status.completedResourceSize); + EXPECT_TRUE(status.requiredResourceCountIsPrecise); + test.loop.stop(); + } + }; + + download.setObserver(std::move(observer)); + download.setState(OfflineRegionDownloadState::Active); + + test.loop.run(); +} + +TEST(OfflineDownload, ReactivatePreviouslyCompletedDownload) { + 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); + + test.fileSource.styleResponse = [&] (const Resource& resource) { + EXPECT_EQ("http://127.0.0.1:3000/offline/style.json", resource.url); + return test.response("offline/inline_source.style.json"); + }; + + test.db.put( + Resource::tile("http://127.0.0.1:3000/offline/{z}-{x}-{y}.vector.pbf", 1, 0, 0, 0), + test.response("offline/0-0-0.vector.pbf")); + + auto observer = std::make_unique(); + bool completedOnce = false; + + observer->statusChangedFn = [&] (OfflineRegionStatus status) { + if (!status.complete()) { + return; + } else if (!completedOnce) { + completedOnce = true; + download.setState(OfflineRegionDownloadState::Inactive); + download.setState(OfflineRegionDownloadState::Active); + } else { + EXPECT_EQ(2, status.completedResourceCount); + EXPECT_EQ(test.size, status.completedResourceSize); + EXPECT_TRUE(status.requiredResourceCountIsPrecise); + test.loop.stop(); + } + }; + + download.setObserver(std::move(observer)); + download.setState(OfflineRegionDownloadState::Active); + + test.loop.run(); +} -- cgit v1.2.1