Merge pull request #3999 from mapnik/test-placement-type

Tests of text_placements_simple and text_placements_list
This commit is contained in:
Artem Pavlenko 2019-07-02 11:56:39 +01:00 committed by GitHub
commit 7d1bfaeb4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 97 additions and 1 deletions

View file

@ -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<directions_e> direction_;
std::vector<int> text_sizes_;
private:

View file

@ -0,0 +1,64 @@
#include "catch.hpp"
#include <mapnik/text/placements/list.hpp>
#include <mapnik/text/formatting/text.hpp>
#include <mapnik/feature.hpp>
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<mapnik::formatting::text_node>("\"Default text\""));
{
mapnik::text_symbolizer_properties & properties = list.add();
properties.format_defaults.text_size = 10.0;
properties.set_format_tree(std::make_shared<mapnik::formatting::text_node>("\"Alternative text 1\""));
}
{
mapnik::text_symbolizer_properties & properties = list.add();
properties.format_defaults.text_size = 8.0;
properties.set_format_tree(std::make_shared<mapnik::formatting::text_node>("\"Alternative text 2\""));
}
mapnik::context_ptr context(std::make_shared<mapnik::context_type>());
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<mapnik::value_double>() == 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>() == mapnik::value_unicode_string("Default text"));
}
{
REQUIRE(info->next());
CHECK(info->properties.format_defaults.text_size.get<mapnik::value_double>() == 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>() == mapnik::value_unicode_string("Alternative text 1"));
}
{
REQUIRE(info->next());
CHECK(info->properties.format_defaults.text_size.get<mapnik::value_double>() == 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>() == mapnik::value_unicode_string("Alternative text 2"));
}
CHECK(!info->next());
}

View file

@ -0,0 +1,33 @@
#include "catch.hpp"
#include <mapnik/text/placements/simple.hpp>
#include <mapnik/feature.hpp>
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::context_type>());
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<mapnik::value_double>() == Approx(12.0));
REQUIRE(info->next());
CHECK(info->properties.layout_defaults.dir == mapnik::SOUTH);
CHECK(info->properties.format_defaults.text_size.get<mapnik::value_double>() == Approx(12.0));
REQUIRE(info->next());
CHECK(info->properties.layout_defaults.dir == mapnik::NORTH);
CHECK(info->properties.format_defaults.text_size.get<mapnik::value_double>() == Approx(8.0));
REQUIRE(info->next());
CHECK(info->properties.layout_defaults.dir == mapnik::SOUTH);
CHECK(info->properties.format_defaults.text_size.get<mapnik::value_double>() == Approx(8.0));
CHECK(!info->next());
}