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
, TestCase::QUICK);
121
}
122
123
static
TracedCallbackTestSuite
tracedCallbackTestSuite
;
BasicTracedCallbackTestCase::CbTwo
void CbTwo(uint8_t a, double b)
Definition:
traced-callback-test-suite.cc:52
TracedCallbackTestSuite::TracedCallbackTestSuite
TracedCallbackTestSuite()
Definition:
traced-callback-test-suite.cc:117
BasicTracedCallbackTestCase
Definition:
traced-callback-test-suite.cc:24
TracedCallbackTestSuite
Definition:
traced-callback-test-suite.cc:111
ns3::TestSuite
A suite of tests to run.
Definition:
test.h:1025
ns3::TracedCallback
forward calls to a chain of CallbackAn ns3::TracedCallback has almost exactly the same API as a norma...
Definition:
traced-callback.h:43
BasicTracedCallbackTestCase::CbOne
void CbOne(uint8_t a, double b)
Definition:
traced-callback-test-suite.cc:46
tracedCallbackTestSuite
static TracedCallbackTestSuite tracedCallbackTestSuite
Definition:
traced-callback-test-suite.cc:123
ns3::TestCase
encapsulates test code
Definition:
test.h:849
ns3::TracedCallback::DisconnectWithoutContext
void DisconnectWithoutContext(const CallbackBase &callback)
Definition:
traced-callback.h:138
CbOne
static double CbOne(double a, double b)
Definition:
main-callback.cc:9
ns3::MakeCallback
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition:
callback.h:1238
BasicTracedCallbackTestCase::BasicTracedCallbackTestCase
BasicTracedCallbackTestCase()
Definition:
traced-callback-test-suite.cc:40
ns3::TestCase::AddTestCase
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition:
test.cc:173
BasicTracedCallbackTestCase::DoRun
virtual void DoRun(void)
Implementation to actually run this TestCase.
Definition:
traced-callback-test-suite.cc:58
ns3::TracedCallback::ConnectWithoutContext
void ConnectWithoutContext(const CallbackBase &callback)
Definition:
traced-callback.h:115
BasicTracedCallbackTestCase::~BasicTracedCallbackTestCase
virtual ~BasicTracedCallbackTestCase()
Definition:
traced-callback-test-suite.cc:28
BasicTracedCallbackTestCase::m_two
bool m_two
Definition:
traced-callback-test-suite.cc:37
BasicTracedCallbackTestCase::m_one
bool m_one
Definition:
traced-callback-test-suite.cc:36
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
traced-callback-test-suite.cc
Generated on Sat Apr 19 2014 14:06:53 for ns-3 by
1.8.6