1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include "testing/testing.hpp"
#include "storage/storage_integration_tests/test_defines.hpp"
#include "map/framework.hpp"
#include "platform/platform.hpp"
#include "platform/platform_tests_support/writable_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 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.GetStorage();
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(), ());
}
|