23 #include <ns3/tuple.h>
24 #include <ns3/double.h>
25 #include <ns3/uinteger.h>
26 #include <ns3/string.h>
28 #include <ns3/object.h>
63 static TypeId GetTypeId ();
71 using Tuple2 = std::tuple <double, uint16_t, std::string>;
77 void SetTuple1 (
const Tuple1& tuple);
82 Tuple1 GetTuple1 (
void)
const;
87 void SetTuple2 (
const Tuple2& tuple);
92 Tuple2 GetTuple2 (
void)
const;
104 .SetGroupName(
"Test")
106 .AddAttribute (
"StringStringEnumTuple",
"Tuple1: string, string, enum",
112 .AddAttribute (
"DoubleUintStringTuple",
"Tuple2: double, uint16_t, string",
116 MakeTupleChecker<DoubleValue, UintegerValue, StringValue> (MakeDoubleChecker<double> (1.0, 10.0),
117 MakeUintegerChecker<int> (1, 30),
164 virtual void DoRun ();
168 :
TestCase (
"test TupleValue attribute value")
175 auto tupleObject = CreateObject <TupleObject> ();
178 auto t1 = tupleObject->GetTuple1 ();
179 NS_TEST_ASSERT_MSG_EQ ((std::get<0> (t1) ==
"Hey"),
true,
"First element of tuple 1 not correctly set");
180 NS_TEST_ASSERT_MSG_EQ ((std::get<1> (t1) ==
"Jude"),
true,
"Second element of tuple 1 not correctly set");
184 auto t2 = tupleObject->GetTuple2 ();
187 NS_TEST_ASSERT_MSG_EQ ((std::get<2> (t2) ==
"Avogadro"),
true,
"Third element of tuple 2 not correctly set");
190 bool ret1 = tupleObject->SetAttributeFailSafe (
"StringStringEnumTuple",
195 ret1 = tupleObject->GetAttributeFailSafe (
"StringStringEnumTuple", tupleValue1);
198 t1 = tupleValue1.
Get ();
199 NS_TEST_ASSERT_MSG_EQ ((std::get<0> (t1) ==
"Norwegian"),
true,
"First element of tuple 1 not correctly set");
200 NS_TEST_ASSERT_MSG_EQ ((std::get<1> (t1) ==
"Wood"),
true,
"Second element of tuple 1 not correctly set");
204 bool ret2 = tupleObject->SetAttributeFailSafe (
"DoubleUintStringTuple",
209 ret2 = tupleObject->GetAttributeFailSafe (
"DoubleUintStringTuple", tupleValue2);
212 t2 = tupleValue2.
Get ();
215 NS_TEST_ASSERT_MSG_EQ ((std::get<2> (t2) ==
"Coulomb"),
true,
"Third element of tuple 2 not correctly set");
218 ret1 = tupleObject->SetAttributeFailSafe (
"StringStringEnumTuple",
StringValue (
"{Come, Together, VALUE1}"));
221 t1 = tupleObject->GetTuple1 ();
222 NS_TEST_ASSERT_MSG_EQ ((std::get<0> (t1) ==
"Come"),
true,
"First element of tuple 1 not correctly set");
223 NS_TEST_ASSERT_MSG_EQ ((std::get<1> (t1) ==
"Together"),
true,
"Second element of tuple 1 not correctly set");
227 ret2 = tupleObject->SetAttributeFailSafe (
"DoubleUintStringTuple",
StringValue (
"{2.99, 8, LightSpeed}"));
230 t2 = tupleObject->GetTuple2 ();
233 NS_TEST_ASSERT_MSG_EQ ((std::get<2> (t2) ==
"LightSpeed"),
true,
"Third element of tuple 2 not correctly set");
236 ret1 = tupleObject->SetAttributeFailSafe (
"StringStringEnumTuple",
240 "Tuple modified after failed assignment");
242 ret1 = tupleObject->SetAttributeFailSafe (
"StringStringEnumTuple",
246 "Tuple modified after failed assignment");
248 ret2 = tupleObject->SetAttributeFailSafe (
"DoubleUintStringTuple",
252 "Tuple modified after failed assignment");
254 ret2 = tupleObject->SetAttributeFailSafe (
"DoubleUintStringTuple",
258 "Tuple modified after failed assignment");
260 ret2 = tupleObject->SetAttributeFailSafe (
"DoubleUintStringTuple",
264 "Tuple modified after failed assignment");
278 :
TestSuite (
"tuple-value-test-suite", UNIT)
Object with attribute values storing tuples.
Tuple2 GetTuple2(void) const
Get tuple2.
void SetTuple1(const Tuple1 &tuple)
Set tuple1.
Tuple1Value::value_type Tuple1Pack
tuple of attribute values
Tuple2 m_tuple2
second tuple
Tuple1 GetTuple1(void) const
Get tuple1.
static TypeId GetTypeId()
Get the type ID.
Tuple1 m_tuple1
first tuple
TupleTestEnum
Test enum type.
void SetTuple2(const Tuple2 &tuple)
Set tuple2.
std::tuple< double, uint16_t, std::string > Tuple2
Tuple2 typedef.
Tuple1Value::result_type Tuple1
tuple of values
Test instantiation, initialization, access.
virtual ~TupleValueTestCase()
virtual void DoRun()
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...>.
result_type Get(void) const
Get the stored values as a std::tuple.
std::tuple< Args... > value_type
Type of value stored in the TupleValue.
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.
Ptr< const AttributeChecker > MakeStringChecker(void)
#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(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
static TupleValueTestSuite g_tupleValueTestSuite
Static variable for test initialization.