diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 11:45:33 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-09-28 16:34:22 +0200 |
commit | 3f3fc7b7723698e44427e2a14a2f4906832800bf (patch) | |
tree | 5acadfa4d77817c41f612c89c93925a149cbcfc0 /test/text/glyph_atlas.test.cpp | |
parent | a8b007daa0e85ea4b1a4898fd591d55d0117cc85 (diff) | |
download | qtlocation-mapboxgl-3f3fc7b7723698e44427e2a14a2f4906832800bf.tar.gz |
[test] add .test.cpp suffix to test case files
Diffstat (limited to 'test/text/glyph_atlas.test.cpp')
-rw-r--r-- | test/text/glyph_atlas.test.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/test/text/glyph_atlas.test.cpp b/test/text/glyph_atlas.test.cpp new file mode 100644 index 0000000000..8634cbe913 --- /dev/null +++ b/test/text/glyph_atlas.test.cpp @@ -0,0 +1,144 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/stub_file_source.hpp> +#include <mbgl/test/stub_style_observer.hpp> + +#include <mbgl/text/glyph_set.hpp> +#include <mbgl/text/glyph_atlas.hpp> +#include <mbgl/util/run_loop.hpp> +#include <mbgl/util/string.hpp> +#include <mbgl/util/io.hpp> +#include <mbgl/platform/log.hpp> + +using namespace mbgl; + +class GlyphAtlasTest { +public: + util::RunLoop loop; + StubFileSource fileSource; + StubStyleObserver observer; + GlyphAtlas glyphAtlas { 32, 32, fileSource }; + + void run(const std::string& url, const FontStack& fontStack, const GlyphRangeSet& glyphRanges) { + // Squelch logging. + Log::setObserver(std::make_unique<Log::NullObserver>()); + + glyphAtlas.setObserver(&observer); + glyphAtlas.setURL(url); + glyphAtlas.hasGlyphRanges(fontStack, glyphRanges); + + loop.run(); + } + + void end() { + loop.stop(); + } +}; + +TEST(GlyphAtlas, LoadingSuccess) { + GlyphAtlasTest test; + + test.fileSource.glyphsResponse = [&] (const Resource& resource) { + EXPECT_EQ(Resource::Kind::Glyphs, resource.kind); + Response response; + response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf")); + return response; + }; + + test.observer.glyphsError = [&] (const FontStack&, const GlyphRange&, std::exception_ptr) { + FAIL(); + test.end(); + }; + + test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { + if (!test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}, {256, 511}})) + return; + + auto glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); + ASSERT_FALSE(glyphSet->getSDFs().empty()); + + test.end(); + }; + + test.run( + "test/fixtures/resources/glyphs.pbf", + {{"Test Stack"}}, + {{0, 255}, {256, 511}}); +} + +TEST(GlyphAtlas, LoadingFail) { + GlyphAtlasTest test; + + test.fileSource.glyphsResponse = [&] (const Resource&) { + Response response; + response.error = std::make_unique<Response::Error>( + Response::Error::Reason::Other, + "Failed by the test case"); + return response; + }; + + test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { + EXPECT_EQ(fontStack, FontStack({"Test Stack"})); + EXPECT_EQ(glyphRange, GlyphRange(0, 255)); + + EXPECT_TRUE(error != nullptr); + EXPECT_EQ(util::toString(error), "Failed by the test case"); + + auto glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); + ASSERT_TRUE(glyphSet->getSDFs().empty()); + ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + + test.end(); + }; + + test.run( + "test/fixtures/resources/glyphs.pbf", + {{"Test Stack"}}, + {{0, 255}}); +} + +TEST(GlyphAtlas, LoadingCorrupted) { + GlyphAtlasTest test; + + test.fileSource.glyphsResponse = [&] (const Resource&) { + Response response; + response.data = std::make_unique<std::string>("CORRUPTED"); + return response; + }; + + test.observer.glyphsError = [&] (const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { + EXPECT_EQ(fontStack, FontStack({"Test Stack"})); + EXPECT_EQ(glyphRange, GlyphRange(0, 255)); + + EXPECT_TRUE(error != nullptr); + EXPECT_EQ(util::toString(error), "unknown pbf field type exception"); + + auto glyphSet = test.glyphAtlas.getGlyphSet({{"Test Stack"}}); + ASSERT_TRUE(glyphSet->getSDFs().empty()); + ASSERT_FALSE(test.glyphAtlas.hasGlyphRanges({{"Test Stack"}}, {{0, 255}})); + + test.end(); + }; + + test.run( + "test/fixtures/resources/glyphs.pbf", + {{"Test Stack"}}, + {{0, 255}}); +} + +TEST(GlyphAtlas, LoadingCancel) { + GlyphAtlasTest test; + + test.fileSource.glyphsResponse = [&] (const Resource&) { + test.end(); + return optional<Response>(); + }; + + test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { + FAIL() << "Should never be called"; + }; + + test.run( + "test/fixtures/resources/glyphs.pbf", + {{"Test Stack"}}, + {{0, 255}}); +} |