From 7bee848ad0ac5b4cf0ebe11af20aed7bf0863e95 Mon Sep 17 00:00:00 2001 From: Borovkova Elena Date: Mon, 6 Jul 2009 22:54:19 +0400 Subject: [PATCH] RREP unit test --- src/routing/aodv/aodv-packet.cc | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/routing/aodv/aodv-packet.cc b/src/routing/aodv/aodv-packet.cc index 1e40bd251..60d209161 100644 --- a/src/routing/aodv/aodv-packet.cc +++ b/src/routing/aodv/aodv-packet.cc @@ -284,5 +284,43 @@ std::ostream & operator<<(std::ostream & os, RrepHeader const & h) return os; } +#ifdef RUN_SELF_TESTS +/// Unit test for RREP +struct RrepHeaderTest : public Test +{ + RrepHeaderTest () : Test ("AODV/RREP") {} + virtual bool RunTests(); +}; + +/// Test instance +static RrepHeaderTest g_RrepHeaderTest; + +bool RrepHeaderTest::RunTests () +{ + bool result(true); + + RrepHeader h; + h.SetDst (Ipv4Address("1.2.3.4")); + h.SetDstSeqno (123); + h.SetSrc (Ipv4Address("4.3.2.1")); + h.SetLifeTime(12); + h.SetAckRequired(true); + NS_TEST_ASSERT(h.GetAckRequired ()); + h.SetAckRequired(false); + NS_TEST_ASSERT(!h.GetAckRequired ()); + h.SetPrefixSize(2); + uint8_t sz = h.GetPrefixSize(); + NS_TEST_ASSERT_EQUAL(2, sz); + + Ptr p = Create (); + p->AddHeader (h); + RrepHeader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 20); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif + }}