20 #include <ns3/double.h>
23 #include <ns3/object.h>
25 #include <ns3/string.h>
27 #include <ns3/tuple.h>
28 #include <ns3/uinteger.h>
70 using Tuple2 = std::tuple<double, uint16_t, std::string>;
76 void SetTuple1(
const Tuple1& tuple);
86 void SetTuple2(
const Tuple2& tuple);
102 TypeId(
"ns3::TupleObject")
104 .SetGroupName(
"Test")
107 "StringStringEnumTuple",
108 "Tuple1: string, string, enum",
111 MakeTupleChecker<Tuple1Pack>(
116 "DoubleUintStringTuple",
117 "Tuple2: double, uint16_t, string",
121 MakeTupleChecker<DoubleValue, UintegerValue, StringValue>(
122 MakeDoubleChecker<double>(1.0, 10.0),
123 MakeUintegerChecker<int>(1, 30),
171 void DoRun()
override;
175 :
TestCase(
"test TupleValue attribute value")
182 auto tupleObject = CreateObject<TupleObject>();
185 auto t1 = tupleObject->GetTuple1();
188 "First element of tuple 1 not correctly set");
191 "Second element of tuple 1 not correctly set");
194 "Third element of tuple 1 not correctly set");
197 auto t2 = tupleObject->GetTuple2();
202 "Third element of tuple 2 not correctly set");
205 bool ret1 = tupleObject->SetAttributeFailSafe(
206 "StringStringEnumTuple",
207 MakeTupleValue<TupleObject::Tuple1Pack>(
212 ret1 = tupleObject->GetAttributeFailSafe(
"StringStringEnumTuple", tupleValue1);
215 t1 = tupleValue1.
Get();
218 "First element of tuple 1 not correctly set");
221 "Second element of tuple 1 not correctly set");
224 "Third element of tuple 1 not correctly set");
227 bool ret2 = tupleObject->SetAttributeFailSafe(
228 "DoubleUintStringTuple",
233 ret2 = tupleObject->GetAttributeFailSafe(
"DoubleUintStringTuple", tupleValue2);
236 t2 = tupleValue2.
Get();
241 "Third element of tuple 2 not correctly set");
244 ret1 = tupleObject->SetAttributeFailSafe(
"StringStringEnumTuple",
248 t1 = tupleObject->GetTuple1();
251 "First element of tuple 1 not correctly set");
254 "Second element of tuple 1 not correctly set");
257 "Third element of tuple 1 not correctly set");
260 ret2 = tupleObject->SetAttributeFailSafe(
"DoubleUintStringTuple",
264 t2 = tupleObject->GetTuple2();
269 "Third element of tuple 2 not correctly set");
272 ret1 = tupleObject->SetAttributeFailSafe(
"StringStringEnumTuple",
278 "Tuple modified after failed assignment");
280 ret1 = tupleObject->SetAttributeFailSafe(
281 "StringStringEnumTuple",
282 MakeTupleValue<TupleObject::Tuple1Pack>(
288 "Tuple modified after failed assignment");
290 ret2 = tupleObject->SetAttributeFailSafe(
291 "DoubleUintStringTuple",
293 {4.83, 14,
"Josephson",
"constant"}));
297 "Tuple modified after failed assignment");
299 ret2 = tupleObject->SetAttributeFailSafe(
300 "DoubleUintStringTuple",
305 "Tuple modified after failed assignment");
307 ret2 = tupleObject->SetAttributeFailSafe(
308 "DoubleUintStringTuple",
313 "Tuple modified after failed assignment");
324 :
TestSuite(
"tuple-value-test-suite", UNIT)
Object with attribute values storing tuples.
Tuple1 GetTuple1() const
Get tuple1.
void SetTuple1(const Tuple1 &tuple)
Set tuple1.
Tuple1Value::value_type Tuple1Pack
tuple of attribute values
Tuple2 m_tuple2
second tuple
std::tuple< double, uint16_t, std::string > Tuple2
Tuple2 typedef.
static TypeId GetTypeId()
Get the type ID.
Tuple2 GetTuple2() const
Get tuple2.
Tuple1 m_tuple1
first tuple
TupleTestEnum
Test enum type.
void SetTuple2(const Tuple2 &tuple)
Set tuple2.
Tuple1Value::result_type Tuple1
tuple of values
Test instantiation, initialization, access.
~TupleValueTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
A base class which provides memory management and object aggregation.
Hold variables of type string.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Hold objects of type std::tuple<Args...>.
std::tuple< Args... > value_type
Type of value stored in the TupleValue.
result_type Get() const
Get the stored values as a std::tuple.
std::tuple< std::invoke_result_t< decltype(&Args::Get), Args >... > result_type
Type returned by Get or passed in Set.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeChecker > MakeStringChecker()
static TupleValueTestSuite g_tupleValueTestSuite
Static variable for test initialization.