Conform ipv6-test with the new test suite
authorfmoatamr
Thu Oct 01 12:38:12 2009 +0200 (4 months ago)
changeset 5338edf753f423d1
parent 5337 adf71e696e17
child 5339 fee694e277da
child 5340 9ca7ee51d883
Conform ipv6-test with the new test suite
src/internet-stack/ipv6-l3-protocol.h
src/internet-stack/ipv6-test.cc
     1.1 --- a/src/internet-stack/ipv6-l3-protocol.h	Thu Oct 01 12:06:03 2009 +0200
     1.2 +++ b/src/internet-stack/ipv6-l3-protocol.h	Thu Oct 01 12:38:12 2009 +0200
     1.3 @@ -334,7 +334,7 @@
     1.4  
     1.5    private:
     1.6      /* for unit-tests */
     1.7 -    friend class Ipv6L3ProtocolTest;
     1.8 +    friend class Ipv6L3ProtocolTestCase;
     1.9  
    1.10      typedef std::list<Ptr<Ipv6Interface> > Ipv6InterfaceList;
    1.11      typedef std::list<Ptr<Ipv6RawSocketImpl> > SocketList;
     2.1 --- a/src/internet-stack/ipv6-test.cc	Thu Oct 01 12:06:03 2009 +0200
     2.2 +++ b/src/internet-stack/ipv6-test.cc	Thu Oct 01 12:38:12 2009 +0200
     2.3 @@ -15,11 +15,9 @@
     2.4   * along with this program; if not, write to the Free Software
     2.5   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.6   *
     2.7 - * Author: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
     2.8 + * Authors: Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
     2.9 + *         Faker Moatamri <faker.moatamri@sophia.inria.fr>
    2.10   */
    2.11 -
    2.12 -#ifdef RUN_SELF_TESTS
    2.13 -
    2.14  #include "ns3/simulator.h"
    2.15  #include "ns3/test.h"
    2.16  #include "ns3/log.h"
    2.17 @@ -32,44 +30,38 @@
    2.18  #include "ipv6-l3-protocol.h"
    2.19  #include "icmpv6-l4-protocol.h"
    2.20  
    2.21 -namespace ns3
    2.22 +namespace ns3 {
    2.23 +class Ipv6L3ProtocolTestCase : public TestCase
    2.24  {
    2.25 +public:
    2.26 +  /**
    2.27 +   * \brief Constructor.
    2.28 +   */
    2.29 +  Ipv6L3ProtocolTestCase ();
    2.30  
    2.31 -/**
    2.32 - * \class Ipv6L3ProtocolTest
    2.33 - * \brief Ipv6L3Protocol unit tests.
    2.34 - */
    2.35 -class Ipv6L3ProtocolTest : public Test
    2.36 -{
    2.37 -  public:
    2.38 -    /**
    2.39 -     * \brief Constructor.
    2.40 -     */
    2.41 -    Ipv6L3ProtocolTest ();
    2.42 +  /**
    2.43 +   * \brief Destructor.
    2.44 +   */
    2.45 +  virtual
    2.46 +  ~Ipv6L3ProtocolTestCase ();
    2.47  
    2.48 -    /**
    2.49 -     * \brief Destructor.
    2.50 -     */
    2.51 -    virtual ~Ipv6L3ProtocolTest ();
    2.52 -
    2.53 -    /**
    2.54 -     * \brief Run unit tests for this class.
    2.55 -     * \return true if all tests have passed, false otherwise
    2.56 -     */
    2.57 -    virtual bool RunTests ();
    2.58 +  /**
    2.59 +   * \brief Run unit tests for this class.
    2.60 +   * \return false if all tests have passed, false otherwise
    2.61 +   */
    2.62 +  virtual bool
    2.63 +  DoRun ();
    2.64  };
    2.65 -
    2.66 -Ipv6L3ProtocolTest::Ipv6L3ProtocolTest () : Test ("Ipv6L3Protocol")
    2.67 +Ipv6L3ProtocolTestCase::Ipv6L3ProtocolTestCase () :
    2.68 +  TestCase ("Verify the IPv6 layer 3 protocol")
    2.69  {
    2.70  }
    2.71 -
    2.72 -Ipv6L3ProtocolTest::~Ipv6L3ProtocolTest ()
    2.73 +Ipv6L3ProtocolTestCase::~Ipv6L3ProtocolTestCase ()
    2.74  {
    2.75  }
    2.76 -
    2.77 -bool Ipv6L3ProtocolTest::RunTests ()
    2.78 +bool
    2.79 +Ipv6L3ProtocolTestCase::DoRun ()
    2.80  {
    2.81 -  bool result = true;
    2.82    Ptr<Node> node = CreateObject<Node> ();
    2.83    Ptr<Ipv6L3Protocol> ipv6 = CreateObject<Ipv6L3Protocol> ();
    2.84    Ptr<Icmpv6L4Protocol> icmpv6 = CreateObject<Icmpv6L4Protocol> ();
    2.85 @@ -90,59 +82,69 @@
    2.86    interface->SetDevice (device);
    2.87    interface->SetNode (node);
    2.88    index = ipv6->AddIpv6Interface (interface);
    2.89 -  NS_TEST_ASSERT_EQUAL (index, 1);
    2.90 +  NS_TEST_ASSERT_MSG_EQ (index, 1,"The index is not 1??");
    2.91  
    2.92    /* second interface */
    2.93    node->AddDevice (device2);
    2.94    interface2->SetDevice (device2);
    2.95    interface2->SetNode (node);
    2.96    index = ipv6->AddIpv6Interface (interface2);
    2.97 -  NS_TEST_ASSERT_EQUAL (index, 2);
    2.98 +  NS_TEST_ASSERT_MSG_EQ (index, 2, "The index is not 2??");
    2.99  
   2.100    Ipv6InterfaceAddress ifaceAddr = interface->GetLinkLocalAddress ();
   2.101 -  NS_TEST_ASSERT_EQUAL (ifaceAddr.GetAddress ().IsLinkLocal (), true);
   2.102 +  NS_TEST_ASSERT_MSG_EQ (ifaceAddr.GetAddress ().IsLinkLocal (), true,
   2.103 +      "Should be link local??");
   2.104  
   2.105    interface->SetUp ();
   2.106 -  NS_TEST_ASSERT_EQUAL (interface->GetNAddresses (), 1); /* interface has always a link-local address */
   2.107 +  NS_TEST_ASSERT_MSG_EQ (interface->GetNAddresses (), 1,
   2.108 +      "interface has always a link-local address"); /* interface has always a link-local address */
   2.109  
   2.110    interface2->SetUp ();
   2.111  
   2.112 -  Ipv6InterfaceAddress ifaceAddr1 = Ipv6InterfaceAddress ("2001:1234:5678:9000::1", Ipv6Prefix (64));
   2.113 +  Ipv6InterfaceAddress ifaceAddr1 = Ipv6InterfaceAddress (
   2.114 +      "2001:1234:5678:9000::1", Ipv6Prefix (64));
   2.115    interface->AddAddress (ifaceAddr1);
   2.116 -  Ipv6InterfaceAddress ifaceAddr2 = Ipv6InterfaceAddress ("2001:ffff:5678:9000::1", Ipv6Prefix (64));
   2.117 +  Ipv6InterfaceAddress ifaceAddr2 = Ipv6InterfaceAddress (
   2.118 +      "2001:ffff:5678:9000::1", Ipv6Prefix (64));
   2.119    interface->AddAddress (ifaceAddr2);
   2.120  
   2.121 -  Ipv6InterfaceAddress ifaceAddr3 = Ipv6InterfaceAddress ("2001:ffff:5678:9001::2", Ipv6Prefix (64));
   2.122 +  Ipv6InterfaceAddress ifaceAddr3 = Ipv6InterfaceAddress (
   2.123 +      "2001:ffff:5678:9001::2", Ipv6Prefix (64));
   2.124    interface2->AddAddress (ifaceAddr3);
   2.125  
   2.126    uint32_t num = interface->GetNAddresses ();
   2.127 -  NS_TEST_ASSERT_EQUAL (num, 3); /* 2 global addresses + link-local ones */
   2.128 +  NS_TEST_ASSERT_MSG_EQ (num, 3, "Number of adresses should be 3??"); /* 2 global addresses + link-local ones */
   2.129  
   2.130    num = interface2->GetNAddresses ();
   2.131 -  NS_TEST_ASSERT_EQUAL (num, 2); /* 1 global addresses + link-local ones */
   2.132 +  NS_TEST_ASSERT_MSG_EQ (num, 2, "1 global addresses + link-local ones"); /* 1 global addresses + link-local ones */
   2.133  
   2.134    interface->RemoveAddress (2);
   2.135    num = interface->GetNAddresses ();
   2.136 -  NS_TEST_ASSERT_EQUAL (num, 2);
   2.137 +  NS_TEST_ASSERT_MSG_EQ (num, 2, "Number of adresses should be 2??");
   2.138  
   2.139    Ipv6InterfaceAddress output = interface->GetAddress (1);
   2.140 -  NS_TEST_ASSERT_EQUAL (ifaceAddr1, output);
   2.141 +  NS_TEST_ASSERT_MSG_EQ (ifaceAddr1, output,
   2.142 +      "Should be the interface address 1?");
   2.143  
   2.144 -  index = ipv6->GetInterfaceForPrefix ("2001:1234:5678:9000::0", Ipv6Prefix (64));
   2.145 -  NS_TEST_ASSERT_EQUAL (index, 1); /* link-local address is always index 0 */
   2.146 +  index = ipv6->GetInterfaceForPrefix ("2001:1234:5678:9000::0",
   2.147 +      Ipv6Prefix (64));
   2.148 +  NS_TEST_ASSERT_MSG_EQ (index, 1, "We should get one address??"); /* link-local address is always index 0 */
   2.149  
   2.150    index = ipv6->GetInterfaceForAddress ("2001:ffff:5678:9001::2");
   2.151 -  NS_TEST_ASSERT_EQUAL (index, 2);
   2.152 +  NS_TEST_ASSERT_MSG_EQ (index, 2, "Number of adresses should be 2??");
   2.153  
   2.154    index = ipv6->GetInterfaceForAddress ("2001:ffff:5678:9000::1"); /* address we just remove */
   2.155 -  NS_TEST_ASSERT_EQUAL (index, (uint32_t)-1);
   2.156 +  NS_TEST_ASSERT_MSG_EQ (index, (uint32_t) -1, "Address should not be found??");
   2.157  
   2.158 -  return result;
   2.159 -}
   2.160 -
   2.161 -static Ipv6L3ProtocolTest gIpv6L3ProtocolTest;
   2.162 -
   2.163 -} /* namespace ns3 */
   2.164 -
   2.165 -#endif /* RUN_SELF_TESTS */
   2.166 -
   2.167 +  return false;
   2.168 +}//end DoRun
   2.169 +static class IPv6L3ProtocolTestSuite : public TestSuite
   2.170 +{
   2.171 +public:
   2.172 +  IPv6L3ProtocolTestSuite () :
   2.173 +    TestSuite ("ipv6-protocol", UNIT)
   2.174 +  {
   2.175 +    AddTestCase (new Ipv6L3ProtocolTestCase ());
   2.176 +  }
   2.177 +} g_IPv6L3ProtocolTestSuite;
   2.178 +} // namespace ns3
   2.179 \ No newline at end of file