diff --git a/data/waypoints.txt b/data/waypoints.txt new file mode 100644 index 0000000..e800586 --- /dev/null +++ b/data/waypoints.txt @@ -0,0 +1,8 @@ +1.0s $ 1.0:2.0:3.0 +2.0s $ 1.0:2.0:3.0 +3.0s $ 1.0:2.0:3.0 +4.0s $ 1.0:2.0:3.0 +5.0s $ 1.0:2.0:3.0 +6.0s $ 1.0:2.0:3.0 +7.0s $ 1.0:2.0:3.0 +8.0s $ 1.0:2.0:3.0 diff --git a/test/leo-input-fstream-container-test-suite.cc b/test/leo-input-fstream-container-test-suite.cc index fe03a71..4a6ca85 100644 --- a/test/leo-input-fstream-container-test-suite.cc +++ b/test/leo-input-fstream-container-test-suite.cc @@ -32,9 +32,49 @@ LeoWaypointFileEmptyTestCase::DoRun (void) container->SetAttribute("LastTime", TimeValue (Time (1))); Waypoint wp; - bool res = container->GetNextSample(wp); + uint32_t i = 0; + while (container->GetNextSample (wp)) + { + i ++; + } - NS_TEST_ASSERT_MSG_EQ (res, false, "Reading from empty stream fails"); + NS_TEST_ASSERT_MSG_EQ ((i == 0), true, "Reading waypoints from empty"); +} + +class LeoWaypointSomeEntriesTestCase : public TestCase +{ +public: + LeoWaypointSomeEntriesTestCase (); + virtual ~LeoWaypointSomeEntriesTestCase (); + +private: + virtual void DoRun (void); +}; + +LeoWaypointSomeEntriesTestCase::LeoWaypointSomeEntriesTestCase () + : TestCase ("Test reading from non-empty file") +{ +} + +LeoWaypointSomeEntriesTestCase::~LeoWaypointSomeEntriesTestCase () +{ +} + +void +LeoWaypointSomeEntriesTestCase::DoRun (void) +{ + Ptr container = CreateObject (); + container->SetAttribute("File", StringValue ("contrib/leo/data/waypoints.txt")); + container->SetAttribute("LastTime", TimeValue (Time (1))); + Waypoint wp; + + uint32_t i = 0; + while (container->GetNextSample (wp)) + { + i ++; + } + + NS_TEST_ASSERT_MSG_EQ ((i > 0), true, "Reading from non-empty stream succeeds"); } class LeoWaypointsTestSuite : public TestSuite @@ -48,6 +88,7 @@ LeoWaypointsTestSuite::LeoWaypointsTestSuite () { // TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER AddTestCase (new LeoWaypointFileEmptyTestCase, TestCase::QUICK); + AddTestCase (new LeoWaypointSomeEntriesTestCase, TestCase::QUICK); } // Do not forget to allocate an instance of this TestSuite diff --git a/utils/leo-input-fstream-container.cc b/utils/leo-input-fstream-container.cc index 8c4365b..c67ca08 100644 --- a/utils/leo-input-fstream-container.cc +++ b/utils/leo-input-fstream-container.cc @@ -63,13 +63,16 @@ LeoWaypointInputFileStreamContainer::GetNextSample (Waypoint &sample) NS_ABORT_MSG ("Input stream is bad"); } - while (!m_input.eof () && sample.time < m_lastTime) + Time newLast = m_lastTime; + while (m_input && sample.time < m_lastTime) { m_input >> sample; + newLast = sample.time; } - m_lastTime = sample.time; + bool res = (newLast != m_lastTime) && m_input; + m_lastTime = newLast; - return m_input.good (); + return res; } void