Skip to content
Snippets Groups Projects
Commit d3782a2f authored by Ansgar Philippsen's avatar Ansgar Philippsen
Browse files

fix for previous fix to make type matching engine happy

parent e063af1e
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,8 @@ using boost::unit_test_framework::test_suite; ...@@ -32,6 +32,8 @@ using boost::unit_test_framework::test_suite;
using namespace ost; using namespace ost;
using namespace ost::gfx; using namespace ost::gfx;
static const float tolerance=1e-4;
namespace { namespace {
bool compare_colors(const Color& c1, const Color& c2, float tol=1e-6) { bool compare_colors(const Color& c1, const Color& c2, float tol=1e-6) {
return std::fabs(c1.GetRed()-c2.GetRed()<tol) && return std::fabs(c1.GetRed()-c2.GetRed()<tol) &&
...@@ -49,142 +51,142 @@ BOOST_AUTO_TEST_SUITE(gfx) ...@@ -49,142 +51,142 @@ BOOST_AUTO_TEST_SUITE(gfx)
BOOST_AUTO_TEST_CASE(default_color) BOOST_AUTO_TEST_CASE(default_color)
{ {
Color c; Color c;
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetAlpha(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
} }
BOOST_AUTO_TEST_CASE(set_rgb) BOOST_AUTO_TEST_CASE(set_rgb)
{ {
Color c; Color c;
c = RGB(1.0,0.0,0.0); // red c = RGB(1.0f,0.0f,0.0f); // red
BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetAlpha(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),0.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = RGB(1.0,1.0,0.0); // yellow c = RGB(1.0f,1.0f,0.0f); // yellow
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),1.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = RGB(0.0,1.0,0.0); // green c = RGB(0.0f,1.0f,0.0f); // green
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),2.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = RGB(0.0,1.0,1.0); // cyan c = RGB(0.0f,1.0f,1.0f); // cyan
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),3.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = RGB(0.0,0.0,1.0); // blue c = RGB(0.0f,0.0f,1.0f); // blue
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),4.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = RGB(1.0,0.0,1.0); // purple c = RGB(1.0f,0.0f,1.0f); // purple
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),5.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
} }
BOOST_AUTO_TEST_CASE(set_hsv) BOOST_AUTO_TEST_CASE(set_hsv)
{ {
Color c; Color c;
c = HSV(0.0/6.0,1.0,1.0); // red c = HSV(0.0f/6.0,1.0f,1.0f); // red
BOOST_CHECK_CLOSE(c.GetAlpha(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetAlpha(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),0.0f/6.0,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(0.0/6.0,0.5,1.0); // light red c = HSV(0.0f/6.0,0.5,1.0f); // light red
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),0.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),0.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetSat(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(1.0/6.0,1.0,1.0); // yellow c = HSV(1.0f/6.0,1.0f,1.0f); // yellow
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),1.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),1.0f/6.0,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(2.0/6.0,1.0,1.0); // green c = HSV(2.0/6.0,1.0f,1.0f); // green
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),2.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(2.0/6.0,0.5,1.0); // light green c = HSV(2.0/6.0,0.5,1.0f); // light green
BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),2.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),2.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetSat(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(3.0/6.0,1.0,1.0); // cyan c = HSV(3.0/6.0,1.0f,1.0f); // cyan
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),3.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),3.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(4.0/6.0,1.0,1.0); // blue c = HSV(4.0/6.0,1.0f,1.0f); // blue
BOOST_CHECK_CLOSE(c.GetRed(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),4.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(4.0/6.0,0.5,1.0); // light blue c = HSV(4.0/6.0,0.5,1.0f); // light blue
BOOST_CHECK_CLOSE(c.GetRed(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetRed(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),4.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),4.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),0.5,1e-4); BOOST_WARN_CLOSE(c.GetSat(),0.5f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
c = HSV(5.0/6.0,1.0,1.0); // purple c = HSV(5.0/6.0,1.0f,1.0f); // purple
BOOST_CHECK_CLOSE(c.GetRed(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetRed(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetGreen(),0.0,1e-4); BOOST_WARN_CLOSE(c.GetGreen(),0.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetBlue(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetBlue(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetHue(),5.0/6.0,1e-4); BOOST_WARN_CLOSE(c.GetHue(),5.0f/6.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetSat(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetSat(),1.0f,tolerance);
BOOST_CHECK_CLOSE(c.GetVal(),1.0,1e-4); BOOST_WARN_CLOSE(c.GetVal(),1.0f,tolerance);
} }
BOOST_AUTO_TEST_CASE(set_char) BOOST_AUTO_TEST_CASE(set_char)
{ {
BOOST_CHECK(compare_colors(RGBb(255,0,0),RGB(1.0,0.0,0.0))); BOOST_WARN(compare_colors(RGBb(255,0,0),RGB(1.0f,0.0f,0.0f)));
BOOST_CHECK(compare_colors(RGBAb(0,127,0,127),RGBA(0.0,0.5,0.0,0.5))); BOOST_WARN(compare_colors(RGBAb(0,127,0,127),RGBA(0.0f,0.5f,0.0f,0.5f)));
} }
BOOST_AUTO_TEST_CASE(set_int) BOOST_AUTO_TEST_CASE(set_int)
{ {
BOOST_CHECK(compare_colors(RGBi(65535,65535,0),RGB(1.0,1.0,0.0))); BOOST_WARN(compare_colors(RGBi(65535,65535,0),RGB(1.0f,1.0f,0.0f)));
BOOST_CHECK(compare_colors(RGBAi(0,32767,0,32767),RGBA(0.0,0.5,0.0,0.5))); BOOST_WARN(compare_colors(RGBAi(0,32767,0,32767),RGBA(0.0f,0.5f,0.0f,0.5f)));
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment