Merge
authorKirill Andreev <andreev@iitp.ru>
Mon, 04 May 2009 17:14:51 +0400
changeset 5006 48e46eef2bfb
parent 5005 8038200dac53 (current diff)
parent 5004 29928e8d1a1c (diff)
child 5007 d301d973792d
Merge
--- a/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-beacon-timing.cc	Mon May 04 17:14:51 2009 +0400
@@ -223,9 +223,9 @@
 }
 
 #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 @@
   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> packet = Create<Packet> ();
-  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
--- a/src/devices/mesh/dot11s/ie-dot11s-configuration.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-configuration.cc	Mon May 04 17:14:51 2009 +0400
@@ -197,9 +197,9 @@
 #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 result(true);
   IeConfiguration a;
-  Ptr<Packet> packet = Create<Packet> ();
-  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
--- a/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-peer-management.cc	Mon May 04 17:14:51 2009 +0400
@@ -159,9 +159,9 @@
       );
 }
 #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 @@
   {
     IePeerManagement a;
     a.SetPeerOpen (1);
-    Ptr<Packet> packet = Create<Packet> ();
-    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> packet = Create<Packet> ();
-    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> packet = Create<Packet> ();
-    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;
 }
--- a/src/devices/mesh/dot11s/ie-dot11s-perr.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-perr.cc	Mon May 04 17:14:51 2009 +0400
@@ -159,9 +159,9 @@
 #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 @@
   dest.destination = Mac48Address("01:02:03:04:05:06");
   dest.seqnum = 3;
   a.AddAddressUnit(dest);
-  Ptr<Packet> packet = Create<Packet> ();
-  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;
 }
 
--- a/src/devices/mesh/dot11s/ie-dot11s-prep.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-prep.cc	Mon May 04 17:14:51 2009 +0400
@@ -228,9 +228,9 @@
 #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 @@
   a.SetMetric (4321);
   a.SetOriginatorAddress (Mac48Address("33:00:22:00:11:00"));
   a.SetOriginatorSeqNumber (666);
-  // test roundtrip serialization
-  Ptr<Packet> packet = Create<Packet> ();
-  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;
 }
 
--- a/src/devices/mesh/dot11s/ie-dot11s-preq.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-preq.cc	Mon May 04 17:14:51 2009 +0400
@@ -433,9 +433,9 @@
 #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 @@
   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> packet = Create<Packet> ();
-  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;
 }
 
--- a/src/devices/mesh/dot11s/ie-dot11s-rann.cc	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/dot11s/ie-dot11s-rann.cc	Mon May 04 17:14:51 2009 +0400
@@ -187,9 +187,9 @@
 #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 @@
   a.IncrementMetric (2);
   NS_TEST_ASSERT_EQUAL (a.GetMetric(), 8);
   
-  // test roundtrip serialization
-  Ptr<Packet> packet = Create<Packet> ();
-  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
--- a/src/devices/mesh/wifi-information-element.h	Mon May 04 17:13:20 2009 +0400
+++ b/src/devices/mesh/wifi-information-element.h	Mon May 04 17:14:51 2009 +0400
@@ -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 @@
 
 /// 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 <typename IE> bool TestRoundtripSerialization (IE a);
+};
+
+template <typename IE> bool
+IeTest::TestRoundtripSerialization (IE a)
+{
+  bool result (true);
+  
+  Ptr<Packet> packet = Create<Packet> ();
+  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_ */