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
event-garbage-collector-test-suite.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2007 INESC Porto
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
7
*/
8
9
#include "ns3/event-garbage-collector.h"
10
#include "ns3/test.h"
11
12
/**
13
* \file
14
* \ingroup core-tests
15
* \ingroup events
16
* \ingroup event-garbage-tests
17
* EventGarbageCollector test suite.
18
*/
19
20
/**
21
* \ingroup core-tests
22
* \defgroup event-garbage-tests EventGarbageCollector test suite
23
*/
24
25
namespace
ns3
26
{
27
28
namespace
tests
29
{
30
31
/**
32
* \ingroup event-garbage-tests
33
* Event garbage collector test.
34
*/
35
class
EventGarbageCollectorTestCase
:
public
TestCase
36
{
37
int
m_counter
;
//!< Counter to trigger deletion of events.
38
EventGarbageCollector
*
m_events
;
//!< Object under test.
39
40
/** Callback to record event invocations. */
41
void
EventGarbageCollectorCallback
();
42
43
public
:
44
/** Constructor. */
45
EventGarbageCollectorTestCase
();
46
/** Destructor. */
47
~EventGarbageCollectorTestCase
()
override
;
48
void
DoRun
()
override
;
49
};
50
51
EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
()
52
:
TestCase
(
"EventGarbageCollector"
),
53
m_counter(0),
54
m_events(nullptr)
55
{
56
}
57
58
EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
()
59
{
60
}
61
62
void
63
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
()
64
{
65
m_counter
++;
66
if
(
m_counter
== 50)
67
{
68
// this should cause the remaining (50) events to be cancelled
69
delete
m_events
;
70
m_events
=
nullptr
;
71
}
72
}
73
74
void
75
EventGarbageCollectorTestCase::DoRun
()
76
{
77
m_events
=
new
EventGarbageCollector
();
78
79
for
(
int
n = 0; n < 100; n++)
80
{
81
m_events
->
Track
(
82
Simulator::Schedule
(
Simulator::Now
(),
83
&
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
,
84
this
));
85
}
86
Simulator::Run
();
87
NS_TEST_EXPECT_MSG_EQ
(
m_events
, 0,
""
);
88
NS_TEST_EXPECT_MSG_EQ
(
m_counter
, 50,
""
);
89
Simulator::Destroy
();
90
}
91
92
/**
93
* \ingroup event-garbage-tests
94
* Event garbage collector test suite.
95
*/
96
class
EventGarbageCollectorTestSuite
:
public
TestSuite
97
{
98
public
:
99
EventGarbageCollectorTestSuite
()
100
:
TestSuite
(
"event-garbage-collector"
)
101
{
102
AddTestCase
(
new
EventGarbageCollectorTestCase
());
103
}
104
};
105
106
/**
107
* \ingroup event-garbage-tests
108
* EventGarbageCollectorTestSuite instance variable.
109
*/
110
static
EventGarbageCollectorTestSuite
g_eventGarbageCollectorTestSuite
;
111
112
}
// namespace tests
113
114
}
// namespace ns3
ns3::EventGarbageCollector
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Definition
event-garbage-collector.h:37
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition
event-garbage-collector.cc:27
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition
simulator.h:560
ns3::Simulator::Destroy
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition
simulator.cc:131
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
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::tests::EventGarbageCollectorTestCase
Event garbage collector test.
Definition
event-garbage-collector-test-suite.cc:36
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
EventGarbageCollectorTestCase()
Constructor.
Definition
event-garbage-collector-test-suite.cc:51
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorCallback
void EventGarbageCollectorCallback()
Callback to record event invocations.
Definition
event-garbage-collector-test-suite.cc:63
ns3::tests::EventGarbageCollectorTestCase::DoRun
void DoRun() override
Implementation to actually run this TestCase.
Definition
event-garbage-collector-test-suite.cc:75
ns3::tests::EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
~EventGarbageCollectorTestCase() override
Destructor.
Definition
event-garbage-collector-test-suite.cc:58
ns3::tests::EventGarbageCollectorTestCase::m_events
EventGarbageCollector * m_events
Object under test.
Definition
event-garbage-collector-test-suite.cc:38
ns3::tests::EventGarbageCollectorTestCase::m_counter
int m_counter
Counter to trigger deletion of events.
Definition
event-garbage-collector-test-suite.cc:37
ns3::tests::EventGarbageCollectorTestSuite
Event garbage collector test suite.
Definition
event-garbage-collector-test-suite.cc:97
ns3::tests::EventGarbageCollectorTestSuite::EventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite()
Definition
event-garbage-collector-test-suite.cc:99
ns3::tests::g_eventGarbageCollectorTestSuite
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
Definition
event-garbage-collector-test-suite.cc:110
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
core
test
event-garbage-collector-test-suite.cc
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0