]> git.saurik.com Git - wxWidgets.git/blame - tests/graphics/colour.cpp
Removed redundant DoEnable
[wxWidgets.git] / tests / graphics / colour.cpp
CommitLineData
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 22
f0e52da8
VZ
23// ----------------------------------------------------------------------------
24// helpers
25// ----------------------------------------------------------------------------
26
27// Check the colour components, with and without alpha.
28//
29// NB: These are macros and not functions to have correct line numbers in case
30// of failure.
31#define ASSERT_EQUAL_RGB(c, r, g, b) \
32 CPPUNIT_ASSERT_EQUAL( r, (int)c.Red() ); \
33 CPPUNIT_ASSERT_EQUAL( g, (int)c.Green() ); \
34 CPPUNIT_ASSERT_EQUAL( b, (int)c.Blue() )
35
36#define ASSERT_EQUAL_RGBA(c, r, g, b, a) \
37 ASSERT_EQUAL_RGB(c, r, g, b); \
38 CPPUNIT_ASSERT_EQUAL( a, (int)c.Alpha() )
39
b0edecea
VZ
40// ----------------------------------------------------------------------------
41// test class
42// ----------------------------------------------------------------------------
43
44class ColourTestCase : public CppUnit::TestCase
45{
46public:
47 ColourTestCase() { }
48
49private:
50 CPPUNIT_TEST_SUITE( ColourTestCase );
51 CPPUNIT_TEST( GetSetRGB );
f0e52da8 52 CPPUNIT_TEST( FromString );
b0edecea
VZ
53 CPPUNIT_TEST_SUITE_END();
54
55 void GetSetRGB();
f0e52da8 56 void FromString();
b0edecea
VZ
57
58 DECLARE_NO_COPY_CLASS(ColourTestCase)
59};
60
61// register in the unnamed registry so that these tests are run by default
62CPPUNIT_TEST_SUITE_REGISTRATION( ColourTestCase );
63
e3778b4d 64// also include in its own registry so that these tests can be run alone
b0edecea
VZ
65CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ColourTestCase, "ColourTestCase" );
66
67void ColourTestCase::GetSetRGB()
68{
69 wxColour c;
70 c.SetRGB(0x123456);
71
72 CPPUNIT_ASSERT_EQUAL( 0x56, (int)c.Red() );
73 CPPUNIT_ASSERT_EQUAL( 0x34, (int)c.Green() );
74 CPPUNIT_ASSERT_EQUAL( 0x12, (int)c.Blue() );
75 CPPUNIT_ASSERT_EQUAL( wxALPHA_OPAQUE, c.Alpha() );
76
77 CPPUNIT_ASSERT_EQUAL( wxColour(0x123456), c );
78 CPPUNIT_ASSERT_EQUAL( 0x123456, c.GetRGB() );
79
80 c.SetRGBA(0xaabbccdd);
81
82 CPPUNIT_ASSERT_EQUAL( 0xdd, (int)c.Red() );
83 CPPUNIT_ASSERT_EQUAL( 0xcc, (int)c.Green() );
84 CPPUNIT_ASSERT_EQUAL( 0xbb, (int)c.Blue() );
ac98aec5
VZ
85
86 // wxX11 doesn't support alpha at all currently.
87#ifndef __WXX11__
b0edecea 88 CPPUNIT_ASSERT_EQUAL( 0xaa, (int)c.Alpha() );
ac98aec5 89#endif // __WXX11__
b0edecea
VZ
90
91 // FIXME: at least under wxGTK wxColour ctor doesn't take alpha channel
92 // into account: bug or feature?
93 //CPPUNIT_ASSERT_EQUAL( wxColour(0xaabbccdd), c );
94 CPPUNIT_ASSERT_EQUAL( 0xbbccdd, c.GetRGB() );
ac98aec5 95#ifndef __WXX11__
b0edecea 96 CPPUNIT_ASSERT_EQUAL( 0xaabbccdd, c.GetRGBA() );
ac98aec5 97#endif // __WXX11__
b0edecea
VZ
98}
99
f0e52da8
VZ
100void ColourTestCase::FromString()
101{
102 ASSERT_EQUAL_RGB( wxColour("rgb(11, 22, 33)"), 11, 22, 33 );
103 ASSERT_EQUAL_RGBA( wxColour("rgba(11, 22, 33, 0.5)"), 11, 22, 33, 128 );
104 ASSERT_EQUAL_RGBA( wxColour("rgba( 11, 22, 33, 0.5 )"), 11, 22, 33, 128 );
105
106 ASSERT_EQUAL_RGB( wxColour("#aabbcc"), 0xaa, 0xbb, 0xcc );
107
108 ASSERT_EQUAL_RGB( wxColour("red"), 0xff, 0, 0 );
109
110 wxColour col;
111 CPPUNIT_ASSERT( !wxFromString("rgb(1, 2)", &col) );
112 CPPUNIT_ASSERT( !wxFromString("rgba(1, 2, 3.456)", &col) );
113 CPPUNIT_ASSERT( !wxFromString("rgba(1, 2, 3.456, foo)", &col) );
114}
115