A Discrete-Event Network Simulator
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 * 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
23/**
24 * \file
25 * \ingroup core-tests
26 * \ingroup events
27 * \ingroup event-garbage-tests
28 * EventGarbageCollector test suite.
29 */
30
31/**
32 * \ingroup core-tests
33 * \defgroup event-garbage-tests EventGarbageCollector test suite
34 */
35
36namespace ns3
37{
38
39namespace tests
40{
41
42/**
43 * \ingroup event-garbage-tests
44 * Event garbage collector test.
45 */
47{
48 int m_counter; //!< Counter to trigger deletion of events.
49 EventGarbageCollector* m_events; //!< Object under test.
50
51 /** Callback to record event invocations. */
53
54 public:
55 /** Constructor. */
57 /** Destructor. */
59 void DoRun() override;
60};
61
63 : TestCase("EventGarbageCollector"),
64 m_counter(0),
65 m_events(nullptr)
66{
67}
68
70{
71}
72
73void
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
85void
87{
89
90 for (int n = 0; n < 100; n++)
91 {
95 this));
96 }
101}
102
103/**
104 * \ingroup event-garbage-tests
105 * Event garbage collector test suite.
106 */
108{
109 public:
111 : TestSuite("event-garbage-collector")
112 {
114 }
115};
116
117/**
118 * \ingroup event-garbage-tests
119 * EventGarbageCollectorTestSuite instance variable.
120 */
122
123} // namespace tests
124
125} // namespace ns3
An object that tracks scheduled events and automatically cancels them when it is destroyed.
void Track(EventId event)
Tracks a new event.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
void EventGarbageCollectorCallback()
Callback to record event invocations.
void DoRun() override
Implementation to actually run this TestCase.
EventGarbageCollector * m_events
Object under test.
int m_counter
Counter to trigger deletion of events.
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
#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:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.