A Discrete-Event Network Simulator
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 
47 {
48  int m_counter;
50 
53 
54  public:
59  void DoRun() override;
60 };
61 
63  : TestCase("EventGarbageCollector"),
64  m_counter(0),
65  m_events(nullptr)
66 {
67 }
68 
70 {
71 }
72 
73 void
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
87 {
89 
90  for (int n = 0; n < 100; n++)
91  {
92  m_events->Track(
95  this));
96  }
101 }
102 
108 {
109  public:
111  : TestSuite("event-garbage-collector")
112  {
114  }
115 };
116 
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:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
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:251
Every class exported by the ns3 library is enclosed in the ns3 namespace.