A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
drop-tail-queue-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 University of Washington
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*/
6
7
#include "ns3/drop-tail-queue.h"
8
#include "ns3/string.h"
9
#include "ns3/test.h"
10
11
using namespace
ns3
;
12
13
/**
14
* @ingroup network-test
15
* @ingroup tests
16
*
17
* DropTailQueue unit tests.
18
*/
19
class
DropTailQueueTestCase
:
public
TestCase
20
{
21
public
:
22
DropTailQueueTestCase
();
23
void
DoRun
()
override
;
24
};
25
26
DropTailQueueTestCase::DropTailQueueTestCase
()
27
:
TestCase
(
"Sanity check on the drop tail queue implementation"
)
28
{
29
}
30
31
void
32
DropTailQueueTestCase::DoRun
()
33
{
34
Ptr<DropTailQueue<Packet>
> queue =
CreateObject<DropTailQueue<Packet>
>();
35
NS_TEST_EXPECT_MSG_EQ
(queue->SetAttributeFailSafe(
"MaxSize"
,
StringValue
(
"3p"
)),
36
true
,
37
"Verify that we can actually set the attribute"
);
38
39
Ptr<Packet>
p1;
40
Ptr<Packet>
p2;
41
Ptr<Packet>
p3;
42
Ptr<Packet>
p4;
43
p1 =
Create<Packet>
();
44
p2 =
Create<Packet>
();
45
p3 =
Create<Packet>
();
46
p4 =
Create<Packet>
();
47
48
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 0,
"There should be no packets in there"
);
49
queue->Enqueue(p1);
50
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 1,
"There should be one packet in there"
);
51
queue->Enqueue(p2);
52
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 2,
"There should be two packets in there"
);
53
queue->Enqueue(p3);
54
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 3,
"There should be three packets in there"
);
55
queue->Enqueue(p4);
// will be dropped
56
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 3,
"There should be still three packets in there"
);
57
58
Ptr<Packet>
packet;
59
60
packet = queue->Dequeue();
61
NS_TEST_EXPECT_MSG_NE
(packet,
nullptr
,
"I want to remove the first packet"
);
62
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 2,
"There should be two packets in there"
);
63
NS_TEST_EXPECT_MSG_EQ
(packet->GetUid(), p1->GetUid(),
"was this the first packet ?"
);
64
65
packet = queue->Dequeue();
66
NS_TEST_EXPECT_MSG_NE
(packet,
nullptr
,
"I want to remove the second packet"
);
67
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 1,
"There should be one packet in there"
);
68
NS_TEST_EXPECT_MSG_EQ
(packet->GetUid(), p2->GetUid(),
"Was this the second packet ?"
);
69
70
packet = queue->Dequeue();
71
NS_TEST_EXPECT_MSG_NE
(packet,
nullptr
,
"I want to remove the third packet"
);
72
NS_TEST_EXPECT_MSG_EQ
(queue->GetNPackets(), 0,
"There should be no packets in there"
);
73
NS_TEST_EXPECT_MSG_EQ
(packet->GetUid(), p3->GetUid(),
"Was this the third packet ?"
);
74
75
packet = queue->Dequeue();
76
NS_TEST_EXPECT_MSG_EQ
(packet,
nullptr
,
"There are really no packets in there"
);
77
}
78
79
/**
80
* @ingroup network-test
81
* @ingroup tests
82
*
83
* @brief DropTail Queue TestSuite
84
*/
85
class
DropTailQueueTestSuite
:
public
TestSuite
86
{
87
public
:
88
DropTailQueueTestSuite
()
89
:
TestSuite
(
"drop-tail-queue"
,
Type
::
UNIT
)
90
{
91
AddTestCase
(
new
DropTailQueueTestCase
(), TestCase::Duration::QUICK);
92
}
93
};
94
95
static
DropTailQueueTestSuite
g_dropTailQueueTestSuite
;
//!< Static variable for test initialization
DropTailQueueTestCase
DropTailQueue unit tests.
Definition
drop-tail-queue-test-suite.cc:20
DropTailQueueTestCase::DropTailQueueTestCase
DropTailQueueTestCase()
Definition
drop-tail-queue-test-suite.cc:26
DropTailQueueTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
drop-tail-queue-test-suite.cc:32
DropTailQueueTestSuite
DropTail Queue TestSuite.
Definition
drop-tail-queue-test-suite.cc:86
DropTailQueueTestSuite::DropTailQueueTestSuite
DropTailQueueTestSuite()
Definition
drop-tail-queue-test-suite.cc:88
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
mpi-test-fixtures.h:37
ns3::StringValue
Hold variables of type string.
Definition
string.h:45
ns3::TestCase
encapsulates test code
Definition
test.h:1050
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition
test.cc:292
ns3::TestSuite
A suite of tests to run.
Definition
test.h:1267
ns3::TestSuite::Type
Type
Type of test.
Definition
test.h:1274
ns3::TestSuite::UNIT
static constexpr auto UNIT
Definition
test.h:1291
g_dropTailQueueTestSuite
static DropTailQueueTestSuite g_dropTailQueueTestSuite
Static variable for test initialization.
Definition
drop-tail-queue-test-suite.cc:95
ns3::CreateObject
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition
object.h:619
ns3::Create
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition
ptr.h:436
NS_TEST_EXPECT_MSG_NE
#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:656
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:241
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
network
test
drop-tail-queue-test-suite.cc
Generated on Fri Dec 13 2024 09:20:47 for ns-3 by
1.11.0