diff --git a/storage/storage.cpp b/storage/storage.cpp index d120a5743d..51b2441256 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -334,6 +334,7 @@ void Storage::DeleteCustomCountryVersion(LocalCountryFile const & localFile) { CountryFile const countryFile = localFile.GetCountryFile(); localFile.DeleteFromDisk(MapOptions::MapWithCarRouting); + CountryIndexes::DeleteFromDisk(localFile); { auto it = m_localFilesForFakeCountries.find(countryFile); diff --git a/storage/storage.hpp b/storage/storage.hpp index 60c02a4c9b..3c7c76decb 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -177,6 +177,8 @@ public: void SetDownloaderForTesting(unique_ptr && downloader); private: + friend void UnitTest_StorageTest_DeleteCountry(); + TStatus CountryStatusWithoutFailed(TIndex const & index) const; TStatus CountryStatusFull(TIndex const & index, TStatus const status) const; diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index e3be812cf0..b481b9dd59 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -11,6 +11,7 @@ #include "platform/local_country_file.hpp" #include "platform/local_country_file_utils.hpp" #include "platform/platform.hpp" +#include "platform/platform_tests_support/scoped_file.hpp" #include "coding/file_name_utils.hpp" #include "coding/file_writer.hpp" @@ -23,12 +24,14 @@ #include "std/bind.hpp" #include "std/map.hpp" +#include "std/shared_ptr.hpp" #include "std/unique_ptr.hpp" #include "std/vector.hpp" using namespace platform; -using namespace storage; +namespace storage +{ namespace { // This class checks steps Storage::DownloadMap() performs to download a map. @@ -583,3 +586,37 @@ UNIT_TEST(StorageTest_CancelDownloadingWhenAlmostDone) shared_ptr file = storage.GetLatestLocalFile(index); TEST(!file, (*file)); } + +UNIT_TEST(StorageTest_DeleteCountry) +{ + Storage storage; + TaskRunner runner; + InitStorage(storage, runner); + + tests_support::ScopedFile map("Uruguay.mwm", "Map"); + tests_support::ScopedFile routing("Uruguay.mwm.routing", "Map"); + LocalCountryFile file = LocalCountryFile::MakeForTesting("Uruguay"); + TEST_EQUAL(MapOptions::MapWithCarRouting, file.GetFiles(), ()); + + TEST(CountryIndexes::PreparePlaceOnDisk(file), ()); + string const bitsPath = CountryIndexes::GetPath(file, CountryIndexes::Index::Bits); + { + FileWriter writer(bitsPath); + string const data = "bits"; + writer.Write(data.data(), data.size()); + } + + storage.RegisterCountryFiles(make_shared(file)); + TEST(map.Exists(), ()); + TEST(routing.Exists(), ()); + TEST(Platform::IsFileExistsByFullPath(bitsPath), (bitsPath)); + + storage.DeleteCustomCountryVersion(file); + TEST(!map.Exists(), ()) + TEST(!routing.Exists(), ()) + TEST(!Platform::IsFileExistsByFullPath(bitsPath), (bitsPath)); + + map.Reset(); + routing.Reset(); +} +} // namespace storage diff --git a/storage/storage_tests/storage_tests.pro b/storage/storage_tests/storage_tests.pro index 1f59397d0d..65dbb75102 100644 --- a/storage/storage_tests/storage_tests.pro +++ b/storage/storage_tests/storage_tests.pro @@ -6,7 +6,7 @@ CONFIG -= app_bundle TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = storage indexer platform geometry coding base jansson tomcrypt stats_client zlib +DEPENDENCIES = storage indexer platform_tests_support platform geometry coding base jansson tomcrypt stats_client zlib include($$ROOT_DIR/common.pri)