src/core/attribute-test.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 3763 e46e361a4262
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
     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 "callback.h"
    33 #include "trace-source-accessor.h"
    34 #include "pointer.h"
    35 
    36 namespace ns3 {
    37 
    38 class ValueClassTest 
    39 {
    40 public:
    41   ValueClassTest () {}
    42 private:
    43   int m_v;
    44 };
    45 bool operator != (const ValueClassTest &a, const ValueClassTest &b)
    46 {
    47   return true;
    48 }
    49 std::ostream & operator << (std::ostream &os, ValueClassTest v)
    50 {
    51   return os;
    52 }
    53 std::istream & operator >> (std::istream &is, ValueClassTest &v)
    54 {
    55   return is;
    56 }
    57 ATTRIBUTE_HELPER_HEADER (ValueClassTest);
    58 ATTRIBUTE_HELPER_CPP (ValueClassTest);
    59 
    60 class AttributeTest : public Test
    61 {
    62 public:
    63   AttributeTest ();
    64   virtual bool RunTests (void);
    65 private:
    66   void NotifySource1 (int8_t old, int8_t n) {
    67     m_got1 = n;
    68   }
    69   void NotifySource2 (double a, int b, float c) {
    70     m_got2 = a;
    71   }
    72   void NotifySourceValue (ValueClassTest old, ValueClassTest n) {
    73     m_gotValue = n;
    74   }
    75   void NotifyCallbackValue (int8_t a) {
    76     m_gotCbValue = a;
    77   }
    78   int64_t m_got1;
    79   double m_got2;
    80   ValueClassTest m_gotValue;
    81   int16_t m_gotCbValue;
    82 };
    83 
    84 class Derived : public Object
    85 {
    86 public:
    87   static TypeId GetTypeId (void) {
    88     static TypeId tid = TypeId ("Derived")
    89       .SetParent<Object> ()
    90       ;
    91     return tid;
    92   }
    93 };
    94 
    95 class AttributeObjectTest : public Object
    96 {
    97 public:
    98   enum Test_e {
    99     TEST_A,
   100     TEST_B,
   101     TEST_C
   102   };
   103   static TypeId GetTypeId (void) {
   104     static TypeId tid = TypeId ("ns3::AttributeObjectTest")
   105       .SetParent<Object> ()
   106       .HideFromDocumentation ()
   107       .AddAttribute ("TestBoolName", "help text",
   108 		     BooleanValue (false),
   109 		     MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
   110 		     MakeBooleanChecker ())
   111       .AddAttribute ("TestBoolA", "help text",
   112 		     BooleanValue (false),
   113 		     MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
   114 					   &AttributeObjectTest::DoGetTestB),
   115 		     MakeBooleanChecker ())
   116       .AddAttribute ("TestInt16", "help text",
   117 		     IntegerValue (-2),
   118 		     MakeIntegerAccessor (&AttributeObjectTest::m_int16),
   119 		     MakeIntegerChecker<int16_t> ())
   120       .AddAttribute ("TestInt16WithBounds", "help text",
   121 		     IntegerValue (-2),
   122 		     MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
   123 		     MakeIntegerChecker<int16_t> (-5, 10))
   124       .AddAttribute ("TestInt16SetGet", "help text",
   125 		     IntegerValue (6),
   126 		     MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
   127 				       &AttributeObjectTest::DoGetInt16),
   128 		     MakeIntegerChecker<int16_t> ())
   129       .AddAttribute ("TestUint8", "help text",
   130 		     UintegerValue (1),
   131 		     MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
   132 		     MakeUintegerChecker<uint8_t> ())
   133       .AddAttribute ("TestEnum", "help text",
   134 		     EnumValue (TEST_A),
   135 		     MakeEnumAccessor (&AttributeObjectTest::m_enum),
   136 		     MakeEnumChecker (TEST_A, "TestA",
   137 				      TEST_B, "TestB",
   138 				      TEST_C, "TestC"))
   139       .AddAttribute ("TestRandom", "help text",
   140 		     RandomVariableValue (ConstantVariable (1.0)),
   141 		     MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
   142 		     MakeRandomVariableChecker ())
   143       .AddAttribute ("TestFloat", "help text",
   144 		     DoubleValue (-1.1),
   145 		     MakeDoubleAccessor (&AttributeObjectTest::m_float),
   146 		     MakeDoubleChecker<float> ())
   147       .AddAttribute ("TestVector1", "help text",
   148 		     ObjectVectorValue (),
   149 		     MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
   150 		     MakeObjectVectorChecker<Derived> ())
   151       .AddAttribute ("TestVector2", "help text",
   152 		     ObjectVectorValue (),
   153 		     MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
   154 						&AttributeObjectTest::DoGetVector),
   155 		     MakeObjectVectorChecker<Derived> ())
   156       .AddAttribute ("IntegerTraceSource1", "help text",
   157 		     IntegerValue (-2),
   158 		     MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
   159 		     MakeIntegerChecker<int8_t> ())
   160       .AddAttribute ("IntegerTraceSource2", "help text",
   161 		     IntegerValue (-2),
   162 		     MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
   163 					  &AttributeObjectTest::DoGetIntSrc),
   164 		     MakeIntegerChecker<int8_t> ())
   165       .AddAttribute ("ValueClassSource", "help text",
   166 		     ValueClassTestValue (ValueClassTest ()),
   167 		     MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
   168 		     MakeValueClassTestChecker ())
   169       .AddTraceSource ("Source1", "help test",
   170 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
   171       .AddTraceSource ("Source2", "help text",
   172 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
   173       .AddTraceSource ("ValueSource", "help text",
   174 		       MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
   175       .AddAttribute ("Pointer", "help text",
   176                      PointerValue (),
   177                      MakePointerAccessor (&AttributeObjectTest::m_ptr),
   178                      MakePointerChecker<Derived> ())
   179       .AddAttribute ("Callback", "help text",
   180                      CallbackValue (),
   181                      MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
   182                      MakeCallbackChecker ())
   183       ;
   184         
   185     return tid;
   186   }
   187 
   188   void AddToVector1 (void) {
   189     m_vector1.push_back (CreateObject<Derived> ());
   190   }
   191   void AddToVector2 (void) {
   192     m_vector2.push_back (CreateObject<Derived> ());
   193   }
   194 
   195   void InvokeCb (double a, int b, float c) {
   196     m_cb (a,b,c);
   197   }
   198 
   199   void InvokeCbValue (int8_t a) {
   200     if (!m_cbValue.IsNull ())
   201       {
   202         m_cbValue (a);
   203       }
   204   }
   205 
   206 private:
   207   void DoSetTestB (bool v) {
   208     m_boolTestA = v;
   209   }
   210   bool DoGetTestB (void) const {
   211     return m_boolTestA;
   212   }
   213   int16_t DoGetInt16 (void) const {
   214     return m_int16SetGet;
   215   }
   216   void DoSetInt16 (int16_t v) {
   217     m_int16SetGet = v;
   218   }
   219   uint32_t DoGetVectorN (void) const {
   220     return m_vector2.size ();
   221   }
   222   Ptr<Derived> DoGetVector (uint32_t i) const {
   223     return m_vector2[i];
   224   }
   225   bool DoSetIntSrc (int8_t v) {
   226     m_intSrc2 = v;
   227     return true;
   228   }
   229   int8_t DoGetIntSrc (void) const {
   230     return m_intSrc2;
   231   }
   232   bool m_boolTestA;
   233   bool m_boolTest;
   234   int16_t m_int16;
   235   int16_t m_int16WithBounds;
   236   int16_t m_int16SetGet;
   237   uint8_t m_uint8;
   238   float m_float;
   239   enum Test_e m_enum;
   240   RandomVariable m_random;
   241   std::vector<Ptr<Derived> > m_vector1;
   242   std::vector<Ptr<Derived> > m_vector2;
   243   Callback<void,int8_t> m_cbValue;
   244   TracedValue<int8_t> m_intSrc1;
   245   TracedValue<int8_t> m_intSrc2;
   246   TracedCallback<double, int, float> m_cb;
   247   TracedValue<ValueClassTest> m_valueSrc;
   248   Ptr<Derived> m_ptr;
   249 };
   250 
   251 
   252 #define CHECK_GET_STR(p,name,value)                               \
   253   {                                                               \
   254     std::string expected = value;                                 \
   255     StringValue got;                                              \
   256     bool ok = p->GetAttributeFailSafe (name, got);                \
   257     NS_TEST_ASSERT (ok);                                          \
   258     NS_TEST_ASSERT_EQUAL (got.Get (), expected);                  \
   259   }
   260 #define CHECK_GET_PARAM(p,name,type,value)		\
   261   {							\
   262     const type expected = value;			\
   263     type got;                                           \
   264     bool ok = p->GetAttributeFailSafe (name, got);      \
   265     NS_TEST_ASSERT (ok);                                \
   266     NS_TEST_ASSERT_EQUAL (got.Get (), expected.Get ());	\
   267   }
   268 
   269 NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
   270 
   271 AttributeTest::AttributeTest ()
   272   : Test ("Attribute")
   273 {}
   274 bool 
   275 AttributeTest::RunTests (void)
   276 {
   277   bool result = true;
   278 
   279   AttributeList params;
   280   Ptr<AttributeObjectTest> p;
   281   NS_TEST_ASSERT (params.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   282   p = CreateObjectWithAttributes<AttributeObjectTest> (params);
   283   CHECK_GET_STR (p, "TestBoolName", "false");
   284   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   285 
   286   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", StringValue ("true")));
   287   CHECK_GET_STR (p, "TestBoolName", "true");
   288   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   289 
   290   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolName", BooleanValue (false)));
   291   CHECK_GET_STR (p, "TestBoolName", "false");
   292   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, false);
   293 
   294   p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
   295   CHECK_GET_STR (p, "TestBoolName", "true");
   296   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   297 
   298   p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", BooleanValue (true));
   299   CHECK_GET_STR (p, "TestBoolName", "true");
   300   CHECK_GET_PARAM (p, "TestBoolName", BooleanValue, true);
   301 
   302   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("false")));
   303   CHECK_GET_STR (p, "TestBoolA", "false");
   304   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, false);
   305 
   306   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestBoolA", StringValue ("true")));
   307   CHECK_GET_STR (p, "TestBoolA", "true");
   308   CHECK_GET_PARAM (p, "TestBoolA", BooleanValue, true);
   309 
   310 
   311   CHECK_GET_STR (p, "TestInt16", "-2");
   312   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -2);
   313 
   314   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", StringValue ("-5")));
   315   CHECK_GET_STR (p, "TestInt16", "-5");
   316   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -5);
   317 
   318   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (+2)));
   319   CHECK_GET_STR (p, "TestInt16", "2");
   320   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, +2);
   321 
   322   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (-32768)));
   323   CHECK_GET_STR (p, "TestInt16", "-32768");
   324   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   325 
   326   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (-32769)));
   327   CHECK_GET_STR (p, "TestInt16", "-32768");
   328   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, -32768);
   329 
   330   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16", IntegerValue (32767)));
   331   CHECK_GET_STR (p, "TestInt16", "32767");
   332   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   333 
   334   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16", IntegerValue (32768)));
   335   CHECK_GET_STR (p, "TestInt16", "32767");
   336   CHECK_GET_PARAM (p, "TestInt16", IntegerValue, 32767);
   337 
   338   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10)));
   339   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   340   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   341   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11)));
   342   CHECK_GET_STR (p, "TestInt16WithBounds", "10");
   343   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, 10);
   344 
   345   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5)));
   346   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   347   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   348   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6)));
   349   CHECK_GET_STR (p, "TestInt16WithBounds", "-5");
   350   CHECK_GET_PARAM (p, "TestInt16WithBounds", IntegerValue, -5);
   351 
   352   CHECK_GET_STR (p, "TestInt16SetGet", "6");
   353   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 6);
   354   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestInt16SetGet", IntegerValue (0)));
   355   CHECK_GET_STR (p, "TestInt16SetGet", "0");
   356   CHECK_GET_PARAM (p, "TestInt16SetGet", IntegerValue, 0);
   357 
   358   CHECK_GET_STR (p, "TestUint8", "1");
   359   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 1);
   360   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (0)));
   361   CHECK_GET_STR (p, "TestUint8", "0");
   362   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 0);
   363   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", UintegerValue (255)));
   364   CHECK_GET_STR (p, "TestUint8", "255");
   365   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   366   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestUint8", StringValue ("255")));
   367   CHECK_GET_STR (p, "TestUint8", "255");
   368   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   369   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("256")));
   370   CHECK_GET_STR (p, "TestUint8", "255");
   371   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   372   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", StringValue ("-1")));
   373   CHECK_GET_STR (p, "TestUint8", "255");
   374   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   375   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestUint8", UintegerValue ((uint64_t)-1)));
   376   CHECK_GET_STR (p, "TestUint8", "255");
   377   CHECK_GET_PARAM (p, "TestUint8", UintegerValue, 255);
   378 
   379   CHECK_GET_STR (p, "TestFloat", "-1.1");
   380   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)+2.3)));
   381   CHECK_GET_PARAM (p, "TestFloat", DoubleValue, (float)+2.3);
   382 
   383   CHECK_GET_STR (p, "TestEnum", "TestA");
   384   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_A);
   385   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C)));
   386   CHECK_GET_STR (p, "TestEnum", "TestC");
   387   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_C);
   388   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestEnum", StringValue ("TestB")));
   389   CHECK_GET_STR (p, "TestEnum", "TestB");
   390   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   391   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", StringValue ("TestD")));
   392   CHECK_GET_STR (p, "TestEnum", "TestB");
   393   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   394   NS_TEST_ASSERT (!p->SetAttributeFailSafe("TestEnum", EnumValue (5)));
   395   CHECK_GET_STR (p, "TestEnum", "TestB");
   396   CHECK_GET_PARAM (p, "TestEnum", EnumValue, AttributeObjectTest::TEST_B);
   397 
   398   RandomVariableValue ran;
   399   p->GetAttribute ("TestRandom", ran);
   400   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0.0, 1.0))));
   401   NS_TEST_ASSERT (p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.0))));
   402 
   403   {
   404     ObjectVectorValue vector;
   405     p->GetAttribute ("TestVector1", vector);
   406     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   407     p->AddToVector1 ();
   408     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   409     p->GetAttribute ("TestVector1", vector);
   410     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   411     Ptr<Object> a = vector.Get (0);
   412     NS_TEST_ASSERT_UNEQUAL (a, 0);
   413     p->AddToVector1 ();
   414     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   415     p->GetAttribute ("TestVector1", vector);
   416     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   417   }
   418 
   419   {
   420     ObjectVectorValue vector;
   421     p->GetAttribute ("TestVector2", vector);
   422     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   423     p->AddToVector2 ();
   424     NS_TEST_ASSERT_EQUAL (vector.GetN (), 0);
   425     p->GetAttribute ("TestVector2", vector);
   426     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   427     Ptr<Object> a = vector.Get (0);
   428     NS_TEST_ASSERT_UNEQUAL (a, 0);
   429     p->AddToVector2 ();
   430     NS_TEST_ASSERT_EQUAL (vector.GetN (), 1);
   431     p->GetAttribute ("TestVector2", vector);
   432     NS_TEST_ASSERT_EQUAL (vector.GetN (), 2);
   433   }
   434 
   435   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true")));
   436   p = CreateObject<AttributeObjectTest> ();
   437   BooleanValue boolV;
   438   p->GetAttribute ("TestBoolName", boolV);
   439   NS_TEST_ASSERT_EQUAL (boolV.Get (), true);
   440 
   441   NS_TEST_ASSERT (AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false")));
   442   p = CreateObject<AttributeObjectTest> ();
   443   p->GetAttribute ("TestBoolName", boolV);
   444   NS_TEST_ASSERT_EQUAL (boolV.Get (), false);
   445 
   446   IntegerValue i;
   447   p->GetAttribute ("IntegerTraceSource1", i);
   448   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   449   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (+5)));
   450   p->GetAttribute ("IntegerTraceSource1", i);
   451   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   452   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (127)));
   453   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (128)));
   454   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-128)));
   455   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-129)));
   456 
   457   p->GetAttribute ("IntegerTraceSource2", i);
   458   NS_TEST_ASSERT_EQUAL (i.Get (), -2);
   459   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (+5)));
   460   p->GetAttribute ("IntegerTraceSource2", i);
   461   NS_TEST_ASSERT_EQUAL (i.Get (), +5);
   462   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (127)));
   463   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (128)));
   464   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-128)));
   465   NS_TEST_ASSERT (!p->SetAttributeFailSafe ("IntegerTraceSource2", IntegerValue (-129)));
   466 
   467   m_got1 = -2;
   468   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1)));
   469   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   470   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0)));
   471   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   472   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&AttributeTest::NotifySource1, this)));
   473   NS_TEST_ASSERT (p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1)));
   474   NS_TEST_ASSERT_EQUAL (m_got1, 0);
   475 
   476   m_got2 = 4.3;
   477   p->InvokeCb (1.0, -5, 0.0);
   478   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   479   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   480   NS_TEST_ASSERT_EQUAL (m_got2, 4.3);
   481   p->InvokeCb (1.0, -5, 0.0);
   482   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   483   NS_TEST_ASSERT (p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&AttributeTest::NotifySource2, this)));
   484   p->InvokeCb (-1.0, -5, 0.0);
   485   NS_TEST_ASSERT_EQUAL (m_got2, 1.0);
   486 
   487   NS_TEST_ASSERT (p->TraceConnectWithoutContext ("ValueSource", MakeCallback (&AttributeTest::NotifySourceValue, this)));
   488 
   489   PointerValue ptr;
   490   p->GetAttribute ("Pointer", ptr);
   491   Ptr<Derived> derived = ptr.Get<Derived> ();
   492   NS_TEST_ASSERT (derived == 0);
   493   derived = Create<Derived> ();
   494   NS_TEST_ASSERT (p->SetAttributeFailSafe("Pointer", PointerValue (derived)));
   495   p->GetAttribute ("Pointer", ptr);
   496   Ptr<Derived> stored = ptr.Get<Derived> ();
   497   NS_TEST_ASSERT (stored == derived);
   498   p->GetAttribute ("Pointer", ptr);
   499   Ptr<Object> storedBase = ptr.Get<Object> ();
   500   NS_TEST_ASSERT (stored == storedBase);
   501   p->GetAttribute ("Pointer", ptr);
   502   Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
   503   NS_TEST_ASSERT (x == 0);
   504 
   505   p = CreateObjectWithAttributes<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
   506   NS_TEST_ASSERT (p != 0);
   507   derived = 0;
   508   p->GetAttribute ("Pointer", ptr);
   509   derived = ptr.Get<Derived> ();
   510   NS_TEST_ASSERT (derived != 0);
   511 
   512   p = CreateObject<AttributeObjectTest> ();
   513   NS_TEST_ASSERT (p != 0);
   514   m_gotCbValue = 1;
   515   p->InvokeCbValue (2);
   516   CallbackValue cbValue = MakeCallback (&AttributeTest::NotifyCallbackValue, this);
   517   NS_TEST_ASSERT_EQUAL (m_gotCbValue, 1);
   518   NS_TEST_ASSERT (p->SetAttributeFailSafe ("Callback", 
   519                                            cbValue));
   520   p->InvokeCbValue (2);
   521   NS_TEST_ASSERT_EQUAL (m_gotCbValue, 2);
   522   NS_TEST_ASSERT (p->SetAttributeFailSafe ("Callback", 
   523                                            CallbackValue (MakeNullCallback<void,int8_t> ())));
   524   p->InvokeCbValue (3);
   525   NS_TEST_ASSERT_EQUAL (m_gotCbValue, 2);
   526   
   527   return result;
   528 }
   529 
   530 
   531 
   532 static AttributeTest g_parameterTest;
   533 
   534 } // namespace ns3
   535 
   536 
   537 #endif /* RUN_SELF_TESTS */