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"
89 .HideFromDocumentation ()
90 .AddAttribute (
"TestBoolName",
"help text",
93 MakeBooleanChecker ())
94 .AddAttribute (
"TestBoolA",
"help text",
98 MakeBooleanChecker ())
99 .AddAttribute (
"TestInt16",
"help text",
102 MakeIntegerChecker<int16_t> ())
103 .AddAttribute (
"TestInt16WithBounds",
"help text",
106 MakeIntegerChecker<int16_t> (-5, 10))
107 .AddAttribute (
"TestInt16SetGet",
"help text",
111 MakeIntegerChecker<int16_t> ())
112 .AddAttribute (
"TestUint8",
"help text",
115 MakeUintegerChecker<uint8_t> ())
116 .AddAttribute (
"TestEnum",
"help text",
122 .AddAttribute (
"TestRandom",
"help text",
123 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
125 MakePointerChecker <RandomVariableStream>())
126 .AddAttribute (
"TestFloat",
"help text",
129 MakeDoubleChecker<float> ())
130 .AddAttribute (
"TestVector1",
"help text",
133 MakeObjectVectorChecker<Derived> ())
134 .AddAttribute (
"TestVector2",
"help text",
138 MakeObjectVectorChecker<Derived> ())
139 .AddAttribute (
"TestMap1",
"help text",
142 MakeObjectMapChecker<Derived> ())
143 .AddAttribute (
"IntegerTraceSource1",
"help text",
146 MakeIntegerChecker<int8_t> ())
147 .AddAttribute (
"IntegerTraceSource2",
"help text",
151 MakeIntegerChecker<int8_t> ())
152 .AddAttribute (
"UIntegerTraceSource",
"help text",
155 MakeIntegerChecker<uint8_t> ())
156 .AddAttribute (
"DoubleTraceSource",
"help text",
159 MakeDoubleChecker<double> ())
160 .AddAttribute (
"BoolTraceSource",
"help text",
163 MakeBooleanChecker ())
164 .AddAttribute (
"EnumTraceSource",
"help text",
168 .AddAttribute (
"ValueClassSource",
"help text",
171 MakeValueClassTestChecker ())
172 .AddTraceSource (
"Source1",
"help test",
174 .AddTraceSource (
"Source2",
"help text",
176 .AddTraceSource (
"ValueSource",
"help text",
178 .AddAttribute (
"Pointer",
"help text",
181 MakePointerChecker<Derived> ())
182 .AddAttribute (
"PointerInitialized",
"help text",
185 MakePointerChecker<Derived> ())
186 .AddAttribute (
"PointerInitialized2",
"help text",
189 MakePointerChecker<Derived> ())
190 .AddAttribute (
"Callback",
"help text",
193 MakeCallbackChecker ())
194 .AddAttribute (
"TestTimeWithBounds",
"help text",
215 void AddToVector1 (
void) { m_vector1.push_back (CreateObject<Derived> ()); }
216 void AddToVector2 (
void) { m_vector2.push_back (CreateObject<Derived> ()); }
220 void InvokeCb (
double a,
int b,
float c) { m_cb (a,b,c); }
224 if (!m_cbValue.IsNull ()) {
250 std::map <uint32_t, Ptr<Derived> >
m_map1;
272 template <
typename T>
280 virtual void DoRun (
void);
282 bool CheckGetCodePaths (
Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
285 template <
typename T>
291 template <
typename T>
296 template <
typename T>
bool
299 std::string attributeName,
300 std::string expectedString,
310 bool ok2 = stringValue.
Get () == expectedString;
316 bool ok4 = expectedValue.Get () == actualValue.Get ();
318 return ok1 && ok2 && ok3 && ok4;
330 p = CreateObject<AttributeObjectTest> ();
338 p = CreateObject<AttributeObjectTest> ();
341 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
350 p = CreateObject<AttributeObjectTest> ();
353 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
362 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
363 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
371 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
372 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
377 p = CreateObject<AttributeObjectTest> ();
389 ok = CheckGetCodePaths (p,
"TestBoolA",
"true",
BooleanValue (
true));
390 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
398 ok = CheckGetCodePaths (p,
"TestBoolA",
"false",
BooleanValue (
false));
399 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
408 p = CreateObject<AttributeObjectTest> ();
415 ok = CheckGetCodePaths (p,
"TestInt16",
"-2",
IntegerValue (-2));
424 ok = CheckGetCodePaths (p,
"TestInt16",
"-5",
IntegerValue (-5));
425 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
433 ok = CheckGetCodePaths (p,
"TestInt16",
"2",
IntegerValue (2));
434 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
442 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
443 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
450 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
452 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
461 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
462 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
469 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
471 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
481 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
482 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
488 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
490 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
499 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
500 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
506 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
508 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
518 p = CreateObject<AttributeObjectTest> ();
525 ok = CheckGetCodePaths (p,
"TestUint8",
"1",
UintegerValue (1));
534 ok = CheckGetCodePaths (p,
"TestUint8",
"0",
UintegerValue (0));
535 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
543 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
544 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
553 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
563 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
564 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
571 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
573 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
580 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
589 p = CreateObject<AttributeObjectTest> ();
596 ok = CheckGetCodePaths (p,
"TestFloat",
"-1.1",
DoubleValue ((
float)-1.1));
605 ok = CheckGetCodePaths (p,
"TestFloat",
"2.3",
DoubleValue ((
float)2.3));
606 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
615 p = CreateObject<AttributeObjectTest> ();
632 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via EnumValue");
641 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
670 p = CreateObject<AttributeObjectTest> ();
679 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+5000000000.0ns",
TimeValue (
Seconds (5)));
680 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (5s) via TimeValue");
685 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+3000000000.0ns",
TimeValue (
Seconds (3)));
686 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (3s) via StringValue");
700 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+10000000000.0ns",
TimeValue (
Seconds (10)));
701 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
709 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"+10000000000.0ns",
TimeValue (
Seconds (10)));
718 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"-5000000000.0ns",
TimeValue (
Seconds (-5)));
719 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
727 ok = CheckGetCodePaths (p,
"TestTimeWithBounds",
"-5000000000.0ns",
TimeValue (
Seconds (-5)));
748 virtual void DoRun (
void);
768 p = CreateObject<AttributeObjectTest> ();
799 virtual void DoRun (
void);
813 p = CreateObject<AttributeObjectTest> ();
864 virtual void DoRun (
void);
878 p = CreateObject<AttributeObjectTest> ();
930 virtual void DoRun (
void);
945 p = CreateObject<AttributeObjectTest> ();
971 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
977 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
1002 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
1008 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
1022 virtual void DoRun (
void);
1039 p = CreateObject<AttributeObjectTest> ();
1058 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
1075 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
1094 virtual void DoRun (
void);
1112 p = CreateObject<AttributeObjectTest> ();
1168 virtual void DoRun (
void);
1186 p = CreateObject<AttributeObjectTest> ();
1197 NS_TEST_ASSERT_MSG_EQ (derived, 0,
"Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
1203 derived = Create<Derived> ();
1205 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a PointerValue of the correct type");
1223 NS_TEST_ASSERT_MSG_EQ (storedBase, stored,
"Retreived Ptr<Object> does not match stored Ptr<Derived>");
1231 NS_TEST_ASSERT_MSG_EQ (x, 0,
"Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
1241 p2->GetAttribute (
"PointerInitialized", ptr2);
1243 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr2,
"ptr and ptr2 both have PointerInitialized pointing to the same object");
1245 p2->GetAttribute (
"PointerInitialized", ptr3);
1247 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr3,
"ptr and ptr3 both have PointerInitialized pointing to the same object");
1253 factory.
SetTypeId (
"ns3::AttributeObjectTest");
1254 factory.
Set (
"PointerInitialized",
StringValue (
"ns3::Derived"));
1266 NS_TEST_ASSERT_MSG_NE (storedPtr4, storedPtr5,
"aotPtr and aotPtr2 are unique, but their Derived member is not");
1286 virtual void DoRun (
void);
1306 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)
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 SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
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
Hold a signed integer type.
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()
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.
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
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)
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)
Callback< void, int8_t > m_cbValue
hold objects of type Ptr<T>
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. Both limits are inclusive.
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 an 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.