Merge pull request #2891 from syershov/MAPSME-822

[downloader] Extend behaviors GetChildrenInGroups
This commit is contained in:
igrechuhin 2016-04-15 12:57:09 +04:00
commit ff07292c95
3 changed files with 44 additions and 12 deletions

View file

@ -1142,7 +1142,8 @@ void Storage::GetLocalRealMaps(TCountriesVec & localMaps) const
}
void Storage::GetChildrenInGroups(TCountryId const & parent,
TCountriesVec & downloadedChildren, TCountriesVec & availChildren) const
TCountriesVec & downloadedChildren, TCountriesVec & availChildren,
bool keepAvailableChildren) const
{
ASSERT_THREAD_CHECKER(m_threadChecker, ());
@ -1172,7 +1173,10 @@ void Storage::GetChildrenInGroups(TCountryId const & parent,
for (auto const & disputed : disputedTerritoriesAndStatus)
allDisputedTerritories.push_back(disputed.first);
if (childStatus.status == NodeStatus::NotDownloaded)
if (childStatus.status != NodeStatus::NotDownloaded)
downloadedChildren.push_back(childValue);
if (keepAvailableChildren || childStatus.status == NodeStatus::NotDownloaded)
{
availChildren.push_back(childValue);
for (auto const & disputed : disputedTerritoriesAndStatus)
@ -1181,10 +1185,6 @@ void Storage::GetChildrenInGroups(TCountryId const & parent,
disputedTerritoriesWithoutSiblings.push_back(disputed.first);
}
}
else
{
downloadedChildren.push_back(childValue);
}
});
TCountriesVec uniqueDisputed(disputedTerritoriesWithoutSiblings.begin(), disputedTerritoriesWithoutSiblings.end());

View file

@ -322,12 +322,15 @@ public:
/// \param parent is a parent acoording to countries.txt or cournties_migrate.txt.
/// \param downloadedChildren children partly or fully downloaded.
/// \param availChildren fully available children. None of its files have been downloaded.
/// \param keepAvailableChildren keeps all children in |availChildren| otherwise downloaded
/// children will be removed from |availChildren|.
/// \note. This method puts to |downloadedChildren| and |availChildren| only real maps (and its ancestors)
/// which have been written in coutries.txt or cournties_migrate.txt.
/// It means the method does not put to its params neither custom maps generated by user
/// nor World.mwm and WorldCoasts.mwm.
void GetChildrenInGroups(TCountryId const & parent,
TCountriesVec & downloadedChildren, TCountriesVec & availChildren) const;
TCountriesVec & downloadedChildren, TCountriesVec & availChildren,
bool keepAvailableChildren = false) const;
/// \brief Fills |queuedChildren| with children of |parent| if they (or thier childen) are in |m_queue|.
/// \note For group node children if one of child's ancestor has status
/// NodeStatus::Downloading or NodeStatus::InQueue the child is considered as a queued child

View file

@ -10,6 +10,8 @@
#include "storage/storage_tests/task_runner.hpp"
#include "storage/storage_tests/test_map_files_downloader.hpp"
#include "storage/storage_integration_tests/test_defines.hpp"
#include "indexer/indexer_tests/test_mwm_set.hpp"
#include "platform/country_file.hpp"
@ -19,6 +21,7 @@
#include "platform/platform.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
#include "platform/platform_tests_support/scoped_file.hpp"
#include "platform/platform_tests_support/write_dir_changer.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
@ -496,9 +499,10 @@ class StorageTest
protected:
Storage storage;
TaskRunner runner;
WritableDirChanger writableDirChanger;
public:
StorageTest() { InitStorage(storage, runner); }
StorageTest() : writableDirChanger(kMapTestDir) { InitStorage(storage, runner); }
};
class TwoComponentStorageTest
@ -506,9 +510,10 @@ class TwoComponentStorageTest
protected:
Storage storage;
TaskRunner runner;
WritableDirChanger writableDirChanger;
public:
TwoComponentStorageTest() : storage(COUNTRIES_OBSOLETE_FILE)
TwoComponentStorageTest() : storage(COUNTRIES_OBSOLETE_FILE), writableDirChanger(kMapTestDir)
{
InitStorage(storage, runner);
}
@ -1067,21 +1072,45 @@ UNIT_CLASS_TEST(StorageTest, DownloadedMap)
// Storage::GetChildrenInGroups test when at least Algeria_Central and Algeria_Coast have been downloaded.
TCountryId const rootCountryId = storage.GetRootId();
TEST_EQUAL(rootCountryId, "Countries", ());
TCountriesVec downloaded, available;
TCountriesVec downloadedWithKeep, availableWithKeep;
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST_EQUAL(downloaded.size(), 1, (downloaded));
TEST_EQUAL(available.size(), 223, ());
storage.GetChildrenInGroups(rootCountryId, downloadedWithKeep,
availableWithKeep, true /* keepAvailableChildren*/);
TEST_EQUAL(downloadedWithKeep.size(), 1, (downloadedWithKeep));
TEST_EQUAL(availableWithKeep.size(), 224, ());
storage.GetChildrenInGroups("Algeria", downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST_EQUAL(downloaded.size(), 2, (downloaded));
storage.GetChildrenInGroups("Algeria", downloadedWithKeep,
availableWithKeep, true /* keepAvailableChildren*/);
TEST_EQUAL(downloadedWithKeep.size(), 2, (downloadedWithKeep));
TEST_EQUAL(availableWithKeep.size(), 2, (availableWithKeep));
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
TEST(downloaded.empty(), ());
storage.GetChildrenInGroups("Algeria_Central", downloadedWithKeep,
availableWithKeep, true /* keepAvailableChildren*/);
TEST_EQUAL(downloadedWithKeep.size(), 0, (downloadedWithKeep));
TEST_EQUAL(availableWithKeep.size(), 0, (availableWithKeep));
storage.DeleteCountry(algeriaCentralCountryId, MapOptions::Map);
// Storage::GetChildrenInGroups test when Algeria_Coast has been downloaded and
// Algeria_Central has been deleted.
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST_EQUAL(downloaded.size(), 1, (downloaded));
storage.GetChildrenInGroups("Algeria", downloadedWithKeep,
availableWithKeep, true /* keepAvailableChildren*/);
TEST_EQUAL(downloadedWithKeep.size(), 1, (downloadedWithKeep));
TEST_EQUAL(availableWithKeep.size(), 2, (availableWithKeep));
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
TEST(downloaded.empty(), ());