[downloader] Add GetGroupNodePathToRoot and test for it

This commit is contained in:
Sergey Yershov 2016-04-18 16:34:08 +03:00
parent e378f5c1d9
commit 28f2c2f469
3 changed files with 61 additions and 0 deletions

View file

@ -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

View file

@ -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; }

View file

@ -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