mirror of
https://gitlab.ibr.cs.tu-bs.de/tschuber/ns-3-leo.git
synced 2025-06-08 18:13:57 +02:00
Refactor tests for brevity
This commit is contained in:
parent
37631d0758
commit
4c008e32f0
5 changed files with 112 additions and 139 deletions
|
@ -14,137 +14,99 @@ using namespace ns3;
|
|||
class LeoMockChannelTransmitUnknownTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoMockChannelTransmitUnknownTestCase ();
|
||||
virtual ~LeoMockChannelTransmitUnknownTestCase ();
|
||||
LeoMockChannelTransmitUnknownTestCase () : TestCase ("transmission from unknown source fails") {}
|
||||
virtual ~LeoMockChannelTransmitUnknownTestCase () {}
|
||||
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
virtual void DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
Address destAddr;
|
||||
Time txTime;
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
bool result = channel->TransmitStart (p, 10000, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, false, "unknown source fails to deliver");
|
||||
}
|
||||
};
|
||||
|
||||
LeoMockChannelTransmitUnknownTestCase::LeoMockChannelTransmitUnknownTestCase ()
|
||||
: TestCase ("Test transmission to unkown destination")
|
||||
{
|
||||
}
|
||||
|
||||
LeoMockChannelTransmitUnknownTestCase::~LeoMockChannelTransmitUnknownTestCase ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
LeoMockChannelTransmitUnknownTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
Address destAddr;
|
||||
Time txTime;
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
bool result = channel->TransmitStart (p, 10000, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, false, "Unknown source fails to deliver");
|
||||
}
|
||||
|
||||
class LeoMockChannelTransmitKnownTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoMockChannelTransmitKnownTestCase ();
|
||||
virtual ~LeoMockChannelTransmitKnownTestCase ();
|
||||
|
||||
LeoMockChannelTransmitKnownTestCase () : TestCase ("transmission from known source succeeds") {}
|
||||
virtual ~LeoMockChannelTransmitKnownTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
virtual void DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
|
||||
Ptr<Node> srcNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> srcDev = CreateObject<LeoMockNetDevice> ();
|
||||
srcDev->SetNode (srcNode);
|
||||
srcDev->SetDeviceType (LeoMockNetDevice::GND);
|
||||
srcDev->SetAddress (Mac48Address::Allocate ());
|
||||
int32_t srcId = channel->Attach (srcDev);
|
||||
|
||||
Ptr<Node> dstNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> dstDev = CreateObject<LeoMockNetDevice> ();
|
||||
dstDev->SetNode (dstNode);
|
||||
dstDev->SetDeviceType (LeoMockNetDevice::SAT);
|
||||
dstDev->SetAddress (Mac48Address::Allocate ());
|
||||
channel->Attach (dstDev);
|
||||
|
||||
Address destAddr = dstDev->GetAddress ();
|
||||
Time txTime;
|
||||
bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, true, "known source does not deliver");
|
||||
}
|
||||
};
|
||||
|
||||
LeoMockChannelTransmitKnownTestCase::LeoMockChannelTransmitKnownTestCase ()
|
||||
: TestCase ("Test transmission to known destination")
|
||||
{
|
||||
}
|
||||
|
||||
LeoMockChannelTransmitKnownTestCase::~LeoMockChannelTransmitKnownTestCase ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
LeoMockChannelTransmitKnownTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
|
||||
Ptr<Node> srcNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> srcDev = CreateObject<LeoMockNetDevice> ();
|
||||
srcDev->SetNode (srcNode);
|
||||
srcDev->SetDeviceType (LeoMockNetDevice::GND);
|
||||
srcDev->SetAddress (Mac48Address::Allocate ());
|
||||
int32_t srcId = channel->Attach (srcDev);
|
||||
|
||||
Ptr<Node> dstNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> dstDev = CreateObject<LeoMockNetDevice> ();
|
||||
dstDev->SetNode (dstNode);
|
||||
dstDev->SetDeviceType (LeoMockNetDevice::SAT);
|
||||
dstDev->SetAddress (Mac48Address::Allocate ());
|
||||
channel->Attach (dstDev);
|
||||
|
||||
Address destAddr = dstDev->GetAddress ();
|
||||
Time txTime;
|
||||
bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, true, "Known source delivers");
|
||||
}
|
||||
|
||||
class LeoMockChannelTransmitSpaceGroundTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoMockChannelTransmitSpaceGroundTestCase ();
|
||||
virtual ~LeoMockChannelTransmitSpaceGroundTestCase ();
|
||||
|
||||
LeoMockChannelTransmitSpaceGroundTestCase () : TestCase ("space to ground transmission succeeds") {}
|
||||
virtual ~LeoMockChannelTransmitSpaceGroundTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void);
|
||||
virtual void DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
|
||||
Ptr<Node> srcNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> srcDev = CreateObject<LeoMockNetDevice> ();
|
||||
srcDev->SetNode (srcNode);
|
||||
srcDev->SetDeviceType (LeoMockNetDevice::SAT);
|
||||
srcDev->SetAddress (Mac48Address::Allocate ());
|
||||
int32_t srcId = channel->Attach (srcDev);
|
||||
|
||||
Ptr<Node> dstNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> dstDev = CreateObject<LeoMockNetDevice> ();
|
||||
dstDev->SetNode (dstNode);
|
||||
dstDev->SetDeviceType (LeoMockNetDevice::GND);
|
||||
dstDev->SetAddress (Mac48Address::Allocate ());
|
||||
channel->Attach (dstDev);
|
||||
|
||||
Address destAddr = dstDev->GetAddress ();
|
||||
Time txTime;
|
||||
bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, true, "space to ground transmission failed");
|
||||
}
|
||||
};
|
||||
|
||||
LeoMockChannelTransmitSpaceGroundTestCase::LeoMockChannelTransmitSpaceGroundTestCase ()
|
||||
: TestCase ("Test transmission to known destination")
|
||||
{
|
||||
}
|
||||
|
||||
LeoMockChannelTransmitSpaceGroundTestCase::~LeoMockChannelTransmitSpaceGroundTestCase ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
LeoMockChannelTransmitSpaceGroundTestCase::DoRun (void)
|
||||
{
|
||||
Ptr<LeoMockChannel> channel = CreateObject<LeoMockChannel> ();
|
||||
channel->SetAttribute ("PropagationDelay", StringValue ("ns3::ConstantSpeedPropagationDelayModel"));
|
||||
channel->SetAttribute ("PropagationLoss", StringValue ("ns3::LeoPropagationLossModel"));
|
||||
|
||||
Packet *packet = new Packet ();
|
||||
Ptr<Packet> p = Ptr<Packet>(packet);
|
||||
|
||||
Ptr<Node> srcNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> srcDev = CreateObject<LeoMockNetDevice> ();
|
||||
srcDev->SetNode (srcNode);
|
||||
srcDev->SetDeviceType (LeoMockNetDevice::SAT);
|
||||
srcDev->SetAddress (Mac48Address::Allocate ());
|
||||
int32_t srcId = channel->Attach (srcDev);
|
||||
|
||||
Ptr<Node> dstNode = CreateObject<Node> ();
|
||||
Ptr<LeoMockNetDevice> dstDev = CreateObject<LeoMockNetDevice> ();
|
||||
dstDev->SetNode (dstNode);
|
||||
dstDev->SetDeviceType (LeoMockNetDevice::GND);
|
||||
dstDev->SetAddress (Mac48Address::Allocate ());
|
||||
channel->Attach (dstDev);
|
||||
|
||||
Address destAddr = dstDev->GetAddress ();
|
||||
Time txTime;
|
||||
bool result = channel->TransmitStart (p, srcId, destAddr, txTime);
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ (result, true, "Space to ground destination delivers");
|
||||
}
|
||||
|
||||
class LeoMockChannelTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
|
@ -154,11 +116,9 @@ public:
|
|||
LeoMockChannelTestSuite::LeoMockChannelTestSuite ()
|
||||
: TestSuite ("leo-mock-channel", UNIT)
|
||||
{
|
||||
// TestDuration for TestCase can be QUICK, EXTENSIVE or TAKES_FOREVER
|
||||
AddTestCase (new LeoMockChannelTransmitUnknownTestCase, TestCase::QUICK);
|
||||
AddTestCase (new LeoMockChannelTransmitKnownTestCase, TestCase::QUICK);
|
||||
AddTestCase (new LeoMockChannelTransmitSpaceGroundTestCase, TestCase::QUICK);
|
||||
}
|
||||
|
||||
// Do not forget to allocate an instance of this TestSuite
|
||||
static LeoMockChannelTestSuite islMockChannelTestSuite;
|
||||
|
|
|
@ -14,7 +14,7 @@ using namespace ns3;
|
|||
class LeoOrbitSpeedTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitSpeedTestCase () : TestCase ("Test speed for 0 altitude") {}
|
||||
LeoOrbitSpeedTestCase () : TestCase ("speed at 0 altitude is earth rotation speed") {}
|
||||
virtual ~LeoOrbitSpeedTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void)
|
||||
|
@ -22,14 +22,14 @@ private:
|
|||
Ptr<LeoCircularOrbitMobilityModel> mob = CreateObject<LeoCircularOrbitMobilityModel> ();
|
||||
mob->SetAttribute ("Altitude", DoubleValue (0.0));
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "Unexpected velocity at earths surface");
|
||||
NS_TEST_ASSERT_MSG_EQ ((uint64_t) mob->GetSpeed (), (uint64_t) 7909.79, "postion at 0 altitude is on surface");
|
||||
}
|
||||
};
|
||||
|
||||
class LeoOrbitPositionTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitPositionTestCase () : TestCase ("Test position for 0 altitude and 1.0 inclination") {}
|
||||
LeoOrbitPositionTestCase () : TestCase ("position is on surface") {}
|
||||
virtual ~LeoOrbitPositionTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void)
|
||||
|
@ -38,21 +38,21 @@ private:
|
|||
mob->SetAttribute ("Altitude", DoubleValue (0.0));
|
||||
mob->SetAttribute ("Inclination", DoubleValue (1.0));
|
||||
|
||||
NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "Unexpected position on earths surface for 1 deg inclination");
|
||||
NS_TEST_ASSERT_MSG_EQ_TOL (mob->GetPosition ().GetLength() / 1000, LEO_EARTH_RAD_KM, 0.1, "unexpected position on earths surface for 1 deg inclination");
|
||||
}
|
||||
};
|
||||
|
||||
class LeoOrbitProgressTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitProgressTestCase () : TestCase ("Test position shoudl not be the same after some time") {}
|
||||
LeoOrbitProgressTestCase () : TestCase ("position changes over time") {}
|
||||
virtual ~LeoOrbitProgressTestCase () {}
|
||||
private:
|
||||
void TestLengthPosition (double expl, double expx, Ptr<LeoCircularOrbitMobilityModel> mob)
|
||||
{
|
||||
Vector pos = mob->GetPosition ();
|
||||
NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (pos.GetLength () / 1000, expl, 0.001, "Distance to earth should be the same", __FILE__, __LINE__);
|
||||
NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "Position should not be equal", __FILE__, __LINE__);
|
||||
NS_TEST_EXPECT_MSG_NE_INTERNAL (pos.x, expx, "position should not be equal", __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
virtual void DoRun (void)
|
||||
|
@ -72,7 +72,7 @@ private:
|
|||
class LeoOrbitLatitudeTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitLatitudeTestCase () : TestCase ("Test offset between neighboring satellites planes") {}
|
||||
LeoOrbitLatitudeTestCase () : TestCase ("neighboring satellite planes have offset") {}
|
||||
virtual ~LeoOrbitLatitudeTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void)
|
||||
|
@ -86,14 +86,14 @@ private:
|
|||
mob->SetPosition (Vector3D (20.0, 0, 0));
|
||||
Vector pos2 = mob->GetPosition ();
|
||||
|
||||
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position");
|
||||
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite planes should have different position");
|
||||
}
|
||||
};
|
||||
|
||||
class LeoOrbitOffsetTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitOffsetTestCase () : TestCase ("Test offset between neighboring satellites") {}
|
||||
LeoOrbitOffsetTestCase () : TestCase ("neighboring satellites have offset") {}
|
||||
virtual ~LeoOrbitOffsetTestCase () {}
|
||||
private:
|
||||
virtual void DoRun (void)
|
||||
|
@ -107,21 +107,19 @@ private:
|
|||
mob->SetPosition (Vector3D (0, 20.0, 0));
|
||||
Vector pos2 = mob->GetPosition ();
|
||||
|
||||
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "Neighboring satellite should have different position");
|
||||
NS_TEST_ASSERT_MSG_NE (pos1.x, pos2.x, "neighboring satellite should have different position");
|
||||
}
|
||||
};
|
||||
|
||||
class LeoOrbitTracingTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
LeoOrbitTracingTestCase () : TestCase ("Test tracing of position changes") {}
|
||||
LeoOrbitTracingTestCase () : TestCase ("position changes are traced") {}
|
||||
virtual ~LeoOrbitTracingTestCase () {}
|
||||
static void CourseChange (std::string context, Ptr<const MobilityModel> position)
|
||||
{
|
||||
Vector pos = position->GetPosition ();
|
||||
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
|
||||
<< ", z=" << pos.z << std::endl;
|
||||
}
|
||||
|
||||
static uint64_t traced;
|
||||
|
||||
static void CourseChange (std::string context, Ptr<const MobilityModel> position);
|
||||
private:
|
||||
virtual void DoRun (void)
|
||||
{
|
||||
|
@ -142,13 +140,27 @@ private:
|
|||
|
||||
Config::Connect ("/NodeList/*/$ns3::MobilityModel/CourseChange",
|
||||
MakeCallback (&CourseChange));
|
||||
traced = 0;
|
||||
|
||||
Simulator::Stop (Seconds (100.0));
|
||||
Simulator::Run ();
|
||||
|
||||
NS_TEST_ASSERT_MSG_GT (traced, 8, "position not every time");
|
||||
|
||||
Simulator::Destroy ();
|
||||
}
|
||||
};
|
||||
|
||||
uint64_t LeoOrbitTracingTestCase::traced = 0;
|
||||
|
||||
void LeoOrbitTracingTestCase::CourseChange (std::string context, Ptr<const MobilityModel> position)
|
||||
{
|
||||
traced ++;
|
||||
Vector pos = position->GetPosition ();
|
||||
std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
|
||||
<< ", z=" << pos.z << std::endl;
|
||||
}
|
||||
|
||||
|
||||
class LeoOrbitTestSuite : TestSuite
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue