From 90a1b6508138c0aa07b93b44b5ed261e9381d698 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Sat, 20 Oct 2018 07:51:57 +0000 Subject: [PATCH 1/3] New test of text_placements_simple --- test/unit/text/text_placements_simple.cpp | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/unit/text/text_placements_simple.cpp diff --git a/test/unit/text/text_placements_simple.cpp b/test/unit/text/text_placements_simple.cpp new file mode 100644 index 000000000..167f55ba9 --- /dev/null +++ b/test/unit/text/text_placements_simple.cpp @@ -0,0 +1,33 @@ +#include "catch.hpp" +#include +#include + +TEST_CASE("text_placements_simple") +{ + mapnik::text_placements_simple simple("N, S, 8"); + + simple.defaults.format_defaults.text_size = 12.0; + + mapnik::context_ptr context(std::make_shared()); + mapnik::feature_impl feature(context, 1); + mapnik::attributes vars; + mapnik::text_placement_info_ptr info = simple.get_placement_info(1.0, feature, vars); + + REQUIRE(info->next()); + CHECK(info->properties.layout_defaults.dir == mapnik::NORTH); + CHECK(info->properties.format_defaults.text_size.get() == Approx(12.0)); + + REQUIRE(info->next()); + CHECK(info->properties.layout_defaults.dir == mapnik::SOUTH); + CHECK(info->properties.format_defaults.text_size.get() == Approx(12.0)); + + REQUIRE(info->next()); + CHECK(info->properties.layout_defaults.dir == mapnik::NORTH); + CHECK(info->properties.format_defaults.text_size.get() == Approx(8.0)); + + REQUIRE(info->next()); + CHECK(info->properties.layout_defaults.dir == mapnik::SOUTH); + CHECK(info->properties.format_defaults.text_size.get() == Approx(8.0)); + + CHECK(!info->next()); +} From 3b188b4c26802ccd07d7f43b56c8eea2994c9033 Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Sat, 20 Oct 2018 07:52:19 +0000 Subject: [PATCH 2/3] Remove method declaration that is not implemented --- include/mapnik/text/placements/simple.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/include/mapnik/text/placements/simple.hpp b/include/mapnik/text/placements/simple.hpp index ac66ba440..224406b7f 100644 --- a/include/mapnik/text/placements/simple.hpp +++ b/include/mapnik/text/placements/simple.hpp @@ -43,7 +43,6 @@ public: text_placement_info_ptr get_placement_info(double _scale_factor, feature_impl const& feature, attributes const& vars) const; std::string get_positions() const; static text_placements_ptr from_xml(xml_node const& xml, fontset_map const& fontsets, bool is_shield); - void init_positions(std::string const& positions) const; std::vector direction_; std::vector text_sizes_; private: From 46de0f661bbc914fd86b7f748f582fb5ea29647e Mon Sep 17 00:00:00 2001 From: Jiri Drbalek Date: Sat, 20 Oct 2018 21:09:08 +0000 Subject: [PATCH 3/3] New test of text_placements_list --- test/unit/text/text_placements_list.cpp | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 test/unit/text/text_placements_list.cpp diff --git a/test/unit/text/text_placements_list.cpp b/test/unit/text/text_placements_list.cpp new file mode 100644 index 000000000..37bc553ed --- /dev/null +++ b/test/unit/text/text_placements_list.cpp @@ -0,0 +1,64 @@ +#include "catch.hpp" +#include +#include +#include + +TEST_CASE("text_placements_list") +{ + mapnik::text_placements_list list; + + list.defaults.format_defaults.text_size = 12.0; + list.defaults.set_format_tree(std::make_shared("\"Default text\"")); + + { + mapnik::text_symbolizer_properties & properties = list.add(); + properties.format_defaults.text_size = 10.0; + properties.set_format_tree(std::make_shared("\"Alternative text 1\"")); + } + + { + mapnik::text_symbolizer_properties & properties = list.add(); + properties.format_defaults.text_size = 8.0; + properties.set_format_tree(std::make_shared("\"Alternative text 2\"")); + } + + mapnik::context_ptr context(std::make_shared()); + mapnik::feature_impl feature(context, 1); + mapnik::attributes vars; + mapnik::text_placement_info_ptr info = list.get_placement_info(1.0, feature, vars); + + { + REQUIRE(info->next()); + CHECK(info->properties.format_defaults.text_size.get() == Approx(12.0)); + REQUIRE(info->properties.format_tree()); + mapnik::expression_set expressions; + info->properties.format_tree()->add_expressions(expressions); + REQUIRE(!expressions.empty()); + mapnik::expr_node const& expression = **expressions.begin(); + CHECK(expression.get() == mapnik::value_unicode_string("Default text")); + } + + { + REQUIRE(info->next()); + CHECK(info->properties.format_defaults.text_size.get() == Approx(10.0)); + REQUIRE(info->properties.format_tree()); + mapnik::expression_set expressions; + info->properties.format_tree()->add_expressions(expressions); + REQUIRE(!expressions.empty()); + mapnik::expr_node const& expression = **expressions.begin(); + CHECK(expression.get() == mapnik::value_unicode_string("Alternative text 1")); + } + + { + REQUIRE(info->next()); + CHECK(info->properties.format_defaults.text_size.get() == Approx(8.0)); + REQUIRE(info->properties.format_tree()); + mapnik::expression_set expressions; + info->properties.format_tree()->add_expressions(expressions); + REQUIRE(!expressions.empty()); + mapnik::expr_node const& expression = **expressions.begin(); + CHECK(expression.get() == mapnik::value_unicode_string("Alternative text 2")); + } + + CHECK(!info->next()); +}