src/core/attribute-test.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 26 May 2008 20:48:54 -0700
changeset 3094 6e787ec9c8aa
parent 2965 4b28e9740e3b
child 3190 51fe9001a679
permissions -rw-r--r--
ATTRIBUTE_HELPER_HEADER_2 -> ATTRIBUTE_HELPER_HEADER
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2008 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #ifdef RUN_SELF_TESTS
    21 #include "test.h"
    22 #include "object.h"
    23 #include "boolean.h"
    24 #include "integer.h"
    25 #include "uinteger.h"
    26 #include "enum.h"
    27 #include "string.h"
    28 #include "random-variable.h"
    29 #include "double.h"
    30 #include "object-vector.h"
    31 #include "traced-value.h"
    32 #include "trace-source-accessor.h"
    33 #include "pointer.h"
    34 
    35 namespace ns3 {
    36 
    37 class ValueClassTest 
    38 {
    39 public:
    40   ValueClassTest () {}
    41 private:
    42   int m_v;
    43 };
    44 bool operator != (const ValueClassTest &a, const ValueClassTest &b)
    45 {
    46   return true;
    47 }
    48 std::ostream & operator << (std::ostream &os, ValueClassTest v)
    49 {
    50   return os;
    51 }
    52 std::istream & operator >> (std::istream &is, ValueClassTest &v)
    53 {
    54   return is;
    55 }
    56 ATTRIBUTE_HELPER_HEADER (ValueClassTest);
    57 ATTRIBUTE_HELPER_CPP (ValueClassTest);
    58 
    59 class AttributeTest : public Test
    60 {
    61 public:
    62   AttributeTest ();
    63   virtual bool RunTests (void);
    64 private:
    65   void NotifySource1 (int8_t old, int8_t n) {
    66     m_got1 = n;
    67   }
    68   void NotifySource2 (double a, int b, float c) {
    69     m_got2 = a;
    70   }
    71   void NotifySourceValue (ValueClassTest old, ValueClassTest n) {
    72     m_gotValue = n;
    73   }
    74   int64_t m_got1;
    75   double m_got2;
    76   ValueClassTest m_gotValue;
    77 };
    78 
    79 class Derived : public Object
    80 {
    81 public:
    82   static TypeId GetTypeId (void) {
    83     static TypeId tid = TypeId ("Derived")
    84       .SetParent<Object> ()
    85       ;
    86     return tid;
    87   }
    88 };
    89 
    90 class AttributeObjectTest : public Object
    91 {
    92 public:
    93   enum Test_e {
    94     TEST_A,
    95     TEST_B,
    96     TEST_C
    97   };
    98   static TypeId GetTypeId (void) {
    99     static TypeId tid = TypeId ("ns3::AttributeObjectTest")
   100       .SetParent<Object> ()
   101       .HideFromDocumentation ()
   102       .AddAttribute ("TestBoolName", "help text",
   103 		     BooleanValue (false),
   104 		     MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
   105 		     MakeBooleanChecker ())
   106       .AddAttribute ("TestBoolA", "help text",
   107 		     BooleanValue (false),
   108 		     MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
   109 					   &AttributeObjectTest::DoGetTestB),
   110 		     MakeBooleanChecker ())
   111       .AddAttribute ("TestInt16", "help text",
   112 		     IntegerValue (-2),
   113 		     MakeIntegerAccessor (&AttributeObjectTest::m_int16),
   114 		     MakeIntegerChecker<int16_t> ())
   115       .AddAttribute ("TestInt16WithBounds", "help text",
   116 		     IntegerValue (-2),
   117 		     MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
   118 		     MakeIntegerChecker<int16_t> (-5, 10))
   119       .AddAttribute ("TestInt16SetGet", "help text",
   120 		     IntegerValue (6),
   121 		     MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
   122 				       &AttributeObjectTest::DoGetInt16),
   123 		     MakeIntegerChecker<int16_t> ())
   124       .AddAttribute ("TestUint8", "help text",
   125 		     UintegerValue (1),
   126 		     MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
   127 		     MakeUintegerChecker<uint8_t> ())
   128       .AddAttribute ("TestEnum", "help text",
   129 		     EnumValue (TEST_A),
   130 		     MakeEnumAccessor (&AttributeObjectTest::m_enum),
   131 		     MakeEnumChecker (TEST_A, "TestA",
   132 				      TEST_B, "TestB",
   133 				      TEST_C, "TestC"))
   134       .AddAttribute ("TestRandom", "help text",
   135 		     RandomVariableValue (ConstantVariable (1.0)),
   136 		     MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
   137 		     MakeRandomVariableChecker ())
   138       .AddAttribute ("TestFloat", "help text",
   139 		     DoubleValue (-1.1),
   140 		     MakeDoubleAccessor (&AttributeObjectTest::m_float),
   141 		     MakeDoubleChecker<float> ())
   142       .AddAttribute ("TestVector1", "help text",
   143 		     ObjectVectorValue (),
   144 		     MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
   145 		     MakeObjectVectorChecker<Derived> ())
   146       .AddAttribute ("TestVector2", "help text",
   147 		     ObjectVectorValue (),
   148 		     MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
   149 						&AttributeObjectTest::DoGetVector),
   150 		     MakeObjectVectorChecker<Derived> ())
   151       .AddAttribute ("IntegerTraceSource1", "help text",
   152 		     IntegerValue (-2),
   153 		     MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
   154 		     MakeIntegerChecker<int8_t> ())
   155       .AddAttribute ("IntegerTraceSource2", "help text",
   156 		     IntegerValue (-2),
   157 		     MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
   158 					  &AttributeObjectTest::DoGetIntSrc),
   159 		     MakeIntegerChecker<int8_t> ())
   160       .AddAttribute ("ValueClassSource", "help text",
   161 		     ValueClassTestValue (ValueClassTest ()),
   162 		     MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
   163 		     MakeValueClassTestChecker ())
   164       .AddTraceSource ("Source1", "help test",
   165 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
   166       .AddTraceSource ("Source2", "help text",
   167 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
   168       .AddTraceSource ("ValueSource", "help text",
   169 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
   170       .AddAttribute ("Pointer", "XXX",
   171                      PointerValue (),
   172                      MakePointerAccessor (&AttributeObjectTest::m_ptr),
   173                      MakePointerChecker<Derived> ())
   174       ;
   175         
   176     return tid;
   177   }
   178 
   179   void AddToVector1 (void) {
   180     m_vector1.push_back (CreateObject<Derived> ());
   181   }
   182   void AddToVector2 (void) {
   183     m_vector2.push_back (CreateObject<Derived> ());
   184   }
   185 
   186   void InvokeCb (double a, int b, float c) {
   187     m_cb (a,b,c);
   188   }
   189 
   190 private:
   191   void DoSetTestB (bool v) {
   192     m_boolTestA = v;
   193   }
   194   bool DoGetTestB (void) const {
   195     return m_boolTestA;
   196   }
   197   int16_t DoGetInt16 (void) const {
   198     return m_int16SetGet;
   199   }
   200   void DoSetInt16 (int16_t v) {
   201     m_int16SetGet = v;
   202   }
   203   uint32_t DoGetVectorN (void) const {
   204     return m_vector2.size ();
   205   }
   206   Ptr<Derived> DoGetVector (uint32_t i) const {
   207     return m_vector2[i];
   208   }
   209   void DoSetIntSrc (int8_t v) {
   210     m_intSrc2 = v;
   211   }
   212   int8_t DoGetIntSrc (void) const {
   213     return m_intSrc2;
   214   }
   215   bool m_boolTestA;
   216   bool m_boolTest;
   217   int16_t m_int16;
   218   int16_t m_int16WithBounds;
   219   int16_t m_int16SetGet;
   220   uint8_t m_uint8;
   221   float m_float;
   222   enum Test_e m_enum;
   223   RandomVariable m_random;
   224   std::vector<Ptr<Derived> > m_vector1;
   225   std::vector<Ptr<Derived> > m_vector2;
   226   TracedValue<int8_t> m_intSrc1;
   227   TracedValue<int8_t> m_intSrc2;
   228   TracedCallback<double, int, float> m_cb;
   229   TracedValue<ValueClassTest> m_valueSrc;
   230   Ptr<Derived> m_ptr;
   231 };
   232 
   233 
   234 #define CHECK_GET_STR(p,name,value)                               \
   235   {                                                               \
   236     std::string expected = value;                                 \
   237     StringValue got;                                              \
   238     bool ok = p->GetAttributeFailSafe (name, got);                \
   239     NS_TEST_ASSERT (ok);                                          \
   240     NS_TEST_ASSERT_EQUAL (got.Get (), expected);                  \
   241   }
   242 #define CHECK_GET_PARAM(p,name,type,value)		\
   243   {							\
   244     const type expected = value;			\
   245     type got;                                           \
   246     bool ok = p->GetAttributeFailSafe (name, got);      \
   247     NS_TEST_ASSERT (ok);                                \
   248     NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ());	\
   249   }
   250 
   251 NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
   252 
   253 AttributeTest::AttributeTest ()
   254   : Test ("Attribute")
   255 {}
   256 bool 
   257 AttributeTest::RunTests (void)
   258 {
   259   bool result = true;
   260 
   261   AttributeList params;
   262   Ptr<AttributeObjectTest> p;
   263   NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   264   p = CreateObject<AttributeObjectTest> (params);
   265   CHECK_GET_STR (p, "TestBoolName", "false");
   266   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   267 
   268   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", StringValue ("true")));
   269   CHECK_GET_STR (p, "TestBoolName", "true");
   270   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   271 
   272   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", BooleanValue (false)));
   273   CHECK_GET_STR (p, "TestBoolName", "false");
   274   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   275 
   276   p = CreateObject<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
   277   CHECK_GET_STR (p, "TestBoolName", "true");
   278   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   279 
   280   p = CreateObject<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
   281   CHECK_GET_STR (p, "TestBoolName", "true");
   282   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   283 
   284   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("false")));
   285   CHECK_GET_STR (p, "TestBoolA", "false");
   286   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, false);
   287 
   288   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("true")));
   289   CHECK_GET_STR (p, "TestBoolA", "true");
   290   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, true);
   291 
   292 
   293   CHECK_GET_STR (p, "TestInt16", "-2");
   294   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -2);
   295 
   296   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", StringValue ("-5")));
   297   CHECK_GET_STR (p, "TestInt16", "-5");
   298   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -5);
   299 
   300   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (+2)));
   301   CHECK_GET_STR (p, "TestInt16", "2");
   302   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, +2);
   303 
   304   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (-32768)));
   305   CHECK_GET_STR (p, "TestInt16", "-32768");
   306   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   307 
   308   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (-32769)));
   309   CHECK_GET_STR (p, "TestInt16", "-32768");
   310   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   311 
   312   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (32767)));
   313   CHECK_GET_STR (p, "TestInt16", "32767");
   314   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   315 
   316   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (32768)));
   317   CHECK_GET_STR (p, "TestInt16", "32767");
   318   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   319 
   320   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10)));
   321   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   322   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   323   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11)));
   324   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   325   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   326 
   327   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5)));
   328   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   329   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   330   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6)));
   331   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   332   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   333 
   334   CHECK_GET_STR (p, "TestInt16SetGet", "6");
   335   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 6);
   336   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", IntegerValue (0)));
   337   CHECK_GET_STR (p, "TestInt16SetGet", "0");
   338   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 0);
   339 
   340   CHECK_GET_STR (p, "TestUint8", "1");
   341   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 1);
   342   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (0)));
   343   CHECK_GET_STR (p, "TestUint8", "0");
   344   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 0);
   345   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (255)));
   346   CHECK_GET_STR (p, "TestUint8", "255");
   347   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   348   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", StringValue ("255")));
   349   CHECK_GET_STR (p, "TestUint8", "255");
   350   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   351   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("256")));
   352   CHECK_GET_STR (p, "TestUint8", "255");
   353   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   354   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("-1")));
   355   CHECK_GET_STR (p, "TestUint8", "255");
   356   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   357   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", UintegerValue ((uint64_t)-1)));
   358   CHECK_GET_STR (p, "TestUint8", "255");
   359   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   360 
   361   CHECK_GET_STR (p, "TestFloat", "-1.1");
   362   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)+2.3)));
   363   CHECK_GET_PARAM (p, "TestFloat", DoubleValue, (float)+2.3);
   364 
   365   CHECK_GET_STR (p, "TestEnum", "TestA");
   366   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_A);
   367   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C)));
   368   CHECK_GET_STR (p, "TestEnum", "TestC");
   369   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_C);
   370   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", StringValue ("TestB")));
   371   CHECK_GET_STR (p, "TestEnum", "TestB");
   372   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   373   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", StringValue ("TestD")));
   374   CHECK_GET_STR (p, "TestEnum", "TestB");
   375   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   376   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", EnumValue (5)));
   377   CHECK_GET_STR (p, "TestEnum", "TestB");
   378   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   379 
   380   RandomVariableValue ran;
   381   p->GetAttribute ("TestRandom", ran);
   382   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0.0, 1.0))));
   383   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.0))));
   384 
   385   {
   386     ObjectVectorValue vector;
   387     p->GetAttribute ("TestVector1", vector);
   388     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   389     p->AddToVector1 ();
   390     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   391     p->GetAttribute ("TestVector1", vector);
   392     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   393     Ptr<Object> a = vector.Get (0);
   394     NS_TEST_ASSERT_UNEQUAL (a, 0);
   395     p->AddToVector1 ();
   396     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   397     p->GetAttribute ("TestVector1", vector);
   398     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   399   }
   400 
   401   {
   402     ObjectVectorValue vector;
   403     p->GetAttribute ("TestVector2", vector);
   404     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   405     p->AddToVector2 ();
   406     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   407     p->GetAttribute ("TestVector2", vector);
   408     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   409     Ptr<Object> a = vector.Get (0);
   410     NS_TEST_ASSERT_UNEQUAL (a, 0);
   411     p->AddToVector2 ();
   412     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   413     p->GetAttribute ("TestVector2", vector);
   414     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   415   }
   416 
   417   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true")));
   418   p = CreateObject<AttributeObjectTest> ();
   419   BooleanValue boolV;
   420   p->GetAttribute ("TestBoolName", boolV);
   421   NS_TEST_ASSERT_EQUAL (boolV.Get (), true);
   422 
   423   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   424   p = CreateObject<AttributeObjectTest> ();
   425   p->GetAttribute ("TestBoolName", boolV);
   426   NS_TEST_ASSERT_EQUAL (boolV.Get (), false);
   427 
   428   IntegerValue i;
   429   p->GetAttribute ("IntegerTraceSource1", i);
   430   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   431   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (+5)));
   432   p->GetAttribute ("IntegerTraceSource1", i);
   433   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   434   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127)));
   435   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128)));
   436   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128)));
   437   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129)));
   438 
   439   p->GetAttribute ("IntegerTraceSource2", i);
   440   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   441   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (+5)));
   442   p->GetAttribute ("IntegerTraceSource2", i);
   443   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   444   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127)));
   445   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128)));
   446   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128)));
   447   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129)));
   448 
   449   m_got1 = -2;
   450   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1)));
   451   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   452   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0)));
   453   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   454   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   455   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1)));
   456   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   457 
   458   m_got2 = 4.3;
   459   p->InvokeCb (1.0, -5, 0.0);
   460   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   461   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   462   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   463   p->InvokeCb (1.0, -5, 0.0);
   464   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   465   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   466   p->InvokeCb (-1.0, -5, 0.0);
   467   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   468 
   469   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this)));
   470 
   471   PointerValue ptr;
   472   p->GetAttribute ("Pointer", ptr);
   473   Ptr<Derived> derived = ptr.Get<Derived> ();
   474   NS_TEST_ASSERT (derived == 0);
   475   derived = Create<Derived> ();
   476   NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", PointerValue (derived)));
   477   p->GetAttribute ("Pointer", ptr);
   478   Ptr<Derived> stored = ptr.Get<Derived> ();
   479   NS_TEST_ASSERT (stored == derived);
   480   p->GetAttribute ("Pointer", ptr);
   481   Ptr<Object> storedBase = ptr.Get<Object> ();
   482   NS_TEST_ASSERT (stored == storedBase);
   483   p->GetAttribute ("Pointer", ptr);
   484   Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
   485   NS_TEST_ASSERT (x == 0);
   486 
   487   p = CreateObject<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
   488   NS_TEST_ASSERT (p != 0);
   489   derived = 0;
   490   p->GetAttribute ("Pointer", ptr);
   491   derived = ptr.Get<Derived> ();
   492   NS_TEST_ASSERT (derived != 0);
   493 
   494   return result;
   495 }
   496 
   497 
   498 
   499 static AttributeTest g_parameterTest;
   500 
   501 } // namespace ns3
   502 
   503 
   504 #endif /* RUN_SELF_TESTS */