src/internet-stack/ipv4-test.cc
changeset 5339 fee694e277da
parent 4571 2c9c600270e0
child 5919 b89ce2e9eed5
--- a/src/internet-stack/ipv4-test.cc	Thu Oct 01 12:38:12 2009 +0200
+++ b/src/internet-stack/ipv4-test.cc	Thu Oct 01 13:00:04 2009 +0200
@@ -12,12 +12,12 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
  *
  */
 /**
  * This is the test code for ipv4-l3-protocol.cc  
  */
-#ifdef RUN_SELF_TESTS
 
 #include "ns3/simulator.h"
 #include "ns3/test.h"
@@ -32,25 +32,38 @@
 
 namespace ns3 {
 
-
-class Ipv4L3ProtocolTest: public Test
+class Ipv4L3ProtocolTestCase : public TestCase
 {
 public:
-  virtual bool RunTests (void);
-  Ipv4L3ProtocolTest ();
+  /**
+   * \brief Constructor.
+   */
+  Ipv4L3ProtocolTestCase ();
+  /**
+   * \brief Destructor.
+   */
+  virtual
+  ~Ipv4L3ProtocolTestCase ();
+  /**
+   * \brief Run unit tests for this class.
+   * \return false if all tests have passed, false otherwise
+   */
+  virtual bool
+  DoRun (void);
 
 };
 
-
-Ipv4L3ProtocolTest::Ipv4L3ProtocolTest ()
-  : Test ("Ipv4L3Protocol") 
+Ipv4L3ProtocolTestCase::Ipv4L3ProtocolTestCase () :
+  TestCase ("Verify the IPv4 layer 3 protocol")
 {
 }
 
+Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase ()
+{
+}
 bool
-Ipv4L3ProtocolTest::RunTests (void)
+Ipv4L3ProtocolTestCase::DoRun (void)
 {
-  bool result = true;
   Ptr<Node> node = CreateObject<Node> ();
   Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
   Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
@@ -59,29 +72,41 @@
   interface->SetDevice (device);
   interface->SetNode (node);
   uint32_t index = ipv4->AddIpv4Interface (interface);
-  NS_TEST_ASSERT_EQUAL (index, 0);
+  NS_TEST_ASSERT_MSG_EQ (index, 0, "No interface should be found??");
   interface->SetUp ();
-  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1", "255.255.255.0");
+  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1",
+      "255.255.255.0");
   interface->AddAddress (ifaceAddr1);
-  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2", "255.255.255.0");
+  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2",
+      "255.255.255.0");
   interface->AddAddress (ifaceAddr2);
-  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1", "255.255.255.0");
+  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1",
+      "255.255.255.0");
   interface->AddAddress (ifaceAddr3);
-  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1", "255.255.255.0");
+  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1",
+      "255.255.255.0");
   interface->AddAddress (ifaceAddr4);
   uint32_t num = interface->GetNAddresses ();
-  NS_TEST_ASSERT_EQUAL (num, 4);
+  NS_TEST_ASSERT_MSG_EQ (num, 4, "Should find 4 interfaces??");
   interface->RemoveAddress (2);
   num = interface->GetNAddresses ();
-  NS_TEST_ASSERT_EQUAL (num, 3);
+  NS_TEST_ASSERT_MSG_EQ (num, 3, "Should find 3 interfaces??");
   Ipv4InterfaceAddress output = interface->GetAddress (2);
-  NS_TEST_ASSERT_EQUAL (ifaceAddr4, output);
-  
-  return result;
+  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
+      "The addresses should be identical");
+
+  return false;
 }
 
-static Ipv4L3ProtocolTest gIpv4L3ProtocolTest;
+static class IPv4L3ProtocolTestSuite : public TestSuite
+{
+public:
+  IPv4L3ProtocolTestSuite () :
+    TestSuite ("ipv4-protocol", UNIT)
+  {
+    AddTestCase (new Ipv4L3ProtocolTestCase ());
+  }
+} g_ipv4protocolTestSuite;
 
-}; // namespace ns3
-
-#endif /* RUN_SELF_TESTS */
+}
+; // namespace ns3