A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
event-garbage-collector-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INESC Porto
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
18
*/
19
20
#include "ns3/event-garbage-collector.h"
21
#include "ns3/test.h"
22
36
namespace
ns3
37
{
38
39
namespace
tests
40
{
41
46
class
EventGarbageCollectorTestCase
:
public
TestCase
47
{
48
int
m_counter
;
49
EventGarbageCollector
*
m_events
;
50
52
void
EventGarbageCollectorCallback
();
53
54
public
:
56
EventGarbageCollectorTestCase
();
58
~EventGarbageCollectorTestCase
()
override
;
59
void
DoRun
()
override
;
60
};
61
62
EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
()
63
:
TestCase
(
"EventGarbageCollector"
),
64
m_counter(0),
65
m_events(nullptr)
66
{
67
}
68
69
EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
()
70
{
71
}
72
73
void
74
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
()
75
{
76
m_counter
++;
77
if
(
m_counter
== 50)
78
{
79
// this should cause the remaining (50) events to be cancelled
80
delete
m_events
;
81
m_events
=
nullptr
;
82
}
83
}
84
85
void
86
EventGarbageCollectorTestCase::DoRun
()
87
{
88
m_events
=
new
EventGarbageCollector
();
89
90
for
(
int
n = 0; n < 100; n++)
91
{
92
m_events
->
Track
(
93
Simulator::Schedule
(
Simulator::Now
(),
94
&
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
,
95
this
));
96
}
97
Simulator::Run
();
98
NS_TEST_EXPECT_MSG_EQ
(
m_events
, 0,
""
);
99
NS_TEST_EXPECT_MSG_EQ
(
m_counter
, 50,
""
);
100
Simulator::Destroy
();
101
}
102
107
class
EventGarbageCollectorTestSuite
:
public
TestSuite
108
{
109
public
:
110
EventGarbageCollectorTestSuite
()
111
:
TestSuite
(
"event-garbage-collector"
)
112
{
113
AddTestCase
(
new
EventGarbageCollectorTestCase
());
114
}
115
};
116
121
static
EventGarbageCollectorTestSuite
g_eventGarbageCollectorTestSuite
;
122
123
}
// namespace tests
124
125
}
// namespace ns3
ns3::EventGarbageCollector
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Definition:
event-garbage-collector.h:48
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:38
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:571
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:142
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:208
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
ns3::TestCase
encapsulates test code
Definition:
test.h:1060
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:301
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1256
ns3::tests::EventGarbageCollectorTestCase
Event garbage collector test.
Definition:
event-garbage-collector-test-suite.cc:47
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
EventGarbageCollectorTestCase()
Constructor.
Definition:
event-garbage-collector-test-suite.cc:62
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorCallback
void EventGarbageCollectorCallback()
Callback to record event invocations.
Definition:
event-garbage-collector-test-suite.cc:74
ns3::tests::EventGarbageCollectorTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition:
event-garbage-collector-test-suite.cc:86
ns3::tests::EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
~EventGarbageCollectorTestCase() override
Destructor.
Definition:
event-garbage-collector-test-suite.cc:69
ns3::tests::EventGarbageCollectorTestCase::m_events
EventGarbageCollector * m_events
Object under test.
Definition:
event-garbage-collector-test-suite.cc:49
ns3::tests::EventGarbageCollectorTestCase::m_counter
int m_counter
Counter to trigger deletion of events.
Definition:
event-garbage-collector-test-suite.cc:48
ns3::tests::EventGarbageCollectorTestSuite
Event garbage collector test suite.
Definition:
event-garbage-collector-test-suite.cc:108
ns3::tests::EventGarbageCollectorTestSuite::EventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite()
Definition:
event-garbage-collector-test-suite.cc:110
ns3::tests::g_eventGarbageCollectorTestSuite
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
Definition:
event-garbage-collector-test-suite.cc:121
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:251
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
test
event-garbage-collector-test-suite.cc
Generated on Sun Mar 3 2024 17:10:56 for ns-3 by
1.9.1