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

apk_test.cpp « platform_tests « platform - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0612e7ff73d6e501734f806b8316484bffd2da3 (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
#include "../../testing/testing.hpp"

#include "../platform.hpp"

#include "../../coding/zip_reader.hpp"
#include "../../coding/internal/file_data.hpp"

#include "../../base/thread.hpp"
#include "../../base/logging.hpp"

#include "../../std/numeric.hpp"


namespace
{
  char const * arrFiles[] = {
    "copyright.html",
    "resources-ldpi/basic.skn",
    "resources-ldpi/plus.png",
    "resources-ldpi/symbols.png",
    "resources-mdpi/basic.skn",
    "resources-mdpi/plus.png",
    "resources-mdpi/symbols.png",
    "resources-hdpi/basic.skn",
    "resources-hdpi/plus.png",
    "resources-hdpi/symbols.png",
    "resources-xhdpi/basic.skn",
    "resources-xhdpi/plus.png",
    "resources-xhdpi/symbols.png",
    "categories.txt",
    "classificator.txt",
    "types.txt",
    "fonts_blacklist.txt",
    "fonts_whitelist.txt",
    "languages.txt",
    "unicode_blocks.txt",
    "drules_proto.bin",
    "external_resources.txt",
    "packed_polygons.bin",
    "countries.txt"
  };

  class ApkTester : public threads::IRoutine
  {
    static const int COUNT = ARRAY_SIZE(arrFiles);
    string const & m_cont;

  public:
    ApkTester(string const & cont) : m_cont(cont)
    {
      m_hashes.resize(COUNT);
    }

    virtual void Do()
    {
      string const prefix("assets/");

      while (true)
      {
        size_t ind = rand() % COUNT;
        if (m_hashes[ind] != 0)
        {
          ind = COUNT;
          for (size_t i = 0; i < COUNT; ++i)
            if (m_hashes[i] == 0)
            {
              ind = i;
              break;
            }
        }

        if (ind == COUNT)
          break;

        try
        {
          ZipFileReader reader(m_cont, prefix + arrFiles[ind]);

          size_t const size = reader.Size();
          vector<char> buffer(size);
          reader.Read(0, &buffer[0], size);

          m_hashes[ind] = accumulate(buffer.begin(), buffer.end(), static_cast<uint64_t>(0));
        }
        catch (Reader::Exception const & ex)
        {
          LOG(LERROR, (ex.Msg()));
          break;
        }
      }
    }

    vector<uint64_t> m_hashes;
  };
}

UNIT_TEST(ApkReader_Multithreaded)
{
  string const path = GetPlatform().WritableDir() + "../android/MapsWithMePro/bin/MapsWithMePro-production.apk";

  uint64_t size;
  if (!my::GetFileSize(path, size))
  {
    LOG(LINFO, ("Apk not found"));
    return;
  }

  srand(static_cast<unsigned>(size));

  size_t const count = 20;
  threads::SimpleThreadPool pool(count);

  for (size_t i = 0; i < count; ++i)
    pool.Add(make_unique<ApkTester>(path));

  pool.Join();

  typedef ApkTester const * PtrT;
  PtrT etalon = dynamic_cast<PtrT>(pool.GetRoutine(0));
  for (size_t i = 1; i < count; ++i)
  {
    PtrT p = dynamic_cast<PtrT>(pool.GetRoutine(i));
    TEST_EQUAL(etalon->m_hashes, p->m_hashes, ());
  }
}