22 #include "ns3/core-module.h" 23 #include "ns3/network-module.h" 35 template <
typename T>
inline 36 std::string
TypeName (
void) {
return "unknown"; }
78 << (int64_t)oldValue <<
" -> " 83 else if (newValue != 1)
94 TracedValueCbSink <int64_t> (oldValue.GetInteger (),
95 newValue.GetInteger ());
104 TracedValueCbSink <int64_t> (oldValue.GetValue (), newValue.GetValue ());
123 template <
typename T>
136 TypeId ( (
"CheckTvCb<" + TypeName<T>() +
">").c_str ())
138 .AddTraceSource (
"value",
139 "A value being traced.",
141 (
"ns3::TracedValueCallback::" + TypeName<T>()).c_str () )
155 template <
typename U>
158 bool ok = TraceConnectWithoutContext (
"value",
MakeCallback (cb));
159 std::cout << GetTypeId () <<
": " 160 << (ok ?
"connected " :
"failed to connect ")
161 << GetTypeId ().GetTraceSource (0).callback
168 m_value = m_value + (T) 1;
172 std::cout << std::endl;
175 g_Result =
"failed to connect callback";
193 template <
typename T,
typename U>
196 U
sink = TracedValueCbSink<T>;
197 CreateObject<CheckTvCb<T> > ()->Invoke (
sink);
204 virtual void DoRun (
void);
209 :
TestCase (
"Check basic TracedValue callback operation")
216 CheckType< bool, TracedValueCallback::Bool > ();
217 CheckType< int8_t, TracedValueCallback::Int8 > ();
218 CheckType< int16_t, TracedValueCallback::Int16 > ();
219 CheckType< int32_t, TracedValueCallback::Int32 > ();
220 CheckType< uint8_t, TracedValueCallback::Uint8 > ();
221 CheckType< uint16_t, TracedValueCallback::Uint16 > ();
222 CheckType< uint32_t, TracedValueCallback::Uint32 > ();
223 CheckType< double, TracedValueCallback::Double > ();
224 CheckType< Time, TracedValueCallback::Time > ();
225 CheckType< SequenceNumber32, TracedValueCallback::SequenceNumber32 > ();
235 :
TestSuite (
"traced-value-callback", UNIT)
std::string TypeName< uint16_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< 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.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
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.
void CheckType(void)
Check the TracedValue typedef against TracedValueCbSink<T>.
std::string TypeName< int32_t >(void)