From cd2b13eb57ad0bd30a642a9c4afec7e72cf14455 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 2 Feb 2016 11:25:32 +0100 Subject: [PATCH] unit test - use 'parse_image_filters' and avoid instantiating expensive redundant grammar --- test/unit/imaging/image_filter.cpp | 95 +++++++++++++----------------- 1 file changed, 42 insertions(+), 53 deletions(-) diff --git a/test/unit/imaging/image_filter.cpp b/test/unit/imaging/image_filter.cpp index 8d41ccbe2..f2805b068 100644 --- a/test/unit/imaging/image_filter.cpp +++ b/test/unit/imaging/image_filter.cpp @@ -6,29 +6,27 @@ #include #include #include -#include -#include -#include +#include TEST_CASE("image filter") { SECTION("test bad filter input") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("red")); - + REQUIRE_THROWS( mapnik::filter::filter_image(im, "foo,asdfasdf()"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha("); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(blue"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "color-to-alpha(,blue)"); ); REQUIRE_THROWS( mapnik::filter::filter_image(im, "colorize-alpha()"); ); - REQUIRE_THROWS( + REQUIRE_THROWS( mapnik::image_rgba8 const& im2 = im; mapnik::image_rgba8 new_im = mapnik::filter::filter_image(im2, "foo"); ); - + CHECK(im(0,0) == 0xffff0000); CHECK(im(0,1) == 0xffff0000); CHECK(im(0,2) == 0xffff0000); @@ -38,11 +36,11 @@ SECTION("test bad filter input") { CHECK(im(2,0) == 0xffff0000); CHECK(im(2,1) == 0xffff0000); CHECK(im(2,2) == 0xffff0000); - + } // END SECTION SECTION("test blur") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("red")); @@ -58,11 +56,11 @@ SECTION("test blur") { CHECK(im(2,0) == 0xffc60038); CHECK(im(2,1) == 0xffe2001c); CHECK(im(2,2) == 0xffc60038); - + } // END SECTION SECTION("test blur constant") { - + mapnik::image_rgba8 im_orig(3,3); mapnik::fill(im_orig,mapnik::color("blue")); mapnik::set_pixel(im_orig, 1, 1, mapnik::color("red")); @@ -79,11 +77,11 @@ SECTION("test blur constant") { CHECK(im(2,0) == 0xffc60038); CHECK(im(2,1) == 0xffe2001c); CHECK(im(2,2) == 0xffc60038); - + } // END SECTION SECTION("test gray") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("red")); @@ -99,11 +97,11 @@ SECTION("test gray") { CHECK(im(2,0) == 0xff1c1c1c); CHECK(im(2,1) == 0xff1c1c1c); CHECK(im(2,2) == 0xff1c1c1c); - + } // END SECTION SECTION("test agg stack blur") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("red")); @@ -123,7 +121,7 @@ SECTION("test agg stack blur") { } // END SECTION SECTION("test scale-hsla 1") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("red")); @@ -139,7 +137,7 @@ SECTION("test scale-hsla 1") { CHECK(im(2,0) == 0x80004000); CHECK(im(2,1) == 0x80004000); CHECK(im(2,2) == 0x80004000); - + } // END SECTION SECTION("test scale-hsla 2") { @@ -172,7 +170,7 @@ SECTION("test scale-hsla 2") { } // END SECTION SECTION("test emboss") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("white")); mapnik::set_pixel(im, 1, 1, mapnik::color("orange")); @@ -188,11 +186,11 @@ SECTION("test emboss") { CHECK(im(2,0) == 0xffffffff); CHECK(im(2,1) == 0xffffffff); CHECK(im(2,2) == 0xffffffff); - + } // END SECTION SECTION("test sharpen") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -208,11 +206,11 @@ SECTION("test sharpen") { CHECK(im(2,0) == 0xffff0000); CHECK(im(2,1) == 0xffff0000); CHECK(im(2,2) == 0xffff0000); - + } // END SECTION SECTION("test edge detect") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -228,11 +226,11 @@ SECTION("test edge detect") { CHECK(im(2,0) == 0xff000000); CHECK(im(2,1) == 0xff008080); CHECK(im(2,2) == 0xff000000); - + } // END SECTION SECTION("test sobel") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -248,11 +246,11 @@ SECTION("test sobel") { CHECK(im(2,0) == 0xfffeffff); CHECK(im(2,1) == 0xfffeffff); CHECK(im(2,2) == 0xfffeffff); - + } // END SECTION SECTION("test x-gradient") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -268,11 +266,11 @@ SECTION("test x-gradient") { CHECK(im(2,0) == 0xff808080); CHECK(im(2,1) == 0xff41c0c0); CHECK(im(2,2) == 0xff808080); - + } // END SECTION SECTION("test y-gradient") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -288,11 +286,11 @@ SECTION("test y-gradient") { CHECK(im(2,0) == 0xff808080); CHECK(im(2,1) == 0xff808080); CHECK(im(2,2) == 0xff808080); - + } // END SECTION SECTION("test invert") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -308,11 +306,11 @@ SECTION("test invert") { CHECK(im(2,0) == 0xff00ffff); CHECK(im(2,1) == 0xff00ffff); CHECK(im(2,2) == 0xff00ffff); - + } // END SECTION SECTION("test colorize-alpha - one color") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -328,11 +326,11 @@ SECTION("test colorize-alpha - one color") { CHECK(im(2,0) == 0xffff0000); CHECK(im(2,1) == 0xffff0000); CHECK(im(2,2) == 0xffff0000); - + } // END SECTION SECTION("test colorize-alpha - two color") { - + mapnik::image_rgba8 im(3,3); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 1, 1, mapnik::color("gray")); @@ -348,7 +346,7 @@ SECTION("test colorize-alpha - two color") { CHECK(im(2,0) == 0xfffd0000); CHECK(im(2,1) == 0xfffd0000); CHECK(im(2,2) == 0xfffd0000); - + } // END SECTION SECTION("test colorize-alpha - one color with transparency") { @@ -393,13 +391,10 @@ SECTION("test colorize-alpha - two color with transparency") { SECTION("test colorize-alpha - parsing correct input") { - mapnik::image_filter_grammar> filter_grammar; - boost::spirit::qi::ascii::space_type space; - std::vector 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 f; + CHECK(parse_image_filters(s, f)); mapnik::filter::colorize_alpha const & ca = mapnik::util::get(f.front()); - { mapnik::filter::color_stop const & s2 = ca[0]; CHECK( s2.color.alpha() == 0xff ); @@ -422,20 +417,15 @@ SECTION("test colorize-alpha - parsing correct input") { SECTION("test colorize-alpha - parsing incorrect input") { - mapnik::image_filter_grammar> 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 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 SECTION("test color-blind-protanope") { - + mapnik::image_rgba8 im(2,2); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 0, 1, mapnik::color("green")); @@ -448,11 +438,11 @@ SECTION("test color-blind-protanope") { CHECK(im(0,1) == 0xff006e7c); CHECK(im(1,0) == 0xffd9f6ff); CHECK(im(1,1) == 0xff1d7e8e); - + } // END SECTION SECTION("test color-blind-deuteranope") { - + mapnik::image_rgba8 im(2,2); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 0, 1, mapnik::color("green")); @@ -465,11 +455,11 @@ SECTION("test color-blind-deuteranope") { CHECK(im(0,1) == 0xff1c688b); CHECK(im(1,0) == 0xffe9f5ff); CHECK(im(1,1) == 0xff0077a0); - + } // END SECTION SECTION("test color-blind-tritanope") { - + mapnik::image_rgba8 im(2,2); mapnik::fill(im,mapnik::color("blue")); mapnik::set_pixel(im, 0, 1, mapnik::color("green")); @@ -482,8 +472,7 @@ SECTION("test color-blind-tritanope") { CHECK(im(0,1) == 0xff80763a); CHECK(im(1,0) == 0xfff8f3ff); CHECK(im(1,1) == 0xff0017fd); - + } // END SECTION } // END TEST CASE -