diff --git a/data/countries.txt b/data/countries.txt index fb2c67b372..e6e2ef69d7 100644 --- a/data/countries.txt +++ b/data/countries.txt @@ -2,6 +2,11 @@ "v": 211122, "id": "Countries", "g": [ + { + "id": "Resources", + "s": 40570432, + "sha1_base64": "s5QytYD+VLl4aG4B/53ZHqcfRUw=" + }, { "id": "Abkhazia", "old": [ diff --git a/defines.hpp b/defines.hpp index 27c0b9271b..cd97d6bcf7 100644 --- a/defines.hpp +++ b/defines.hpp @@ -13,6 +13,7 @@ #define ARCHIVE_TRACKS_FILE_EXTENSION ".track" #define ARCHIVE_TRACKS_ZIPPED_FILE_EXTENSION ".track.zip" #define STATS_EXTENSION ".stats" +#define RESOURCES_EXTENSION ".zip" #define NODES_FILE "nodes.dat" #define WAYS_FILE "ways.dat" @@ -74,6 +75,7 @@ #define WORLD_FILE_NAME "World" #define WORLD_COASTS_FILE_NAME "WorldCoasts" +#define RESOURCES_FILE_NAME "Resources" #define SETTINGS_FILE_NAME "settings.ini" #define MARKETING_SETTINGS_FILE_NAME "marketing_settings.ini" diff --git a/platform/country_file.cpp b/platform/country_file.cpp index 6ff6e77eab..eb3f977518 100644 --- a/platform/country_file.cpp +++ b/platform/country_file.cpp @@ -12,9 +12,7 @@ using namespace std; namespace { -/// \returns file name (m_name) with extension dependent on the file param. -/// The extension could be .mwm.routing or just .mwm. -/// The method is used for old (two components) mwm support. +/// \returns Map's file name with extension depending on the \a file type. string GetNameWithExt(string const & countryFile, MapFileType file) { switch (file) @@ -42,9 +40,20 @@ CountryFile::CountryFile(std::string name, MwmSize size, std::string sha1) { } -string GetFileName(string const & countryFile, MapFileType type) +string CountryFile::GetFileName(MapFileType type) const { - return GetNameWithExt(countryFile, type); + ASSERT(!m_name.empty(), ()); + + if (m_name == RESOURCES_FILE_NAME) + { + std::string res = m_name + RESOURCES_EXTENSION; + // Map and Diff should be different to avoid conflicts. + if (type == MapFileType::Diff) + res += "diff"; + return res; + } + + return GetNameWithExt(m_name, type); } string DebugPrint(CountryFile const & file) diff --git a/platform/country_file.hpp b/platform/country_file.hpp index 01f0521896..efd9c684ae 100644 --- a/platform/country_file.hpp +++ b/platform/country_file.hpp @@ -19,10 +19,13 @@ public: explicit CountryFile(std::string name); CountryFile(std::string name, MwmSize size, std::string sha1); + /// \returns File name with extension (for download url and save on disk) for \a type. + /// For example Abkhazia.mwm or Resources.zip + std::string GetFileName(MapFileType type) const; + /// \returns Empty (invalid) CountryFile. bool IsEmpty() const { return m_name.empty(); } - /// \returns file name without extensions. std::string const & GetName() const { return m_name; } MwmSize GetRemoteSize() const { return m_mapSize; } std::string const & GetSha1() const { return m_sha1; } @@ -41,9 +44,5 @@ private: std::string m_sha1; }; -/// \returns This method returns file name with extension. For example Abkhazia.mwm. -/// \param countryFile is a file name without extension. For example Abkhazia. -/// \param type is type of map data. -std::string GetFileName(std::string const & countryFile, MapFileType type); std::string DebugPrint(CountryFile const & file); } // namespace platform diff --git a/platform/local_country_file.cpp b/platform/local_country_file.cpp index 1a2c8bf9c8..7e1acd73ca 100644 --- a/platform/local_country_file.cpp +++ b/platform/local_country_file.cpp @@ -10,6 +10,7 @@ #include "base/file_name_utils.hpp" #include "base/logging.hpp" #include "base/stl_helpers.hpp" +#include "base/string_utils.hpp" #include #include @@ -56,7 +57,12 @@ void LocalCountryFile::DeleteFromDisk(MapFileType type) const string LocalCountryFile::GetPath(MapFileType type) const { - return base::JoinPath(m_directory, GetFileName(m_countryFile.GetName(), type)); + return base::JoinPath(m_directory, GetFileName(type)); +} + +std::string LocalCountryFile::GetFileName(MapFileType type) const +{ + return m_countryFile.GetFileName(type); } uint64_t LocalCountryFile::GetSize(MapFileType type) const @@ -74,9 +80,18 @@ bool LocalCountryFile::HasFiles() const bool LocalCountryFile::OnDisk(MapFileType type) const { - ASSERT_LESS(base::Underlying(type), m_files.size(), ()); + auto const ut = base::Underlying(type); + ASSERT_LESS(ut, m_files.size(), ()); + return m_files[ut].has_value(); +} - return m_files[base::Underlying(type)].has_value(); +LocalCountryFile::DirectoryType LocalCountryFile::GetDirectoryType() const +{ + if (m_directory.empty()) + return BUNDLE; + if (strings::EndsWith(m_directory, RESOURCES_EXTENSION)) + return RESOURCE; + return DISK_PATH; } bool LocalCountryFile::operator<(LocalCountryFile const & rhs) const diff --git a/platform/local_country_file.hpp b/platform/local_country_file.hpp index a0b023a818..2d038238ec 100644 --- a/platform/local_country_file.hpp +++ b/platform/local_country_file.hpp @@ -48,6 +48,7 @@ public: // Returns path to a file. // Return value may be empty until SyncWithDisk() is called. std::string GetPath(MapFileType type) const; + std::string GetFileName(MapFileType type) const; // Returns size of a file. // Return value may be zero until SyncWithDisk() is called. @@ -61,6 +62,9 @@ public: // Return value will be false until SyncWithDisk() is called. bool OnDisk(MapFileType type) const; + enum DirectoryType { BUNDLE, RESOURCE, DISK_PATH }; + DirectoryType GetDirectoryType() const; + std::string const & GetDirectory() const { return m_directory; } std::string const & GetCountryName() const { return m_countryFile.GetName(); } int64_t GetVersion() const { return m_version; } @@ -84,8 +88,7 @@ private: friend void FindAllLocalMapsAndCleanup(int64_t latestVersion, std::string const & dataDir, std::vector & localFiles); - /// @note! If directory is empty, the file is stored in resources. - /// In this case, the only valid params are m_countryFile and m_version. + /// @see GetDirectoryType. std::string m_directory; CountryFile m_countryFile; int64_t m_version; diff --git a/platform/local_country_file_utils.cpp b/platform/local_country_file_utils.cpp index e9c263f703..b7a892f2a3 100644 --- a/platform/local_country_file_utils.cpp +++ b/platform/local_country_file_utils.cpp @@ -1,5 +1,6 @@ #include "platform/local_country_file_utils.hpp" +#include "platform/constants.hpp" #include "platform/country_file.hpp" #include "platform/mwm_version.hpp" #include "platform/platform.hpp" @@ -7,6 +8,7 @@ #include "coding/internal/file_data.hpp" #include "coding/reader.hpp" +#include "coding/zip_reader.hpp" #include "base/assert.hpp" #include "base/file_name_utils.hpp" @@ -33,9 +35,7 @@ char const kBitsExt[] = ".bftsegbits"; char const kNodesExt[] = ".bftsegnodes"; char const kOffsetsExt[] = ".offsets"; -size_t const kMaxTimestampLength = 18; - -string GetSpecialFilesSearchScope() +string GetAdditionalWorldScope() { return "r"; } @@ -110,10 +110,10 @@ void FindAllDiffsInDirectory(string const & dir, vector & diff } } -string GetFilePath(int64_t version, string const & dataDir, CountryFile const & countryFile, - MapFileType type) +string GetFilePath(int64_t version, string const & dataDir, + CountryFile const & countryFile, MapFileType type) { - string const filename = GetFileName(countryFile.GetName(), type); + string const filename = countryFile.GetFileName(type); string const dir = GetDataDirFullPath(dataDir); if (version == 0) return base::JoinPath(dir, filename); @@ -153,8 +153,9 @@ void FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t ver Platform & platform = GetPlatform(); Platform::TFilesWithType fwts; - platform.GetFilesByType(directory, Platform::FILE_TYPE_REGULAR | Platform::FILE_TYPE_DIRECTORY, - fwts); + platform.GetFilesByType(directory, Platform::FILE_TYPE_REGULAR | Platform::FILE_TYPE_DIRECTORY, fwts); + + char const * resourcesFile = RESOURCES_FILE_NAME RESOURCES_EXTENSION; unordered_set names; for (auto const & fwt : fwts) @@ -171,15 +172,22 @@ void FindAllLocalMapsInDirectoryAndCleanup(string const & directory, int64_t ver continue; } - if (!strings::EndsWith(name, DATA_FILE_EXTENSION)) - continue; + if (strings::EndsWith(name, DATA_FILE_EXTENSION)) + { + // Remove DATA_FILE_EXTENSION and use base name as a country file name. + base::GetNameWithoutExt(name); + names.insert(name); + localFiles.emplace_back(directory, CountryFile(std::move(name)), version); + } + else if (name == resourcesFile) + { + localFiles.emplace_back(directory, CountryFile(RESOURCES_FILE_NAME), version); - // Remove DATA_FILE_EXTENSION and use base name as a country file name. - base::GetNameWithoutExt(name); - names.insert(name); - LocalCountryFile localFile(directory, CountryFile(name), version); - - localFiles.push_back(localFile); + /// @todo Should we check actual MWMs presence in resource container? + auto const fullPath = base::JoinPath(directory, name); + localFiles.emplace_back(fullPath, CountryFile(WORLD_FILE_NAME), version); + localFiles.emplace_back(fullPath, CountryFile(WORLD_COASTS_FILE_NAME), version); + } } for (auto const & fwt : fwts) @@ -241,8 +249,8 @@ void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir, LOG(LWARNING, ("Can't remove directory:", fullPath, err)); } - // World and WorldCoasts can be stored in app bundle or in resources - // directory, thus it's better to get them via Platform. + // Check for World and WorldCoasts in app bundle or in resources. + Platform & platform = GetPlatform(); string const world(WORLD_FILE_NAME); string const worldCoasts(WORLD_COASTS_FILE_NAME); for (string const & file : {world, worldCoasts}) @@ -256,20 +264,20 @@ void FindAllLocalMapsAndCleanup(int64_t latestVersion, string const & dataDir, try { - Platform & platform = GetPlatform(); - ModelReaderPtr reader( - platform.GetReader(file + DATA_FILE_EXTENSION, GetSpecialFilesSearchScope())); + ModelReaderPtr reader(platform.GetReader(file + DATA_FILE_EXTENSION, GetAdditionalWorldScope())); - // Assume that empty path means the resource file. - LocalCountryFile worldFile{string(), CountryFile(file), version::ReadVersionDate(reader)}; - worldFile.m_files[base::Underlying(MapFileType::Map)] = 1; + // Empty path means the resource file. + LocalCountryFile worldFile(string(), CountryFile(file), version::ReadVersionDate(reader)); + worldFile.m_files[base::Underlying(MapFileType::Map)] = reader.Size(); + + // Replace if newer only. if (i != localFiles.end()) { - // Always use resource World files instead of local on disk. - *i = worldFile; + if (worldFile.GetVersion() > i->GetVersion()) + *i = std::move(worldFile); } else - localFiles.push_back(worldFile); + localFiles.push_back(std::move(worldFile)); } catch (RootException const & ex) { @@ -328,26 +336,25 @@ string GetFileDownloadPath(int64_t version, CountryFile const & countryFile, Map return GetFileDownloadPath(version, string(), countryFile, type); } -string GetFileDownloadPath(int64_t version, string const & dataDir, CountryFile const & countryFile, - MapFileType type) +string GetFileDownloadPath(int64_t version, string const & dataDir, + CountryFile const & countryFile, MapFileType type) { - string const readyFile = GetFileName(countryFile.GetName(), type) + READY_FILE_EXTENSION; - string const dir = GetDataDirFullPath(dataDir); - if (version == 0) - return base::JoinPath(dir, readyFile); - return base::JoinPath(dir, strings::to_string(version), readyFile); + return GetFilePath(version, dataDir, countryFile, type) + READY_FILE_EXTENSION; } -unique_ptr GetCountryReader(platform::LocalCountryFile const & file, MapFileType type) +unique_ptr GetCountryReader(LocalCountryFile const & file, MapFileType type) { Platform & platform = GetPlatform(); - // See LocalCountryFile comment for explanation. - if (file.GetDirectory().empty()) + switch (file.GetDirectoryType()) { - return platform.GetReader(file.GetCountryName() + DATA_FILE_EXTENSION, - GetSpecialFilesSearchScope()); + case LocalCountryFile::BUNDLE: + return platform.GetReader(file.GetFileName(type), GetAdditionalWorldScope()); + case LocalCountryFile::RESOURCE: + return make_unique(file.GetDirectory(), file.GetFileName(type), + READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT); + case LocalCountryFile::DISK_PATH: + return platform.GetReader(file.GetPath(type), "f"); } - return platform.GetReader(file.GetPath(type), "f"); } // static @@ -417,11 +424,9 @@ string CountryIndexes::IndexesDir(LocalCountryFile const & localFile) string dir = localFile.GetDirectory(); CountryFile const & file = localFile.GetCountryFile(); - /// @todo It's a temporary code until we will put fIndex->fOffset into mwm container. - /// IndexesDir should not throw any exceptions. - if (dir.empty()) + if (localFile.GetDirectoryType() == LocalCountryFile::BUNDLE) { - // Local file is stored in resources. Need to prepare index folder in the writable directory. + // Local file is stored in bundle. Need to prepare index folder in the writable directory. int64_t const version = localFile.GetVersion(); ASSERT_GREATER(version, 0, ()); diff --git a/platform/platform_tests/country_file_tests.cpp b/platform/platform_tests/country_file_tests.cpp index f3b313b491..c44a9d17de 100644 --- a/platform/platform_tests/country_file_tests.cpp +++ b/platform/platform_tests/country_file_tests.cpp @@ -16,7 +16,7 @@ UNIT_TEST(CountryFile_Smoke) { CountryFile cf("One"); TEST_EQUAL("One", cf.GetName(), ()); - string const mapFileName = GetFileName(cf.GetName(), MapFileType::Map); + string const mapFileName = cf.GetFileName(MapFileType::Map); TEST_EQUAL("One" DATA_FILE_EXTENSION, mapFileName, ()); TEST_EQUAL(0, cf.GetRemoteSize(), ()); @@ -25,7 +25,7 @@ UNIT_TEST(CountryFile_Smoke) { CountryFile cf("Three", 666, "xxxSHAxxx"); TEST_EQUAL("Three", cf.GetName(), ()); - string const mapFileName = GetFileName(cf.GetName(), MapFileType::Map); + string const mapFileName = cf.GetFileName(MapFileType::Map); TEST_EQUAL("Three" DATA_FILE_EXTENSION, mapFileName, ()); TEST_EQUAL(666, cf.GetRemoteSize(), ()); diff --git a/platform/platform_tests/downloader_utils_tests.cpp b/platform/platform_tests/downloader_utils_tests.cpp index 82e59a8d31..cff1f8ba7e 100644 --- a/platform/platform_tests/downloader_utils_tests.cpp +++ b/platform/platform_tests/downloader_utils_tests.cpp @@ -4,17 +4,18 @@ #include "platform/local_country_file_utils.hpp" #include "platform/mwm_version.hpp" +using namespace platform; + UNIT_TEST(UrlConversionTest) { { - std::string const mwmName = "Luna"; - std::string const fileName = platform::GetFileName(mwmName, MapFileType::Map); + CountryFile mwmCF("Luna"); + std::string const fileName = mwmCF.GetFileName(MapFileType::Map); int64_t const dataVersion = version::FOR_TESTING_MWM1; int64_t const diffVersion = 0; MapFileType const fileType = MapFileType::Map; - auto const path = - platform::GetFileDownloadPath(dataVersion, platform::CountryFile(mwmName), fileType); + auto const path = GetFileDownloadPath(dataVersion, mwmCF, fileType); auto const url = downloader::GetFileDownloadUrl(fileName, dataVersion, diffVersion); auto const resultPath = downloader::GetFilePathByUrl(url); @@ -22,14 +23,13 @@ UNIT_TEST(UrlConversionTest) TEST_EQUAL(path, resultPath, ()); } { - std::string const mwmName = "Luna"; - std::string const fileName = platform::GetFileName(mwmName, MapFileType::Diff); + CountryFile mwmCF("Luna"); + std::string const fileName = mwmCF.GetFileName(MapFileType::Diff); int64_t const dataVersion = version::FOR_TESTING_MWM2; int64_t const diffVersion = version::FOR_TESTING_MWM1; MapFileType const fileType = MapFileType::Diff; - auto const path = - platform::GetFileDownloadPath(dataVersion, platform::CountryFile(mwmName), fileType); + auto const path = GetFileDownloadPath(dataVersion, mwmCF, fileType); auto const url = downloader::GetFileDownloadUrl(fileName, dataVersion, diffVersion); auto const resultPath = downloader::GetFilePathByUrl(url); @@ -40,9 +40,9 @@ UNIT_TEST(UrlConversionTest) UNIT_TEST(IsUrlSupportedTest) { - std::string const mwmName = "Luna"; + CountryFile mwmCF("Luna"); - std::string fileName = platform::GetFileName(mwmName, MapFileType::Map); + std::string fileName = mwmCF.GetFileName(MapFileType::Map); int64_t dataVersion = version::FOR_TESTING_MWM1; int64_t diffVersion = 0; @@ -59,7 +59,7 @@ UNIT_TEST(IsUrlSupportedTest) TEST(!downloader::IsUrlSupported("Luna.mwm"), ()); TEST(!downloader::IsUrlSupported("Luna"), ()); - fileName = platform::GetFileName(mwmName, MapFileType::Diff); + fileName = mwmCF.GetFileName(MapFileType::Diff); diffVersion = version::FOR_TESTING_MWM1; url = downloader::GetFileDownloadUrl(fileName, dataVersion, diffVersion); TEST(downloader::IsUrlSupported(url), ()); diff --git a/platform/platform_tests/local_country_file_tests.cpp b/platform/platform_tests/local_country_file_tests.cpp index 9f0a54ccb3..53836198be 100644 --- a/platform/platform_tests/local_country_file_tests.cpp +++ b/platform/platform_tests/local_country_file_tests.cpp @@ -96,7 +96,7 @@ UNIT_TEST(LocalCountryFile_DiskFiles) TEST(!localFile.OnDisk(MapFileType::Map), ()); TEST(!localFile.OnDisk(MapFileType::Diff), ()); - string const mapFileName = GetFileName(countryFile.GetName(), MapFileType::Map); + string const mapFileName = countryFile.GetFileName(MapFileType::Map); string const mapFileContents("map"); ScopedFile testMapFile(mapFileName, mapFileContents); diff --git a/platform/platform_tests_support/scoped_file.cpp b/platform/platform_tests_support/scoped_file.cpp index 105c5e2b1f..9249b11ac2 100644 --- a/platform/platform_tests_support/scoped_file.cpp +++ b/platform/platform_tests_support/scoped_file.cpp @@ -31,9 +31,7 @@ ScopedFile::ScopedFile(std::string const & relativePath, std::string const & con } ScopedFile::ScopedFile(ScopedDir const & dir, CountryFile const & countryFile, MapFileType type) - : ScopedFile( - base::JoinPath(dir.GetRelativePath(), GetFileName(countryFile.GetName(), type)), - Mode::Create) +: ScopedFile(base::JoinPath(dir.GetRelativePath(), countryFile.GetFileName(type)), Mode::Create) { } diff --git a/storage/country_info_getter.cpp b/storage/country_info_getter.cpp index a72adaeff4..cf881069f0 100644 --- a/storage/country_info_getter.cpp +++ b/storage/country_info_getter.cpp @@ -148,9 +148,16 @@ m2::RectD CountryInfoGetter::CalcLimitRect(std::string const & prefix) const m2::RectD CountryInfoGetter::GetLimitRectForLeaf(CountryId const & leafCountryId) const { auto const it = m_countryIndex.find(leafCountryId); - ASSERT(it != m_countryIndex.end(), ()); - ASSERT_LESS(it->second, m_countries.size(), ()); - return m_countries[it->second].m_rect; + if (it != m_countryIndex.end()) + { + ASSERT_LESS(it->second, m_countries.size(), ()); + return m_countries[it->second].m_rect; + } + else + { + // Full rect for World files. + return mercator::Bounds::FullRect(); + } } void CountryInfoGetter::GetMatchedRegions(std::string const & affiliation, diff --git a/storage/queued_country.cpp b/storage/queued_country.cpp index 2dda9b7526..542a0e5813 100644 --- a/storage/queued_country.cpp +++ b/storage/queued_country.cpp @@ -53,7 +53,7 @@ CountryId const & QueuedCountry::GetCountryId() const std::string QueuedCountry::GetRelativeUrl() const { - auto const fileName = platform::GetFileName(m_countryFile.GetName(), m_fileType); + auto const fileName = m_countryFile.GetFileName(m_fileType); uint64_t diffVersion = 0; if (m_fileType == MapFileType::Diff) diff --git a/storage/storage.cpp b/storage/storage.cpp index b58e3be55b..372516faaa 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -271,7 +271,10 @@ void Storage::GetLocalMaps(vector & maps) const CHECK_THREAD_CHECKER(m_threadChecker, ()); for (auto const & p : m_localFiles) - maps.push_back(GetLatestLocalFile(p.first)); + { + if (!IsResourceID(p.first)) + maps.push_back(GetLatestLocalFile(p.first)); + } for (auto const & p : m_localFilesForFakeCountries) maps.push_back(p.second); @@ -706,8 +709,15 @@ void Storage::RegisterDownloadedFiles(CountryId const & countryId, MapFileType t CountryFile const countryFile = GetCountryFile(countryId); LocalFilePtr localFile = GetLocalFile(countryId, GetCurrentDataVersion()); - if (!localFile) + + if (!localFile || localFile->GetDirectoryType() == LocalCountryFile::BUNDLE) localFile = PreparePlaceForCountryFiles(GetCurrentDataVersion(), m_dataDir, countryFile); + else + { + /// @todo If localFile already exists, we will remove it from disk below? + LOG(LERROR, ("Downloaded country file for already existing one", *localFile)); + } + if (!localFile) { LOG(LERROR, ("Can't prepare LocalCountryFile for", countryFile, "in folder", m_dataDir)); @@ -778,13 +788,9 @@ void Storage::GetOutdatedCountries(vector & countries) const for (auto const & p : m_localFiles) { CountryId const & countryId = p.first; - string const name = GetCountryFile(countryId).GetName(); LocalFilePtr file = GetLatestLocalFile(countryId); - if (file && file->GetVersion() != GetCurrentDataVersion() && name != WORLD_COASTS_FILE_NAME - && name != WORLD_FILE_NAME) - { + if (file && file->GetVersion() != GetCurrentDataVersion()) countries.push_back(&CountryLeafByCountryId(countryId)); - } } } @@ -1243,6 +1249,19 @@ bool Storage::IsDisputed(CountryTree::Node const & node) const return found.size() > 1; } +bool Storage::IsRealCountryLeaf(CountryTree::Node const & node) +{ + if (node.ChildrenCount() != 0) + return false; + + return !IsResourceID(node.Value().Name()); +} + +bool Storage::IsResourceID(CountryId const & countryId) +{ + return countryId == RESOURCES_FILE_NAME; +} + void Storage::CalcMaxMwmSizeBytes() { m_maxMwmSizeBytes = 0; diff --git a/storage/storage.hpp b/storage/storage.hpp index 2dfd4c4d0c..277cdf955f 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -629,6 +629,10 @@ private: /// @return true if |node.Value().Name()| is a disputed territory and false otherwise. bool IsDisputed(CountryTree::Node const & node) const; + /// @return true iff \a node is a country MWM leaf of the tree. + static bool IsRealCountryLeaf(CountryTree::Node const & node); + static bool IsResourceID(CountryId const & countryId); + void CalcMaxMwmSizeBytes(); void OnMapDownloadFailed(CountryId const & countryId); @@ -708,7 +712,7 @@ void Storage::ForEachCountry(ToDo && toDo) const { m_countries.GetRoot().ForEachInSubtree([&](CountryTree::Node const & node) { - if (node.ChildrenCount() == 0) + if (IsRealCountryLeaf(node)) toDo(node.Value()); }); } diff --git a/storage/storage_tests/CMakeLists.txt b/storage/storage_tests/CMakeLists.txt index 2cebfe6c5c..3233d526f3 100644 --- a/storage/storage_tests/CMakeLists.txt +++ b/storage/storage_tests/CMakeLists.txt @@ -1,6 +1,7 @@ project(storage_tests) set(SRC + countries_tests.cpp country_info_getter_tests.cpp country_name_getter_tests.cpp downloader_tests.cpp diff --git a/storage/storage_tests/countries_tests.cpp b/storage/storage_tests/countries_tests.cpp new file mode 100644 index 0000000000..f27ed1aa95 --- /dev/null +++ b/storage/storage_tests/countries_tests.cpp @@ -0,0 +1,14 @@ +#include "testing/testing.hpp" + +#include "platform/platform.hpp" + +#include "coding/sha1.hpp" + +#include + +UNIT_TEST(CalculateWorldSHA) +{ + auto const path = GetPlatform().ResourcesDir(); + for (char const * country : { WORLD_FILE_NAME, WORLD_COASTS_FILE_NAME }) + std::cout << coding::SHA1::CalculateBase64(path + country + DATA_FILE_EXTENSION) << std::endl; +} diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index b37d56c4f8..2d7e00b194 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -515,8 +515,7 @@ UNIT_TEST(StorageTest_Smoke) CountryId const georgiaCountryId = storage.FindCountryIdByFile("Georgia"); TEST(IsCountryIdValid(georgiaCountryId), ()); CountryFile usaGeorgiaFile = storage.GetCountryFile(georgiaCountryId); - TEST_EQUAL(platform::GetFileName(usaGeorgiaFile.GetName(), MapFileType::Map), - "Georgia" DATA_FILE_EXTENSION, ()); + TEST_EQUAL(usaGeorgiaFile.GetFileName(MapFileType::Map), "Georgia" DATA_FILE_EXTENSION, ()); } UNIT_CLASS_TEST(StorageTest, CountryDownloading) @@ -820,12 +819,12 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap) storage.GetChildrenInGroups(rootCountryId, downloaded, available); TEST_EQUAL(downloaded.size(), 1, (downloaded)); - TEST_EQUAL(available.size(), 223, ()); + TEST_EQUAL(available.size(), 225, ()); storage.GetChildrenInGroups(rootCountryId, downloadedWithKeep, availableWithKeep, true /* keepAvailableChildren*/); TEST_EQUAL(downloadedWithKeep.size(), 1, (downloadedWithKeep)); - TEST_EQUAL(availableWithKeep.size(), 224, ()); + TEST_EQUAL(availableWithKeep.size(), 226, ()); storage.GetChildrenInGroups("Algeria", downloaded, available); TEST_EQUAL(downloaded.size(), 2, (downloaded));