From a1b7e6df7cbddd2796b0c637318c63563b4db25c Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 30 Mar 2016 13:52:55 +0300 Subject: [PATCH 1/4] Storage integration tests refactoring. --- storage/storage_integration_tests/migrate_tests.cpp | 7 ++----- .../storage_integration_tests/storage_3levels_tests.cpp | 7 ++----- .../storage_downloading_tests.cpp | 7 ++----- .../storage_group_download_tests.cpp | 7 ++----- storage/storage_integration_tests/storage_http_tests.cpp | 7 ++----- .../storage_integration_tests.pro | 2 ++ storage/storage_integration_tests/storage_update_tests.cpp | 7 ++----- storage/storage_integration_tests/test_defines.cpp | 4 ++++ storage/storage_integration_tests/test_defines.hpp | 6 ++++++ 9 files changed, 24 insertions(+), 30 deletions(-) create mode 100644 storage/storage_integration_tests/test_defines.cpp create mode 100644 storage/storage_integration_tests/test_defines.hpp diff --git a/storage/storage_integration_tests/migrate_tests.cpp b/storage/storage_integration_tests/migrate_tests.cpp index 9289269680..8493bff093 100644 --- a/storage/storage_integration_tests/migrate_tests.cpp +++ b/storage/storage_integration_tests/migrate_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "map/framework.hpp" #include "platform/local_country_file_utils.hpp" @@ -18,11 +20,6 @@ using namespace platform; using namespace storage; -namespace -{ -static string const kMapTestDir = "map-tests"; -} - UNIT_TEST(StorageFastMigrationTests) { WritableDirChanger writableDirChanger(kMapTestDir); diff --git a/storage/storage_integration_tests/storage_3levels_tests.cpp b/storage/storage_integration_tests/storage_3levels_tests.cpp index 9f6bcbdb6b..cefe208345 100644 --- a/storage/storage_integration_tests/storage_3levels_tests.cpp +++ b/storage/storage_integration_tests/storage_3levels_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "map/framework.hpp" #include "platform/platform.hpp" @@ -17,11 +19,6 @@ using namespace storage; namespace { - -string const kTestWebServer = "http://direct.mapswithme.com/"; - -string const kMapTestDir = "map-tests"; - string const kCountryId = "Germany"; // Germany has 3-levels hierachy int GetLevelCount(Storage & storage, TCountryId const & countryId) diff --git a/storage/storage_integration_tests/storage_downloading_tests.cpp b/storage/storage_integration_tests/storage_downloading_tests.cpp index ac6ad386ad..1ac228000a 100644 --- a/storage/storage_integration_tests/storage_downloading_tests.cpp +++ b/storage/storage_integration_tests/storage_downloading_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "storage/storage.hpp" #include "platform/local_country_file_utils.hpp" @@ -23,13 +25,8 @@ using namespace storage; namespace { - string const kCountryId = "Angola"; -string const kTestWebServer = "http://direct.mapswithme.com/"; - -string const kMapTestDir = "map-tests"; - class InterruptException : public exception {}; void Update(TCountryId const &, storage::Storage::TLocalFilePtr const localCountryFile) diff --git a/storage/storage_integration_tests/storage_group_download_tests.cpp b/storage/storage_integration_tests/storage_group_download_tests.cpp index 9aec0d15a2..3793c99a4d 100644 --- a/storage/storage_integration_tests/storage_group_download_tests.cpp +++ b/storage/storage_integration_tests/storage_group_download_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "map/framework.hpp" #include "platform/http_request.hpp" @@ -24,11 +26,6 @@ using namespace storage; namespace { - -string const kTestWebServer = "http://direct.mapswithme.com/"; - -string const kMapTestDir = "map-tests"; - TCountryId const kGroupCountryId = "New Zealand"; TCountriesSet const kLeafCountriesIds = {"Tokelau", "New Zealand North_Auckland", diff --git a/storage/storage_integration_tests/storage_http_tests.cpp b/storage/storage_integration_tests/storage_http_tests.cpp index 88b72c1f84..b24b15ad85 100644 --- a/storage/storage_integration_tests/storage_http_tests.cpp +++ b/storage/storage_integration_tests/storage_http_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "storage/storage.hpp" #include "platform/local_country_file_utils.hpp" @@ -21,13 +23,8 @@ using namespace storage; namespace { - string const kCountryId = "Angola"; -string const kMapTestDir = "map-tests"; - -string const kTestWebServer = "http://direct.mapswithme.com/"; - void Update(TCountryId const &, storage::Storage::TLocalFilePtr const localCountryFile) { TEST_EQUAL(localCountryFile->GetCountryName(), kCountryId, ()); diff --git a/storage/storage_integration_tests/storage_integration_tests.pro b/storage/storage_integration_tests/storage_integration_tests.pro index 9a6bb41eac..d1a60c60fd 100644 --- a/storage/storage_integration_tests/storage_integration_tests.pro +++ b/storage/storage_integration_tests/storage_integration_tests.pro @@ -25,6 +25,7 @@ win32*|linux* { } HEADERS += \ + test_defines.hpp SOURCES += \ ../../testing/testingmain.cpp \ @@ -34,3 +35,4 @@ SOURCES += \ storage_group_download_tests.cpp \ storage_http_tests.cpp \ storage_update_tests.cpp \ + test_defines.cpp diff --git a/storage/storage_integration_tests/storage_update_tests.cpp b/storage/storage_integration_tests/storage_update_tests.cpp index 74ae75fbf7..37e0c99f63 100644 --- a/storage/storage_integration_tests/storage_update_tests.cpp +++ b/storage/storage_integration_tests/storage_update_tests.cpp @@ -1,5 +1,7 @@ #include "testing/testing.hpp" +#include "storage/storage_integration_tests/test_defines.hpp" + #include "map/framework.hpp" #include "platform/http_request.hpp" @@ -19,11 +21,6 @@ using namespace storage; namespace { - -string const kTestWebServer = "http://direct.mapswithme.com/"; - -string const kMapTestDir = "map-tests"; - string const kCountriesTxtFile = COUNTRIES_FILE; string const kMwmVersion1 = "160316"; diff --git a/storage/storage_integration_tests/test_defines.cpp b/storage/storage_integration_tests/test_defines.cpp new file mode 100644 index 0000000000..a8f0279a8d --- /dev/null +++ b/storage/storage_integration_tests/test_defines.cpp @@ -0,0 +1,4 @@ +#include "storage/storage_integration_tests/test_defines.hpp" + +string const kMapTestDir = string("map-tests"); +string const kTestWebServer = string("http://direct.mapswithme.com/"); diff --git a/storage/storage_integration_tests/test_defines.hpp b/storage/storage_integration_tests/test_defines.hpp new file mode 100644 index 0000000000..27875cd25b --- /dev/null +++ b/storage/storage_integration_tests/test_defines.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include "std/string.hpp" + +extern string const kMapTestDir; +extern string const kTestWebServer; From 62e42c52ddb9a2d57b5c8ed2458f4cddade1d916 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 30 Mar 2016 17:03:26 +0300 Subject: [PATCH 2/4] Storage integration test on downloading and grouping disputed territories. --- .../storage_http_tests.cpp | 127 +++++++++++++++--- .../storage_integration_tests.pro | 2 +- 2 files changed, 107 insertions(+), 22 deletions(-) diff --git a/storage/storage_integration_tests/storage_http_tests.cpp b/storage/storage_integration_tests/storage_http_tests.cpp index b24b15ad85..3f208c7c5f 100644 --- a/storage/storage_integration_tests/storage_http_tests.cpp +++ b/storage/storage_integration_tests/storage_http_tests.cpp @@ -24,22 +24,44 @@ using namespace storage; namespace { string const kCountryId = "Angola"; +string const kDisputedCountryId1 = "Jerusalem"; +string const kDisputedCountryId2 = "Crimea"; +string const kDisputedCountryId3 = "Campo de Hielo Sur"; +string const kUndisputedCountryId = "Argentina_Buenos Aires_North"; -void Update(TCountryId const &, storage::Storage::TLocalFilePtr const localCountryFile) +void Update(TCountryId const &, Storage::TLocalFilePtr const localCountryFile) { TEST_EQUAL(localCountryFile->GetCountryName(), kCountryId, ()); } -} // namespace - -UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) +void UpdateWithoutChecks(TCountryId const &, Storage::TLocalFilePtr const /* localCountryFile */) { - WritableDirChanger writableDirChanger(kMapTestDir); +} - Storage storage(COUNTRIES_FILE); +string const GetMwmFullPath(string const & countryId, string const & version) +{ + return my::JoinFoldersToPath({GetPlatform().WritableDir(), version}, + countryId + DATA_FILE_EXTENSION); +} + +string const GetDownloadingFullPath(string const & countryId, string const & version) +{ + return my::JoinFoldersToPath({GetPlatform().WritableDir(), version}, + kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION); +} + +string const GetResumeFullPath(string const & countryId, string const & version) +{ + return my::JoinFoldersToPath({GetPlatform().WritableDir(), version}, + kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION); +} + +void InitStorage(Storage & storage, Storage::TUpdateCallback const & didDownload, + Storage::TProgressFunction const & progress) +{ TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); - auto ChangeCountryFunction = [&](TCountryId const & countryId) + auto const changeCountryFunction = [&](TCountryId const & /* countryId */) { if (!storage.IsDownloadInProgress()) { @@ -48,7 +70,20 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) } }; - auto ProgressFunction = [&storage](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) + storage.Init(didDownload, [](TCountryId const &, Storage::TLocalFilePtr const){return false;}); + storage.RegisterAllLocalMaps(); + storage.Subscribe(changeCountryFunction, progress); + storage.SetDownloadingUrlsForTesting({kTestWebServer}); +} +} // namespace + +UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) +{ + WritableDirChanger writableDirChanger(kMapTestDir); + + Storage storage(COUNTRIES_FILE); + + auto const progressFunction = [&storage](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { NodeAttrs nodeAttrs; storage.GetNodeAttrs(countryId, nodeAttrs); @@ -58,28 +93,21 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) TEST_EQUAL(countryId, kCountryId, (countryId)); }; - storage.Init(Update, [](TCountryId const &, storage::Storage::TLocalFilePtr const){return false;}); - storage.RegisterAllLocalMaps(); - storage.Subscribe(ChangeCountryFunction, ProgressFunction); - storage.SetDownloadingUrlsForTesting({kTestWebServer}); + InitStorage(storage, Update, progressFunction); + string const version = strings::to_string(storage.GetCurrentDataVersion()); tests_support::ScopedDir cleanupVersionDir(version); - string const mwmFullPath = my::JoinFoldersToPath({GetPlatform().WritableDir(), version}, - kCountryId + DATA_FILE_EXTENSION); - string const downloadingFullPath = my::JoinFoldersToPath( - {GetPlatform().WritableDir(), version}, - kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION DOWNLOADING_FILE_EXTENSION); - string const resumeFullPath = my::JoinFoldersToPath( - {GetPlatform().WritableDir(), version}, - kCountryId + DATA_FILE_EXTENSION READY_FILE_EXTENSION RESUME_FILE_EXTENSION); - Platform & platform = GetPlatform(); + string const mwmFullPath = GetMwmFullPath(kCountryId, version); + string const downloadingFullPath = GetDownloadingFullPath(kCountryId, version); + string const resumeFullPath = GetResumeFullPath(kCountryId, version); // Downloading to an empty directory. storage.DownloadNode(kCountryId); // Wait for downloading complete. testing::RunEventLoop(); + Platform & platform = GetPlatform(); TEST(platform.IsFileExistsByFullPath(mwmFullPath), ()); TEST(!platform.IsFileExistsByFullPath(downloadingFullPath), ()); TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ()); @@ -94,3 +122,60 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) storage.DeleteNode(kCountryId); TEST(!platform.IsFileExistsByFullPath(mwmFullPath), ()); } + +UNIT_TEST(StorageDownloadAndDeleteDisputedNodeTests) +{ + WritableDirChanger writableDirChanger(kMapTestDir); + + Storage storage(COUNTRIES_FILE); + auto const progressFunction = [&storage](TCountryId const & countryId, + TLocalAndRemoteSize const & mapSize) + { + NodeAttrs nodeAttrs; + storage.GetNodeAttrs(countryId, nodeAttrs); + + TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId)); + TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId)); + }; + + InitStorage(storage, UpdateWithoutChecks, progressFunction); + + string const version = strings::to_string(storage.GetCurrentDataVersion()); + tests_support::ScopedDir cleanupVersionDir(version); + + string const mwmFullPath1 = GetMwmFullPath(kDisputedCountryId1, version); + string const mwmFullPath2 = GetMwmFullPath(kDisputedCountryId2, version); + string const mwmFullPath3 = GetMwmFullPath(kDisputedCountryId3, version); + string const mwmFullPathUndisputed = GetMwmFullPath(kUndisputedCountryId, version); + + // Downloading to an empty directory. + storage.DownloadNode(kDisputedCountryId1); + storage.DownloadNode(kDisputedCountryId2); + storage.DownloadNode(kDisputedCountryId3); + storage.DownloadNode(kUndisputedCountryId); + // Wait for downloading complete. + testing::RunEventLoop(); + + Platform & platform = GetPlatform(); + TEST(platform.IsFileExistsByFullPath(mwmFullPath1), ()); + TEST(platform.IsFileExistsByFullPath(mwmFullPath2), ()); + TEST(platform.IsFileExistsByFullPath(mwmFullPath3), ()); + TEST(platform.IsFileExistsByFullPath(mwmFullPathUndisputed), ()); + + TCountriesVec downloadedChildren; + TCountriesVec availChildren; + storage.GetChildrenInGroups(storage.GetRootId(), downloadedChildren, availChildren); + + TCountriesVec const expectedDownloadedChildren = {"Argentina", kDisputedCountryId2, kDisputedCountryId1}; + TEST_EQUAL(downloadedChildren, expectedDownloadedChildren, ()); + TEST_EQUAL(availChildren.size(), 221, ()); + + storage.DeleteNode(kDisputedCountryId1); + storage.DeleteNode(kDisputedCountryId2); + storage.DeleteNode(kDisputedCountryId3); + storage.DeleteNode(kUndisputedCountryId); + TEST(!platform.IsFileExistsByFullPath(mwmFullPath1), ()); + TEST(!platform.IsFileExistsByFullPath(mwmFullPath2), ()); + TEST(!platform.IsFileExistsByFullPath(mwmFullPath3), ()); + TEST(!platform.IsFileExistsByFullPath(mwmFullPathUndisputed), ()); +} diff --git a/storage/storage_integration_tests/storage_integration_tests.pro b/storage/storage_integration_tests/storage_integration_tests.pro index d1a60c60fd..d038ad45e4 100644 --- a/storage/storage_integration_tests/storage_integration_tests.pro +++ b/storage/storage_integration_tests/storage_integration_tests.pro @@ -35,4 +35,4 @@ SOURCES += \ storage_group_download_tests.cpp \ storage_http_tests.cpp \ storage_update_tests.cpp \ - test_defines.cpp + test_defines.cpp \ From 67fbb29d032b5968547dc07d1bf10f4040c6eac2 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 30 Mar 2016 17:22:55 +0300 Subject: [PATCH 3/4] Correcting xcode project. --- xcode/storage/storage.xcodeproj/project.pbxproj | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/xcode/storage/storage.xcodeproj/project.pbxproj b/xcode/storage/storage.xcodeproj/project.pbxproj index 54d8040c1b..64e503c9a5 100644 --- a/xcode/storage/storage.xcodeproj/project.pbxproj +++ b/xcode/storage/storage.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 34B093261C61F9BA0066F4C3 /* app_store.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34B093211C61F9BA0066F4C3 /* app_store.hpp */; }; 34C9BCFC1C6CCF85000DC38D /* country_name_getter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 34C9BCFA1C6CCF85000DC38D /* country_name_getter.cpp */; }; 34C9BCFD1C6CCF85000DC38D /* country_name_getter.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 34C9BCFB1C6CCF85000DC38D /* country_name_getter.hpp */; }; + 56D8CB991CAC17A80003F420 /* test_defines.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 56D8CB971CAC17A80003F420 /* test_defines.cpp */; }; + 56D8CB9A1CAC17A80003F420 /* test_defines.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 56D8CB981CAC17A80003F420 /* test_defines.hpp */; }; 671182CE1C7E06B400CB8177 /* storage_3levels_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */; }; 671182D21C7F0D5D00CB8177 /* WorldCoasts_obsolete.mwm in Resources */ = {isa = PBXBuildFile; fileRef = 671182D11C7F0D5400CB8177 /* WorldCoasts_obsolete.mwm */; }; 671182D31C7F0D5D00CB8177 /* WorldCoasts_obsolete.mwm in Resources */ = {isa = PBXBuildFile; fileRef = 671182D11C7F0D5400CB8177 /* WorldCoasts_obsolete.mwm */; }; @@ -158,6 +160,8 @@ 34B093211C61F9BA0066F4C3 /* app_store.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = app_store.hpp; sourceTree = ""; }; 34C9BCFA1C6CCF85000DC38D /* country_name_getter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = country_name_getter.cpp; sourceTree = ""; }; 34C9BCFB1C6CCF85000DC38D /* country_name_getter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = country_name_getter.hpp; sourceTree = ""; }; + 56D8CB971CAC17A80003F420 /* test_defines.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_defines.cpp; sourceTree = ""; }; + 56D8CB981CAC17A80003F420 /* test_defines.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = test_defines.hpp; sourceTree = ""; }; 670D05A81B0E04450013A7AC /* defaults.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = defaults.xcconfig; path = ../defaults.xcconfig; sourceTree = ""; }; 671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = storage_3levels_tests.cpp; sourceTree = ""; }; 671182CF1C7F0D5400CB8177 /* countries_obsolete.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = countries_obsolete.txt; sourceTree = ""; }; @@ -403,6 +407,8 @@ 672480071C60CE3D00EDE56A /* storage_integration_tests */ = { isa = PBXGroup; children = ( + 56D8CB971CAC17A80003F420 /* test_defines.cpp */, + 56D8CB981CAC17A80003F420 /* test_defines.hpp */, 671182CC1C7E069C00CB8177 /* storage_3levels_tests.cpp */, 676C83C01C637FAE00DC9603 /* storage_downloading_tests.cpp */, 676C83C11C637FAE00DC9603 /* storage_update_tests.cpp */, @@ -502,6 +508,7 @@ buildActionMask = 2147483647; files = ( 674125201B4C05FA00A3E828 /* map_files_downloader.hpp in Headers */, + 56D8CB9A1CAC17A80003F420 /* test_defines.hpp in Headers */, 6753430D1A3F5A2600A0A8C3 /* country_polygon.hpp in Headers */, 34C9BCFD1C6CCF85000DC38D /* country_name_getter.hpp in Headers */, 6741251F1B4C05FA00A3E828 /* http_map_files_downloader.hpp in Headers */, @@ -672,6 +679,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 56D8CB991CAC17A80003F420 /* test_defines.cpp in Sources */, 6753430E1A3F5A2600A0A8C3 /* country.cpp in Sources */, 67AF4A001BC579DD0048B1ED /* country_info_getter.cpp in Sources */, 34B093221C61F9BA0066F4C3 /* storage_helpers.cpp in Sources */, From 9e22a814da13570f582645b221c3774bbc8cdbd6 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Wed, 30 Mar 2016 17:36:51 +0300 Subject: [PATCH 4/4] Review fixes. --- .../storage_http_tests.cpp | 83 ++++++++++--------- .../test_defines.cpp | 3 + .../test_defines.hpp | 3 + 3 files changed, 50 insertions(+), 39 deletions(-) diff --git a/storage/storage_integration_tests/storage_http_tests.cpp b/storage/storage_integration_tests/storage_http_tests.cpp index 3f208c7c5f..cfe3683e94 100644 --- a/storage/storage_integration_tests/storage_http_tests.cpp +++ b/storage/storage_integration_tests/storage_http_tests.cpp @@ -75,35 +75,46 @@ void InitStorage(Storage & storage, Storage::TUpdateCallback const & didDownload storage.Subscribe(changeCountryFunction, progress); storage.SetDownloadingUrlsForTesting({kTestWebServer}); } -} // namespace -UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) +class StorageHttpTest { - WritableDirChanger writableDirChanger(kMapTestDir); +protected: + WritableDirChanger const m_writableDirChanger; + Storage m_storage; + string const m_version; + tests_support::ScopedDir const m_cleanupVersionDir; - Storage storage(COUNTRIES_FILE); +public: + StorageHttpTest() + : m_writableDirChanger(kMapTestDir), m_storage(COUNTRIES_FILE), + m_version(strings::to_string(m_storage.GetCurrentDataVersion())), + m_cleanupVersionDir(m_version) + { + TEST(version::IsSingleMwm(m_storage.GetCurrentDataVersion()), ()); + } +}; +} // namespace - auto const progressFunction = [&storage](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) +UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadNodeAndDeleteNode) +{ + auto const progressFunction = [this](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { NodeAttrs nodeAttrs; - storage.GetNodeAttrs(countryId, nodeAttrs); + m_storage.GetNodeAttrs(countryId, nodeAttrs); TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId)); TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId)); TEST_EQUAL(countryId, kCountryId, (countryId)); }; - InitStorage(storage, Update, progressFunction); + InitStorage(m_storage, Update, progressFunction); - string const version = strings::to_string(storage.GetCurrentDataVersion()); - tests_support::ScopedDir cleanupVersionDir(version); - - string const mwmFullPath = GetMwmFullPath(kCountryId, version); - string const downloadingFullPath = GetDownloadingFullPath(kCountryId, version); - string const resumeFullPath = GetResumeFullPath(kCountryId, version); + string const mwmFullPath = GetMwmFullPath(kCountryId, m_version); + string const downloadingFullPath = GetDownloadingFullPath(kCountryId, m_version); + string const resumeFullPath = GetResumeFullPath(kCountryId, m_version); // Downloading to an empty directory. - storage.DownloadNode(kCountryId); + m_storage.DownloadNode(kCountryId); // Wait for downloading complete. testing::RunEventLoop(); @@ -113,46 +124,40 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ()); // Downloading to directory with Angola.mwm. - storage.DownloadNode(kCountryId); + m_storage.DownloadNode(kCountryId); TEST(platform.IsFileExistsByFullPath(mwmFullPath), ()); TEST(!platform.IsFileExistsByFullPath(downloadingFullPath), ()); TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ()); - storage.DeleteNode(kCountryId); + m_storage.DeleteNode(kCountryId); TEST(!platform.IsFileExistsByFullPath(mwmFullPath), ()); } -UNIT_TEST(StorageDownloadAndDeleteDisputedNodeTests) +UNIT_CLASS_TEST(StorageHttpTest, StorageDownloadAndDeleteDisputedNode) { - WritableDirChanger writableDirChanger(kMapTestDir); - - Storage storage(COUNTRIES_FILE); - auto const progressFunction = [&storage](TCountryId const & countryId, + auto const progressFunction = [this](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { NodeAttrs nodeAttrs; - storage.GetNodeAttrs(countryId, nodeAttrs); + m_storage.GetNodeAttrs(countryId, nodeAttrs); TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId)); TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId)); }; - InitStorage(storage, UpdateWithoutChecks, progressFunction); + InitStorage(m_storage, UpdateWithoutChecks, progressFunction); - string const version = strings::to_string(storage.GetCurrentDataVersion()); - tests_support::ScopedDir cleanupVersionDir(version); - - string const mwmFullPath1 = GetMwmFullPath(kDisputedCountryId1, version); - string const mwmFullPath2 = GetMwmFullPath(kDisputedCountryId2, version); - string const mwmFullPath3 = GetMwmFullPath(kDisputedCountryId3, version); - string const mwmFullPathUndisputed = GetMwmFullPath(kUndisputedCountryId, version); + string const mwmFullPath1 = GetMwmFullPath(kDisputedCountryId1, m_version); + string const mwmFullPath2 = GetMwmFullPath(kDisputedCountryId2, m_version); + string const mwmFullPath3 = GetMwmFullPath(kDisputedCountryId3, m_version); + string const mwmFullPathUndisputed = GetMwmFullPath(kUndisputedCountryId, m_version); // Downloading to an empty directory. - storage.DownloadNode(kDisputedCountryId1); - storage.DownloadNode(kDisputedCountryId2); - storage.DownloadNode(kDisputedCountryId3); - storage.DownloadNode(kUndisputedCountryId); + m_storage.DownloadNode(kDisputedCountryId1); + m_storage.DownloadNode(kDisputedCountryId2); + m_storage.DownloadNode(kDisputedCountryId3); + m_storage.DownloadNode(kUndisputedCountryId); // Wait for downloading complete. testing::RunEventLoop(); @@ -164,16 +169,16 @@ UNIT_TEST(StorageDownloadAndDeleteDisputedNodeTests) TCountriesVec downloadedChildren; TCountriesVec availChildren; - storage.GetChildrenInGroups(storage.GetRootId(), downloadedChildren, availChildren); + m_storage.GetChildrenInGroups(m_storage.GetRootId(), downloadedChildren, availChildren); TCountriesVec const expectedDownloadedChildren = {"Argentina", kDisputedCountryId2, kDisputedCountryId1}; TEST_EQUAL(downloadedChildren, expectedDownloadedChildren, ()); TEST_EQUAL(availChildren.size(), 221, ()); - storage.DeleteNode(kDisputedCountryId1); - storage.DeleteNode(kDisputedCountryId2); - storage.DeleteNode(kDisputedCountryId3); - storage.DeleteNode(kUndisputedCountryId); + m_storage.DeleteNode(kDisputedCountryId1); + m_storage.DeleteNode(kDisputedCountryId2); + m_storage.DeleteNode(kDisputedCountryId3); + m_storage.DeleteNode(kUndisputedCountryId); TEST(!platform.IsFileExistsByFullPath(mwmFullPath1), ()); TEST(!platform.IsFileExistsByFullPath(mwmFullPath2), ()); TEST(!platform.IsFileExistsByFullPath(mwmFullPath3), ()); diff --git a/storage/storage_integration_tests/test_defines.cpp b/storage/storage_integration_tests/test_defines.cpp index a8f0279a8d..7618747d3e 100644 --- a/storage/storage_integration_tests/test_defines.cpp +++ b/storage/storage_integration_tests/test_defines.cpp @@ -1,4 +1,7 @@ #include "storage/storage_integration_tests/test_defines.hpp" +namespace storage +{ string const kMapTestDir = string("map-tests"); string const kTestWebServer = string("http://direct.mapswithme.com/"); +} // namespace storage diff --git a/storage/storage_integration_tests/test_defines.hpp b/storage/storage_integration_tests/test_defines.hpp index 27875cd25b..068e132b02 100644 --- a/storage/storage_integration_tests/test_defines.hpp +++ b/storage/storage_integration_tests/test_defines.hpp @@ -2,5 +2,8 @@ #include "std/string.hpp" +namespace storage +{ extern string const kMapTestDir; extern string const kTestWebServer; +} // namespace storage