]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/weakref/weakref.cpp
applying editor part of patch, see #15003
[wxWidgets.git] / tests / weakref / weakref.cpp
index 2c0eea61be63b4f0199c6ebc4cbf21564a7d37c5..e0e6000038afd1d6ff4d02847be07e8894b06da3 100644 (file)
@@ -73,12 +73,28 @@ private:
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( WeakRefTestCase );
 
 // register in the unnamed registry so that these tests are run by default
 CPPUNIT_TEST_SUITE_REGISTRATION( WeakRefTestCase );
 
-// 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( WeakRefTestCase, "WeakRefTestCase" );
 
 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<ForwardDeclaredClass> g_incompleteWeakRef;
+
+struct ForwardDeclaredClass : wxEvtHandler { };
+
 void WeakRefTestCase::DeclareTest()
 {
     {
 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<wxEvtHandler> wroDef;
+        wxWeakRef<wxEvtHandler> wro0(NULL);
+#endif // __VISUALC6__
+
         wxObject o; // Should not work
         wxEvtHandler eh;
         wxObjectTrackable ot;
         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 );
     }
         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()
 }
 
 void WeakRefTestCase::AssignTest()
@@ -123,6 +150,23 @@ void WeakRefTestCase::AssignTest()
     // Should be reset now
     CPPUNIT_ASSERT( !wro1 );
     CPPUNIT_ASSERT( !wro2 );
     // 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()
 }
 
 void WeakRefTestCase::AssignWeakRefTest()