[new downloader] Storage::GetChildrenInGroups(). Test fix.

This commit is contained in:
Vladimir Byko-Ianko 2016-02-24 10:24:07 +03:00 committed by Sergey Yershov
parent 427338222e
commit c12ffc6e64
2 changed files with 51 additions and 61 deletions

View file

@ -78,13 +78,13 @@ void DownloadGroup(Storage & storage, bool oneByOne)
}
};
TCountriesSet downloaded;
TCountriesSet downloadedChecker;
auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize)
{
TEST(children.find(countryId) != children.end(), ());
if (mapSize.first == mapSize.second)
{
auto const res = downloaded.insert(countryId);
auto const res = downloadedChecker.insert(countryId);
TEST_EQUAL(res.second, true, ()); // every child is downloaded only once
}
};
@ -92,12 +92,13 @@ void DownloadGroup(Storage & storage, bool oneByOne)
int const subsrcibtionId = storage.Subscribe(onChangeCountryFn, onProgressFn);
// Check group node is not downloaded
storage.GetDownloadedChildren(storage.GetRootId(), v);
TEST(v.empty(), ());
TCountriesVec downloaded, available;
storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available);
TEST(downloaded.empty(), ());
// Check children nodes are not downloaded
storage.GetDownloadedChildren(kGroupCountryId, v);
TEST(v.empty(), ());
storage.GetChildrenInGroups(kGroupCountryId, downloaded, available);
TEST(downloaded.empty(), ());
// Check status for the all children nodes is set to ENotDownloaded
size_t totalGroupSize = 0;
@ -144,7 +145,7 @@ void DownloadGroup(Storage & storage, bool oneByOne)
// Check all children nodes have been downloaded and changed.
TEST_EQUAL(changed, children, ());
TEST_EQUAL(downloaded, children, ());
TEST_EQUAL(downloadedChecker, children, ());
// Check status for the group node is set to EOnDisk
storage.GetNodeAttrs(kGroupCountryId, attrs);
@ -171,14 +172,12 @@ void DownloadGroup(Storage & storage, bool oneByOne)
}
// Check group is downloaded
storage.GetDownloadedChildren(storage.GetRootId(), v);
TEST_EQUAL(v, TCountriesVec({kGroupCountryId}), ());
v.clear();
storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available);
TEST_EQUAL(downloaded, TCountriesVec({kGroupCountryId}), ());
// Check all group children are downloaded
storage.GetDownloadedChildren(kGroupCountryId, v);
TEST_EQUAL(children, TCountriesSet(v.begin(), v.end()), ());
v.clear();
storage.GetChildrenInGroups(kGroupCountryId, downloaded, available);
TEST_EQUAL(children, TCountriesSet(downloaded.begin(), downloaded.end()), ());
storage.Unsubscribe(subsrcibtionId);
}
@ -196,14 +195,13 @@ void DeleteGroup(Storage & storage, bool oneByOne)
v.clear();
// Check group node is downloaded
storage.GetDownloadedChildren(storage.GetRootId(), v);
TEST_EQUAL(v, TCountriesVec({kGroupCountryId}), ());
v.clear();
TCountriesVec downloaded, available;
storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available);
TEST_EQUAL(downloaded, TCountriesVec({kGroupCountryId}), ());
// Check children nodes are downloaded
storage.GetDownloadedChildren(kGroupCountryId, v);
TEST_EQUAL(children, TCountriesSet(v.begin(), v.end()), ());
v.clear();
storage.GetChildrenInGroups(kGroupCountryId, downloaded, available);
TEST_EQUAL(children, TCountriesSet(downloaded.begin(), downloaded.end()), ());
// Check there are mwm files for the children nodes
for (auto const & countryId : children)
@ -245,12 +243,12 @@ void DeleteGroup(Storage & storage, bool oneByOne)
}
// Check group is not downloaded
storage.GetDownloadedChildren(storage.GetRootId(), v);
TEST(v.empty(), ());
storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available);
TEST(downloaded.empty(), ());
// Check all children nodes are not downloaded
storage.GetDownloadedChildren(kGroupCountryId, v);
TEST(v.empty(), ());
storage.GetChildrenInGroups(kGroupCountryId, downloaded, available);
TEST(downloaded.empty(), ());
}
void TestDownloadDelete(bool downloadOneByOne, bool deleteOneByOne)

View file

