1.1 --- a/src/core/ptr-test-suite.cc Thu Oct 01 13:41:02 2009 +0200
1.2 +++ b/src/core/ptr-test-suite.cc Thu Oct 01 13:41:21 2009 +0200
1.3 @@ -1,6 +1,6 @@
1.4 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1.5 /*
1.6 - * Copyright (c) 2009 University of Washington
1.7 + * Copyright (c) 2005,2006 INRIA
1.8 *
1.9 * This program is free software; you can redistribute it and/or modify
1.10 * it under the terms of the GNU General Public License version 2 as
1.11 @@ -14,75 +14,16 @@
1.12 * You should have received a copy of the GNU General Public License
1.13 * along with this program; if not, write to the Free Software
1.14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.15 + *
1.16 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
1.17 */
1.18
1.19 +#include "test.h"
1.20 #include "ptr.h"
1.21 -#include "test.h"
1.22
1.23 namespace ns3 {
1.24
1.25 -class PtrTestCase : public TestCase
1.26 -{
1.27 -public:
1.28 - PtrTestCase ();
1.29 - virtual ~PtrTestCase () {}
1.30 -
1.31 -private:
1.32 - virtual bool DoRun (void);
1.33 -};
1.34 -
1.35 -PtrTestCase::PtrTestCase (void)
1.36 - : TestCase ("Handy fake test to check error reporting")
1.37 -{
1.38 -}
1.39 -
1.40 -bool
1.41 -PtrTestCase::DoRun (void)
1.42 -{
1.43 - NS_TEST_ASSERT_MSG_EQ (true, false, "Expected false, got true first time");
1.44 - NS_TEST_ASSERT_MSG_EQ (true, false, "Expected false, got true second time");
1.45 - NS_TEST_ASSERT_MSG_EQ (true, false, "Expected false, got true third time");
1.46 -
1.47 - return GetErrorStatus ();
1.48 -}
1.49 -
1.50 -class PtrTestSuite : public TestSuite
1.51 -{
1.52 -public:
1.53 - PtrTestSuite ();
1.54 -};
1.55 -
1.56 -PtrTestSuite::PtrTestSuite ()
1.57 - : TestSuite ("ptr", UNIT)
1.58 -{
1.59 - AddTestCase (new PtrTestCase);
1.60 - AddTestCase (new PtrTestCase);
1.61 -}
1.62 -
1.63 -PtrTestSuite ptrTestSuite;
1.64 -
1.65 -
1.66 -
1.67 -
1.68 -#ifdef NOTDEF
1.69 -class NoCount;
1.70 -
1.71 -template <typename T>
1.72 -void Foo (void) {}
1.73 -
1.74 -class PtrTest : Test
1.75 -{
1.76 -public:
1.77 - PtrTest ();
1.78 - virtual ~PtrTest ();
1.79 - virtual bool RunTests (void);
1.80 - void DestroyNotify (void);
1.81 -private:
1.82 - Ptr<NoCount> CallTest (Ptr<NoCount> p);
1.83 - Ptr<NoCount> const CallTestConst (Ptr<NoCount> const p);
1.84 - uint32_t m_nDestroyed;
1.85 -};
1.86 -
1.87 +class PtrTestCase;
1.88
1.89 class Base
1.90 {
1.91 @@ -98,13 +39,27 @@
1.92 class NoCount : public Base
1.93 {
1.94 public:
1.95 - NoCount (PtrTest *test);
1.96 + NoCount (PtrTestCase *test);
1.97 ~NoCount ();
1.98 void Nothing (void) const;
1.99 private:
1.100 - PtrTest *m_test;
1.101 + PtrTestCase *m_test;
1.102 };
1.103
1.104 +
1.105 +class PtrTestCase : public TestCase
1.106 +{
1.107 +public:
1.108 + PtrTestCase ();
1.109 + void DestroyNotify (void);
1.110 +private:
1.111 + virtual bool DoRun (void);
1.112 + Ptr<NoCount> CallTest (Ptr<NoCount> p);
1.113 + Ptr<NoCount> const CallTestConst (Ptr<NoCount> const p);
1.114 + uint32_t m_nDestroyed;
1.115 +};
1.116 +
1.117 +
1.118 Base::Base ()
1.119 : m_count (1)
1.120 {}
1.121 @@ -125,7 +80,7 @@
1.122 }
1.123 }
1.124
1.125 -NoCount::NoCount (PtrTest *test)
1.126 +NoCount::NoCount (PtrTestCase *test)
1.127 : m_test (test)
1.128 {}
1.129 NoCount::~NoCount ()
1.130 @@ -136,43 +91,37 @@
1.131 NoCount::Nothing () const
1.132 {}
1.133
1.134 -PtrTest::PtrTest ()
1.135 - : Test ("Ptr")
1.136 +
1.137 +
1.138 +PtrTestCase::PtrTestCase (void)
1.139 + : TestCase ("Sanity checking of Ptr<>")
1.140 {}
1.141 -
1.142 -PtrTest::~PtrTest ()
1.143 -{}
1.144 -
1.145 void
1.146 -PtrTest::DestroyNotify (void)
1.147 +PtrTestCase::DestroyNotify (void)
1.148 {
1.149 m_nDestroyed++;
1.150 }
1.151 Ptr<NoCount>
1.152 -PtrTest::CallTest (Ptr<NoCount> p)
1.153 +PtrTestCase::CallTest (Ptr<NoCount> p)
1.154 {
1.155 return p;
1.156 }
1.157
1.158 Ptr<NoCount> const
1.159 -PtrTest::CallTestConst (Ptr<NoCount> const p)
1.160 +PtrTestCase::CallTestConst (Ptr<NoCount> const p)
1.161 {
1.162 return p;
1.163 }
1.164
1.165 +
1.166 bool
1.167 -PtrTest::RunTests (void)
1.168 +PtrTestCase::DoRun (void)
1.169 {
1.170 - bool ok = true;
1.171 -
1.172 m_nDestroyed = false;
1.173 {
1.174 Ptr<NoCount> p = Create<NoCount> (this);
1.175 }
1.176 - if (m_nDestroyed != 1)
1.177 - {
1.178 - ok = false;
1.179 - }
1.180 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.181
1.182 m_nDestroyed = 0;
1.183 {
1.184 @@ -180,10 +129,7 @@
1.185 p = Create<NoCount> (this);
1.186 p = p;
1.187 }
1.188 - if (m_nDestroyed != 1)
1.189 - {
1.190 - ok = false;
1.191 - }
1.192 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.193
1.194 m_nDestroyed = 0;
1.195 {
1.196 @@ -191,10 +137,7 @@
1.197 p1 = Create<NoCount> (this);
1.198 Ptr<NoCount> p2 = p1;
1.199 }
1.200 - if (m_nDestroyed != 1)
1.201 - {
1.202 - ok = false;
1.203 - }
1.204 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.205
1.206 m_nDestroyed = 0;
1.207 {
1.208 @@ -203,10 +146,7 @@
1.209 Ptr<NoCount> p2;
1.210 p2 = p1;
1.211 }
1.212 - if (m_nDestroyed != 1)
1.213 - {
1.214 - ok = false;
1.215 - }
1.216 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.217
1.218 m_nDestroyed = 0;
1.219 {
1.220 @@ -215,10 +155,7 @@
1.221 Ptr<NoCount> p2 = Create<NoCount> (this);
1.222 p2 = p1;
1.223 }
1.224 - if (m_nDestroyed != 2)
1.225 - {
1.226 - ok = false;
1.227 - }
1.228 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
1.229
1.230 m_nDestroyed = 0;
1.231 {
1.232 @@ -228,10 +165,7 @@
1.233 p2 = Create<NoCount> (this);
1.234 p2 = p1;
1.235 }
1.236 - if (m_nDestroyed != 2)
1.237 - {
1.238 - ok = false;
1.239 - }
1.240 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
1.241
1.242 m_nDestroyed = 0;
1.243 {
1.244 @@ -239,10 +173,7 @@
1.245 p1 = Create<NoCount> (this);
1.246 p1 = Create<NoCount> (this);
1.247 }
1.248 - if (m_nDestroyed != 2)
1.249 - {
1.250 - ok = false;
1.251 - }
1.252 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
1.253
1.254 m_nDestroyed = 0;
1.255 {
1.256 @@ -253,15 +184,9 @@
1.257 p2 = Create<NoCount> (this);
1.258 p2 = p1;
1.259 }
1.260 - if (m_nDestroyed != 1)
1.261 - {
1.262 - ok = false;
1.263 - }
1.264 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.265 }
1.266 - if (m_nDestroyed != 2)
1.267 - {
1.268 - ok = false;
1.269 - }
1.270 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
1.271
1.272 m_nDestroyed = 0;
1.273 {
1.274 @@ -272,15 +197,9 @@
1.275 p2 = Create<NoCount> (this);
1.276 p2 = CallTest (p1);
1.277 }
1.278 - if (m_nDestroyed != 1)
1.279 - {
1.280 - ok = false;
1.281 - }
1.282 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.283 }
1.284 - if (m_nDestroyed != 2)
1.285 - {
1.286 - ok = false;
1.287 - }
1.288 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
1.289
1.290 {
1.291 Ptr<NoCount> p1;
1.292 @@ -318,10 +237,7 @@
1.293 raw = GetPointer (p);
1.294 p = 0;
1.295 }
1.296 - if (m_nDestroyed != 0)
1.297 - {
1.298 - ok = false;
1.299 - }
1.300 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 0, "XXX");
1.301 delete raw;
1.302 }
1.303
1.304 @@ -333,62 +249,26 @@
1.305 v1->Nothing ();
1.306 v2->Nothing ();
1.307 }
1.308 - if (m_nDestroyed != 1)
1.309 - {
1.310 - ok = false;
1.311 - }
1.312 + NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
1.313
1.314 {
1.315 Ptr<Base> p0 = Create<NoCount> (this);
1.316 Ptr<NoCount> p1 = Create<NoCount> (this);
1.317 - if (p0 == p1)
1.318 - {
1.319 - ok = false;
1.320 - }
1.321 - if (p0 != p1)
1.322 - {
1.323 - }
1.324 - else
1.325 - {
1.326 - ok = false;
1.327 - }
1.328 + NS_TEST_EXPECT_MSG_EQ ((p0 == p1), false, "operator == failed");
1.329 + NS_TEST_EXPECT_MSG_EQ ((p0 != p1), true, "operator != failed");
1.330 }
1.331 -#if 0
1.332 - {
1.333 - Ptr<NoCount> p = Create<NoCount> (cb);
1.334 - Callback<void> callback = MakeCallback (&NoCount::Nothing, p);
1.335 - callback ();
1.336 - }
1.337 - {
1.338 - Ptr<const NoCount> p = Create<NoCount> (cb);
1.339 - Callback<void> callback = MakeCallback (&NoCount::Nothing, p);
1.340 - callback ();
1.341 - }
1.342 -#endif
1.343
1.344 -#if 0
1.345 - // as expected, fails compilation.
1.346 - {
1.347 - Ptr<const Base> p = Create<NoCount> (cb);
1.348 - Callback<void> callback = MakeCallback (&NoCount::Nothing, p);
1.349 - }
1.350 - // local types are not allowed as arguments to a template.
1.351 - {
1.352 - class B
1.353 - {
1.354 - public:
1.355 - B () {}
1.356 - };
1.357 - Foo<B> ();
1.358 - }
1.359 -#endif
1.360 -
1.361 -
1.362 - return ok;
1.363 + return false;
1.364 }
1.365
1.366 -PtrTest g_ptr_test;
1.367 +static class PtrTestSuite : public TestSuite
1.368 +{
1.369 +public:
1.370 + PtrTestSuite ()
1.371 + : TestSuite ("ptr", UNIT)
1.372 + {
1.373 + AddTestCase (new PtrTestCase ());
1.374 + }
1.375 +} g_ptrTestSuite;
1.376
1.377 -#endif // NOTDEF
1.378 -
1.379 -}; // namespace ns3
1.380 +} // namespace ns3