diff options
Diffstat (limited to 'drape/drape_tests/font_texture_tests.cpp')
-rw-r--r-- | drape/drape_tests/font_texture_tests.cpp | 109 |
1 files changed, 53 insertions, 56 deletions
diff --git a/drape/drape_tests/font_texture_tests.cpp b/drape/drape_tests/font_texture_tests.cpp index b6b7882fd2..f4eab31fd1 100644 --- a/drape/drape_tests/font_texture_tests.cpp +++ b/drape/drape_tests/font_texture_tests.cpp @@ -1,6 +1,6 @@ -#include "testing/testing.hpp" -#include "drape/drape_tests/img.hpp" #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" @@ -10,8 +10,8 @@ #include "std/bind.hpp" -#include <QtGui/QPainter> #include <QtCore/QPoint> +#include <QtGui/QPainter> #include "drape/drape_tests/glmock_functions.hpp" @@ -26,59 +26,52 @@ using namespace dp; namespace { - class UploadedRender +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) { - 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, ()); - 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 + 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) { - 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); - } - }; -} + 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. +// 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()); @@ -96,11 +89,12 @@ UNIT_TEST(UploadingGlyphs) GlyphManager mng(args); DummyGlyphIndex index(m2::PointU(128, 128), make_ref(&mng)); - size_t count = 1; // invalid symbol glyph has mapped internally. + 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); + while (index.GetPendingNodesCount() < count) + ; Texture::Params p; p.m_allocator = GetDefaultAllocator(); @@ -109,7 +103,8 @@ UNIT_TEST(UploadingGlyphs) DummyTexture tex; tex.Create(p); - EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage)); + EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)) + .WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage)); index.UploadResources(make_ref(&tex)); count = 0; @@ -119,9 +114,11 @@ UNIT_TEST(UploadingGlyphs) 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); + while (index.GetPendingNodesCount() < count) + ; - EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage)); + EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)) + .WillRepeatedly(Invoke(&r, &UploadedRender::glMemoryToQImage)); index.UploadResources(make_ref(&tex)); RunTestLoop("UploadingGlyphs", bind(&UploadedRender::Render, &r, _1)); |