A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
test
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
#include "ns3/unused.h"
22
23
using namespace
ns3
;
24
25
class
BasicTracedCallbackTestCase
:
public
TestCase
26
{
27
public
:
28
BasicTracedCallbackTestCase
();
29
virtual
~BasicTracedCallbackTestCase
() {}
30
31
private
:
32
virtual
void
DoRun (
void
);
33
34
void
CbOne (uint8_t a,
double
b);
35
void
CbTwo (uint8_t a,
double
b);
36
37
bool
m_one
;
38
bool
m_two
;
39
};
40
41
BasicTracedCallbackTestCase::BasicTracedCallbackTestCase
()
42
:
TestCase
(
"Check basic TracedCallback operation"
)
43
{
44
}
45
46
void
47
BasicTracedCallbackTestCase::CbOne
(uint8_t a,
double
b)
48
{
49
NS_UNUSED
(a);
50
NS_UNUSED
(b);
51
m_one
=
true
;
52
}
53
54
void
55
BasicTracedCallbackTestCase::CbTwo
(uint8_t a,
double
b)
56
{
57
NS_UNUSED
(a);
58
NS_UNUSED
(b);
59
m_two
=
true
;
60
}
61
62
void
63
BasicTracedCallbackTestCase::DoRun
(
void
)
64
{
65
//
66
// Create a traced callback and connect it up to our target methods. All that
67
// these methods do is to set corresponding member variables m_one and m_two.
68
//
69
TracedCallback<uint8_t, double>
trace;
70
71
//
72
// Connect both callbacks to their respective test methods. If we hit the
73
// trace, both callbacks should be called and the two variables should be set
74
// to true.
75
//
76
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
77
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
78
m_one
=
false
;
79
m_two
=
false
;
80
trace (1, 2);
81
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
true
,
"Callback CbOne not called"
);
82
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
83
84
//
85
// If we now disconnect callback one then only callback two should be called.
86
//
87
trace.
DisconnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
88
m_one
=
false
;
89
m_two
=
false
;
90
trace (1, 2);
91
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
false
,
"Callback CbOne unexpectedly called"
);
92
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
93
94
//
95
// If we now disconnect callback two then neither callback should be called.
96
//
97
trace.
DisconnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
98
m_one
=
false
;
99
m_two
=
false
;
100
trace (1, 2);
101
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
false
,
"Callback CbOne unexpectedly called"
);
102
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
false
,
"Callback CbTwo unexpectedly called"
);
103
104
//
105
// If we connect them back up, then both callbacks should be called.
106
//
107
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbOne
,
this
));
108
trace.
ConnectWithoutContext
(
MakeCallback
(&
BasicTracedCallbackTestCase::CbTwo
,
this
));
109
m_one
=
false
;
110
m_two
=
false
;
111
trace (1, 2);
112
NS_TEST_ASSERT_MSG_EQ
(
m_one
,
true
,
"Callback CbOne not called"
);
113
NS_TEST_ASSERT_MSG_EQ
(
m_two
,
true
,
"Callback CbTwo not called"
);
114
}
115
116
class
TracedCallbackTestSuite
:
public
TestSuite
117
{
118
public
:
119
TracedCallbackTestSuite
();
120
};
121
122
TracedCallbackTestSuite::TracedCallbackTestSuite
()
123
:
TestSuite
(
"traced-callback"
, UNIT)
124
{
125
AddTestCase
(
new
BasicTracedCallbackTestCase
, TestCase::QUICK);
126
}
127
128
static
TracedCallbackTestSuite
tracedCallbackTestSuite
;
BasicTracedCallbackTestCase::CbTwo
void CbTwo(uint8_t a, double b)
Definition:
traced-callback-test-suite.cc:55
TracedCallbackTestSuite::TracedCallbackTestSuite
TracedCallbackTestSuite()
Definition:
traced-callback-test-suite.cc:122
BasicTracedCallbackTestCase
Definition:
traced-callback-test-suite.cc:25
TracedCallbackTestSuite
Definition:
traced-callback-test-suite.cc:116
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1342
ns3::TracedCallback
Forward calls to a chain of Callback.
Definition:
traced-callback.h:62
BasicTracedCallbackTestCase::CbOne
void CbOne(uint8_t a, double b)
Definition:
traced-callback-test-suite.cc:47
NS_UNUSED
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition:
unused.h:36
tracedCallbackTestSuite
static TracedCallbackTestSuite tracedCallbackTestSuite
Definition:
traced-callback-test-suite.cc:128
ns3::TestCase
encapsulates test code
Definition:
test.h:1155
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition:
test.cc:299
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:168
ns3::TracedCallback::DisconnectWithoutContext
void DisconnectWithoutContext(const CallbackBase &callback)
Remove from the chain a Callback which was connected without a context.
Definition:
traced-callback.h:289
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1489
BasicTracedCallbackTestCase::BasicTracedCallbackTestCase
BasicTracedCallbackTestCase()
Definition:
traced-callback-test-suite.cc:41
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
BasicTracedCallbackTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
traced-callback-test-suite.cc:63
ns3::TracedCallback::ConnectWithoutContext
void ConnectWithoutContext(const CallbackBase &callback)
Append a Callback to the chain (without a context).
Definition:
traced-callback.h:264
BasicTracedCallbackTestCase::~BasicTracedCallbackTestCase
virtual ~BasicTracedCallbackTestCase()
Definition:
traced-callback-test-suite.cc:29
BasicTracedCallbackTestCase::m_two
bool m_two
Definition:
traced-callback-test-suite.cc:38
BasicTracedCallbackTestCase::m_one
bool m_one
Definition:
traced-callback-test-suite.cc:37
Generated on Wed Nov 7 2018 10:01:51 for ns-3 by
1.8.14