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 {
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");
std::map<unsigned,double> width_map;
@ -30,11 +30,19 @@ void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm,
std::size_t index = 0;
for (auto const& g : line)
{
unsigned glyph_index, char_index;
CHECK(index < expected.size());
std::tie(glyph_index, char_index) = expected[index++];
REQUIRE(glyph_index == g.glyph_index);
REQUIRE(char_index == g.char_index);
if (debug)
{
if (index++ > 0) std::cerr << ",";
std::cerr << "{" << g.glyph_index << ", " << g.char_index << "}";
}
else
{
unsigned glyph_index, char_index;
CHECK(index < expected.size());
std::tie(glyph_index, char_index) = expected[index++];
REQUIRE(glyph_index == g.glyph_index);
REQUIRE(char_index == g.char_index);
}
}
}
}
@ -76,4 +84,11 @@ TEST_CASE("shaping")
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)");
}
}