Add a Packet::AddAtEnd unit test.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 15 Jun 2007 18:10:40 +0100
changeset 7721e4fde8c1249
parent 771 86b8d2312ec8
child 774 d8b27eb4efc5
Add a Packet::AddAtEnd unit test.
src/common/packet.cc
     1.1 --- a/src/common/packet.cc	Fri Jun 15 15:25:01 2007 +0100
     1.2 +++ b/src/common/packet.cc	Fri Jun 15 18:10:40 2007 +0100
     1.3 @@ -119,3 +119,58 @@
     1.4  {}
     1.5  
     1.6  }; // namespace ns3
     1.7 +
     1.8 +
     1.9 +
    1.10 +#ifdef RUN_SELF_TESTS
    1.11 +
    1.12 +#include "ns3/test.h"
    1.13 +#include <string>
    1.14 +
    1.15 +namespace ns3 {
    1.16 +
    1.17 +class PacketTest: public Test {
    1.18 +public:
    1.19 +  virtual bool RunTests (void);
    1.20 +  PacketTest ();
    1.21 +};
    1.22 +
    1.23 +
    1.24 +PacketTest::PacketTest ()
    1.25 +  : Test ("Packet") {}
    1.26 +
    1.27 +
    1.28 +bool
    1.29 +PacketTest::RunTests (void)
    1.30 +{
    1.31 +  bool ok = true;
    1.32 +
    1.33 +  Packet pkt1 (reinterpret_cast<const uint8_t*> ("hello"), 5);
    1.34 +  Packet pkt2 (reinterpret_cast<const uint8_t*> (" world"), 6);
    1.35 +  Packet packet;
    1.36 +  packet.AddAtEnd (pkt1);
    1.37 +  packet.AddAtEnd (pkt2);
    1.38 +  
    1.39 +  if (packet.GetSize () != 11)
    1.40 +    {
    1.41 +      Failure () << "expected size 11, got " << packet.GetSize () << std::endl;
    1.42 +      ok = false;
    1.43 +    }
    1.44 +
    1.45 +  std::string msg = std::string (reinterpret_cast<const char *>(packet.PeekData ()),
    1.46 +                                 packet.GetSize ());
    1.47 +  if (msg != "hello world")
    1.48 +    {
    1.49 +      Failure () << "expected size 'hello world', got " << msg << std::endl;
    1.50 +      ok = false;
    1.51 +    }
    1.52 +
    1.53 +  return ok;
    1.54 +}
    1.55 +
    1.56 +
    1.57 +static PacketTest gPacketTest;
    1.58 +
    1.59 +}; // namespace ns3
    1.60 +
    1.61 +#endif /* RUN_SELF_TESTS */