A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 (p1);
51  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
52  queue->Enqueue (p2);
53  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
54  queue->Enqueue (p3);
55  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
56  queue->Enqueue (p4); // will be dropped
57  NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
58 
59  Ptr<Packet> p;
60 
61  p = queue->Dequeue ();
62  NS_TEST_EXPECT_MSG_EQ ((p != 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 (p->GetUid (), p1->GetUid (), "was this the first packet ?");
65 
66  p = queue->Dequeue ();
67  NS_TEST_EXPECT_MSG_EQ ((p != 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 (p->GetUid (), p2->GetUid (), "Was this the second packet ?");
70 
71  p = queue->Dequeue ();
72  NS_TEST_EXPECT_MSG_EQ ((p != 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 (p->GetUid (), p3->GetUid (), "Was this the third packet ?");
75 
76  p = queue->Dequeue ();
77  NS_TEST_EXPECT_MSG_EQ ((p == 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:60
bool Enqueue(Ptr< Packet > p)
Place a packet into the rear of the Queue.
Definition: queue.cc:62
DropTailQueueTestSuite g_dropTailQueueTestSuite
A suite of tests to run.
Definition: test.h:1105
#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:265
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Definition: object-base.cc:196
encapsulates test code
Definition: test.h:929
virtual void DoRun(void)
Implementation to actually run this TestCase.
Hold an unsigned integer type.
Definition: uinteger.h:46
Ptr< Packet > Dequeue(void)
Remove a packet from the front of the Queue.
Definition: queue.cc:86
uint32_t GetNPackets(void) const
Definition: queue.cc:125
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
This test suite implements a Unit Test.
Definition: test.h:1115