Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorygorshenin <mipt.vi002@gmail.com>2016-04-27 12:29:28 +0300
committerygorshenin <mipt.vi002@gmail.com>2016-04-27 12:29:28 +0300
commitbdf513171abcacab39e4f89829d313057ad7d876 (patch)
tree10562bcb0e95671bef0f2f108c77ac8550f5b0a7 /storage
parent199e742ae764529751ce4952a086c582e3157851 (diff)
parentd22f657bdbad7d65bcf6c08052033e286bd93fef (diff)
Merge pull request #2997 from syershov/MAPSME-935
[downloader] Fix GetTopmostNodesFor and added test
Diffstat (limited to 'storage')
-rw-r--r--storage/storage.cpp11
-rw-r--r--storage/storage.hpp3
-rw-r--r--storage/storage_tests/storage_tests.cpp21
3 files changed, 28 insertions, 7 deletions
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