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};
219 auto aciter = ac.
Begin();
220 for (
auto rend = ref.end(), riter = ref.begin(); riter != rend; ++riter)
230 std::vector<int> ref = {-2, 3, 10, -1042};
235 auto aciter = ac.
Begin();
236 for (
auto rend = ref.end(), riter = ref.begin(); riter != rend; ++riter)
246 auto ref = {
"one",
"two",
"three"};
250 auto aciter = ac.
Begin();
261 auto ref = {
"one",
"two",
"three"};
265 auto aciter = ac.Begin();
277 std::map<std::string, int64_t> ref = {{
"one", 1}, {
"two", 2}, {
"three", 3}};
281 auto aciter = ac.
Begin();
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");
334 std::string canonical = doubles;
335 canonical.erase(std::remove(canonical.begin(), canonical.end(),
' '), canonical.end());
341 std::string ints =
"1, 2, -3, -4";
349 "Deserialize failed");
353 std::string canonical = ints;
354 canonical.erase(std::remove(canonical.begin(), canonical.end(),
' '), canonical.end());
359 std::string strings =
"this is a sentence with words";
367 "Deserialize failed");
375 std::string pairs =
"one 1,two 2,three 3";
379 acchecker->SetItemChecker(
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")
438 auto doubleList = obj->GetDoubleList();
442 const std::list<double> doubles = {1.1, 2.22, 3.333};
445 auto doubleList = obj->GetDoubleList();
448 "DoubleList incorrectly set");
451 obj->ReverseDoubleList();
453 auto doubleList = obj->GetDoubleList();
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");
488 std::string intVecPairString(
"0 1,2,3; 1 0; 2 0,1");
490 obj->SetAttribute(
"IntVecPairVec",
StringValue(intVecPairString));
497 obj->GetAttribute(
"IntVecPairVec", value);
502 auto reslistIt = reslist.begin();
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);
529 std::map<std::string, int> mapstrint;
530 auto lst = value.Get();
531 for (
const auto& l : lst)
533 mapstrint[l.first] = l.second;
537 auto iter = map.begin();
538 for (
const auto& v : mapstrint)
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.
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
C< item_type > result_type
Type of container returned.
Iterator Begin()
NS3-style beginning of container.
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
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< const AttributeAccessor > MakeAttributeContainerAccessor(T1 a1)
Make AttributeContainerAccessor using explicit types.
Ptr< AttributeChecker > MakePairChecker()
Make a PairChecker without abscissa and ordinate AttributeCheckers.
Ptr< const AttributeChecker > MakeTupleChecker(Ts... checkers)
Create a TupleChecker from AttributeCheckers associated with TupleValue elements.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
Ptr< const AttributeChecker > MakeIntegerChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Ptr< const AttributeChecker > MakeStringChecker()