diff options
Diffstat (limited to 'test/text')
-rw-r--r-- | test/text/glyph_loader.test.cpp (renamed from test/text/glyph_atlas.test.cpp) | 67 | ||||
-rw-r--r-- | test/text/quads.test.cpp | 276 |
2 files changed, 170 insertions, 173 deletions
diff --git a/test/text/glyph_atlas.test.cpp b/test/text/glyph_loader.test.cpp index 5aff1ee441..be197ebb46 100644 --- a/test/text/glyph_atlas.test.cpp +++ b/test/text/glyph_loader.test.cpp @@ -1,8 +1,7 @@ #include <mbgl/test/util.hpp> #include <mbgl/test/stub_file_source.hpp> -#include <mbgl/test/stub_style_observer.hpp> -#include <mbgl/text/glyph_atlas.hpp> +#include <mbgl/text/glyph_manager.hpp> #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/io.hpp> @@ -10,30 +9,44 @@ using namespace mbgl; +class StubGlyphManagerObserver : public GlyphManagerObserver { +public: + void onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) override { + if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange); + } + + void onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) override { + if (glyphsError) glyphsError(fontStack, glyphRange, error); + } + + std::function<void (const FontStack&, const GlyphRange&)> glyphsLoaded; + std::function<void (const FontStack&, const GlyphRange&, std::exception_ptr)> glyphsError; +}; + class StubGlyphRequestor : public GlyphRequestor { public: - void onGlyphsAvailable(GlyphPositionMap positions) override { - if (glyphsAvailable) glyphsAvailable(std::move(positions)); + void onGlyphsAvailable(GlyphMap glyphs) override { + if (glyphsAvailable) glyphsAvailable(std::move(glyphs)); } - std::function<void (GlyphPositionMap)> glyphsAvailable; + std::function<void (GlyphMap)> glyphsAvailable; }; -class GlyphAtlasTest { +class GlyphManagerTest { public: util::RunLoop loop; StubFileSource fileSource; - StubStyleObserver observer; + StubGlyphManagerObserver observer; StubGlyphRequestor requestor; - GlyphAtlas glyphAtlas{ { 32, 32 }, fileSource }; + GlyphManager glyphManager { fileSource }; void run(const std::string& url, GlyphDependencies dependencies) { // Squelch logging. Log::setObserver(std::make_unique<Log::NullObserver>()); - glyphAtlas.setURL(url); - glyphAtlas.setObserver(&observer); - glyphAtlas.getGlyphs(requestor, std::move(dependencies)); + glyphManager.setURL(url); + glyphManager.setObserver(&observer); + glyphManager.getGlyphs(requestor, std::move(dependencies)); loop.run(); } @@ -43,8 +56,8 @@ public: } }; -TEST(GlyphAtlas, LoadingSuccess) { - GlyphAtlasTest test; +TEST(GlyphManager, LoadingSuccess) { + GlyphManagerTest test; test.fileSource.glyphsResponse = [&] (const Resource& resource) { EXPECT_EQ(Resource::Kind::Glyphs, resource.kind); @@ -63,8 +76,8 @@ TEST(GlyphAtlas, LoadingSuccess) { ASSERT_EQ(range, GlyphRange(0, 255)); }; - test.requestor.glyphsAvailable = [&] (GlyphPositionMap positions) { - const auto& testPositions = positions.at({{"Test Stack"}}); + test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) { + const auto& testPositions = glyphs.at({{"Test Stack"}}); ASSERT_EQ(testPositions.size(), 3u); ASSERT_EQ(testPositions.count(u'a'), 1u); @@ -82,8 +95,8 @@ TEST(GlyphAtlas, LoadingSuccess) { }); } -TEST(GlyphAtlas, LoadingFail) { - GlyphAtlasTest test; +TEST(GlyphManager, LoadingFail) { + GlyphManagerTest test; test.fileSource.glyphsResponse = [&] (const Resource&) { Response response; @@ -103,7 +116,7 @@ TEST(GlyphAtlas, LoadingFail) { test.end(); }; - test.requestor.glyphsAvailable = [&] (GlyphPositionMap) { + test.requestor.glyphsAvailable = [&] (GlyphMap) { FAIL(); test.end(); }; @@ -115,8 +128,8 @@ TEST(GlyphAtlas, LoadingFail) { }); } -TEST(GlyphAtlas, LoadingCorrupted) { - GlyphAtlasTest test; +TEST(GlyphManager, LoadingCorrupted) { + GlyphManagerTest test; test.fileSource.glyphsResponse = [&] (const Resource&) { Response response; @@ -134,7 +147,7 @@ TEST(GlyphAtlas, LoadingCorrupted) { test.end(); }; - test.requestor.glyphsAvailable = [&] (GlyphPositionMap) { + test.requestor.glyphsAvailable = [&] (GlyphMap) { FAIL(); test.end(); }; @@ -146,8 +159,8 @@ TEST(GlyphAtlas, LoadingCorrupted) { }); } -TEST(GlyphAtlas, LoadingCancel) { - GlyphAtlasTest test; +TEST(GlyphManager, LoadingCancel) { + GlyphManagerTest test; test.fileSource.glyphsResponse = [&] (const Resource&) { test.end(); @@ -165,8 +178,8 @@ TEST(GlyphAtlas, LoadingCancel) { }); } -TEST(GlyphAtlas, LoadingInvalid) { - GlyphAtlasTest test; +TEST(GlyphManager, LoadingInvalid) { + GlyphManagerTest test; test.fileSource.glyphsResponse = [&] (const Resource& resource) { EXPECT_EQ(Resource::Kind::Glyphs, resource.kind); @@ -185,8 +198,8 @@ TEST(GlyphAtlas, LoadingInvalid) { ASSERT_EQ(range, GlyphRange(0, 255)); }; - test.requestor.glyphsAvailable = [&] (GlyphPositionMap positions) { - const auto& testPositions = positions.at({{"Test Stack"}}); + test.requestor.glyphsAvailable = [&] (GlyphMap glyphs) { + const auto& testPositions = glyphs.at({{"Test Stack"}}); ASSERT_EQ(testPositions.size(), 2u); ASSERT_FALSE(bool(testPositions.at(u'A'))); diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index 83fd249535..8eedd9bd2e 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -1,5 +1,5 @@ #include <mbgl/geometry/anchor.hpp> -#include <mbgl/sprite/sprite_atlas.hpp> +#include <mbgl/style/image_impl.hpp> #include <mbgl/test/util.hpp> #include <mbgl/text/quads.hpp> #include <mbgl/text/shaping.hpp> @@ -12,48 +12,37 @@ using namespace mbgl::style; TEST(getIconQuads, normal) { SymbolLayoutProperties::Evaluated layout; Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0); - SpriteAtlasElement image = { - Rect<uint16_t>( 0, 0, 15, 11 ), - style::Image(PremultipliedImage({1,1}), 1.0), - { 0, 0 }, - 1.0f + ImagePosition image = { + mapbox::Bin(-1, 15, 11, 0, 0, 0, 0), + style::Image::Impl("test", PremultipliedImage({1,1}), 1.0) }; - auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -6.5f, -4.5f }}, 0); - ASSERT_TRUE(shapedIcon); + auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -6.5f, -4.5f }}, SymbolAnchorType::Center, 0); GeometryCoordinates line; Shaping shapedText; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 16.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.anchorPoint.x, 2); - ASSERT_EQ(quad.anchorPoint.y, 3); - ASSERT_EQ(quad.tl.x, -8); - ASSERT_EQ(quad.tl.y, -6); - ASSERT_EQ(quad.tr.x, 7); - ASSERT_EQ(quad.tr.y, -6); - ASSERT_EQ(quad.bl.x, -8); - ASSERT_EQ(quad.bl.y, 5); - ASSERT_EQ(quad.br.x, 7); - ASSERT_EQ(quad.br.y, 5); - ASSERT_EQ(quad.anchorAngle, 0.0f); - ASSERT_EQ(quad.glyphAngle, 0.0f); - ASSERT_EQ(quad.minScale, 0.5f); + getIconQuad(shapedIcon, layout, 16.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -14); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, 1); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -14); + EXPECT_EQ(quad.bl.y, 1); + EXPECT_EQ(quad.br.x, 1); + EXPECT_EQ(quad.br.y, 1); } TEST(getIconQuads, style) { Anchor anchor(0.0, 0.0, 0.0, 0.5f, 0); - SpriteAtlasElement image = { - Rect<uint16_t>( 0, 0, 20, 20 ), - style::Image(PremultipliedImage({1,1}), 1.0), - { 0, 0 }, - 1.0f + ImagePosition image = { + mapbox::Bin(-1, 20, 20, 0, 0, 0, 0), + style::Image::Impl("test", PremultipliedImage({1,1}), 1.0) }; - auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -9.5f, -9.5f }}, 0); - ASSERT_TRUE(shapedIcon); + auto shapedIcon = PositionedIcon::shapeIcon(image, {{ -9.5f, -9.5f }}, SymbolAnchorType::Center, 0); GeometryCoordinates line; Shaping shapedText; @@ -61,27 +50,22 @@ TEST(getIconQuads, style) { shapedText.bottom = 30.0f; shapedText.left = -60.0f; shapedText.right = 20.0f; - shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, 0)); + shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, false)); // none { SymbolLayoutProperties::Evaluated layout; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.anchorPoint.x, 0); - ASSERT_EQ(quad.anchorPoint.y, 0); - ASSERT_EQ(quad.tl.x, -11); - ASSERT_EQ(quad.tl.y, -11); - ASSERT_EQ(quad.tr.x, 9); - ASSERT_EQ(quad.tr.y, -11); - ASSERT_EQ(quad.bl.x, -11); - ASSERT_EQ(quad.bl.y, 9); - ASSERT_EQ(quad.br.x, 9); - ASSERT_EQ(quad.br.y, 9); - ASSERT_EQ(quad.anchorAngle, 0.0f); - ASSERT_EQ(quad.glyphAngle, 0.0f); - ASSERT_EQ(quad.minScale, 0.5f); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -19.5); + EXPECT_EQ(quad.tl.y, -19.5); + EXPECT_EQ(quad.tr.x, 0.5); + EXPECT_EQ(quad.tr.y, -19.5); + EXPECT_EQ(quad.bl.x, -19.5); + EXPECT_EQ(quad.bl.y, 0.5); + EXPECT_EQ(quad.br.x, 0.5); + EXPECT_EQ(quad.br.y, 0.5); } // width @@ -90,16 +74,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 24.0f; layout.get<IconTextFit>() = IconTextFitType::Width; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -60); - ASSERT_EQ(quad.tl.y, 0); - ASSERT_EQ(quad.tr.x, 20); - ASSERT_EQ(quad.tr.y, 0); - ASSERT_EQ(quad.bl.x, -60); - ASSERT_EQ(quad.bl.y, 20); - ASSERT_EQ(quad.br.x, 20); - ASSERT_EQ(quad.br.y, 20); + getIconQuad(shapedIcon, layout, 24.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -60); + EXPECT_EQ(quad.tl.y, 0); + EXPECT_EQ(quad.tr.x, 20); + EXPECT_EQ(quad.tr.y, 0); + EXPECT_EQ(quad.bl.x, -60); + EXPECT_EQ(quad.bl.y, 20); + EXPECT_EQ(quad.br.x, 20); + EXPECT_EQ(quad.br.y, 20); } // width x textSize @@ -108,16 +92,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 12.0f; layout.get<IconTextFit>() = IconTextFitType::Width; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -30); - ASSERT_EQ(quad.tl.y, -5); - ASSERT_EQ(quad.tr.x, 10); - ASSERT_EQ(quad.tr.y, -5); - ASSERT_EQ(quad.bl.x, -30); - ASSERT_EQ(quad.bl.y, 15); - ASSERT_EQ(quad.br.x, 10); - ASSERT_EQ(quad.br.y, 15); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -30); + EXPECT_EQ(quad.tl.y, -5); + EXPECT_EQ(quad.tr.x, 10); + EXPECT_EQ(quad.tr.y, -5); + EXPECT_EQ(quad.bl.x, -30); + EXPECT_EQ(quad.bl.y, 15); + EXPECT_EQ(quad.br.x, 10); + EXPECT_EQ(quad.br.y, 15); } // width x textSize + padding @@ -130,16 +114,16 @@ TEST(getIconQuads, style) { layout.get<IconTextFitPadding>()[2] = 5.0f; layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -40); - ASSERT_EQ(quad.tl.y, -10); - ASSERT_EQ(quad.tr.x, 20); - ASSERT_EQ(quad.tr.y, -10); - ASSERT_EQ(quad.bl.x, -40); - ASSERT_EQ(quad.bl.y, 20); - ASSERT_EQ(quad.br.x, 20); - ASSERT_EQ(quad.br.y, 20); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -40); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, 20); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -40); + EXPECT_EQ(quad.bl.y, 20); + EXPECT_EQ(quad.br.x, 20); + EXPECT_EQ(quad.br.y, 20); } // height @@ -148,16 +132,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 24.0f; layout.get<IconTextFit>() = IconTextFitType::Height; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -30); - ASSERT_EQ(quad.tl.y, -10); - ASSERT_EQ(quad.tr.x, -10); - ASSERT_EQ(quad.tr.y, -10); - ASSERT_EQ(quad.bl.x, -30); - ASSERT_EQ(quad.bl.y, 30); - ASSERT_EQ(quad.br.x, -10); - ASSERT_EQ(quad.br.y, 30); + getIconQuad(shapedIcon, layout, 24.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -30); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, -10); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -30); + EXPECT_EQ(quad.bl.y, 30); + EXPECT_EQ(quad.br.x, -10); + EXPECT_EQ(quad.br.y, 30); } // height x textSize @@ -166,16 +150,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 12.0f; layout.get<IconTextFit>() = IconTextFitType::Height; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -20); - ASSERT_EQ(quad.tl.y, -5); - ASSERT_EQ(quad.tr.x, 0); - ASSERT_EQ(quad.tr.y, -5); - ASSERT_EQ(quad.bl.x, -20); - ASSERT_EQ(quad.bl.y, 15); - ASSERT_EQ(quad.br.x, 0); - ASSERT_EQ(quad.br.y, 15); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -20); + EXPECT_EQ(quad.tl.y, -5); + EXPECT_EQ(quad.tr.x, 0); + EXPECT_EQ(quad.tr.y, -5); + EXPECT_EQ(quad.bl.x, -20); + EXPECT_EQ(quad.bl.y, 15); + EXPECT_EQ(quad.br.x, 0); + EXPECT_EQ(quad.br.y, 15); } // height x textSize + padding @@ -188,16 +172,16 @@ TEST(getIconQuads, style) { layout.get<IconTextFitPadding>()[2] = 5.0f; layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -30); - ASSERT_EQ(quad.tl.y, -10); - ASSERT_EQ(quad.tr.x, 10); - ASSERT_EQ(quad.tr.y, -10); - ASSERT_EQ(quad.bl.x, -30); - ASSERT_EQ(quad.bl.y, 20); - ASSERT_EQ(quad.br.x, 10); - ASSERT_EQ(quad.br.y, 20); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -30); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, 10); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -30); + EXPECT_EQ(quad.bl.y, 20); + EXPECT_EQ(quad.br.x, 10); + EXPECT_EQ(quad.br.y, 20); } // both @@ -206,16 +190,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 24.0f; layout.get<IconTextFit>() = IconTextFitType::Both; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 24.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -60); - ASSERT_EQ(quad.tl.y, -10); - ASSERT_EQ(quad.tr.x, 20); - ASSERT_EQ(quad.tr.y, -10); - ASSERT_EQ(quad.bl.x, -60); - ASSERT_EQ(quad.bl.y, 30); - ASSERT_EQ(quad.br.x, 20); - ASSERT_EQ(quad.br.y, 30); + getIconQuad(shapedIcon, layout, 24.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -60); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, 20); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -60); + EXPECT_EQ(quad.bl.y, 30); + EXPECT_EQ(quad.br.x, 20); + EXPECT_EQ(quad.br.y, 30); } // both x textSize @@ -224,16 +208,16 @@ TEST(getIconQuads, style) { layout.get<TextSize>() = 12.0f; layout.get<IconTextFit>() = IconTextFitType::Both; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -30); - ASSERT_EQ(quad.tl.y, -5); - ASSERT_EQ(quad.tr.x, 10); - ASSERT_EQ(quad.tr.y, -5); - ASSERT_EQ(quad.bl.x, -30); - ASSERT_EQ(quad.bl.y, 15); - ASSERT_EQ(quad.br.x, 10); - ASSERT_EQ(quad.br.y, 15); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -30); + EXPECT_EQ(quad.tl.y, -5); + EXPECT_EQ(quad.tr.x, 10); + EXPECT_EQ(quad.tr.y, -5); + EXPECT_EQ(quad.bl.x, -30); + EXPECT_EQ(quad.bl.y, 15); + EXPECT_EQ(quad.br.x, 10); + EXPECT_EQ(quad.br.y, 15); } // both x textSize + padding @@ -246,16 +230,16 @@ TEST(getIconQuads, style) { layout.get<IconTextFitPadding>()[2] = 5.0f; layout.get<IconTextFitPadding>()[3] = 10.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -40); - ASSERT_EQ(quad.tl.y, -10); - ASSERT_EQ(quad.tr.x, 20); - ASSERT_EQ(quad.tr.y, -10); - ASSERT_EQ(quad.bl.x, -40); - ASSERT_EQ(quad.bl.y, 20); - ASSERT_EQ(quad.br.x, 20); - ASSERT_EQ(quad.br.y, 20); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -40); + EXPECT_EQ(quad.tl.y, -10); + EXPECT_EQ(quad.tr.x, 20); + EXPECT_EQ(quad.tr.y, -10); + EXPECT_EQ(quad.bl.x, -40); + EXPECT_EQ(quad.bl.y, 20); + EXPECT_EQ(quad.br.x, 20); + EXPECT_EQ(quad.br.y, 20); } // both x textSize + padding t/r/b/l @@ -268,16 +252,16 @@ TEST(getIconQuads, style) { layout.get<IconTextFitPadding>()[2] = 10.0f; layout.get<IconTextFitPadding>()[3] = 15.0f; SymbolQuad quad = - getIconQuad(anchor, *shapedIcon, line, layout, 12.0f, SymbolPlacementType::Point, shapedText); - - ASSERT_EQ(quad.tl.x, -45); - ASSERT_EQ(quad.tl.y, -5); - ASSERT_EQ(quad.tr.x, 15); - ASSERT_EQ(quad.tr.y, -5); - ASSERT_EQ(quad.bl.x, -45); - ASSERT_EQ(quad.bl.y, 25); - ASSERT_EQ(quad.br.x, 15); - ASSERT_EQ(quad.br.y, 25); + getIconQuad(shapedIcon, layout, 12.0f, shapedText); + + EXPECT_EQ(quad.tl.x, -45); + EXPECT_EQ(quad.tl.y, -5); + EXPECT_EQ(quad.tr.x, 15); + EXPECT_EQ(quad.tr.y, -5); + EXPECT_EQ(quad.bl.x, -45); + EXPECT_EQ(quad.bl.y, 25); + EXPECT_EQ(quad.br.x, 15); + EXPECT_EQ(quad.br.y, 25); } } |