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 
68 {}
69 
70 void
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 
83 {
85 
86  for (int n = 0; n < 100; n++)
87  {
89  (Simulator::Now (),
91  this));
92  }
93  Simulator::Run ();
97 }
98 
104 {
105 public:
107  : TestSuite ("event-garbage-collector")
108  {
110  }
111 };
112 
118 
119 
120 } // namespace tests
121 
122 } // namespace ns3
123 
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
ns3::EventGarbageCollector::Track
void Track(EventId event)
Tracks a new event.
Definition: event-garbage-collector.cc:38
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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::TestCase
encapsulates test code
Definition: test.h:1154
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorCallback
void EventGarbageCollectorCallback()
Callback to record event invocations.
Definition: event-garbage-collector-test-suite.cc:71
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::m_counter
int m_counter
Counter to trigger deletion of events.
Definition: event-garbage-collector-test-suite.cc:48
ns3::EventGarbageCollector
An object that tracks scheduled events and automatically cancels them when it is destroyed.
Definition: event-garbage-collector.h:47
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:283
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::tests::EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
virtual ~EventGarbageCollectorTestCase()
Destructor.
Definition: event-garbage-collector-test-suite.cc:67
ns3::TestSuite
A suite of tests to run.
Definition: test.h:1344
ns3::tests::EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
EventGarbageCollectorTestCase()
Constructor.
Definition: event-garbage-collector-test-suite.cc:63
ns3::tests::EventGarbageCollectorTestSuite
Event garbage collector test suite.
Definition: event-garbage-collector-test-suite.cc:104
ns3::Simulator::Destroy
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
ns3::tests::g_eventGarbageCollectorTestSuite
static EventGarbageCollectorTestSuite g_eventGarbageCollectorTestSuite
EventGarbageCollectorTestSuite instance variable.
Definition: event-garbage-collector-test-suite.cc:117
ns3::tests::EventGarbageCollectorTestCase
Event garbage collector test.
Definition: event-garbage-collector-test-suite.cc:47
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:106
sample-rng-plot.n
n
Definition: sample-rng-plot.py:37