@ -998,9 +998,7 @@ UNIT_TEST(StorageTest_HasCountryId)
UNIT_TEST(StorageTest_DownloadedMapTests)
{
Storage storage;
if (!version::IsSingleMwm(storage.GetCurrentDataVersion()))
return; // storage::GetDownloadedChildren is not used in case of two components mwm.
Storage storage(COUNTRIES_MIGRATE_FILE);
TaskRunner runner;
InitStorage(storage, runner);
@ -1049,55 +1047,49 @@ UNIT_TEST(StorageTest_DownloadedMapTests)
TEST(!storage.IsNodeDownloaded("World"), ());
TEST(!storage.IsNodeDownloaded("World"), ());
// Storage::GetDownloadedChildren test when at least Algeria_Central and Algeria_Coast have been downloaded.
// Storage::GetChildrenInGroups test when at least Algeria_Central and Algeria_Coast have been downloaded.
TCountryId const rootCountryId = storage.GetRootId();
TEST_EQUAL(rootCountryId, "Countries", ());
TCountriesVec rootChildrenCountriesId;
storage.GetDownloadedChildren(rootCountryId, rootChildrenCountriesId);
sort(rootChildrenCountriesId.begin(), rootChildrenCountriesId.end());
TEST(HasCountryId(rootChildrenCountriesId, "Algeria"), ());
TEST(!HasCountryId(rootChildrenCountriesId, "Algeria_Central"), ());
TEST(!HasCountryId(rootChildrenCountriesId, "Algeria_Coast"), ());
TCountriesVec downloaded, available;
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST(HasCountryId(downloaded, "Algeria"), ());
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
TCountriesVec algeriaChildrenCountriesId;
storage.GetDownloadedChildren("Algeria", algeriaChildrenCountriesId);
sort(algeriaChildrenCountriesId.begin(), algeriaChildrenCountriesId.end());
TEST(HasCountryId(algeriaChildrenCountriesId, "Algeria_Central"), ());
TEST(HasCountryId(algeriaChildrenCountriesId, "Algeria_Coast"), ());
storage.GetChildrenInGroups("Algeria", downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST(HasCountryId(downloaded, "Algeria_Central"), ());
TEST(HasCountryId(downloaded, "Algeria_Coast"), ());
TCountriesVec algeriaCentralChildrenCountriesId;
storage.GetDownloadedChildren("Algeria_Central", algeriaCentralChildrenCountriesId);
TEST(algeriaCentralChildrenCountriesId.empty(), ());
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
TEST(downloaded.empty(), ());
storage.DeleteCountry(algeriaCentralCountryId, MapOptions::Map);
// Storage::GetDownloadedChildren test when Algeria_Coast has been downloaded and
// Storage::GetChildrenInGroups test when Algeria_Coast has been downloaded and
// Algeria_Central has been deleted.
TCountriesVec rootChildrenCountriesId2;
storage.GetDownloadedChildren(rootCountryId, rootChildrenCountriesId2);
sort(rootChildrenCountriesId2.begin(), rootChildrenCountriesId2.end());
TEST(!HasCountryId(rootChildrenCountriesId2, "Algeria"), ());
TEST(!HasCountryId(rootChildrenCountriesId2, "Algeria_Central"), ());
TEST(HasCountryId(rootChildrenCountriesId2, "Algeria_Coast"), ());
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST(HasCountryId(downloaded, "Algeria"), ());
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
TCountriesVec childrenOfAbsentCountry;
storage.GetDownloadedChildren("Algeria_Central", childrenOfAbsentCountry);
TEST(childrenOfAbsentCountry.empty(), ());
storage.GetChildrenInGroups("Algeria_Central", downloaded, available);
TEST(downloaded.empty(), ());
TCountriesVec algeriaCoastChildrenCountriesId;
storage.GetDownloadedChildren("Algeria_Coast", algeriaCoastChildrenCountriesId);
TEST(algeriaCoastChildrenCountriesId.empty(), ());
storage.GetChildrenInGroups("Algeria_Coast", downloaded, available);
TEST(downloaded.empty(), ());
TEST(!storage.IsNodeDownloaded("Algeria_Central"), ());
TEST(storage.IsNodeDownloaded("Algeria_Coast"), ());
storage.DeleteCountry(algeriaCoastCountryId, MapOptions::Map);
// Storage::GetDownloadedChildren test when Algeria_Coast and Algeria_Central have been deleted.
TCountriesVec rootChildrenCountriesId3;
storage.GetDownloadedChildren(rootCountryId, rootChildrenCountriesId3);
sort(rootChildrenCountriesId3.begin(), rootChildrenCountriesId3.end());
TEST(!HasCountryId(rootChildrenCountriesId3, "Algeria"), ());
TEST(!HasCountryId(rootChildrenCountriesId3, "Algeria_Central"), ());
TEST(!HasCountryId(rootChildrenCountriesId3, "Algeria_Coast"), ());
// Storage::GetChildrenInGroups test when Algeria_Coast and Algeria_Central have been deleted.
storage.GetChildrenInGroups(rootCountryId, downloaded, available);
sort(downloaded.begin(), downloaded.end());
TEST(!HasCountryId(downloaded, "Algeria"), ());
TEST(!HasCountryId(downloaded, "Algeria_Central"), ());
TEST(!HasCountryId(downloaded, "Algeria_Coast"), ());
TEST(!storage.IsNodeDownloaded("Algeria_Central"), ());
TEST(!storage.IsNodeDownloaded("Algeria_Coast"), ());