A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
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
23
using namespace
ns3
;
24
31
class
DropTailQueueTestCase
:
public
TestCase
32
{
33
public
:
34
DropTailQueueTestCase
();
35
virtual
void
DoRun (
void
);
36
};
37
38
DropTailQueueTestCase::DropTailQueueTestCase
()
39
:
TestCase
(
"Sanity check on the drop tail queue implementation"
)
40
{
41
}
42
void
43
DropTailQueueTestCase::DoRun
(
void
)
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_EQ
((packet != 0),
true
,
"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_EQ
((packet != 0),
true
,
"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_EQ
((packet != 0),
true
,
"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 == 0),
true
,
"There are really no packets in there"
);
84
}
85
92
class
DropTailQueueTestSuite
:
public
TestSuite
93
{
94
public
:
95
DropTailQueueTestSuite
()
96
:
TestSuite
(
"drop-tail-queue"
,
UNIT
)
97
{
98
AddTestCase
(
new
DropTailQueueTestCase
(), TestCase::QUICK);
99
}
100
};
101
102
static
DropTailQueueTestSuite
g_dropTailQueueTestSuite
;
DropTailQueueTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
drop-tail-queue-test-suite.cc:43
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
g_dropTailQueueTestSuite
static DropTailQueueTestSuite g_dropTailQueueTestSuite
Static variable for test initialization.
Definition:
drop-tail-queue-test-suite.cc:102
DropTailQueueTestCase
DropTailQueue unit tests.
Definition:
drop-tail-queue-test-suite.cc:32
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TestCase
encapsulates test code
Definition:
test.h:1154
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:74
NS_TEST_EXPECT_MSG_EQ
#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:283
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
DropTailQueueTestSuite::DropTailQueueTestSuite
DropTailQueueTestSuite()
Definition:
drop-tail-queue-test-suite.cc:95
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1344
ns3::TestSuite::UNIT
@ UNIT
This test suite implements a Unit Test.
Definition:
test.h:1353
DropTailQueueTestCase::DropTailQueueTestCase
DropTailQueueTestCase()
Definition:
drop-tail-queue-test-suite.cc:38
DropTailQueueTestSuite
DropTail Queue TestSuite.
Definition:
drop-tail-queue-test-suite.cc:93
ns3::Packet::GetUid
uint64_t GetUid(void) const
Returns the packet's Uid.
Definition:
packet.cc:390
src
network
test
drop-tail-queue-test-suite.cc
Generated on Fri Oct 1 2021 17:03:29 for ns-3 by
1.8.20