A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
24 namespace ns3 {
25 
27 {
28  int m_counter;
30 
32 
33 public:
34 
37  virtual void DoRun (void);
38 };
39 
41  : TestCase ("EventGarbageCollector"), m_counter (0), m_events (0)
42 {
43 }
44 
46 {
47 }
48 
49 void
51 {
52  m_counter++;
53  if (m_counter == 50)
54  {
55  // this should cause the remaining (50) events to be cancelled
56  delete m_events;
57  m_events = 0;
58  }
59 }
60 
62 {
64 
65  for (int n = 0; n < 100; n++)
66  {
68  (Simulator::Now (),
70  this));
71  }
72  Simulator::Run ();
76 }
77 
79 {
80 public:
82  : TestSuite ("event-garbage-collector", UNIT)
83  {
85  }
87 
88 }
89 
A suite of tests to run.
Definition: test.h:1025
static void Run(void)
Definition: simulator.cc:157
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:824
virtual void DoRun(void)
Implementation to actually run this TestCase.
ns3::EventGarbageCollectorTestSuite g_eventGarbageCollectorTests
An object that tracks scheduled events and automatically cancels them when it is destroyed. It is useful in situations where multiple instances of the same type of event can simultaneously be scheduled, and when the events should be limited to the lifetime of a container object.
#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:244
static void Destroy(void)
Definition: simulator.cc:121
static Time Now(void)
Definition: simulator.cc:180
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:172
Fast test.
Definition: test.h:857
void Track(EventId event)
Tracks a new event.
This test suite implements a Unit Test.
Definition: test.h:1035