src/simulator/simulator.cc
changeset 1521 7563328d71ea
parent 1296 173efb6d92d8
child 1522 70371ffd0ce5
--- a/src/simulator/simulator.cc	Fri Sep 21 15:57:20 2007 +0100
+++ b/src/simulator/simulator.cc	Fri Sep 21 17:57:06 2007 +0100
@@ -762,7 +762,7 @@
 bool
 SimulatorTests::RunOneTest (void)
 {
-  bool ok = true;
+  bool result = true;
   m_a = true;
   m_b = false;
   m_c = true;
@@ -772,26 +772,16 @@
   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 @@
 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 @@
 
   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;