20 #include "ns3/nstime.h"
21 #include "ns3/object.h"
22 #include "ns3/sequence-number.h"
24 #include "ns3/traced-value.h"
25 #include "ns3/type-id.h"
26 #include "ns3/type-name.h"
28 #include <type_traits>
74 std::cout <<
": " <<
static_cast<int64_t
>(oldValue) <<
" -> " <<
static_cast<int64_t
>(newValue)
84 g_Result += std::string(
g_Result.empty() ?
"" :
" | ") +
"newValue should be 1";
137 template <
typename T>
157 TypeId(
"CheckTvCb<" + TypeNameGet<T>() +
">")
159 .AddTraceSource(
"value",
160 "A value being traced.",
162 (
"ns3::TracedValueCallback::" + TypeNameGet<T>()));
177 template <
typename U>
180 bool ok = TraceConnectWithoutContext(
"value",
MakeCallback(cb));
181 std::cout << GetTypeId() <<
": " << (ok ?
"connected " :
"failed to connect ")
182 << GetTypeId().GetTraceSource(0).callback;
188 std::cout << std::endl;
191 g_Result =
"failed to connect callback";
198 m_value = m_value +
static_cast<T
>(1);
214 template <
typename T,
typename U>
217 U
sink = TracedValueCbSink<T>;
218 CreateObject<CheckTvCb<T>>()->Invoke(
sink);
225 void DoRun()
override;
229 :
TestCase(
"Check basic TracedValue callback operation")
236 CheckType<bool, TracedValueCallback::Bool>();
237 CheckType<int8_t, TracedValueCallback::Int8>();
238 CheckType<int16_t, TracedValueCallback::Int16>();
239 CheckType<int32_t, TracedValueCallback::Int32>();
240 CheckType<int64_t, TracedValueCallback::Int64>();
241 CheckType<uint8_t, TracedValueCallback::Uint8>();
242 CheckType<uint16_t, TracedValueCallback::Uint16>();
243 CheckType<uint32_t, TracedValueCallback::Uint32>();
244 CheckType<uint64_t, TracedValueCallback::Uint64>();
245 CheckType<double, TracedValueCallback::Double>();
246 CheckType<Time, TracedValueCallback::Time>();
247 CheckType<SequenceNumber32, TracedValueCallback::SequenceNumber32>();
262 :
TestSuite(
"traced-value-callback", UNIT)
A class to check that the callback function typedef will actually connect to the TracedValue.
static TypeId GetTypeId()
Register this type.
void Invoke(U cb)
Check the sink function against the actual TracedValue invocation.
TracedValue< T > m_value
Traced value.
TracedValueCallback Test Case.
~TracedValueCallbackTestCase() override
void CheckType()
Check the TracedValue typedef against TracedValueCbSink<T>.
void DoRun() override
Implementation to actually run this TestCase.
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() 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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), 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.
Ptr< PacketSink > sink
Pointer to the packet sink application.