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
callback-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) 2009 University of Washington
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
19
#include "ns3/test.h"
20
#include "ns3/callback.h"
21
#include <stdint.h>
22
23
using namespace
ns3;
24
25
// ===========================================================================
26
// Test the basic Callback mechanism
27
// ===========================================================================
28
class
BasicCallbackTestCase
:
public
TestCase
29
{
30
public
:
31
BasicCallbackTestCase
();
32
virtual
~BasicCallbackTestCase
() {}
33
34
void
Target1
(
void
) { m_test1 =
true
; }
35
int
Target2
(
void
) { m_test2 =
true
;
return
2; }
36
void
Target3
(
double
a) { m_test3 =
true
; }
37
int
Target4
(
double
a,
int
b) { m_test4 =
true
;
return
4; }
38
39
private
:
40
virtual
void
DoRun (
void
);
41
virtual
void
DoSetup (
void
);
42
43
bool
m_test1
;
44
bool
m_test2
;
45
bool
m_test3
;
46
bool
m_test4
;
47
};
48
49
static
bool
gBasicCallbackTest5
;
50
static
bool
gBasicCallbackTest6
;
51
static
bool
gBasicCallbackTest7
;
52
53
void
54
BasicCallbackTarget5
(
void
)
55
{
56
gBasicCallbackTest5
=
true
;
57
}
58
59
void
60
BasicCallbackTarget6
(
int
)
61
{
62
gBasicCallbackTest6
=
true
;
63
}
64
65
int
66
BasicCallbackTarget7
(
int
a)
67
{
68
gBasicCallbackTest7
=
true
;
69
return
a;
70
}
71
72
BasicCallbackTestCase::BasicCallbackTestCase
()
73
:
TestCase
(
"Check basic Callback mechansim"
)
74
{
75
}
76
77
void
78
BasicCallbackTestCase::DoSetup
(
void
)
79
{
80
m_test1
=
false
;
81
m_test2
=
false
;
82
m_test3
=
false
;
83
m_test4
=
false
;
84
gBasicCallbackTest5
=
false
;
85
gBasicCallbackTest6
=
false
;
86
gBasicCallbackTest7
=
false
;
87
}
88
89
void
90
BasicCallbackTestCase::DoRun
(
void
)
91
{
92
//
93
// Make sure we can declare and compile a Callback pointing to a member
94
// function returning void and execute it.
95
//
96
Callback<void>
target1 (
this
, &
BasicCallbackTestCase::Target1
);
97
target1 ();
98
NS_TEST_ASSERT_MSG_EQ
(
m_test1
,
true
,
"Callback did not fire"
);
99
100
//
101
// Make sure we can declare and compile a Callback pointing to a member
102
// function that returns an int and execute it.
103
//
104
Callback<int>
target2;
105
target2 =
Callback<int>
(
this
, &
BasicCallbackTestCase::Target2
);
106
target2 ();
107
NS_TEST_ASSERT_MSG_EQ
(
m_test2
,
true
,
"Callback did not fire"
);
108
109
//
110
// Make sure we can declare and compile a Callback pointing to a member
111
// function that returns void, takes a double parameter, and execute it.
112
//
113
Callback<void, double>
target3 =
Callback<void, double>
(
this
, &
BasicCallbackTestCase::Target3
);
114
target3 (0.0);
115
NS_TEST_ASSERT_MSG_EQ
(
m_test3
,
true
,
"Callback did not fire"
);
116
117
//
118
// Make sure we can declare and compile a Callback pointing to a member
119
// function that returns void, takes two parameters, and execute it.
120
//
121
Callback<int, double, int>
target4 =
Callback<int, double, int>
(
this
, &
BasicCallbackTestCase::Target4
);
122
target4 (0.0, 1);
123
NS_TEST_ASSERT_MSG_EQ
(
m_test4
,
true
,
"Callback did not fire"
);
124
125
//
126
// Make sure we can declare and compile a Callback pointing to a non-member
127
// function that returns void, and execute it. This is a lower level call
128
// than MakeCallback so we have got to include at least two arguments to make
129
// sure that the constructor is properly disambiguated. If the arguments are
130
// not needed, we just pass in dummy values.
131
//
132
Callback<void>
target5 =
Callback<void>
(&
BasicCallbackTarget5
,
true
,
true
);
133
target5 ();
134
NS_TEST_ASSERT_MSG_EQ
(
gBasicCallbackTest5
,
true
,
"Callback did not fire"
);
135
136
//
137
// Make sure we can declare and compile a Callback pointing to a non-member
138
// function that returns void, takes one integer argument and execute it.
139
// We also need to provide two dummy arguments to the constructor here.
140
//
141
Callback<void, int>
target6 =
Callback<void, int>
(&
BasicCallbackTarget6
,
true
,
true
);
142
target6 (1);
143
NS_TEST_ASSERT_MSG_EQ
(
gBasicCallbackTest6
,
true
,
"Callback did not fire"
);
144
145
//
146
// Make sure we can declare and compile a Callback pointing to a non-member
147
// function that returns int, takes one integer argument and execute it.
148
// We also need to provide two dummy arguments to the constructor here.
149
//
150
Callback<int, int>
target7 =
Callback<int, int>
(&
BasicCallbackTarget7
,
true
,
true
);
151
target7 (1);
152
NS_TEST_ASSERT_MSG_EQ
(
gBasicCallbackTest7
,
true
,
"Callback did not fire"
);
153
}
154
155
// ===========================================================================
156
// Test the MakeCallback mechanism
157
// ===========================================================================
158
class
MakeCallbackTestCase
:
public
TestCase
159
{
160
public
:
161
MakeCallbackTestCase
();
162
virtual
~MakeCallbackTestCase
() {}
163
164
void
Target1
(
void
) {
m_test1
=
true
; }
165
int
Target2
(
void
) {
m_test2
=
true
;
return
2; }
166
void
Target3
(
double
a) {
m_test3
=
true
; }
167
int
Target4
(
double
a,
int
b) {
m_test4
=
true
;
return
4; }
168
169
private
:
170
virtual
void
DoRun
(
void
);
171
virtual
void
DoSetup
(
void
);
172
173
bool
m_test1
;
174
bool
m_test2
;
175
bool
m_test3
;
176
bool
m_test4
;
177
};
178
179
static
bool
gMakeCallbackTest5
;
180
static
bool
gMakeCallbackTest6
;
181
static
bool
gMakeCallbackTest7
;
182
183
void
184
MakeCallbackTarget5
(
void
)
185
{
186
gMakeCallbackTest5
=
true
;
187
}
188
189
void
190
MakeCallbackTarget6
(
int
)
191
{
192
gMakeCallbackTest6
=
true
;
193
}
194
195
int
196
MakeCallbackTarget7
(
int
a)
197
{
198
gMakeCallbackTest7
=
true
;
199
return
a;
200
}
201
202
MakeCallbackTestCase::MakeCallbackTestCase
()
203
:
TestCase
(
"Check MakeCallback() mechanism"
)
204
{
205
}
206
207
void
208
MakeCallbackTestCase::DoSetup
(
void
)
209
{
210
m_test1
=
false
;
211
m_test2
=
false
;
212
m_test3
=
false
;
213
m_test4
=
false
;
214
gMakeCallbackTest5
=
false
;
215
gMakeCallbackTest6
=
false
;
216
gMakeCallbackTest7
=
false
;
217
}
218
219
void
220
MakeCallbackTestCase::DoRun
(
void
)
221
{
222
//
223
// Make sure we can declare and make a Callback pointing to a member
224
// function returning void and execute it.
225
//
226
Callback<void>
target1 =
MakeCallback
(&
MakeCallbackTestCase::Target1
,
this
);
227
target1 ();
228
NS_TEST_ASSERT_MSG_EQ
(
m_test1
,
true
,
"Callback did not fire"
);
229
230
//
231
// Make sure we can declare and make a Callback pointing to a member
232
// function that returns an int and execute it.
233
//
234
Callback<int>
target2 =
MakeCallback
(&
MakeCallbackTestCase::Target2
,
this
);
235
target2 ();
236
NS_TEST_ASSERT_MSG_EQ
(
m_test2
,
true
,
"Callback did not fire"
);
237
238
//
239
// Make sure we can declare and make a Callback pointing to a member
240
// function that returns void, takes a double parameter, and execute it.
241
//
242
Callback<void, double>
target3 =
MakeCallback
(&
MakeCallbackTestCase::Target3
,
this
);
243
target3 (0.0);
244
NS_TEST_ASSERT_MSG_EQ
(
m_test3
,
true
,
"Callback did not fire"
);
245
246
//
247
// Make sure we can declare and make a Callback pointing to a member
248
// function that returns void, takes two parameters, and execute it.
249
//
250
Callback<int, double, int>
target4 =
MakeCallback
(&
MakeCallbackTestCase::Target4
,
this
);
251
target4 (0.0, 1);
252
NS_TEST_ASSERT_MSG_EQ
(
m_test4
,
true
,
"Callback did not fire"
);
253
254
//
255
// Make sure we can declare and make a Callback pointing to a non-member
256
// function that returns void, and execute it. This uses a higher level call
257
// than in the basic tests so we do not need to include any dummy arguments
258
// here.
259
//
260
Callback<void>
target5 =
MakeCallback
(&
MakeCallbackTarget5
);
261
target5 ();
262
NS_TEST_ASSERT_MSG_EQ
(
gMakeCallbackTest5
,
true
,
"Callback did not fire"
);
263
264
//
265
// Make sure we can declare and compile a Callback pointing to a non-member
266
// function that returns void, takes one integer argument and execute it.
267
// This uses a higher level call than in the basic tests so we do not need to
268
// include any dummy arguments here.
269
//
270
Callback<void, int>
target6 =
MakeCallback
(&
MakeCallbackTarget6
);
271
target6 (1);
272
NS_TEST_ASSERT_MSG_EQ
(
gMakeCallbackTest6
,
true
,
"Callback did not fire"
);
273
274
//
275
// Make sure we can declare and compile a Callback pointing to a non-member
276
// function that returns int, takes one integer argument and execute it.
277
// This uses a higher level call than in the basic tests so we do not need to
278
// include any dummy arguments here.
279
//
280
Callback<int, int>
target7 =
MakeCallback
(&
MakeCallbackTarget7
);
281
target7 (1);
282
NS_TEST_ASSERT_MSG_EQ
(
gMakeCallbackTest7
,
true
,
"Callback did not fire"
);
283
}
284
285
// ===========================================================================
286
// Test the MakeBoundCallback mechanism
287
// ===========================================================================
288
class
MakeBoundCallbackTestCase
:
public
TestCase
289
{
290
public
:
291
MakeBoundCallbackTestCase
();
292
virtual
~MakeBoundCallbackTestCase
() {}
293
294
private
:
295
virtual
void
DoRun
(
void
);
296
virtual
void
DoSetup
(
void
);
297
};
298
299
static
int
gMakeBoundCallbackTest1
;
300
static
bool
*
gMakeBoundCallbackTest2
;
301
static
bool
*
gMakeBoundCallbackTest3a
;
302
static
int
gMakeBoundCallbackTest3b
;
303
static
int
gMakeBoundCallbackTest4a
;
304
static
int
gMakeBoundCallbackTest4b
;
305
static
int
gMakeBoundCallbackTest5a
;
306
static
int
gMakeBoundCallbackTest5b
;
307
static
int
gMakeBoundCallbackTest5c
;
308
static
int
gMakeBoundCallbackTest6a
;
309
static
int
gMakeBoundCallbackTest6b
;
310
static
int
gMakeBoundCallbackTest6c
;
311
static
int
gMakeBoundCallbackTest7a
;
312
static
int
gMakeBoundCallbackTest7b
;
313
static
int
gMakeBoundCallbackTest7c
;
314
static
int
gMakeBoundCallbackTest8a
;
315
static
int
gMakeBoundCallbackTest8b
;
316
static
int
gMakeBoundCallbackTest8c
;
317
static
int
gMakeBoundCallbackTest9a
;
318
static
int
gMakeBoundCallbackTest9b
;
319
static
int
gMakeBoundCallbackTest9c
;
320
static
int
gMakeBoundCallbackTest9d
;
321
322
void
323
MakeBoundCallbackTarget1
(
int
a)
324
{
325
gMakeBoundCallbackTest1
= a;
326
}
327
328
void
329
MakeBoundCallbackTarget2
(
bool
*a)
330
{
331
gMakeBoundCallbackTest2
= a;
332
}
333
334
int
335
MakeBoundCallbackTarget3
(
bool
*a,
int
b)
336
{
337
gMakeBoundCallbackTest3a
= a;
338
gMakeBoundCallbackTest3b
= b;
339
return
1234;
340
}
341
342
void
343
MakeBoundCallbackTarget4
(
int
a,
int
b)
344
{
345
gMakeBoundCallbackTest4a
= a;
346
gMakeBoundCallbackTest4b
= b;
347
}
348
349
int
350
MakeBoundCallbackTarget5
(
int
a,
int
b)
351
{
352
gMakeBoundCallbackTest5a
= a;
353
gMakeBoundCallbackTest5b
= b;
354
return
1234;
355
}
356
357
int
358
MakeBoundCallbackTarget6
(
int
a,
int
b,
int
c)
359
{
360
gMakeBoundCallbackTest6a
= a;
361
gMakeBoundCallbackTest6b
= b;
362
gMakeBoundCallbackTest6c
= c;
363
return
1234;
364
}
365
366
void
367
MakeBoundCallbackTarget7
(
int
a,
int
b,
int
c)
368
{
369
gMakeBoundCallbackTest7a
= a;
370
gMakeBoundCallbackTest7b
= b;
371
gMakeBoundCallbackTest7c
= c;
372
}
373
374
int
375
MakeBoundCallbackTarget8
(
int
a,
int
b,
int
c)
376
{
377
gMakeBoundCallbackTest8a
= a;
378
gMakeBoundCallbackTest8b
= b;
379
gMakeBoundCallbackTest8c
= c;
380
return
1234;
381
}
382
383
int
384
MakeBoundCallbackTarget9
(
int
a,
int
b,
int
c,
int
d)
385
{
386
gMakeBoundCallbackTest9a
= a;
387
gMakeBoundCallbackTest9b
= b;
388
gMakeBoundCallbackTest9c
= c;
389
gMakeBoundCallbackTest9d
= d;
390
return
1234;
391
}
392
393
MakeBoundCallbackTestCase::MakeBoundCallbackTestCase
()
394
:
TestCase
(
"Check MakeBoundCallback() mechanism"
)
395
{
396
}
397
398
void
399
MakeBoundCallbackTestCase::DoSetup
(
void
)
400
{
401
gMakeBoundCallbackTest1
= 0;
402
gMakeBoundCallbackTest2
= 0;
403
gMakeBoundCallbackTest3a
= 0;
404
gMakeBoundCallbackTest3b
= 0;
405
gMakeBoundCallbackTest4a
= 0;
406
gMakeBoundCallbackTest4b
= 0;
407
gMakeBoundCallbackTest5a
= 0;
408
gMakeBoundCallbackTest5b
= 0;
409
gMakeBoundCallbackTest5c
= 0;
410
gMakeBoundCallbackTest6a
= 0;
411
gMakeBoundCallbackTest6b
= 0;
412
gMakeBoundCallbackTest6c
= 0;
413
gMakeBoundCallbackTest7a
= 0;
414
gMakeBoundCallbackTest7b
= 0;
415
gMakeBoundCallbackTest7c
= 0;
416
gMakeBoundCallbackTest8a
= 0;
417
gMakeBoundCallbackTest8b
= 0;
418
gMakeBoundCallbackTest8c
= 0;
419
gMakeBoundCallbackTest9a
= 0;
420
gMakeBoundCallbackTest9b
= 0;
421
gMakeBoundCallbackTest9c
= 0;
422
gMakeBoundCallbackTest9d
= 0;
423
}
424
425
void
426
MakeBoundCallbackTestCase::DoRun
(
void
)
427
{
428
//
429
// This is slightly tricky to explain. A bound Callback allows us to package
430
// up arguments for use later. The arguments are bound when the callback is
431
// created and the code that fires the Callback does not know they are there.
432
//
433
// Since the callback is *declared* according to the way it will be used, the
434
// arguments are not seen there. However, the target function of the callback
435
// will have the provided arguments present. The MakeBoundCallback template
436
// function is what connects the two together and where you provide the
437
// arguments to be bound.
438
//
439
// Here we declare a Callback that returns a void and takes no parameters.
440
// MakeBoundCallback connects this Callback to a target function that returns
441
// void and takes an integer argument. That integer argument is bound to the
442
// value 1234. When the Callback is fired, no integer argument is provided
443
// directly. The argument is provided by bound Callback mechanism.
444
//
445
Callback<void>
target1 =
MakeBoundCallback
(&
MakeBoundCallbackTarget1
, 1234);
446
target1 ();
447
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest1
, 1234,
"Callback did not fire or binding not correct"
);
448
449
//
450
// Make sure we can bind a pointer value (a common use case).
451
//
452
bool
a;
453
Callback<void>
target2 =
MakeBoundCallback
(&
MakeBoundCallbackTarget2
, &a);
454
target2 ();
455
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest2
, &a,
"Callback did not fire or binding not correct"
);
456
457
//
458
// Make sure we can mix and match bound and unbound arguments. This callback
459
// returns an integer so we should see that appear.
460
//
461
Callback<int, int>
target3 =
MakeBoundCallback
(&
MakeBoundCallbackTarget3
, &a);
462
int
result = target3 (2468);
463
NS_TEST_ASSERT_MSG_EQ
(result, 1234,
"Return value of callback not correct"
);
464
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest3a
, &a,
"Callback did not fire or binding not correct"
);
465
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest3b
, 2468,
"Callback did not fire or argument not correct"
);
466
467
//
468
// Test the TwoBound variant
469
//
470
Callback<void>
target4 =
MakeBoundCallback
(&
MakeBoundCallbackTarget4
, 3456, 5678);
471
target4 ();
472
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest4a
, 3456,
"Callback did not fire or binding not correct"
);
473
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest4b
, 5678,
"Callback did not fire or binding not correct"
);
474
475
Callback<int>
target5 =
MakeBoundCallback
(&
MakeBoundCallbackTarget5
, 3456, 5678);
476
int
resultTwoA = target5 ();
477
NS_TEST_ASSERT_MSG_EQ
(resultTwoA, 1234,
"Return value of callback not correct"
);
478
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest5a
, 3456,
"Callback did not fire or binding not correct"
);
479
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest5b
, 5678,
"Callback did not fire or binding not correct"
);
480
481
Callback<int, int>
target6 =
MakeBoundCallback
(&
MakeBoundCallbackTarget6
, 3456, 5678);
482
int
resultTwoB = target6 (6789);
483
NS_TEST_ASSERT_MSG_EQ
(resultTwoB, 1234,
"Return value of callback not correct"
);
484
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest6a
, 3456,
"Callback did not fire or binding not correct"
);
485
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest6b
, 5678,
"Callback did not fire or binding not correct"
);
486
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest6c
, 6789,
"Callback did not fire or argument not correct"
);
487
488
//
489
// Test the ThreeBound variant
490
//
491
Callback<void>
target7 =
MakeBoundCallback
(&
MakeBoundCallbackTarget7
, 2345, 3456, 4567);
492
target7 ();
493
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest7a
, 2345,
"Callback did not fire or binding not correct"
);
494
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest7b
, 3456,
"Callback did not fire or binding not correct"
);
495
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest7c
, 4567,
"Callback did not fire or binding not correct"
);
496
497
Callback<int>
target8 =
MakeBoundCallback
(&
MakeBoundCallbackTarget8
, 2345, 3456, 4567);
498
int
resultThreeA = target8 ();
499
NS_TEST_ASSERT_MSG_EQ
(resultThreeA, 1234,
"Return value of callback not correct"
);
500
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest8a
, 2345,
"Callback did not fire or binding not correct"
);
501
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest8b
, 3456,
"Callback did not fire or binding not correct"
);
502
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest8c
, 4567,
"Callback did not fire or binding not correct"
);
503
504
Callback<int, int>
target9 =
MakeBoundCallback
(&
MakeBoundCallbackTarget9
, 2345, 3456, 4567);
505
int
resultThreeB = target9 (5678);
506
NS_TEST_ASSERT_MSG_EQ
(resultThreeB, 1234,
"Return value of callback not correct"
);
507
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest9a
, 2345,
"Callback did not fire or binding not correct"
);
508
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest9b
, 3456,
"Callback did not fire or binding not correct"
);
509
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest9c
, 4567,
"Callback did not fire or binding not correct"
);
510
NS_TEST_ASSERT_MSG_EQ
(
gMakeBoundCallbackTest9d
, 5678,
"Callback did not fire or binding not correct"
);
511
}
512
513
// ===========================================================================
514
// Test the Nullify mechanism
515
// ===========================================================================
516
class
NullifyCallbackTestCase
:
public
TestCase
517
{
518
public
:
519
NullifyCallbackTestCase
();
520
virtual
~NullifyCallbackTestCase
() {}
521
522
void
Target1
(
void
) {
m_test1
=
true
; }
523
524
private
:
525
virtual
void
DoRun
(
void
);
526
virtual
void
DoSetup
(
void
);
527
528
bool
m_test1
;
529
};
530
531
NullifyCallbackTestCase::NullifyCallbackTestCase
()
532
:
TestCase
(
"Check Nullify() and IsNull()"
)
533
{
534
}
535
536
void
537
NullifyCallbackTestCase::DoSetup
(
void
)
538
{
539
m_test1
=
false
;
540
}
541
542
void
543
NullifyCallbackTestCase::DoRun
(
void
)
544
{
545
//
546
// Make sure we can declare and make a Callback pointing to a member
547
// function returning void and execute it.
548
//
549
Callback<void>
target1 =
MakeCallback
(&
NullifyCallbackTestCase::Target1
,
this
);
550
target1 ();
551
NS_TEST_ASSERT_MSG_EQ
(
m_test1
,
true
,
"Callback did not fire"
);
552
553
NS_TEST_ASSERT_MSG_EQ
(target1.
IsNull
(),
false
,
"Working Callback reports IsNull()"
);
554
555
target1.
Nullify
();
556
557
NS_TEST_ASSERT_MSG_EQ
(target1.
IsNull
(),
true
,
"Nullified Callback reports not IsNull()"
);
558
}
559
560
// ===========================================================================
561
// Make sure that various MakeCallback template functions compile and execute.
562
// Doesn't check an results of the execution.
563
// ===========================================================================
564
class
MakeCallbackTemplatesTestCase
:
public
TestCase
565
{
566
public
:
567
MakeCallbackTemplatesTestCase
();
568
virtual
~MakeCallbackTemplatesTestCase
() {}
569
570
void
Target1
(
void
) {
m_test1
=
true
; }
571
572
private
:
573
virtual
void
DoRun
(
void
);
574
575
bool
m_test1
;
576
};
577
578
void
TestFZero
(
void
) {}
579
void
TestFOne
(
int
) {}
580
void
TestFTwo
(
int
,
int
) {}
581
void
TestFThree
(
int
,
int
,
int
) {}
582
void
TestFFour
(
int
,
int
,
int
,
int
) {}
583
void
TestFFive
(
int
,
int
,
int
,
int
,
int
) {}
584
void
TestFSix
(
int
,
int
,
int
,
int
,
int
,
int
) {}
585
586
void
TestFROne
(
int
&) {}
587
void
TestFRTwo
(
int
&,
int
&) {}
588
void
TestFRThree
(
int
&,
int
&,
int
&) {}
589
void
TestFRFour
(
int
&,
int
&,
int
&,
int
&) {}
590
void
TestFRFive
(
int
&,
int
&,
int
&,
int
&,
int
&) {}
591
void
TestFRSix
(
int
&,
int
&,
int
&,
int
&,
int
&,
int
&) {}
592
593
class
CallbackTestParent
594
{
595
public
:
596
void
PublicParent
(
void
) {}
597
protected
:
598
void
ProtectedParent
(
void
) {}
599
static
void
StaticProtectedParent
(
void
) {}
600
private
:
601
void
PrivateParent
(
void
) {}
602
};
603
604
class
CallbackTestClass
:
public
CallbackTestParent
605
{
606
public
:
607
void
TestZero
(
void
) {}
608
void
TestOne
(
int
) {}
609
void
TestTwo
(
int
,
int
) {}
610
void
TestThree
(
int
,
int
,
int
) {}
611
void
TestFour
(
int
,
int
,
int
,
int
) {}
612
void
TestFive
(
int
,
int
,
int
,
int
,
int
) {}
613
void
TestSix
(
int
,
int
,
int
,
int
,
int
,
int
) {}
614
void
TestCZero
(
void
)
const
{}
615
void
TestCOne
(
int
)
const
{}
616
void
TestCTwo
(
int
,
int
)
const
{}
617
void
TestCThree
(
int
,
int
,
int
)
const
{}
618
void
TestCFour
(
int
,
int
,
int
,
int
)
const
{}
619
void
TestCFive
(
int
,
int
,
int
,
int
,
int
)
const
{}
620
void
TestCSix
(
int
,
int
,
int
,
int
,
int
,
int
)
const
{}
621
622
void
CheckParentalRights
(
void
)
623
{
624
MakeCallback
(&
CallbackTestParent::StaticProtectedParent
);
625
MakeCallback
(&
CallbackTestParent::PublicParent
,
this
);
626
MakeCallback
(&
CallbackTestClass::ProtectedParent
,
this
);
627
// as expected, fails.
628
// MakeCallback (&CallbackTestParent::PrivateParent, this);
629
// unexpected, but fails too. It does fumble me.
630
// MakeCallback (&CallbackTestParent::ProtectedParent, this);
631
}
632
633
};
634
635
MakeCallbackTemplatesTestCase::MakeCallbackTemplatesTestCase
()
636
:
TestCase
(
"Check various MakeCallback() template functions"
)
637
{
638
}
639
640
void
641
MakeCallbackTemplatesTestCase::DoRun
(
void
)
642
{
643
CallbackTestClass
that;
644
645
MakeCallback
(&
CallbackTestClass::TestZero
, &that);
646
MakeCallback
(&
CallbackTestClass::TestOne
, &that);
647
MakeCallback
(&
CallbackTestClass::TestTwo
, &that);
648
MakeCallback
(&
CallbackTestClass::TestThree
, &that);
649
MakeCallback
(&
CallbackTestClass::TestFour
, &that);
650
MakeCallback
(&
CallbackTestClass::TestFive
, &that);
651
MakeCallback
(&
CallbackTestClass::TestSix
, &that);
652
653
MakeCallback
(&
CallbackTestClass::TestCZero
, &that);
654
MakeCallback
(&
CallbackTestClass::TestCOne
, &that);
655
MakeCallback
(&
CallbackTestClass::TestCTwo
, &that);
656
MakeCallback
(&
CallbackTestClass::TestCThree
, &that);
657
MakeCallback
(&
CallbackTestClass::TestCFour
, &that);
658
MakeCallback
(&
CallbackTestClass::TestCFive
, &that);
659
MakeCallback
(&
CallbackTestClass::TestCSix
, &that);
660
661
MakeCallback
(&
TestFZero
);
662
MakeCallback
(&
TestFOne
);
663
MakeCallback
(&
TestFTwo
);
664
MakeCallback
(&
TestFThree
);
665
MakeCallback
(&
TestFFour
);
666
MakeCallback
(&
TestFFive
);
667
MakeCallback
(&
TestFSix
);
668
669
MakeCallback
(&
TestFROne
);
670
MakeCallback
(&
TestFRTwo
);
671
MakeCallback
(&
TestFRThree
);
672
MakeCallback
(&
TestFRFour
);
673
MakeCallback
(&
TestFRFive
);
674
MakeCallback
(&
TestFRSix
);
675
676
MakeBoundCallback
(&
TestFOne
, 1);
677
MakeBoundCallback
(&
TestFTwo
, 1);
678
MakeBoundCallback
(&
TestFThree
, 1);
679
MakeBoundCallback
(&
TestFFour
, 1);
680
MakeBoundCallback
(&
TestFFive
, 1);
681
682
MakeBoundCallback
(&
TestFROne
, 1);
683
MakeBoundCallback
(&
TestFRTwo
, 1);
684
MakeBoundCallback
(&
TestFRThree
, 1);
685
MakeBoundCallback
(&
TestFRFour
, 1);
686
MakeBoundCallback
(&
TestFRFive
, 1);
687
688
that.
CheckParentalRights
();
689
}
690
691
// ===========================================================================
692
// The Test Suite that glues all of the Test Cases together.
693
// ===========================================================================
694
class
CallbackTestSuite
:
public
TestSuite
695
{
696
public
:
697
CallbackTestSuite
();
698
};
699
700
CallbackTestSuite::CallbackTestSuite
()
701
:
TestSuite
(
"callback"
, UNIT)
702
{
703
AddTestCase
(
new
BasicCallbackTestCase
, TestCase::QUICK);
704
AddTestCase
(
new
MakeCallbackTestCase
, TestCase::QUICK);
705
AddTestCase
(
new
MakeBoundCallbackTestCase
, TestCase::QUICK);
706
AddTestCase
(
new
NullifyCallbackTestCase
, TestCase::QUICK);
707
AddTestCase
(
new
MakeCallbackTemplatesTestCase
, TestCase::QUICK);
708
}
709
710
static
CallbackTestSuite
CallbackTestSuite
;
src
core
test
callback-test-suite.cc
Generated on Fri Aug 30 2013 01:42:48 for ns-3 by
1.8.1.2