22 #include "ns3/core-module.h"
23 #include "ns3/network-module.h"
35 template <
typename T>
inline
36 std::string
TypeName (
void) {
return "unknown"; }
80 << (int64_t)oldValue <<
" -> "
85 else if (newValue != 1)
96 TracedValueCbSink <int64_t> (oldValue.
GetInteger (),
125 template <
typename T>
138 TypeId ( (
"CheckTvCb<" + TypeName<T>() +
">").c_str ())
140 .AddTraceSource (
"value",
141 "A value being traced.",
143 (
"ns3::TracedValueCallback::" + TypeName<T>()).c_str () )
157 template <
typename U>
160 bool ok = TraceConnectWithoutContext (
"value",
MakeCallback (cb));
161 std::cout << GetTypeId () <<
": "
162 << (ok ?
"connected " :
"failed to connect ")
163 << GetTypeId ().GetTraceSource (0).callback
170 m_value = m_value + (T) 1;
174 std::cout << std::endl;
177 g_Result =
"failed to connect callback";
195 template <
typename T,
typename U>
198 U
sink = TracedValueCbSink<T>;
199 CreateObject<CheckTvCb<T> > ()->Invoke (
sink);
206 virtual void DoRun (
void);
211 :
TestCase (
"Check basic TracedValue callback operation")
218 CheckType< bool, TracedValueCallback::Bool > ();
219 CheckType< int8_t, TracedValueCallback::Int8 > ();
220 CheckType< int16_t, TracedValueCallback::Int16 > ();
221 CheckType< int32_t, TracedValueCallback::Int32 > ();
222 CheckType< int64_t, TracedValueCallback::Int64 > ();
223 CheckType< uint8_t, TracedValueCallback::Uint8 > ();
224 CheckType< uint16_t, TracedValueCallback::Uint16 > ();
225 CheckType< uint32_t, TracedValueCallback::Uint32 > ();
226 CheckType< uint64_t, TracedValueCallback::Uint64 > ();
227 CheckType< double, TracedValueCallback::Double > ();
228 CheckType< Time, TracedValueCallback::Time > ();
229 CheckType< SequenceNumber32, TracedValueCallback::SequenceNumber32 > ();
239 :
TestSuite (
"traced-value-callback", UNIT)
A class to check that the callback function typedef will actually connect to the TracedValue.
static TypeId GetTypeId(void)
Register this type.
CheckTvCb(void)
Constructor.
void Invoke(U cb)
Check the sink function against the actual TracedValue invocation.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~TracedValueCallbackTestCase()
void CheckType(void)
Check the TracedValue typedef against TracedValueCbSink<T>.
TracedValueCallbackTestCase()
TracedValueCallbackTestSuite()
A base class which provides memory management and object aggregation.
NUMERIC_TYPE GetValue() const
Extracts the numeric value of the sequence number.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Simulation virtual time values and global simulation resolution.
int64_t GetInteger(void) const
Get the raw time value, in the current resolution unit.
Trace classes with value semantics.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#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.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
std::string TypeName< int64_t >(void)
std::string g_Result
Result of callback test.
void TracedValueCbSink< SequenceNumber32 >(SequenceNumber32 oldValue, SequenceNumber32 newValue)
TracedValueCbSink specialization for SequenceNumber32.
std::string TypeName< int8_t >(void)
std::string TypeName< uint16_t >(void)
std::string TypeName< uint64_t >(void)
std::string TypeName< uint8_t >(void)
std::string TypeName< double >(void)
std::string TypeName< bool >(void)
std::string TypeName(void)
std::string TypeName< SequenceNumber32 >(void)
std::string TypeName< uint32_t >(void)
void TracedValueCbSink< Time >(Time oldValue, Time newValue)
TracedValueCbSink specialization for Time.
void TracedValueCbSink(T oldValue, T newValue)
Template for TracedValue sink functions.
std::string TypeName< Time >(void)
std::string TypeName< int32_t >(void)
std::string TypeName< int16_t >(void)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
static TracedValueCallbackTestSuite tracedValueCallbackTestSuite