add debug mode to generate expected result + add one more test

This commit is contained in:
artemp 2017-02-21 13:17:41 +01:00
parent 8af91146c4
commit 10b1ed2fa9

View file

@ -7,7 +7,7 @@
namespace { namespace {
void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm, void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
std::vector<std::tuple<unsigned, unsigned>> const& expected, char const* str) std::vector<std::tuple<unsigned, unsigned>> const& expected, char const* str, bool debug = false)
{ {
mapnik::transcoder tr("utf8"); mapnik::transcoder tr("utf8");
std::map<unsigned,double> width_map; std::map<unsigned,double> width_map;
@ -29,6 +29,13 @@ void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
std::size_t index = 0; std::size_t index = 0;
for (auto const& g : line) for (auto const& g : line)
{
if (debug)
{
if (index++ > 0) std::cerr << ",";
std::cerr << "{" << g.glyph_index << ", " << g.char_index << "}";
}
else
{ {
unsigned glyph_index, char_index; unsigned glyph_index, char_index;
CHECK(index < expected.size()); CHECK(index < expected.size());
@ -38,6 +45,7 @@ void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
} }
} }
} }
}
TEST_CASE("shaping") TEST_CASE("shaping")
{ {
@ -76,4 +84,11 @@ TEST_CASE("shaping")
test_shaping(fontset, fm, expected, "abc (普兰镇)"); test_shaping(fontset, fm, expected, "abc (普兰镇)");
} }
{
std::vector<std::tuple<unsigned, unsigned>> expected =
{{68, 0}, {69, 1}, {70, 2}, {3, 3}, {11, 4}, {68, 5}, {69, 6}, {70, 7}, {12, 8}};
test_shaping(fontset, fm, expected, "abc (abc)");
}
} }