22 #include "ns3/core-module.h"
23 #include "ns3/network-module.h"
48 template <
typename T>
inline
49 std::string
TypeName (
void) {
return "unknown"; }
97 << (int64_t)oldValue <<
" -> "
102 else if (newValue != 1)
117 TracedValueCbSink <int64_t> (oldValue.
GetInteger (),
155 template <
typename T>
172 TypeId (
"CheckTvCb<" + TypeName<T>() +
">")
174 .AddTraceSource (
"value",
175 "A value being traced.",
177 (
"ns3::TracedValueCallback::" + TypeName<T>()) )
193 template <
typename U>
196 bool ok = TraceConnectWithoutContext (
"value",
MakeCallback (cb));
197 std::cout << GetTypeId () <<
": "
198 << (ok ?
"connected " :
"failed to connect ")
199 << GetTypeId ().GetTraceSource (0).callback
206 m_value = m_value + (T) 1;
210 std::cout << std::endl;
213 g_Result =
"failed to connect callback";
231 template <
typename T,
typename U>
234 U
sink = TracedValueCbSink<T>;
235 CreateObject<CheckTvCb<T> > ()->Invoke (
sink);
242 virtual void DoRun (
void);
247 :
TestCase (
"Check basic TracedValue callback operation")
254 CheckType< bool, TracedValueCallback::Bool > ();
255 CheckType< int8_t, TracedValueCallback::Int8 > ();
256 CheckType< int16_t, TracedValueCallback::Int16 > ();
257 CheckType< int32_t, TracedValueCallback::Int32 > ();
258 CheckType< int64_t, TracedValueCallback::Int64 > ();
259 CheckType< uint8_t, TracedValueCallback::Uint8 > ();
260 CheckType< uint16_t, TracedValueCallback::Uint16 > ();
261 CheckType< uint32_t, TracedValueCallback::Uint32 > ();
262 CheckType< uint64_t, TracedValueCallback::Uint64 > ();
263 CheckType< double, TracedValueCallback::Double > ();
264 CheckType< Time, TracedValueCallback::Time > ();
265 CheckType< SequenceNumber32, TracedValueCallback::SequenceNumber32 > ();
280 :
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.
TracedValue< T > m_value
Traced value.
TracedValueCallback Test Case.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~TracedValueCallbackTestCase()
void CheckType(void)
Check the TracedValue typedef against TracedValueCbSink<T>.
TracedValueCallbackTestCase()
TracedValueCallback TestSuite.
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.
std::string g_Result
Result of callback test.
void TracedValueCbSink< SequenceNumber32 >(SequenceNumber32 oldValue, SequenceNumber32 newValue)
TracedValueCbSink specialization for SequenceNumber32.
void TracedValueCbSink< Time >(Time oldValue, Time newValue)
TracedValueCbSink specialization for Time.
void TracedValueCbSink(T oldValue, T newValue)
Template for TracedValue sink functions.
#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)
Generic template for unknown classes.
std::string TypeName< int8_t >(void)
Generic template for unknown classes.
std::string TypeName< uint16_t >(void)
Generic template for unknown classes.
std::string TypeName< uint64_t >(void)
Generic template for unknown classes.
std::string TypeName< uint8_t >(void)
Generic template for unknown classes.
std::string TypeName< double >(void)
Generic template for unknown classes.
std::string TypeName< bool >(void)
Generic template for unknown classes.
std::string TypeName(void)
Generic template for unknown classes.
std::string TypeName< SequenceNumber32 >(void)
Generic template for unknown classes.
std::string TypeName< uint32_t >(void)
Generic template for unknown classes.
std::string TypeName< Time >(void)
Generic template for unknown classes.
std::string TypeName< int32_t >(void)
Generic template for unknown classes.
std::string TypeName< int16_t >(void)
Generic template for unknown classes.
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
Static variable for test initialization.