From d5260811dcdd63e72284499b2f4b79d938efb010 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Fri, 15 Jun 2007 18:10:40 +0100 Subject: [PATCH] Add a Packet::AddAtEnd unit test. --- src/common/packet.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/common/packet.cc b/src/common/packet.cc index 459cdae39..4acc7fe0e 100644 --- a/src/common/packet.cc +++ b/src/common/packet.cc @@ -119,3 +119,58 @@ Packet::Print (std::ostream &os) const {} }; // namespace ns3 + + + +#ifdef RUN_SELF_TESTS + +#include "ns3/test.h" +#include + +namespace ns3 { + +class PacketTest: public Test { +public: + virtual bool RunTests (void); + PacketTest (); +}; + + +PacketTest::PacketTest () + : Test ("Packet") {} + + +bool +PacketTest::RunTests (void) +{ + bool ok = true; + + Packet pkt1 (reinterpret_cast ("hello"), 5); + Packet pkt2 (reinterpret_cast (" world"), 6); + Packet packet; + packet.AddAtEnd (pkt1); + packet.AddAtEnd (pkt2); + + if (packet.GetSize () != 11) + { + Failure () << "expected size 11, got " << packet.GetSize () << std::endl; + ok = false; + } + + std::string msg = std::string (reinterpret_cast(packet.PeekData ()), + packet.GetSize ()); + if (msg != "hello world") + { + Failure () << "expected size 'hello world', got " << msg << std::endl; + ok = false; + } + + return ok; +} + + +static PacketTest gPacketTest; + +}; // namespace ns3 + +#endif /* RUN_SELF_TESTS */