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
timer-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 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "ns3/timer.h"
21
#include "ns3/test.h"
22
#include "ns3/simulator.h"
23
#include "ns3/nstime.h"
24
25
namespace
{
26
void
bari
(
int
)
27
{
28
}
29
void
bar2i
(
int
,
int
)
30
{
31
}
32
void
bar3i
(
int
,
int
,
int
)
33
{
34
}
35
void
bar4i
(
int
,
int
,
int
,
int
)
36
{
37
}
38
void
bar5i
(
int
,
int
,
int
,
int
,
int
)
39
{
40
}
41
void
barcir
(
const
int
&)
42
{
43
}
44
void
barir
(
int
&)
45
{
46
}
47
}
// anonymous namespace
48
49
using namespace
ns3;
50
51
class
TimerStateTestCase
:
public
TestCase
52
{
53
public
:
54
TimerStateTestCase
();
55
virtual
void
DoRun (
void
);
56
};
57
58
TimerStateTestCase::TimerStateTestCase
()
59
:
TestCase
(
"Check correct state transitions"
)
60
{
61
}
62
void
63
TimerStateTestCase::DoRun
(
void
)
64
{
65
Timer
timer =
Timer
(Timer::CANCEL_ON_DESTROY);
66
67
timer.
SetFunction
(&
bari
);
68
timer.
SetArguments
(1);
69
timer.
SetDelay
(Seconds (10.0));
70
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsRunning
(),
true
,
""
);
71
NS_TEST_ASSERT_MSG_EQ
(timer.
IsExpired
(),
true
,
""
);
72
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsSuspended
(),
true
,
""
);
73
NS_TEST_ASSERT_MSG_EQ
(timer.
GetState
(), Timer::EXPIRED,
""
);
74
timer.
Schedule
();
75
NS_TEST_ASSERT_MSG_EQ
(timer.
IsRunning
(),
true
,
""
);
76
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsExpired
(),
true
,
""
);
77
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsSuspended
(),
true
,
""
);
78
NS_TEST_ASSERT_MSG_EQ
(timer.
GetState
(), Timer::RUNNING,
""
);
79
timer.
Suspend
();
80
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsRunning
(),
true
,
""
);
81
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsExpired
(),
true
,
""
);
82
NS_TEST_ASSERT_MSG_EQ
(timer.
IsSuspended
(),
true
,
""
);
83
NS_TEST_ASSERT_MSG_EQ
(timer.
GetState
(), Timer::SUSPENDED,
""
);
84
timer.
Resume
();
85
NS_TEST_ASSERT_MSG_EQ
(timer.
IsRunning
(),
true
,
""
);
86
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsExpired
(),
true
,
""
);
87
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsSuspended
(),
true
,
""
);
88
NS_TEST_ASSERT_MSG_EQ
(timer.
GetState
(), Timer::RUNNING,
""
);
89
timer.
Cancel
();
90
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsRunning
(),
true
,
""
);
91
NS_TEST_ASSERT_MSG_EQ
(timer.
IsExpired
(),
true
,
""
);
92
NS_TEST_ASSERT_MSG_EQ
(!timer.
IsSuspended
(),
true
,
""
);
93
NS_TEST_ASSERT_MSG_EQ
(timer.
GetState
(), Timer::EXPIRED,
""
);
94
}
95
96
class
TimerTemplateTestCase
:
public
TestCase
97
{
98
public
:
99
TimerTemplateTestCase
();
100
virtual
void
DoRun
(
void
);
101
virtual
void
DoTeardown
(
void
);
102
void
bazi
(
int
)
103
{
104
}
105
void
baz2i
(
int
,
int
)
106
{
107
}
108
void
baz3i
(
int
,
int
,
int
)
109
{
110
}
111
void
baz4i
(
int
,
int
,
int
,
int
)
112
{
113
}
114
void
baz5i
(
int
,
int
,
int
,
int
,
int
)
115
{
116
}
117
void
baz6i
(
int
,
int
,
int
,
int
,
int
,
int
)
118
{
119
}
120
void
bazcir
(
const
int
&)
121
{
122
}
123
void
bazir
(
int
&)
124
{
125
}
126
void
bazip
(
int
*)
127
{
128
}
129
void
bazcip
(
const
int
*)
130
{
131
}
132
};
133
134
TimerTemplateTestCase::TimerTemplateTestCase
()
135
:
TestCase
(
"Check that template magic is working"
)
136
{
137
}
138
139
void
140
TimerTemplateTestCase::DoRun
(
void
)
141
{
142
Timer
timer =
Timer
(Timer::CANCEL_ON_DESTROY);
143
144
int
a = 0;
145
int
&b = a;
146
const
int
&c = a;
147
148
timer.
SetFunction
(&
bari
);
149
timer.
SetArguments
(2);
150
timer.
SetArguments
(a);
151
timer.
SetArguments
(b);
152
timer.
SetArguments
(c);
153
timer.
SetFunction
(&
barir
);
154
timer.
SetArguments
(2);
155
timer.
SetArguments
(a);
156
timer.
SetArguments
(b);
157
timer.
SetArguments
(c);
158
timer.
SetFunction
(&
barcir
);
159
timer.
SetArguments
(2);
160
timer.
SetArguments
(a);
161
timer.
SetArguments
(b);
162
timer.
SetArguments
(c);
163
// the following call cannot possibly work and is flagged by
164
// a runtime error.
165
// timer.SetArguments (0.0);
166
timer.
SetDelay
(Seconds (1.0));
167
timer.
Schedule
();
168
169
timer.
SetFunction
(&
TimerTemplateTestCase::bazi
,
this
);
170
timer.
SetArguments
(3);
171
timer.
SetFunction
(&
TimerTemplateTestCase::bazir
,
this
);
172
timer.
SetArguments
(3);
173
timer.
SetFunction
(&
TimerTemplateTestCase::bazcir
,
this
);
174
timer.
SetArguments
(3);
175
176
timer.
SetFunction
(&
bar2i
);
177
timer.
SetArguments
(1, 1);
178
timer.
SetFunction
(&
bar3i
);
179
timer.
SetArguments
(1, 1, 1);
180
timer.
SetFunction
(&
bar4i
);
181
timer.
SetArguments
(1, 1, 1, 1);
182
timer.
SetFunction
(&
bar5i
);
183
timer.
SetArguments
(1, 1, 1, 1, 1);
184
// unsupported in simulator class
185
// timer.SetFunction (&bar6i);
186
// timer.SetArguments (1, 1, 1, 1, 1, 1);
187
188
timer.
SetFunction
(&
TimerTemplateTestCase::baz2i
,
this
);
189
timer.
SetArguments
(1, 1);
190
timer.
SetFunction
(&
TimerTemplateTestCase::baz3i
,
this
);
191
timer.
SetArguments
(1, 1, 1);
192
timer.
SetFunction
(&
TimerTemplateTestCase::baz4i
,
this
);
193
timer.
SetArguments
(1, 1, 1, 1);
194
timer.
SetFunction
(&
TimerTemplateTestCase::baz5i
,
this
);
195
timer.
SetArguments
(1, 1, 1, 1, 1);
196
// unsupported in simulator class
197
// timer.SetFunction (&TimerTemplateTestCase::baz6i, this);
198
// timer.SetArguments (1, 1, 1, 1, 1, 1);
199
200
Simulator::Run ();
201
Simulator::Destroy ();
202
}
203
204
void
205
TimerTemplateTestCase::DoTeardown
(
void
)
206
{
207
Simulator::Run ();
208
Simulator::Destroy ();
209
}
210
211
static
class
TimerTestSuite
:
public
TestSuite
212
{
213
public
:
214
TimerTestSuite
()
215
:
TestSuite
(
"timer"
,
UNIT
)
216
{
217
AddTestCase
(
new
TimerStateTestCase
(), TestCase::QUICK);
218
AddTestCase
(
new
TimerTemplateTestCase
(), TestCase::QUICK);
219
}
220
}
g_timerTestSuite
;
anonymous_namespace{timer-test-suite.cc}::bar4i
void bar4i(int, int, int, int)
Definition:
timer-test-suite.cc:35
TimerTestSuite
Definition:
timer-test-suite.cc:211
anonymous_namespace{timer-test-suite.cc}::bar3i
void bar3i(int, int, int)
Definition:
timer-test-suite.cc:32
ns3::Timer
a simple Timer class
Definition:
timer.h:45
TimerTemplateTestCase::bazcir
void bazcir(const int &)
Definition:
timer-test-suite.cc:120
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
TimerTestSuite::TimerTestSuite
TimerTestSuite()
Definition:
timer-test-suite.cc:214
TimerTemplateTestCase::baz4i
void baz4i(int, int, int, int)
Definition:
timer-test-suite.cc:111
ns3::TestCase
encapsulates test code
Definition:
test.h:849
TimerStateTestCase::TimerStateTestCase
TimerStateTestCase()
Definition:
timer-test-suite.cc:58
TimerTemplateTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
timer-test-suite.cc:140
ns3::Timer::IsRunning
bool IsRunning(void) const
Definition:
timer.cc:121
TimerTemplateTestCase::DoTeardown
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Definition:
timer-test-suite.cc:205
TimerStateTestCase
Definition:
timer-test-suite.cc:51
ns3::Timer::Schedule
void Schedule(void)
Schedule a new event using the currently-configured delay, function, and arguments.
Definition:
timer.cc:152
TimerTemplateTestCase::baz2i
void baz2i(int, int)
Definition:
timer-test-suite.cc:105
ns3::Timer::SetFunction
void SetFunction(FN fn)
Definition:
timer.h:254
TimerTemplateTestCase::bazir
void bazir(int &)
Definition:
timer-test-suite.cc:123
anonymous_namespace{timer-test-suite.cc}::bar5i
void bar5i(int, int, int, int, int)
Definition:
timer-test-suite.cc:38
ns3::Timer::SetDelay
void SetDelay(const Time &delay)
Definition:
timer.cc:69
ns3::Timer::GetState
enum Timer::State GetState(void) const
Definition:
timer.cc:133
TimerTemplateTestCase
Definition:
timer-test-suite.cc:96
TimerTemplateTestCase::bazi
void bazi(int)
Definition:
timer-test-suite.cc:102
anonymous_namespace{timer-test-suite.cc}::barir
void barir(int &)
Definition:
timer-test-suite.cc:44
TimerTemplateTestCase::bazip
void bazip(int *)
Definition:
timer-test-suite.cc:126
ns3::Timer::SetArguments
void SetArguments(T1 a1)
Definition:
timer.h:269
TimerStateTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
timer-test-suite.cc:63
ns3::Timer::Resume
void Resume(void)
Restart the timer to expire within the amount of time left saved during Suspend.
Definition:
timer.cc:181
TimerTemplateTestCase::bazcip
void bazcip(const int *)
Definition:
timer-test-suite.cc:129
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
anonymous_namespace{timer-test-suite.cc}::barcir
void barcir(const int &)
Definition:
timer-test-suite.cc:41
TimerTemplateTestCase::baz5i
void baz5i(int, int, int, int, int)
Definition:
timer-test-suite.cc:114
TimerTemplateTestCase::baz6i
void baz6i(int, int, int, int, int, int)
Definition:
timer-test-suite.cc:117
ns3::Timer::Cancel
void Cancel(void)
Cancel the currently-running event if there is one.
Definition:
timer.cc:103
ns3::Timer::IsExpired
bool IsExpired(void) const
Definition:
timer.cc:115
ns3::Timer::Suspend
void Suspend(void)
Cancel the timer and save the amount of time left until it was set to expire.
Definition:
timer.cc:171
anonymous_namespace{timer-test-suite.cc}::bar2i
void bar2i(int, int)
Definition:
timer-test-suite.cc:29
g_timerTestSuite
TimerTestSuite g_timerTestSuite
ns3::TestSuite::UNIT
This test suite implements a Unit Test.
Definition:
test.h:1035
ns3::Timer::IsSuspended
bool IsSuspended(void) const
Definition:
timer.cc:127
TimerTemplateTestCase::baz3i
void baz3i(int, int, int)
Definition:
timer-test-suite.cc:108
TimerTemplateTestCase::TimerTemplateTestCase
TimerTemplateTestCase()
Definition:
timer-test-suite.cc:134
anonymous_namespace{timer-test-suite.cc}::bari
void bari(int)
Definition:
timer-test-suite.cc:26
NS_TEST_ASSERT_MSG_EQ
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition:
test.h:137
src
core
test
timer-test-suite.cc
Generated on Sat Apr 19 2014 14:06:53 for ns-3 by
1.8.6