]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/graphics/colour.cpp
proper default for iphone
[wxWidgets.git] / tests / graphics / colour.cpp
index dfec5fea61e9f4cbb79bf1af41688d384edb2453..40b92bbd63a3adfd772960dd73facc7f37e1fa0a 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     wxColour unit test
 // Author:      Vadim Zeitlin
 // Created:     2009-09-19
-// RCS-ID:      $Id$
 // Copyright:   (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "wx/colour.h"
 #include "asserthelper.h"
 
+// ----------------------------------------------------------------------------
+// helpers
+// ----------------------------------------------------------------------------
+
+// Check the colour components, with and without alpha.
+//
+// NB: These are macros and not functions to have correct line numbers in case
+//     of failure.
+#define ASSERT_EQUAL_RGB(c, r, g, b) \
+    CPPUNIT_ASSERT_EQUAL( r, (int)c.Red() ); \
+    CPPUNIT_ASSERT_EQUAL( g, (int)c.Green() ); \
+    CPPUNIT_ASSERT_EQUAL( b, (int)c.Blue() )
+
+#define ASSERT_EQUAL_RGBA(c, r, g, b, a) \
+    ASSERT_EQUAL_RGB(c, r, g, b); \
+    CPPUNIT_ASSERT_EQUAL( a, (int)c.Alpha() )
+
 // ----------------------------------------------------------------------------
 // test class
 // ----------------------------------------------------------------------------
@@ -32,9 +48,11 @@ public:
 private:
     CPPUNIT_TEST_SUITE( ColourTestCase );
         CPPUNIT_TEST( GetSetRGB );
+        CPPUNIT_TEST( FromString );
     CPPUNIT_TEST_SUITE_END();
 
     void GetSetRGB();
+    void FromString();
 
     DECLARE_NO_COPY_CLASS(ColourTestCase)
 };
@@ -42,7 +60,7 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( ColourTestCase );
 
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ColourTestCase, "ColourTestCase" );
 
 void ColourTestCase::GetSetRGB()
@@ -78,3 +96,19 @@ void ColourTestCase::GetSetRGB()
 #endif // __WXX11__
 }
 
+void ColourTestCase::FromString()
+{
+    ASSERT_EQUAL_RGB( wxColour("rgb(11, 22, 33)"), 11, 22, 33 );
+    ASSERT_EQUAL_RGBA( wxColour("rgba(11, 22, 33, 0.5)"), 11, 22, 33, 128 );
+    ASSERT_EQUAL_RGBA( wxColour("rgba( 11, 22, 33, 0.5 )"), 11, 22, 33, 128 );
+
+    ASSERT_EQUAL_RGB( wxColour("#aabbcc"), 0xaa, 0xbb, 0xcc );
+
+    ASSERT_EQUAL_RGB( wxColour("red"), 0xff, 0, 0 );
+
+    wxColour col;
+    CPPUNIT_ASSERT( !wxFromString("rgb(1, 2)", &col) );
+    CPPUNIT_ASSERT( !wxFromString("rgba(1, 2, 3.456)", &col) );
+    CPPUNIT_ASSERT( !wxFromString("rgba(1, 2, 3.456, foo)", &col) );
+}
+