A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
test
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
68
EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
()
69
{
70
}
71
72
void
73
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
()
74
{
75
m_counter
++;
76
if
(
m_counter
== 50)
77
{
78
// this should cause the remaining (50) events to be cancelled
79
delete
m_events
;
80
m_events
= 0;
81
}
82
}
83
84
void
EventGarbageCollectorTestCase::DoRun
(
void
)
85
{
86
m_events
=
new
EventGarbageCollector
();
87
88
for
(
int
n
= 0;
n
< 100;
n
++)
89
{
90
m_events
->
Track
(
Simulator::Schedule
91
(
Simulator::Now
(),
92
&
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
,
93
this
));
94
}
95
Simulator::Run
();
96
NS_TEST_EXPECT_MSG_EQ
(
m_events
, 0,
""
);
97
NS_TEST_EXPECT_MSG_EQ
(
m_counter
, 50,
""
);
98
Simulator::Destroy
();
99
}
100
105
class
EventGarbageCollectorTestSuite
:
public
TestSuite
106
{
107
public
:
108
EventGarbageCollectorTestSuite
()
109
:
TestSuite
(
"event-garbage-collector"
)
110
{
111
AddTestCase
(
new
EventGarbageCollectorTestCase
());
112
}
113
};
114
119
static
EventGarbageCollectorTestSuite
g_eventGarbageCollectorTestSuite
;
120
121
122
}
// namespace tests
123
124
}
// namespace ns3
125
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition:
simulator.cc:226
ns3::tests::EventGarbageCollectorTestSuite
Event garbage collector test suite.
Definition:
event-garbage-collector-test-suite.cc:105
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:285
ns3::tests::g_eventGarbageCollectorTestSuite
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
Definition:
event-garbage-collector-test-suite.cc:119
ns3::tests::EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
virtual ~EventGarbageCollectorTestCase()
Destructor.
Definition:
event-garbage-collector-test-suite.cc:68
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
ns3::tests::EventGarbageCollectorTestCase
Event garbage collector test.
Definition:
event-garbage-collector-test-suite.cc:46
ns3::EventGarbageCollector
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Definition:
event-garbage-collector.h:46
sample-rng-plot.n
n
Definition:
sample-rng-plot.py:37
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition:
simulator.h:1381
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
ns3::tests::EventGarbageCollectorTestCase::m_counter
int m_counter
Counter to trigger deletion of events.
Definition:
event-garbage-collector-test-suite.cc:48
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition:
simulator.cc:190
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition:
simulator.cc:249
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
EventGarbageCollectorTestCase()
Constructor.
Definition:
event-garbage-collector-test-suite.cc:63
ns3::tests::EventGarbageCollectorTestCase::m_events
EventGarbageCollector * m_events
Object under test.
Definition:
event-garbage-collector-test-suite.cc:49
ns3::tests::EventGarbageCollectorTestSuite::EventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite()
Definition:
event-garbage-collector-test-suite.cc:108
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition:
event-garbage-collector.cc:39
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorCallback
void EventGarbageCollectorCallback()
Callback to record event invocations.
Definition:
event-garbage-collector-test-suite.cc:73
ns3::tests::EventGarbageCollectorTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
event-garbage-collector-test-suite.cc:84
Generated on Wed Nov 7 2018 10:01:50 for ns-3 by
1.8.14