]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/misc/metatest.cpp
XRC: make wxSplitterWindow's sashpos and minpanesize dimensions.
[wxWidgets.git] / tests / misc / metatest.cpp
index 1fcefd245cd0f9c8d3a376a75a4e67ca737cf8dd..59e323cd9ac4a08b0a49ccd210f6814493e3faba 100644 (file)
@@ -2,7 +2,6 @@
 // Name:        tests/misc/metatest.cpp
 // Purpose:     Test template meta-programming constructs
 // Author:      Jaakko Salli
-// RCS-ID:      $Id$
 // Copyright:   (c) the wxWidgets team
 // Licence:     wxWindows licence
 ///////////////////////////////////////////////////////////////////////////////
 #endif
 
 #include "wx/object.h"
+#include "wx/utils.h"
 #include "wx/meta/pod.h"
 #include "wx/meta/movable.h"
 
+#ifndef wxNO_RTTI
+#include <typeinfo>
+#endif
+
 // ----------------------------------------------------------------------------
 // test class
 // ----------------------------------------------------------------------------
@@ -30,10 +34,14 @@ private:
     CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
         CPPUNIT_TEST( IsPod );
         CPPUNIT_TEST( IsMovable );
+        CPPUNIT_TEST( ImplicitConversion );
+        CPPUNIT_TEST( MinMax );
     CPPUNIT_TEST_SUITE_END();
 
     void IsPod();
     void IsMovable();
+    void ImplicitConversion();
+    void MinMax();
 
     DECLARE_NO_COPY_CLASS(MetaProgrammingTestCase)
 };
@@ -41,7 +49,7 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
 
-// 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( MetaProgrammingTestCase,
                                        "MetaProgrammingTestCase" );
 
@@ -67,3 +75,30 @@ void MetaProgrammingTestCase::IsMovable()
 #endif
     CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
 }
+
+void MetaProgrammingTestCase::ImplicitConversion()
+{
+#ifndef wxNO_RTTI
+    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
+    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
+#ifdef wxLongLong_t
+    CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
+#endif
+#endif // !wxNO_RTTI
+}
+
+void MetaProgrammingTestCase::MinMax()
+{
+    // test that wxMax(1.1,1) returns float, not long int
+    float f = wxMax(1.1f, 1l);
+    CPPUNIT_ASSERT_EQUAL( 1.1f, f);
+
+    // test that comparing signed and unsigned correctly returns unsigned: this
+    // may seem counterintuitive in this case but this is consistent with the
+    // standard C conversions
+    CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );
+
+    CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
+    CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
+    CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
+}