From 3a88bb5f3215976891e259babc7760a112274b7d Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Mon, 18 Dec 2006 13:28:29 +0100 Subject: [PATCH] smart pointer tests. no bugs for now --- src/core/ptr.cc | 117 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/src/core/ptr.cc b/src/core/ptr.cc index 1c2b240b0..97e26f232 100644 --- a/src/core/ptr.cc +++ b/src/core/ptr.cc @@ -51,7 +51,8 @@ public: virtual bool RunTests (void); private: void DestroyNotify (void); - bool m_destroyed; + Ptr CallTest (Ptr p); + uint32_t m_nDestroyed; }; PtrTest::PtrTest () @@ -64,9 +65,13 @@ PtrTest::~PtrTest () void PtrTest::DestroyNotify (void) { - m_destroyed = true; + m_nDestroyed++; +} +Ptr +PtrTest::CallTest (Ptr p) +{ + return p; } - bool PtrTest::RunTests (void) @@ -74,20 +79,118 @@ PtrTest::RunTests (void) bool ok = true; Callback cb = MakeCallback (&PtrTest::DestroyNotify, this); - m_destroyed = false; + m_nDestroyed = false; { Ptr p = new NoCount (cb); } - if (!m_destroyed) + if (m_nDestroyed != 1) { ok = false; } - m_destroyed = false; + + m_nDestroyed = 0; { Ptr p; p = new NoCount (cb); } - if (!m_destroyed) + if (m_nDestroyed != 1) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + p1 = new NoCount (cb); + Ptr p2 = p1; + } + if (m_nDestroyed != 1) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + p1 = new NoCount (cb); + Ptr p2; + p2 = p1; + } + if (m_nDestroyed != 1) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + p1 = new NoCount (cb); + Ptr p2 = new NoCount (cb); + p2 = p1; + } + if (m_nDestroyed != 2) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + p1 = new NoCount (cb); + Ptr p2; + p2 = new NoCount (cb); + p2 = p1; + } + if (m_nDestroyed != 2) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + p1 = new NoCount (cb); + p1 = new NoCount (cb); + } + if (m_nDestroyed != 2) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + { + Ptr p2; + p1 = new NoCount (cb); + p2 = new NoCount (cb); + p2 = p1; + } + if (m_nDestroyed != 1) + { + ok = false; + } + } + if (m_nDestroyed != 2) + { + ok = false; + } + + m_nDestroyed = 0; + { + Ptr p1; + { + Ptr p2; + p1 = new NoCount (cb); + p2 = new NoCount (cb); + p2 = CallTest (p1); + } + if (m_nDestroyed != 1) + { + ok = false; + } + } + if (m_nDestroyed != 2) { ok = false; }