20 #include "ns3/object.h"
21 #include "ns3/boolean.h"
22 #include "ns3/integer.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/config.h"
26 #include "ns3/string.h"
27 #include "ns3/random-variable-stream.h"
28 #include "ns3/double.h"
29 #include "ns3/object-vector.h"
30 #include "ns3/object-map.h"
31 #include "ns3/traced-value.h"
32 #include "ns3/callback.h"
33 #include "ns3/trace-source-accessor.h"
34 #include "ns3/pointer.h"
35 #include "ns3/object-factory.h"
36 #include "ns3/nstime.h"
90 .HideFromDocumentation ()
91 .AddAttribute (
"TestBoolName",
"help text",
94 MakeBooleanChecker ())
95 .AddAttribute (
"TestBoolA",
"help text",
99 MakeBooleanChecker ())
100 .AddAttribute (
"TestInt16",
"help text",
103 MakeIntegerChecker<int16_t> ())
104 .AddAttribute (
"TestInt16WithBounds",
"help text",
107 MakeIntegerChecker<int16_t> (-5, 10))
108 .AddAttribute (
"TestInt16SetGet",
"help text",
112 MakeIntegerChecker<int16_t> ())
113 .AddAttribute (
"TestUint8",
"help text",
116 MakeUintegerChecker<uint8_t> ())
117 .AddAttribute (
"TestEnum",
"help text",
123 .AddAttribute (
"TestRandom",
"help text",
124 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
126 MakePointerChecker <RandomVariableStream>())
127 .AddAttribute (
"TestFloat",
"help text",
130 MakeDoubleChecker<float> ())
131 .AddAttribute (
"TestVector1",
"help text",
134 MakeObjectVectorChecker<Derived> ())
135 .AddAttribute (
"TestVector2",
"help text",
139 MakeObjectVectorChecker<Derived> ())
140 .AddAttribute (
"TestMap1",
"help text",
143 MakeObjectMapChecker<Derived> ())
144 .AddAttribute (
"IntegerTraceSource1",
"help text",
147 MakeIntegerChecker<int8_t> ())
148 .AddAttribute (
"IntegerTraceSource2",
"help text",
152 MakeIntegerChecker<int8_t> ())
153 .AddAttribute (
"UIntegerTraceSource",
"help text",
156 MakeIntegerChecker<uint8_t> ())
157 .AddAttribute (
"DoubleTraceSource",
"help text",
160 MakeDoubleChecker<double> ())
161 .AddAttribute (
"BoolTraceSource",
"help text",
164 MakeBooleanChecker ())
165 .AddAttribute (
"EnumTraceSource",
"help text",
169 .AddAttribute (
"ValueClassSource",
"help text",
172 MakeValueClassTestChecker ())
173 .AddTraceSource (
"Source1",
"help test",
175 .AddTraceSource (
"Source2",
"help text",
177 .AddTraceSource (
"ValueSource",
"help text",
179 .AddAttribute (
"Pointer",
"help text",
182 MakePointerChecker<Derived> ())
183 .AddAttribute (
"PointerInitialized",
"help text",
186 MakePointerChecker<Derived> ())
187 .AddAttribute (
"PointerInitialized2",
"help text",
190 MakePointerChecker<Derived> ())
191 .AddAttribute (
"Callback",
"help text",
194 MakeCallbackChecker ())
195 .AddAttribute (
"TestTimeWithBounds",
"help text",
216 void AddToVector1 (
void) { m_vector1.push_back (CreateObject<Derived> ()); }
217 void AddToVector2 (
void) { m_vector2.push_back (CreateObject<Derived> ()); }
221 void InvokeCb (
double a,
int b,
float c) { m_cb (a,b,c); }
225 if (!m_cbValue.IsNull ()) {
251 std::map <uint32_t, Ptr<Derived> >
m_map1;
274 template <
typename T>
282 virtual void DoRun (
void);
284 bool CheckGetCodePaths (
Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
287 template <
typename T>
293 template <
typename T>
298 template <
typename T>
bool
301 std::string attributeName,
302 std::string expectedString,
312 bool ok2 = stringValue.
Get () == expectedString;
318 bool ok4 = expectedValue.Get () == actualValue.Get ();
320 return ok1 && ok2 && ok3 && ok4;
332 p = CreateObject<AttributeObjectTest> ();
340 p = CreateObject<AttributeObjectTest> ();
343 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
352 p = CreateObject<AttributeObjectTest> ();
355 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
364 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
365 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
373 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
374 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
379 p = CreateObject<AttributeObjectTest> ();
391 ok = CheckGetCodePaths (p,
"TestBoolA",
"true",
BooleanValue (
true));
392 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
400 ok = CheckGetCodePaths (p,
"TestBoolA",
"false",
BooleanValue (
false));
401 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
410 p = CreateObject<AttributeObjectTest> ();
417 ok = CheckGetCodePaths (p,
"TestInt16",
"-2",
IntegerValue (-2));
426 ok = CheckGetCodePaths (p,
"TestInt16",
"-5",
IntegerValue (-5));
427 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
435 ok = CheckGetCodePaths (p,
"TestInt16",
"2",
IntegerValue (2));
436 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
444 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
445 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
452 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
454 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
463 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
464 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
471 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
473 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
483 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
484 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
490 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
492 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
501 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
502 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
508 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
510 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
520 p = CreateObject<AttributeObjectTest> ();
527 ok = CheckGetCodePaths (p,
"TestUint8",
"1",
UintegerValue (1));
536 ok = CheckGetCodePaths (p,
"TestUint8",
"0",
UintegerValue (0));
537 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
545 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
546 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
555 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
565 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
566 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
573 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
575 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
582 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
591 p = CreateObject<AttributeObjectTest> ();
598 ok = CheckGetCodePaths (p,
"TestFloat",
"-1.1",
DoubleValue ((
float)-1.1));
607 ok = CheckGetCodePaths (p,
"TestFloat",
"2.3",
DoubleValue ((
float)2.3));
608 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
617 p = CreateObject<AttributeObjectTest> ();
634 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via EnumValue");
643 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
672 p = CreateObject<AttributeObjectTest> ();
681 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+5000000000.0ns",
TimeValue (
Seconds (5)));
682 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (5s) via TimeValue");
687 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+3000000000.0ns",
TimeValue (
Seconds (3)));
688 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (3s) via StringValue");
702 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+10000000000.0ns",
TimeValue (
Seconds (10)));
703 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
711 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+10000000000.0ns",
TimeValue (
Seconds (10)));
720 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"-5000000000.0ns",
TimeValue (
Seconds (-5)));
721 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
729 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"-5000000000.0ns",
TimeValue (
Seconds (-5)));
750 virtual void DoRun (
void);
770 p = CreateObject<AttributeObjectTest> ();
801 virtual void DoRun (
void);
815 p = CreateObject<AttributeObjectTest> ();
866 virtual void DoRun (
void);
880 p = CreateObject<AttributeObjectTest> ();
932 virtual void DoRun (
void);
947 p = CreateObject<AttributeObjectTest> ();
973 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
979 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
1004 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
1010 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
1024 virtual void DoRun (
void);
1041 p = CreateObject<AttributeObjectTest> ();
1060 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
1077 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
1096 virtual void DoRun (
void);
1114 p = CreateObject<AttributeObjectTest> ();
1170 virtual void DoRun (
void);
1188 p = CreateObject<AttributeObjectTest> ();
1199 NS_TEST_ASSERT_MSG_EQ (derived, 0,
"Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
1205 derived = Create<Derived> ();
1207 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a PointerValue of the correct type");
1225 NS_TEST_ASSERT_MSG_EQ (storedBase, stored,
"Retreived Ptr<Object> does not match stored Ptr<Derived>");
1233 NS_TEST_ASSERT_MSG_EQ (x, 0,
"Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
1243 p2->GetAttribute (
"PointerInitialized", ptr2);
1245 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr2,
"ptr and ptr2 both have PointerInitialized pointing to the same object");
1247 p2->GetAttribute (
"PointerInitialized", ptr3);
1249 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr3,
"ptr and ptr3 both have PointerInitialized pointing to the same object");
1255 factory.
SetTypeId (
"ns3::AttributeObjectTest");
1256 factory.
Set (
"PointerInitialized",
StringValue (
"ns3::Derived"));
1268 NS_TEST_ASSERT_MSG_NE (storedPtr4, storedPtr5,
"aotPtr and aotPtr2 are unique, but their Derived member is not");
1288 virtual void DoRun (
void);
1308 p = CreateObject<AttributeObjectTest> ();
void InvokeCbValue(int8_t a)
int16_t m_int16WithBounds
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
ATTRIBUTE_HELPER_HEADER(ObjectFactory)
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
TracedValue< enum Test_e > m_enumSrc
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
keep track of time values and allow control of global simulation resolution
virtual ~RandomVariableStreamAttributeTestCase()
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
std::string Get(void) const
Ptr< Derived > m_ptrInitialized2
TypeId AddConstructor(void)
TracedValue< uint8_t > m_uintSrc
bool CheckGetCodePaths(Ptr< Object > p, std::string attributeName, std::string expectedString, T expectedValue)
virtual ~AttributeObjectTest(void)
Ptr< Derived > m_ptrInitialized
hold variables of type string
Ptr< Derived > DoGetVector(uint32_t i) const
virtual void DoRun(void)
Implementation to actually run this TestCase.
void NotifySource2(double a, int b, float c)
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::vector< Ptr< Derived > > m_vector2
bool IsNull(void) const
Check for null implementation.
Hold a signed integer type.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void SetTypeId(TypeId tid)
#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...
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberContainer)
bool DoGetTestB(void) const
Callback< void, int8_t > m_cbValue
ObjectMapAttributeTestCase(std::string description)
RandomVariableStreamAttributeTestCase(std::string description)
std::map< uint32_t, Ptr< Derived > > m_map1
IntegerTraceSourceAttributeTestCase(std::string description)
void NotifyCallbackValue(int8_t a)
virtual ~CallbackValueTestCase()
AttributeValue form of a Callback.
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
virtual void DoRun(void)
Implementation to actually run this TestCase.
std::vector< Ptr< Derived > > m_vector1
Ptr< Object > Get(uint32_t i) const
TracedCallbackTestCase(std::string description)
hold variables of type 'enum'
TracedValue< int8_t > m_intSrc2
hold objects of type ns3::Time
Ptr< Object > Create(void) const
int16_t DoGetInt16(void) const
Hold an unsigned integer type.
void NotifySource2(double a, int b, float c)
virtual void DoRun(void)
Implementation to actually run this TestCase.
IntegerTraceSourceTestCase(std::string description)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void NotifySource1(int8_t old, int8_t n)
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
TracedValue< int8_t > m_intSrc1
virtual ~PointerAttributeTestCase()
void AddToMap1(uint32_t i)
TracedCallback< double, int, float > m_cb
void DoSetInt16(int16_t v)
AttributeObjectTest(void)
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
TracedValue< ValueClassTest > m_valueSrc
void SetDefault(std::string name, const AttributeValue &value)
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Callback< void, int8_t > m_cbValue
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual ~AttributeTestCase()
ObjectVectorAttributeTestCase(std::string description)
virtual void DoRun(void)
Implementation to actually run this TestCase.
void Set(std::string name, const AttributeValue &value)
virtual ~ObjectMapAttributeTestCase()
void GetAttribute(std::string name, AttributeValue &value) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
static AttributesTestSuite attributesTestSuite
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
void InvokeCb(double a, int b, float c)
int8_t DoGetIntSrc(void) const
TracedValue< double > m_doubleSrc
instantiate subclasses of ns3::Object.
AttributeTestCase(std::string description)
virtual void DoRun(void)
Implementation to actually run this TestCase.
static TypeId GetTypeId(void)
uint32_t DoGetVectorN(void) const
bool DoSetIntSrc(int8_t v)
void NotifyCallbackValue(int8_t a)
virtual ~ObjectVectorAttributeTestCase()
virtual ~TracedCallbackTestCase()
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
static TypeId GetTypeId(void)
bool GetAttributeFailSafe(std::string name, AttributeValue &attribute) const
Ptr< RandomVariableStream > m_random
uint32_t GetN(void) const
a base class which provides memory management and object aggregation
ATTRIBUTE_HELPER_CPP(ObjectFactory)
void InvokeCbValue(int8_t a)
contain a set of ns3::Object pointers.
TracedValue< bool > m_boolSrc
PointerAttributeTestCase(std::string description)
Hold a floating point type.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
CallbackValueTestCase(std::string description)
virtual ~IntegerTraceSourceAttributeTestCase()
virtual ~IntegerTraceSourceTestCase()
Callback< void, int8_t > m_cbValue
virtual void DoRun(void)
Implementation to actually run this TestCase.
void InvokeCbValue(int8_t a)
virtual void DoRun(void)
Implementation to actually run this TestCase.
#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.