diff --git a/storage/storage.cpp b/storage/storage.cpp index 41a38d11ee..82799a6603 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -88,6 +88,25 @@ void GetQueuedCountries(Storage::TQueue const & queue, TCountriesSet & resultCou resultCountries.insert(country.GetCountryId()); } +MapFilesDownloader::TProgress Storage::GetOverallProgress(TCountriesVec const & countries) +{ + MapFilesDownloader::TProgress overallProgress = {0, 0}; + for (auto const & country : countries) + { + NodeAttrs attr; + GetNodeAttrs(country, attr); + + ASSERT_EQUAL(attr.m_mwmCounter, 1, ()); + + if (attr.m_downloadingProgress.second != -1) + { + overallProgress.first += attr.m_downloadingProgress.first; + overallProgress.second += attr.m_downloadingProgress.second; + } + } + return overallProgress; +} + Storage::Storage(string const & pathToCountriesFile /* = COUNTRIES_FILE */, string const & dataDir /* = string() */) : m_downloader(new HttpMapFilesDownloader()), m_currentSlotId(0), m_dataDir(dataDir), m_downloadMapOnTheMap(nullptr) diff --git a/storage/storage.hpp b/storage/storage.hpp index 3f096121c6..3f811be1a8 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -444,6 +444,10 @@ public: int Subscribe(TChangeCountryFunction const & change, TProgressFunction const & progress); void Unsubscribe(int slotId); + /// Returns information about selected counties downloading progress. + /// |countries| - watched CountryId, ONLY leaf expected. + MapFilesDownloader::TProgress GetOverallProgress(TCountriesVec const &countries); + Country const & CountryLeafByCountryId(TCountryId const & countryId) const; Country const & CountryByCountryId(TCountryId const & countryId) const; diff --git a/storage/storage_integration_tests/download_calc_size_test.cpp b/storage/storage_integration_tests/download_calc_size_test.cpp new file mode 100644 index 0000000000..88ccb2a21d --- /dev/null +++ b/storage/storage_integration_tests/download_calc_size_test.cpp @@ -0,0 +1,75 @@ +#include "testing/testing.hpp" + +#include "storage/storage_integration_tests/test_defines.hpp" + +#include "storage/storage.hpp" + +#include "platform/mwm_version.hpp" +#include "platform/platform.hpp" +#include "platform/platform_tests_support/write_dir_changer.hpp" + +using namespace storage; + +void InitStorage(Storage & storage, Storage::TUpdateCallback const & didDownload, + Storage::TProgressFunction const & progress) +{ + TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); + + auto const changeCountryFunction = [&](TCountryId const & /* countryId */) + { + if (!storage.IsDownloadInProgress()) + { + // End wait for downloading complete. + testing::StopEventLoop(); + } + }; + + storage.Init(didDownload, [](TCountryId const &, Storage::TLocalFilePtr const){return false;}); + storage.RegisterAllLocalMaps(); + storage.Subscribe(changeCountryFunction, progress); + storage.SetDownloadingUrlsForTesting({kTestWebServer}); +} + +UNIT_TEST(DownloadingTests_CalcOverallProgress) +{ + WritableDirChanger writableDirChanger(storage::kMapTestDir); + + TCountriesVec const kTestCountries = { + "Angola", + "Tokelau", + "New Zealand North_Auckland", + "New Zealand North_Wellington" + }; + + Storage s; + + s.SetDownloadingUrlsForTesting({storage::kTestWebServer}); + MapFilesDownloader::TProgress baseProgress = s.GetOverallProgress(kTestCountries); + + TEST_EQUAL(baseProgress.first, 0, ()); + TEST_EQUAL(baseProgress.second, 0, ()); + + for (auto const &country : kTestCountries) + { + baseProgress.second += s.CountrySizeInBytes(country, MapOptions::MapWithCarRouting).second; + } + + auto progressChanged = [&s, &kTestCountries, &baseProgress](TCountryId const & id, TLocalAndRemoteSize const & sz) + { + MapFilesDownloader::TProgress currentProgress = s.GetOverallProgress(kTestCountries); + LOG_SHORT(LINFO, (id, "downloading progress:", currentProgress)); + + TEST_GREATER_OR_EQUAL(currentProgress.first, baseProgress.first, ()); + baseProgress.first = currentProgress.first; + + TEST_LESS_OR_EQUAL(currentProgress.first, baseProgress.second, ()); + TEST_EQUAL(currentProgress.second, baseProgress.second, ()); + }; + + InitStorage(s, [](storage::TCountryId const &, storage::Storage::TLocalFilePtr const){}, progressChanged); + + for (auto const & countryId : kTestCountries) + s.DownloadNode(countryId); + + testing::RunEventLoop(); +} diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 6e528d4f1d..5928a63487 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1588,6 +1588,17 @@ UNIT_TEST(StorageTest_DeleteNodeWithoutDownloading) TEST_EQUAL(nodeAttrs.m_status, NodeStatus::NotDownloaded, ()); } +UNIT_TEST(StorageTest_GetOverallProgressSmokeTest) +{ + Storage storage(kSingleMwmCountriesTxt, make_unique()); + TaskRunner runner; + InitStorage(storage, runner); + + MapFilesDownloader::TProgress currentProgress = storage.GetOverallProgress({"Abkhazia","Algeria_Coast"}); + TEST_EQUAL(currentProgress.first, 0, ()); + TEST_EQUAL(currentProgress.second, 0, ()); +} + UNIT_TEST(StorageTest_GetQueuedChildrenSmokeTest) { Storage storage(kSingleMwmCountriesTxt, make_unique()); diff --git a/xcode/storage/storage.xcodeproj/project.pbxproj b/xcode/storage/storage.xcodeproj/project.pbxproj index 64e503c9a5..c5e29a31cc 100644 --- a/xcode/storage/storage.xcodeproj/project.pbxproj +++ b/xcode/storage/storage.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 671182D51C7F0D6500CB8177 /* packed_polygons_obsolete.bin in Resources */ = {isa = PBXBuildFile; fileRef = 671182D01C7F0D5400CB8177 /* packed_polygons_obsolete.bin */; }; 671182D61C7F0D6800CB8177 /* countries_obsolete.txt in Resources */ = {isa = PBXBuildFile; fileRef = 671182CF1C7F0D5400CB8177 /* countries_obsolete.txt */; }; 671182D71C7F0D6900CB8177 /* countries_obsolete.txt in Resources */ = {isa = PBXBuildFile; fileRef = 671182CF1C7F0D5400CB8177 /* countries_obsolete.txt */; }; + 67239C961CBBDB1700C530A8 /* download_calc_size_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 67239C941CBBDB0E00C530A8 /* download_calc_size_test.cpp */; }; 67247FCF1C60BA8A00EDE56A /* fake_map_files_downloader.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 67247FC51C60BA8A00EDE56A /* fake_map_files_downloader.hpp */; }; 67247FD41C60BA8A00EDE56A /* task_runner.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 67247FCA1C60BA8A00EDE56A /* task_runner.hpp */; }; 67247FD61C60BA8A00EDE56A /* test_map_files_downloader.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 67247FCC1C60BA8A00EDE56A /* test_map_files_downloader.hpp */; }; @@ -167,6 +168,7 @@ 671182CF1C7F0D5400CB8177 /* countries_obsolete.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = countries_obsolete.txt; sourceTree = ""; }; 671182D01C7F0D5400CB8177 /* packed_polygons_obsolete.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; path = packed_polygons_obsolete.bin; sourceTree = ""; }; 671182D11C7F0D5400CB8177 /* WorldCoasts_obsolete.mwm */ = {isa = PBXFileReference; lastKnownFileType = file; path = WorldCoasts_obsolete.mwm; sourceTree = ""; }; + 67239C941CBBDB0E00C530A8 /* download_calc_size_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = download_calc_size_test.cpp; sourceTree = ""; }; 67247FC31C60BA8A00EDE56A /* country_info_getter_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = country_info_getter_test.cpp; sourceTree = ""; }; 67247FC41C60BA8A00EDE56A /* fake_map_files_downloader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fake_map_files_downloader.cpp; sourceTree = ""; }; 67247FC51C60BA8A00EDE56A /* fake_map_files_downloader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = fake_map_files_downloader.hpp; sourceTree = ""; }; @@ -407,6 +409,7 @@ 672480071C60CE3D00EDE56A /* storage_integration_tests */ = { isa = PBXGroup; children = ( + 67239C941CBBDB0E00C530A8 /* download_calc_size_test.cpp */, 56D8CB971CAC17A80003F420 /* test_defines.cpp */, 56D8CB981CAC17A80003F420 /* test_defines.hpp */, 671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */, @@ -721,6 +724,7 @@ 67F90BD01C6A2A1E00CD458E /* storage_group_download_tests.cpp in Sources */, 67F90BCF1C6A2A1E00CD458E /* migrate_tests.cpp in Sources */, 67F90BD11C6A2A1E00CD458E /* storage_http_tests.cpp in Sources */, + 67239C961CBBDB1700C530A8 /* download_calc_size_test.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };