A Discrete-Event Network Simulator
API
drop-tail-queue-test-suite.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #include "ns3/drop-tail-queue.h"
19 #include "ns3/string.h"
20 #include "ns3/test.h"
21 
22 using namespace ns3;
23 
31 {
32  public:
34  void DoRun() override;
35 };
36 
38  : TestCase("Sanity check on the drop tail queue implementation")
39 {
40 }
41 
42 void
44 {
45  Ptr<DropTailQueue<Packet>> queue = CreateObject<DropTailQueue<Packet>>();
46  NS_TEST_EXPECT_MSG_EQ(queue->SetAttributeFailSafe("MaxSize", StringValue("3p")),
47  true,
48  "Verify that we can actually set the attribute");
49 
50  Ptr<Packet> p1;
51  Ptr<Packet> p2;
52  Ptr<Packet> p3;
53  Ptr<Packet> p4;
54  p1 = Create<Packet>();
55  p2 = Create<Packet>();
56  p3 = Create<Packet>();
57  p4 = Create<Packet>();
58 
59  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 0, "There should be no packets in there");
60  queue->Enqueue(p1);
61  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 1, "There should be one packet in there");
62  queue->Enqueue(p2);
63  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 2, "There should be two packets in there");
64  queue->Enqueue(p3);
65  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 3, "There should be three packets in there");
66  queue->Enqueue(p4); // will be dropped
67  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 3, "There should be still three packets in there");
68 
69  Ptr<Packet> packet;
70 
71  packet = queue->Dequeue();
72  NS_TEST_EXPECT_MSG_NE(packet, nullptr, "I want to remove the first packet");
73  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 2, "There should be two packets in there");
74  NS_TEST_EXPECT_MSG_EQ(packet->GetUid(), p1->GetUid(), "was this the first packet ?");
75 
76  packet = queue->Dequeue();
77  NS_TEST_EXPECT_MSG_NE(packet, nullptr, "I want to remove the second packet");
78  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 1, "There should be one packet in there");
79  NS_TEST_EXPECT_MSG_EQ(packet->GetUid(), p2->GetUid(), "Was this the second packet ?");
80 
81  packet = queue->Dequeue();
82  NS_TEST_EXPECT_MSG_NE(packet, nullptr, "I want to remove the third packet");
83  NS_TEST_EXPECT_MSG_EQ(queue->GetNPackets(), 0, "There should be no packets in there");
84  NS_TEST_EXPECT_MSG_EQ(packet->GetUid(), p3->GetUid(), "Was this the third packet ?");
85 
86  packet = queue->Dequeue();
87  NS_TEST_EXPECT_MSG_EQ(packet, nullptr, "There are really no packets in there");
88 }
89 
97 {
98  public:
100  : TestSuite("drop-tail-queue", UNIT)
101  {
102  AddTestCase(new DropTailQueueTestCase(), TestCase::QUICK);
103  }
104 };
105 
DropTailQueue unit tests.
void DoRun() override
Implementation to actually run this TestCase.
DropTail Queue TestSuite.
uint64_t GetUid() const
Returns the packet's Uid.
Definition: packet.cc:412
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1265
static DropTailQueueTestSuite g_dropTailQueueTestSuite
Static variable for test initialization.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
Definition: test.h:666
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Definition: test.h:251
Every class exported by the ns3 library is enclosed in the ns3 namespace.