From 09576cd905da7be5dbb42fe139d8f347fbfe9649 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 10:50:03 +0200 Subject: [PATCH 1/7] according to C language lawyers, this construct is undefined. In practice, its gcc definition is not what you want: the variable content is read before calling DoRun, and is ored+stored after calling DoRun. --- src/core/test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/test.cc b/src/core/test.cc index f34c05a86..29e66548d 100644 --- a/src/core/test.cc +++ b/src/core/test.cc @@ -124,7 +124,8 @@ TestCase::Run (void) { DoReportStart (); DoSetup (); - m_error |= DoRun (); + bool status = DoRun (); + m_error |= status; DoTeardown (); if (m_error == false) { From f7e39fc9f35ab8bf6bc797c1efd3da9f50ad6917 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 11:08:57 +0200 Subject: [PATCH 2/7] bug 675: convert unit tests to new test framework --- src/simulator/simulator.cc | 846 +++++++++++++++---------------------- 1 file changed, 345 insertions(+), 501 deletions(-) diff --git a/src/simulator/simulator.cc b/src/simulator/simulator.cc index d5d77f84f..7a0c2a7fb 100644 --- a/src/simulator/simulator.cc +++ b/src/simulator/simulator.cc @@ -316,11 +316,7 @@ Simulator::GetImplementation (void) } // namespace ns3 - -#ifdef RUN_SELF_TESTS - #include "ns3/test.h" -#include "ns3/ptr.h" #include "list-scheduler.h" #include "heap-scheduler.h" #include "map-scheduler.h" @@ -329,6 +325,190 @@ Simulator::GetImplementation (void) namespace ns3 { +class SimulatorEventsTestCase : public TestCase +{ +public: + SimulatorEventsTestCase (Ptr scheduler); + virtual bool DoRun (void); + void A (int a); + void B (int b); + void C (int c); + void D (int d); + void foo0 (void); + uint64_t NowUs (void); + void destroy(void); + bool m_b; + bool m_a; + bool m_c; + bool m_d; + EventId m_idC; + bool m_destroy; + EventId m_destroyId; +}; + +SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr scheduler) + : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ()) +{} +uint64_t +SimulatorEventsTestCase::NowUs (void) +{ + uint64_t ns = Now ().GetNanoSeconds (); + return ns / 1000; +} + +void +SimulatorEventsTestCase::A (int a) +{ + m_a = false; +} + +void +SimulatorEventsTestCase::B (int b) +{ + if (b != 2 || NowUs () != 11) + { + m_b = false; + } + else + { + m_b = true; + } + Simulator::Remove (m_idC); + Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::D, this, 4); +} + +void +SimulatorEventsTestCase::C (int c) +{ + m_c = false; +} + +void +SimulatorEventsTestCase::D (int d) +{ + if (d != 4 || NowUs () != (11+10)) + { + m_d = false; + } + else + { + m_d = true; + } +} + +void +SimulatorEventsTestCase::foo0(void) +{} + +void +SimulatorEventsTestCase::destroy (void) +{ + if (m_destroyId.IsExpired ()) + { + m_destroy = true; + } +} +bool +SimulatorEventsTestCase::DoRun (void) +{ + m_a = true; + m_b = false; + m_c = true; + m_d = false; + + EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1); + Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2); + m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3); + + NS_TEST_EXPECT_MSG_EQ (!m_idC.IsExpired (), true, ""); + NS_TEST_EXPECT_MSG_EQ (!a.IsExpired (), true, ""); + Simulator::Cancel (a); + NS_TEST_EXPECT_MSG_EQ (a.IsExpired (), true, ""); + Simulator::Run (); + NS_TEST_EXPECT_MSG_EQ (m_a, true, "Event A did not run ?"); + NS_TEST_EXPECT_MSG_EQ (m_b, true, "Event B did not run ?"); + NS_TEST_EXPECT_MSG_EQ (m_c, true, "Event C did not run ?"); + NS_TEST_EXPECT_MSG_EQ (m_d, true, "Event D did not run ?"); + + EventId anId = Simulator::ScheduleNow (&SimulatorEventsTestCase::foo0, this); + EventId anotherId = anId; + NS_TEST_EXPECT_MSG_EQ (!(anId.IsExpired () || anotherId.IsExpired ()), true, "Event should not have expired yet."); + + Simulator::Remove (anId); + NS_TEST_EXPECT_MSG_EQ (anId.IsExpired (), true, "Event was removed: it is now expired"); + NS_TEST_EXPECT_MSG_EQ (anotherId.IsExpired (), true, "Event was removed: it is now expired"); + + m_destroy = false; + m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this); + NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet"); + m_destroyId.Cancel (); + NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now"); + + m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this); + NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet"); + Simulator::Remove (m_destroyId); + NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event was canceled: should have expired now"); + + m_destroyId = Simulator::ScheduleDestroy (&SimulatorEventsTestCase::destroy, this); + NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet"); + + Simulator::Run (); + NS_TEST_EXPECT_MSG_EQ (!m_destroyId.IsExpired (), true, "Event should not have expired yet"); + NS_TEST_EXPECT_MSG_EQ (!m_destroy, true, "Event should not have run"); + + Simulator::Destroy (); + NS_TEST_EXPECT_MSG_EQ (m_destroyId.IsExpired (), true, "Event should have expired now"); + NS_TEST_EXPECT_MSG_EQ (m_destroy, true, "Event should have run"); + + return false; +} + +class SimulatorTemplateTestCase : public TestCase +{ +public: + SimulatorTemplateTestCase (); + // only here for testing of Ptr<> + void Ref (void) const {} + void Unref (void) const {} +private: + virtual bool DoRun (void); + + void bar0 (void) {} + void bar1 (int) {} + void bar2 (int, int) {} + void bar3 (int, int, int) {} + void bar4 (int, int, int, int) {} + void bar5 (int, int, int, int, int) {} + void baz1 (int &) {} + void baz2 (int &, int &) {} + void baz3 (int &, int &, int &) {} + void baz4 (int &, int &, int &, int &) {} + void baz5 (int &, int &, int &, int &, int &) {} + void cbaz1 (const int &) {} + void cbaz2 (const int &, const int &) {} + void cbaz3 (const int &, const int &, const int &) {} + void cbaz4 (const int &, const int &, const int &, const int &) {} + void cbaz5 (const int &, const int &, const int &, const int &, const int &) {} + + void bar0c (void) const {} + void bar1c (int) const {} + void bar2c (int, int) const {} + void bar3c (int, int, int) const {} + void bar4c (int, int, int, int) const {} + void bar5c (int, int, int, int, int) const {} + void baz1c (int &) const {} + void baz2c (int &, int &) const {} + void baz3c (int &, int &, int &) const {} + void baz4c (int &, int &, int &, int &) const {} + void baz5c (int &, int &, int &, int &, int &) const {} + void cbaz1c (const int &) const {} + void cbaz2c (const int &, const int &) const {} + void cbaz3c (const int &, const int &, const int &) const {} + void cbaz4c (const int &, const int &, const int &, const int &) const {} + void cbaz5c (const int &, const int &, const int &, const int &, const int &) const {} + +}; + static void foo0 (void) {} static void foo1 (int) @@ -341,8 +521,6 @@ static void foo4 (int, int, int, int) {} static void foo5 (int, int, int, int, int) {} - -#if 1 static void ber1 (int &) {} static void ber2 (int &, int &) @@ -353,8 +531,6 @@ static void ber4 (int &, int &, int &, int &) {} static void ber5 (int &, int &, int &, int &, int &) {} -#endif - static void cber1 (const int &) {} static void cber2 (const int &, const int &) @@ -365,407 +541,85 @@ static void cber4 (const int &, const int &, const int &, const int &) {} static void cber5 (const int &, const int &, const int &, const int &, const int &) {} - -class SimulatorTests : public Test -{ -public: - SimulatorTests (); - // only here for testing of Ptr<> - void Ref (void) const; - void Unref (void) const; - virtual ~SimulatorTests (); - virtual bool RunTests (void); -private: - uint64_t NowUs (); - bool RunOneTest (void); - void RunTestsConst (void) const; - void A (int a); - void B (int b); - void C (int c); - void D (int d); - void bar0 (void); - void bar1 (int); - void bar2 (int, int); - void bar3 (int, int, int); - void bar4 (int, int, int, int); - void bar5 (int, int, int, int, int); - void baz1 (int &); - void baz2 (int &, int &); - void baz3 (int &, int &, int &); - void baz4 (int &, int &, int &, int &); - void baz5 (int &, int &, int &, int &, int &); - void cbaz1 (const int &); - void cbaz2 (const int &, const int &); - void cbaz3 (const int &, const int &, const int &); - void cbaz4 (const int &, const int &, const int &, const int &); - void cbaz5 (const int &, const int &, const int &, const int &, const int &); - - void bar0c (void) const; - void bar1c (int) const; - void bar2c (int, int) const; - void bar3c (int, int, int) const; - void bar4c (int, int, int, int) const; - void bar5c (int, int, int, int, int) const; - void baz1c (int &) const; - void baz2c (int &, int &) const; - void baz3c (int &, int &, int &) const; - void baz4c (int &, int &, int &, int &) const; - void baz5c (int &, int &, int &, int &, int &) const; - void cbaz1c (const int &) const; - void cbaz2c (const int &, const int &) const; - void cbaz3c (const int &, const int &, const int &) const; - void cbaz4c (const int &, const int &, const int &, const int &) const; - void cbaz5c (const int &, const int &, const int &, const int &, const int &) const; - - void destroy (void); - - bool m_b; - bool m_a; - bool m_c; - bool m_d; - EventId m_idC; - bool m_destroy; - EventId m_destroyId; -}; - -SimulatorTests::SimulatorTests () - : Test ("Simulator") +SimulatorTemplateTestCase::SimulatorTemplateTestCase () + : TestCase ("Check that all templates are instanciated correctly. This is a compilation test, it cannot fail at runtime.") {} - -SimulatorTests::~SimulatorTests () -{} - -void -SimulatorTests::Ref (void) const -{} - -void -SimulatorTests::Unref (void) const -{} - -uint64_t -SimulatorTests::NowUs (void) -{ - uint64_t ns = Now ().GetNanoSeconds (); - return ns / 1000; -} - -void -SimulatorTests::A (int a) -{ - m_a = false; -} - -void -SimulatorTests::B (int b) -{ - if (b != 2 || NowUs () != 11) - { - m_b = false; - } - else - { - m_b = true; - } - Simulator::Remove (m_idC); - Simulator::Schedule (MicroSeconds (10), &SimulatorTests::D, this, 4); -} - -void -SimulatorTests::C (int c) -{ - m_c = false; -} - -void -SimulatorTests::D (int d) -{ - if (d != 4 || NowUs () != (11+10)) - { - m_d = false; - } - else - { - m_d = true; - } -} - -void -SimulatorTests::destroy (void) -{ - if (m_destroyId.IsExpired ()) - { - m_destroy = true; - } -} - -void -SimulatorTests::bar0 (void) -{} - -void -SimulatorTests::bar1 (int) -{} - -void -SimulatorTests::bar2 (int, int) -{} - -void -SimulatorTests::bar3 (int, int, int) -{} - -void -SimulatorTests::bar4 (int, int, int, int) -{} - -void -SimulatorTests::bar5 (int, int, int, int, int) -{} - -void -SimulatorTests::baz1 (int &) -{} - -void -SimulatorTests::baz2 (int &, int &) -{} - -void -SimulatorTests::baz3 (int &, int &, int &) -{} - -void -SimulatorTests::baz4 (int &, int &, int &, int &) -{} - -void -SimulatorTests::baz5 (int &, int &, int &, int &, int &) -{} - -void -SimulatorTests::cbaz1 (const int &) -{} - -void -SimulatorTests::cbaz2 (const int &, const int &) -{} - -void -SimulatorTests::cbaz3 (const int &, const int &, const int &) -{} - -void -SimulatorTests::cbaz4 (const int &, const int &, const int &, const int &) -{} - -void -SimulatorTests::cbaz5 (const int &, const int &, const int &, const int &, const int &) -{} - -void -SimulatorTests::bar0c (void) const -{} - -void -SimulatorTests::bar1c (int) const -{} - -void -SimulatorTests::bar2c (int, int) const -{} - -void -SimulatorTests::bar3c (int, int, int) const -{} - -void -SimulatorTests::bar4c (int, int, int, int) const -{} - -void -SimulatorTests::bar5c (int, int, int, int, int) const -{} - -void -SimulatorTests::baz1c (int &) const -{} - -void -SimulatorTests::baz2c (int &, int &) const -{} - -void -SimulatorTests::baz3c (int &, int &, int &) const -{} - -void -SimulatorTests::baz4c (int &, int &, int &, int &) const -{} - -void -SimulatorTests::baz5c (int &, int &, int &, int &, int &) const -{} - -void -SimulatorTests::cbaz1c (const int &) const -{} - -void -SimulatorTests::cbaz2c (const int &, const int &) const -{} - -void -SimulatorTests::cbaz3c (const int &, const int &, const int &) const -{} - -void -SimulatorTests::cbaz4c (const int &, const int &, const int &, const int &) const -{} - -void -SimulatorTests::cbaz5c (const int &, const int &, const int &, const int &, const int &) const -{} - -bool -SimulatorTests::RunOneTest (void) -{ - bool result = true; - m_a = true; - m_b = false; - m_c = true; - m_d = false; - - EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorTests::A, this, 1); - Simulator::Schedule (MicroSeconds (11), &SimulatorTests::B, this, 2); - m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorTests::C, this, 3); - - NS_TEST_ASSERT (!m_idC.IsExpired ()); - NS_TEST_ASSERT (!a.IsExpired ()); - Simulator::Cancel (a); - NS_TEST_ASSERT (a.IsExpired ()); - Simulator::Run (); - 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 -{ - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, this); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, this, 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0c, Ptr (this)); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1c, Ptr (this), 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2c, Ptr (this), 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3c, Ptr (this), 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4c, Ptr (this), 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5c, Ptr (this), 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1c, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2c, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3c, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4c, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar0c, this); - Simulator::ScheduleNow (&SimulatorTests::bar1c, this, 0); - Simulator::ScheduleNow (&SimulatorTests::bar2c, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar3c, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar4c, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz1c, this, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz2c, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz3c, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar0c, Ptr (this)); - Simulator::ScheduleNow (&SimulatorTests::bar1c, Ptr (this), 0); - Simulator::ScheduleNow (&SimulatorTests::bar2c, Ptr (this), 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar3c, Ptr (this), 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar4c, Ptr (this), 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar5c, Ptr (this), 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar0c, this); - Simulator::ScheduleDestroy (&SimulatorTests::bar1c, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar2c, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar3c, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar4c, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz1c, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz2c, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz3c, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz4c, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar0c, Ptr (this)); - Simulator::ScheduleDestroy (&SimulatorTests::bar1c, Ptr (this), 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar2c, Ptr (this), 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar3c, Ptr (this), 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar4c, Ptr (this), 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar5c, Ptr (this), 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1c, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2c, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3c, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4c, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz1c, this, 0); - Simulator::ScheduleNow (&SimulatorTests::baz2c, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz3c, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz4c, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz1c, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz2c, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz3c, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz4c, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz5c, this, 0, 0, 0, 0, 0); - - Simulator::Run (); - Simulator::Destroy (); -} - bool -SimulatorTests::RunTests (void) +SimulatorTemplateTestCase::DoRun (void) { - bool result = true; + // Test schedule of const methods + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, this); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1c, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2c, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, this); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1c, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, this); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1c, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2c, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3c, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4c, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5c, this, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1c, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2c, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3c, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1c, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2c, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1c, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2c, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3c, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4c, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5c, this, 0, 0, 0, 0, 0); - Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); - if (!RunOneTest ()) - { - result = false; - } - Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); - if (!RunOneTest ()) - { - result = false; - } - Simulator::Destroy (); - Simulator::SetScheduler (CreateObject ()); - if (!RunOneTest ()) - { - result = false; - } - Simulator::Destroy (); + // Test of schedule const methods with Ptr<> pointers + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0c, Ptr (this)); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1c, Ptr (this), 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2c, Ptr (this), 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3c, Ptr (this), 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4c, Ptr (this), 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5c, Ptr (this), 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0c, Ptr (this)); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1c, Ptr (this), 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2c, Ptr (this), 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3c, Ptr (this), 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4c, Ptr (this), 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5c, Ptr (this), 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0c, Ptr (this)); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1c, Ptr (this), 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2c, Ptr (this), 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3c, Ptr (this), 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4c, Ptr (this), 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5c, Ptr (this), 0, 0, 0, 0, 0); - Simulator::SetScheduler (CreateObject ()); - if (!RunOneTest ()) - { - result = false; - } - Simulator::Destroy (); - - Simulator::SetScheduler (CreateObject ()); - if (!RunOneTest ()) - { - result = false; - } - Simulator::Destroy (); + // Test schedule of raw functions Simulator::Schedule (Seconds (0.0), &foo0); Simulator::Schedule (Seconds (0.0), &foo1, 0); Simulator::Schedule (Seconds (0.0), &foo2, 0, 0); @@ -777,23 +631,6 @@ SimulatorTests::RunTests (void) Simulator::Schedule (Seconds (0.0), &cber3, 0, 0, 0); Simulator::Schedule (Seconds (0.0), &cber4, 0, 0, 0, 0); Simulator::Schedule (Seconds (0.0), &cber5, 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, this); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar0, Ptr (this)); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar1, Ptr (this), 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar2, Ptr (this), 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar3, Ptr (this), 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar4, Ptr (this), 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::bar5, Ptr (this), 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz1, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz2, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz3, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz4, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0); Simulator::ScheduleNow (&foo0); Simulator::ScheduleNow (&foo1, 0); Simulator::ScheduleNow (&foo2, 0, 0); @@ -805,23 +642,6 @@ SimulatorTests::RunTests (void) Simulator::ScheduleNow (&cber3, 0, 0, 0); Simulator::ScheduleNow (&cber4, 0, 0, 0, 0); Simulator::ScheduleNow (&cber5, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar0, this); - Simulator::ScheduleNow (&SimulatorTests::bar1, this, 0); - Simulator::ScheduleNow (&SimulatorTests::bar2, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar3, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz1, this, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz2, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz3, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz4, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar0, Ptr (this)); - Simulator::ScheduleNow (&SimulatorTests::bar1, Ptr (this), 0); - Simulator::ScheduleNow (&SimulatorTests::bar2, Ptr (this), 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar3, Ptr (this), 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar4, Ptr (this), 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::bar5, Ptr (this), 0, 0, 0, 0, 0); Simulator::ScheduleDestroy (&foo0); Simulator::ScheduleDestroy (&foo1, 0); Simulator::ScheduleDestroy (&foo2, 0, 0); @@ -833,96 +653,120 @@ SimulatorTests::RunTests (void) Simulator::ScheduleDestroy (&cber3, 0, 0, 0); Simulator::ScheduleDestroy (&cber4, 0, 0, 0, 0); Simulator::ScheduleDestroy (&cber5, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar0, this); - Simulator::ScheduleDestroy (&SimulatorTests::bar1, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar2, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar3, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar4, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz1, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz2, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz3, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz4, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::cbaz5, this, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar0, Ptr (this)); - Simulator::ScheduleDestroy (&SimulatorTests::bar1, Ptr (this), 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar2, Ptr (this), 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar3, Ptr (this), 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar4, Ptr (this), 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::bar5, Ptr (this), 0, 0, 0, 0, 0); + + + // Test schedule of normal member methods + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, this); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz1, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz2, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, this); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz1, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz2, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, this); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz1, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz2, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz3, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz4, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::cbaz5, this, 0, 0, 0, 0, 0); + + + // test schedule of normal methods with Ptr<> pointers + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar0, Ptr (this)); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar1, Ptr (this), 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar2, Ptr (this), 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar3, Ptr (this), 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar4, Ptr (this), 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::bar5, Ptr (this), 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar0, Ptr (this)); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar1, Ptr (this), 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar2, Ptr (this), 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar3, Ptr (this), 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar4, Ptr (this), 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::bar5, Ptr (this), 0, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar0, Ptr (this)); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar1, Ptr (this), 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar2, Ptr (this), 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar3, Ptr (this), 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar4, Ptr (this), 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::bar5, Ptr (this), 0, 0, 0, 0, 0); // the code below does not compile, as expected. //Simulator::Schedule (Seconds (0.0), &cber1, 0.0); -#if 1 + + // This code appears to be duplicate test code. Simulator::Schedule (Seconds (0.0), &ber1, 0); Simulator::Schedule (Seconds (0.0), &ber2, 0, 0); Simulator::Schedule (Seconds (0.0), &ber3, 0, 0, 0); Simulator::Schedule (Seconds (0.0), &ber4, 0, 0, 0, 0); Simulator::Schedule (Seconds (0.0), &ber5, 0, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz1, this, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz2, this, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz3, this, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz4, this, 0, 0, 0, 0); - Simulator::Schedule (Seconds (0.0), &SimulatorTests::baz5, this, 0, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz1, this, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz2, this, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz3, this, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0); + Simulator::Schedule (Seconds (0.0), &SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0); Simulator::ScheduleNow (&ber1, 0); Simulator::ScheduleNow (&ber2, 0, 0); Simulator::ScheduleNow (&ber3, 0, 0, 0); Simulator::ScheduleNow (&ber4, 0, 0, 0, 0); Simulator::ScheduleNow (&ber5, 0, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz1, this, 0); - Simulator::ScheduleNow (&SimulatorTests::baz2, this, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz3, this, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz4, this, 0, 0, 0, 0); - Simulator::ScheduleNow (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz1, this, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz2, this, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0); + Simulator::ScheduleNow (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0); Simulator::ScheduleDestroy (&ber1, 0); Simulator::ScheduleDestroy (&ber2, 0, 0); Simulator::ScheduleDestroy (&ber3, 0, 0, 0); Simulator::ScheduleDestroy (&ber4, 0, 0, 0, 0); Simulator::ScheduleDestroy (&ber5, 0, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz1, this, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz2, this, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz3, this, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz4, this, 0, 0, 0, 0); - Simulator::ScheduleDestroy (&SimulatorTests::baz5, this, 0, 0, 0, 0, 0); -#endif + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz1, this, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz2, this, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz3, this, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz4, this, 0, 0, 0, 0); + Simulator::ScheduleDestroy (&SimulatorTemplateTestCase::baz5, this, 0, 0, 0, 0, 0); - RunTestsConst (); - - EventId nowId = Simulator::ScheduleNow (&foo0); - m_destroyId = Simulator::ScheduleDestroy (&SimulatorTests::destroy, this); - NS_TEST_ASSERT (!m_destroyId.IsExpired ()); - - Simulator::Run (); - m_destroy = false; - Simulator::Destroy (); - NS_TEST_ASSERT (m_destroy); - - EventId anId = Simulator::ScheduleNow (&foo0); - EventId anotherId = anId; - NS_TEST_ASSERT (!(anId.IsExpired () || anotherId.IsExpired ())); - - Simulator::Remove (anId); - NS_TEST_ASSERT (anId.IsExpired ()); - NS_TEST_ASSERT (anotherId.IsExpired ()); Simulator::Run (); Simulator::Destroy (); - Simulator::Schedule (Seconds (10.0), &SimulatorTests::baz1, this, 0); - Simulator::Stop (Seconds (1.0)); - Simulator::Run (); - Simulator::Destroy (); - - return result; + return false; } -SimulatorTests gSimulatorTests; - -}; // namespace ns3 - -#endif /* RUN_SELF_TESTS */ - - +class SimulatorTestSuite : public TestSuite +{ +public: + SimulatorTestSuite () + : TestSuite ("simulator") + { + AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + AddTestCase (new SimulatorEventsTestCase (CreateObject ())); + } +} g_simulatorTestSuite; +} // namespace ns3 From 1d515320dc1f304c79446827ac2a5691a2db2652 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 11:09:18 +0200 Subject: [PATCH 3/7] fix old bug: canceled destroy events are expired --- src/simulator/default-simulator-impl.cc | 5 +++++ src/simulator/realtime-simulator-impl.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/simulator/default-simulator-impl.cc b/src/simulator/default-simulator-impl.cc index eb619d56a..394545651 100644 --- a/src/simulator/default-simulator-impl.cc +++ b/src/simulator/default-simulator-impl.cc @@ -268,6 +268,11 @@ DefaultSimulatorImpl::IsExpired (const EventId &ev) const { if (ev.GetUid () == 2) { + if (ev.PeekEventImpl () == 0 || + ev.PeekEventImpl ()->IsCancelled ()) + { + return true; + } // destroy events. for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++) { diff --git a/src/simulator/realtime-simulator-impl.cc b/src/simulator/realtime-simulator-impl.cc index 9443db38f..b096c99f0 100644 --- a/src/simulator/realtime-simulator-impl.cc +++ b/src/simulator/realtime-simulator-impl.cc @@ -725,6 +725,11 @@ RealtimeSimulatorImpl::IsExpired (const EventId &ev) const { if (ev.GetUid () == 2) { + if (ev.PeekEventImpl () == 0 || + ev.PeekEventImpl ()->IsCancelled ()) + { + return true; + } // destroy events. for (DestroyEvents::const_iterator i = m_destroyEvents.begin (); i != m_destroyEvents.end (); i++) From f4ab1d87c693ec279329268ac3bdd1a6ee269821 Mon Sep 17 00:00:00 2001 From: Andrey Mazo Date: Wed, 30 Sep 2009 13:15:16 +0200 Subject: [PATCH 4/7] Add explicit typecasts for gcc-4.1.2 --- src/simulator/time.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/simulator/time.cc b/src/simulator/time.cc index 65d0a9027..a986e2dfb 100644 --- a/src/simulator/time.cc +++ b/src/simulator/time.cc @@ -586,35 +586,36 @@ void ConversionTestCase::DoTeardown (void) ASSERT_MSG_EQ_INT(t_sec.GetNanoSeconds(), val*1e9, 1e9, "conv sec ns"); \ ASSERT_MSG_EQ_INT(t_sec.GetPicoSeconds(), val*1e12, 1e12, "conv sec ps"); \ ASSERT_MSG_EQ_INT(t_sec.GetFemtoSeconds(), val*1e15, 1e15, "conv sec fs"); \ - Time t_ms = MilliSeconds(val); \ + uint64_t int_val = (uint64_t)val; \ + Time t_ms = MilliSeconds(int_val); \ ASSERT_MSG_EQ(t_ms.GetSeconds(), val*1e-3, 1e0, "conv ms s"); \ ASSERT_MSG_EQ_INT(t_ms.GetMilliSeconds(), val*1e0, 1e3, "conv ms ms"); \ ASSERT_MSG_EQ_INT(t_ms.GetMicroSeconds(), val*1e3, 1e6, "conv ms us"); \ ASSERT_MSG_EQ_INT(t_ms.GetNanoSeconds(), val*1e6, 1e9, "conv ms ns"); \ ASSERT_MSG_EQ_INT(t_ms.GetPicoSeconds(), val*1e9, 1e12, "conv ms fs"); \ ASSERT_MSG_EQ_INT(t_ms.GetFemtoSeconds(), val*1e12, 1e15, "conv ms ps"); \ - Time t_us = MicroSeconds(val); \ + Time t_us = MicroSeconds(int_val); \ ASSERT_MSG_EQ(t_us.GetSeconds(), val*1e-6, 1e0, "conv us s"); \ ASSERT_MSG_EQ_INT(t_us.GetMilliSeconds(), val*1e-3, 1e3, "conv us ms"); \ ASSERT_MSG_EQ_INT(t_us.GetMicroSeconds(), val*1e0, 1e6, "conv us us"); \ ASSERT_MSG_EQ_INT(t_us.GetNanoSeconds(), val*1e3, 1e9, "conv us ns"); \ ASSERT_MSG_EQ_INT(t_us.GetPicoSeconds(), val*1e6, 1e12, "conv us ps"); \ ASSERT_MSG_EQ_INT(t_us.GetFemtoSeconds(), val*1e9, 1e15, "conv us fs"); \ - Time t_ns = NanoSeconds(val); \ + Time t_ns = NanoSeconds(int_val); \ ASSERT_MSG_EQ(t_ns.GetSeconds(), val*1e-9, 1e0, "conv ns s"); \ ASSERT_MSG_EQ_INT(t_ns.GetMilliSeconds(), val*1e-6, 1e3, "conv ns ms"); \ ASSERT_MSG_EQ_INT(t_ns.GetMicroSeconds(), val*1e-3, 1e6, "conv ns us"); \ ASSERT_MSG_EQ_INT(t_ns.GetNanoSeconds(), val*1e0, 1e9, "conv ns ns"); \ ASSERT_MSG_EQ_INT(t_ns.GetPicoSeconds(), val*1e3, 1e12, "conv ns ps"); \ ASSERT_MSG_EQ_INT(t_ns.GetFemtoSeconds(), val*1e6, 1e15, "conv ns fs"); \ - Time t_ps = PicoSeconds(val); \ + Time t_ps = PicoSeconds(int_val); \ ASSERT_MSG_EQ(t_ps.GetSeconds(), val*1e-12, 1e0, "conv ps s"); \ ASSERT_MSG_EQ_INT(t_ps.GetMilliSeconds(), val*1e-9, 1e3, "conv ps ms"); \ ASSERT_MSG_EQ_INT(t_ps.GetMicroSeconds(), val*1e-6, 1e6, "conv ps us"); \ ASSERT_MSG_EQ_INT(t_ps.GetNanoSeconds(), val*1e-3, 1e9, "conv ps ns"); \ ASSERT_MSG_EQ_INT(t_ps.GetPicoSeconds(), val*1e0, 1e12, "conv ps ps"); \ ASSERT_MSG_EQ_INT(t_ps.GetFemtoSeconds(), val*1e3, 1e15, "conv ps fs"); \ - Time t_fs = FemtoSeconds(val); \ + Time t_fs = FemtoSeconds(int_val); \ ASSERT_MSG_EQ(t_fs.GetSeconds(), val*1e-15, 1e0, "conv fs sec"); \ ASSERT_MSG_EQ_INT(t_fs.GetMilliSeconds(), val*1e-12, 1e3, "conv fs ms"); \ ASSERT_MSG_EQ_INT(t_fs.GetMicroSeconds(), val*1e-9, 1e6, "conv fs us"); \ From 1ea9a297939227f3b43ef4f85e87e92433cfe314 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 13:20:10 +0200 Subject: [PATCH 5/7] remove stupid XXX --- src/routing/olsr/olsr-header.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/routing/olsr/olsr-header.cc b/src/routing/olsr/olsr-header.cc index ad84ad2fa..1bd09a4f3 100644 --- a/src/routing/olsr/olsr-header.cc +++ b/src/routing/olsr/olsr-header.cc @@ -525,7 +525,6 @@ OlsrEmfTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), true, "XXX"); } - // XXX return false; } @@ -632,7 +631,6 @@ OlsrMidTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ (sizeLeft, 0, "XXX"); } } - // XXX return false; } @@ -694,7 +692,6 @@ OlsrHelloTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read"); - // XXX return false; } @@ -732,7 +729,7 @@ OlsrTcTestCase::DoRun (void) Ipv4Address ("1.2.3.5"), "XXX"); NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "XXX"); - // XXX + return false; } @@ -777,7 +774,6 @@ OlsrHnaTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ (packet.GetSize (), 0, "All bytes in packet were not read"); - // XXX: why are we returning a constant here ? return false; } From fcf9745f91e86b4d31ab48b6f53f2cd0f2754f6e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 13:23:54 +0200 Subject: [PATCH 6/7] fix stupid test conversion error --- src/routing/olsr/olsr-header.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routing/olsr/olsr-header.cc b/src/routing/olsr/olsr-header.cc index 1bd09a4f3..2a66280b3 100644 --- a/src/routing/olsr/olsr-header.cc +++ b/src/routing/olsr/olsr-header.cc @@ -522,7 +522,7 @@ OlsrEmfTestCase::DoRun (void) { uint8_t emf = olsr::SecondsToEmf (time); double seconds = olsr::EmfToSeconds (emf); - NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), true, + NS_TEST_ASSERT_MSG_EQ((seconds < 0 || fabs (seconds - time) > 0.1), false, "XXX"); } return false; From b63393d355ed8546fbc23a1b68db42d51a3f1e3e Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 30 Sep 2009 13:32:48 +0200 Subject: [PATCH 7/7] remove un-needed code --- src/simulator/watchdog.cc | 53 --------------------------------------- 1 file changed, 53 deletions(-) diff --git a/src/simulator/watchdog.cc b/src/simulator/watchdog.cc index 9bfc47430..0a6b2d346 100644 --- a/src/simulator/watchdog.cc +++ b/src/simulator/watchdog.cc @@ -122,56 +122,3 @@ public: } // namespace ns3 -#ifdef RUN_SELF_TESTS - -#include "ns3/test.h" - -namespace ns3 { - -class WatchdogTests : public Test -{ -public: - WatchdogTests (); - virtual bool RunTests (void); -private: - void Expire (Time expected); - bool m_error; -}; - -WatchdogTests::WatchdogTests () - : Test ("Watchdog") -{} - -void -WatchdogTests::Expire (Time expected) -{ - bool result = true; - NS_TEST_ASSERT_EQUAL (Simulator::Now (), expected); - m_error = !result; -} - -bool -WatchdogTests::RunTests (void) -{ - bool result = true; - - m_error = false; - Watchdog watchdog; - watchdog.SetFunction (&WatchdogTests::Expire, this); - watchdog.SetArguments (MicroSeconds (40)); - watchdog.Ping (MicroSeconds (10)); - Simulator::Schedule (MicroSeconds (5), &Watchdog::Ping, &watchdog, MicroSeconds (20)); - Simulator::Schedule (MicroSeconds (20), &Watchdog::Ping, &watchdog, MicroSeconds (2)); - Simulator::Schedule (MicroSeconds (23), &Watchdog::Ping, &watchdog, MicroSeconds (17)); - Simulator::Run (); - NS_TEST_ASSERT (!m_error); - Simulator::Destroy (); - - return result; -} - -static WatchdogTests g_watchdogTests; - -} // namespace ns3 - -#endif /* RUN_SELF_TESTS */