X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d517b60699db7507e9cb377a810b56f108cb7d88..17beda75ef9780ebef5044e41889a9b598dcf186:/tests/any/anytest.cpp diff --git a/tests/any/anytest.cpp b/tests/any/anytest.cpp index 0d856445a6..7c6fdaa131 100644 --- a/tests/any/anytest.cpp +++ b/tests/any/anytest.cpp @@ -18,6 +18,7 @@ #include "wx/any.h" #include "wx/datetime.h" #include "wx/object.h" +#include "wx/vector.h" #include @@ -39,6 +40,7 @@ private: CPPUNIT_TEST( Null ); CPPUNIT_TEST( wxVariantConversions ); CPPUNIT_TEST( CustomTemplateSpecialization ); + CPPUNIT_TEST( Misc ); CPPUNIT_TEST_SUITE_END(); void CheckType(); @@ -48,6 +50,7 @@ private: void Null(); void wxVariantConversions(); void CustomTemplateSpecialization(); + void Misc(); wxDateTime m_testDateTime; @@ -98,7 +101,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( wxAnyTestCase ); -// 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( wxAnyTestCase, "wxAnyTestCase" ); // Let's use a number with first digit after decimal dot less than 5, @@ -178,6 +181,10 @@ void wxAnyTestCase::CheckType() CPPUNIT_ASSERT(wxANY_CHECK_TYPE(m_anyWcharString2, const wchar_t*)); CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, wxString)); CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, const char*)); + + // HasSameType() + CPPUNIT_ASSERT( m_anyWcharString1.HasSameType(m_anyWcharString2) ); + CPPUNIT_ASSERT( !m_anyWcharString1.HasSameType(m_anyBool1) ); } void wxAnyTestCase::Equality() @@ -404,16 +411,42 @@ void wxAnyTestCase::GetAs() // // Test user data type for wxAnyValueTypeImpl specialization -// any hand-built wxVariantData +// any hand-built wxVariantData. Also for inplace allocation +// sanity checks. // +class MyClass; + +static wxVector gs_myClassInstances; + class MyClass { public: MyClass( int someValue = 32768 ) { + Init(); m_someValue = someValue; } + MyClass( const MyClass& other ) + { + Init(); + m_someValue = other.m_someValue; + } + virtual ~MyClass() + { + for ( size_t i=0; i(&any); + size_t anyEnd = anyBegin + sizeof(wxAny); + size_t pos = reinterpret_cast(gs_myClassInstances[1]); + CPPUNIT_ASSERT( pos >= anyBegin ); + CPPUNIT_ASSERT( pos < anyEnd ); + } + + wxAny any2 = any; + CPPUNIT_ASSERT( wxANY_AS(any2, MyClass).GetValue() == 15 ); + } + + // Make sure allocations and deallocations match + CPPUNIT_ASSERT_EQUAL(gs_myClassInstances.size(), 0); +} + #endif // wxUSE_ANY