X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc6ceca789f584cf3fc3fc17f6da4b7493ca69bd..fd5907ffd9b0785bb6eb6f2546101623b23827c5:/tests/weakref/weakref.cpp diff --git a/tests/weakref/weakref.cpp b/tests/weakref/weakref.cpp index f2a9c79d04..163a16f401 100644 --- a/tests/weakref/weakref.cpp +++ b/tests/weakref/weakref.cpp @@ -76,9 +76,25 @@ CPPUNIT_TEST_SUITE_REGISTRATION( WeakRefTestCase ); // also include in it's own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( WeakRefTestCase, "WeakRefTestCase" ); + +// Test weak reference to an incomplete type, this should work if the type is +// fully defined before it is used (but currently doesn't, see #11916) +struct ForwardDeclaredClass; +wxWeakRef g_incompleteWeakRef; + +struct ForwardDeclaredClass : wxEvtHandler { }; + void WeakRefTestCase::DeclareTest() { { + // Not initializing or initializing with NULL should work too + // + // FIXME-VC6: but it doesn't with VC6, see comment in wx/weakref.h +#ifndef __VISUALC6__ + wxWeakRef wroDef; + wxWeakRef wro0(NULL); +#endif // __VISUALC6__ + wxObject o; // Should not work wxEvtHandler eh; wxObjectTrackable ot; @@ -102,6 +118,17 @@ void WeakRefTestCase::DeclareTest() CPPUNIT_ASSERT( wreh.get() == &eh ); CPPUNIT_ASSERT( wrot.get() == &ot ); } + + // This test requires a working dynamic_cast<> +#ifndef wxNO_RTTI + { + ForwardDeclaredClass fdc; + g_incompleteWeakRef = &fdc; + CPPUNIT_ASSERT( g_incompleteWeakRef ); + } + + CPPUNIT_ASSERT( !g_incompleteWeakRef ); +#endif // RTTI enabled } void WeakRefTestCase::AssignTest() @@ -123,6 +150,23 @@ void WeakRefTestCase::AssignTest() // Should be reset now CPPUNIT_ASSERT( !wro1 ); CPPUNIT_ASSERT( !wro2 ); + + // Explicitly resetting should work too + // + // FIXME-VC6: as above, it doesn't work with VC6, see wx/weakref.h +#ifndef __VISUALC6__ + wxEvtHandler eh; + wxObjectTrackable ot; + + wro1 = &eh; + wro2 = &ot; + + wro1 = NULL; + wro2 = NULL; + + CPPUNIT_ASSERT( !wro1 ); + CPPUNIT_ASSERT( !wro2 ); +#endif // __VISUALC6__ } void WeakRefTestCase::AssignWeakRefTest() @@ -226,15 +270,6 @@ void WeakRefTestCase::DeleteTest() wxEvtHandlerRef wre(peh); wxWeakRef wro(peh); - // test size of references (see that it has selected right base class) -#ifdef HAVE_PARTIAL_SPECIALIZATION - CPPUNIT_ASSERT_EQUAL( sizeof(void*)*3, sizeof(wre) ); - CPPUNIT_ASSERT_EQUAL( sizeof(void*)*4, sizeof(wro) ); -#else - CPPUNIT_ASSERT_EQUAL( sizeof(void*)*3, sizeof(wre) ); - CPPUNIT_ASSERT_EQUAL( sizeof(void*)*3, sizeof(wro) ); -#endif - CPPUNIT_ASSERT( wre.get() == peh ); CPPUNIT_ASSERT( wro.get() == peh );