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 (),
97 newValue.GetInteger ());
106 TracedValueCbSink <int64_t> (oldValue.GetValue (), newValue.GetValue ());
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)
std::string TypeName< uint16_t >(void)
std::string TypeName< uint64_t >(void)
Simulation virtual time values and global simulation resolution.
TracedValueCallbackTestCase()
std::string TypeName< int8_t >(void)
void TracedValueCbSink< Time >(Time oldValue, Time newValue)
TracedValueCbSink specialization for Time.
void TracedValueCbSink< SequenceNumber32 >(SequenceNumber32 oldValue, SequenceNumber32 newValue)
TracedValueCbSink specialization for SequenceNumber32.
std::string TypeName(void)
std::string TypeName< int16_t >(void)
std::string TypeName< int64_t >(void)
std::string TypeName< SequenceNumber32 >(void)
Trace classes with value semantics.
CheckTvCb(void)
Constructor.
std::string TypeName< uint8_t >(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
std::string TypeName< bool >(void)
TracedValueCallbackTestSuite()
std::string TypeName< Time >(void)
static TracedValueCallbackTestSuite tracedValueCallbackTestSuite
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
#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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
A class to check that the callback function typedef will actually connect to the TracedValue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string TypeName< uint32_t >(void)
static TypeId GetTypeId(void)
Register this type.
void Invoke(U cb)
Check the sink function against the actual TracedValue invocation.
std::string TypeName< double >(void)
virtual ~TracedValueCallbackTestCase()
void TracedValueCbSink(T oldValue, T newValue)
Template for TracedValue sink functions.
std::string g_Result
Result of callback test.
A base class which provides memory management and object aggregation.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
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...
void CheckType(void)
Check the TracedValue typedef against TracedValueCbSink<T>.
std::string TypeName< int32_t >(void)