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
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
());
218
AddTestCase
(
new
TimerTemplateTestCase
());
219
}
220
}
g_timerTestSuite
;
221
222
}
// namespace ns3
223
224
src
core
test
timer-test-suite.cc
Generated on Tue Nov 13 2012 10:32:12 for ns-3 by
1.8.1.2