Skip to content

Commit 1b35d5a

Browse files
author
Dane Springmeyer
committed
C++ test cleanup
1 parent a6978cb commit 1b35d5a

12 files changed

+254
-211
lines changed

tests/cpp_tests/agg_blend_src_over_test.cpp

+58-50
Original file line numberDiff line numberDiff line change
@@ -144,64 +144,72 @@ int main(int argc, char** argv)
144144
using source_over_old_agg = agg::comp_op_rgba_src_over2<color, agg::order_rgba>;
145145
using source_over = agg::comp_op_rgba_src_over<color, agg::order_rgba>;
146146

147-
color white(255,255,255,255);
148-
color black(0,0,0,255);
147+
try
148+
{
149+
color white(255,255,255,255);
150+
color black(0,0,0,255);
149151

150-
BOOST_TEST_EQ( to_string(blend<source_over>(white,white)), to_string(white) );
151-
BOOST_TEST_EQ( to_string(blend<source_over>(white,black)), to_string(white) );
152-
BOOST_TEST_EQ( to_string(blend<source_over>(black,white)), to_string(black) );
152+
BOOST_TEST_EQ( to_string(blend<source_over>(white,white)), to_string(white) );
153+
BOOST_TEST_EQ( to_string(blend<source_over>(white,black)), to_string(white) );
154+
BOOST_TEST_EQ( to_string(blend<source_over>(black,white)), to_string(black) );
153155

154-
// https://github.com/mapnik/mapnik/issues/1452#issuecomment-8154646
155-
color near_white(254,254,254,254); // Source
156-
color near_trans(1,1,1,1); // Dest
157-
color expected_color(252,252,252,255); // expected result
158-
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(near_white,near_trans)), to_string(color(252,252,252,254)) );
159-
BOOST_TEST_EQ( to_string(blend<source_over>(near_white,near_trans)), to_string(expected_color) );
160-
BOOST_TEST_EQ( to_string(normal_blend(near_white,near_trans)), to_string(expected_color) );
156+
// https://github.com/mapnik/mapnik/issues/1452#issuecomment-8154646
157+
color near_white(254,254,254,254); // Source
158+
color near_trans(1,1,1,1); // Dest
159+
color expected_color(252,252,252,255); // expected result
160+
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(near_white,near_trans)), to_string(color(252,252,252,254)) );
161+
BOOST_TEST_EQ( to_string(blend<source_over>(near_white,near_trans)), to_string(expected_color) );
162+
BOOST_TEST_EQ( to_string(normal_blend(near_white,near_trans)), to_string(expected_color) );
161163

162-
// using normal_blend as expected, compare a variety of other colors
164+
// using normal_blend as expected, compare a variety of other colors
163165

164-
{
165-
color source(128,128,128,255);
166-
color dest(128,128,128,255);
167-
unsigned cover = 128;
168-
std::string expected_str = to_string(normal_blend(source,dest,cover));
169-
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
170-
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
171-
}
166+
{
167+
color source(128,128,128,255);
168+
color dest(128,128,128,255);
169+
unsigned cover = 128;
170+
std::string expected_str = to_string(normal_blend(source,dest,cover));
171+
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
172+
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
173+
}
172174

175+
{
176+
color source(128,128,128,255);
177+
color dest(128,128,128,255);
178+
unsigned cover = 245;
179+
std::string expected_str = to_string(normal_blend(source,dest,cover));
180+
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
181+
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
182+
}
183+
184+
// commenting until I study these failures more (dane)
185+
/*
186+
{
187+
// fails, why?
188+
color source(127,127,127,127);
189+
color dest(127,127,127,127);
190+
unsigned cover = 255;
191+
std::string expected_str = to_string(normal_blend(source,dest,cover));
192+
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
193+
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
194+
}
195+
196+
{
197+
// fails, why?
198+
color source(128,128,128,128);
199+
color dest(128,128,128,128);
200+
unsigned cover = 128;
201+
std::string expected_str = to_string(normal_blend(source,dest,cover));
202+
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
203+
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
204+
}
205+
*/
206+
}
207+
catch (std::exception const & ex)
173208
{
174-
color source(128,128,128,255);
175-
color dest(128,128,128,255);
176-
unsigned cover = 245;
177-
std::string expected_str = to_string(normal_blend(source,dest,cover));
178-
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
179-
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
209+
std::clog << ex.what() << "\n";
210+
BOOST_TEST(false);
180211
}
181212

182-
// commenting until I study these failures more (dane)
183-
/*
184-
{
185-
// fails, why?
186-
color source(127,127,127,127);
187-
color dest(127,127,127,127);
188-
unsigned cover = 255;
189-
std::string expected_str = to_string(normal_blend(source,dest,cover));
190-
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
191-
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
192-
}
193-
194-
{
195-
// fails, why?
196-
color source(128,128,128,128);
197-
color dest(128,128,128,128);
198-
unsigned cover = 128;
199-
std::string expected_str = to_string(normal_blend(source,dest,cover));
200-
BOOST_TEST_EQ( to_string(blend<source_over>(source,dest,cover)), expected_str );
201-
BOOST_TEST_EQ( to_string(blend<source_over_old_agg>(source,dest,cover)), expected_str );
202-
}
203-
*/
204-
205213
if (!::boost::detail::test_errors()) {
206214
if (quiet) std::clog << "\x1b[1;32m.\x1b[0m";
207215
else std::clog << "C++ AGG blending: \x1b[1;32m✓ \x1b[0m\n";

tests/cpp_tests/conversions_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ int main(int argc, char** argv)
295295
}
296296
catch (std::exception const & ex)
297297
{
298-
std::clog << "C++ type conversions problem: " << ex.what() << "\n";
298+
std::clog << ex.what() << "\n";
299299
BOOST_TEST(false);
300300
}
301301

