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

storage_3levels_tests.cpp « storage_integration_tests « storage - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3ee82944688a8c3d78502046a413463a05556c1c (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
#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 "base/file_name_utils.hpp"

#include <algorithm>
#include <string>

#include "defines.hpp"

using namespace platform;
using namespace storage;

namespace
{
std::string const kCountryId = "Germany";  // Germany has 3-levels hierachy

int GetLevelCount(Storage & storage, CountryId const & countryId)
{
  CountriesVec children;
  storage.GetChildren(countryId, children);
  int level = 0;
  for (auto const & child : children)
    level = std::max(level, GetLevelCount(storage, child));
  return 1 + level;
}
} // namespace

UNIT_TEST(SmallMwms_3levels_Test)
{
  WritableDirChanger writableDirChanger(kMapTestDir);

  Platform & platform = GetPlatform();

  Framework f(FrameworkParams(false /* m_enableLocalAds */, false /* m_enableDiffs */));
  auto & storage = f.GetStorage();
  std::string const version = strings::to_string(storage.GetCurrentDataVersion());

  TEST_EQUAL(3, GetLevelCount(storage, kCountryId), ());

  std::string const mapDir = base::JoinPath(platform.WritableDir(), version);

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

  auto onChangeCountryFn = [&](CountryId const & countryId) {
    if (!storage.IsDownloadInProgress())
      testing::StopEventLoop();
  };

  storage.Subscribe(onChangeCountryFn, onProgressFn);
  storage.SetDownloadingServersForTesting({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(), ());
}