diff --git a/platform/local_country_file.cpp b/platform/local_country_file.cpp index f49d9364ce..b471abc4e9 100644 --- a/platform/local_country_file.cpp +++ b/platform/local_country_file.cpp @@ -100,10 +100,10 @@ bool LocalCountryFile::operator==(LocalCountryFile const & rhs) const } // static -LocalCountryFile LocalCountryFile::MakeForTesting(string const & countryFileName) +LocalCountryFile LocalCountryFile::MakeForTesting(string const & countryFileName, int64_t version) { CountryFile const countryFile(countryFileName); - LocalCountryFile localFile(GetPlatform().WritableDir(), countryFile, 0 /* version */); + LocalCountryFile localFile(GetPlatform().WritableDir(), countryFile, version); localFile.SyncWithDisk(); return localFile; } diff --git a/platform/local_country_file.hpp b/platform/local_country_file.hpp index 7ead5f1d86..1906fd82ee 100644 --- a/platform/local_country_file.hpp +++ b/platform/local_country_file.hpp @@ -72,7 +72,7 @@ public: // Creates LocalCountryFile for test purposes, for a country region // with countryFileName (without any extensions). Automatically // performs sync with disk. - static LocalCountryFile MakeForTesting(string const & countryFileName); + static LocalCountryFile MakeForTesting(string const & countryFileName, int64_t version = 0); /// @todo The easiest solution for now. Need to be removed in future. /// @param fullPath Full path to the mwm file. diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 4dcf6994c3..be0f212988 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -14,6 +14,7 @@ #include "platform/platform.hpp" #include "platform/platform_tests_support/scoped_dir.hpp" #include "platform/platform_tests_support/scoped_file.hpp" +#include "platform/settings.hpp" #include "coding/file_name_utils.hpp" #include "coding/file_writer.hpp" @@ -32,6 +33,8 @@ #include "std/unique_ptr.hpp" #include "std/vector.hpp" +#include "storage/storage_tests/write_dir_changer.hpp" + #include using namespace platform; @@ -322,10 +325,22 @@ void InitStorage(Storage & storage, TaskRunner & runner, storage.RegisterAllLocalMaps(); storage.SetDownloaderForTesting(make_unique(runner)); } + +string const kTestDir = "storage_tests"; + +void SetMigrationComplete() +{ + int constexpr kSmallMwmVersion = 160107; + Settings::Set("LastMigration", kSmallMwmVersion); +} } // namespace UNIT_TEST(StorageTest_Smoke) { + WritableDirChanger writableDirChanger(kTestDir); + + SetMigrationComplete(); + Storage storage; TIndex const usaGeorgiaIndex = storage.FindIndexByFile("US_Georgia_North"); @@ -345,6 +360,8 @@ UNIT_TEST(StorageTest_Smoke) UNIT_TEST(StorageTest_SingleCountryDownloading) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner); @@ -376,6 +393,8 @@ UNIT_TEST(StorageTest_SingleCountryDownloading) UNIT_TEST(StorageTest_TwoCountriesDownloading) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner); @@ -403,6 +422,8 @@ UNIT_TEST(StorageTest_TwoCountriesDownloading) UNIT_TEST(StorageTest_DeleteTwoVersionsOfTheSameCountry) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; storage.Init(&OnCountryDownloaded); storage.RegisterAllLocalMaps(); @@ -443,6 +464,8 @@ UNIT_TEST(StorageTest_DeleteTwoVersionsOfTheSameCountry) UNIT_TEST(StorageTest_DownloadCountryAndDeleteRoutingOnly) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; if (version::IsSingleMwm(storage.GetCurrentDataVersion())) @@ -481,6 +504,8 @@ UNIT_TEST(StorageTest_DownloadCountryAndDeleteRoutingOnly) UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; tests::TestMwmSet mwmSet; @@ -562,6 +587,8 @@ UNIT_TEST(StorageTest_DownloadMapAndRoutingSeparately) UNIT_TEST(StorageTest_DeletePendingCountry) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner); @@ -581,6 +608,8 @@ UNIT_TEST(StorageTest_DeletePendingCountry) UNIT_TEST(StorageTest_DownloadTwoCountriesAndDelete) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner); @@ -650,13 +679,15 @@ UNIT_TEST(StorageTest_CancelDownloadingWhenAlmostDone) UNIT_TEST(StorageTest_DeleteCountry) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner); tests_support::ScopedFile map("Wonderland.mwm", "map"); tests_support::ScopedFile routing("Wonderland.mwm.routing", "routing"); - LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland"); + LocalCountryFile file = LocalCountryFile::MakeForTesting("Wonderland", storage.GetCurrentDataVersion()); TEST_EQUAL(MapOptions::MapWithCarRouting, file.GetFiles(), ()); CountryIndexes::PreparePlaceOnDisk(file); @@ -684,6 +715,8 @@ UNIT_TEST(StorageTest_DeleteCountry) UNIT_TEST(StorageTest_FailedDownloading) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; storage.Init(&OnCountryDownloaded); storage.SetDownloaderForTesting(make_unique()); @@ -718,6 +751,8 @@ UNIT_TEST(StorageTest_FailedDownloading) // is no routing file for this island. UNIT_TEST(StorageTest_EmptyRoutingFile) { + WritableDirChanger writableDirChanger(kTestDir); + Storage storage; TaskRunner runner; InitStorage(storage, runner, [](LocalCountryFile const & localFile) @@ -742,6 +777,8 @@ UNIT_TEST(StorageTest_EmptyRoutingFile) UNIT_TEST(StorageTest_ObsoleteMapsRemoval) { + WritableDirChanger writableDirChanger(kTestDir); + CountryFile country("Azerbaijan"); tests_support::ScopedDir dir1("1"); diff --git a/storage/storage_tests/write_dir_changer.cpp b/storage/storage_tests/write_dir_changer.cpp index 16748894e6..b56a02c26d 100644 --- a/storage/storage_tests/write_dir_changer.cpp +++ b/storage/storage_tests/write_dir_changer.cpp @@ -3,6 +3,7 @@ #include "write_dir_changer.hpp" #include "platform/platform.hpp" +#include "platform/settings.hpp" #include "coding/file_name_utils.hpp" #include "coding/internal/file_data.hpp" @@ -16,10 +17,12 @@ WritableDirChanger::WritableDirChanger(string testDir) TEST(!platform.IsFileExistsByFullPath(m_testDirFullPath), ()); TEST_EQUAL(Platform::ERR_OK, platform.MkDir(m_testDirFullPath), ()); platform.SetWritableDirForTests(m_testDirFullPath); + Settings::Clear(); } WritableDirChanger::~WritableDirChanger() { + Settings::Clear(); Platform & platform = GetPlatform(); string const writableDirForTest = platform.WritableDir(); platform.SetWritableDirForTests(m_writableDirBeforeTest);