diff --git a/src/mobility/test/waypoint-mobility-model-test.cc b/src/mobility/test/waypoint-mobility-model-test.cc index 624fea228..e2c0b4500 100644 --- a/src/mobility/test/waypoint-mobility-model-test.cc +++ b/src/mobility/test/waypoint-mobility-model-test.cc @@ -49,7 +49,7 @@ private: virtual void DoRun (void); virtual void DoTeardown (void); void ForceUpdates (void); - void CourseChangeCallback (std::string path, Ptr model); + void CourseChangeCallback (Ptr model); }; void @@ -94,6 +94,7 @@ WaypointMobilityModelNotifyTest::DoRun (void) for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i) { Ptr mob = (*i)->GetObject (); + mob->TraceConnectWithoutContext ("CourseChange", MakeCallback (&WaypointMobilityModelNotifyTest::CourseChangeCallback, this)); for ( std::deque::iterator w = waypoints.begin (); w != waypoints.end (); ++w ) { @@ -107,9 +108,6 @@ WaypointMobilityModelNotifyTest::DoRun (void) Simulator::Schedule (Seconds (updateTime), &WaypointMobilityModelNotifyTest::ForceUpdates, this); } - Config::Connect ("/NodeList/*/$ns3::WaypointMobilityModel/CourseChange", - MakeCallback (&WaypointMobilityModelNotifyTest::CourseChangeCallback, this)); - Simulator::Stop (Seconds ((double)waypointCount + 2.0)); Simulator::Run (); Simulator::Destroy (); @@ -125,7 +123,7 @@ WaypointMobilityModelNotifyTest::ForceUpdates (void) } } void -WaypointMobilityModelNotifyTest::CourseChangeCallback (std::string path, Ptr model) +WaypointMobilityModelNotifyTest::CourseChangeCallback (Ptr model) { const Time now = Simulator::Now (); const double sec = now.GetSeconds (); @@ -137,7 +135,7 @@ WaypointMobilityModelNotifyTest::CourseChangeCallback (std::string path, Ptr m_mobilityModel; + uint32_t m_waypointCount; + uint32_t m_waypointCounter; + Waypoint m_nextWaypoint; +private: + virtual void DoRun (void); + virtual void DoTeardown (void); + void CourseChangeCallback (Ptr model); +}; + + +void +WaypointMobilityModelAddWaypointTest::DoTeardown (void) +{ + m_mobilityModel = 0; +} + +void +WaypointMobilityModelAddWaypointTest::DoRun (void) +{ + m_waypointCount = 10; + m_waypointCounter = 1; + + ObjectFactory mobilityFactory; + mobilityFactory.SetTypeId ("ns3::WaypointMobilityModel"); + mobilityFactory.Set ("LazyNotify", BooleanValue (false)); + + // Create a new mobility model. + m_mobilityModel = mobilityFactory.Create ()->GetObject (); + m_mobilityModel->TraceConnectWithoutContext ("CourseChange", MakeCallback (&WaypointMobilityModelAddWaypointTest::CourseChangeCallback, this)); + + // Add this mobility model to the stack. + Simulator::Schedule (Seconds (0.0), &Object::Initialize, m_mobilityModel); + + Ptr mob = DynamicCast (m_mobilityModel); + Waypoint m_nextWaypoint (Seconds (m_waypointCounter), Vector (0.0, 0.0, 0.0)); + mob->AddWaypoint (m_nextWaypoint); + + Simulator::Stop (Seconds ((double)m_waypointCount + 2.0)); + Simulator::Run (); + Simulator::Destroy (); +} + +void +WaypointMobilityModelAddWaypointTest::CourseChangeCallback (Ptr model) +{ + const Time now = Simulator::Now (); + Ptr mob = DynamicCast (m_mobilityModel); + + std::cout << now << " CourseChangeCallback" << std::endl; + + NS_TEST_EXPECT_MSG_EQ (now, Seconds (m_waypointCounter), "Waypoint time not properly set"); + + if (now < Seconds ((double)m_waypointCount) ) + { + m_waypointCounter ++; + m_nextWaypoint = Waypoint (Seconds (m_waypointCounter), Vector (0.0, 0.0, 0.0)); + mob->AddWaypoint (m_nextWaypoint); + + } +} + static struct WaypointMobilityModelTestSuite : public TestSuite { WaypointMobilityModelTestSuite () : TestSuite ("waypoint-mobility-model", UNIT) { AddTestCase (new WaypointMobilityModelNotifyTest (true), TestCase::QUICK); AddTestCase (new WaypointMobilityModelNotifyTest (false), TestCase::QUICK); + AddTestCase (new WaypointMobilityModelAddWaypointTest (), TestCase::QUICK); } } g_waypointMobilityModelTestSuite;