diff --git a/storage/storage.cpp b/storage/storage.cpp index 239c9d9680..070961742a 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1644,15 +1644,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 a9383d9bb2..1b445b2e1d 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -357,7 +357,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 87c440e3a2..31849335af 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1739,4 +1739,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