diff --git a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc index cdb45fe64..89d698785 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc @@ -223,9 +223,9 @@ bool operator== (const IeBeaconTiming & a, const IeBeaconTiming& b) } #ifdef RUN_SELF_TESTS -struct IeBeaconTimingBist : public Test +struct IeBeaconTimingBist : public IeTest { - IeBeaconTimingBist () : Test ("Mesh/802.11s/IE/BeaconTiming") {} + IeBeaconTimingBist () : IeTest ("Mesh/802.11s/IE/BeaconTiming") {} virtual bool RunTests(); }; @@ -241,17 +241,8 @@ bool IeBeaconTimingBist::RunTests () a.IeBeaconTiming::AddNeighboursTimingElementUnit (2,Seconds(2.0), Seconds(3.0)); a.IeBeaconTiming::AddNeighboursTimingElementUnit (3,Seconds(3.0), Seconds(2.0)); a.IeBeaconTiming::AddNeighboursTimingElementUnit (4,Seconds(4.0), Seconds(1.0)); - Ptr packet = Create (); - packet->AddHeader(a); - IeBeaconTiming b; - packet->RemoveHeader(b); - NS_TEST_ASSERT_EQUAL (a, b); - //Test Find First - packet->AddHeader (a); - IeBeaconTiming c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + + result = TestRoundtripSerialization (a); return result; } #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-configuration.cc b/src/devices/mesh/dot11s/ie-dot11s-configuration.cc index 86d33fd0c..50d764be0 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-configuration.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-configuration.cc @@ -197,9 +197,9 @@ bool operator== (const IeConfiguration & a, const IeConfiguration & b) #ifdef RUN_SELF_TESTS /// Built-in self test for IePreq -struct IeConfigurationBist : public Test +struct IeConfigurationBist : public IeTest { - IeConfigurationBist () : Test ("Mesh/802.11s/IE/Configuration") {} + IeConfigurationBist () : IeTest ("Mesh/802.11s/IE/Configuration") {} virtual bool RunTests(); }; @@ -210,18 +210,8 @@ bool IeConfigurationBist::RunTests () { bool result(true); IeConfiguration a; - Ptr packet = Create (); - packet->AddHeader (a); - IeConfiguration b; - packet->RemoveHeader (b); - NS_TEST_ASSERT_EQUAL (a, b); - // test FindFirst() - packet->AddHeader (a); - IeConfiguration c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); - + + result = TestRoundtripSerialization (a); return result; } #endif diff --git a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc index 90f4e089a..9bf6ce332 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc @@ -159,9 +159,9 @@ bool operator== (const IePeerManagement & a, const IePeerManagement & b) ); } #ifdef RUN_SELF_TESTS -struct IePeerManagementBist : public Test +struct IePeerManagementBist : public IeTest { - IePeerManagementBist () : Test ("Mesh/802.11s/IE/PeerManagement") {} + IePeerManagementBist () : IeTest ("Mesh/802.11s/IE/PeerManagement") {} virtual bool RunTests(); }; @@ -174,44 +174,17 @@ bool IePeerManagementBist::RunTests () { IePeerManagement a; a.SetPeerOpen (1); - Ptr packet = Create (); - packet->AddHeader(a); - IePeerManagement b; - packet->RemoveHeader(b); - NS_TEST_ASSERT_EQUAL (a, b); - packet->AddHeader (a); - IePeerManagement c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + result = result && TestRoundtripSerialization (a); } { IePeerManagement a; a.SetPeerConfirm (1,2); - Ptr packet = Create (); - packet->AddHeader(a); - IePeerManagement b; - packet->RemoveHeader(b); - NS_TEST_ASSERT_EQUAL (a, b); - packet->AddHeader (a); - IePeerManagement c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + result = result && TestRoundtripSerialization (a); } { IePeerManagement a; a.SetPeerClose (1, 2, REASON11S_MESH_CONFIGURATION_POLICY_VIOLATION); - Ptr packet = Create (); - packet->AddHeader(a); - IePeerManagement b; - packet->RemoveHeader(b); - NS_TEST_ASSERT_EQUAL (a, b); - packet->AddHeader (a); - IePeerManagement c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + result = result && TestRoundtripSerialization (a); } return result; } diff --git a/src/devices/mesh/dot11s/ie-dot11s-perr.cc b/src/devices/mesh/dot11s/ie-dot11s-perr.cc index 1a6584f24..ee379d12d 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-perr.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-perr.cc @@ -159,9 +159,9 @@ bool operator== (const IePerr & a, const IePerr & b) #ifdef RUN_SELF_TESTS /// Built-in self test for IePreq -struct IePerrBist : public Test +struct IePerrBist : public IeTest { - IePerrBist () : Test ("Mesh/802.11s/IE/PERR") {} + IePerrBist () : IeTest ("Mesh/802.11s/IE/PERR") {} virtual bool RunTests(); }; @@ -183,19 +183,12 @@ bool IePerrBist::RunTests () dest.destination = Mac48Address("01:02:03:04:05:06"); dest.seqnum = 3; a.AddAddressUnit(dest); - Ptr packet = Create (); - packet->AddHeader (a); - IePerr b; - packet->RemoveHeader (b); - NS_TEST_ASSERT_EQUAL (a, b); + + IePerr b = a; b.Merge(a); NS_TEST_ASSERT_EQUAL (a, b); - // test FindFirst() - packet->AddHeader (a); - IePerr c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + + result = result && TestRoundtripSerialization (a); return result; } diff --git a/src/devices/mesh/dot11s/ie-dot11s-prep.cc b/src/devices/mesh/dot11s/ie-dot11s-prep.cc index 3d9f8c351..6913537c9 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-prep.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-prep.cc @@ -228,9 +228,9 @@ bool operator== (const IePrep & a, const IePrep & b) #ifdef RUN_SELF_TESTS /// Built-in self test for IePrep -struct IePrepBist : public Test +struct IePrepBist : public IeTest { - IePrepBist () : Test ("Mesh/802.11s/IE/PREP") {}; + IePrepBist () : IeTest ("Mesh/802.11s/IE/PREP") {}; virtual bool RunTests(); }; @@ -252,18 +252,8 @@ bool IePrepBist::RunTests () a.SetMetric (4321); a.SetOriginatorAddress (Mac48Address("33:00:22:00:11:00")); a.SetOriginatorSeqNumber (666); - // test roundtrip serialization - Ptr packet = Create (); - packet->AddHeader (a); - IePrep b; - packet->RemoveHeader (b); - NS_TEST_ASSERT_EQUAL (a, b); - // test FindFirst() - packet->AddHeader (a); - IePrep c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); + + result = result && TestRoundtripSerialization (a); return result; } diff --git a/src/devices/mesh/dot11s/ie-dot11s-preq.cc b/src/devices/mesh/dot11s/ie-dot11s-preq.cc index aa55538bf..344f3e04f 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-preq.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-preq.cc @@ -433,9 +433,9 @@ IePreq::MayAddAddress (Mac48Address originator) #ifdef RUN_SELF_TESTS /// Built-in self test for IePreq -struct IePreqBist : public Test +struct IePreqBist : public IeTest { - IePreqBist () : Test ("Mesh/802.11s/IE/PREQ") {} + IePreqBist () : IeTest ("Mesh/802.11s/IE/PREQ") {} virtual bool RunTests(); }; @@ -456,21 +456,8 @@ bool IePreqBist::RunTests () a.SetLifetime (4); a.AddDestinationAddressElement (false, false, Mac48Address("11:11:11:11:11:11"), 5); a.AddDestinationAddressElement (false, false, Mac48Address("22:22:22:22:22:22"), 6); - - // test roundtrip serialization - Ptr packet = Create (); - packet->AddHeader (a); - IePreq b; - packet->RemoveHeader (b); - NS_TEST_ASSERT_EQUAL (a, b); - - // test FindFirst() - packet->AddHeader (a); - IePreq c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); - + + result = result && TestRoundtripSerialization (a); return result; } diff --git a/src/devices/mesh/dot11s/ie-dot11s-rann.cc b/src/devices/mesh/dot11s/ie-dot11s-rann.cc index 4b40006d4..d1e010252 100644 --- a/src/devices/mesh/dot11s/ie-dot11s-rann.cc +++ b/src/devices/mesh/dot11s/ie-dot11s-rann.cc @@ -187,9 +187,9 @@ operator== (const IeRann & a, const IeRann & b) #ifdef RUN_SELF_TESTS /// Built-in self test for IeRann -struct IeRannBist : public Test +struct IeRannBist : public IeTest { - IeRannBist () : Test ("Mesh/802.11s/IE/RANN") {} + IeRannBist () : IeTest ("Mesh/802.11s/IE/RANN") {} virtual bool RunTests(); }; @@ -214,20 +214,7 @@ bool IeRannBist::RunTests () a.IncrementMetric (2); NS_TEST_ASSERT_EQUAL (a.GetMetric(), 8); - // test roundtrip serialization - Ptr packet = Create (); - packet->AddHeader (a); - IeRann b; - packet->RemoveHeader (b); - NS_TEST_ASSERT_EQUAL (a, b); - - // test FindFirst() - packet->AddHeader (a); - IeRann c; - bool ok = c.FindFirst(packet); - NS_TEST_ASSERT (ok); - NS_TEST_ASSERT_EQUAL (a, c); - + result = result && TestRoundtripSerialization (a); return result; } #endif // RUN_SELF_TESTS diff --git a/src/devices/mesh/wifi-information-element.h b/src/devices/mesh/wifi-information-element.h index 233f9849f..bee361338 100644 --- a/src/devices/mesh/wifi-information-element.h +++ b/src/devices/mesh/wifi-information-element.h @@ -23,6 +23,8 @@ #include "ns3/header.h" #include "ns3/ref-count-base.h" +#include "ns3/test.h" +#include "ns3/packet.h" namespace ns3 { class Packet; @@ -162,6 +164,36 @@ protected: /// Compare information elements using Element ID bool operator< (WifiInformationElement const & a, WifiInformationElement const & b); - + +#ifdef RUN_SELF_TESTS +/// Generic test of information element +class IeTest : public Test +{ +public: + IeTest (const char * name) : Test (name) {} + /// Test roundtrip serialization + template bool TestRoundtripSerialization (IE a); +}; + +template bool +IeTest::TestRoundtripSerialization (IE a) +{ + bool result (true); + + Ptr packet = Create (); + packet->AddHeader (a); + IE b; + packet->RemoveHeader (b); + NS_TEST_ASSERT_EQUAL (a, b); + packet->AddHeader (a); + IE c; + bool ok = c.FindFirst(packet); + NS_TEST_ASSERT (ok); + NS_TEST_ASSERT_EQUAL (a, c); + + return result; +} +#endif + } // namespace ns3 #endif /* WIFIINFORMATIONELEMENT_H_ */