From 227c5734a2053b34aa2086a039137fa26b18fdf7 Mon Sep 17 00:00:00 2001 From: fmoatamr Date: Thu, 1 Oct 2009 13:00:04 +0200 Subject: [PATCH] Conform ipv4-test with the new test suite --- src/internet-stack/ipv4-l3-protocol.h | 2 +- src/internet-stack/ipv4-test.cc | 75 ++++++++++++++++++--------- src/internet-stack/ipv6-test.cc | 2 +- 3 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/internet-stack/ipv4-l3-protocol.h b/src/internet-stack/ipv4-l3-protocol.h index 7e2a53a2f..a22425034 100644 --- a/src/internet-stack/ipv4-l3-protocol.h +++ b/src/internet-stack/ipv4-l3-protocol.h @@ -185,7 +185,7 @@ protected: */ virtual void NotifyNewAggregate (); private: - friend class Ipv4L3ProtocolTest; + friend class Ipv4L3ProtocolTestCase; Ipv4L3Protocol(const Ipv4L3Protocol &); Ipv4L3Protocol &operator = (const Ipv4L3Protocol &); diff --git a/src/internet-stack/ipv4-test.cc b/src/internet-stack/ipv4-test.cc index 1ca51924b..9f38b5b7e 100644 --- a/src/internet-stack/ipv4-test.cc +++ b/src/internet-stack/ipv4-test.cc @@ -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 * */ /** * 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") { } -bool -Ipv4L3ProtocolTest::RunTests (void) +Ipv4L3ProtocolTestCase::~Ipv4L3ProtocolTestCase () +{ +} +bool +Ipv4L3ProtocolTestCase::DoRun (void) { - bool result = true; Ptr node = CreateObject (); Ptr ipv4 = CreateObject (); Ptr interface = CreateObject (); @@ -59,29 +72,41 @@ Ipv4L3ProtocolTest::RunTests (void) 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 diff --git a/src/internet-stack/ipv6-test.cc b/src/internet-stack/ipv6-test.cc index b32c8a54c..9c848be50 100644 --- a/src/internet-stack/ipv6-test.cc +++ b/src/internet-stack/ipv6-test.cc @@ -146,5 +146,5 @@ public: { AddTestCase (new Ipv6L3ProtocolTestCase ()); } -} g_IPv6L3ProtocolTestSuite; +} g_ipv6protocolTestSuite; } // namespace ns3 \ No newline at end of file