mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 10:03:58 +02:00
Add test for non-empty waypoint file
This commit is contained in:
parent
42787c2b41
commit
e1bca0b7d9
3 changed files with 57 additions and 5 deletions
8
data/waypoints.txt
Normal file
8
data/waypoints.txt
Normal file
|
@ -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
|
|
@ -32,9 +32,49 @@ LeoWaypointFileEmptyTestCase::DoRun (void)
|
||||||
container->SetAttribute("LastTime", TimeValue (Time (1)));
|
container->SetAttribute("LastTime", TimeValue (Time (1)));
|
||||||
Waypoint wp;
|
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<LeoWaypointInputFileStreamContainer> container = CreateObject<LeoWaypointInputFileStreamContainer> ();
|
||||||
|
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
|
class LeoWaypointsTestSuite : public TestSuite
|
||||||
|
@ -48,6 +88,7 @@ LeoWaypointsTestSuite::LeoWaypointsTestSuite ()
|
||||||
{
|
{
|
||||||
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
|
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
|
||||||
AddTestCase (new LeoWaypointFileEmptyTestCase, TestCase::QUICK);
|
AddTestCase (new LeoWaypointFileEmptyTestCase, TestCase::QUICK);
|
||||||
|
AddTestCase (new LeoWaypointSomeEntriesTestCase, TestCase::QUICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not forget to allocate an instance of this TestSuite
|
// Do not forget to allocate an instance of this TestSuite
|
||||||
|
|
|
@ -63,13 +63,16 @@ LeoWaypointInputFileStreamContainer::GetNextSample (Waypoint &sample)
|
||||||
NS_ABORT_MSG ("Input stream is bad");
|
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;
|
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
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue