From 0ccb87f2c803c48cc5e4f7ac579a6442010124d1 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Mon, 14 Mar 2016 18:15:48 +0300 Subject: [PATCH] [new downloader] Fixing storage integration tests. --- .../storage_group_download_tests.cpp | 69 ++++++++++--------- .../storage_http_tests.cpp | 16 +++-- .../storage_update_tests.cpp | 8 +-- 3 files changed, 51 insertions(+), 42 deletions(-) diff --git a/storage/storage_integration_tests/storage_group_download_tests.cpp b/storage/storage_integration_tests/storage_group_download_tests.cpp index ace790a4f2..255961a467 100644 --- a/storage/storage_integration_tests/storage_group_download_tests.cpp +++ b/storage/storage_integration_tests/storage_group_download_tests.cpp @@ -60,20 +60,24 @@ void DownloadGroup(Storage & storage, bool oneByOne) string const version = strings::to_string(storage.GetCurrentDataVersion()); - // Get children nodes for the group node - TCountriesVec v; - storage.GetChildren(kGroupCountryId, v); - TCountriesSet const children(v.begin(), v.end()); - v.clear(); + // Get children nodes for the group node. + TCountriesVec children; + // All nodes in subtree (including the root) for the group node. + storage.GetChildren(kGroupCountryId, children); + TCountriesSet subTree; + storage.ForEachInSubtree(kGroupCountryId, [&subTree](TCountryId const & descendantId, bool /* groupNode */) + { + subTree.insert(descendantId); + }); TCountriesSet changed; auto onChangeCountryFn = [&](TCountryId const & countryId) { - TEST(children.find(countryId) != children.end(), ()); + TEST(subTree.find(countryId) != subTree.end(), (countryId)); changed.insert(countryId); if (!storage.IsDownloadInProgress()) { - // end waiting when all chilren will be downloaded + // Stop waiting when all chilren will be downloaded. testing::StopEventLoop(); } }; @@ -81,11 +85,11 @@ void DownloadGroup(Storage & storage, bool oneByOne) TCountriesSet downloadedChecker; auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) { - TEST(children.find(countryId) != children.end(), ()); + TEST(subTree.find(countryId) != subTree.end(), ()); if (mapSize.first == mapSize.second) { auto const res = downloadedChecker.insert(countryId); - TEST_EQUAL(res.second, true, ()); // every child is downloaded only once + TEST_EQUAL(res.second, true, ()); // Every child is downloaded only once. } }; @@ -100,7 +104,7 @@ void DownloadGroup(Storage & storage, bool oneByOne) storage.GetChildrenInGroups(kGroupCountryId, downloaded, available); TEST(downloaded.empty(), ()); - // Check status for the all children nodes is set to ENotDownloaded + // Check status for the all children nodes is set to ENotDownloaded. size_t totalGroupSize = 0; for (auto const & countryId : children) { @@ -112,14 +116,14 @@ void DownloadGroup(Storage & storage, bool oneByOne) totalGroupSize += attrs.m_mwmSize; } - // Check status for the group node is set to ENotDownloaded + // Check status for the group node is set to ENotDownloaded. NodeAttrs attrs; storage.GetNodeAttrs(kGroupCountryId, attrs); TEST_EQUAL(NodeStatus::NotDownloaded, attrs.m_status, ()); TEST_EQUAL(attrs.m_mwmSize, totalGroupSize, ()); attrs = NodeAttrs(); - // Check there is no mwm or any other files for the children nodes + // Check there is no mwm or any other files for the children nodes. for (auto const & countryId : children) { string const mwmFullPath = GetMwmFilePath(version, countryId); @@ -130,7 +134,7 @@ void DownloadGroup(Storage & storage, bool oneByOne) TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ()); } - // Download the group + // Download the group. if (oneByOne) { for (auto const & countryId : children) @@ -140,18 +144,18 @@ void DownloadGroup(Storage & storage, bool oneByOne) { storage.DownloadNode(kGroupCountryId); } - // wait for downloading of all children + // Wait for downloading of all children. testing::RunEventLoop(); - // Check all children nodes have been downloaded and changed. - TEST_EQUAL(changed, children, ()); - TEST_EQUAL(downloadedChecker, children, ()); + // Check if all nodes in the subtree have been downloaded and changed. + TEST_EQUAL(changed, subTree, ()); + TEST_EQUAL(downloadedChecker, subTree, ()); - // Check status for the group node is set to EOnDisk + // Check status for the group node is set to EOnDisk. storage.GetNodeAttrs(kGroupCountryId, attrs); TEST_EQUAL(NodeStatus::OnDisk, attrs.m_status, ()); - // Check status for the all children nodes is set to EOnDisk + // Check status for the all children nodes is set to EOnDisk. for (auto const & countryId : children) { TEST_EQUAL(Status::EOnDisk, storage.CountryStatusEx(countryId), ()); @@ -160,7 +164,7 @@ void DownloadGroup(Storage & storage, bool oneByOne) TEST_EQUAL(NodeStatus::OnDisk, attrs.m_status, ()); } - // Check there is only mwm files are present and no any other for the children nodes + // Check there is only mwm files are present and no any other for the children nodes. for (auto const & countryId : children) { string const mwmFullPath = GetMwmFilePath(version, countryId); @@ -171,13 +175,14 @@ void DownloadGroup(Storage & storage, bool oneByOne) TEST(!platform.IsFileExistsByFullPath(resumeFullPath), ()); } - // Check group is downloaded + // Check group is downloaded. storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available); TEST_EQUAL(downloaded, TCountriesVec({kGroupCountryId}), ()); - // Check all group children are downloaded + // Check all group children are downloaded. storage.GetChildrenInGroups(kGroupCountryId, downloaded, available); - TEST_EQUAL(children, TCountriesSet(downloaded.begin(), downloaded.end()), ()); + TEST_EQUAL(TCountriesSet(children.begin(), children.end()), + TCountriesSet(downloaded.begin(), downloaded.end()), ()); storage.Unsubscribe(subsrcibtionId); } @@ -188,22 +193,22 @@ void DeleteGroup(Storage & storage, bool oneByOne) string const version = strings::to_string(storage.GetCurrentDataVersion()); - // Get children nodes for the group node + // Get children nodes for the group node. TCountriesVec v; storage.GetChildren(kGroupCountryId, v); TCountriesSet const children(v.begin(), v.end()); v.clear(); - // Check group node is downloaded + // Check group node is downloaded. TCountriesVec downloaded, available; storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available); TEST_EQUAL(downloaded, TCountriesVec({kGroupCountryId}), ()); - // Check children nodes are downloaded + // Check children nodes are downloaded. storage.GetChildrenInGroups(kGroupCountryId, downloaded, available); TEST_EQUAL(children, TCountriesSet(downloaded.begin(), downloaded.end()), ()); - // Check there are mwm files for the children nodes + // Check there are mwm files for the children nodes. for (auto const & countryId : children) { string const mwmFullPath = GetMwmFilePath(version, countryId); @@ -221,12 +226,12 @@ void DeleteGroup(Storage & storage, bool oneByOne) storage.DeleteNode(kGroupCountryId); } - // Check state for the group node is set to NotDownloaded and NoError + // Check state for the group node is set to NotDownloaded and NoError. NodeAttrs attrs; storage.GetNodeAttrs(kGroupCountryId, attrs); TEST_EQUAL(NodeStatus::NotDownloaded, attrs.m_status, ()); - // Check state for the all children nodes is set to NotDownloaded and NoError + // Check state for the all children nodes is set to NotDownloaded and NoError. for (auto const & countryId : children) { TEST_EQUAL(Status::ENotDownloaded, storage.CountryStatusEx(countryId), ()); @@ -235,18 +240,18 @@ void DeleteGroup(Storage & storage, bool oneByOne) TEST_EQUAL(NodeStatus::NotDownloaded, attrs.m_status, ()); } - // Check there are no mwm files for the children nodes + // Check there are no mwm files for the children nodes. for (auto const & countryId : children) { string const mwmFullPath = GetMwmFilePath(version, countryId); TEST(!platform.IsFileExistsByFullPath(mwmFullPath), ()); } - // Check group is not downloaded + // Check group is not downloaded. storage.GetChildrenInGroups(storage.GetRootId(), downloaded, available); TEST(downloaded.empty(), ()); - // Check all children nodes are not downloaded + // Check all children nodes are not downloaded. storage.GetChildrenInGroups(kGroupCountryId, downloaded, available); TEST(downloaded.empty(), ()); } diff --git a/storage/storage_integration_tests/storage_http_tests.cpp b/storage/storage_integration_tests/storage_http_tests.cpp index 337f71e376..975eff16fe 100644 --- a/storage/storage_integration_tests/storage_http_tests.cpp +++ b/storage/storage_integration_tests/storage_http_tests.cpp @@ -28,11 +28,6 @@ string const kMapTestDir = "map-tests"; string const kTestWebServer = "http://new-search.mapswithme.com/"; -void ProgressFunction(TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) -{ - TEST_EQUAL(countryId, kCountryId, ()); -} - void Update(LocalCountryFile const & localCountryFile) { TEST_EQUAL(localCountryFile.GetCountryName(), kCountryId, ()); @@ -56,6 +51,16 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) } }; + auto ProgressFunction = [&storage](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) + { + NodeAttrs nodeAttrs; + storage.GetNodeAttrs(countryId, nodeAttrs); + + TEST_EQUAL(mapSize.first, nodeAttrs.m_downloadingProgress.first, (countryId)); + TEST_EQUAL(mapSize.second, nodeAttrs.m_downloadingProgress.second, (countryId)); + TEST_EQUAL(countryId, kCountryId, (countryId)); + }; + storage.Init(Update); storage.RegisterAllLocalMaps(); storage.Subscribe(ChangeCountryFunction, ProgressFunction); @@ -84,7 +89,6 @@ UNIT_TEST(StorageDownloadNodeAndDeleteNodeTests) // Downloading to directory with Angola.mwm. storage.DownloadNode(kCountryId); - testing::RunEventLoop(); TEST(platform.IsFileExistsByFullPath(mwmFullPath), ()); TEST(!platform.IsFileExistsByFullPath(downloadingFullPath), ()); diff --git a/storage/storage_integration_tests/storage_update_tests.cpp b/storage/storage_integration_tests/storage_update_tests.cpp index 75421de594..dc17795124 100644 --- a/storage/storage_integration_tests/storage_update_tests.cpp +++ b/storage/storage_integration_tests/storage_update_tests.cpp @@ -26,11 +26,11 @@ string const kMapTestDir = "map-tests"; string const kCountriesTxtFile = COUNTRIES_FILE; -string const kMwmVersion1 = "160126"; -size_t const kCountriesTxtFileSize1 = 131201; +string const kMwmVersion1 = "160224"; +size_t const kCountriesTxtFileSize1 = 143739; -string const kMwmVersion2 = "160128"; -size_t const kCountriesTxtFileSize2 = 127870; +string const kMwmVersion2 = "160313"; +size_t const kCountriesTxtFileSize2 = 193637; string const kGroupCountryId = "Belarus";