]>
Commit | Line | Data |
---|---|---|
b0edecea VZ |
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" | |
232fdc63 | 21 | #include "asserthelper.h" |
b0edecea VZ |
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() ); | |
ac98aec5 VZ |
66 | |
67 | // wxX11 doesn't support alpha at all currently. | |
68 | #ifndef __WXX11__ | |
b0edecea | 69 | CPPUNIT_ASSERT_EQUAL( 0xaa, (int)c.Alpha() ); |
ac98aec5 | 70 | #endif // __WXX11__ |
b0edecea VZ |
71 | |
72 | // FIXME: at least under wxGTK wxColour ctor doesn't take alpha channel | |
73 | // into account: bug or feature? | |
74 | //CPPUNIT_ASSERT_EQUAL( wxColour(0xaabbccdd), c ); | |
75 | CPPUNIT_ASSERT_EQUAL( 0xbbccdd, c.GetRGB() ); | |
ac98aec5 | 76 | #ifndef __WXX11__ |
b0edecea | 77 | CPPUNIT_ASSERT_EQUAL( 0xaabbccdd, c.GetRGBA() ); |
ac98aec5 | 78 | #endif // __WXX11__ |
b0edecea VZ |
79 | } |
80 |