]> git.saurik.com Git - wxWidgets.git/blob - tests/graphics/colour.cpp
Fix for wxChm
[wxWidgets.git] / tests / graphics / colour.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/graphics/colour.cpp
3 // Purpose: wxColour unit test
4 // Author: Vadim Zeitlin
5 // Created: 2009-09-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 ///////////////////////////////////////////////////////////////////////////////
9
10 // ----------------------------------------------------------------------------
11 // headers
12 // ----------------------------------------------------------------------------
13
14 #include "testprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #include "wx/colour.h"
21 #include "asserthelper.h"
22
23 // ----------------------------------------------------------------------------
24 // test class
25 // ----------------------------------------------------------------------------
26
27 class ColourTestCase : public CppUnit::TestCase
28 {
29 public:
30 ColourTestCase() { }
31
32 private:
33 CPPUNIT_TEST_SUITE( ColourTestCase );
34 CPPUNIT_TEST( GetSetRGB );
35 CPPUNIT_TEST_SUITE_END();
36
37 void GetSetRGB();
38
39 DECLARE_NO_COPY_CLASS(ColourTestCase)
40 };
41
42 // register in the unnamed registry so that these tests are run by default
43 CPPUNIT_TEST_SUITE_REGISTRATION( ColourTestCase );
44
45 // also include in it's own registry so that these tests can be run alone
46 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ColourTestCase, "ColourTestCase" );
47
48 void ColourTestCase::GetSetRGB()
49 {
50 wxColour c;
51 c.SetRGB(0x123456);
52
53 CPPUNIT_ASSERT_EQUAL( 0x56, (int)c.Red() );
54 CPPUNIT_ASSERT_EQUAL( 0x34, (int)c.Green() );
55 CPPUNIT_ASSERT_EQUAL( 0x12, (int)c.Blue() );
56 CPPUNIT_ASSERT_EQUAL( wxALPHA_OPAQUE, c.Alpha() );
57
58 CPPUNIT_ASSERT_EQUAL( wxColour(0x123456), c );
59 CPPUNIT_ASSERT_EQUAL( 0x123456, c.GetRGB() );
60
61 c.SetRGBA(0xaabbccdd);
62
63 CPPUNIT_ASSERT_EQUAL( 0xdd, (int)c.Red() );
64 CPPUNIT_ASSERT_EQUAL( 0xcc, (int)c.Green() );
65 CPPUNIT_ASSERT_EQUAL( 0xbb, (int)c.Blue() );
66 CPPUNIT_ASSERT_EQUAL( 0xaa, (int)c.Alpha() );
67
68 // FIXME: at least under wxGTK wxColour ctor doesn't take alpha channel
69 // into account: bug or feature?
70 //CPPUNIT_ASSERT_EQUAL( wxColour(0xaabbccdd), c );
71 CPPUNIT_ASSERT_EQUAL( 0xbbccdd, c.GetRGB() );
72 CPPUNIT_ASSERT_EQUAL( 0xaabbccdd, c.GetRGBA() );
73 }
74