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/string.h"
22
23using namespace ns3;
24
32{
33public:
35 virtual void DoRun (void);
36};
37
39 : TestCase ("Sanity check on the drop tail queue implementation")
40{
41}
42void
44{
45 Ptr<DropTailQueue<Packet> > queue = CreateObject<DropTailQueue<Packet> > ();
46 NS_TEST_EXPECT_MSG_EQ (queue->SetAttributeFailSafe ("MaxSize", StringValue ("3p")), true,
47 "Verify that we can actually set the attribute");
48
49 Ptr<Packet> p1, p2, p3, p4;
50 p1 = Create<Packet> ();
51 p2 = Create<Packet> ();
52 p3 = Create<Packet> ();
53 p4 = Create<Packet> ();
54
55 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
56 queue->Enqueue (p1);
57 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
58 queue->Enqueue (p2);
59 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
60 queue->Enqueue (p3);
61 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be three packets in there");
62 queue->Enqueue (p4); // will be dropped
63 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 3, "There should be still three packets in there");
64
65 Ptr<Packet> packet;
66
67 packet = queue->Dequeue ();
68 NS_TEST_EXPECT_MSG_NE (packet, nullptr, "I want to remove the first packet");
69 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 2, "There should be two packets in there");
70 NS_TEST_EXPECT_MSG_EQ (packet->GetUid (), p1->GetUid (), "was this the first packet ?");
71
72 packet = queue->Dequeue ();
73 NS_TEST_EXPECT_MSG_NE (packet, nullptr, "I want to remove the second packet");
74 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 1, "There should be one packet in there");
75 NS_TEST_EXPECT_MSG_EQ (packet->GetUid (), p2->GetUid (), "Was this the second packet ?");
76
77 packet = queue->Dequeue ();
78 NS_TEST_EXPECT_MSG_NE (packet, nullptr, "I want to remove the third packet");
79 NS_TEST_EXPECT_MSG_EQ (queue->GetNPackets (), 0, "There should be no packets in there");
80 NS_TEST_EXPECT_MSG_EQ (packet->GetUid (), p3->GetUid (), "Was this the third packet ?");
81
82 packet = queue->Dequeue ();
83 NS_TEST_EXPECT_MSG_EQ (packet, nullptr, "There are really no packets in there");
84}
85
93{
94public:
96 : TestSuite ("drop-tail-queue", UNIT)
97 {
98 AddTestCase (new DropTailQueueTestCase (), TestCase::QUICK);
99 }
100};
101
DropTailQueue unit tests.
virtual void DoRun(void)
Implementation to actually run this TestCase.
DropTail Queue TestSuite.
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition: packet.cc:390
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
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:636
#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:240
Every class exported by the ns3 library is enclosed in the ns3 namespace.