Conform ipv4-test with the new test suite
authorfmoatamr
Thu Oct 01 13:00:04 2009 +0200 (4 months ago)
changeset 5339fee694e277da
parent 5338 edf753f423d1
child 5341 586ce4339aab
Conform ipv4-test with the new test suite
src/internet-stack/ipv4-l3-protocol.h
src/internet-stack/ipv4-test.cc
src/internet-stack/ipv6-test.cc
     1.1 --- a/src/internet-stack/ipv4-l3-protocol.h	Thu Oct 01 12:38:12 2009 +0200
     1.2 +++ b/src/internet-stack/ipv4-l3-protocol.h	Thu Oct 01 13:00:04 2009 +0200
     1.3 @@ -185,7 +185,7 @@
     1.4     */
     1.5    virtual void NotifyNewAggregate ();
     1.6  private:
     1.7 -  friend class Ipv4L3ProtocolTest;
     1.8 +  friend class Ipv4L3ProtocolTestCase;
     1.9    Ipv4L3Protocol(const Ipv4L3Protocol &);
    1.10    Ipv4L3Protocol &operator = (const Ipv4L3Protocol &);
    1.11  
     2.1 --- a/src/internet-stack/ipv4-test.cc	Thu Oct 01 12:38:12 2009 +0200
     2.2 +++ b/src/internet-stack/ipv4-test.cc	Thu Oct 01 13:00:04 2009 +0200
     2.3 @@ -12,12 +12,12 @@
     2.4   * You should have received a copy of the GNU General Public License
     2.5   * along with this program; if not, write to the Free Software
     2.6   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.7 + * Author: Faker Moatamri <faker.moatamri@sophia.inria.fr>
     2.8   *
     2.9   */
    2.10  /**
    2.11   * This is the test code for ipv4-l3-protocol.cc  
    2.12   */
    2.13 -#ifdef RUN_SELF_TESTS
    2.14  
    2.15  #include "ns3/simulator.h"
    2.16  #include "ns3/test.h"
    2.17 @@ -32,25 +32,38 @@
    2.18  
    2.19  namespace ns3 {
    2.20  
    2.21 -
    2.22 -class Ipv4L3ProtocolTest: public Test
    2.23 +class Ipv4L3ProtocolTestCase : public TestCase
    2.24  {
    2.25  public:
    2.26 -  virtual bool RunTests (void);
    2.27 -  Ipv4L3ProtocolTest ();
    2.28 +  /**
    2.29 +   * \brief Constructor.
    2.30 +   */
    2.31 +  Ipv4L3ProtocolTestCase ();
    2.32 +  /**
    2.33 +   * \brief Destructor.
    2.34 +   */
    2.35 +  virtual
    2.36 +  ~Ipv4L3ProtocolTestCase ();
    2.37 +  /**
    2.38 +   * \brief Run unit tests for this class.
    2.39 +   * \return false if all tests have passed, false otherwise
    2.40 +   */
    2.41 +  virtual bool
    2.42 +  DoRun (void);
    2.43  
    2.44  };
    2.45  
    2.46 -
    2.47 -Ipv4L3ProtocolTest::Ipv4L3ProtocolTest ()
    2.48 -  : Test ("Ipv4L3Protocol") 
    2.49 +Ipv4L3ProtocolTestCase::Ipv4L3ProtocolTestCase () :
    2.50 +  TestCase ("Verify the IPv4 layer 3 protocol")
    2.51  {
    2.52  }
    2.53  
    2.54 +Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase ()
    2.55 +{
    2.56 +}
    2.57  bool
    2.58 -Ipv4L3ProtocolTest::RunTests (void)
    2.59 +Ipv4L3ProtocolTestCase::DoRun (void)
    2.60  {
    2.61 -  bool result = true;
    2.62    Ptr<Node> node = CreateObject<Node> ();
    2.63    Ptr<Ipv4L3Protocol> ipv4 = CreateObject<Ipv4L3Protocol> ();
    2.64    Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
    2.65 @@ -59,29 +72,41 @@
    2.66    interface->SetDevice (device);
    2.67    interface->SetNode (node);
    2.68    uint32_t index = ipv4->AddIpv4Interface (interface);
    2.69 -  NS_TEST_ASSERT_EQUAL (index, 0);
    2.70 +  NS_TEST_ASSERT_MSG_EQ (index, 0, "No interface should be found??");
    2.71    interface->SetUp ();
    2.72 -  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1", "255.255.255.0");
    2.73 +  Ipv4InterfaceAddress ifaceAddr1 = Ipv4InterfaceAddress ("192.168.0.1",
    2.74 +      "255.255.255.0");
    2.75    interface->AddAddress (ifaceAddr1);
    2.76 -  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2", "255.255.255.0");
    2.77 +  Ipv4InterfaceAddress ifaceAddr2 = Ipv4InterfaceAddress ("192.168.0.2",
    2.78 +      "255.255.255.0");
    2.79    interface->AddAddress (ifaceAddr2);
    2.80 -  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1", "255.255.255.0");
    2.81 +  Ipv4InterfaceAddress ifaceAddr3 = Ipv4InterfaceAddress ("10.30.0.1",
    2.82 +      "255.255.255.0");
    2.83    interface->AddAddress (ifaceAddr3);
    2.84 -  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1", "255.255.255.0");
    2.85 +  Ipv4InterfaceAddress ifaceAddr4 = Ipv4InterfaceAddress ("250.0.0.1",
    2.86 +      "255.255.255.0");
    2.87    interface->AddAddress (ifaceAddr4);
    2.88    uint32_t num = interface->GetNAddresses ();
    2.89 -  NS_TEST_ASSERT_EQUAL (num, 4);
    2.90 +  NS_TEST_ASSERT_MSG_EQ (num, 4, "Should find 4 interfaces??");
    2.91    interface->RemoveAddress (2);
    2.92    num = interface->GetNAddresses ();
    2.93 -  NS_TEST_ASSERT_EQUAL (num, 3);
    2.94 +  NS_TEST_ASSERT_MSG_EQ (num, 3, "Should find 3 interfaces??");
    2.95    Ipv4InterfaceAddress output = interface->GetAddress (2);
    2.96 -  NS_TEST_ASSERT_EQUAL (ifaceAddr4, output);
    2.97 -  
    2.98 -  return result;
    2.99 +  NS_TEST_ASSERT_MSG_EQ (ifaceAddr4, output,
   2.100 +      "The addresses should be identical");
   2.101 +
   2.102 +  return false;
   2.103  }
   2.104  
   2.105 -static Ipv4L3ProtocolTest gIpv4L3ProtocolTest;
   2.106 +static class IPv4L3ProtocolTestSuite : public TestSuite
   2.107 +{
   2.108 +public:
   2.109 +  IPv4L3ProtocolTestSuite () :
   2.110 +    TestSuite ("ipv4-protocol", UNIT)
   2.111 +  {
   2.112 +    AddTestCase (new Ipv4L3ProtocolTestCase ());
   2.113 +  }
   2.114 +} g_ipv4protocolTestSuite;
   2.115  
   2.116 -}; // namespace ns3
   2.117 -
   2.118 -#endif /* RUN_SELF_TESTS */
   2.119 +}
   2.120 +; // namespace ns3
     3.1 --- a/src/internet-stack/ipv6-test.cc	Thu Oct 01 12:38:12 2009 +0200
     3.2 +++ b/src/internet-stack/ipv6-test.cc	Thu Oct 01 13:00:04 2009 +0200
     3.3 @@ -146,5 +146,5 @@
     3.4    {
     3.5      AddTestCase (new Ipv6L3ProtocolTestCase ());
     3.6    }
     3.7 -} g_IPv6L3ProtocolTestSuite;
     3.8 +} g_ipv6protocolTestSuite;
     3.9  } // namespace ns3
    3.10 \ No newline at end of file