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 using namespace ns3;
25 
27 {
28  int m_counter;
30 
31  void EventGarbageCollectorCallback ();
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  {
67  m_events->Track (Simulator::Schedule
68  (Simulator::Now (),
70  this));
71  }
72  Simulator::Run ();
75  Simulator::Destroy ();
76 }
77 
79 {
80 public:
82  : TestSuite ("event-garbage-collector", UNIT)
83  {
84  AddTestCase (new EventGarbageCollectorTestCase (), TestCase::QUICK);
85  }
virtual void DoRun(void)
Implementation to actually run this TestCase.
A suite of tests to run.
Definition: test.h:1105
#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:265
encapsulates test code
Definition: test.h:929
An object that tracks scheduled events and automatically cancels them when it is destroyed.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void Track(EventId event)
Tracks a new event.
EventGarbageCollectorTestSuite g_eventGarbageCollectorTests
This test suite implements a Unit Test.
Definition: test.h:1115