24 #include <boost/test/unit_test.hpp> 32 #ifdef WX_COMPATIBILITY 33 #include <wx/colour.h> 37 using namespace KIGFX;
43 BOOST_AUTO_TEST_SUITE( Color4D )
51 const auto c =
COLOR4D{ 0.4, 0.5, 0.6, 0.7 };
53 BOOST_CHECK_EQUAL( c.r, 0.4 );
54 BOOST_CHECK_EQUAL( c.g, 0.5 );
55 BOOST_CHECK_EQUAL( c.b, 0.6 );
56 BOOST_CHECK_EQUAL( c.a, 0.7 );
58 const auto copied = c;
61 BOOST_CHECK_EQUAL( c, copied );
63 const auto c2 =
COLOR4D{ 0.1, 0.2, 0.3, 0.4 };
66 BOOST_CHECK_NE( c, c2 );
88 static const std::vector<COLOR_SCALAR_CASE> cases = {
89 { { 0.0, 0.25, 1.0, 1.0 }, 0.0, { 1.0, 0.75, 0.0, 1.0 } },
92 for(
const auto& c : cases )
96 const auto inverted = col.Inverted();
97 BOOST_CHECK_EQUAL( inverted, c.expected );
101 BOOST_CHECK_EQUAL( col, c.expected );
111 static const std::vector<COLOR_SCALAR_CASE> cases = {
112 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.5, 0.5, 0.5, 1.0 } },
113 { { 0.0, 0.5, 1.0, 1.0 }, 0.5, { 0.5, 0.75, 1.0, 1.0 } },
116 for(
const auto& c : cases )
120 const auto brightened = col.Brightened( c.factor );
121 BOOST_CHECK_EQUAL( brightened, c.expected );
124 col.Brighten( c.factor );
125 BOOST_CHECK_EQUAL( col, c.expected );
135 static const std::vector<COLOR_SCALAR_CASE> cases = {
136 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.0, 0.0, 0.0, 1.0 } },
137 { { 1.0, 1.0, 1.0, 1.0 }, 0.5, { 0.5, 0.5, 0.5, 1.0 } },
140 for(
const auto& c : cases )
144 const auto brightened = col.Darkened( c.factor );
145 BOOST_CHECK_EQUAL( brightened, c.expected );
148 col.Darken( c.factor );
149 BOOST_CHECK_EQUAL( col, c.expected );
159 static const std::vector<COLOR_SCALAR_CASE> cases = {
160 { { 0.0, 0.0, 0.0, 1.0 }, 0.5, { 0.0, 0.0, 0.0, 0.5 } },
161 { { 0.0, 0.5, 1.0, 1.0 }, 0.5, { 0.0, 0.5, 1.0, 0.5 } },
164 for(
const auto& c : cases )
168 const auto with_alpha = col.WithAlpha( c.factor );
169 BOOST_CHECK_EQUAL( with_alpha, c.expected );
193 static const std::vector<FROM_HSV_TO_HEX_CASE> cases = {
194 { 10, 0.71, 0.66, 168, 69, 49 },
195 { 15, 0.96, 0.34, 87, 24, 3 },
196 { 120, 0.50, 0.50, 64, 128, 64 },
197 { 190, 0.32, 0.97, 168, 234, 247 },
198 { 240, 0.15, 0.75, 163, 163, 191 },
199 { 240, 0.90, 0.75, 19, 19, 191 },
200 { 310, 0.71, 0.66, 168, 49, 148 },
201 { 331, 0.15, 0.85, 217, 184, 200 },
204 for(
const auto& c : cases )
208 double new_h, new_s, new_v;
209 col.ToHSV( new_h, new_s, new_v );
210 const unsigned char alpha = 0xFF;
213 BOOST_CHECK_CLOSE( c.h, new_h, 0.0001 );
214 BOOST_CHECK_CLOSE( c.s, new_s, 0.0001 );
215 BOOST_CHECK_CLOSE( c.v, new_v, 0.0001 );
235 static const std::vector<FROM_HSL_TO_HEX_CASE> cases = {
236 { 10, 0.71, 0.66, 230, 127, 107 },
237 { 15, 0.96, 0.34, 170, 45, 3 },
238 { 120, 0.5, 0.5, 64, 191, 64 },
239 { 190, 0.32, 0.97, 245, 249, 250 },
240 { 240, 0.15, 0.75, 182, 182, 201 },
241 { 240, 0.90, 0.75, 134, 134, 249 },
242 { 310, 0.71, 0.66, 230, 107, 209 },
243 { 331, 0.15, 0.85, 222, 211, 217 },
246 for(
const auto& c : cases )
250 double new_h, new_s, new_l;
251 col.ToHSL( new_h, new_s, new_l );
252 const unsigned char alpha = 0xFF;
255 BOOST_CHECK_CLOSE( c.h, new_h, 0.0001 );
256 BOOST_CHECK_CLOSE( c.s, new_s, 0.0001 );
257 BOOST_CHECK_CLOSE( c.l, new_l, 0.0001 );
262 #ifdef WX_COMPATIBILITY 271 static std::vector<WX_CONV_CASE> wx_conv_cases = {
272 { { 0x00, 0x00, 0x00, 0x00 }, { 0.0, 0.0, 0.0, 0.0 } },
273 { { 0x66, 0x80, 0x99, 0xB3 }, { 0.4, 0.5, 0.6, 0.7 } },
274 { { 0xFF, 0xFF, 0xFF, 0xFF }, { 1.0, 1.0, 1.0, 1.0 } },
275 { { 0xFF, 0x00, 0x00, 0xFF }, { 0.999, 0.001, 0.0, 1.0 } },
284 for(
const auto& c : wx_conv_cases )
286 wxColour wx_col = c.c4d.ToColour();
289 BOOST_CHECK_EQUAL( wx_col.Red(), c.wx.Red() );
290 BOOST_CHECK_EQUAL( wx_col.Green(), c.wx.Green() );
291 BOOST_CHECK_EQUAL( wx_col.Blue(), c.wx.Blue() );
292 BOOST_CHECK_EQUAL( wx_col.Alpha(), c.wx.Alpha() );
302 const double tol = 0.5 / 255.0;
304 for(
const auto& c : wx_conv_cases )
306 const auto col =
COLOR4D{ c.wx };
312 #endif // WX_COMPATIBILITY 314 BOOST_AUTO_TEST_SUITE_END()
The Cairo implementation of the graphics abstraction layer.
Test case data for a test that takes a colour and a scalar factor and returns a result.
bool IsColorNearHex(const KIGFX::COLOR4D &aCol, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Checks if a COLOR4D is close enough to a given RGB char value.
void FromHSV(double aInH, double aInS, double aInV)
Changes currently used color to the one given by hue, saturation and value parameters.
BOOST_AUTO_TEST_CASE(BasicOps)
Declares a struct as the Boost test fixture.
bool IsColorNear(const KIGFX::COLOR4D &aCol, const KIGFX::COLOR4D aOther, double aTol)
Checks if a COLOR4D is close enough to another.
Test utilities for COLOUR4D objects.
void FromHSL(double aInHue, double aInSaturation, double aInLightness)
Change currently used color to the one given by hue, saturation and lightness parameters.
A color representation with 4 components: red, green, blue, alpha.