A Discrete-Event Network Simulator
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 
47 {
48  int m_counter;
50 
53 
54 public:
55 
60  virtual void DoRun (void);
61 };
62 
64  : TestCase ("EventGarbageCollector"), m_counter (0), m_events (0)
65 {
66 }
67 
69 {
70 }
71 
72 void
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 
85 {
87 
88  for (int n = 0; n < 100; n++)
89  {
91  (Simulator::Now (),
93  this));
94  }
95  Simulator::Run ();
99 }
100 
106 {
107 public:
109  : TestSuite ("event-garbage-collector")
110  {
112  }
113 };
114 
120 
121 
122  } // namespace tests
123 
124 } // namespace ns3
125 
A suite of tests to run.
Definition: test.h:1342
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#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
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
encapsulates test code
Definition: test.h:1155
An object that tracks scheduled events and automatically cancels them when it is destroyed.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1375
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
int m_counter
Counter to trigger deletion of events.
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
EventGarbageCollector * m_events
Object under test.
void Track(EventId event)
Tracks a new event.
void EventGarbageCollectorCallback()
Callback to record event invocations.
virtual void DoRun(void)
Implementation to actually run this TestCase.