X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/109e2ca4349381ca7ed73f78795f1779c33143e5..fd5907ffd9b0785bb6eb6f2546101623b23827c5:/tests/misc/metatest.cpp diff --git a/tests/misc/metatest.cpp b/tests/misc/metatest.cpp index 1fcefd245c..9072c70334 100644 --- a/tests/misc/metatest.cpp +++ b/tests/misc/metatest.cpp @@ -14,9 +14,14 @@ #endif #include "wx/object.h" +#include "wx/utils.h" #include "wx/meta/pod.h" #include "wx/meta/movable.h" +#ifndef wxNO_RTTI +#include +#endif + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -30,10 +35,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) }; @@ -67,3 +76,30 @@ void MetaProgrammingTestCase::IsMovable() #endif CPPUNIT_ASSERT(!wxIsMovable::value); } + +void MetaProgrammingTestCase::ImplicitConversion() +{ +#ifndef wxNO_RTTI + CPPUNIT_ASSERT(typeid(wxImplicitConversionType::value) == typeid(int)); + CPPUNIT_ASSERT(typeid(wxImplicitConversionType::value) == typeid(unsigned)); +#ifdef wxLongLong_t + CPPUNIT_ASSERT(typeid(wxImplicitConversionType::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) ); +}