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
traced-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/traced-callback.h"
21
22
using namespace
ns3;
23
24
class
BasicTracedCallbackTestCase
:
public
TestCase
25
{
26
public
:
27
BasicTracedCallbackTestCase
();
28
virtual
~BasicTracedCallbackTestCase
() {}
29
30
private
:
31
virtual
void
DoRun (
void
);
32
33
void
CbOne
(uint8_t a,
double
b);
34
void
CbTwo (uint8_t a,
double
b);
35
36
bool
m_one
;
37
bool
m_two
;
38
};
39
40
BasicTracedCallbackTestCase::BasicTracedCallbackTestCase
()
41
:
TestCase
(
"Check basic TracedCallback operation"
)
42
{
43
}
44
45
void
46
BasicTracedCallbackTestCase::CbOne
(uint8_t a,
double
b)
47
{
48
m_one
=
true
;
49
}
50
51
void
52
BasicTracedCallbackTestCase::CbTwo
(uint8_t a,
double
b)
53
{
54
m_two
=
true
;
55
}
56
57
void
58
BasicTracedCallbackTestCase::DoRun
(
void
)
59
{
60
//
61
// Create a traced callback and connect it up to our target methods. All that
62
// these methods do is to set corresponding member variables m_one and m_two.
63
//
64
TracedCallback<uint8_t, double>
trace;
65
66
//
67
// Connect both callbacks to their respective test methods. If we hit the
68
// trace, both callbacks should be called and the two variables should be set
69
// to true.
70
//
71
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
72
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
73
m_one
=
false
;
74
m_two
=
false
;
75
trace (1, 2);
76
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
true
,
"Callback CbOne not called"
);
77
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
78
79
//
80
// If we now disconnect callback one then only callback two should be called.
81
//
82
trace.
DisconnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
83
m_one
=
false
;
84
m_two
=
false
;
85
trace (1, 2);
86
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
false
,
"Callback CbOne unexpectedly called"
);
87
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
88
89
//
90
// If we now disconnect callback two then neither callback should be called.
91
//
92
trace.
DisconnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
93
m_one
=
false
;
94
m_two
=
false
;
95
trace (1, 2);
96
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
false
,
"Callback CbOne unexpectedly called"
);
97
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
false
,
"Callback CbTwo unexpectedly called"
);
98
99
//
100
// If we connect them back up, then both callbacks should be called.
101
//
102
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
103
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
104
m_one
=
false
;
105
m_two
=
false
;
106
trace (1, 2);
107
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
true
,
"Callback CbOne not called"
);
108
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
109
}
110
111
class
TracedCallbackTestSuite
:
public
TestSuite
112
{
113
public
:
114
TracedCallbackTestSuite
();
115
};
116
117
TracedCallbackTestSuite::TracedCallbackTestSuite
()
118
:
TestSuite
(
"traced-callback"
, UNIT)
119
{
120
AddTestCase
(
new
BasicTracedCallbackTestCase
);
121
}
122
123
static
TracedCallbackTestSuite
tracedCallbackTestSuite
;
src
core
test
traced-callback-test-suite.cc
Generated on Fri Dec 21 2012 19:00:33 for ns-3 by
1.8.1.2