src/core/attribute-test.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 12 Aug 2008 12:55:11 -0700
changeset 3527 1548d7e3604f
parent 3190 51fe9001a679
child 3763 e46e361a4262
permissions -rw-r--r--
allow attribute setters to fail.
     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", "help text",
   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   bool DoSetIntSrc (int8_t v) {
   210     m_intSrc2 = v;
   211     return true;
   212   }
   213   int8_t DoGetIntSrc (void) const {
   214     return m_intSrc2;
   215   }
   216   bool m_boolTestA;
   217   bool m_boolTest;
   218   int16_t m_int16;
   219   int16_t m_int16WithBounds;
   220   int16_t m_int16SetGet;
   221   uint8_t m_uint8;
   222   float m_float;
   223   enum Test_e m_enum;
   224   RandomVariable m_random;
   225   std::vector<Ptr<Derived> > m_vector1;
   226   std::vector<Ptr<Derived> > m_vector2;
   227   TracedValue<int8_t> m_intSrc1;
   228   TracedValue<int8_t> m_intSrc2;
   229   TracedCallback<double, int, float> m_cb;
   230   TracedValue<ValueClassTest> m_valueSrc;
   231   Ptr<Derived> m_ptr;
   232 };
   233 
   234 
   235 #define CHECK_GET_STR(p,name,value)                               \
   236   {                                                               \
   237     std::string expected = value;                                 \
   238     StringValue got;                                              \
   239     bool ok = p->GetAttributeFailSafe (name, got);                \
   240     NS_TEST_ASSERT (ok);                                          \
   241     NS_TEST_ASSERT_EQUAL (got.Get (), expected);                  \
   242   }
   243 #define CHECK_GET_PARAM(p,name,type,value)		\
   244   {							\
   245     const type expected = value;			\
   246     type got;                                           \
   247     bool ok = p->GetAttributeFailSafe (name, got);      \
   248     NS_TEST_ASSERT (ok);                                \
   249     NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ());	\
   250   }
   251 
   252 NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
   253 
   254 AttributeTest::AttributeTest ()
   255   : Test ("Attribute")
   256 {}
   257 bool 
   258 AttributeTest::RunTests (void)
   259 {
   260   bool result = true;
   261 
   262   AttributeList params;
   263   Ptr<AttributeObjectTest> p;
   264   NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   265   p = CreateObject<AttributeObjectTest> (params);
   266   CHECK_GET_STR (p, "TestBoolName", "false");
   267   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   268 
   269   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", StringValue ("true")));
   270   CHECK_GET_STR (p, "TestBoolName", "true");
   271   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   272 
   273   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", BooleanValue (false)));
   274   CHECK_GET_STR (p, "TestBoolName", "false");
   275   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   276 
   277   p = CreateObject<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
   278   CHECK_GET_STR (p, "TestBoolName", "true");
   279   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   280 
   281   p = CreateObject<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
   282   CHECK_GET_STR (p, "TestBoolName", "true");
   283   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   284 
   285   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("false")));
   286   CHECK_GET_STR (p, "TestBoolA", "false");
   287   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, false);
   288 
   289   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("true")));
   290   CHECK_GET_STR (p, "TestBoolA", "true");
   291   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, true);
   292 
   293 
   294   CHECK_GET_STR (p, "TestInt16", "-2");
   295   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -2);
   296 
   297   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", StringValue ("-5")));
   298   CHECK_GET_STR (p, "TestInt16", "-5");
   299   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -5);
   300 
   301   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (+2)));
   302   CHECK_GET_STR (p, "TestInt16", "2");
   303   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, +2);
   304 
   305   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (-32768)));
   306   CHECK_GET_STR (p, "TestInt16", "-32768");
   307   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   308 
   309   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (-32769)));
   310   CHECK_GET_STR (p, "TestInt16", "-32768");
   311   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   312 
   313   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (32767)));
   314   CHECK_GET_STR (p, "TestInt16", "32767");
   315   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   316 
   317   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (32768)));
   318   CHECK_GET_STR (p, "TestInt16", "32767");
   319   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   320 
   321   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10)));
   322   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   323   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   324   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11)));
   325   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   326   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   327 
   328   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5)));
   329   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   330   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   331   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6)));
   332   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   333   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   334 
   335   CHECK_GET_STR (p, "TestInt16SetGet", "6");
   336   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 6);
   337   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", IntegerValue (0)));
   338   CHECK_GET_STR (p, "TestInt16SetGet", "0");
   339   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 0);
   340 
   341   CHECK_GET_STR (p, "TestUint8", "1");
   342   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 1);
   343   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (0)));
   344   CHECK_GET_STR (p, "TestUint8", "0");
   345   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 0);
   346   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (255)));
   347   CHECK_GET_STR (p, "TestUint8", "255");
   348   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   349   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", StringValue ("255")));
   350   CHECK_GET_STR (p, "TestUint8", "255");
   351   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   352   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("256")));
   353   CHECK_GET_STR (p, "TestUint8", "255");
   354   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   355   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("-1")));
   356   CHECK_GET_STR (p, "TestUint8", "255");
   357   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   358   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", UintegerValue ((uint64_t)-1)));
   359   CHECK_GET_STR (p, "TestUint8", "255");
   360   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   361 
   362   CHECK_GET_STR (p, "TestFloat", "-1.1");
   363   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)+2.3)));
   364   CHECK_GET_PARAM (p, "TestFloat", DoubleValue, (float)+2.3);
   365 
   366   CHECK_GET_STR (p, "TestEnum", "TestA");
   367   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_A);
   368   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C)));
   369   CHECK_GET_STR (p, "TestEnum", "TestC");
   370   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_C);
   371   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", StringValue ("TestB")));
   372   CHECK_GET_STR (p, "TestEnum", "TestB");
   373   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   374   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", StringValue ("TestD")));
   375   CHECK_GET_STR (p, "TestEnum", "TestB");
   376   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   377   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", EnumValue (5)));
   378   CHECK_GET_STR (p, "TestEnum", "TestB");
   379   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   380 
   381   RandomVariableValue ran;
   382   p->GetAttribute ("TestRandom", ran);
   383   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0.0, 1.0))));
   384   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.0))));
   385 
   386   {
   387     ObjectVectorValue vector;
   388     p->GetAttribute ("TestVector1", vector);
   389     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   390     p->AddToVector1 ();
   391     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   392     p->GetAttribute ("TestVector1", vector);
   393     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   394     Ptr<Object> a = vector.Get (0);
   395     NS_TEST_ASSERT_UNEQUAL (a, 0);
   396     p->AddToVector1 ();
   397     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   398     p->GetAttribute ("TestVector1", vector);
   399     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   400   }
   401 
   402   {
   403     ObjectVectorValue vector;
   404     p->GetAttribute ("TestVector2", vector);
   405     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   406     p->AddToVector2 ();
   407     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   408     p->GetAttribute ("TestVector2", vector);
   409     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   410     Ptr<Object> a = vector.Get (0);
   411     NS_TEST_ASSERT_UNEQUAL (a, 0);
   412     p->AddToVector2 ();
   413     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   414     p->GetAttribute ("TestVector2", vector);
   415     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   416   }
   417 
   418   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true")));
   419   p = CreateObject<AttributeObjectTest> ();
   420   BooleanValue boolV;
   421   p->GetAttribute ("TestBoolName", boolV);
   422   NS_TEST_ASSERT_EQUAL (boolV.Get (), true);
   423 
   424   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   425   p = CreateObject<AttributeObjectTest> ();
   426   p->GetAttribute ("TestBoolName", boolV);
   427   NS_TEST_ASSERT_EQUAL (boolV.Get (), false);
   428 
   429   IntegerValue i;
   430   p->GetAttribute ("IntegerTraceSource1", i);
   431   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   432   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (+5)));
   433   p->GetAttribute ("IntegerTraceSource1", i);
   434   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   435   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127)));
   436   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128)));
   437   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128)));
   438   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129)));
   439 
   440   p->GetAttribute ("IntegerTraceSource2", i);
   441   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   442   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (+5)));
   443   p->GetAttribute ("IntegerTraceSource2", i);
   444   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   445   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127)));
   446   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128)));
   447   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128)));
   448   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129)));
   449 
   450   m_got1 = -2;
   451   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1)));
   452   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   453   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0)));
   454   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   455   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   456   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1)));
   457   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   458 
   459   m_got2 = 4.3;
   460   p->InvokeCb (1.0, -5, 0.0);
   461   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   462   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   463   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   464   p->InvokeCb (1.0, -5, 0.0);
   465   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   466   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   467   p->InvokeCb (-1.0, -5, 0.0);
   468   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   469 
   470   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this)));
   471 
   472   PointerValue ptr;
   473   p->GetAttribute ("Pointer", ptr);
   474   Ptr<Derived> derived = ptr.Get<Derived> ();
   475   NS_TEST_ASSERT (derived == 0);
   476   derived = Create<Derived> ();
   477   NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", PointerValue (derived)));
   478   p->GetAttribute ("Pointer", ptr);
   479   Ptr<Derived> stored = ptr.Get<Derived> ();
   480   NS_TEST_ASSERT (stored == derived);
   481   p->GetAttribute ("Pointer", ptr);
   482   Ptr<Object> storedBase = ptr.Get<Object> ();
   483   NS_TEST_ASSERT (stored == storedBase);
   484   p->GetAttribute ("Pointer", ptr);
   485   Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
   486   NS_TEST_ASSERT (x == 0);
   487 
   488   p = CreateObject<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
   489   NS_TEST_ASSERT (p != 0);
   490   derived = 0;
   491   p->GetAttribute ("Pointer", ptr);
   492   derived = ptr.Get<Derived> ();
   493   NS_TEST_ASSERT (derived != 0);
   494 
   495   return result;
   496 }
   497 
   498 
   499 
   500 static AttributeTest g_parameterTest;
   501 
   502 } // namespace ns3
   503 
   504 
   505 #endif /* RUN_SELF_TESTS */