From 4b242b57c84cf3f2f62fbcbfa6b2f1a407e84e4d Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Fri, 21 Sep 2007 17:57:06 +0100 Subject: [PATCH] Use NS_TEST_* macros for simulator unit tests --- src/simulator/simulator.cc | 62 ++++++++++++++------------------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index 6ee0340fd..5002cec81 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -762,7 +762,7 @@ SimulatorTests::cbaz5c (const int &, const int &, const int &, const int &, cons bool SimulatorTests::RunOneTest (void) { - bool ok = true; + bool result = true; m_a = true; m_b = false; m_c = true; @@ -772,26 +772,16 @@ SimulatorTests::RunOneTest (void) Simulator::Schedule (MicroSeconds (11), &SimulatorTests::B, this, 2); m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorTests::C, this, 3); - if (m_idC.IsExpired ()) - { - ok = false; - } - if (a.IsExpired ()) - { - ok = false; - } + NS_TEST_ASSERT (!m_idC.IsExpired ()); + NS_TEST_ASSERT (!a.IsExpired ()); Simulator::Cancel (a); - if (!a.IsExpired ()) - { - ok = false; - } + NS_TEST_ASSERT (a.IsExpired ()); Simulator::Run (); - - if (!m_a || !m_b || !m_c || !m_d) - { - ok = false; - } - return ok; + NS_TEST_ASSERT (m_a); + NS_TEST_ASSERT (m_b); + NS_TEST_ASSERT (m_c); + NS_TEST_ASSERT (m_d); + return result; } void SimulatorTests::RunTestsConst (void) const @@ -870,24 +860,26 @@ SimulatorTests::RunTestsConst (void) const bool SimulatorTests::RunTests (void) { - bool ok = true; + bool result = true; + + Simulator::Run (); // flush out any pending events before running our tests Simulator::SetLinkedList (); if (!RunOneTest ()) { - ok = false; + result = false; } Simulator::Destroy (); Simulator::SetBinaryHeap (); if (!RunOneTest ()) { - ok = false; + result = false; } Simulator::Destroy (); Simulator::SetStdMap (); if (!RunOneTest ()) { - ok = false; + result = false; } Simulator::Destroy (); @@ -1018,36 +1010,26 @@ SimulatorTests::RunTests (void) EventId nowId = Simulator::ScheduleNow (&foo0); m_destroyId = Simulator::ScheduleDestroy (&SimulatorTests::destroy, this); - if (m_destroyId.IsExpired ()) - { - ok = false; - } + NS_TEST_ASSERT (!m_destroyId.IsExpired ()); Simulator::Run (); m_destroy = false; Simulator::Destroy (); - if (!m_destroy) - { - ok = false; - } + NS_TEST_ASSERT (m_destroy); EventId anId = Simulator::ScheduleNow (&foo0); EventId anotherId = anId; - if (anId.IsExpired () || anotherId.IsExpired ()) - { - ok = false; - } + NS_TEST_ASSERT (!(anId.IsExpired () || anotherId.IsExpired ())); + Simulator::Remove (anId); - if (!anId.IsExpired () || !anotherId.IsExpired ()) - { - ok = false; - } + NS_TEST_ASSERT (anId.IsExpired ()); + NS_TEST_ASSERT (anotherId.IsExpired ()); Simulator::Run (); Simulator::Destroy (); - return ok; + return result; } SimulatorTests gSimulatorTests;