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

font_texture_tests.cpp « drape_tests « drape - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f4eab31fd1e8c7553ca0b4a3b0fbecc2171effb5 (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
#include "drape/drape_tests/dummy_texture.hpp"
#include "drape/drape_tests/img.hpp"
#include "testing/testing.hpp"

#include "drape/font_texture.hpp"
#include "drape/glyph_manager.hpp"

#include "platform/platform.hpp"
#include "qt_tstfrm/test_main_loop.hpp"

#include "std/bind.hpp"

#include <QtCore/QPoint>
#include <QtGui/QPainter>

#include "drape/drape_tests/glmock_functions.hpp"

#include <gmock/gmock.h>

using ::testing::_;
using ::testing::Return;
using ::testing::InSequence;
using ::testing::AnyNumber;
using ::testing::Invoke;
using namespace dp;

namespace
{
class UploadedRender
{
public:
  UploadedRender(QPoint const & pen) : m_pen(pen) {}
  void glMemoryToQImage(int x, int y, int w, int h, glConst f, glConst t, void const * memory)
  {
    TEST(f == gl_const::GLAlpha || f == gl_const::GLAlpha8 || f == gl_const::GLRed, ());
    TEST(t == gl_const::GLUnsignedByteType, ());

    uint8_t const * image = reinterpret_cast<uint8_t const *>(memory);

    QPoint p(m_pen);
    p.rx() += x;
    m_images.push_back(qMakePair(p, CreateImage(w, h, image)));
    m_pen.ry() += h;
  }

  void Render(QPaintDevice * device)
  {
    QPainter p(device);
    for (auto d : m_images)
      p.drawImage(d.first, d.second);
  }

private:
  QPoint m_pen;
  QVector<QPair<QPoint, QImage>> m_images;
};

class DummyGlyphIndex : public GlyphIndex
{
  typedef GlyphIndex TBase;

public:
  DummyGlyphIndex(m2::PointU size, ref_ptr<GlyphManager> mng) : TBase(size, mng) {}
  ref_ptr<Texture::ResourceInfo> MapResource(GlyphKey const & key)
  {
    bool dummy = false;
    return TBase::MapResource(key, dummy);
  }
};
}  // namespace

UNIT_TEST(UploadingGlyphs)
{
// This unit test creates window so can't be run in GUI-less Linux machine.
#ifndef OMIM_OS_LINUX
  EXPECTGL(glHasExtension(_)).Times(AnyNumber());
  EXPECTGL(glBindTexture(_)).Times(AnyNumber());
  EXPECTGL(glDeleteTexture(_)).Times(AnyNumber());
  EXPECTGL(glTexParameter(_, _)).Times(AnyNumber());
  EXPECTGL(glTexImage2D(_, _, _, _, _)).Times(AnyNumber());
  EXPECTGL(glGenTexture()).Times(AnyNumber());

  UploadedRender r(QPoint(10, 10));
  dp::GlyphManager::Params args;
  args.m_uniBlocks = "unicode_blocks.txt";
  args.m_whitelist = "fonts_whitelist.txt";
  args.m_blacklist = "fonts_blacklist.txt";
  GetPlatform().GetFontNames(args.m_fonts);

  GlyphManager mng(args);
  DummyGlyphIndex index(m2::PointU(128, 128), make_ref(&mng));
  size_t count = 1;  // invalid symbol glyph has mapped internally.
  count += (index.MapResource(GlyphKey(0x58, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x59, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x61, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  while (index.GetPendingNodesCount() < count)
    ;

  Texture::Params p;
  p.m_allocator = GetDefaultAllocator();
  p.m_format = dp::ALPHA;
  p.m_width = p.m_height = 128;

  DummyTexture tex;
  tex.Create(p);
  EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _))
      .WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage));
  index.UploadResources(make_ref(&tex));

  count = 0;
  count += (index.MapResource(GlyphKey(0x68, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x30, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x62, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x65, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x400, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  count += (index.MapResource(GlyphKey(0x401, GlyphManager::kDynamicGlyphSize)) != nullptr) ? 1 : 0;
  while (index.GetPendingNodesCount() < count)
    ;

  EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _))
      .WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage));
  index.UploadResources(make_ref(&tex));

  RunTestLoop("UploadingGlyphs", bind(&UploadedRender::Render, &r, _1));
#endif
}