aboutsummaryrefslogtreecommitdiff
path: root/libs/map/map_tests/mwm_set_test.cpp
blob: d58f06345350a2d8764d19323603174b8de45b0f (plain) (blame)
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
#include "testing/testing.hpp"

#include "indexer/data_source.hpp"

#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"

#include "base/scope_guard.hpp"

#ifndef OMIM_OS_WINDOWS
#include <sys/stat.h>
#endif

using namespace base;
using namespace platform;

/*
 * This test is useless because of we don't build offsets index from now.
#ifndef OMIM_OS_WINDOWS
UNIT_TEST(MwmSet_FileSystemErrors)
{
  string const dir = GetPlatform().WritableDir();

  CountryFile file("minsk-pass");
  LocalCountryFile localFile(dir, file, 0);
  TEST(CountryIndexes::DeleteFromDisk(localFile), ());

  // Maximum level to check exception handling logic.
  LogLevel oldLevel = g_LogAbortLevel;
  g_LogAbortLevel = LCRITICAL;

  // Remove writable permission.
  int const readOnlyMode = S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP | S_IXOTH;
  TEST_EQUAL(chmod(dir.c_str(), readOnlyMode), 0, ());

  auto restoreFn = [oldLevel, &dir, readOnlyMode] ()
  {
    g_LogAbortLevel = oldLevel;
    TEST_EQUAL(chmod(dir.c_str(), readOnlyMode | S_IWUSR), 0, ());
  };
  SCOPE_GUARD(restoreGuard, restoreFn);

  DataSource dataSource;
  auto p = dataSource.RegisterMap(localFile);
  TEST_EQUAL(p.second, DataSource::RegResult::Success, ());

  // Registering should pass ok.
  TEST(dataSource.GetMwmIdByCountryFile(file) != DataSource::MwmId(), ());

  // Getting handle causes feature offsets index building which should fail
  // because of write permissions.
  TEST(!dataSource.GetMwmHandleById(p.first).IsAlive(), ());

  // Map is automatically deregistered after the fail.
  vector<shared_ptr<MwmInfo>> infos;
  dataSource.GetMwmsInfo(infos);
  TEST(infos.empty(), ());
}
#endif
*/