A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
26
class
EventGarbageCollectorTestCase
:
public
TestCase
27
{
28
int
m_counter
;
29
EventGarbageCollector
*
m_events
;
30
31
void
EventGarbageCollectorCallback
();
32
33
public
:
34
35
EventGarbageCollectorTestCase
();
36
virtual
~EventGarbageCollectorTestCase
();
37
virtual
void
DoRun
(
void
);
38
};
39
40
EventGarbageCollectorTestCase::EventGarbageCollectorTestCase
()
41
:
TestCase
(
"EventGarbageCollector"
), m_counter (0), m_events (0)
42
{
43
}
44
45
EventGarbageCollectorTestCase::~EventGarbageCollectorTestCase
()
46
{
47
}
48
49
void
50
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
()
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
61
void
EventGarbageCollectorTestCase::DoRun
(
void
)
62
{
63
m_events
=
new
EventGarbageCollector
();
64
65
for
(
int
n = 0; n < 100; n++)
66
{
67
m_events
->
Track
(
Simulator::Schedule
68
(
Simulator::Now
(),
69
&
EventGarbageCollectorTestCase::EventGarbageCollectorCallback
,
70
this
));
71
}
72
Simulator::Run
();
73
NS_TEST_EXPECT_MSG_EQ
(
m_events
, 0,
""
);
74
NS_TEST_EXPECT_MSG_EQ
(
m_counter
, 50,
""
);
75
Simulator::Destroy
();
76
}
77
78
static
class
EventGarbageCollectorTestSuite
:
public
TestSuite
79
{
80
public
:
81
EventGarbageCollectorTestSuite
()
82
:
TestSuite
(
"event-garbage-collector"
,
UNIT
)
83
{
84
AddTestCase
(
new
EventGarbageCollectorTestCase
(),
TestCase::QUICK
);
85
}
86
}
g_eventGarbageCollectorTests
;
87
88
}
89
src
tools
test
event-garbage-collector-test-suite.cc
Generated on Tue May 14 2013 11:08:33 for ns-3 by
1.8.1.2