diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2016-04-18 16:34:08 +0300 |
---|---|---|
committer | Sergey Yershov <yershov@corp.mail.ru> | 2016-04-18 16:34:08 +0300 |
commit | 28f2c2f469f47f59079155d180e085d228cbb9e3 (patch) | |
tree | 1e74628af2d36da444f14637f734472ba2bc923c /storage | |
parent | e378f5c1d97b69a715d68b2399ea942ea0b97851 (diff) |
[downloader] Add GetGroupNodePathToRoot and test for it
Diffstat (limited to 'storage')
-rw-r--r-- | storage/storage.cpp | 31 | ||||
-rw-r--r-- | storage/storage.hpp | 5 | ||||
-rw-r--r-- | storage/storage_tests/storage_tests.cpp | 25 |
3 files changed, 61 insertions, 0 deletions
diff --git a/storage/storage.cpp b/storage/storage.cpp index 433ac09f9e..f21727d634 100644 --- a/storage/storage.cpp +++ b/storage/storage.cpp @@ -1562,4 +1562,35 @@ void Storage::GetQueuedChildren(TCountryId const & parent, TCountriesVec & queue queuedChildren.push_back(child.Value().Name()); }); } + +void Storage::GetGroupNodePathToRoot(TCountryId const & groupNode, TCountriesVec & path) const +{ + path.clear(); + + vector<TCountryTreeNode const *> nodes; + m_countries.Find(groupNode, nodes); + if (nodes.empty()) + { + LOG(LWARNING, ("TCountryId =", groupNode, "not found in m_countries.")); + return; + } + + if (nodes.size() != 1) + { + LOG(LWARNING, (groupNode, "Group node can't have more then one parent.")); + return; + } + + if (nodes[0]->ChildrenCount() == 0) + { + LOG(LWARNING, (nodes[0]->Value().Name(), "is a leaf node.")); + return; + } + + ForEachAncestorExceptForTheRoot(nodes, [&path](TCountryId const & id, TCountryTreeNode const &) + { + path.push_back(id); + }); +} + } // namespace storage diff --git a/storage/storage.hpp b/storage/storage.hpp index 91cd9c89a8..428f9f566b 100644 --- a/storage/storage.hpp +++ b/storage/storage.hpp @@ -337,6 +337,11 @@ public: /// and will be added to |queuedChildren|. void GetQueuedChildren(TCountryId const & parent, TCountriesVec & queuedChildren) const; + /// \brief Fills |path| with list of TCountryId corresponding with path to the root of hierachy. + /// \param groupNode is start of path, can't be a leaf node. + /// \param path is resulting array of TCountryId. + void GetGroupNodePathToRoot(TCountryId const & groupNode, TCountriesVec & path) const; + /// \brief Returns current version for mwms which are used by storage. inline int64_t GetCurrentDataVersion() const { return m_currentVersion; } diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index e9fb1bd3ef..76e1fdf607 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -1644,4 +1644,29 @@ UNIT_TEST(StorageTest_GetQueuedChildrenSmokeTest) storage.GetQueuedChildren("Country1", queuedChildren); TEST(queuedChildren.empty(), ()); } + +UNIT_TEST(StorageTest_GetGroupNodePathToRootTest) +{ + Storage storage; + + TCountriesVec path; + + storage.GetGroupNodePathToRoot("France_Auvergne_Allier", path); + TEST(path.empty(), ()); + + storage.GetGroupNodePathToRoot("France_Auvergne", path); + TEST_EQUAL(path.size(), 1, (path)); + + storage.GetGroupNodePathToRoot("France", path); + TEST(path.empty(), ()); + + storage.GetGroupNodePathToRoot("US_Florida_Miami", path); + TEST(path.empty(), ()); + + storage.GetGroupNodePathToRoot("Florida", path); + TEST_EQUAL(path.size(), 1, (path)); + + storage.GetGroupNodePathToRoot("Country1", path); + TEST(path.empty(), ()); +} } // namespace storage |