tests/cpp_tests/copy_move_test.cpp

+50-42
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,66 @@ int main(int argc, char** argv)
1818
}
1919
bool quiet = std::find(args.begin(), args.end(), "-q")!=args.end();
2020

21-
mapnik::Map m0(100,100);
22-
mapnik::Map m2(200,100);
21+
try
22+
{
23+
mapnik::Map m0(100,100);
24+
mapnik::Map m2(200,100);
2325

24-
// mapnik::datasource
25-
mapnik::datasource_cache::instance().register_datasources("plugins/input/shape.input");
26-
mapnik::parameters p;
27-
p["type"]="shape";
28-
p["file"]="demo/data/boundaries";
29-
p["encoding"]="latin1";
30-
auto ds0 = mapnik::datasource_cache::instance().create(p);
26+
// mapnik::datasource
27+
mapnik::datasource_cache::instance().register_datasources("plugins/input/shape.input");
28+
mapnik::parameters p;
29+
p["type"]="shape";
30+
p["file"]="demo/data/boundaries";
31+
p["encoding"]="latin1";
32+
auto ds0 = mapnik::datasource_cache::instance().create(p);
3133

32-
auto ds1 = ds0; // shared ptr copy
33-
BOOST_TEST(ds1 == ds0);
34-
BOOST_TEST(*ds1 == *ds0);
35-
ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
36-
BOOST_TEST(ds1 != ds0);
37-
BOOST_TEST(*ds1 == *ds0);
38-
auto ds2 = std::move(ds1);
39-
BOOST_TEST(ds2 != ds0);
40-
BOOST_TEST(*ds2 == *ds0);
34+
auto ds1 = ds0; // shared ptr copy
35+
BOOST_TEST(ds1 == ds0);
36+
BOOST_TEST(*ds1 == *ds0);
37+
ds1 = mapnik::datasource_cache::instance().create(p); // new with the same parameters
38+
BOOST_TEST(ds1 != ds0);
39+
BOOST_TEST(*ds1 == *ds0);
40+
auto ds2 = std::move(ds1);
41+
BOOST_TEST(ds2 != ds0);
42+
BOOST_TEST(*ds2 == *ds0);
4143

42-
// mapnik::layer
43-
mapnik::layer l0("test-layer");
44-
l0.set_datasource(ds0);
44+
// mapnik::layer
45+
mapnik::layer l0("test-layer");
46+
l0.set_datasource(ds0);
4547

46-
mapnik::layer l1 = l0; // copy assignment
47-
BOOST_TEST(l1 == l0);
48-
mapnik::layer l2(l0); // copy ctor
49-
BOOST_TEST(l2 == l0);
50-
mapnik::layer l3(mapnik::layer("test-layer")); // move ctor
51-
l3.set_datasource(ds2);
48+
mapnik::layer l1 = l0; // copy assignment
49+
BOOST_TEST(l1 == l0);
50+
mapnik::layer l2(l0); // copy ctor
51+
BOOST_TEST(l2 == l0);
52+
mapnik::layer l3(mapnik::layer("test-layer")); // move ctor
53+
l3.set_datasource(ds2);
5254

53-
BOOST_TEST(l3 == l0);
54-
mapnik::layer l4 = std::move(l3);
55-
BOOST_TEST(l4 == l0); // move assignment
55+
BOOST_TEST(l3 == l0);
56+
mapnik::layer l4 = std::move(l3);
57+
BOOST_TEST(l4 == l0); // move assignment
5658

57-
m0.add_layer(l4);
58-
m0.set_background(mapnik::color("skyblue"));
59-
m2.set_background(mapnik::color("skyblue"));
59+
m0.add_layer(l4);
60+
m0.set_background(mapnik::color("skyblue"));
61+
m2.set_background(mapnik::color("skyblue"));
6062

61-
auto m1 = m0; //copy
63+
auto m1 = m0; //copy
6264

63-
BOOST_TEST(m0 == m1);
64-
BOOST_TEST(m0 != m2);
65+
BOOST_TEST(m0 == m1);
66+
BOOST_TEST(m0 != m2);
6567

66-
m2 = m1; // copy
67-
BOOST_TEST(m2 == m1);
68-
m2 = std::move(m1);
69-
BOOST_TEST(m2 == m0);
70-
BOOST_TEST(m1 != m0);
68+
m2 = m1; // copy
69+
BOOST_TEST(m2 == m1);
70+
m2 = std::move(m1);
71+
BOOST_TEST(m2 == m0);
72+
BOOST_TEST(m1 != m0);
7173

72-
BOOST_TEST(m0 == m2);
74+
BOOST_TEST(m0 == m2);
75+
}
76+
catch (std::exception const & ex)
77+
{
78+
std::clog << ex.what() << "\n";
79+
BOOST_TEST(false);
80+
}
7381

