9#include "ns3/attribute-container.h"
10#include "ns3/double.h"
11#include "ns3/integer.h"
13#include "ns3/object.h"
16#include "ns3/string.h"
19#include "ns3/type-id.h"
20#include "ns3/uinteger.h"
90 std::map<std::string, int>
m_map;
108 TypeId(
"ns3::AttributeContainerObject")
110 .SetGroupName(
"Test")
112 .AddAttribute(
"DoubleList",
120 "Vector of integers",
130 "Map of strings to ints",
140 "An example of complex attribute that is defined by a vector of pairs consisting "
141 "of an integer value and a vector of integers. In case a string is used to set "
142 "this attribute, the string shall contain the pairs separated by a semicolon (;); "
143 "in every pair, the integer value and the vector of integers are separated by a "
144 "blank space, and the elements of the vectors are separated by a comma (,) "
145 "without spaces. E.g. \"0 1,2,3; 1 0; 2 0,1\" consists of three pairs containing "
146 "vectors of 3, 1 and 2 elements, respectively.",
202 void DoRun()
override;
206 :
TestCase(
"test instantiation, initialization, access")
214 std::list<double>
ref = {1.0, 2.1, 3.145269};
230 std::vector<int>
ref = {-2, 3, 10, -1042};
246 auto ref = {
"one",
"two",
"three"};
261 auto ref = {
"one",
"two",
"three"};
277 std::map<std::string, int64_t>
ref = {{
"one", 1}, {
"two", 2}, {
"three", 3}};
282 for (
const auto& v :
ref)
286 v.first == (*aciter)->Get().first && v.second == (*aciter)->Get().second;
309 void DoRun()
override;
313 :
TestCase(
"test serialization and deserialization")
322 std::string
doubles =
"1.0001, 20.53, -102.3";
330 "Deserialize failed");
341 std::string
ints =
"1, 2, -3, -4";
349 "Deserialize failed");
359 std::string
strings =
"this is a sentence with words";
367 "Deserialize failed");
375 std::string
pairs =
"one 1,two 2,three 3";
384 "Deserialization failed");
392 std::string
tupleVec =
"{-1, 2, 3.4};{-2, 1, 4.3}";
402 "Deserialization failed");
425 void DoRun()
override;
429 :
TestCase(
"test attribute set and get")
442 const std::list<double>
doubles = {1.1, 2.22, 3.333};
448 "DoubleList incorrectly set");
451 obj->ReverseDoubleList();
456 "DoubleList incorrectly reversed");
460 obj->GetAttribute(
"DoubleList",
value);
467 "Incorrect value in doublesvec");
470 const std::vector<int>
ints = {-1, 0, 1, 2, 3};
477 obj->GetAttribute(
"IntegerVector",
value);
485 "Incorrect value in intvec");
497 obj->GetAttribute(
"IntVecPairVec",
value);
506 "Incorrect number of integer values in first pair");
511 "Incorrect number of integer values in second pair");
516 "Incorrect number of integer values in third pair");
519 std::map<std::string, int> map = {{
"one", 1}, {
"two", 2}, {
"three", 3}};
520 obj->SetAttribute(
"MapStringInt",
525 obj->GetAttribute(
"MapStringInt",
value);
531 for (
const auto&
l :
lst)
537 auto iter = map.begin();
540 bool valCheck = v.first == (*iter).first && v.second == (*iter).second;
static AttributeContainerTestSuite g_attributeContainerTestSuite
Static variable for test initialization.
Attribute container object.
std::vector< int > GetIntVec() const
Get the vector of ints.
std::vector< int > m_intvec
Vector of ints.
AttributeContainerObject()
void ReverseDoubleList()
Reverses the list of doubles.
std::list< double > m_doublelist
List of doubles.
~AttributeContainerObject() override
std::list< double > GetDoubleList() const
Get the list of doubles.
std::map< std::string, int > m_map
Map of <std::string, int>.
static TypeId GetTypeId()
Get the type ID.
void SetIntVec(std::vector< int > vec)
Set the vector of ints to the given vector.
void SetDoubleList(const std::list< double > &doubleList)
Set the list of doubles to the given list.
std::map< int64_t, std::list< int64_t > > m_intVecIntMapping
Mapping integers to vectors.
Attribute serialization and deserialization TestCase.
void DoRun() override
Implementation to actually run this TestCase.
AttributeContainerSerializationTestCase()
~AttributeContainerSerializationTestCase() override
Attribute set and get TestCase.
AttributeContainerSetGetTestCase()
~AttributeContainerSetGetTestCase() override
void DoRun() override
Implementation to actually run this TestCase.
Test AttributeContainer instantiation, initialization, access.
void DoRun() override
Implementation to actually run this TestCase.
AttributeContainerTestCase()
~AttributeContainerTestCase() override
Attribute attribute container TestCase.
AttributeContainerTestSuite()
A container for one type of attribute.
Iterator End()
NS3-style ending of container.
size_type GetN() const
NS3-style Number of items.
C< item_type > result_type
Type of container returned.
Iterator Begin()
NS3-style beginning of container.
Hold a signed integer type.
A base class which provides memory management and object aggregation.
AttributeValue implementation for Pair.
Smart pointer class similar to boost::intrusive_ptr.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< AttributeChecker > MakeAttributeContainerChecker()
Make uninitialized AttributeContainerChecker using explicit types.
Ptr< AttributeChecker > MakePairChecker()
Make a PairChecker without abscissa and ordinate AttributeCheckers.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#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.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static unsigned int value(char c)
Ptr< const AttributeChecker > MakeStringChecker()