# HG changeset patch # User Pavel Boyko # Date 1246870462 -14400 # Node ID f65511805a276909b1900ebd32ae788232a6ea77 # Parent e149190912e47379420ea6f6e6f38685ce23c2bd RREQ unit test diff -r e149190912e4 -r f65511805a27 src/core/test.h --- a/src/core/test.h Mon Jul 06 12:44:34 2009 +0400 +++ b/src/core/test.h Mon Jul 06 12:54:22 2009 +0400 @@ -115,7 +115,7 @@ #define NS_TEST_ASSERT_EQUAL_FILELINE(got, expected, file, line) \ do { \ - if ((got) != (expected)) \ + if (! ((got) == (expected))) \ { \ Failure () << file << ":" < */ +#include "ns3/test.h" #include "aodv-packet.h" #include "ns3/address-utils.h" +#include "ns3/packet.h" namespace ns3 { namespace aodv { @@ -38,14 +40,19 @@ SetUnknownSeqno (false); } +TypeId RreqHeader::GetInstanceTypeId() const +{ + return TypeId(); +} + uint32_t -RreqHeader::GetSerializedSize () +RreqHeader::GetSerializedSize () const { return 24; } void -RreqHeader::Serialize (Buffer::Iterator i) +RreqHeader::Serialize (Buffer::Iterator i) const { i.WriteU8 (type()); i.WriteU8 (rq_flags); @@ -139,4 +146,42 @@ rq_src == o.rq_src && rq_src_seqno == o.rq_src_seqno); } +#ifdef RUN_SELF_TESTS +/// Unit test for RREQ +struct RreqHeaderTest : public Test +{ + RreqHeaderTest () : Test ("AODV/RREQ") {} + virtual bool RunTests(); +}; + +/// Test instance +static RreqHeaderTest g_RreqHeaderTest; + +bool RreqHeaderTest::RunTests () +{ + bool result(true); + + RreqHeader h; + h.SetDst (Ipv4Address("1.2.3.4")); + h.SetDstSeqno (123); + h.SetSrc (Ipv4Address("4.3.2.1")); + h.SetSrcSeqno (321); + h.SetId (1); + h.SetGratiousRrep (true); + NS_TEST_ASSERT(h.GetGratiousRrep ()); + h.SetDestinationOnly (true); + NS_TEST_ASSERT(h.GetDestinationOnly ()); + h.SetUnknownSeqno (true); + NS_TEST_ASSERT(h.GetUnknownSeqno ()); + + Ptr p = Create (); + p->AddHeader (h); + RreqHeader h2; + uint32_t bytes = p->RemoveHeader(h2); + NS_TEST_ASSERT_EQUAL (bytes, 24); + NS_TEST_ASSERT_EQUAL (h, h2); + return result; +} +#endif + }} diff -r e149190912e4 -r f65511805a27 src/routing/aodv/aodv-packet.h --- a/src/routing/aodv/aodv-packet.h Mon Jul 06 12:44:34 2009 +0400 +++ b/src/routing/aodv/aodv-packet.h Mon Jul 06 12:54:22 2009 +0400 @@ -70,8 +70,9 @@ ///\name Header serialization/deserialization //\{ - uint32_t GetSerializedSize (); - void Serialize (Buffer::Iterator start); + TypeId GetInstanceTypeId() const; + uint32_t GetSerializedSize () const; + void Serialize (Buffer::Iterator start) const; uint32_t Deserialize (Buffer::Iterator start); void Print (std::ostream &os) const; //\}