src/common/packet.cc
changeset 896 9abc108e9817
parent 888 f882ee7eaccf
parent 772 1e4fde8c1249
child 1138 27245d50e5e0
equal deleted inserted replaced
895:b90ba0bcfd36 896:9abc108e9817
   142 {
   142 {
   143   PacketMetadata::Enable ();
   143   PacketMetadata::Enable ();
   144 }
   144 }
   145 
   145 
   146 }; // namespace ns3
   146 }; // namespace ns3
       
   147 
       
   148 
       
   149 
       
   150 #ifdef RUN_SELF_TESTS
       
   151 
       
   152 #include "ns3/test.h"
       
   153 #include <string>
       
   154 
       
   155 namespace ns3 {
       
   156 
       
   157 class PacketTest: public Test {
       
   158 public:
       
   159   virtual bool RunTests (void);
       
   160   PacketTest ();
       
   161 };
       
   162 
       
   163 
       
   164 PacketTest::PacketTest ()
       
   165   : Test ("Packet") {}
       
   166 
       
   167 
       
   168 bool
       
   169 PacketTest::RunTests (void)
       
   170 {
       
   171   bool ok = true;
       
   172 
       
   173   Packet pkt1 (reinterpret_cast<const uint8_t*> ("hello"), 5);
       
   174   Packet pkt2 (reinterpret_cast<const uint8_t*> (" world"), 6);
       
   175   Packet packet;
       
   176   packet.AddAtEnd (pkt1);
       
   177   packet.AddAtEnd (pkt2);
       
   178   
       
   179   if (packet.GetSize () != 11)
       
   180     {
       
   181       Failure () << "expected size 11, got " << packet.GetSize () << std::endl;
       
   182       ok = false;
       
   183     }
       
   184 
       
   185   std::string msg = std::string (reinterpret_cast<const char *>(packet.PeekData ()),
       
   186                                  packet.GetSize ());
       
   187   if (msg != "hello world")
       
   188     {
       
   189       Failure () << "expected size 'hello world', got " << msg << std::endl;
       
   190       ok = false;
       
   191     }
       
   192 
       
   193   return ok;
       
   194 }
       
   195 
       
   196 
       
   197 static PacketTest gPacketTest;
       
   198 
       
   199 }; // namespace ns3
       
   200 
       
   201 #endif /* RUN_SELF_TESTS */