Welcome to mirror list, hosted at ThFree Co, Russian Federation.

storage_update_tests.cpp « storage_integration_tests « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f55889078425c9ac3d9d59c21155b732f0452de6 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "testing/testing.hpp"

#include "storage/storage_integration_tests/test_defines.hpp"

#include "map/framework.hpp"

#include "platform/http_request.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include "platform/platform_tests_support/writable_dir_changer.hpp"

#include "coding/internal/file_data.hpp"

#include "storage/storage.hpp"

#include "base/file_name_utils.hpp"

#include <memory>
#include <string>

using namespace platform;
using namespace std;
using namespace storage;

namespace
{
static FrameworkParams const kFrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */);

string const kCountriesTxtFile = COUNTRIES_FILE;

string const kMwmVersion1 = "190830";
size_t const kCountriesTxtFileSize1 = 420632;

string const kMwmVersion2 = "190910";
size_t const kCountriesTxtFileSize2 = 420634;

string const kGroupCountryId = "Belarus";

bool DownloadFile(string const & url,
                  string const & filePath,
                  size_t fileSize)
{
  using namespace downloader;

  HttpRequest::Status httpStatus;
  bool finished = false;

  unique_ptr<HttpRequest> request(HttpRequest::GetFile({url}, filePath, fileSize,
                                  [&](HttpRequest & request)
  {
    HttpRequest::Status const s = request.GetStatus();
    if (s != HttpRequest::Status::InProgress)
    {
      httpStatus = s;
      finished = true;
      testing::StopEventLoop();
    }
  }));

  testing::RunEventLoop();

  return httpStatus == HttpRequest::Status::Completed;
}

string GetCountriesTxtWebUrl(string const version)
{
  return kTestWebServer + "direct/" + version + "/" + kCountriesTxtFile;
}

string GetCountriesTxtFilePath()
{
  return base::JoinPath(GetPlatform().WritableDir(), kCountriesTxtFile);
}

string GetMwmFilePath(string const & version, CountryId const & countryId)
{
  return base::JoinPath(GetPlatform().WritableDir(), version, countryId + DATA_FILE_EXTENSION);
}

} // namespace

UNIT_TEST(SmallMwms_Update_Test)
{
  WritableDirChanger writableDirChanger(kMapTestDir);

  Platform & platform = GetPlatform();

  auto onProgressFn = [&](CountryId const & countryId, LocalAndRemoteSize const & mapSize) {};

  // Download countries.txt for version 1
  TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion1), GetCountriesTxtFilePath(), kCountriesTxtFileSize1), ());

  {
    Framework f(kFrameworkParams);
    auto & storage = f.GetStorage();
    string const version = strings::to_string(storage.GetCurrentDataVersion());
    TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ());
    TEST_EQUAL(version, kMwmVersion1, ());
    auto onChangeCountryFn = [&](CountryId const & countryId) {
      if (!storage.IsDownloadInProgress())
        testing::StopEventLoop();
    };
    storage.Subscribe(onChangeCountryFn, onProgressFn);
    storage.SetDownloadingServersForTesting({kTestWebServer});

    CountriesVec children;
    storage.GetChildren(kGroupCountryId, children);

    // Download group
    storage.DownloadNode(kGroupCountryId);
    testing::RunEventLoop();

    // Check group node status is EOnDisk
    NodeAttrs attrs;
    storage.GetNodeAttrs(kGroupCountryId, attrs);
    TEST_EQUAL(NodeStatus::OnDisk, attrs.m_status, ());

    // Check mwm files for version 1 are present
    for (auto const & child : children)
    {
      string const mwmFullPathV1 = GetMwmFilePath(kMwmVersion1, child);
      TEST(platform.IsFileExistsByFullPath(mwmFullPathV1), ());
    }
  }

  // Replace countries.txt by version 2
  TEST(base::DeleteFileX(GetCountriesTxtFilePath()), ());
  TEST(DownloadFile(GetCountriesTxtWebUrl(kMwmVersion2), GetCountriesTxtFilePath(), kCountriesTxtFileSize2), ());

  {
    Framework f(kFrameworkParams);
    auto & storage = f.GetStorage();
    string const version = strings::to_string(storage.GetCurrentDataVersion());
    TEST(version::IsSingleMwm(storage.GetCurrentDataVersion()), ());
    TEST_EQUAL(version, kMwmVersion2, ());
    auto onChangeCountryFn = [&](CountryId const & countryId) {
      if (!storage.IsDownloadInProgress())
        testing::StopEventLoop();
    };
    storage.Subscribe(onChangeCountryFn, onProgressFn);
    storage.SetDownloadingServersForTesting({kTestWebServer});

    CountriesVec children;
    storage.GetChildren(kGroupCountryId, children);

    // Check group node status is EOnDiskOutOfDate
    NodeAttrs attrs;
    storage.GetNodeAttrs(kGroupCountryId, attrs);
    TEST_EQUAL(NodeStatus::OnDiskOutOfDate, attrs.m_status, ());

    // Check children node status is EOnDiskOutOfDate
    for (auto const & child : children)
    {
      NodeAttrs attrs;
      storage.GetNodeAttrs(child, attrs);
      TEST_EQUAL(NodeStatus::OnDiskOutOfDate, attrs.m_status, ());
    }

    // Check mwm files for version 1 are present
    for (auto const & child : children)
    {
      string const mwmFullPathV1 = GetMwmFilePath(kMwmVersion1, child);
      TEST(platform.IsFileExistsByFullPath(mwmFullPathV1), ());
    }

    // Download group, new version
    storage.DownloadNode(kGroupCountryId);
    testing::RunEventLoop();

    // Check group node status is EOnDisk
    storage.GetNodeAttrs(kGroupCountryId, attrs);
    TEST_EQUAL(NodeStatus::OnDisk, attrs.m_status, ());

    // Check children node status is EOnDisk
    for (auto const & child : children)
    {
      NodeAttrs attrs;
      storage.GetNodeAttrs(child, attrs);
      TEST_EQUAL(NodeStatus::OnDisk, attrs.m_status, ());
    }

    // Check mwm files for version 2 are present and not present for version 1
    for (auto const & child : children)
    {
      string const mwmFullPathV1 = GetMwmFilePath(kMwmVersion1, child);
      string const mwmFullPathV2 = GetMwmFilePath(kMwmVersion2, child);
      TEST(platform.IsFileExistsByFullPath(mwmFullPathV2), ());
      TEST(!platform.IsFileExistsByFullPath(mwmFullPathV1), ());
    }
  }
}