A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
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
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INESC Porto
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
* Author: Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
19
*/
20
21
#include "ns3/test.h"
22
#include "ns3/event-garbage-collector.h"
23
37
namespace
ns3
{
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
:
55
57
EventGarbageCollectorTestCase
();
59
virtual
~EventGarbageCollectorTestCase
();
60
virtual
void
DoRun
(
void
);
61
};
62
63
EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
()
64
:
TestCase
(
"EventGarbageCollector"
), m_counter (0), m_events (0)
65
{}
66
67
EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
()
68
{}
69
70
void
71
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
()
72
{
73
m_counter
++;
74
if
(
m_counter
== 50)
75
{
76
// this should cause the remaining (50) events to be cancelled
77
delete
m_events
;
78
m_events
= 0;
79
}
80
}
81
82
void
EventGarbageCollectorTestCase::DoRun
(
void
)
83
{
84
m_events
=
new
EventGarbageCollector
();
85
86
for
(
int
n = 0; n < 100; n++)
87
{
88
m_events
->
Track
(
Simulator::Schedule
89
(
Simulator::Now
(),
90
&
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
,
91
this
));
92
}
93
Simulator::Run
();
94
NS_TEST_EXPECT_MSG_EQ
(
m_events
, 0,
""
);
95
NS_TEST_EXPECT_MSG_EQ
(
m_counter
, 50,
""
);
96
Simulator::Destroy
();
97
}
98
103
class
EventGarbageCollectorTestSuite
:
public
TestSuite
104
{
105
public
:
106
EventGarbageCollectorTestSuite
()
107
:
TestSuite
(
"event-garbage-collector"
)
108
{
109
AddTestCase
(
new
EventGarbageCollectorTestCase
());
110
}
111
};
112
117
static
EventGarbageCollectorTestSuite
g_eventGarbageCollectorTestSuite
;
118
119
120
}
// namespace tests
121
122
}
// namespace ns3
123
ns3::EventGarbageCollector
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Definition:
event-garbage-collector.h:47
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:38
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:136
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:556
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:172
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition:
simulator.cc:195
ns3::TestCase
encapsulates test code
Definition:
test.h:994
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1188
ns3::tests::EventGarbageCollectorTestCase
Event garbage collector test.
Definition:
event-garbage-collector-test-suite.cc:47
ns3::tests::EventGarbageCollectorTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
event-garbage-collector-test-suite.cc:82
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
EventGarbageCollectorTestCase()
Constructor.
Definition:
event-garbage-collector-test-suite.cc:63
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorCallback
void EventGarbageCollectorCallback()
Callback to record event invocations.
Definition:
event-garbage-collector-test-suite.cc:71
ns3::tests::EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
virtual ~EventGarbageCollectorTestCase()
Destructor.
Definition:
event-garbage-collector-test-suite.cc:67
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:104
ns3::tests::EventGarbageCollectorTestSuite::EventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite()
Definition:
event-garbage-collector-test-suite.cc:106
ns3::tests::g_eventGarbageCollectorTestSuite
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
Definition:
event-garbage-collector-test-suite.cc:117
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:240
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
test-ns3.tests
tests
Definition:
test-ns3.py:2134
src
core
test
event-garbage-collector-test-suite.cc
Generated on Tue Feb 6 2024 19:21:17 for ns-3 by
1.9.1