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"
64 static TypeId GetTypeId (
void) {
74 NS_OBJECT_ENSURE_REGISTERED (
Derived);
84 static TypeId GetTypeId (
void) {
88 .HideFromDocumentation ()
89 .AddAttribute (
"TestBoolName",
"help text",
91 MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
92 MakeBooleanChecker ())
93 .AddAttribute (
"TestBoolA",
"help text",
95 MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
96 &AttributeObjectTest::DoGetTestB),
97 MakeBooleanChecker ())
98 .AddAttribute (
"TestInt16",
"help text",
100 MakeIntegerAccessor (&AttributeObjectTest::m_int16),
101 MakeIntegerChecker<int16_t> ())
102 .AddAttribute (
"TestInt16WithBounds",
"help text",
104 MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
105 MakeIntegerChecker<int16_t> (-5, 10))
106 .AddAttribute (
"TestInt16SetGet",
"help text",
108 MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
109 &AttributeObjectTest::DoGetInt16),
110 MakeIntegerChecker<int16_t> ())
111 .AddAttribute (
"TestUint8",
"help text",
113 MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
114 MakeUintegerChecker<uint8_t> ())
115 .AddAttribute (
"TestEnum",
"help text",
117 MakeEnumAccessor (&AttributeObjectTest::m_enum),
118 MakeEnumChecker (TEST_A,
"TestA",
121 .AddAttribute (
"TestRandom",
"help text",
122 StringValue (
"ns3::ConstantRandomVariable[Constant=1.0]"),
123 MakePointerAccessor (&AttributeObjectTest::m_random),
124 MakePointerChecker <RandomVariableStream>())
125 .AddAttribute (
"TestFloat",
"help text",
127 MakeDoubleAccessor (&AttributeObjectTest::m_float),
128 MakeDoubleChecker<float> ())
129 .AddAttribute (
"TestVector1",
"help text",
131 MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
132 MakeObjectVectorChecker<Derived> ())
133 .AddAttribute (
"TestVector2",
"help text",
135 MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
136 &AttributeObjectTest::DoGetVector),
137 MakeObjectVectorChecker<Derived> ())
138 .AddAttribute (
"TestMap1",
"help text",
140 MakeObjectMapAccessor (&AttributeObjectTest::m_map1),
141 MakeObjectMapChecker<Derived> ())
142 .AddAttribute (
"IntegerTraceSource1",
"help text",
144 MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
145 MakeIntegerChecker<int8_t> ())
146 .AddAttribute (
"IntegerTraceSource2",
"help text",
148 MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
149 &AttributeObjectTest::DoGetIntSrc),
150 MakeIntegerChecker<int8_t> ())
151 .AddAttribute (
"UIntegerTraceSource",
"help text",
153 MakeUintegerAccessor (&AttributeObjectTest::m_uintSrc),
154 MakeIntegerChecker<uint8_t> ())
155 .AddAttribute (
"DoubleTraceSource",
"help text",
157 MakeDoubleAccessor (&AttributeObjectTest::m_doubleSrc),
158 MakeDoubleChecker<double> ())
159 .AddAttribute (
"BoolTraceSource",
"help text",
161 MakeBooleanAccessor (&AttributeObjectTest::m_boolSrc),
162 MakeBooleanChecker ())
163 .AddAttribute (
"EnumTraceSource",
"help text",
165 MakeEnumAccessor (&AttributeObjectTest::m_enumSrc),
166 MakeEnumChecker (TEST_A,
"TestA"))
167 .AddAttribute (
"ValueClassSource",
"help text",
169 MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
170 MakeValueClassTestChecker ())
171 .AddTraceSource (
"Source1",
"help test",
173 .AddTraceSource (
"Source2",
"help text",
175 .AddTraceSource (
"ValueSource",
"help text",
177 .AddAttribute (
"Pointer",
"help text",
179 MakePointerAccessor (&AttributeObjectTest::m_ptr),
180 MakePointerChecker<Derived> ())
181 .AddAttribute (
"PointerInitialized",
"help text",
183 MakePointerAccessor (&AttributeObjectTest::m_ptrInitialized),
184 MakePointerChecker<Derived> ())
185 .AddAttribute (
"PointerInitialized2",
"help text",
187 MakePointerAccessor (&AttributeObjectTest::m_ptrInitialized2),
188 MakePointerChecker<Derived> ())
189 .AddAttribute (
"Callback",
"help text",
191 MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
192 MakeCallbackChecker ())
198 void AddToVector1 (
void) { m_vector1.push_back (CreateObject<Derived> ()); }
199 void AddToVector2 (
void) { m_vector2.push_back (CreateObject<Derived> ()); }
201 void AddToMap1 (uint32_t i) { m_map1.insert (std::pair <uint32_t,
Ptr<Derived> > (i, CreateObject<Derived> ())); }
203 void InvokeCb (
double a,
int b,
float c) { m_cb (a,b,c); }
205 void InvokeCbValue (int8_t a)
207 if (!m_cbValue.IsNull ()) {
213 void DoSetTestB (
bool v) { m_boolTestA = v; }
214 bool DoGetTestB (
void)
const {
return m_boolTestA; }
215 int16_t DoGetInt16 (
void)
const {
return m_int16SetGet; }
216 void DoSetInt16 (int16_t v) { m_int16SetGet = v; }
217 uint32_t DoGetVectorN (
void)
const {
return m_vector2.size (); }
218 Ptr<Derived> DoGetVector (uint32_t i)
const {
return m_vector2[i]; }
219 bool DoSetIntSrc (int8_t v) { m_intSrc2 = v;
return true; }
220 int8_t DoGetIntSrc (
void)
const {
return m_intSrc2; }
225 int16_t m_int16WithBounds;
226 int16_t m_int16SetGet;
231 std::vector<Ptr<Derived> > m_vector1;
232 std::vector<Ptr<Derived> > m_vector2;
233 std::map <uint32_t, Ptr<Derived> > m_map1;
254 template <
typename T>
262 virtual void DoRun (
void);
264 bool CheckGetCodePaths (
Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
267 template <
typename T>
273 template <
typename T>
278 template <
typename T>
bool
281 std::string attributeName,
282 std::string expectedString,
292 bool ok2 = stringValue.Get () == expectedString;
298 bool ok4 = expectedValue.Get () == actualValue.Get ();
300 return ok1 && ok2 && ok3 && ok4;
312 p = CreateObject<AttributeObjectTest> ();
313 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
319 Config::SetDefault (
"ns3::AttributeObjectTest::TestBoolName",
StringValue (
"true"));
320 p = CreateObject<AttributeObjectTest> ();
321 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
323 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
324 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by default value");
330 Config::SetDefaultFailSafe (
"ns3::AttributeObjectTest::TestBoolName",
StringValue (
"false"));
332 p = CreateObject<AttributeObjectTest> ();
333 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
335 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
336 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not et properly by default value");
342 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() \"TestBoolName\" to true");
344 ok = CheckGetCodePaths (p,
"TestBoolName",
"true",
BooleanValue (
true));
345 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
351 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() \"TestBoolName\" to false");
353 ok = CheckGetCodePaths (p,
"TestBoolName",
"false",
BooleanValue (
false));
354 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
359 p = CreateObject<AttributeObjectTest> ();
360 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
369 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a boolean value to true");
371 ok = CheckGetCodePaths (p,
"TestBoolA",
"true",
BooleanValue (
true));
372 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
378 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a boolean value to false");
380 ok = CheckGetCodePaths (p,
"TestBoolA",
"false",
BooleanValue (
false));
381 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
390 p = CreateObject<AttributeObjectTest> ();
391 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
397 ok = CheckGetCodePaths (p,
"TestInt16",
"-2",
IntegerValue (-2));
398 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by default value");
404 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via StringValue to -5");
406 ok = CheckGetCodePaths (p,
"TestInt16",
"-5",
IntegerValue (-5));
407 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
413 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via StringValue to +2");
415 ok = CheckGetCodePaths (p,
"TestInt16",
"2",
IntegerValue (2));
416 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
422 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via StringValue to -32768");
424 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
425 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
432 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
434 ok = CheckGetCodePaths (p,
"TestInt16",
"-32768",
IntegerValue (-32768));
435 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
441 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via StringValue to 32767");
443 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
444 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
451 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
453 ok = CheckGetCodePaths (p,
"TestInt16",
"32767",
IntegerValue (32767));
454 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
461 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 10");
463 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
464 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
470 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
472 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"10",
IntegerValue (10));
473 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
479 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to -5");
481 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
482 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
488 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
490 ok = CheckGetCodePaths (p,
"TestInt16WithBounds",
"-5",
IntegerValue (-5));
491 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
500 p = CreateObject<AttributeObjectTest> ();
501 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
507 ok = CheckGetCodePaths (p,
"TestUint8",
"1",
UintegerValue (1));
508 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by default value");;
514 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() to 0");
516 ok = CheckGetCodePaths (p,
"TestUint8",
"0",
UintegerValue (0));
517 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
523 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() to 255");
525 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
526 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
533 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() to 256");
535 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
536 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
543 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via StringValue to 255");
545 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
546 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
553 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
555 ok = CheckGetCodePaths (p,
"TestUint8",
"255",
UintegerValue (255));
556 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
562 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
571 p = CreateObject<AttributeObjectTest> ();
572 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
578 ok = CheckGetCodePaths (p,
"TestFloat",
"-1.1",
DoubleValue ((
float)-1.1));
579 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by default value");
585 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() to 2.3");
587 ok = CheckGetCodePaths (p,
"TestFloat",
"2.3",
DoubleValue ((
float)2.3));
588 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
597 p = CreateObject<AttributeObjectTest> ();
598 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
604 ok = CheckGetCodePaths (p,
"TestEnum",
"TestA",
EnumValue (AttributeObjectTest::TEST_A));
605 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by default value");
611 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() to TEST_C");
613 ok = CheckGetCodePaths (p,
"TestEnum",
"TestC",
EnumValue (AttributeObjectTest::TEST_C));
614 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via EnumValue");
620 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() to TEST_B");
622 ok = CheckGetCodePaths (p,
"TestEnum",
"TestB",
EnumValue (AttributeObjectTest::TEST_B));
623 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Attribute not set properly by SetAttributeFailSafe() via StringValue");
630 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() to TEST_D");
632 ok = CheckGetCodePaths (p,
"TestEnum",
"TestB",
EnumValue (AttributeObjectTest::TEST_B));
633 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
640 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() to 5");
642 ok = CheckGetCodePaths (p,
"TestEnum",
"TestB",
EnumValue (AttributeObjectTest::TEST_B));
643 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Error in SetAttributeFailSafe() but value changes");
655 void InvokeCbValue (int8_t a)
657 if (!m_cbValue.IsNull ()) {
663 virtual void DoRun (
void);
667 void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; }
669 int16_t m_gotCbValue;
672 RandomVariableStreamAttributeTestCase::RandomVariableStreamAttributeTestCase (std::string description)
683 p = CreateObject<AttributeObjectTest> ();
684 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
690 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a UniformRandomVariable");
700 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a ConstantRandomVariable");
714 virtual void DoRun (
void);
717 ObjectVectorAttributeTestCase::ObjectVectorAttributeTestCase (std::string description)
728 p = CreateObject<AttributeObjectTest> ();
729 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
736 NS_TEST_ASSERT_MSG_EQ (vector.
GetN (), 0,
"Initial count of ObjectVectorValue \"TestVector1\" should be zero");
742 NS_TEST_ASSERT_MSG_EQ (vector.
GetN (), 0,
"Initial count of ObjectVectorValue \"TestVector1\" should still be zero");
748 NS_TEST_ASSERT_MSG_EQ (vector.
GetN (), 1,
"ObjectVectorValue \"TestVector1\" should be incremented");
754 NS_TEST_ASSERT_MSG_NE (a, 0,
"Ptr<Object> from VectorValue \"TestVector1\" is zero");
760 NS_TEST_ASSERT_MSG_EQ (vector.
GetN (), 1,
"Count of ObjectVectorValue \"TestVector1\" should still be one");
766 NS_TEST_ASSERT_MSG_EQ (vector.
GetN (), 2,
"ObjectVectorValue \"TestVector1\" should be incremented");
779 virtual void DoRun (
void);
782 ObjectMapAttributeTestCase::ObjectMapAttributeTestCase (std::string description)
793 p = CreateObject<AttributeObjectTest> ();
794 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
801 NS_TEST_ASSERT_MSG_EQ (map.
GetN (), 0,
"Initial count of ObjectVectorValue \"TestMap1\" should be zero");
807 NS_TEST_ASSERT_MSG_EQ (map.
GetN (), 0,
"Initial count of ObjectVectorValue \"TestMap1\" should still be zero");
813 NS_TEST_ASSERT_MSG_EQ (map.
GetN (), 1,
"ObjectVectorValue \"TestMap1\" should be incremented");
819 NS_TEST_ASSERT_MSG_NE (a, 0,
"Ptr<Object> from VectorValue \"TestMap1\" is zero");
825 NS_TEST_ASSERT_MSG_EQ (map.
GetN (), 1,
"Count of ObjectVectorValue \"TestMap1\" should still be one");
831 NS_TEST_ASSERT_MSG_EQ (map.
GetN (), 2,
"ObjectVectorValue \"TestMap1\" should be incremented");
845 virtual void DoRun (
void);
848 IntegerTraceSourceAttributeTestCase::IntegerTraceSourceAttributeTestCase (std::string description)
860 p = CreateObject<AttributeObjectTest> ();
861 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
868 NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2,
"Attribute not set properly by default value");
874 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 5");
877 NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5,
"Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
883 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 127");
886 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
889 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to -128");
892 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
899 NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2,
"Attribute not set properly by default value");
905 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 5");
908 NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5,
"Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
914 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 127");
917 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
920 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to -128");
923 NS_TEST_ASSERT_MSG_EQ (ok,
false,
"Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
937 virtual void DoRun (
void);
939 void NotifySource1 (int8_t old, int8_t n) { m_got1 = n; }
943 IntegerTraceSourceTestCase::IntegerTraceSourceTestCase (std::string description)
954 p = CreateObject<AttributeObjectTest> ();
955 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
964 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to -1");
973 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
981 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 0");
983 NS_TEST_ASSERT_MSG_EQ (m_got1, 0,
"Hitting a TracedValue does not cause trace callback to be called");
990 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
993 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() via IntegerValue to 1");
995 NS_TEST_ASSERT_MSG_EQ (m_got1, 0,
"Hitting a TracedValue after disconnect still causes callback");
1009 virtual void DoRun (
void);
1011 void NotifySource2 (
double a,
int b,
float c) { m_got2 = a; }
1016 TracedCallbackTestCase::TracedCallbackTestCase (std::string description)
1027 p = CreateObject<AttributeObjectTest> ();
1028 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
1043 p->InvokeCb (1.0, -5, 0.0);
1044 NS_TEST_ASSERT_MSG_EQ (m_got2, 4.3,
"Invoking a newly created TracedCallback results in an unexpected callback");
1051 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceConnectWithoutContext() to NotifySource2");
1057 p->InvokeCb (1.0, -5, 0.0);
1058 NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0,
"Invoking TracedCallback does not result in trace callback");
1066 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not TraceDisconnectWithoutContext() from NotifySource2");
1068 p->InvokeCb (-1.0, -5, 0.0);
1069 NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0,
"Invoking disconnected TracedCallback unexpectedly results in trace callback");
1083 virtual void DoRun (
void);
1085 void NotifySource2 (
double a,
int b,
float c) { m_got2 = a; }
1090 PointerAttributeTestCase::PointerAttributeTestCase (std::string description)
1101 p = CreateObject<AttributeObjectTest> ();
1102 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
1112 NS_TEST_ASSERT_MSG_EQ (derived, 0,
"Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
1118 derived = Create<Derived> ();
1120 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a PointerValue of the correct type");
1128 NS_TEST_ASSERT_MSG_EQ (stored, derived,
"Retreived Attribute does not match stored PointerValue");
1138 NS_TEST_ASSERT_MSG_EQ (storedBase, stored,
"Retreived Ptr<Object> does not match stored Ptr<Derived>");
1146 NS_TEST_ASSERT_MSG_EQ (x, 0,
"Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
1156 p2->GetAttribute (
"PointerInitialized", ptr2);
1158 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr2,
"ptr and ptr2 both have PointerInitialized pointing to the same object");
1160 p2->GetAttribute (
"PointerInitialized", ptr3);
1162 NS_TEST_ASSERT_MSG_NE (storedPtr, storedPtr3,
"ptr and ptr3 both have PointerInitialized pointing to the same object");
1168 factory.
SetTypeId (
"ns3::AttributeObjectTest");
1169 factory.
Set (
"PointerInitialized",
StringValue (
"ns3::Derived"));
1171 NS_TEST_ASSERT_MSG_NE (aotPtr, 0,
"Unable to factory.Create() a AttributeObjectTest");
1173 NS_TEST_ASSERT_MSG_NE (aotPtr2, 0,
"Unable to factory.Create() a AttributeObjectTest");
1174 NS_TEST_ASSERT_MSG_NE (aotPtr, aotPtr2,
"factory object not creating unique objects");
1181 NS_TEST_ASSERT_MSG_NE (storedPtr4, storedPtr5,
"aotPtr and aotPtr2 are unique, but their Derived member is not");
1193 void InvokeCbValue (int8_t a)
1195 if (!m_cbValue.IsNull ()) {
1201 virtual void DoRun (
void);
1205 void NotifyCallbackValue (int8_t a) { m_gotCbValue = a; }
1207 int16_t m_gotCbValue;
1210 CallbackValueTestCase::CallbackValueTestCase (std::string description)
1221 p = CreateObject<AttributeObjectTest> ();
1222 NS_TEST_ASSERT_MSG_NE (p, 0,
"Unable to CreateObject");
1241 p->InvokeCbValue (2);
1244 NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 1,
"Callback unexpectedly fired");
1247 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a CallbackValue");
1252 p->InvokeCbValue (2);
1253 NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2,
"Callback Attribute set by CallbackValue did not fire");
1256 NS_TEST_ASSERT_MSG_EQ (ok,
true,
"Could not SetAttributeFailSafe() a null CallbackValue");
1261 p->InvokeCbValue (3);
1262 NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2,
"Callback Attribute set to null callback unexpectedly fired");
1274 AttributesTestSuite::AttributesTestSuite ()
std::istream & operator>>(std::istream &is, Angles &a)
TypeId AddConstructor(void)
hold variables of type string
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
Hold a signed integer type.
void SetTypeId(TypeId tid)
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
virtual void DoRun(void)
Implementation to actually run this test case.
Ptr< Object > Get(uint32_t i) const
hold variables of type 'enum'
Ptr< Object > Create(void) const
Hold an unsigned integer type.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
#define ATTRIBUTE_HELPER_HEADER(type)
std::ostream & operator<<(std::ostream &os, const Angles &a)
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
hold objects of type Ptr<T>
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
#define ATTRIBUTE_HELPER_CPP(type)
virtual void DoRun(void)
Implementation to actually run this test case.
void Set(std::string name, const AttributeValue &value)
void GetAttribute(std::string name, AttributeValue &value) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
instantiate subclasses of ns3::Object.
virtual void DoRun(void)
Implementation to actually run this test case.
bool GetAttributeFailSafe(std::string name, AttributeValue &attribute) const
uint32_t GetN(void) const
a base class which provides memory management and object aggregation
contain a set of ns3::Object pointers.
Hold an floating point type.
Ptr< T > GetObject(void) const
a unique identifier for an interface.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.