00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef RUN_SELF_TESTS
00021 #include "test.h"
00022 #include "object.h"
00023 #include "boolean.h"
00024 #include "integer.h"
00025 #include "uinteger.h"
00026 #include "enum.h"
00027 #include "string.h"
00028 #include "random-variable.h"
00029 #include "double.h"
00030 #include "object-vector.h"
00031 #include "traced-value.h"
00032 #include "callback.h"
00033 #include "trace-source-accessor.h"
00034 #include "pointer.h"
00035
00036 namespace ns3 {
00037
00038 class ValueClassTest
00039 {
00040 public:
00041 ValueClassTest () {}
00042 private:
00043 int m_v;
00044 };
00045 bool operator != (const ValueClassTest &a, const ValueClassTest &b)
00046 {
00047 return true;
00048 }
00049 std::ostream & operator << (std::ostream &os, ValueClassTest v)
00050 {
00051 return os;
00052 }
00053 std::istream & operator >> (std::istream &is, ValueClassTest &v)
00054 {
00055 return is;
00056 }
00057 ATTRIBUTE_HELPER_HEADER (ValueClassTest);
00058 ATTRIBUTE_HELPER_CPP (ValueClassTest);
00059
00060 class AttributeTest : public Test
00061 {
00062 public:
00063 AttributeTest ();
00064 virtual bool RunTests (void);
00065 private:
00066 void NotifySource1 (int8_t old, int8_t n) {
00067 m_got1 = n;
00068 }
00069 void NotifySource2 (double a, int b, float c) {
00070 m_got2 = a;
00071 }
00072 void NotifySourceValue (ValueClassTest old, ValueClassTest n) {
00073 m_gotValue = n;
00074 }
00075 void NotifyCallbackValue (int8_t a) {
00076 m_gotCbValue = a;
00077 }
00078 int64_t m_got1;
00079 double m_got2;
00080 ValueClassTest m_gotValue;
00081 int16_t m_gotCbValue;
00082 };
00083
00084 class Derived : public Object
00085 {
00086 public:
00087 static TypeId GetTypeId (void) {
00088 static TypeId tid = TypeId ("Derived")
00089 .SetParent<Object> ()
00090 ;
00091 return tid;
00092 }
00093 };
00094
00095 class AttributeObjectTest : public Object
00096 {
00097 public:
00098 enum Test_e {
00099 TEST_A,
00100 TEST_B,
00101 TEST_C
00102 };
00103 static TypeId GetTypeId (void) {
00104 static TypeId tid = TypeId ("ns3::AttributeObjectTest")
00105 .SetParent<Object> ()
00106 .HideFromDocumentation ()
00107 .AddAttribute ("TestBoolName", "help text",
00108 BooleanValue (false),
00109 MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
00110 MakeBooleanChecker ())
00111 .AddAttribute ("TestBoolA", "help text",
00112 BooleanValue (false),
00113 MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
00114 &AttributeObjectTest::DoGetTestB),
00115 MakeBooleanChecker ())
00116 .AddAttribute ("TestInt16", "help text",
00117 IntegerValue (-2),
00118 MakeIntegerAccessor (&AttributeObjectTest::m_int16),
00119 MakeIntegerChecker<int16_t> ())
00120 .AddAttribute ("TestInt16WithBounds", "help text",
00121 IntegerValue (-2),
00122 MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
00123 MakeIntegerChecker<int16_t> (-5, 10))
00124 .AddAttribute ("TestInt16SetGet", "help text",
00125 IntegerValue (6),
00126 MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
00127 &AttributeObjectTest::DoGetInt16),
00128 MakeIntegerChecker<int16_t> ())
00129 .AddAttribute ("TestUint8", "help text",
00130 UintegerValue (1),
00131 MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
00132 MakeUintegerChecker<uint8_t> ())
00133 .AddAttribute ("TestEnum", "help text",
00134 EnumValue (TEST_A),
00135 MakeEnumAccessor (&AttributeObjectTest::m_enum),
00136 MakeEnumChecker (TEST_A, "TestA",
00137 TEST_B, "TestB",
00138 TEST_C, "TestC"))
00139 .AddAttribute ("TestRandom", "help text",
00140 RandomVariableValue (ConstantVariable (1.0)),
00141 MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
00142 MakeRandomVariableChecker ())
00143 .AddAttribute ("TestFloat", "help text",
00144 DoubleValue (-1.1),
00145 MakeDoubleAccessor (&AttributeObjectTest::m_float),
00146 MakeDoubleChecker<float> ())
00147 .AddAttribute ("TestVector1", "help text",
00148 ObjectVectorValue (),
00149 MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
00150 MakeObjectVectorChecker<Derived> ())
00151 .AddAttribute ("TestVector2", "help text",
00152 ObjectVectorValue (),
00153 MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
00154 &AttributeObjectTest::DoGetVector),
00155 MakeObjectVectorChecker<Derived> ())
00156 .AddAttribute ("IntegerTraceSource1", "help text",
00157 IntegerValue (-2),
00158 MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
00159 MakeIntegerChecker<int8_t> ())
00160 .AddAttribute ("IntegerTraceSource2", "help text",
00161 IntegerValue (-2),
00162 MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
00163 &AttributeObjectTest::DoGetIntSrc),
00164 MakeIntegerChecker<int8_t> ())
00165 .AddAttribute ("ValueClassSource", "help text",
00166 ValueClassTestValue (ValueClassTest ()),
00167 MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
00168 MakeValueClassTestChecker ())
00169 .AddTraceSource ("Source1", "help test",
00170 MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
00171 .AddTraceSource ("Source2", "help text",
00172 MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
00173 .AddTraceSource ("ValueSource", "help text",
00174 MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
00175 .AddAttribute ("Pointer", "help text",
00176 PointerValue (),
00177 MakePointerAccessor (&AttributeObjectTest::m_ptr),
00178 MakePointerChecker<Derived> ())
00179 .AddAttribute ("Callback", "help text",
00180 CallbackValue (),
00181 MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
00182 MakeCallbackChecker ())
00183 ;
00184
00185 return tid;
00186 }
00187
00188 void AddToVector1 (void) {
00189 m_vector1.push_back (CreateObject<Derived> ());
00190 }
00191 void AddToVector2 (void) {
00192 m_vector2.push_back (CreateObject<Derived> ());
00193 }
00194
00195 void InvokeCb (double a, int b, float c) {
00196 m_cb (a,b,c);
00197 }
00198
00199 void InvokeCbValue (int8_t a) {
00200 if (!m_cbValue.IsNull ())
00201 {
00202 m_cbValue (a);
00203 }
00204 }
00205
00206 private:
00207 void DoSetTestB (bool v) {
00208 m_boolTestA = v;
00209 }
00210 bool DoGetTestB (void) const {
00211 return m_boolTestA;
00212 }
00213 int16_t DoGetInt16 (void) const {
00214 return m_int16SetGet;
00215 }
00216 void DoSetInt16 (int16_t v) {
00217 m_int16SetGet = v;
00218 }
00219 uint32_t DoGetVectorN (void) const {
00220 return m_vector2.size ();
00221 }
00222 Ptr<Derived> DoGetVector (uint32_t i) const {
00223 return m_vector2[i];
00224 }
00225 bool DoSetIntSrc (int8_t v) {
00226 m_intSrc2 = v;
00227 return true;
00228 }
00229 int8_t DoGetIntSrc (void) const {
00230 return m_intSrc2;
00231 }
00232 bool m_boolTestA;
00233 bool m_boolTest;
00234 int16_t m_int16;
00235 int16_t m_int16WithBounds;
00236 int16_t m_int16SetGet;
00237 uint8_t m_uint8;
00238 float m_float;
00239 enum Test_e m_enum;
00240 RandomVariable m_random;
00241 std::vector<Ptr<Derived> > m_vector1;
00242 std::vector<Ptr<Derived> > m_vector2;
00243 Callback<void,int8_t> m_cbValue;
00244 TracedValue<int8_t> m_intSrc1;
00245 TracedValue<int8_t> m_intSrc2;
00246 TracedCallback<double, int, float> m_cb;
00247 TracedValue<ValueClassTest> m_valueSrc;
00248 Ptr<Derived> m_ptr;
00249 };
00250
00251
00252 #define CHECK_GET_STR(p,name,value) \
00253 { \
00254 std::string expected = value; \
00255 StringValue got; \
00256 bool ok = p->GetAttributeFailSafe (name, got); \
00257 NS_TEST_ASSERT (ok); \
00258 NS_TEST_ASSERT_EQUAL (got.Get (), expected); \
00259 }
00260 #define CHECK_GET_PARAM(p,name,type,value) \
00261 { \
00262 const type expected = value; \
00263 type got; \
00264 bool ok = p->GetAttributeFailSafe (name, got); \
00265 NS_TEST_ASSERT (ok); \
00266 NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ()); \
00267 }
00268
00269 NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
00270
00271 AttributeTest::AttributeTest ()
00272 : Test ("Attribute")
00273 {}
00274 bool
00275 AttributeTest::RunTests (void)
00276 {
00277 bool result = true;
00278
00279 AttributeList params;
00280 Ptr<AttributeObjectTest> p;
00281 NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
00282 p = CreateObject<AttributeObjectTest> (params);
00283 CHECK_GET_STR (p, "TestBoolName", "false");
00284 CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
00285
00286 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", StringValue ("true")));
00287 CHECK_GET_STR (p, "TestBoolName", "true");
00288 CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
00289
00290 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", BooleanValue (false)));
00291 CHECK_GET_STR (p, "TestBoolName", "false");
00292 CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
00293
00294 p = CreateObject<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
00295 CHECK_GET_STR (p, "TestBoolName", "true");
00296 CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
00297
00298 p = CreateObject<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
00299 CHECK_GET_STR (p, "TestBoolName", "true");
00300 CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
00301
00302 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("false")));
00303 CHECK_GET_STR (p, "TestBoolA", "false");
00304 CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, false);
00305
00306 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("true")));
00307 CHECK_GET_STR (p, "TestBoolA", "true");
00308 CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, true);
00309
00310
00311 CHECK_GET_STR (p, "TestInt16", "-2");
00312 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -2);
00313
00314 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", StringValue ("-5")));
00315 CHECK_GET_STR (p, "TestInt16", "-5");
00316 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -5);
00317
00318 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (+2)));
00319 CHECK_GET_STR (p, "TestInt16", "2");
00320 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, +2);
00321
00322 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (-32768)));
00323 CHECK_GET_STR (p, "TestInt16", "-32768");
00324 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
00325
00326 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (-32769)));
00327 CHECK_GET_STR (p, "TestInt16", "-32768");
00328 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
00329
00330 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (32767)));
00331 CHECK_GET_STR (p, "TestInt16", "32767");
00332 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
00333
00334 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (32768)));
00335 CHECK_GET_STR (p, "TestInt16", "32767");
00336 CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
00337
00338 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10)));
00339 CHECK_GET_STR (p, "TestInt16WithBounds", "10");
00340 CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
00341 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11)));
00342 CHECK_GET_STR (p, "TestInt16WithBounds", "10");
00343 CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
00344
00345 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5)));
00346 CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
00347 CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
00348 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6)));
00349 CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
00350 CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
00351
00352 CHECK_GET_STR (p, "TestInt16SetGet", "6");
00353 CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 6);
00354 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", IntegerValue (0)));
00355 CHECK_GET_STR (p, "TestInt16SetGet", "0");
00356 CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 0);
00357
00358 CHECK_GET_STR (p, "TestUint8", "1");
00359 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 1);
00360 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (0)));
00361 CHECK_GET_STR (p, "TestUint8", "0");
00362 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 0);
00363 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (255)));
00364 CHECK_GET_STR (p, "TestUint8", "255");
00365 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
00366 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", StringValue ("255")));
00367 CHECK_GET_STR (p, "TestUint8", "255");
00368 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
00369 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("256")));
00370 CHECK_GET_STR (p, "TestUint8", "255");
00371 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
00372 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("-1")));
00373 CHECK_GET_STR (p, "TestUint8", "255");
00374 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
00375 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", UintegerValue ((uint64_t)-1)));
00376 CHECK_GET_STR (p, "TestUint8", "255");
00377 CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
00378
00379 CHECK_GET_STR (p, "TestFloat", "-1.1");
00380 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)+2.3)));
00381 CHECK_GET_PARAM (p, "TestFloat", DoubleValue, (float)+2.3);
00382
00383 CHECK_GET_STR (p, "TestEnum", "TestA");
00384 CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_A);
00385 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C)));
00386 CHECK_GET_STR (p, "TestEnum", "TestC");
00387 CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_C);
00388 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", StringValue ("TestB")));
00389 CHECK_GET_STR (p, "TestEnum", "TestB");
00390 CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
00391 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", StringValue ("TestD")));
00392 CHECK_GET_STR (p, "TestEnum", "TestB");
00393 CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
00394 NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", EnumValue (5)));
00395 CHECK_GET_STR (p, "TestEnum", "TestB");
00396 CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
00397
00398 RandomVariableValue ran;
00399 p->GetAttribute ("TestRandom", ran);
00400 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0.0, 1.0))));
00401 NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.0))));
00402
00403 {
00404 ObjectVectorValue vector;
00405 p->GetAttribute ("TestVector1", vector);
00406 NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
00407 p->AddToVector1 ();
00408 NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
00409 p->GetAttribute ("TestVector1", vector);
00410 NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
00411 Ptr<Object> a = vector.Get (0);
00412 NS_TEST_ASSERT_UNEQUAL (a, 0);
00413 p->AddToVector1 ();
00414 NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
00415 p->GetAttribute ("TestVector1", vector);
00416 NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
00417 }
00418
00419 {
00420 ObjectVectorValue vector;
00421 p->GetAttribute ("TestVector2", vector);
00422 NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
00423 p->AddToVector2 ();
00424 NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
00425 p->GetAttribute ("TestVector2", vector);
00426 NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
00427 Ptr<Object> a = vector.Get (0);
00428 NS_TEST_ASSERT_UNEQUAL (a, 0);
00429 p->AddToVector2 ();
00430 NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
00431 p->GetAttribute ("TestVector2", vector);
00432 NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
00433 }
00434
00435 NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true")));
00436 p = CreateObject<AttributeObjectTest> ();
00437 BooleanValue boolV;
00438 p->GetAttribute ("TestBoolName", boolV);
00439 NS_TEST_ASSERT_EQUAL (boolV.Get (), true);
00440
00441 NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
00442 p = CreateObject<AttributeObjectTest> ();
00443 p->GetAttribute ("TestBoolName", boolV);
00444 NS_TEST_ASSERT_EQUAL (boolV.Get (), false);
00445
00446 IntegerValue i;
00447 p->GetAttribute ("IntegerTraceSource1", i);
00448 NS_TEST_ASSERT_EQUAL (i.Get (), -2);
00449 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (+5)));
00450 p->GetAttribute ("IntegerTraceSource1", i);
00451 NS_TEST_ASSERT_EQUAL (i.Get (), +5);
00452 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127)));
00453 NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128)));
00454 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128)));
00455 NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129)));
00456
00457 p->GetAttribute ("IntegerTraceSource2", i);
00458 NS_TEST_ASSERT_EQUAL (i.Get (), -2);
00459 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (+5)));
00460 p->GetAttribute ("IntegerTraceSource2", i);
00461 NS_TEST_ASSERT_EQUAL (i.Get (), +5);
00462 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127)));
00463 NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128)));
00464 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128)));
00465 NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129)));
00466
00467 m_got1 = -2;
00468 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1)));
00469 NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
00470 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0)));
00471 NS_TEST_ASSERT_EQUAL (m_got1, 0);
00472 NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
00473 NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1)));
00474 NS_TEST_ASSERT_EQUAL (m_got1, 0);
00475
00476 m_got2 = 4.3;
00477 p->InvokeCb (1.0, -5, 0.0);
00478 NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
00479 NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
00480 NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
00481 p->InvokeCb (1.0, -5, 0.0);
00482 NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
00483 NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
00484 p->InvokeCb (-1.0, -5, 0.0);
00485 NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
00486
00487 NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this)));
00488
00489 PointerValue ptr;
00490 p->GetAttribute ("Pointer", ptr);
00491 Ptr<Derived> derived = ptr.Get<Derived> ();
00492 NS_TEST_ASSERT (derived == 0);
00493 derived = Create<Derived> ();
00494 NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", PointerValue (derived)));
00495 p->GetAttribute ("Pointer", ptr);
00496 Ptr<Derived> stored = ptr.Get<Derived> ();
00497 NS_TEST_ASSERT (stored == derived);
00498 p->GetAttribute ("Pointer", ptr);
00499 Ptr<Object> storedBase = ptr.Get<Object> ();
00500 NS_TEST_ASSERT (stored == storedBase);
00501 p->GetAttribute ("Pointer", ptr);
00502 Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
00503 NS_TEST_ASSERT (x == 0);
00504
00505 p = CreateObject<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
00506 NS_TEST_ASSERT (p != 0);
00507 derived = 0;
00508 p->GetAttribute ("Pointer", ptr);
00509 derived = ptr.Get<Derived> ();
00510 NS_TEST_ASSERT (derived != 0);
00511
00512 p = CreateObject<AttributeObjectTest> ();
00513 NS_TEST_ASSERT (p != 0);
00514 m_gotCbValue = 1;
00515 p->InvokeCbValue (2);
00516 CallbackValue cbValue = MakeCallback (&AttributeTest::NotifyCallbackValue, this);
00517 NS_TEST_ASSERT_EQUAL (m_gotCbValue, 1);
00518 NS_TEST_ASSERT (p->SetAttributeFailSafe ("Callback",
00519 cbValue));
00520 p->InvokeCbValue (2);
00521 NS_TEST_ASSERT_EQUAL (m_gotCbValue, 2);
00522 NS_TEST_ASSERT (p->SetAttributeFailSafe ("Callback",
00523 CallbackValue (MakeNullCallback<void,int8_t> ())));
00524 p->InvokeCbValue (3);
00525 NS_TEST_ASSERT_EQUAL (m_gotCbValue, 2);
00526
00527 return result;
00528 }
00529
00530
00531
00532 static AttributeTest g_parameterTest;
00533
00534 }
00535
00536
00537 #endif