From b46a46b12784a188fb95d4dcedfb7236c05593f6 Mon Sep 17 00:00:00 2001 From: Constantin Shalnev Date: Tue, 9 Feb 2016 16:48:34 +0300 Subject: [PATCH] [new downloader] Added 3level country test --- .../storage_3levels_tests.cpp | 93 +++++++++++++++++++ .../storage_integration_tests.pro | 1 + 2 files changed, 94 insertions(+) create mode 100644 storage/storage_integration_tests/storage_3levels_tests.cpp diff --git a/storage/storage_integration_tests/storage_3levels_tests.cpp b/storage/storage_integration_tests/storage_3levels_tests.cpp new file mode 100644 index 0000000000..9b8b49c292 --- /dev/null +++ b/storage/storage_integration_tests/storage_3levels_tests.cpp @@ -0,0 +1,93 @@ +#include "testing/testing.hpp" + +#include "map/framework.hpp" + +#include "platform/platform.hpp" +#include "platform/platform_tests_support/write_dir_changer.hpp" + +#include "coding/file_name_utils.hpp" + +#include "std/algorithm.hpp" +#include "std/unique_ptr.hpp" + +#include "defines.hpp" + +using namespace platform; +using namespace storage; + +namespace +{ + +string const kTestWebServer = "http://new-search.mapswithme.com/"; + +string const kMapTestDir = "map-tests"; + +string const kCountryId = "Germany"; // Germany has 3-levels hierachy + +int GetLevelCount(Storage & storage, TCountryId const & countryId) +{ + TCountriesVec children; + storage.GetChildren(countryId, children); + int level = 0; + for (auto const & child : children) + level = max(level, GetLevelCount(storage, child)); + return 1 + level; +} + +} // namespace + +UNIT_TEST(SmallMwms_3levels_Test) +{ + WritableDirChanger writableDirChanger(kMapTestDir); + + Platform & platform = GetPlatform(); + + Framework f; + auto & storage = f.Storage(); + string const version = strings::to_string(storage.GetCurrentDataVersion()); + TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ()); + + TEST_EQUAL(3, GetLevelCount(storage, kCountryId), ()); + + string const mapDir = my::JoinFoldersToPath(platform.WritableDir(), version); + + auto onProgressFn = [&](TCountryId const & countryId, TLocalAndRemoteSize const & mapSize) + { + }; + + auto onChangeCountryFn = [&](TCountryId const & countryId) + { + if (!storage.IsDownloadInProgress()) + testing::StopEventLoop(); + }; + + storage.Subscribe(onChangeCountryFn, onProgressFn); + storage.SetDownloadingUrlsForTesting({kTestWebServer}); + + NodeAttrs attrs; + storage.GetNodeAttrs(kCountryId, attrs); + TEST_EQUAL(attrs.m_status, NodeStatus::NotDownloaded, ()); + + Platform::FilesList files; + platform.GetFilesByExt(mapDir, DATA_FILE_EXTENSION, files); + TEST_EQUAL(0, files.size(), ()); + + storage.DownloadNode(kCountryId); + testing::RunEventLoop(); + + storage.GetNodeAttrs(kCountryId, attrs); + TEST_EQUAL(attrs.m_status, NodeStatus::OnDisk, ()); + + files.clear(); + platform.GetFilesByExt(mapDir, DATA_FILE_EXTENSION, files); + TEST_GREATER(files.size(), 0, ()); + + storage.DeleteNode(kCountryId); + + storage.GetNodeAttrs(kCountryId, attrs); + TEST_EQUAL(attrs.m_status, NodeStatus::NotDownloaded, ()); + + files.clear(); + platform.GetFilesByExt(mapDir, DATA_FILE_EXTENSION, files); + TEST_EQUAL(0, files.size(), ()); +} diff --git a/storage/storage_integration_tests/storage_integration_tests.pro b/storage/storage_integration_tests/storage_integration_tests.pro index e59f71a2ac..9a6bb41eac 100644 --- a/storage/storage_integration_tests/storage_integration_tests.pro +++ b/storage/storage_integration_tests/storage_integration_tests.pro @@ -29,6 +29,7 @@ HEADERS += \ SOURCES += \ ../../testing/testingmain.cpp \ migrate_tests.cpp \ + storage_3levels_tests.cpp \ storage_downloading_tests.cpp \ storage_group_download_tests.cpp \ storage_http_tests.cpp \