A Discrete-Event Network Simulator
API
drop-tail-queue-test-suite.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #include "ns3/test.h"
20 #include "ns3/drop-tail-queue.h"
21 #include "ns3/uinteger.h"
22 
23 using namespace ns3;
24 
26 {
27 public:
29  virtual void DoRun (void);
30 };
31 
33  : TestCase ("Sanity check on the drop tail queue implementation")
34 {
35 }
36 void
38 {
39  Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
40  NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxPackets", UintegerValue (3)), true,
41  "Verify that we can actually set the attribute");
42 
43  Ptr<Packet> p1, p2, p3, p4;
44  p1 = Create<Packet> ();
45  p2 = Create<Packet> ();
46  p3 = Create<Packet> ();
47  p4 = Create<Packet> ();
48 
49  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
50  queue->Enqueue (Create<QueueItem> (p1));
51  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
52  queue->Enqueue (Create<QueueItem> (p2));
53  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
54  queue->Enqueue (Create<QueueItem> (p3));
55  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
56  queue->Enqueue (Create<QueueItem> (p4)); // will be dropped
57  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
58 
59  Ptr<QueueItem> item;
60 
61  item = queue->Dequeue ();
62  NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the first packet");
63  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
64  NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p1->GetUid (), "was this the first packet ?");
65 
66  item = queue->Dequeue ();
67  NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the second packet");
68  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
69  NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p2->GetUid (), "Was this the second packet ?");
70 
71  item = queue->Dequeue ();
72  NS_TEST_EXPECT_MSG_EQ ((item != 0), true, "I want to remove the third packet");
73  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
74  NS_TEST_EXPECT_MSG_EQ (item->GetPacket ()->GetUid (), p3->GetUid (), "Was this the third packet ?");
75 
76  item = queue->Dequeue ();
77  NS_TEST_EXPECT_MSG_EQ ((item == 0), true, "There are really no packets in there");
78 }
79 
80 static class DropTailQueueTestSuite : public TestSuite
81 {
82 public:
84  : TestSuite ("drop-tail-queue", UNIT)
85  {
86  AddTestCase (new DropTailQueueTestCase (), TestCase::QUICK);
87  }
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
DropTailQueueTestSuite g_dropTailQueueTestSuite
A suite of tests to run.
Definition: test.h:1333
#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:278
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:211
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
virtual void DoRun(void)
Implementation to actually run this TestCase.
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
Hold an unsigned integer type.
Definition: uinteger.h:44
uint32_t GetNPackets(void) const
Definition: queue.cc:213
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool Enqueue(Ptr< QueueItem > item)
Place a queue item into the rear of the Queue.
Definition: queue.cc:97
Ptr< QueueItem > Dequeue(void)
Remove an item from the front of the Queue, counting it as dequeued.
Definition: queue.cc:135