7482
if (!::boost::detail::test_errors())
7583
{

tests/cpp_tests/font_registration_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ int main(int argc, char** argv)
193193
}
194194
catch (std::exception const & ex)
195195
{
196-
std::clog << "C++ fonts registration problem: " << ex.what() << "\n";
196+
std::clog << ex.what() << "\n";
197197
BOOST_TEST(false);
198198
}
199199

tests/cpp_tests/geometry_converters_test.cpp

+40-31
Original file line numberDiff line numberDiff line change
@@ -143,43 +143,52 @@ int main(int argc, char** argv)
143143

144144
BOOST_TEST(set_working_dir(args));
145145

146-
// LineString/bbox clipping
146+
try
147147
{
148-
std::string wkt_in("LineString(0 0,200 200)");
149-
boost::optional<std::string> result = linestring_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
150-
BOOST_TEST(result);
151-
BOOST_TEST_EQ(*result,std::string("LineString(50 50,150 150)"));
152-
}
153-
// Polygon/bbox clipping
154-
#if 0
155-
// these tests will fail
156-
{
157-
std::string wkt_in("Polygon((50 50,150 50,150 150,50 150,50 50))");
158-
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
159-
BOOST_TEST(result);
160-
BOOST_TEST_EQ(*result,std::string("Polygon((50 50,150 50,150 150,50 150,50 50))"));
161-
}
148+
// LineString/bbox clipping
149+
{
150+
std::string wkt_in("LineString(0 0,200 200)");
151+
boost::optional<std::string> result = linestring_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
152+
BOOST_TEST(result);
153+
BOOST_TEST_EQ(*result,std::string("LineString(50 50,150 150)"));
154+
}
155+
// Polygon/bbox clipping
156+
#if 0
157+
// these tests will fail
158+
{
159+
std::string wkt_in("Polygon((50 50,150 50,150 150,50 150,50 50))");
160+
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
161+
BOOST_TEST(result);
162+
BOOST_TEST_EQ(*result,std::string("Polygon((50 50,150 50,150 150,50 150,50 50))"));
163+
}
162164

163-
{
164-
std::string wkt_in("Polygon((60 60,140 60,140 160,60 140,60 60))");
165-
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
166-
BOOST_TEST(result);
167-
BOOST_TEST_EQ(*result,std::string("Polygon((60 60,140 60,140 160,60 140,60 60))"));
168-
}
165+
{
166+
std::string wkt_in("Polygon((60 60,140 60,140 160,60 140,60 60))");
167+
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
168+
BOOST_TEST(result);
169+
BOOST_TEST_EQ(*result,std::string("Polygon((60 60,140 60,140 160,60 140,60 60))"));
170+
}
169171

170-
{
171-
std::string wkt_in("Polygon((0 0,10 0,10 10,0 10,0 0))");
172-
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
173-
BOOST_TEST(result);
174-
BOOST_TEST_EQ(*result, std::string("GeometryCollection EMPTY"));
172+
{
173+
std::string wkt_in("Polygon((0 0,10 0,10 10,0 10,0 0))");
174+
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
175+
BOOST_TEST(result);
176+
BOOST_TEST_EQ(*result, std::string("GeometryCollection EMPTY"));
177+
}
178+
{
179+
std::string wkt_in("Polygon((0 0,100 200,200 0,0 0 ))");
180+
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
181+
BOOST_TEST(result);
182+
BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))"));
183+
}
184+
#endif
175185
}
186+
catch (std::exception const & ex)
176187
{
177-
std::string wkt_in("Polygon((0 0,100 200,200 0,0 0 ))");
178-
boost::optional<std::string> result = polygon_bbox_clipping(mapnik::box2d<double>(50,50,150,150),wkt_in);
179-
BOOST_TEST(result);
180-
BOOST_TEST_EQ(*result,std::string("Polygon((50 50,50 100,75 150,125 150,150 100,150 50,50 50))"));
188+
std::clog << ex.what() << "\n";
189+
BOOST_TEST(false);
181190
}
182-
#endif
191+
183192

184193
if (!::boost::detail::test_errors())
185194
{

tests/cpp_tests/image_io_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ int main(int argc, char** argv)
110110
}
111111
catch (std::exception const & ex)
112112
{
113-
std::clog << "C++ image i/o problem: " << ex.what() << "\n";
113+
std::clog << ex.what() << "\n";
114114
BOOST_TEST(false);
115115
}
116116

tests/cpp_tests/image_painted_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int main(int argc, char** argv)
6868
}
6969
catch (std::exception const & ex)
7070
{
71-
std::clog << "C++ image painted problem: " << ex.what() << std::endl;
71+
std::clog << ex.what() << std::endl;
7272
BOOST_TEST(false);
7373
}
7474

0 commit comments

Comments
 (0)