Add test for adding waypoints

This commit is contained in:
Tim Schubert 2020-07-07 20:26:38 +02:00
parent e1bca0b7d9
commit 737c9a49c7
3 changed files with 65 additions and 7 deletions

View file

@ -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<LeoWaypointInputFileStreamContainer> container = CreateObject<LeoWaypointInputFileStreamContainer> ();
container->SetAttribute("File", StringValue ("contrib/leo/data/waypoints.txt"));
container->SetAttribute("LastTime", TimeValue (Time (1)));
Ptr<WaypointMobilityModel> mobility = CreateObject<WaypointMobilityModel> ();
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;

View file

@ -63,16 +63,19 @@ LeoWaypointInputFileStreamContainer::GetNextSample (Waypoint &sample)
NS_ABORT_MSG ("Input stream is bad"); NS_ABORT_MSG ("Input stream is bad");
} }
Time newLast = m_lastTime; sample.time = Time (0);
while (m_input && sample.time < m_lastTime) sample.position = Vector (0.0, 0.0, 0.0);
bool updated = false;
while (sample.time < m_lastTime && (m_input >> sample))
{ {
m_input >> sample; updated = true;
newLast = sample.time; }
if (updated)
{
m_lastTime = sample.time;
} }
bool res = (newLast != m_lastTime) && m_input;
m_lastTime = newLast;
return res; return updated;
} }
void void

View file

@ -31,6 +31,7 @@ def build(bld):
'test/isl-mock-channel-test-suite.cc', 'test/isl-mock-channel-test-suite.cc',
'test/leo-mock-channel-test-suite.cc', 'test/leo-mock-channel-test-suite.cc',
'test/leo-input-fstream-container-test-suite.cc', 'test/leo-input-fstream-container-test-suite.cc',
'test/leo-mobility-test-suite.cc',
] ]
headers = bld(features='ns3header') headers = bld(features='ns3header')