diff --git a/test/leo-mobility-test-suite.cc b/test/leo-mobility-test-suite.cc new file mode 100644 index 0000000..d315b28 --- /dev/null +++ b/test/leo-mobility-test-suite.cc @@ -0,0 +1,54 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ + +#include "ns3/leo-module.h" +#include "ns3/test.h" + +using namespace ns3; + +class LeoMobilityWaypointTestCase : public TestCase +{ +public: + LeoMobilityWaypointTestCase (); + virtual ~LeoMobilityWaypointTestCase () {} + +private: + virtual void DoRun (void); +}; + +LeoMobilityWaypointTestCase::LeoMobilityWaypointTestCase () + : TestCase ("Feed waypoints to mobility model") +{ +} + +void +LeoMobilityWaypointTestCase::DoRun (void) +{ + Ptr container = CreateObject (); + container->SetAttribute("File", StringValue ("contrib/leo/data/waypoints.txt")); + container->SetAttribute("LastTime", TimeValue (Time (1))); + + Ptr mobility = CreateObject (); + Waypoint wp; + while (container->GetNextSample (wp)) + { + mobility->AddWaypoint (wp); + } + + NS_TEST_ASSERT_MSG_EQ ((mobility->WaypointsLeft () > 0), true, "Reading waypoints from empty"); +} + +class LeoMobilityTestSuite : public TestSuite +{ +public: + LeoMobilityTestSuite (); +}; + +LeoMobilityTestSuite::LeoMobilityTestSuite () + : TestSuite ("leo-mobility", UNIT) +{ + // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER + AddTestCase (new LeoMobilityWaypointTestCase, TestCase::QUICK); +} + +// Do not forget to allocate an instance of this TestSuite +static LeoMobilityTestSuite leoMobilityTestSuite; diff --git a/utils/leo-input-fstream-container.cc b/utils/leo-input-fstream-container.cc index c67ca08..616147c 100644 --- a/utils/leo-input-fstream-container.cc +++ b/utils/leo-input-fstream-container.cc @@ -63,16 +63,19 @@ LeoWaypointInputFileStreamContainer::GetNextSample (Waypoint &sample) NS_ABORT_MSG ("Input stream is bad"); } - Time newLast = m_lastTime; - while (m_input && sample.time < m_lastTime) + sample.time = Time (0); + sample.position = Vector (0.0, 0.0, 0.0); + bool updated = false; + while (sample.time < m_lastTime && (m_input >> sample)) { - m_input >> sample; - newLast = sample.time; + updated = true; + } + if (updated) + { + m_lastTime = sample.time; } - bool res = (newLast != m_lastTime) && m_input; - m_lastTime = newLast; - return res; + return updated; } void diff --git a/wscript b/wscript index 8bc4582..d605332 100644 --- a/wscript +++ b/wscript @@ -31,6 +31,7 @@ def build(bld): 'test/isl-mock-channel-test-suite.cc', 'test/leo-mock-channel-test-suite.cc', 'test/leo-input-fstream-container-test-suite.cc', + 'test/leo-mobility-test-suite.cc', ] headers = bld(features='ns3header')