diff --git a/storage/storage.cpp b/storage/storage.cpp index c54020b8ad..5c8e7baafc 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1642,15 +1642,14 @@ void Storage::GetTopmostNodesFor(TCountryId const & countryId, TCountriesVec & n return; } - nodes.clear(); nodes.resize(treeNodes.size()); - for (auto & node : nodes) + for (size_t i = 0; i < treeNodes.size(); ++i) { - node = countryId; - ForEachAncestorExceptForTheRoot(treeNodes, - [&node](TCountryId const & id, TCountryTreeNode const &) + nodes[i] = countryId; + ForEachAncestorExceptForTheRoot({treeNodes[i]}, + [&nodes, i](TCountryId const & id, TCountryTreeNode const &) { - node = id; + nodes[i] = id; }); } } diff --git a/storage/storage.hpp b/storage/storage.hpp index 53bf3fb3ec..f18c78e471 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -355,7 +355,8 @@ public: /// \param path is resulting array of TCountryId. void GetGroupNodePathToRoot(TCountryId const & groupNode, TCountriesVec & path) const; - /// \brief TODO + /// \brief Fills |nodes| with CountryIds of topmost nodes for this |countryId|. + /// For disputed territories all possible owners will be added. void GetTopmostNodesFor(TCountryId const & countryId, TCountriesVec & nodes) const; /// \brief Returns current version for mwms which are used by storage. diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 2fc2a610e9..4073a3fea3 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1674,4 +1674,25 @@ UNIT_TEST(StorageTest_GetGroupNodePathToRootTest) storage.GetGroupNodePathToRoot("Country1", path); TEST(path.empty(), ()); } + +UNIT_TEST(StorageTest_GetTopmostNodesFor) +{ + Storage storage; + + TCountriesVec path; + + storage.GetTopmostNodesFor("France_Auvergne_Allier", path); + TEST_EQUAL(path.size(), 1, (path)); + TEST_EQUAL(path[0], "France", ()); + + storage.GetTopmostNodesFor("France_Auvergne", path); + TEST_EQUAL(path.size(), 1, (path)); + TEST_EQUAL(path[0], "France", ()); + + storage.GetTopmostNodesFor("Jerusalem", path); + TEST_EQUAL(path.size(), 2, (path)); + TEST_EQUAL(path[0], "Israel Region", (path)); + TEST_EQUAL(path[1], "Palestine Region", (path)); +} + } // namespace storage