diff options
Diffstat (limited to 'test/text/glyph_atlas.test.cpp')
-rw-r--r-- | test/text/glyph_atlas.test.cpp | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/test/text/glyph_atlas.test.cpp b/test/text/glyph_atlas.test.cpp index 3679cabc1b..fe27e4c6fe 100644 --- a/test/text/glyph_atlas.test.cpp +++ b/test/text/glyph_atlas.test.cpp @@ -11,12 +11,14 @@ using namespace mbgl; -class GlyphAtlasTest { +class GlyphAtlasTest : public GlyphRequestor { public: util::RunLoop loop; StubFileSource fileSource; StubStyleObserver observer; GlyphAtlas glyphAtlas{ { 32, 32 }, fileSource }; + GlyphPositionMap glyphPositions; + GlyphRangeSet loadedRanges; void run(const std::string& url, const FontStack& fontStack, const GlyphRangeSet& glyphRanges) { // Squelch logging. @@ -24,14 +26,31 @@ public: glyphAtlas.setObserver(&observer); glyphAtlas.setURL(url); + GlyphDependencies glyphDependencies; + for (const auto& range : glyphRanges) { + glyphDependencies[fontStack].insert(range.first); + } + glyphAtlas.getGlyphs(*this, glyphDependencies); glyphAtlas.hasGlyphRanges(fontStack, glyphRanges); loop.run(); } + void addGlyphs(GlyphRequestor& requestor, const GlyphDependencies& glyphDependencies) { + glyphAtlas.addGlyphs(requestor, glyphDependencies); + } + + bool hasGlyphRanges(const FontStack& fontStack, const GlyphRangeSet& ranges) const { + return glyphAtlas.hasGlyphRanges(fontStack, ranges); + } void end() { loop.stop(); } + + virtual void onGlyphsAvailable(GlyphPositionMap positions, GlyphRangeSet _loadedRanges) { + glyphPositions = std::move(positions); + loadedRanges = std::move(_loadedRanges); + } }; TEST(GlyphAtlas, LoadingSuccess) { @@ -50,11 +69,11 @@ TEST(GlyphAtlas, LoadingSuccess) { }; test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { - if (!test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}})) + if (!test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}})) return; - auto glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); - ASSERT_FALSE(glyphSet->getSDFs().empty()); + auto& glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); + ASSERT_FALSE(glyphSet.getSDFs().empty()); test.end(); }; @@ -83,8 +102,8 @@ TEST(GlyphAtlas, LoadingFail) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "Failed by the test case"); - ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}})->getSDFs().empty()); - ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}}).getSDFs().empty()); + ASSERT_FALSE(test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); test.end(); }; @@ -111,8 +130,8 @@ TEST(GlyphAtlas, LoadingCorrupted) { EXPECT_TRUE(error != nullptr); EXPECT_EQ(util::toString(error), "unknown pbf field type exception"); - ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}})->getSDFs().empty()); - ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + ASSERT_TRUE(test.glyphAtlas.getGlyphSet({{"Test Stack"}}).getSDFs().empty()); + ASSERT_FALSE(test.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); test.end(); }; @@ -145,19 +164,20 @@ TEST(GlyphAtlas, InvalidSDFGlyph) { const FontStack fontStack{ "Mock Font" }; GlyphAtlasTest test; - GlyphPositions positions; - auto glyphSet = test.glyphAtlas.getGlyphSet(fontStack); - glyphSet->insert(66, SDFGlyph{ 66 /* ASCII 'B' */, + auto& glyphSet = test.glyphAtlas.getGlyphSet(fontStack); + glyphSet.insert(66, SDFGlyph{ 66 /* ASCII 'B' */, AlphaImage({7, 7}), /* correct */ { 1 /* width */, 1 /* height */, 0 /* left */, 0 /* top */, 0 /* advance */ } }); - glyphSet->insert(67, SDFGlyph{ 67 /* ASCII 'C' */, + glyphSet.insert(67, SDFGlyph{ 67 /* ASCII 'C' */, AlphaImage({518, 8}), /* correct */ { 512 /* width */, 2 /* height */, 0 /* left */, 0 /* top */, 0 /* advance */ } }); - test.glyphAtlas.addGlyphs(1, std::u16string{u"ABC"}, fontStack, glyphSet, positions); + GlyphDependencies glyphDependencies = {{fontStack, {'A','B','C'}}}; + test.addGlyphs(test, glyphDependencies); + GlyphPositions positions = test.glyphPositions[fontStack]; ASSERT_EQ(2u, positions.size()); |