RREQ unit test
authorPavel Boyko <boyko@iitp.ru>
Mon, 06 Jul 2009 12:54:22 +0400
changeset 5545 f65511805a27
parent 5544 e149190912e4
child 5546 cd0e776c884f
child 5547 5e5a5628a904
RREQ unit test
src/core/test.h
src/routing/aodv/aodv-packet.cc
src/routing/aodv/aodv-packet.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 << ":" <<line                            \
                    << ": expected " << (expected)                   \
--- a/src/routing/aodv/aodv-packet.cc	Mon Jul 06 12:44:34 2009 +0400
+++ b/src/routing/aodv/aodv-packet.cc	Mon Jul 06 12:54:22 2009 +0400
@@ -21,8 +21,10 @@
  *
  * Ported to ns-3 by Elena Borovkova <borovkovaes@iitp.ru>
  */
+#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<Packet> p = Create<Packet> ();
+  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 
+
 }}
--- 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;
   //\}