9#include "ns3/attribute-container.h"
10#include "ns3/double.h"
11#include "ns3/object.h"
12#include "ns3/string.h"
13#include "ns3/struct.h"
15#include "ns3/uinteger.h"
76 return {std::move(name), count, value};
176 TypeId(
"ns3::StructObject")
178 .SetGroupName(
"Test")
180 .AddAttribute(
"MemberStruct",
181 "Structure accessed as a data member",
189 "Structure whose fields are accessed through getters and setters",
195 .AddAttribute(
"MethodStruct",
196 "Structure accessed through a getter and a setter",
226 void DoRun()
override;
230 :
TestCase(
"test StructValue attribute value")
241 "The data member did not receive its default value");
244 "The setter did not receive its default value");
247 "The private structure did not receive its default value");
249 auto success =
object->SetAttributeFailSafe(
"MemberStruct",
254 "The data member was not updated");
257 success =
object->GetAttributeFailSafe(
"MemberStruct", value);
261 "The StructValue does not contain the data member fields");
263 success =
object->SetAttributeFailSafe(
"PrivateStruct",
StringValue(
"{accessors, 7, 8.5}"));
267 "The private fields were not updated through their setters");
270 success =
object->GetAttributeFailSafe(
"PrivateStruct", privateValue);
274 "The private fields were not read through their getters");
276 auto constructorChecker =
281 success = constructedValue.DeserializeFromString(
"{constructed, 9, 1.5}", constructorChecker);
285 "The private fields were not passed to the constructor function");
287 success =
object->SetAttributeFailSafe(
"MethodStruct",
StringValue(
"{parsed, 8, 9.5}"));
291 "The deserialized structure was not passed to the setter");
293 success =
object->SetAttributeFailSafe(
"MethodStruct",
298 "The structure changed after a failed assignment");
300 success =
object->SetAttributeFailSafe(
"MethodStruct",
StringValue(
"{incomplete}"));
304 "The structure changed after failed deserialization");
311 "The structure was not serialized as a tuple");
317 "Copy did not preserve the structure fields");
321 std::set<uint8_t> ids;
323 bool operator==(
const ContainerData&)
const =
default;
326 using ContainerValue =
331 ContainerValue containerValue(ContainerData{{1, 3, 5}});
334 "Container field was not stored from the data member");
337 "Container field was not serialized with the item separator");
340 "Deserializing a container field failed");
343 "Container field was not written back to the data member");
Object containing attributes represented by structures.
StructTestData GetMethodStruct() const
Get the structure accessed through methods.
StructTestData m_memberStruct
Structure accessed as a data member.
PrivateStructTestData m_privateStruct
Structure whose fields are accessed through methods.
void SetMethodStruct(const StructTestData &value)
Set the structure accessed through methods.
static TypeId GetTypeId()
Get the type ID.
StructTestData m_methodStruct
Structure accessed through methods.
Test StructValue construction, checking, serialization, and access.
void DoRun() override
Implementation to actually run this TestCase.
StructValueTestCase()
Constructor.
StructValueTestSuite()
Constructor.
A container for one type of attribute.
Object()
Caller graph was not generated because of its size.
Hold variables of type string.
AttributeValue implementation for structures.
result_type Get() const
Get the stored fields as a structure.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
Ptr< AttributeChecker > MakeAttributeContainerChecker(const AttributeContainerValue< A, Sep, C > &value)
Make AttributeContainerChecker from AttributeContainerValue.
Ptr< const AttributeChecker > MakeStructChecker(Ts... checkers)
Create a StructChecker from the AttributeCheckers associated with the fields.
Ptr< const AttributeAccessor > MakeStructAccessor(T1 a1)
Create an AttributeAccessor for a structure data member, or for a lone class get functor or set metho...
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 > MakeUintegerChecker()
bool operator==(const EventId &a, const EventId &b)
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Ptr< const AttributeChecker > MakeStringChecker()
static StructValueTestSuite g_structValueTestSuite
Static test suite registration.
StructValue< PrivateStructTestData, StructConstructor<&PrivateStructTestData::Create >, StructField< StringValue, &PrivateStructTestData::m_name >, StructField< UintegerValue, &PrivateStructTestData::GetCount >, StructField< DoubleValue, &PrivateStructTestData::GetValue > > ConstructedStructTestValue
StructValue using a constructor function and getters for private fields.
StructValue< StructTestData, StructField< StringValue, &StructTestData::name >, StructField< UintegerValue, &StructTestData::count >, StructField< DoubleValue, &StructTestData::value > > StructTestValue
StructValue type used by the tests.
StructValue< PrivateStructTestData, StructField< StringValue, &PrivateStructTestData::m_name >, StructField< UintegerValue, &PrivateStructTestData::GetCount, &PrivateStructTestData::SetCount >, StructField< DoubleValue, &PrivateStructTestData::GetValue, &PrivateStructTestData::SetValue > > PrivateStructTestValue
StructValue using getters and setters to access private fields.
Structure with private fields used by the StructValue tests.
uint16_t m_count
Count field.
PrivateStructTestData(std::string name, uint16_t count, double value)
Construct an instance with the given field values.
std::string m_name
Name field (publicly accessible).
PrivateStructTestData()=default
Default constructor.
bool operator==(const PrivateStructTestData &) const =default
Compare two structures.
uint16_t GetCount() const
void SetValue(double value)
Set the value field.
static PrivateStructTestData Create(std::string name, uint16_t count, double value)
Construct an instance from its field values.
double m_value
Value field.
void SetCount(uint16_t count)
Set the count field.
Structure used by the StructValue tests.
uint16_t count
Count field.
std::string name
Name field.
bool operator==(const StructTestData &) const =default
Compare two structures.
Describe a function that constructs a structure from its field values.
Describe a structure field and the AttributeValue used to represent it.