diff options
author | Chris Loer <chris.loer@gmail.com> | 2017-12-06 15:03:28 -0800 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2017-12-11 10:43:00 -0800 |
commit | b4c781aef73faa62e20af38016ac99ce8bc638ac (patch) | |
tree | dfb0dad467e242dead569b03a08465a9804205c3 /test/text | |
parent | b2f06677a787fe7b9b08608e5a55aaedbe50ed3a (diff) | |
download | qtlocation-mapboxgl-b4c781aef73faa62e20af38016ac99ce8bc638ac.tar.gz |
[core, macos, ios] Unit tests for LocalGlyphRasterizer
Core test uses stubbed "glyph.pbf" without Chinese glyphs
Darwin test relies on locally available "PingFang" font.
Android test relies on locally available "Droid" font. 'expected.png' is NOT correct b/c I haven't figured out how to run unit tests on Android yet.
Diffstat (limited to 'test/text')
-rw-r--r-- | test/text/local_glyph_rasterizer.test.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp new file mode 100644 index 0000000000..a77083a5d8 --- /dev/null +++ b/test/text/local_glyph_rasterizer.test.cpp @@ -0,0 +1,86 @@ +#include <mbgl/test/util.hpp> +#include <mbgl/test/stub_file_source.hpp> +#include <mbgl/map/map.hpp> +#include <mbgl/util/io.hpp> +#include <mbgl/util/run_loop.hpp> +#include <mbgl/util/color.hpp> +#include <mbgl/renderer/renderer.hpp> +#include <mbgl/gl/headless_frontend.hpp> +#include <mbgl/util/default_thread_pool.hpp> +#include <mbgl/style/style.hpp> + +using namespace mbgl; + +namespace { + +class LocalGlyphRasterizerTest { +public: + LocalGlyphRasterizerTest(const optional<std::string> fontFamily) + : frontend(pixelRatio, fileSource, threadPool, optional<std::string>(), GLContextMode::Unique, fontFamily) + { + } + + util::RunLoop loop; + StubFileSource fileSource; + ThreadPool threadPool { 4 }; + float pixelRatio { 1 }; + HeadlessFrontend frontend; + Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, + threadPool, MapMode::Static}; + + void checkRendering(const char * name) { + test::checkImage(std::string("test/fixtures/local_glyphs/") + name, + frontend.render(map), 0.0002, 0.1); + } +}; + +} // end namespace + +#ifdef __APPLE__ + +TEST(LocalGlyphRasterizer, PingFang) { + LocalGlyphRasterizerTest test(std::string("PingFang")); + + 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.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json")); + test.checkRendering("ping_fang"); +} + +#endif + +TEST(LocalGlyphRasterizer, NoLocal) { + // Expectation: without any local fonts set, and without any CJK glyphs provided, + // the output should just contain basic latin characters. + LocalGlyphRasterizerTest 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.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json")); + test.checkRendering("no_local"); +} + +#if ANDROID + +TEST(LocalGlyphRasterizer, Droid) { + LocalGlyphRasterizerTest test(std::string("Droid")); + + 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.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json")); + test.checkRendering("droid"); +} + +#endif |