]>
git.saurik.com Git - wxWidgets.git/blob - tests/graphics/colour.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/colour.cpp
3 // Purpose: wxColour unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
20 #include "wx/colour.h"
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
28 // by default colour components values are output incorrectly because they
29 // are unsigned chars, define a small helper struct which formats them in
33 ColourChannel(unsigned char value
) : m_value(value
) { }
35 unsigned char m_value
;
38 std::ostream
& operator<<(std::ostream
& os
, const ColourChannel
& cc
)
42 os
<< static_cast<int>(cc
.m_value
);
45 } // anonymous namespace
47 // this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxColour objects
48 std::ostream
& operator<<(std::ostream
& os
, const wxColour
& c
)
50 os
<< std::hex
<< std::noshowbase
52 << ColourChannel(c
.Red()) << ", "
53 << ColourChannel(c
.Green()) << ", "
54 << ColourChannel(c
.Blue());
56 if ( const unsigned char a
= c
.Alpha() )
58 os
<< ", " << ColourChannel(a
);
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 class ColourTestCase
: public CppUnit::TestCase
76 CPPUNIT_TEST_SUITE( ColourTestCase
);
77 CPPUNIT_TEST( GetSetRGB
);
78 CPPUNIT_TEST_SUITE_END();
82 DECLARE_NO_COPY_CLASS(ColourTestCase
)
85 // register in the unnamed registry so that these tests are run by default
86 CPPUNIT_TEST_SUITE_REGISTRATION( ColourTestCase
);
88 // also include in it's own registry so that these tests can be run alone
89 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ColourTestCase
, "ColourTestCase" );
91 void ColourTestCase::GetSetRGB()
96 CPPUNIT_ASSERT_EQUAL( 0x56, (int)c
.Red() );
97 CPPUNIT_ASSERT_EQUAL( 0x34, (int)c
.Green() );
98 CPPUNIT_ASSERT_EQUAL( 0x12, (int)c
.Blue() );
99 CPPUNIT_ASSERT_EQUAL( wxALPHA_OPAQUE
, c
.Alpha() );
101 CPPUNIT_ASSERT_EQUAL( wxColour(0x123456), c
);
102 CPPUNIT_ASSERT_EQUAL( 0x123456, c
.GetRGB() );
104 c
.SetRGBA(0xaabbccdd);
106 CPPUNIT_ASSERT_EQUAL( 0xdd, (int)c
.Red() );
107 CPPUNIT_ASSERT_EQUAL( 0xcc, (int)c
.Green() );
108 CPPUNIT_ASSERT_EQUAL( 0xbb, (int)c
.Blue() );
109 CPPUNIT_ASSERT_EQUAL( 0xaa, (int)c
.Alpha() );
111 // FIXME: at least under wxGTK wxColour ctor doesn't take alpha channel
112 // into account: bug or feature?
113 //CPPUNIT_ASSERT_EQUAL( wxColour(0xaabbccdd), c );
114 CPPUNIT_ASSERT_EQUAL( 0xbbccdd, c
.GetRGB() );
115 CPPUNIT_ASSERT_EQUAL( 0xaabbccdd, c
.GetRGBA() );