A Discrete-Event Network Simulator
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
11using namespace ns3;
12
13/**
14 * \ingroup network-test
15 * \ingroup tests
16 *
17 * DropTailQueue unit tests.
18 */
20{
21 public:
23 void DoRun() override;
24};
25
27 : TestCase("Sanity check on the drop tail queue implementation")
28{
29}
30
31void
33{
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 */
86{
87 public:
89 : TestSuite("drop-tail-queue", Type::UNIT)
90 {
91 AddTestCase(new DropTailQueueTestCase(), TestCase::Duration::QUICK);
92 }
93};
94
95static DropTailQueueTestSuite g_dropTailQueueTestSuite; //!< Static variable for test initialization
DropTailQueue unit tests.
void DoRun() override
Implementation to actually run this TestCase.
DropTail Queue TestSuite.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
static DropTailQueueTestSuite g_dropTailQueueTestSuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.