unit test - use 'parse_image_filters' and avoid instantiating expensive redundant grammar

This commit is contained in:
artemp 2016-02-02 11:25:32 +01:00
parent 4122826031
commit cd2b13eb57

View file

@ -6,9 +6,7 @@
#include <mapnik/color.hpp>
#include <mapnik/image_filter.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/image_filter_grammar.hpp>
#include <mapnik/image_filter_grammar_impl.hpp>
#include <mapnik/css_color_grammar_impl.hpp>
#include <mapnik/image_filter_types.hpp>
TEST_CASE("image filter") {
@ -393,13 +391,10 @@ SECTION("test colorize-alpha - two color with transparency") {
SECTION("test colorize-alpha - parsing correct input") {
mapnik::image_filter_grammar<std::string::const_iterator, std::vector<mapnik::filter::filter_type>> filter_grammar;
boost::spirit::qi::ascii::space_type space;
std::vector<mapnik::filter::filter_type> f;
std::string s("colorize-alpha(#0000ff 0%, #00ff00 100%)");
CHECK( boost::spirit::qi::phrase_parse(s.cbegin(), s.cend(), filter_grammar, space, f) );
std::vector<mapnik::filter::filter_type> f;
CHECK(parse_image_filters(s, f));
mapnik::filter::colorize_alpha const & ca = mapnik::util::get<mapnik::filter::colorize_alpha>(f.front());
{
mapnik::filter::color_stop const & s2 = ca[0];
CHECK( s2.color.alpha() == 0xff );
@ -422,15 +417,10 @@ SECTION("test colorize-alpha - parsing correct input") {
SECTION("test colorize-alpha - parsing incorrect input") {
mapnik::image_filter_grammar<std::string::const_iterator, std::vector<mapnik::filter::filter_type>> filter_grammar;
boost::spirit::qi::ascii::space_type space;
std::string s("colorize-alpha(#0000ff 0%, #00ff00 00 100%)");
std::string::const_iterator itr = s.cbegin();
std::string::const_iterator end = s.cend();
std::vector<mapnik::filter::filter_type> f;
CHECK( boost::spirit::qi::phrase_parse(s.cbegin(), s.cend(), filter_grammar, space, f) );
CHECK(!parse_image_filters(s, f));
CHECK( f.empty() );
CHECK( itr != end );
} // END SECTION
@ -486,4 +476,3 @@ SECTION("test color-blind-tritanope") {
} // END SECTION
} // END TEST CASE