--- a/modules/simulator/model/attribute-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1195 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "test.h"
-#include "object.h"
-#include "boolean.h"
-#include "integer.h"
-#include "uinteger.h"
-#include "enum.h"
-#include "string.h"
-#include "random-variable.h"
-#include "double.h"
-#include "object-vector.h"
-#include "traced-value.h"
-#include "callback.h"
-#include "trace-source-accessor.h"
-#include "pointer.h"
-
-namespace ns3 {
-
-class ValueClassTest
-{
-public:
- ValueClassTest () {}
-private:
- int m_v;
-};
-bool operator != (const ValueClassTest &a, const ValueClassTest &b)
-{
- return true;
-}
-std::ostream & operator << (std::ostream &os, ValueClassTest v)
-{
- return os;
-}
-std::istream & operator >> (std::istream &is, ValueClassTest &v)
-{
- return is;
-}
-ATTRIBUTE_HELPER_HEADER (ValueClassTest);
-ATTRIBUTE_HELPER_CPP (ValueClassTest);
-
-class Derived : public Object
-{
-public:
- static TypeId GetTypeId (void) {
- static TypeId tid = TypeId ("ns3::Derived")
- .SetParent<Object> ()
- ;
- return tid;
- }
-};
-
-class AttributeObjectTest : public Object
-{
-public:
- enum Test_e {
- TEST_A,
- TEST_B,
- TEST_C
- };
- static TypeId GetTypeId (void) {
- static TypeId tid = TypeId ("ns3::AttributeObjectTest")
- .SetParent<Object> ()
- .HideFromDocumentation ()
- .AddAttribute ("TestBoolName", "help text",
- BooleanValue (false),
- MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
- MakeBooleanChecker ())
- .AddAttribute ("TestBoolA", "help text",
- BooleanValue (false),
- MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
- &AttributeObjectTest::DoGetTestB),
- MakeBooleanChecker ())
- .AddAttribute ("TestInt16", "help text",
- IntegerValue (-2),
- MakeIntegerAccessor (&AttributeObjectTest::m_int16),
- MakeIntegerChecker<int16_t> ())
- .AddAttribute ("TestInt16WithBounds", "help text",
- IntegerValue (-2),
- MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
- MakeIntegerChecker<int16_t> (-5, 10))
- .AddAttribute ("TestInt16SetGet", "help text",
- IntegerValue (6),
- MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
- &AttributeObjectTest::DoGetInt16),
- MakeIntegerChecker<int16_t> ())
- .AddAttribute ("TestUint8", "help text",
- UintegerValue (1),
- MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
- MakeUintegerChecker<uint8_t> ())
- .AddAttribute ("TestEnum", "help text",
- EnumValue (TEST_A),
- MakeEnumAccessor (&AttributeObjectTest::m_enum),
- MakeEnumChecker (TEST_A, "TestA",
- TEST_B, "TestB",
- TEST_C, "TestC"))
- .AddAttribute ("TestRandom", "help text",
- RandomVariableValue (ConstantVariable (1.0)),
- MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
- MakeRandomVariableChecker ())
- .AddAttribute ("TestFloat", "help text",
- DoubleValue (-1.1),
- MakeDoubleAccessor (&AttributeObjectTest::m_float),
- MakeDoubleChecker<float> ())
- .AddAttribute ("TestVector1", "help text",
- ObjectVectorValue (),
- MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
- MakeObjectVectorChecker<Derived> ())
- .AddAttribute ("TestVector2", "help text",
- ObjectVectorValue (),
- MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
- &AttributeObjectTest::DoGetVector),
- MakeObjectVectorChecker<Derived> ())
- .AddAttribute ("IntegerTraceSource1", "help text",
- IntegerValue (-2),
- MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
- MakeIntegerChecker<int8_t> ())
- .AddAttribute ("IntegerTraceSource2", "help text",
- IntegerValue (-2),
- MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
- &AttributeObjectTest::DoGetIntSrc),
- MakeIntegerChecker<int8_t> ())
- .AddAttribute ("UIntegerTraceSource", "help text",
- UintegerValue (2),
- MakeUintegerAccessor (&AttributeObjectTest::m_uintSrc),
- MakeIntegerChecker<uint8_t> ())
- .AddAttribute ("DoubleTraceSource", "help text",
- DoubleValue (2),
- MakeDoubleAccessor (&AttributeObjectTest::m_doubleSrc),
- MakeDoubleChecker<double> ())
- .AddAttribute ("BoolTraceSource", "help text",
- BooleanValue (false),
- MakeBooleanAccessor (&AttributeObjectTest::m_boolSrc),
- MakeBooleanChecker ())
- .AddAttribute ("EnumTraceSource", "help text",
- EnumValue (false),
- MakeEnumAccessor (&AttributeObjectTest::m_enumSrc),
- MakeEnumChecker (TEST_A, "TestA"))
- .AddAttribute ("ValueClassSource", "help text",
- ValueClassTestValue (ValueClassTest ()),
- MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
- MakeValueClassTestChecker ())
- .AddTraceSource ("Source1", "help test",
- MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
- .AddTraceSource ("Source2", "help text",
- MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
- .AddTraceSource ("ValueSource", "help text",
- MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
- .AddAttribute ("Pointer", "help text",
- PointerValue (),
- MakePointerAccessor (&AttributeObjectTest::m_ptr),
- MakePointerChecker<Derived> ())
- .AddAttribute ("Callback", "help text",
- CallbackValue (),
- MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
- MakeCallbackChecker ())
- ;
-
- return tid;
- }
-
- void AddToVector1 (void) {m_vector1.push_back (CreateObject<Derived> ());}
- void AddToVector2 (void) {m_vector2.push_back (CreateObject<Derived> ());}
- void InvokeCb (double a, int b, float c) {m_cb (a,b,c);}
-
- void InvokeCbValue (int8_t a)
- {
- if (!m_cbValue.IsNull ()) {
- m_cbValue (a);
- }
- }
-
-private:
- void DoSetTestB (bool v) {m_boolTestA = v;}
- bool DoGetTestB (void) const {return m_boolTestA;}
- int16_t DoGetInt16 (void) const {return m_int16SetGet;}
- void DoSetInt16 (int16_t v) {m_int16SetGet = v;}
- uint32_t DoGetVectorN (void) const {return m_vector2.size ();}
- Ptr<Derived> DoGetVector (uint32_t i) const {return m_vector2[i];}
- bool DoSetIntSrc (int8_t v) {m_intSrc2 = v; return true;}
- int8_t DoGetIntSrc (void) const {return m_intSrc2;}
-
- bool m_boolTestA;
- bool m_boolTest;
- int16_t m_int16;
- int16_t m_int16WithBounds;
- int16_t m_int16SetGet;
- uint8_t m_uint8;
- float m_float;
- enum Test_e m_enum;
- RandomVariable m_random;
- std::vector<Ptr<Derived> > m_vector1;
- std::vector<Ptr<Derived> > m_vector2;
- Callback<void,int8_t> m_cbValue;
- TracedValue<int8_t> m_intSrc1;
- TracedValue<int8_t> m_intSrc2;
- TracedCallback<double, int, float> m_cb;
- TracedValue<ValueClassTest> m_valueSrc;
- Ptr<Derived> m_ptr;
- TracedValue<uint8_t> m_uintSrc;
- TracedValue<enum Test_e> m_enumSrc;
- TracedValue<double> m_doubleSrc;
- TracedValue<bool> m_boolSrc;
-};
-
-NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
-
-// ===========================================================================
-// Test case template used for generic Attribute Value types -- used to make
-// sure that Attributes work as expected.
-// ===========================================================================
-template <typename T>
-class AttributeTestCase : public TestCase
-{
-public:
- AttributeTestCase (std::string description);
- virtual ~AttributeTestCase ();
-
-private:
- virtual bool DoRun (void);
-
- bool CheckGetCodePaths (Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
-};
-
-template <typename T>
-AttributeTestCase<T>::AttributeTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-template <typename T>
-AttributeTestCase<T>::~AttributeTestCase ()
-{
-}
-
-template <typename T> bool
-AttributeTestCase<T>::CheckGetCodePaths (
- Ptr<Object> p,
- std::string attributeName,
- std::string expectedString,
- T expectedValue)
-{
- StringValue stringValue;
- T actualValue;
-
- //
- // Get an Attribute value through its StringValue representation.
- //
- bool ok = p->GetAttributeFailSafe (attributeName.c_str (), stringValue);
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not GetAttributeFailSafe() " << attributeName << " from Object");
- NS_TEST_ASSERT_MSG_EQ (stringValue.Get (), expectedString, "Got unexpected StringValue representation");
-
- //
- // Get the existing boolean value through its particular type representation.
- //
- ok = p->GetAttributeFailSafe (attributeName.c_str (), actualValue);
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not GetAttributeFailSafe() " << attributeName << " from Object");
- NS_TEST_ASSERT_MSG_EQ (actualValue.Get (), expectedValue.Get (), "Got unexpected Value from Object");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// The actual Attribute type test cases are specialized for each Attribute type
-// ===========================================================================
-template <> bool
-AttributeTestCase<BooleanValue>::DoRun (void)
-{
- AttributeList attrs;
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- //
- // Test setting a boolean via string representation using AttributeList.
- //
- ok = attrs.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetFailSafe() \"ns3::AttributeObjectTest::TestBoolName\" into AttributeList");
-
- //
- // Create an object using that attribute list (which should therefore have the
- // boolean from above set to false.
- //
- p = CreateObjectWithAttributes<AttributeObjectTest> (attrs);
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly from CreateObjectWithAttributes");
-
- //
- // Set the default value of the BooleanValue and create an object. The new
- // default value should stick.
- //
- AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true"));
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
-
- //
- // Set the default value of the BooleanValue the other way and create an object.
- // The new default value should stick.
- //
- AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not et properly by default value");
-
- //
- // Set the BooleanValue Attribute to true via SetAttributeFailSafe path.
- //
- ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("true"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to true");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Set the BooleanValue to false via SetAttributeFailSafe path.
- //
- ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("false"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to false");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Create an object using individually provided StringValue Attribute.
- //
- p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by CreateObjectWithAttributes() with StringValue");
-
- //
- // Create an object using individually provided BooleanValue Attribute.
- //
- p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", BooleanValue (false));
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
-
- ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by CreateObjectWithAttributes() with BooleanValue");
-
- //
- // The previous object-based tests checked access directly. Now check through
- // setter and getter. The code here looks the same, but the underlying
- // attribute is declared differently in the object. First make sure we can set
- // to true.
- //
- ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("true"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to true");
-
- ok = CheckGetCodePaths (p, "TestBoolA", "true", BooleanValue (true));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
-
- //
- // Now Set the BooleanValue to false via the setter.
- //
- ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("false"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to false");
-
- ok = CheckGetCodePaths (p, "TestBoolA", "false", BooleanValue (false));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
-
- return GetErrorStatus ();
-}
-
-template <> bool
-AttributeTestCase<IntegerValue>::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- ok = CheckGetCodePaths (p, "TestInt16", "-2", IntegerValue (-2));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
-
- //
- // Set the Attribute to a negative value through a StringValue.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-5"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -5");
-
- ok = CheckGetCodePaths (p, "TestInt16", "-5", IntegerValue (-5));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Set the Attribute to a positive value through a StringValue.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("+2"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to +2");
-
- ok = CheckGetCodePaths (p, "TestInt16", "2", IntegerValue (2));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Set the Attribute to the most negative value of the signed 16-bit range.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32768"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -32768");
-
- ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
-
- //
- // Try to set the Attribute past the most negative value of the signed 16-bit
- // range and make sure the underlying attribute is unchanged.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32769"));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
-
- ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Set the Attribute to the most positive value of the signed 16-bit range.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32767"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 32767");
-
- ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
-
- //
- // Try to set the Attribute past the most positive value of the signed 16-bit
- // range and make sure the underlying attribute is unchanged.
- //
- ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32768"));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
-
- ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Attributes can have limits other than the intrinsic limits of the
- // underlying data types. These limits are specified in the Object.
- //
- ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 10");
-
- ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
-
- //
- // Set the Attribute past the positive limit.
- //
- ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
-
- ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Set the Attribute at the negative limit.
- //
- ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -5");
-
- ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
-
- //
- // Set the Attribute past the negative limit.
- //
- ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
-
- ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- return GetErrorStatus ();
-}
-
-template <> bool
-AttributeTestCase<UintegerValue>::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- ok = CheckGetCodePaths (p, "TestUint8", "1", UintegerValue (1));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");;
-
- //
- // Set the Attribute to zero.
- //
- ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (0));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 0");
-
- ok = CheckGetCodePaths (p, "TestUint8", "0", UintegerValue (0));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Set the Attribute to the most positive value of the unsigned 8-bit range.
- //
- ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (255));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 255");
-
- ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
-
- //
- // Try and set the Attribute past the most positive value of the unsigned
- // 8-bit range.
- //
- ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (256));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 256");
-
- ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Set the Attribute to the most positive value of the unsigned 8-bit range
- // through a StringValue.
- //
- ok = p->SetAttributeFailSafe("TestUint8", StringValue ("255"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 255");
-
- ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Try and set the Attribute past the most positive value of the unsigned
- // 8-bit range through a StringValue.
- //
- ok = p->SetAttributeFailSafe("TestUint8", StringValue ("256"));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
-
- ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Try to set the Attribute to a negative StringValue.
- //
- ok = p->SetAttributeFailSafe("TestUint8", StringValue ("-1"));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
-
- return GetErrorStatus ();
-}
-
-template <> bool
-AttributeTestCase<DoubleValue>::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- ok = CheckGetCodePaths (p, "TestFloat", "-1.1", DoubleValue ((float)-1.1));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
-
- //
- // Set the Attribute.
- //
- ok = p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)2.3));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 2.3");
-
- ok = CheckGetCodePaths (p, "TestFloat", "2.3", DoubleValue ((float)2.3));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
-
- return GetErrorStatus ();
-}
-
-template <> bool
-AttributeTestCase<EnumValue>::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- ok = CheckGetCodePaths (p, "TestEnum", "TestA", EnumValue (AttributeObjectTest::TEST_A));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
-
- //
- // Set the Attribute using the EnumValue type.
- //
- ok = p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_C");
-
- ok = CheckGetCodePaths (p, "TestEnum", "TestC", EnumValue (AttributeObjectTest::TEST_C));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via EnumValue");
-
- //
- // Set the Attribute using the StringValue type.
- //
- ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestB"));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_B");
-
- ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
-
- //
- // Try to set the Attribute to a bogus enum using the StringValue type and
- // make sure the underlying value doesn't change.
- //
- ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestD"));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to TEST_D"); //
-
- ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- //
- // Try to set the Attribute to a bogus enum using an integer implicit conversion
- // and make sure the underlying value doesn't change.
- //
- ok = p->SetAttributeFailSafe("TestEnum", EnumValue (5));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 5");
-
- ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
-
- return GetErrorStatus ();
-}
-
-template <> bool
-AttributeTestCase<RandomVariableValue>::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // Try to set a UniformVariable
- //
- ok = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0., 1.)));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
-
- //
- // Try to set a <snicker> ConstantVariable
- //
- ok = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.)));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Test case for Object Vector Attributes. Generic nature is pretty much lost
-// here, so we just break the class out.
-// ===========================================================================
-class ObjectVectorAttributeTestCase : public TestCase
-{
-public:
- ObjectVectorAttributeTestCase (std::string description);
- virtual ~ObjectVectorAttributeTestCase () {}
-
-private:
- virtual bool DoRun (void);
-};
-
-ObjectVectorAttributeTestCase::ObjectVectorAttributeTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-ObjectVectorAttributeTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- ObjectVectorValue vector;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have no items in
- // the vector.
- //
- p->GetAttribute ("TestVector1", vector);
- NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should be zero");
-
- //
- // Adding to the attribute shouldn't affect the value we already have.
- //
- p->AddToVector1 ();
- NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should still be zero");
-
- //
- // Getting the attribute again should update the value.
- //
- p->GetAttribute ("TestVector1", vector);
- NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "ObjectVectorValue \"TestVector1\" should be incremented");
-
- //
- // Get the Object pointer from the value.
- //
- Ptr<Object> a = vector.Get (0);
- NS_TEST_ASSERT_MSG_NE (a, 0, "Ptr<Object> from VectorValue \"TestVector1\" is zero");
-
- //
- // Adding to the attribute shouldn't affect the value we already have.
- //
- p->AddToVector1 ();
- NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "Count of ObjectVectorValue \"TestVector1\" should still be one");
-
- //
- // Getting the attribute again should update the value.
- //
- p->GetAttribute ("TestVector1", vector);
- NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 2, "ObjectVectorValue \"TestVector1\" should be incremented");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Trace sources with value semantics can be used like Attributes. Make sure
-// we can use them that way.
-// ===========================================================================
-class IntegerTraceSourceAttributeTestCase : public TestCase
-{
-public:
- IntegerTraceSourceAttributeTestCase (std::string description);
- virtual ~IntegerTraceSourceAttributeTestCase () {}
-
-private:
- virtual bool DoRun (void);
-};
-
-IntegerTraceSourceAttributeTestCase::IntegerTraceSourceAttributeTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-IntegerTraceSourceAttributeTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- IntegerValue iv;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- p->GetAttribute ("IntegerTraceSource1", iv);
- NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
-
- //
- // Set the Attribute to a positive value through an IntegerValue.
- //
- ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (5));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
-
- p->GetAttribute ("IntegerTraceSource1", iv);
- NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
-
- //
- // Limits should work.
- //
- ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (127));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (128));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-128));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-129));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
-
- //
- // When the object is first created, the Attribute should have the default
- // value.
- //
- p->GetAttribute ("IntegerTraceSource2", iv);
- NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
-
- //
- // Set the Attribute to a positive value through an IntegerValue.
- //
- ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (5));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
-
- p->GetAttribute ("IntegerTraceSource2", iv);
- NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
-
- //
- // Limits should work.
- //
- ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (127));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (128));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-128));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
-
- ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-129));
- NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Trace sources used like Attributes must also work as trace sources. Make
-// sure we can use them that way.
-// ===========================================================================
-class IntegerTraceSourceTestCase : public TestCase
-{
-public:
- IntegerTraceSourceTestCase (std::string description);
- virtual ~IntegerTraceSourceTestCase () {}
-
-private:
- virtual bool DoRun (void);
-
- void NotifySource1 (int8_t old, int8_t n) {m_got1 = n;}
- int64_t m_got1;
-};
-
-IntegerTraceSourceTestCase::IntegerTraceSourceTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-IntegerTraceSourceTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // Check to make sure changing an Attibute value triggers a trace callback
- // that sets a member variable.
- //
- m_got1 = 1234;
-
- ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -1");
-
- //
- // Source1 is declared as a TraceSourceAccessor to m_intSrc1. This m_intSrc1
- // is also declared as an Integer Attribute. We just checked to make sure we
- // could set it using an IntegerValue through its IntegerTraceSource1 "persona."
- // We should also be able to hook a trace source to the underlying variable.
- //
- ok = p->TraceConnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
-
- //
- // When we set the IntegerValue that now underlies both the Integer Attribute
- // and the trace source, the trace should fire and call NotifySource1 which
- // will set m_got1 to the new value.
- //
- ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 0");
-
- NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue does not cause trace callback to be called");
-
- //
- // Now disconnect from the trace source and ensure that the trace callback
- // is not called if the trace source is hit.
- //
- ok = p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
-
- ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 1");
-
- NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue after disconnect still causes callback");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Trace sources used like Attributes must also work as trace sources. Make
-// sure we can use them that way.
-// ===========================================================================
-class TracedCallbackTestCase : public TestCase
-{
-public:
- TracedCallbackTestCase (std::string description);
- virtual ~TracedCallbackTestCase () {}
-
-private:
- virtual bool DoRun (void);
-
- void NotifySource2 (double a, int b, float c) {m_got2 = a;}
-
- double m_got2;
-};
-
-TracedCallbackTestCase::TracedCallbackTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-TracedCallbackTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // Initialize the
- //
- m_got2 = 4.3;
-
- //
- // Invoke the callback that lies at the heart of this test. We have a
- // method InvokeCb() that just executes m_cb(). The variable m_cb is
- // declared as a TracedCallback<double, int, float>. This kind of beast
- // is like a callback but can call a list of targets. This list should
- // be empty so nothing should happen now. Specifically, m_got2 shouldn't
- // have changed.
- //
- p->InvokeCb (1.0, -5, 0.0);
- NS_TEST_ASSERT_MSG_EQ (m_got2, 4.3, "Invoking a newly created TracedCallback results in an unexpected callback");
-
- //
- // Now, wire the TracedCallback up to a trace sink. This sink will just set
- // m_got2 to the first argument.
- //
- ok = p->TraceConnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() to NotifySource2");
-
- //
- // Now if we invoke the callback, the trace source should fire and m_got2
- // should be set in the trace sink.
- //
- p->InvokeCb (1.0, -5, 0.0);
- NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking TracedCallback does not result in trace callback");
-
- //
- // Now, disconnect the trace sink and see what happens when we invoke the
- // callback again. Of course, the trace should not happen and m_got2
- // should remain unchanged.
- //
- ok = p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceDisconnectWithoutContext() from NotifySource2");
-
- p->InvokeCb (-1.0, -5, 0.0);
- NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking disconnected TracedCallback unexpectedly results in trace callback");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Smart pointers (Ptr) are central to our architecture, so they must work as
-// attributes.
-// ===========================================================================
-class PointerAttributeTestCase : public TestCase
-{
-public:
- PointerAttributeTestCase (std::string description);
- virtual ~PointerAttributeTestCase () {}
-
-private:
- virtual bool DoRun (void);
-
- void NotifySource2 (double a, int b, float c) {m_got2 = a;}
-
- double m_got2;
-};
-
-PointerAttributeTestCase::PointerAttributeTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-PointerAttributeTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // We have declared a PointerValue Attribute named "Pointer" with a pointer
- // checker of type Derived. This means that we should be able to pull out
- // a Ptr<Derived> with the initial value (which is 0).
- //
- PointerValue ptr;
- p->GetAttribute ("Pointer", ptr);
- Ptr<Derived> derived = ptr.Get<Derived> ();
- NS_TEST_ASSERT_MSG_EQ (derived, 0, "Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
-
- //
- // Now, lets create an Object of type Derived and set the local Ptr to point
- // to that object. We can then set the PointerValue Attribute to that Ptr.
- //
- derived = Create<Derived> ();
- ok = p->SetAttributeFailSafe("Pointer", PointerValue (derived));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a PointerValue of the correct type");
-
- //
- // Pull the value back out of the Attribute and make sure it points to the
- // correct object.
- //
- p->GetAttribute ("Pointer", ptr);
- Ptr<Derived> stored = ptr.Get<Derived> ();
- NS_TEST_ASSERT_MSG_EQ (stored, derived, "Retreived Attribute does not match stored PointerValue");
-
- //
- // We should be able to use the Attribute Get() just like GetObject<type>,
- // So see if we can get a Ptr<Object> out of the Ptr<Derived> we stored.
- // This should be a pointer to the same physical memory since its the
- // same object.
- //
- p->GetAttribute ("Pointer", ptr);
- Ptr<Object> storedBase = ptr.Get<Object> ();
- NS_TEST_ASSERT_MSG_EQ (storedBase, stored, "Retreived Ptr<Object> does not match stored Ptr<Derived>");
-
- //
- // If we try to Get() something that is unrelated to what we stored, we should
- // retrieve a 0.
- //
- p->GetAttribute ("Pointer", ptr);
- Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_EQ (x, 0, "Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
-
- //
- // We should be able to create the object From a list of attributes.
- //
- p = CreateObjectWithAttributes<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
- NS_TEST_ASSERT_MSG_NE (p, 0, "Could not create Object with PointerValue Attribute in Attribute List");
-
- derived = 0;
- p->GetAttribute ("Pointer", ptr);
- derived = ptr.Get<Derived> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Retrieved zero PointerValue Attribute after initializing to non-zero Ptr");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Test the Attributes of type CallbackVale.
-// ===========================================================================
-class CallbackValueTestCase : public TestCase
-{
-public:
- CallbackValueTestCase (std::string description);
- virtual ~CallbackValueTestCase () {}
-
- void InvokeCbValue (int8_t a)
- {
- if (!m_cbValue.IsNull ()) {
- m_cbValue (a);
- }
- }
-
-private:
- virtual bool DoRun (void);
-
- Callback<void,int8_t> m_cbValue;
-
- void NotifyCallbackValue (int8_t a) {m_gotCbValue = a;}
-
- int16_t m_gotCbValue;
-};
-
-CallbackValueTestCase::CallbackValueTestCase (std::string description)
- : TestCase (description)
-{
-}
-
-bool
-CallbackValueTestCase::DoRun (void)
-{
- Ptr<AttributeObjectTest> p;
- bool ok;
-
- p = CreateObject<AttributeObjectTest> ();
- NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
-
- //
- // The member variable m_cbValue is declared as a Callback<void, int8_t>. The
- // Attibute named "Callback" also points to m_cbValue and allows us to set the
- // callback using that Attribute.
- //
- // NotifyCallbackValue is going to be the target of the callback and will just set
- // m_gotCbValue to its single parameter. This will be the parameter from the
- // callback invocation. The method InvokeCbValue() just invokes the m_cbValue
- // callback if it is non-null.
- //
- m_gotCbValue = 1;
-
- //
- // If we invoke the callback (which has not been set) nothing should happen.
- // Further, nothing should happen when we initialize the callback (it shouldn't
- // accidentally fire).
- //
- p->InvokeCbValue (2);
- CallbackValue cbValue = MakeCallback (&CallbackValueTestCase::NotifyCallbackValue, this);
-
- NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 1, "Callback unexpectedly fired");
-
- ok = p->SetAttributeFailSafe ("Callback", cbValue);
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a CallbackValue");
-
- //
- // Now that the callback has been set, invoking it should set m_gotCbValue.
- //
- p->InvokeCbValue (2);
- NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set by CallbackValue did not fire");
-
- ok = p->SetAttributeFailSafe ("Callback", CallbackValue (MakeNullCallback<void,int8_t> ()));
- NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a null CallbackValue");
-
- //
- // If the callback has been set to a null callback, it should no longer fire.
- //
- p->InvokeCbValue (3);
- NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set to null callback unexpectedly fired");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// The Test Suite that glues all of the Test Cases together.
-// ===========================================================================
-class AttributesTestSuite : public TestSuite
-{
-public:
- AttributesTestSuite ();
-};
-
-AttributesTestSuite::AttributesTestSuite ()
- : TestSuite ("attributes", UNIT)
-{
- AddTestCase (new AttributeTestCase<BooleanValue> ("Check Attributes of type BooleanValue"));
- AddTestCase (new AttributeTestCase<IntegerValue> ("Check Attributes of type IntegerValue"));
- AddTestCase (new AttributeTestCase<UintegerValue> ("Check Attributes of type UintegerValue"));
- AddTestCase (new AttributeTestCase<DoubleValue> ("Check Attributes of type DoubleValue"));
- AddTestCase (new AttributeTestCase<EnumValue> ("Check Attributes of type EnumValue"));
- AddTestCase (new AttributeTestCase<RandomVariableValue> ("Check Attributes of type RandomVariableValue"));
- AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue"));
- AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue<uint8_t> can be set like IntegerValue"));
- AddTestCase (new IntegerTraceSourceTestCase ("Ensure TracedValue<uint8_t> also works as trace source"));
- AddTestCase (new TracedCallbackTestCase ("Ensure TracedCallback<double, int, float> works as trace source"));
- AddTestCase (new PointerAttributeTestCase ("Check Attributes of type PointerValue"));
- AddTestCase (new CallbackValueTestCase ("Check Attributes of type CallbackValue"));
-}
-
-static AttributesTestSuite attributesTestSuite;
-
-} // namespace ns3
--- a/modules/simulator/model/callback-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,590 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "test.h"
-#include "callback.h"
-#include <stdint.h>
-
-namespace ns3 {
-
-// ===========================================================================
-// Test the basic Callback mechanism
-// ===========================================================================
-class BasicCallbackTestCase : public TestCase
-{
-public:
- BasicCallbackTestCase ();
- virtual ~BasicCallbackTestCase () {}
-
- void Target1 (void) {m_test1 = true;}
- int Target2 (void) {m_test2 = true; return 2;}
- void Target3 (double a) {m_test3 = true;}
- int Target4 (double a, int b) {m_test4 = true; return 4;}
-
-private:
- virtual bool DoRun (void);
- virtual void DoSetup (void);
-
- bool m_test1;
- bool m_test2;
- bool m_test3;
- bool m_test4;
-};
-
-static bool gBasicCallbackTest5;
-static bool gBasicCallbackTest6;
-static bool gBasicCallbackTest7;
-
-void
-BasicCallbackTarget5 (void)
-{
- gBasicCallbackTest5 = true;
-}
-
-void
-BasicCallbackTarget6 (int)
-{
- gBasicCallbackTest6 = true;
-}
-
-int
-BasicCallbackTarget7 (int a)
-{
- gBasicCallbackTest7 = true;
- return a;
-}
-
-BasicCallbackTestCase::BasicCallbackTestCase ()
- : TestCase ("Check basic Callback mechansim")
-{
-}
-
-void
-BasicCallbackTestCase::DoSetup (void)
-{
- m_test1 = false;
- m_test2 = false;
- m_test3 = false;
- m_test4 = false;
- gBasicCallbackTest5 = false;
- gBasicCallbackTest6 = false;
- gBasicCallbackTest7 = false;
-}
-
-bool
-BasicCallbackTestCase::DoRun (void)
-{
- //
- // Make sure we can declare and compile a Callback pointing to a member
- // function returning void and execute it.
- //
- Callback<void> target1 (this, &BasicCallbackTestCase::Target1);
- target1 ();
- NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a member
- // function that returns an int and execute it.
- //
- Callback<int> target2;
- target2 = Callback<int> (this, &BasicCallbackTestCase::Target2);
- target2 ();
- NS_TEST_ASSERT_MSG_EQ (m_test2, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a member
- // function that returns void, takes a double parameter, and execute it.
- //
- Callback<void, double> target3 = Callback<void, double> (this, &BasicCallbackTestCase::Target3);
- target3 (0.0);
- NS_TEST_ASSERT_MSG_EQ (m_test3, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a member
- // function that returns void, takes two parameters, and execute it.
- //
- Callback<int, double, int> target4 = Callback<int, double, int> (this, &BasicCallbackTestCase::Target4);
- target4 (0.0, 1);
- NS_TEST_ASSERT_MSG_EQ (m_test4, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a non-member
- // function that returns void, and execute it. This is a lower level call
- // than MakeCallback so we have got to include at least two arguments to make
- // sure that the constructor is properly disambiguated. If the arguments are
- // not needed, we just pass in dummy values.
- //
- Callback<void> target5 = Callback<void> (&BasicCallbackTarget5, true, true);
- target5 ();
- NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest5, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a non-member
- // function that returns void, takes one integer argument and execute it.
- // We also need to provide two dummy arguments to the constructor here.
- //
- Callback<void, int> target6 = Callback<void, int> (&BasicCallbackTarget6, true, true);
- target6 (1);
- NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest6, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a non-member
- // function that returns int, takes one integer argument and execute it.
- // We also need to provide two dummy arguments to the constructor here.
- //
- Callback<int, int> target7 = Callback<int, int> (&BasicCallbackTarget7, true, true);
- target7 (1);
- NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest7, true, "Callback did not fire");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Test the MakeCallback mechanism
-// ===========================================================================
-class MakeCallbackTestCase : public TestCase
-{
-public:
- MakeCallbackTestCase ();
- virtual ~MakeCallbackTestCase () {}
-
- void Target1 (void) {m_test1 = true;}
- int Target2 (void) {m_test2 = true; return 2;}
- void Target3 (double a) {m_test3 = true;}
- int Target4 (double a, int b) {m_test4 = true; return 4;}
-
-private:
- virtual bool DoRun (void);
- virtual void DoSetup (void);
-
- bool m_test1;
- bool m_test2;
- bool m_test3;
- bool m_test4;
-};
-
-static bool gMakeCallbackTest5;
-static bool gMakeCallbackTest6;
-static bool gMakeCallbackTest7;
-
-void
-MakeCallbackTarget5 (void)
-{
- gMakeCallbackTest5 = true;
-}
-
-void
-MakeCallbackTarget6 (int)
-{
- gMakeCallbackTest6 = true;
-}
-
-int
-MakeCallbackTarget7 (int a)
-{
- gMakeCallbackTest7 = true;
- return a;
-}
-
-MakeCallbackTestCase::MakeCallbackTestCase ()
- : TestCase ("Check MakeCallback() mechanism")
-{
-}
-
-void
-MakeCallbackTestCase::DoSetup (void)
-{
- m_test1 = false;
- m_test2 = false;
- m_test3 = false;
- m_test4 = false;
- gMakeCallbackTest5 = false;
- gMakeCallbackTest6 = false;
- gMakeCallbackTest7 = false;
-}
-
-bool
-MakeCallbackTestCase::DoRun (void)
-{
- //
- // Make sure we can declare and make a Callback pointing to a member
- // function returning void and execute it.
- //
- Callback<void> target1 = MakeCallback (&MakeCallbackTestCase::Target1, this);
- target1 ();
- NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
-
- //
- // Make sure we can declare and make a Callback pointing to a member
- // function that returns an int and execute it.
- //
- Callback<int> target2 = MakeCallback (&MakeCallbackTestCase::Target2, this);
- target2 ();
- NS_TEST_ASSERT_MSG_EQ (m_test2, true, "Callback did not fire");
-
- //
- // Make sure we can declare and make a Callback pointing to a member
- // function that returns void, takes a double parameter, and execute it.
- //
- Callback<void, double> target3 = MakeCallback (&MakeCallbackTestCase::Target3, this);
- target3 (0.0);
- NS_TEST_ASSERT_MSG_EQ (m_test3, true, "Callback did not fire");
-
- //
- // Make sure we can declare and make a Callback pointing to a member
- // function that returns void, takes two parameters, and execute it.
- //
- Callback<int, double, int> target4 = MakeCallback (&MakeCallbackTestCase::Target4, this);
- target4 (0.0, 1);
- NS_TEST_ASSERT_MSG_EQ (m_test4, true, "Callback did not fire");
-
- //
- // Make sure we can declare and make a Callback pointing to a non-member
- // function that returns void, and execute it. This uses a higher level call
- // than in the basic tests so we do not need to include any dummy arguments
- // here.
- //
- Callback<void> target5 = MakeCallback (&MakeCallbackTarget5);
- target5 ();
- NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest5, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a non-member
- // function that returns void, takes one integer argument and execute it.
- // This uses a higher level call than in the basic tests so we do not need to
- // include any dummy arguments here.
- //
- Callback<void, int> target6 = MakeCallback (&MakeCallbackTarget6);
- target6 (1);
- NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest6, true, "Callback did not fire");
-
- //
- // Make sure we can declare and compile a Callback pointing to a non-member
- // function that returns int, takes one integer argument and execute it.
- // This uses a higher level call than in the basic tests so we do not need to
- // include any dummy arguments here.
- //
- Callback<int, int> target7 = MakeCallback (&MakeCallbackTarget7);
- target7 (1);
- NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest7, true, "Callback did not fire");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Test the MakeBoundCallback mechanism
-// ===========================================================================
-class MakeBoundCallbackTestCase : public TestCase
-{
-public:
- MakeBoundCallbackTestCase ();
- virtual ~MakeBoundCallbackTestCase () {}
-
-private:
- virtual bool DoRun (void);
- virtual void DoSetup (void);
-};
-
-static int gMakeBoundCallbackTest1;
-static bool *gMakeBoundCallbackTest2;
-static bool *gMakeBoundCallbackTest3a;
-static int gMakeBoundCallbackTest3b;
-
-void
-MakeBoundCallbackTarget1 (int a)
-{
- gMakeBoundCallbackTest1 = a;
-}
-
-void
-MakeBoundCallbackTarget2 (bool *a)
-{
- gMakeBoundCallbackTest2 = a;
-}
-
-int
-MakeBoundCallbackTarget3 (bool *a, int b)
-{
- gMakeBoundCallbackTest3a = a;
- gMakeBoundCallbackTest3b = b;
- return 1234;
-}
-
-MakeBoundCallbackTestCase::MakeBoundCallbackTestCase ()
- : TestCase ("Check MakeBoundCallback() mechanism")
-{
-}
-
-void
-MakeBoundCallbackTestCase::DoSetup (void)
-{
- gMakeBoundCallbackTest1 = 0;
- gMakeBoundCallbackTest2 = 0;
- gMakeBoundCallbackTest3a = 0;
- gMakeBoundCallbackTest3b = 0;
-}
-
-bool
-MakeBoundCallbackTestCase::DoRun (void)
-{
- //
- // This is slightly tricky to explain. A bound Callback allows us to package
- // up arguments for use later. The arguments are bound when the callback is
- // created and the code that fires the Callback does not know they are there.
- //
- // Since the callback is *declared* according to the way it will be used, the
- // arguments are not seen there. However, the target function of the callback
- // will have the provided arguments present. The MakeBoundCallback template
- // function is what connects the two together and where you provide the
- // arguments to be bound.
- //
- // Here we declare a Callback that returns a void and takes no parameters.
- // MakeBoundCallback connects this Callback to a target function that returns
- // void and takes an integer argument. That integer argument is bound to the
- // value 1234. When the Callback is fired, no integer argument is provided
- // directly. The argument is provided by bound Callback mechanism.
- //
- Callback<void> target1 = MakeBoundCallback (&MakeBoundCallbackTarget1, 1234);
- target1 ();
- NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest1, 1234, "Callback did not fire or binding not correct");
-
- //
- // Make sure we can bind a pointer value (a common use case).
- //
- bool a;
- Callback<void> target2 = MakeBoundCallback (&MakeBoundCallbackTarget2, &a);
- target2 ();
- NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest2, &a, "Callback did not fire or binding not correct");
-
- //
- // Make sure we can mix and match bound and unbound arguments. This callback
- // returns an integer so we should see that appear.
- //
- Callback<int, int> target3 = MakeBoundCallback (&MakeBoundCallbackTarget3, &a);
- int result = target3 (2468);
- NS_TEST_ASSERT_MSG_EQ (result, 1234, "Return value of callback not correct");
- NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3a, &a, "Callback did not fire or binding not correct");
- NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3b, 2468, "Callback did not fire or argument not correct");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Test the Nullify mechanism
-// ===========================================================================
-class NullifyCallbackTestCase : public TestCase
-{
-public:
- NullifyCallbackTestCase ();
- virtual ~NullifyCallbackTestCase () {}
-
- void Target1 (void) {m_test1 = true;}
-
-private:
- virtual bool DoRun (void);
- virtual void DoSetup (void);
-
- bool m_test1;
-};
-
-NullifyCallbackTestCase::NullifyCallbackTestCase ()
- : TestCase ("Check Nullify() and IsNull()")
-{
-}
-
-void
-NullifyCallbackTestCase::DoSetup (void)
-{
- m_test1 = false;
-}
-
-bool
-NullifyCallbackTestCase::DoRun (void)
-{
- //
- // Make sure we can declare and make a Callback pointing to a member
- // function returning void and execute it.
- //
- Callback<void> target1 = MakeCallback (&NullifyCallbackTestCase::Target1, this);
- target1 ();
- NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
-
- NS_TEST_ASSERT_MSG_EQ (target1.IsNull (), false, "Working Callback reports IsNull()");
-
- target1.Nullify ();
-
- NS_TEST_ASSERT_MSG_EQ (target1.IsNull (), true, "Nullified Callback reports not IsNull()");
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// Make sure that various MakeCallback template functions compile and execute.
-// Doesn't check an results of the execution.
-// ===========================================================================
-class MakeCallbackTemplatesTestCase : public TestCase
-{
-public:
- MakeCallbackTemplatesTestCase ();
- virtual ~MakeCallbackTemplatesTestCase () {}
-
- void Target1 (void) {m_test1 = true;}
-
-private:
- virtual bool DoRun (void);
-
- bool m_test1;
-};
-
-void TestFZero (void) {}
-void TestFOne (int) {}
-void TestFTwo (int, int) {}
-void TestFThree (int, int, int) {}
-void TestFFour (int, int, int, int) {}
-void TestFFive (int, int, int, int, int) {}
-void TestFSix (int, int, int, int, int, int) {}
-
-void TestFROne (int &) {}
-void TestFRTwo (int &, int &) {}
-void TestFRThree (int &, int &, int &) {}
-void TestFRFour (int &, int &, int &, int &) {}
-void TestFRFive (int &, int &, int &, int &, int &) {}
-void TestFRSix (int &, int &, int &, int &, int &, int &) {}
-
-class CallbackTestParent
-{
-public:
- void PublicParent (void) {}
-protected:
- void ProtectedParent (void) {}
- static void StaticProtectedParent (void) {}
-private:
- void PrivateParent (void) {}
-};
-
-class CallbackTestClass : public CallbackTestParent
-{
-public:
- void TestZero (void) {}
- void TestOne (int) {}
- void TestTwo (int, int) {}
- void TestThree (int, int, int) {}
- void TestFour (int, int, int, int) {}
- void TestFive (int, int, int, int, int) {}
- void TestSix (int, int, int, int, int, int) {}
- void TestCZero (void) const {}
- void TestCOne (int) const {}
- void TestCTwo (int, int) const {}
- void TestCThree (int, int, int) const {}
- void TestCFour (int, int, int, int) const {}
- void TestCFive (int, int, int, int, int) const {}
- void TestCSix (int, int, int, int, int, int) const {}
-
- void CheckParentalRights (void)
- {
- MakeCallback (&CallbackTestParent::StaticProtectedParent);
- MakeCallback (&CallbackTestParent::PublicParent, this);
- MakeCallback (&CallbackTestClass::ProtectedParent, this);
- // as expected, fails.
- // MakeCallback (&CallbackTestParent::PrivateParent, this);
- // unexpected, but fails too. It does fumble me.
- // MakeCallback (&CallbackTestParent::ProtectedParent, this);
- }
-
-};
-
-MakeCallbackTemplatesTestCase::MakeCallbackTemplatesTestCase ()
- : TestCase ("Check various MakeCallback() template functions")
-{
-}
-
-bool
-MakeCallbackTemplatesTestCase::DoRun (void)
-{
- CallbackTestClass that;
-
- MakeCallback (&CallbackTestClass::TestZero, &that);
- MakeCallback (&CallbackTestClass::TestOne, &that);
- MakeCallback (&CallbackTestClass::TestTwo, &that);
- MakeCallback (&CallbackTestClass::TestThree, &that);
- MakeCallback (&CallbackTestClass::TestFour, &that);
- MakeCallback (&CallbackTestClass::TestFive, &that);
- MakeCallback (&CallbackTestClass::TestSix, &that);
-
- MakeCallback (&CallbackTestClass::TestCZero, &that);
- MakeCallback (&CallbackTestClass::TestCOne, &that);
- MakeCallback (&CallbackTestClass::TestCTwo, &that);
- MakeCallback (&CallbackTestClass::TestCThree, &that);
- MakeCallback (&CallbackTestClass::TestCFour, &that);
- MakeCallback (&CallbackTestClass::TestCFive, &that);
- MakeCallback (&CallbackTestClass::TestCSix, &that);
-
- MakeCallback (&TestFZero);
- MakeCallback (&TestFOne);
- MakeCallback (&TestFTwo);
- MakeCallback (&TestFThree);
- MakeCallback (&TestFFour);
- MakeCallback (&TestFFive);
- MakeCallback (&TestFSix);
-
- MakeCallback (&TestFROne);
- MakeCallback (&TestFRTwo);
- MakeCallback (&TestFRThree);
- MakeCallback (&TestFRFour);
- MakeCallback (&TestFRFive);
- MakeCallback (&TestFRSix);
-
- MakeBoundCallback (&TestFOne, 1);
- MakeBoundCallback (&TestFTwo, 1);
- MakeBoundCallback (&TestFThree, 1);
- MakeBoundCallback (&TestFFour, 1);
- MakeBoundCallback (&TestFFive, 1);
-
- MakeBoundCallback (&TestFROne, 1);
- MakeBoundCallback (&TestFRTwo, 1);
- MakeBoundCallback (&TestFRThree, 1);
- MakeBoundCallback (&TestFRFour, 1);
- MakeBoundCallback (&TestFRFive, 1);
-
- that.CheckParentalRights ();
-
- return GetErrorStatus ();
-}
-
-// ===========================================================================
-// The Test Suite that glues all of the Test Cases together.
-// ===========================================================================
-class CallbackTestSuite : public TestSuite
-{
-public:
- CallbackTestSuite ();
-};
-
-CallbackTestSuite::CallbackTestSuite ()
- : TestSuite ("callback", UNIT)
-{
- AddTestCase (new BasicCallbackTestCase);
- AddTestCase (new MakeCallbackTestCase);
- AddTestCase (new MakeBoundCallbackTestCase);
- AddTestCase (new NullifyCallbackTestCase);
- AddTestCase (new MakeCallbackTemplatesTestCase);
-}
-
-CallbackTestSuite CallbackTestSuite;
-
-} // namespace
--- a/modules/simulator/model/names-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,975 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "test.h"
-#include "names.h"
-
-using namespace ns3;
-
-// ===========================================================================
-// Cook up a couple of simple object class that we can use in the object
-// naming tests. They do nothing but be of the right type.
-// ===========================================================================
-class TestObject : public Object
-{
-public:
- static TypeId GetTypeId (void)
- {
- static TypeId tid = TypeId ("TestObject")
- .SetParent (Object::GetTypeId ())
- .HideFromDocumentation ()
- .AddConstructor<TestObject> ();
- return tid;
- }
- TestObject () {}
- virtual void Dispose (void) {}
-};
-
-class AlternateTestObject : public Object
-{
-public:
- static TypeId GetTypeId (void)
- {
- static TypeId tid = TypeId ("AlternateTestObject")
- .SetParent (Object::GetTypeId ())
- .HideFromDocumentation ()
- .AddConstructor<AlternateTestObject> ();
- return tid;
- }
- AlternateTestObject () {}
- virtual void Dispose (void) {}
-};
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can do its most basic
-// job and add associations between Objects using the lowest level add
-// function, which is:
-//
-// Add (Ptr<Object> context, std::string name, Ptr<Object> object);
-//
-// All other add functions will just translate into this form, so this is the
-// most basic Add functionality.
-// ===========================================================================
-class BasicAddTestCase : public TestCase
-{
-public:
- BasicAddTestCase ();
- virtual ~BasicAddTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-BasicAddTestCase::BasicAddTestCase ()
- : TestCase ("Check low level Names::Add and Names::FindName functionality")
-{
-}
-
-BasicAddTestCase::~BasicAddTestCase ()
-{
-}
-
-void
-BasicAddTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-BasicAddTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add (Ptr<Object> (0, false), "Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add (Ptr<Object> (0, false), "Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add (objectOne, "Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add (objectTwo, "Child", childOfObjectTwo);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
-
- found = Names::FindName (objectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- found = Names::FindName (childOfObjectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can correctly use a
-// string context in the most basic ways
-//
-// Add (std::string context, std::string name, Ptr<Object> object);
-//
-// High level path-based functions will translate into this form, so this is
-// the second most basic Add functionality.
-// ===========================================================================
-class StringContextAddTestCase : public TestCase
-{
-public:
- StringContextAddTestCase ();
- virtual ~StringContextAddTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-StringContextAddTestCase::StringContextAddTestCase ()
- : TestCase ("Check string context Names::Add and Names::FindName functionality")
-
-{
-}
-
-StringContextAddTestCase::~StringContextAddTestCase ()
-{
-}
-
-void
-StringContextAddTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-StringContextAddTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("/Names", "Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names", "Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name One", "Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names/Name Two", "Child", childOfObjectTwo);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
-
- found = Names::FindName (objectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- found = Names::FindName (childOfObjectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can correctly use a
-// fully qualified path to add assocations
-//
-// Add (std::string name, Ptr<Object> object);
-// ===========================================================================
-class FullyQualifiedAddTestCase : public TestCase
-{
-public:
- FullyQualifiedAddTestCase ();
- virtual ~FullyQualifiedAddTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-FullyQualifiedAddTestCase::FullyQualifiedAddTestCase ()
- : TestCase ("Check fully qualified path Names::Add and Names::FindName functionality")
-
-{
-}
-
-FullyQualifiedAddTestCase::~FullyQualifiedAddTestCase ()
-{
-}
-
-void
-FullyQualifiedAddTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-FullyQualifiedAddTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names/Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
-
- found = Names::FindName (objectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- found = Names::FindName (childOfObjectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can correctly use a
-// relative path to add assocations. This functionality is provided as a
-// convenience so clients don't always have to provide the name service
-// namespace name in all of their strings.
-//
-//
-// Add (std::string name, Ptr<Object> object);
-// ===========================================================================
-class RelativeAddTestCase : public TestCase
-{
-public:
- RelativeAddTestCase ();
- virtual ~RelativeAddTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-RelativeAddTestCase::RelativeAddTestCase ()
- : TestCase ("Check relative path Names::Add and Names::FindName functionality")
-
-{
-}
-
-RelativeAddTestCase::~RelativeAddTestCase ()
-{
-}
-
-void
-RelativeAddTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-RelativeAddTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two/Child", childOfObjectTwo);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
-
- found = Names::FindName (objectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- found = Names::FindName (childOfObjectTwo);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can rename objects in
-// its most basic way, which is
-//
-// Rename (Ptr<Object> context, std::string oldname, std::string newname);
-//
-// All other rename functions will just translate into this form, so this is the
-// most basic rename functionality.
-// ===========================================================================
-class BasicRenameTestCase : public TestCase
-{
-public:
- BasicRenameTestCase ();
- virtual ~BasicRenameTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-BasicRenameTestCase::BasicRenameTestCase ()
- : TestCase ("Check low level Names::Rename functionality")
-{
-}
-
-BasicRenameTestCase::~BasicRenameTestCase ()
-{
-}
-
-void
-BasicRenameTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-BasicRenameTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add (Ptr<Object> (0, false), "Name", objectOne);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add (objectOne, "Child", childOfObjectOne);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
-
- Names::Rename (Ptr<Object> (0, false), "Name", "New Name");
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- Names::Rename (objectOne, "Child", "New Child");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can rename objects
-// using a string context
-//
-// Rename (std::string context, std::string oldname, std::string newname);
-// ===========================================================================
-class StringContextRenameTestCase : public TestCase
-{
-public:
- StringContextRenameTestCase ();
- virtual ~StringContextRenameTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-StringContextRenameTestCase::StringContextRenameTestCase ()
- : TestCase ("Check string context-based Names::Rename functionality")
-{
-}
-
-StringContextRenameTestCase::~StringContextRenameTestCase ()
-{
-}
-
-void
-StringContextRenameTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-StringContextRenameTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("/Names", "Name", objectOne);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name", "Child", childOfObjectOne);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
-
- Names::Rename ("/Names", "Name", "New Name");
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- Names::Rename ("/Names/New Name", "Child", "New Child");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can rename objects
-// using a fully qualified path name
-//
-// Rename (std::string oldpath, std::string newname);
-// ===========================================================================
-class FullyQualifiedRenameTestCase : public TestCase
-{
-public:
- FullyQualifiedRenameTestCase ();
- virtual ~FullyQualifiedRenameTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-FullyQualifiedRenameTestCase::FullyQualifiedRenameTestCase ()
- : TestCase ("Check fully qualified path Names::Rename functionality")
-{
-}
-
-FullyQualifiedRenameTestCase::~FullyQualifiedRenameTestCase ()
-{
-}
-
-void
-FullyQualifiedRenameTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-FullyQualifiedRenameTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name", objectOne);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name/Child", childOfObjectOne);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
-
- Names::Rename ("/Names/Name", "New Name");
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- Names::Rename ("/Names/New Name/Child", "New Child");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can rename objects
-// using a relaltive path name
-//
-// Rename (std::string oldpath, std::string newname);
-// ===========================================================================
-class RelativeRenameTestCase : public TestCase
-{
-public:
- RelativeRenameTestCase ();
- virtual ~RelativeRenameTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-RelativeRenameTestCase::RelativeRenameTestCase ()
- : TestCase ("Check relative path Names::Rename functionality")
-{
-}
-
-RelativeRenameTestCase::~RelativeRenameTestCase ()
-{
-}
-
-void
-RelativeRenameTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-RelativeRenameTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name", objectOne);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("Name/Child", childOfObjectOne);
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
-
- Names::Rename ("Name", "New Name");
-
- found = Names::FindName (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
-
- Names::Rename ("New Name/Child", "New Child");
-
- found = Names::FindName (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can look up an object
-// and return its fully qualified path name
-//
-// FindPath (Ptr<Object> object);
-// ===========================================================================
-class FindPathTestCase : public TestCase
-{
-public:
- FindPathTestCase ();
- virtual ~FindPathTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-FindPathTestCase::FindPathTestCase ()
- : TestCase ("Check Names::FindPath functionality")
-{
-}
-
-FindPathTestCase::~FindPathTestCase ()
-{
-}
-
-void
-FindPathTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-FindPathTestCase::DoRun (void)
-{
- std::string found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name", objectOne);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name/Child", childOfObjectOne);
-
- found = Names::FindPath (objectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name", "Could not Names::Add and Names::FindPath an Object");
-
- found = Names::FindPath (childOfObjectOne);
- NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name/Child", "Could not Names::Add and Names::FindPath a child Object");
-
- Ptr<TestObject> objectNotThere = CreateObject<TestObject> ();
- found = Names::FindPath (objectNotThere);
- NS_TEST_ASSERT_MSG_EQ (found, "", "Unexpectedly found a non-existent Object");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can find Objects using
-// the lowest level find function, which is:
-//
-// Find (Ptr<Object> context, std::string name);
-// ===========================================================================
-class BasicFindTestCase : public TestCase
-{
-public:
- BasicFindTestCase ();
- virtual ~BasicFindTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-BasicFindTestCase::BasicFindTestCase ()
- : TestCase ("Check low level Names::Find functionality")
-{
-}
-
-BasicFindTestCase::~BasicFindTestCase ()
-{
-}
-
-void
-BasicFindTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-BasicFindTestCase::DoRun (void)
-{
- Ptr<TestObject> found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two/Child", childOfObjectTwo);
-
- found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name One");
- NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via object context");
-
- found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name Two");
- NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via object context");
-
- found = Names::Find<TestObject> (objectOne, "Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via object context");
-
- found = Names::Find<TestObject> (objectTwo, "Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via object context");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can find Objects using
-// a string context-based find function, which is:
-//
-// Find (std::string context, std::string name);
-// ===========================================================================
-class StringContextFindTestCase : public TestCase
-{
-public:
- StringContextFindTestCase ();
- virtual ~StringContextFindTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-StringContextFindTestCase::StringContextFindTestCase ()
- : TestCase ("Check string context-based Names::Find functionality")
-{
-}
-
-StringContextFindTestCase::~StringContextFindTestCase ()
-{
-}
-
-void
-StringContextFindTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-StringContextFindTestCase::DoRun (void)
-{
- Ptr<TestObject> found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two/Child", childOfObjectTwo);
-
- found = Names::Find<TestObject> ("/Names", "Name One");
- NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
-
- found = Names::Find<TestObject> ("/Names", "Name Two");
- NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
-
- found = Names::Find<TestObject> ("/Names/Name One", "Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
-
- found = Names::Find<TestObject> ("/Names/Name Two", "Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can find Objects using
-// a fully qualified path name-based find function, which is:
-//
-// Find (std::string name);
-// ===========================================================================
-class FullyQualifiedFindTestCase : public TestCase
-{
-public:
- FullyQualifiedFindTestCase ();
- virtual ~FullyQualifiedFindTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-FullyQualifiedFindTestCase::FullyQualifiedFindTestCase ()
- : TestCase ("Check fully qualified path Names::Find functionality")
-{
-}
-
-FullyQualifiedFindTestCase::~FullyQualifiedFindTestCase ()
-{
-}
-
-void
-FullyQualifiedFindTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-FullyQualifiedFindTestCase::DoRun (void)
-{
- Ptr<TestObject> found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names/Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("/Names/Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
-
- found = Names::Find<TestObject> ("/Names/Name One");
- NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
-
- found = Names::Find<TestObject> ("/Names/Name Two");
- NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
-
- found = Names::Find<TestObject> ("/Names/Name One/Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
-
- found = Names::Find<TestObject> ("/Names/Name Two/Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can find Objects using
-// a relative path name-based find function, which is:
-//
-// Find (std::string name);
-// ===========================================================================
-class RelativeFindTestCase : public TestCase
-{
-public:
- RelativeFindTestCase ();
- virtual ~RelativeFindTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-RelativeFindTestCase::RelativeFindTestCase ()
- : TestCase ("Check relative path Names::Find functionality")
-{
-}
-
-RelativeFindTestCase::~RelativeFindTestCase ()
-{
-}
-
-void
-RelativeFindTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-RelativeFindTestCase::DoRun (void)
-{
- Ptr<TestObject> found;
-
- Ptr<TestObject> objectOne = CreateObject<TestObject> ();
- Names::Add ("Name One", objectOne);
-
- Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two", objectTwo);
-
- Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
- Names::Add ("Name One/Child", childOfObjectOne);
-
- Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
- Names::Add ("Name Two/Child", childOfObjectTwo);
-
- found = Names::Find<TestObject> ("Name One");
- NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
-
- found = Names::Find<TestObject> ("Name Two");
- NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
-
- found = Names::Find<TestObject> ("Name One/Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
-
- found = Names::Find<TestObject> ("Name Two/Child");
- NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
-
- return false;
-}
-
-// ===========================================================================
-// Test case to make sure that the Object Name Service can find Objects using
-// a second type.
-// ===========================================================================
-class AlternateFindTestCase : public TestCase
-{
-public:
- AlternateFindTestCase ();
- virtual ~AlternateFindTestCase ();
-
-private:
- virtual bool DoRun (void);
- virtual void DoTeardown (void);
-};
-
-AlternateFindTestCase::AlternateFindTestCase ()
- : TestCase ("Check GetObject operation in Names::Find")
-{
-}
-
-AlternateFindTestCase::~AlternateFindTestCase ()
-{
-}
-
-void
-AlternateFindTestCase::DoTeardown (void)
-{
- Names::Clear ();
-}
-
-bool
-AlternateFindTestCase::DoRun (void)
-{
- Ptr<TestObject> testObject = CreateObject<TestObject> ();
- Names::Add ("Test Object", testObject);
-
- Ptr<AlternateTestObject> alternateTestObject = CreateObject<AlternateTestObject> ();
- Names::Add ("Alternate Test Object", alternateTestObject);
-
- Ptr<TestObject> foundTestObject;
- Ptr<AlternateTestObject> foundAlternateTestObject;
-
- foundTestObject = Names::Find<TestObject> ("Test Object");
- NS_TEST_ASSERT_MSG_EQ (foundTestObject, testObject,
- "Could not find a previously named TestObject via GetObject");
-
- foundAlternateTestObject = Names::Find<AlternateTestObject> ("Alternate Test Object");
- NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, alternateTestObject,
- "Could not find a previously named AlternateTestObject via GetObject");
-
-
- foundAlternateTestObject = Names::Find<AlternateTestObject> ("Test Object");
- NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, 0,
- "Unexpectedly able to GetObject<AlternateTestObject> on a TestObject");
-
- foundTestObject = Names::Find<TestObject> ("Alternate Test Object");
- NS_TEST_ASSERT_MSG_EQ (foundTestObject, 0,
- "Unexpectedly able to GetObject<TestObject> on an AlternateTestObject");
-
- return false;
-}
-
-class NamesTestSuite : public TestSuite
-{
-public:
- NamesTestSuite ();
-};
-
-NamesTestSuite::NamesTestSuite ()
- : TestSuite ("object-name-service", UNIT)
-{
- AddTestCase (new BasicAddTestCase);
- AddTestCase (new StringContextAddTestCase);
- AddTestCase (new FullyQualifiedAddTestCase);
- AddTestCase (new RelativeAddTestCase);
- AddTestCase (new BasicRenameTestCase);
- AddTestCase (new StringContextRenameTestCase);
- AddTestCase (new FullyQualifiedRenameTestCase);
- AddTestCase (new RelativeRenameTestCase);
- AddTestCase (new FindPathTestCase);
- AddTestCase (new BasicFindTestCase);
- AddTestCase (new StringContextFindTestCase);
- AddTestCase (new FullyQualifiedFindTestCase);
- AddTestCase (new RelativeFindTestCase);
- AddTestCase (new AlternateFindTestCase);
-}
-
-NamesTestSuite namesTestSuite;
--- a/modules/simulator/model/ptr-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,274 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2005,2006 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "test.h"
-#include "ptr.h"
-
-namespace ns3 {
-
-class PtrTestCase;
-
-class Base
-{
-public:
- Base ();
- virtual ~Base ();
- void Ref (void) const;
- void Unref (void) const;
-private:
- mutable uint32_t m_count;
-};
-
-class NoCount : public Base
-{
-public:
- NoCount (PtrTestCase *test);
- ~NoCount ();
- void Nothing (void) const;
-private:
- PtrTestCase *m_test;
-};
-
-
-class PtrTestCase : public TestCase
-{
-public:
- PtrTestCase ();
- void DestroyNotify (void);
-private:
- virtual bool DoRun (void);
- Ptr<NoCount> CallTest (Ptr<NoCount> p);
- Ptr<NoCount> const CallTestConst (Ptr<NoCount> const p);
- uint32_t m_nDestroyed;
-};
-
-
-Base::Base ()
- : m_count (1)
-{}
-Base::~Base ()
-{}
-void
-Base::Ref (void) const
-{
- m_count++;
-}
-void
-Base::Unref (void) const
-{
- m_count--;
- if (m_count == 0)
- {
- delete this;
- }
-}
-
-NoCount::NoCount (PtrTestCase *test)
- : m_test (test)
-{}
-NoCount::~NoCount ()
-{
- m_test->DestroyNotify ();
-}
-void
-NoCount::Nothing () const
-{}
-
-
-
-PtrTestCase::PtrTestCase (void)
- : TestCase ("Sanity checking of Ptr<>")
-{}
-void
-PtrTestCase::DestroyNotify (void)
-{
- m_nDestroyed++;
-}
-Ptr<NoCount>
-PtrTestCase::CallTest (Ptr<NoCount> p)
-{
- return p;
-}
-
-Ptr<NoCount> const
-PtrTestCase::CallTestConst (Ptr<NoCount> const p)
-{
- return p;
-}
-
-
-bool
-PtrTestCase::DoRun (void)
-{
- m_nDestroyed = false;
- {
- Ptr<NoCount> p = Create<NoCount> (this);
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p;
- p = Create<NoCount> (this);
- p = p;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- p1 = Create<NoCount> (this);
- Ptr<NoCount> p2 = p1;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- p1 = Create<NoCount> (this);
- Ptr<NoCount> p2;
- p2 = p1;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- p1 = Create<NoCount> (this);
- Ptr<NoCount> p2 = Create<NoCount> (this);
- p2 = p1;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- p1 = Create<NoCount> (this);
- Ptr<NoCount> p2;
- p2 = Create<NoCount> (this);
- p2 = p1;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- p1 = Create<NoCount> (this);
- p1 = Create<NoCount> (this);
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- {
- Ptr<NoCount> p2;
- p1 = Create<NoCount> (this);
- p2 = Create<NoCount> (this);
- p2 = p1;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p1;
- {
- Ptr<NoCount> p2;
- p1 = Create<NoCount> (this);
- p2 = Create<NoCount> (this);
- p2 = CallTest (p1);
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
-
- {
- Ptr<NoCount> p1;
- Ptr<NoCount> const p2 = CallTest (p1);
- Ptr<NoCount> const p3 = CallTestConst (p1);
- Ptr<NoCount> p4 = CallTestConst (p1);
- Ptr<NoCount const> p5 = p4;
- //p4 = p5; You cannot make a const pointer be a non-const pointer.
- // but if you use ConstCast, you can.
- p4 = ConstCast<NoCount> (p5);
- p5 = p1;
- Ptr<NoCount> p;
- if (p == 0)
- {}
- if (p != 0)
- {}
- if (0 == p)
- {}
- if (0 != p)
- {}
- if (p)
- {}
- if (!p)
- {}
- }
-
- m_nDestroyed = 0;
- {
- NoCount *raw;
- {
- Ptr<NoCount> p = Create<NoCount> (this);
- {
- Ptr<NoCount const> p1 = p;
- }
- raw = GetPointer (p);
- p = 0;
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 0, "XXX");
- delete raw;
- }
-
- m_nDestroyed = 0;
- {
- Ptr<NoCount> p = Create<NoCount> (this);
- const NoCount *v1 = PeekPointer (p);
- NoCount *v2 = PeekPointer (p);
- v1->Nothing ();
- v2->Nothing ();
- }
- NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
-
- {
- Ptr<Base> p0 = Create<NoCount> (this);
- Ptr<NoCount> p1 = Create<NoCount> (this);
- NS_TEST_EXPECT_MSG_EQ ((p0 == p1), false, "operator == failed");
- NS_TEST_EXPECT_MSG_EQ ((p0 != p1), true, "operator != failed");
- }
-
- return false;
-}
-
-static class PtrTestSuite : public TestSuite
-{
-public:
- PtrTestSuite ()
- : TestSuite ("ptr", UNIT)
- {
- AddTestCase (new PtrTestCase ());
- }
-} g_ptrTestSuite;
-
-} // namespace ns3
--- a/modules/simulator/model/rng-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,434 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-
-#include <math.h>
-#include <gsl/gsl_cdf.h>
-#include <gsl/gsl_histogram.h>
-#include <time.h>
-#include <fstream>
-
-#include "test.h"
-#include "random-variable.h"
-
-using namespace ns3;
-
-void
-FillHistoRangeUniformly (double *array, uint32_t n, double start, double end)
-{
- double increment = (end - start) / (n - 1.);
- double d = start;
-
- for (uint32_t i = 0; i < n; ++i)
- {
- array[i] = d;
- d += increment;
- }
-}
-
-// ===========================================================================
-// Test case for uniform distribution random number generator
-// ===========================================================================
-class RngUniformTestCase : public TestCase
-{
-public:
- static const uint32_t N_RUNS = 5;
- static const uint32_t N_BINS = 50;
- static const uint32_t N_MEASUREMENTS = 1000000;
-
- RngUniformTestCase ();
- virtual ~RngUniformTestCase ();
-
- double ChiSquaredTest (UniformVariable &u);
-
-private:
- virtual bool DoRun (void);
-};
-
-RngUniformTestCase::RngUniformTestCase ()
- : TestCase ("Uniform Random Number Generator")
-{
-}
-
-RngUniformTestCase::~RngUniformTestCase ()
-{
-}
-
-double
-RngUniformTestCase::ChiSquaredTest (UniformVariable &u)
-{
- gsl_histogram * h = gsl_histogram_alloc (N_BINS);
- gsl_histogram_set_ranges_uniform (h, 0., 1.);
-
- for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
- {
- gsl_histogram_increment (h, u.GetValue ());
- }
-
- double tmp[N_BINS];
-
- double expected = ((double)N_MEASUREMENTS / (double)N_BINS);
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- tmp[i] = gsl_histogram_get (h, i);
- tmp[i] -= expected;
- tmp[i] *= tmp[i];
- tmp[i] /= expected;
- }
-
- gsl_histogram_free (h);
-
- double chiSquared = 0;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- chiSquared += tmp[i];
- }
-
- return chiSquared;
-}
-
-bool
-RngUniformTestCase::DoRun (void)
-{
- SeedManager::SetSeed (time (0));
-
- double sum = 0.;
- double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
-
- for (uint32_t i = 0; i < N_RUNS; ++i)
- {
- UniformVariable u;
- double result = ChiSquaredTest (u);
- sum += result;
- }
-
- sum /= (double)N_RUNS;
-
- NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
- return false;
-}
-
-// ===========================================================================
-// Test case for normal distribution random number generator
-// ===========================================================================
-class RngNormalTestCase : public TestCase
-{
-public:
- static const uint32_t N_RUNS = 5;
- static const uint32_t N_BINS = 50;
- static const uint32_t N_MEASUREMENTS = 1000000;
-
- RngNormalTestCase ();
- virtual ~RngNormalTestCase ();
-
- double ChiSquaredTest (NormalVariable &n);
-
-private:
- virtual bool DoRun (void);
-};
-
-RngNormalTestCase::RngNormalTestCase ()
- : TestCase ("Normal Random Number Generator")
-{
-}
-
-RngNormalTestCase::~RngNormalTestCase ()
-{
-}
-
-double
-RngNormalTestCase::ChiSquaredTest (NormalVariable &n)
-{
- gsl_histogram * h = gsl_histogram_alloc (N_BINS);
-
- double range[N_BINS + 1];
- FillHistoRangeUniformly (range, N_BINS + 1, -4., 4.);
- range[0] = -std::numeric_limits<double>::max ();
- range[N_BINS] = std::numeric_limits<double>::max ();
-
- gsl_histogram_set_ranges (h, range, N_BINS + 1);
-
- double expected[N_BINS];
-
- double sigma = 1.;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- expected[i] = gsl_cdf_gaussian_P (range[i + 1], sigma) - gsl_cdf_gaussian_P (range[i], sigma);
- expected[i] *= N_MEASUREMENTS;
- }
-
- for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
- {
- gsl_histogram_increment (h, n.GetValue ());
- }
-
- double tmp[N_BINS];
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- tmp[i] = gsl_histogram_get (h, i);
- tmp[i] -= expected[i];
- tmp[i] *= tmp[i];
- tmp[i] /= expected[i];
- }
-
- gsl_histogram_free (h);
-
- double chiSquared = 0;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- chiSquared += tmp[i];
- }
-
- return chiSquared;
-}
-
-bool
-RngNormalTestCase::DoRun (void)
-{
- SeedManager::SetSeed (time (0));
-
- double sum = 0.;
- double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
-
- for (uint32_t i = 0; i < N_RUNS; ++i)
- {
- NormalVariable n;
- double result = ChiSquaredTest (n);
- sum += result;
- }
-
- sum /= (double)N_RUNS;
-
- NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
- return false;
-}
-
-// ===========================================================================
-// Test case for exponential distribution random number generator
-// ===========================================================================
-class RngExponentialTestCase : public TestCase
-{
-public:
- static const uint32_t N_RUNS = 5;
- static const uint32_t N_BINS = 50;
- static const uint32_t N_MEASUREMENTS = 1000000;
-
- RngExponentialTestCase ();
- virtual ~RngExponentialTestCase ();
-
- double ChiSquaredTest (ExponentialVariable &n);
-
-private:
- virtual bool DoRun (void);
-};
-
-RngExponentialTestCase::RngExponentialTestCase ()
- : TestCase ("Exponential Random Number Generator")
-{
-}
-
-RngExponentialTestCase::~RngExponentialTestCase ()
-{
-}
-
-double
-RngExponentialTestCase::ChiSquaredTest (ExponentialVariable &e)
-{
- gsl_histogram * h = gsl_histogram_alloc (N_BINS);
-
- double range[N_BINS + 1];
- FillHistoRangeUniformly (range, N_BINS + 1, 0., 10.);
- range[N_BINS] = std::numeric_limits<double>::max ();
-
- gsl_histogram_set_ranges (h, range, N_BINS + 1);
-
- double expected[N_BINS];
-
- double mu = 1.;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- expected[i] = gsl_cdf_exponential_P (range[i + 1], mu) - gsl_cdf_exponential_P (range[i], mu);
- expected[i] *= N_MEASUREMENTS;
- }
-
- for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
- {
- gsl_histogram_increment (h, e.GetValue ());
- }
-
- double tmp[N_BINS];
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- tmp[i] = gsl_histogram_get (h, i);
- tmp[i] -= expected[i];
- tmp[i] *= tmp[i];
- tmp[i] /= expected[i];
- }
-
- gsl_histogram_free (h);
-
- double chiSquared = 0;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- chiSquared += tmp[i];
- }
-
- return chiSquared;
-}
-
-bool
-RngExponentialTestCase::DoRun (void)
-{
- SeedManager::SetSeed (time (0));
-
- double sum = 0.;
- double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
-
- for (uint32_t i = 0; i < N_RUNS; ++i)
- {
- ExponentialVariable e;
- double result = ChiSquaredTest (e);
- sum += result;
- }
-
- sum /= (double)N_RUNS;
-
- NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
- return false;
-}
-
-// ===========================================================================
-// Test case for pareto distribution random number generator
-// ===========================================================================
-class RngParetoTestCase : public TestCase
-{
-public:
- static const uint32_t N_RUNS = 5;
- static const uint32_t N_BINS = 50;
- static const uint32_t N_MEASUREMENTS = 1000000;
-
- RngParetoTestCase ();
- virtual ~RngParetoTestCase ();
-
- double ChiSquaredTest (ParetoVariable &p);
-
-private:
- virtual bool DoRun (void);
-};
-
-RngParetoTestCase::RngParetoTestCase ()
- : TestCase ("Pareto Random Number Generator")
-{
-}
-
-RngParetoTestCase::~RngParetoTestCase ()
-{
-}
-
-double
-RngParetoTestCase::ChiSquaredTest (ParetoVariable &p)
-{
- gsl_histogram * h = gsl_histogram_alloc (N_BINS);
-
- double range[N_BINS + 1];
- FillHistoRangeUniformly (range, N_BINS + 1, 1., 10.);
- range[N_BINS] = std::numeric_limits<double>::max ();
-
- gsl_histogram_set_ranges (h, range, N_BINS + 1);
-
- double expected[N_BINS];
-
- double a = 1.5;
- double b = 0.33333333;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- expected[i] = gsl_cdf_pareto_P (range[i + 1], a, b) - gsl_cdf_pareto_P (range[i], a, b);
- expected[i] *= N_MEASUREMENTS;
- }
-
- for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
- {
- gsl_histogram_increment (h, p.GetValue ());
- }
-
- double tmp[N_BINS];
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- tmp[i] = gsl_histogram_get (h, i);
- tmp[i] -= expected[i];
- tmp[i] *= tmp[i];
- tmp[i] /= expected[i];
- }
-
- gsl_histogram_free (h);
-
- double chiSquared = 0;
-
- for (uint32_t i = 0; i < N_BINS; ++i)
- {
- chiSquared += tmp[i];
- }
-
- return chiSquared;
-}
-
-bool
-RngParetoTestCase::DoRun (void)
-{
- SeedManager::SetSeed (time (0));
-
- double sum = 0.;
- double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
-
- for (uint32_t i = 0; i < N_RUNS; ++i)
- {
- ParetoVariable e;
- double result = ChiSquaredTest (e);
- sum += result;
- }
-
- sum /= (double)N_RUNS;
-
- NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
- return false;
-}
-
-class RngTestSuite : public TestSuite
-{
-public:
- RngTestSuite ();
-};
-
-RngTestSuite::RngTestSuite ()
- : TestSuite ("random-number-generators", UNIT)
-{
- AddTestCase (new RngUniformTestCase);
- AddTestCase (new RngNormalTestCase);
- AddTestCase (new RngExponentialTestCase);
- AddTestCase (new RngParetoTestCase);
-}
-
-RngTestSuite rngTestSuite;
--- a/modules/simulator/model/traced-callback-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "test.h"
-#include "traced-callback.h"
-
-using namespace ns3;
-
-class BasicTracedCallbackTestCase : public TestCase
-{
-public:
- BasicTracedCallbackTestCase ();
- virtual ~BasicTracedCallbackTestCase () {}
-
-private:
- virtual bool DoRun (void);
-
- void CbOne (uint8_t a, double b);
- void CbTwo (uint8_t a, double b);
-
- bool m_one;
- bool m_two;
-};
-
-BasicTracedCallbackTestCase::BasicTracedCallbackTestCase ()
- : TestCase ("Check basic TracedCallback operation")
-{
-}
-
-void
-BasicTracedCallbackTestCase::CbOne (uint8_t a, double b)
-{
- m_one = true;
-}
-
-void
-BasicTracedCallbackTestCase::CbTwo (uint8_t a, double b)
-{
- m_two = true;
-}
-
-bool
-BasicTracedCallbackTestCase::DoRun (void)
-{
- //
- // Create a traced callback and connect it up to our target methods. All that
- // these methods do is to set corresponding member variables m_one and m_two.
- //
- TracedCallback<uint8_t, double> trace;
-
- //
- // Connect both callbacks to their respective test methods. If we hit the
- // trace, both callbacks should be called and the two variables should be set
- // to true.
- //
- trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
- trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
- NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
-
- //
- // If we now disconnect callback one then only callback two should be called.
- //
- trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
- NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
-
- //
- // If we now disconnect callback two then neither callback should be called.
- //
- trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
- NS_TEST_ASSERT_MSG_EQ (m_two, false, "Callback CbTwo unexpectedly called");
-
- //
- // If we connect them back up, then both callbacks should be called.
- //
- trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
- trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
- m_one = false;
- m_two = false;
- trace (1, 2);
- NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
- NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
-
- return GetErrorStatus ();
-}
-
-class TracedCallbackTestSuite : public TestSuite
-{
-public:
- TracedCallbackTestSuite ();
-};
-
-TracedCallbackTestSuite::TracedCallbackTestSuite ()
- : TestSuite ("traced-callback", UNIT)
-{
- AddTestCase (new BasicTracedCallbackTestCase);
-}
-
-TracedCallbackTestSuite tracedCallbackTestSuite;
--- a/modules/simulator/model/type-traits-test-suite.cc Thu Dec 16 09:55:26 2010 -0800
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2009 University of Washington
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-#include "type-traits.h"
-#include "test.h"
-
-namespace ns3 {
-
-class TypeTraitsTestCase : public TestCase
-{
-public:
- TypeTraitsTestCase ();
- virtual ~TypeTraitsTestCase () {}
-
-private:
- virtual bool DoRun (void);
-};
-
-TypeTraitsTestCase::TypeTraitsTestCase (void)
- : TestCase ("Check type traits")
-{
-}
-
-bool
-TypeTraitsTestCase::DoRun (void)
-{
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void)>::IsPointerToMember, 1, "Check");
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void) const>::IsPointerToMember, 1, "Check");
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int)>::IsPointerToMember, 1, "Check");
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int) const>::IsPointerToMember, 1, "Check");
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void) const>::PointerToMemberTraits::nArgs, 0, "Check");
- NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int) const>::PointerToMemberTraits::nArgs, 1, "Check");
-
- return GetErrorStatus ();
-}
-
-class TypeTraitsTestSuite : public TestSuite
-{
-public:
- TypeTraitsTestSuite ();
-};
-
-TypeTraitsTestSuite::TypeTraitsTestSuite ()
- : TestSuite ("type-traits", UNIT)
-{
- AddTestCase (new TypeTraitsTestCase);
-}
-
-TypeTraitsTestSuite typeTraitsTestSuite;
-
-} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/attribute-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,1195 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "model/test.h"
+#include "model/object.h"
+#include "model/boolean.h"
+#include "model/integer.h"
+#include "model/uinteger.h"
+#include "model/enum.h"
+#include "model/string.h"
+#include "model/random-variable.h"
+#include "model/double.h"
+#include "model/object-vector.h"
+#include "model/traced-value.h"
+#include "model/callback.h"
+#include "model/trace-source-accessor.h"
+#include "model/pointer.h"
+
+namespace ns3 {
+
+class ValueClassTest
+{
+public:
+ ValueClassTest () {}
+private:
+ int m_v;
+};
+bool operator != (const ValueClassTest &a, const ValueClassTest &b)
+{
+ return true;
+}
+std::ostream & operator << (std::ostream &os, ValueClassTest v)
+{
+ return os;
+}
+std::istream & operator >> (std::istream &is, ValueClassTest &v)
+{
+ return is;
+}
+ATTRIBUTE_HELPER_HEADER (ValueClassTest);
+ATTRIBUTE_HELPER_CPP (ValueClassTest);
+
+class Derived : public Object
+{
+public:
+ static TypeId GetTypeId (void) {
+ static TypeId tid = TypeId ("ns3::Derived")
+ .SetParent<Object> ()
+ ;
+ return tid;
+ }
+};
+
+class AttributeObjectTest : public Object
+{
+public:
+ enum Test_e {
+ TEST_A,
+ TEST_B,
+ TEST_C
+ };
+ static TypeId GetTypeId (void) {
+ static TypeId tid = TypeId ("ns3::AttributeObjectTest")
+ .SetParent<Object> ()
+ .HideFromDocumentation ()
+ .AddAttribute ("TestBoolName", "help text",
+ BooleanValue (false),
+ MakeBooleanAccessor (&AttributeObjectTest::m_boolTest),
+ MakeBooleanChecker ())
+ .AddAttribute ("TestBoolA", "help text",
+ BooleanValue (false),
+ MakeBooleanAccessor (&AttributeObjectTest::DoSetTestB,
+ &AttributeObjectTest::DoGetTestB),
+ MakeBooleanChecker ())
+ .AddAttribute ("TestInt16", "help text",
+ IntegerValue (-2),
+ MakeIntegerAccessor (&AttributeObjectTest::m_int16),
+ MakeIntegerChecker<int16_t> ())
+ .AddAttribute ("TestInt16WithBounds", "help text",
+ IntegerValue (-2),
+ MakeIntegerAccessor (&AttributeObjectTest::m_int16WithBounds),
+ MakeIntegerChecker<int16_t> (-5, 10))
+ .AddAttribute ("TestInt16SetGet", "help text",
+ IntegerValue (6),
+ MakeIntegerAccessor (&AttributeObjectTest::DoSetInt16,
+ &AttributeObjectTest::DoGetInt16),
+ MakeIntegerChecker<int16_t> ())
+ .AddAttribute ("TestUint8", "help text",
+ UintegerValue (1),
+ MakeUintegerAccessor (&AttributeObjectTest::m_uint8),
+ MakeUintegerChecker<uint8_t> ())
+ .AddAttribute ("TestEnum", "help text",
+ EnumValue (TEST_A),
+ MakeEnumAccessor (&AttributeObjectTest::m_enum),
+ MakeEnumChecker (TEST_A, "TestA",
+ TEST_B, "TestB",
+ TEST_C, "TestC"))
+ .AddAttribute ("TestRandom", "help text",
+ RandomVariableValue (ConstantVariable (1.0)),
+ MakeRandomVariableAccessor (&AttributeObjectTest::m_random),
+ MakeRandomVariableChecker ())
+ .AddAttribute ("TestFloat", "help text",
+ DoubleValue (-1.1),
+ MakeDoubleAccessor (&AttributeObjectTest::m_float),
+ MakeDoubleChecker<float> ())
+ .AddAttribute ("TestVector1", "help text",
+ ObjectVectorValue (),
+ MakeObjectVectorAccessor (&AttributeObjectTest::m_vector1),
+ MakeObjectVectorChecker<Derived> ())
+ .AddAttribute ("TestVector2", "help text",
+ ObjectVectorValue (),
+ MakeObjectVectorAccessor (&AttributeObjectTest::DoGetVectorN,
+ &AttributeObjectTest::DoGetVector),
+ MakeObjectVectorChecker<Derived> ())
+ .AddAttribute ("IntegerTraceSource1", "help text",
+ IntegerValue (-2),
+ MakeIntegerAccessor (&AttributeObjectTest::m_intSrc1),
+ MakeIntegerChecker<int8_t> ())
+ .AddAttribute ("IntegerTraceSource2", "help text",
+ IntegerValue (-2),
+ MakeIntegerAccessor (&AttributeObjectTest::DoSetIntSrc,
+ &AttributeObjectTest::DoGetIntSrc),
+ MakeIntegerChecker<int8_t> ())
+ .AddAttribute ("UIntegerTraceSource", "help text",
+ UintegerValue (2),
+ MakeUintegerAccessor (&AttributeObjectTest::m_uintSrc),
+ MakeIntegerChecker<uint8_t> ())
+ .AddAttribute ("DoubleTraceSource", "help text",
+ DoubleValue (2),
+ MakeDoubleAccessor (&AttributeObjectTest::m_doubleSrc),
+ MakeDoubleChecker<double> ())
+ .AddAttribute ("BoolTraceSource", "help text",
+ BooleanValue (false),
+ MakeBooleanAccessor (&AttributeObjectTest::m_boolSrc),
+ MakeBooleanChecker ())
+ .AddAttribute ("EnumTraceSource", "help text",
+ EnumValue (false),
+ MakeEnumAccessor (&AttributeObjectTest::m_enumSrc),
+ MakeEnumChecker (TEST_A, "TestA"))
+ .AddAttribute ("ValueClassSource", "help text",
+ ValueClassTestValue (ValueClassTest ()),
+ MakeValueClassTestAccessor (&AttributeObjectTest::m_valueSrc),
+ MakeValueClassTestChecker ())
+ .AddTraceSource ("Source1", "help test",
+ MakeTraceSourceAccessor (&AttributeObjectTest::m_intSrc1))
+ .AddTraceSource ("Source2", "help text",
+ MakeTraceSourceAccessor (&AttributeObjectTest::m_cb))
+ .AddTraceSource ("ValueSource", "help text",
+ MakeTraceSourceAccessor (&AttributeObjectTest::m_valueSrc))
+ .AddAttribute ("Pointer", "help text",
+ PointerValue (),
+ MakePointerAccessor (&AttributeObjectTest::m_ptr),
+ MakePointerChecker<Derived> ())
+ .AddAttribute ("Callback", "help text",
+ CallbackValue (),
+ MakeCallbackAccessor (&AttributeObjectTest::m_cbValue),
+ MakeCallbackChecker ())
+ ;
+
+ return tid;
+ }
+
+ void AddToVector1 (void) {m_vector1.push_back (CreateObject<Derived> ());}
+ void AddToVector2 (void) {m_vector2.push_back (CreateObject<Derived> ());}
+ void InvokeCb (double a, int b, float c) {m_cb (a,b,c);}
+
+ void InvokeCbValue (int8_t a)
+ {
+ if (!m_cbValue.IsNull ()) {
+ m_cbValue (a);
+ }
+ }
+
+private:
+ void DoSetTestB (bool v) {m_boolTestA = v;}
+ bool DoGetTestB (void) const {return m_boolTestA;}
+ int16_t DoGetInt16 (void) const {return m_int16SetGet;}
+ void DoSetInt16 (int16_t v) {m_int16SetGet = v;}
+ uint32_t DoGetVectorN (void) const {return m_vector2.size ();}
+ Ptr<Derived> DoGetVector (uint32_t i) const {return m_vector2[i];}
+ bool DoSetIntSrc (int8_t v) {m_intSrc2 = v; return true;}
+ int8_t DoGetIntSrc (void) const {return m_intSrc2;}
+
+ bool m_boolTestA;
+ bool m_boolTest;
+ int16_t m_int16;
+ int16_t m_int16WithBounds;
+ int16_t m_int16SetGet;
+ uint8_t m_uint8;
+ float m_float;
+ enum Test_e m_enum;
+ RandomVariable m_random;
+ std::vector<Ptr<Derived> > m_vector1;
+ std::vector<Ptr<Derived> > m_vector2;
+ Callback<void,int8_t> m_cbValue;
+ TracedValue<int8_t> m_intSrc1;
+ TracedValue<int8_t> m_intSrc2;
+ TracedCallback<double, int, float> m_cb;
+ TracedValue<ValueClassTest> m_valueSrc;
+ Ptr<Derived> m_ptr;
+ TracedValue<uint8_t> m_uintSrc;
+ TracedValue<enum Test_e> m_enumSrc;
+ TracedValue<double> m_doubleSrc;
+ TracedValue<bool> m_boolSrc;
+};
+
+NS_OBJECT_ENSURE_REGISTERED (AttributeObjectTest);
+
+// ===========================================================================
+// Test case template used for generic Attribute Value types -- used to make
+// sure that Attributes work as expected.
+// ===========================================================================
+template <typename T>
+class AttributeTestCase : public TestCase
+{
+public:
+ AttributeTestCase (std::string description);
+ virtual ~AttributeTestCase ();
+
+private:
+ virtual bool DoRun (void);
+
+ bool CheckGetCodePaths (Ptr<Object> p, std::string attributeName, std::string expectedString, T expectedValue);
+};
+
+template <typename T>
+AttributeTestCase<T>::AttributeTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+template <typename T>
+AttributeTestCase<T>::~AttributeTestCase ()
+{
+}
+
+template <typename T> bool
+AttributeTestCase<T>::CheckGetCodePaths (
+ Ptr<Object> p,
+ std::string attributeName,
+ std::string expectedString,
+ T expectedValue)
+{
+ StringValue stringValue;
+ T actualValue;
+
+ //
+ // Get an Attribute value through its StringValue representation.
+ //
+ bool ok = p->GetAttributeFailSafe (attributeName.c_str (), stringValue);
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not GetAttributeFailSafe() " << attributeName << " from Object");
+ NS_TEST_ASSERT_MSG_EQ (stringValue.Get (), expectedString, "Got unexpected StringValue representation");
+
+ //
+ // Get the existing boolean value through its particular type representation.
+ //
+ ok = p->GetAttributeFailSafe (attributeName.c_str (), actualValue);
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not GetAttributeFailSafe() " << attributeName << " from Object");
+ NS_TEST_ASSERT_MSG_EQ (actualValue.Get (), expectedValue.Get (), "Got unexpected Value from Object");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// The actual Attribute type test cases are specialized for each Attribute type
+// ===========================================================================
+template <> bool
+AttributeTestCase<BooleanValue>::DoRun (void)
+{
+ AttributeList attrs;
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ //
+ // Test setting a boolean via string representation using AttributeList.
+ //
+ ok = attrs.SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetFailSafe() \"ns3::AttributeObjectTest::TestBoolName\" into AttributeList");
+
+ //
+ // Create an object using that attribute list (which should therefore have the
+ // boolean from above set to false.
+ //
+ p = CreateObjectWithAttributes<AttributeObjectTest> (attrs);
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly from CreateObjectWithAttributes");
+
+ //
+ // Set the default value of the BooleanValue and create an object. The new
+ // default value should stick.
+ //
+ AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("true"));
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
+
+ //
+ // Set the default value of the BooleanValue the other way and create an object.
+ // The new default value should stick.
+ //
+ AttributeList::GetGlobal ()->SetFailSafe ("ns3::AttributeObjectTest::TestBoolName", StringValue ("false"));
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not et properly by default value");
+
+ //
+ // Set the BooleanValue Attribute to true via SetAttributeFailSafe path.
+ //
+ ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("true"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to true");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Set the BooleanValue to false via SetAttributeFailSafe path.
+ //
+ ok = p->SetAttributeFailSafe("TestBoolName", StringValue ("false"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() \"TestBoolName\" to false");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Create an object using individually provided StringValue Attribute.
+ //
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", StringValue ("true"));
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by CreateObjectWithAttributes() with StringValue");
+
+ //
+ // Create an object using individually provided BooleanValue Attribute.
+ //
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("TestBoolName", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObjectWithAttributes");
+
+ ok = CheckGetCodePaths (p, "TestBoolName", "false", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by CreateObjectWithAttributes() with BooleanValue");
+
+ //
+ // The previous object-based tests checked access directly. Now check through
+ // setter and getter. The code here looks the same, but the underlying
+ // attribute is declared differently in the object. First make sure we can set
+ // to true.
+ //
+ ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("true"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to true");
+
+ ok = CheckGetCodePaths (p, "TestBoolA", "true", BooleanValue (true));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
+
+ //
+ // Now Set the BooleanValue to false via the setter.
+ //
+ ok = p->SetAttributeFailSafe("TestBoolA", StringValue ("false"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a boolean value to false");
+
+ ok = CheckGetCodePaths (p, "TestBoolA", "false", BooleanValue (false));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (getter/setter) via StringValue");
+
+ return GetErrorStatus ();
+}
+
+template <> bool
+AttributeTestCase<IntegerValue>::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ ok = CheckGetCodePaths (p, "TestInt16", "-2", IntegerValue (-2));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
+
+ //
+ // Set the Attribute to a negative value through a StringValue.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-5"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -5");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "-5", IntegerValue (-5));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Set the Attribute to a positive value through a StringValue.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("+2"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to +2");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "2", IntegerValue (2));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Set the Attribute to the most negative value of the signed 16-bit range.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32768"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to -32768");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (most negative) via StringValue");
+
+ //
+ // Try to set the Attribute past the most negative value of the signed 16-bit
+ // range and make sure the underlying attribute is unchanged.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("-32769"));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -32769");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "-32768", IntegerValue (-32768));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Set the Attribute to the most positive value of the signed 16-bit range.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32767"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 32767");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (most positive) via StringValue");
+
+ //
+ // Try to set the Attribute past the most positive value of the signed 16-bit
+ // range and make sure the underlying attribute is unchanged.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16", StringValue ("32768"));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 32768");
+
+ ok = CheckGetCodePaths (p, "TestInt16", "32767", IntegerValue (32767));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Attributes can have limits other than the intrinsic limits of the
+ // underlying data types. These limits are specified in the Object.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (10));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 10");
+
+ ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via StringValue");
+
+ //
+ // Set the Attribute past the positive limit.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (11));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 11");
+
+ ok = CheckGetCodePaths (p, "TestInt16WithBounds", "10", IntegerValue (10));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Set the Attribute at the negative limit.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-5));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -5");
+
+ ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (negative limit) via StringValue");
+
+ //
+ // Set the Attribute past the negative limit.
+ //
+ ok = p->SetAttributeFailSafe("TestInt16WithBounds", IntegerValue (-6));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -6");
+
+ ok = CheckGetCodePaths (p, "TestInt16WithBounds", "-5", IntegerValue (-5));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ return GetErrorStatus ();
+}
+
+template <> bool
+AttributeTestCase<UintegerValue>::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ ok = CheckGetCodePaths (p, "TestUint8", "1", UintegerValue (1));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");;
+
+ //
+ // Set the Attribute to zero.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (0));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 0");
+
+ ok = CheckGetCodePaths (p, "TestUint8", "0", UintegerValue (0));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Set the Attribute to the most positive value of the unsigned 8-bit range.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (255));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 255");
+
+ ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() (positive limit) via UintegerValue");
+
+ //
+ // Try and set the Attribute past the most positive value of the unsigned
+ // 8-bit range.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", UintegerValue (256));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 256");
+
+ ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Set the Attribute to the most positive value of the unsigned 8-bit range
+ // through a StringValue.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", StringValue ("255"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via StringValue to 255");
+
+ ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Try and set the Attribute past the most positive value of the unsigned
+ // 8-bit range through a StringValue.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", StringValue ("256"));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to 256");
+
+ ok = CheckGetCodePaths (p, "TestUint8", "255", UintegerValue (255));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Try to set the Attribute to a negative StringValue.
+ //
+ ok = p->SetAttributeFailSafe("TestUint8", StringValue ("-1"));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via StringValue to -1");
+
+ return GetErrorStatus ();
+}
+
+template <> bool
+AttributeTestCase<DoubleValue>::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ ok = CheckGetCodePaths (p, "TestFloat", "-1.1", DoubleValue ((float)-1.1));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
+
+ //
+ // Set the Attribute.
+ //
+ ok = p->SetAttributeFailSafe("TestFloat", DoubleValue ((float)2.3));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to 2.3");
+
+ ok = CheckGetCodePaths (p, "TestFloat", "2.3", DoubleValue ((float)2.3));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via DoubleValue");
+
+ return GetErrorStatus ();
+}
+
+template <> bool
+AttributeTestCase<EnumValue>::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ ok = CheckGetCodePaths (p, "TestEnum", "TestA", EnumValue (AttributeObjectTest::TEST_A));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by default value");
+
+ //
+ // Set the Attribute using the EnumValue type.
+ //
+ ok = p->SetAttributeFailSafe("TestEnum", EnumValue (AttributeObjectTest::TEST_C));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_C");
+
+ ok = CheckGetCodePaths (p, "TestEnum", "TestC", EnumValue (AttributeObjectTest::TEST_C));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via EnumValue");
+
+ //
+ // Set the Attribute using the StringValue type.
+ //
+ ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestB"));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() to TEST_B");
+
+ ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Attribute not set properly by SetAttributeFailSafe() via StringValue");
+
+ //
+ // Try to set the Attribute to a bogus enum using the StringValue type and
+ // make sure the underlying value doesn't change.
+ //
+ ok = p->SetAttributeFailSafe("TestEnum", StringValue ("TestD"));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to TEST_D"); //
+
+ ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ //
+ // Try to set the Attribute to a bogus enum using an integer implicit conversion
+ // and make sure the underlying value doesn't change.
+ //
+ ok = p->SetAttributeFailSafe("TestEnum", EnumValue (5));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() to 5");
+
+ ok = CheckGetCodePaths (p, "TestEnum", "TestB", EnumValue (AttributeObjectTest::TEST_B));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Error in SetAttributeFailSafe() but value changes");
+
+ return GetErrorStatus ();
+}
+
+template <> bool
+AttributeTestCase<RandomVariableValue>::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // Try to set a UniformVariable
+ //
+ ok = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (UniformVariable (0., 1.)));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
+
+ //
+ // Try to set a <snicker> ConstantVariable
+ //
+ ok = p->SetAttributeFailSafe("TestRandom", RandomVariableValue (ConstantVariable (10.)));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a UniformVariable");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test case for Object Vector Attributes. Generic nature is pretty much lost
+// here, so we just break the class out.
+// ===========================================================================
+class ObjectVectorAttributeTestCase : public TestCase
+{
+public:
+ ObjectVectorAttributeTestCase (std::string description);
+ virtual ~ObjectVectorAttributeTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+};
+
+ObjectVectorAttributeTestCase::ObjectVectorAttributeTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+ObjectVectorAttributeTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ ObjectVectorValue vector;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have no items in
+ // the vector.
+ //
+ p->GetAttribute ("TestVector1", vector);
+ NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should be zero");
+
+ //
+ // Adding to the attribute shouldn't affect the value we already have.
+ //
+ p->AddToVector1 ();
+ NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 0, "Initial count of ObjectVectorValue \"TestVector1\" should still be zero");
+
+ //
+ // Getting the attribute again should update the value.
+ //
+ p->GetAttribute ("TestVector1", vector);
+ NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "ObjectVectorValue \"TestVector1\" should be incremented");
+
+ //
+ // Get the Object pointer from the value.
+ //
+ Ptr<Object> a = vector.Get (0);
+ NS_TEST_ASSERT_MSG_NE (a, 0, "Ptr<Object> from VectorValue \"TestVector1\" is zero");
+
+ //
+ // Adding to the attribute shouldn't affect the value we already have.
+ //
+ p->AddToVector1 ();
+ NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 1, "Count of ObjectVectorValue \"TestVector1\" should still be one");
+
+ //
+ // Getting the attribute again should update the value.
+ //
+ p->GetAttribute ("TestVector1", vector);
+ NS_TEST_ASSERT_MSG_EQ (vector.GetN (), 2, "ObjectVectorValue \"TestVector1\" should be incremented");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Trace sources with value semantics can be used like Attributes. Make sure
+// we can use them that way.
+// ===========================================================================
+class IntegerTraceSourceAttributeTestCase : public TestCase
+{
+public:
+ IntegerTraceSourceAttributeTestCase (std::string description);
+ virtual ~IntegerTraceSourceAttributeTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+};
+
+IntegerTraceSourceAttributeTestCase::IntegerTraceSourceAttributeTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+IntegerTraceSourceAttributeTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ IntegerValue iv;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ p->GetAttribute ("IntegerTraceSource1", iv);
+ NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
+
+ //
+ // Set the Attribute to a positive value through an IntegerValue.
+ //
+ ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (5));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
+
+ p->GetAttribute ("IntegerTraceSource1", iv);
+ NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
+
+ //
+ // Limits should work.
+ //
+ ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (127));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (128));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-128));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource1", IntegerValue (-129));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
+
+ //
+ // When the object is first created, the Attribute should have the default
+ // value.
+ //
+ p->GetAttribute ("IntegerTraceSource2", iv);
+ NS_TEST_ASSERT_MSG_EQ (iv.Get (), -2, "Attribute not set properly by default value");
+
+ //
+ // Set the Attribute to a positive value through an IntegerValue.
+ //
+ ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (5));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 5");
+
+ p->GetAttribute ("IntegerTraceSource2", iv);
+ NS_TEST_ASSERT_MSG_EQ (iv.Get (), 5, "Attribute not set properly by SetAttributeFailSafe() via IntegerValue");
+
+ //
+ // Limits should work.
+ //
+ ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (127));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 127");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (128));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to 128");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-128));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -128");
+
+ ok = p->SetAttributeFailSafe("IntegerTraceSource2", IntegerValue (-129));
+ NS_TEST_ASSERT_MSG_EQ (ok, false, "Unexpectedly could SetAttributeFailSafe() via IntegerValue to -129");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Trace sources used like Attributes must also work as trace sources. Make
+// sure we can use them that way.
+// ===========================================================================
+class IntegerTraceSourceTestCase : public TestCase
+{
+public:
+ IntegerTraceSourceTestCase (std::string description);
+ virtual ~IntegerTraceSourceTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+
+ void NotifySource1 (int8_t old, int8_t n) {m_got1 = n;}
+ int64_t m_got1;
+};
+
+IntegerTraceSourceTestCase::IntegerTraceSourceTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+IntegerTraceSourceTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // Check to make sure changing an Attibute value triggers a trace callback
+ // that sets a member variable.
+ //
+ m_got1 = 1234;
+
+ ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (-1));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to -1");
+
+ //
+ // Source1 is declared as a TraceSourceAccessor to m_intSrc1. This m_intSrc1
+ // is also declared as an Integer Attribute. We just checked to make sure we
+ // could set it using an IntegerValue through its IntegerTraceSource1 "persona."
+ // We should also be able to hook a trace source to the underlying variable.
+ //
+ ok = p->TraceConnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
+
+ //
+ // When we set the IntegerValue that now underlies both the Integer Attribute
+ // and the trace source, the trace should fire and call NotifySource1 which
+ // will set m_got1 to the new value.
+ //
+ ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (0));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 0");
+
+ NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue does not cause trace callback to be called");
+
+ //
+ // Now disconnect from the trace source and ensure that the trace callback
+ // is not called if the trace source is hit.
+ //
+ ok = p->TraceDisconnectWithoutContext ("Source1", MakeCallback (&IntegerTraceSourceTestCase::NotifySource1, this));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() \"Source1\" to NodifySource1()");
+
+ ok = p->SetAttributeFailSafe ("IntegerTraceSource1", IntegerValue (1));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() via IntegerValue to 1");
+
+ NS_TEST_ASSERT_MSG_EQ (m_got1, 0, "Hitting a TracedValue after disconnect still causes callback");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Trace sources used like Attributes must also work as trace sources. Make
+// sure we can use them that way.
+// ===========================================================================
+class TracedCallbackTestCase : public TestCase
+{
+public:
+ TracedCallbackTestCase (std::string description);
+ virtual ~TracedCallbackTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+
+ void NotifySource2 (double a, int b, float c) {m_got2 = a;}
+
+ double m_got2;
+};
+
+TracedCallbackTestCase::TracedCallbackTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+TracedCallbackTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // Initialize the
+ //
+ m_got2 = 4.3;
+
+ //
+ // Invoke the callback that lies at the heart of this test. We have a
+ // method InvokeCb() that just executes m_cb(). The variable m_cb is
+ // declared as a TracedCallback<double, int, float>. This kind of beast
+ // is like a callback but can call a list of targets. This list should
+ // be empty so nothing should happen now. Specifically, m_got2 shouldn't
+ // have changed.
+ //
+ p->InvokeCb (1.0, -5, 0.0);
+ NS_TEST_ASSERT_MSG_EQ (m_got2, 4.3, "Invoking a newly created TracedCallback results in an unexpected callback");
+
+ //
+ // Now, wire the TracedCallback up to a trace sink. This sink will just set
+ // m_got2 to the first argument.
+ //
+ ok = p->TraceConnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceConnectWithoutContext() to NotifySource2");
+
+ //
+ // Now if we invoke the callback, the trace source should fire and m_got2
+ // should be set in the trace sink.
+ //
+ p->InvokeCb (1.0, -5, 0.0);
+ NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking TracedCallback does not result in trace callback");
+
+ //
+ // Now, disconnect the trace sink and see what happens when we invoke the
+ // callback again. Of course, the trace should not happen and m_got2
+ // should remain unchanged.
+ //
+ ok = p->TraceDisconnectWithoutContext ("Source2", MakeCallback (&TracedCallbackTestCase::NotifySource2, this));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not TraceDisconnectWithoutContext() from NotifySource2");
+
+ p->InvokeCb (-1.0, -5, 0.0);
+ NS_TEST_ASSERT_MSG_EQ (m_got2, 1.0, "Invoking disconnected TracedCallback unexpectedly results in trace callback");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Smart pointers (Ptr) are central to our architecture, so they must work as
+// attributes.
+// ===========================================================================
+class PointerAttributeTestCase : public TestCase
+{
+public:
+ PointerAttributeTestCase (std::string description);
+ virtual ~PointerAttributeTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+
+ void NotifySource2 (double a, int b, float c) {m_got2 = a;}
+
+ double m_got2;
+};
+
+PointerAttributeTestCase::PointerAttributeTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+PointerAttributeTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // We have declared a PointerValue Attribute named "Pointer" with a pointer
+ // checker of type Derived. This means that we should be able to pull out
+ // a Ptr<Derived> with the initial value (which is 0).
+ //
+ PointerValue ptr;
+ p->GetAttribute ("Pointer", ptr);
+ Ptr<Derived> derived = ptr.Get<Derived> ();
+ NS_TEST_ASSERT_MSG_EQ (derived, 0, "Unexpectedly found non-null pointer in newly initialized PointerValue Attribute");
+
+ //
+ // Now, lets create an Object of type Derived and set the local Ptr to point
+ // to that object. We can then set the PointerValue Attribute to that Ptr.
+ //
+ derived = Create<Derived> ();
+ ok = p->SetAttributeFailSafe("Pointer", PointerValue (derived));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a PointerValue of the correct type");
+
+ //
+ // Pull the value back out of the Attribute and make sure it points to the
+ // correct object.
+ //
+ p->GetAttribute ("Pointer", ptr);
+ Ptr<Derived> stored = ptr.Get<Derived> ();
+ NS_TEST_ASSERT_MSG_EQ (stored, derived, "Retreived Attribute does not match stored PointerValue");
+
+ //
+ // We should be able to use the Attribute Get() just like GetObject<type>,
+ // So see if we can get a Ptr<Object> out of the Ptr<Derived> we stored.
+ // This should be a pointer to the same physical memory since its the
+ // same object.
+ //
+ p->GetAttribute ("Pointer", ptr);
+ Ptr<Object> storedBase = ptr.Get<Object> ();
+ NS_TEST_ASSERT_MSG_EQ (storedBase, stored, "Retreived Ptr<Object> does not match stored Ptr<Derived>");
+
+ //
+ // If we try to Get() something that is unrelated to what we stored, we should
+ // retrieve a 0.
+ //
+ p->GetAttribute ("Pointer", ptr);
+ Ptr<AttributeObjectTest> x = ptr.Get<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_EQ (x, 0, "Unexpectedly retreived unrelated Ptr<type> from stored Ptr<Derived>");
+
+ //
+ // We should be able to create the object From a list of attributes.
+ //
+ p = CreateObjectWithAttributes<AttributeObjectTest> ("Pointer", PointerValue (Create<Derived> ()));
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Could not create Object with PointerValue Attribute in Attribute List");
+
+ derived = 0;
+ p->GetAttribute ("Pointer", ptr);
+ derived = ptr.Get<Derived> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Retrieved zero PointerValue Attribute after initializing to non-zero Ptr");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test the Attributes of type CallbackVale.
+// ===========================================================================
+class CallbackValueTestCase : public TestCase
+{
+public:
+ CallbackValueTestCase (std::string description);
+ virtual ~CallbackValueTestCase () {}
+
+ void InvokeCbValue (int8_t a)
+ {
+ if (!m_cbValue.IsNull ()) {
+ m_cbValue (a);
+ }
+ }
+
+private:
+ virtual bool DoRun (void);
+
+ Callback<void,int8_t> m_cbValue;
+
+ void NotifyCallbackValue (int8_t a) {m_gotCbValue = a;}
+
+ int16_t m_gotCbValue;
+};
+
+CallbackValueTestCase::CallbackValueTestCase (std::string description)
+ : TestCase (description)
+{
+}
+
+bool
+CallbackValueTestCase::DoRun (void)
+{
+ Ptr<AttributeObjectTest> p;
+ bool ok;
+
+ p = CreateObject<AttributeObjectTest> ();
+ NS_TEST_ASSERT_MSG_NE (p, 0, "Unable to CreateObject");
+
+ //
+ // The member variable m_cbValue is declared as a Callback<void, int8_t>. The
+ // Attibute named "Callback" also points to m_cbValue and allows us to set the
+ // callback using that Attribute.
+ //
+ // NotifyCallbackValue is going to be the target of the callback and will just set
+ // m_gotCbValue to its single parameter. This will be the parameter from the
+ // callback invocation. The method InvokeCbValue() just invokes the m_cbValue
+ // callback if it is non-null.
+ //
+ m_gotCbValue = 1;
+
+ //
+ // If we invoke the callback (which has not been set) nothing should happen.
+ // Further, nothing should happen when we initialize the callback (it shouldn't
+ // accidentally fire).
+ //
+ p->InvokeCbValue (2);
+ CallbackValue cbValue = MakeCallback (&CallbackValueTestCase::NotifyCallbackValue, this);
+
+ NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 1, "Callback unexpectedly fired");
+
+ ok = p->SetAttributeFailSafe ("Callback", cbValue);
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a CallbackValue");
+
+ //
+ // Now that the callback has been set, invoking it should set m_gotCbValue.
+ //
+ p->InvokeCbValue (2);
+ NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set by CallbackValue did not fire");
+
+ ok = p->SetAttributeFailSafe ("Callback", CallbackValue (MakeNullCallback<void,int8_t> ()));
+ NS_TEST_ASSERT_MSG_EQ (ok, true, "Could not SetAttributeFailSafe() a null CallbackValue");
+
+ //
+ // If the callback has been set to a null callback, it should no longer fire.
+ //
+ p->InvokeCbValue (3);
+ NS_TEST_ASSERT_MSG_EQ (m_gotCbValue, 2, "Callback Attribute set to null callback unexpectedly fired");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// The Test Suite that glues all of the Test Cases together.
+// ===========================================================================
+class AttributesTestSuite : public TestSuite
+{
+public:
+ AttributesTestSuite ();
+};
+
+AttributesTestSuite::AttributesTestSuite ()
+ : TestSuite ("attributes", UNIT)
+{
+ AddTestCase (new AttributeTestCase<BooleanValue> ("Check Attributes of type BooleanValue"));
+ AddTestCase (new AttributeTestCase<IntegerValue> ("Check Attributes of type IntegerValue"));
+ AddTestCase (new AttributeTestCase<UintegerValue> ("Check Attributes of type UintegerValue"));
+ AddTestCase (new AttributeTestCase<DoubleValue> ("Check Attributes of type DoubleValue"));
+ AddTestCase (new AttributeTestCase<EnumValue> ("Check Attributes of type EnumValue"));
+ AddTestCase (new AttributeTestCase<RandomVariableValue> ("Check Attributes of type RandomVariableValue"));
+ AddTestCase (new ObjectVectorAttributeTestCase ("Check Attributes of type ObjectVectorValue"));
+ AddTestCase (new IntegerTraceSourceAttributeTestCase ("Ensure TracedValue<uint8_t> can be set like IntegerValue"));
+ AddTestCase (new IntegerTraceSourceTestCase ("Ensure TracedValue<uint8_t> also works as trace source"));
+ AddTestCase (new TracedCallbackTestCase ("Ensure TracedCallback<double, int, float> works as trace source"));
+ AddTestCase (new PointerAttributeTestCase ("Check Attributes of type PointerValue"));
+ AddTestCase (new CallbackValueTestCase ("Check Attributes of type CallbackValue"));
+}
+
+static AttributesTestSuite attributesTestSuite;
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/callback-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,590 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "model/test.h"
+#include "model/callback.h"
+#include <stdint.h>
+
+namespace ns3 {
+
+// ===========================================================================
+// Test the basic Callback mechanism
+// ===========================================================================
+class BasicCallbackTestCase : public TestCase
+{
+public:
+ BasicCallbackTestCase ();
+ virtual ~BasicCallbackTestCase () {}
+
+ void Target1 (void) {m_test1 = true;}
+ int Target2 (void) {m_test2 = true; return 2;}
+ void Target3 (double a) {m_test3 = true;}
+ int Target4 (double a, int b) {m_test4 = true; return 4;}
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoSetup (void);
+
+ bool m_test1;
+ bool m_test2;
+ bool m_test3;
+ bool m_test4;
+};
+
+static bool gBasicCallbackTest5;
+static bool gBasicCallbackTest6;
+static bool gBasicCallbackTest7;
+
+void
+BasicCallbackTarget5 (void)
+{
+ gBasicCallbackTest5 = true;
+}
+
+void
+BasicCallbackTarget6 (int)
+{
+ gBasicCallbackTest6 = true;
+}
+
+int
+BasicCallbackTarget7 (int a)
+{
+ gBasicCallbackTest7 = true;
+ return a;
+}
+
+BasicCallbackTestCase::BasicCallbackTestCase ()
+ : TestCase ("Check basic Callback mechansim")
+{
+}
+
+void
+BasicCallbackTestCase::DoSetup (void)
+{
+ m_test1 = false;
+ m_test2 = false;
+ m_test3 = false;
+ m_test4 = false;
+ gBasicCallbackTest5 = false;
+ gBasicCallbackTest6 = false;
+ gBasicCallbackTest7 = false;
+}
+
+bool
+BasicCallbackTestCase::DoRun (void)
+{
+ //
+ // Make sure we can declare and compile a Callback pointing to a member
+ // function returning void and execute it.
+ //
+ Callback<void> target1 (this, &BasicCallbackTestCase::Target1);
+ target1 ();
+ NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a member
+ // function that returns an int and execute it.
+ //
+ Callback<int> target2;
+ target2 = Callback<int> (this, &BasicCallbackTestCase::Target2);
+ target2 ();
+ NS_TEST_ASSERT_MSG_EQ (m_test2, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a member
+ // function that returns void, takes a double parameter, and execute it.
+ //
+ Callback<void, double> target3 = Callback<void, double> (this, &BasicCallbackTestCase::Target3);
+ target3 (0.0);
+ NS_TEST_ASSERT_MSG_EQ (m_test3, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a member
+ // function that returns void, takes two parameters, and execute it.
+ //
+ Callback<int, double, int> target4 = Callback<int, double, int> (this, &BasicCallbackTestCase::Target4);
+ target4 (0.0, 1);
+ NS_TEST_ASSERT_MSG_EQ (m_test4, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a non-member
+ // function that returns void, and execute it. This is a lower level call
+ // than MakeCallback so we have got to include at least two arguments to make
+ // sure that the constructor is properly disambiguated. If the arguments are
+ // not needed, we just pass in dummy values.
+ //
+ Callback<void> target5 = Callback<void> (&BasicCallbackTarget5, true, true);
+ target5 ();
+ NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest5, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a non-member
+ // function that returns void, takes one integer argument and execute it.
+ // We also need to provide two dummy arguments to the constructor here.
+ //
+ Callback<void, int> target6 = Callback<void, int> (&BasicCallbackTarget6, true, true);
+ target6 (1);
+ NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest6, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a non-member
+ // function that returns int, takes one integer argument and execute it.
+ // We also need to provide two dummy arguments to the constructor here.
+ //
+ Callback<int, int> target7 = Callback<int, int> (&BasicCallbackTarget7, true, true);
+ target7 (1);
+ NS_TEST_ASSERT_MSG_EQ (gBasicCallbackTest7, true, "Callback did not fire");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test the MakeCallback mechanism
+// ===========================================================================
+class MakeCallbackTestCase : public TestCase
+{
+public:
+ MakeCallbackTestCase ();
+ virtual ~MakeCallbackTestCase () {}
+
+ void Target1 (void) {m_test1 = true;}
+ int Target2 (void) {m_test2 = true; return 2;}
+ void Target3 (double a) {m_test3 = true;}
+ int Target4 (double a, int b) {m_test4 = true; return 4;}
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoSetup (void);
+
+ bool m_test1;
+ bool m_test2;
+ bool m_test3;
+ bool m_test4;
+};
+
+static bool gMakeCallbackTest5;
+static bool gMakeCallbackTest6;
+static bool gMakeCallbackTest7;
+
+void
+MakeCallbackTarget5 (void)
+{
+ gMakeCallbackTest5 = true;
+}
+
+void
+MakeCallbackTarget6 (int)
+{
+ gMakeCallbackTest6 = true;
+}
+
+int
+MakeCallbackTarget7 (int a)
+{
+ gMakeCallbackTest7 = true;
+ return a;
+}
+
+MakeCallbackTestCase::MakeCallbackTestCase ()
+ : TestCase ("Check MakeCallback() mechanism")
+{
+}
+
+void
+MakeCallbackTestCase::DoSetup (void)
+{
+ m_test1 = false;
+ m_test2 = false;
+ m_test3 = false;
+ m_test4 = false;
+ gMakeCallbackTest5 = false;
+ gMakeCallbackTest6 = false;
+ gMakeCallbackTest7 = false;
+}
+
+bool
+MakeCallbackTestCase::DoRun (void)
+{
+ //
+ // Make sure we can declare and make a Callback pointing to a member
+ // function returning void and execute it.
+ //
+ Callback<void> target1 = MakeCallback (&MakeCallbackTestCase::Target1, this);
+ target1 ();
+ NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and make a Callback pointing to a member
+ // function that returns an int and execute it.
+ //
+ Callback<int> target2 = MakeCallback (&MakeCallbackTestCase::Target2, this);
+ target2 ();
+ NS_TEST_ASSERT_MSG_EQ (m_test2, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and make a Callback pointing to a member
+ // function that returns void, takes a double parameter, and execute it.
+ //
+ Callback<void, double> target3 = MakeCallback (&MakeCallbackTestCase::Target3, this);
+ target3 (0.0);
+ NS_TEST_ASSERT_MSG_EQ (m_test3, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and make a Callback pointing to a member
+ // function that returns void, takes two parameters, and execute it.
+ //
+ Callback<int, double, int> target4 = MakeCallback (&MakeCallbackTestCase::Target4, this);
+ target4 (0.0, 1);
+ NS_TEST_ASSERT_MSG_EQ (m_test4, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and make a Callback pointing to a non-member
+ // function that returns void, and execute it. This uses a higher level call
+ // than in the basic tests so we do not need to include any dummy arguments
+ // here.
+ //
+ Callback<void> target5 = MakeCallback (&MakeCallbackTarget5);
+ target5 ();
+ NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest5, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a non-member
+ // function that returns void, takes one integer argument and execute it.
+ // This uses a higher level call than in the basic tests so we do not need to
+ // include any dummy arguments here.
+ //
+ Callback<void, int> target6 = MakeCallback (&MakeCallbackTarget6);
+ target6 (1);
+ NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest6, true, "Callback did not fire");
+
+ //
+ // Make sure we can declare and compile a Callback pointing to a non-member
+ // function that returns int, takes one integer argument and execute it.
+ // This uses a higher level call than in the basic tests so we do not need to
+ // include any dummy arguments here.
+ //
+ Callback<int, int> target7 = MakeCallback (&MakeCallbackTarget7);
+ target7 (1);
+ NS_TEST_ASSERT_MSG_EQ (gMakeCallbackTest7, true, "Callback did not fire");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test the MakeBoundCallback mechanism
+// ===========================================================================
+class MakeBoundCallbackTestCase : public TestCase
+{
+public:
+ MakeBoundCallbackTestCase ();
+ virtual ~MakeBoundCallbackTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoSetup (void);
+};
+
+static int gMakeBoundCallbackTest1;
+static bool *gMakeBoundCallbackTest2;
+static bool *gMakeBoundCallbackTest3a;
+static int gMakeBoundCallbackTest3b;
+
+void
+MakeBoundCallbackTarget1 (int a)
+{
+ gMakeBoundCallbackTest1 = a;
+}
+
+void
+MakeBoundCallbackTarget2 (bool *a)
+{
+ gMakeBoundCallbackTest2 = a;
+}
+
+int
+MakeBoundCallbackTarget3 (bool *a, int b)
+{
+ gMakeBoundCallbackTest3a = a;
+ gMakeBoundCallbackTest3b = b;
+ return 1234;
+}
+
+MakeBoundCallbackTestCase::MakeBoundCallbackTestCase ()
+ : TestCase ("Check MakeBoundCallback() mechanism")
+{
+}
+
+void
+MakeBoundCallbackTestCase::DoSetup (void)
+{
+ gMakeBoundCallbackTest1 = 0;
+ gMakeBoundCallbackTest2 = 0;
+ gMakeBoundCallbackTest3a = 0;
+ gMakeBoundCallbackTest3b = 0;
+}
+
+bool
+MakeBoundCallbackTestCase::DoRun (void)
+{
+ //
+ // This is slightly tricky to explain. A bound Callback allows us to package
+ // up arguments for use later. The arguments are bound when the callback is
+ // created and the code that fires the Callback does not know they are there.
+ //
+ // Since the callback is *declared* according to the way it will be used, the
+ // arguments are not seen there. However, the target function of the callback
+ // will have the provided arguments present. The MakeBoundCallback template
+ // function is what connects the two together and where you provide the
+ // arguments to be bound.
+ //
+ // Here we declare a Callback that returns a void and takes no parameters.
+ // MakeBoundCallback connects this Callback to a target function that returns
+ // void and takes an integer argument. That integer argument is bound to the
+ // value 1234. When the Callback is fired, no integer argument is provided
+ // directly. The argument is provided by bound Callback mechanism.
+ //
+ Callback<void> target1 = MakeBoundCallback (&MakeBoundCallbackTarget1, 1234);
+ target1 ();
+ NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest1, 1234, "Callback did not fire or binding not correct");
+
+ //
+ // Make sure we can bind a pointer value (a common use case).
+ //
+ bool a;
+ Callback<void> target2 = MakeBoundCallback (&MakeBoundCallbackTarget2, &a);
+ target2 ();
+ NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest2, &a, "Callback did not fire or binding not correct");
+
+ //
+ // Make sure we can mix and match bound and unbound arguments. This callback
+ // returns an integer so we should see that appear.
+ //
+ Callback<int, int> target3 = MakeBoundCallback (&MakeBoundCallbackTarget3, &a);
+ int result = target3 (2468);
+ NS_TEST_ASSERT_MSG_EQ (result, 1234, "Return value of callback not correct");
+ NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3a, &a, "Callback did not fire or binding not correct");
+ NS_TEST_ASSERT_MSG_EQ (gMakeBoundCallbackTest3b, 2468, "Callback did not fire or argument not correct");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Test the Nullify mechanism
+// ===========================================================================
+class NullifyCallbackTestCase : public TestCase
+{
+public:
+ NullifyCallbackTestCase ();
+ virtual ~NullifyCallbackTestCase () {}
+
+ void Target1 (void) {m_test1 = true;}
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoSetup (void);
+
+ bool m_test1;
+};
+
+NullifyCallbackTestCase::NullifyCallbackTestCase ()
+ : TestCase ("Check Nullify() and IsNull()")
+{
+}
+
+void
+NullifyCallbackTestCase::DoSetup (void)
+{
+ m_test1 = false;
+}
+
+bool
+NullifyCallbackTestCase::DoRun (void)
+{
+ //
+ // Make sure we can declare and make a Callback pointing to a member
+ // function returning void and execute it.
+ //
+ Callback<void> target1 = MakeCallback (&NullifyCallbackTestCase::Target1, this);
+ target1 ();
+ NS_TEST_ASSERT_MSG_EQ (m_test1, true, "Callback did not fire");
+
+ NS_TEST_ASSERT_MSG_EQ (target1.IsNull (), false, "Working Callback reports IsNull()");
+
+ target1.Nullify ();
+
+ NS_TEST_ASSERT_MSG_EQ (target1.IsNull (), true, "Nullified Callback reports not IsNull()");
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// Make sure that various MakeCallback template functions compile and execute.
+// Doesn't check an results of the execution.
+// ===========================================================================
+class MakeCallbackTemplatesTestCase : public TestCase
+{
+public:
+ MakeCallbackTemplatesTestCase ();
+ virtual ~MakeCallbackTemplatesTestCase () {}
+
+ void Target1 (void) {m_test1 = true;}
+
+private:
+ virtual bool DoRun (void);
+
+ bool m_test1;
+};
+
+void TestFZero (void) {}
+void TestFOne (int) {}
+void TestFTwo (int, int) {}
+void TestFThree (int, int, int) {}
+void TestFFour (int, int, int, int) {}
+void TestFFive (int, int, int, int, int) {}
+void TestFSix (int, int, int, int, int, int) {}
+
+void TestFROne (int &) {}
+void TestFRTwo (int &, int &) {}
+void TestFRThree (int &, int &, int &) {}
+void TestFRFour (int &, int &, int &, int &) {}
+void TestFRFive (int &, int &, int &, int &, int &) {}
+void TestFRSix (int &, int &, int &, int &, int &, int &) {}
+
+class CallbackTestParent
+{
+public:
+ void PublicParent (void) {}
+protected:
+ void ProtectedParent (void) {}
+ static void StaticProtectedParent (void) {}
+private:
+ void PrivateParent (void) {}
+};
+
+class CallbackTestClass : public CallbackTestParent
+{
+public:
+ void TestZero (void) {}
+ void TestOne (int) {}
+ void TestTwo (int, int) {}
+ void TestThree (int, int, int) {}
+ void TestFour (int, int, int, int) {}
+ void TestFive (int, int, int, int, int) {}
+ void TestSix (int, int, int, int, int, int) {}
+ void TestCZero (void) const {}
+ void TestCOne (int) const {}
+ void TestCTwo (int, int) const {}
+ void TestCThree (int, int, int) const {}
+ void TestCFour (int, int, int, int) const {}
+ void TestCFive (int, int, int, int, int) const {}
+ void TestCSix (int, int, int, int, int, int) const {}
+
+ void CheckParentalRights (void)
+ {
+ MakeCallback (&CallbackTestParent::StaticProtectedParent);
+ MakeCallback (&CallbackTestParent::PublicParent, this);
+ MakeCallback (&CallbackTestClass::ProtectedParent, this);
+ // as expected, fails.
+ // MakeCallback (&CallbackTestParent::PrivateParent, this);
+ // unexpected, but fails too. It does fumble me.
+ // MakeCallback (&CallbackTestParent::ProtectedParent, this);
+ }
+
+};
+
+MakeCallbackTemplatesTestCase::MakeCallbackTemplatesTestCase ()
+ : TestCase ("Check various MakeCallback() template functions")
+{
+}
+
+bool
+MakeCallbackTemplatesTestCase::DoRun (void)
+{
+ CallbackTestClass that;
+
+ MakeCallback (&CallbackTestClass::TestZero, &that);
+ MakeCallback (&CallbackTestClass::TestOne, &that);
+ MakeCallback (&CallbackTestClass::TestTwo, &that);
+ MakeCallback (&CallbackTestClass::TestThree, &that);
+ MakeCallback (&CallbackTestClass::TestFour, &that);
+ MakeCallback (&CallbackTestClass::TestFive, &that);
+ MakeCallback (&CallbackTestClass::TestSix, &that);
+
+ MakeCallback (&CallbackTestClass::TestCZero, &that);
+ MakeCallback (&CallbackTestClass::TestCOne, &that);
+ MakeCallback (&CallbackTestClass::TestCTwo, &that);
+ MakeCallback (&CallbackTestClass::TestCThree, &that);
+ MakeCallback (&CallbackTestClass::TestCFour, &that);
+ MakeCallback (&CallbackTestClass::TestCFive, &that);
+ MakeCallback (&CallbackTestClass::TestCSix, &that);
+
+ MakeCallback (&TestFZero);
+ MakeCallback (&TestFOne);
+ MakeCallback (&TestFTwo);
+ MakeCallback (&TestFThree);
+ MakeCallback (&TestFFour);
+ MakeCallback (&TestFFive);
+ MakeCallback (&TestFSix);
+
+ MakeCallback (&TestFROne);
+ MakeCallback (&TestFRTwo);
+ MakeCallback (&TestFRThree);
+ MakeCallback (&TestFRFour);
+ MakeCallback (&TestFRFive);
+ MakeCallback (&TestFRSix);
+
+ MakeBoundCallback (&TestFOne, 1);
+ MakeBoundCallback (&TestFTwo, 1);
+ MakeBoundCallback (&TestFThree, 1);
+ MakeBoundCallback (&TestFFour, 1);
+ MakeBoundCallback (&TestFFive, 1);
+
+ MakeBoundCallback (&TestFROne, 1);
+ MakeBoundCallback (&TestFRTwo, 1);
+ MakeBoundCallback (&TestFRThree, 1);
+ MakeBoundCallback (&TestFRFour, 1);
+ MakeBoundCallback (&TestFRFive, 1);
+
+ that.CheckParentalRights ();
+
+ return GetErrorStatus ();
+}
+
+// ===========================================================================
+// The Test Suite that glues all of the Test Cases together.
+// ===========================================================================
+class CallbackTestSuite : public TestSuite
+{
+public:
+ CallbackTestSuite ();
+};
+
+CallbackTestSuite::CallbackTestSuite ()
+ : TestSuite ("callback", UNIT)
+{
+ AddTestCase (new BasicCallbackTestCase);
+ AddTestCase (new MakeCallbackTestCase);
+ AddTestCase (new MakeBoundCallbackTestCase);
+ AddTestCase (new NullifyCallbackTestCase);
+ AddTestCase (new MakeCallbackTemplatesTestCase);
+}
+
+CallbackTestSuite CallbackTestSuite;
+
+} // namespace
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/names-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,975 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "model/test.h"
+#include "model/names.h"
+
+using namespace ns3;
+
+// ===========================================================================
+// Cook up a couple of simple object class that we can use in the object
+// naming tests. They do nothing but be of the right type.
+// ===========================================================================
+class TestObject : public Object
+{
+public:
+ static TypeId GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("TestObject")
+ .SetParent (Object::GetTypeId ())
+ .HideFromDocumentation ()
+ .AddConstructor<TestObject> ();
+ return tid;
+ }
+ TestObject () {}
+ virtual void Dispose (void) {}
+};
+
+class AlternateTestObject : public Object
+{
+public:
+ static TypeId GetTypeId (void)
+ {
+ static TypeId tid = TypeId ("AlternateTestObject")
+ .SetParent (Object::GetTypeId ())
+ .HideFromDocumentation ()
+ .AddConstructor<AlternateTestObject> ();
+ return tid;
+ }
+ AlternateTestObject () {}
+ virtual void Dispose (void) {}
+};
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can do its most basic
+// job and add associations between Objects using the lowest level add
+// function, which is:
+//
+// Add (Ptr<Object> context, std::string name, Ptr<Object> object);
+//
+// All other add functions will just translate into this form, so this is the
+// most basic Add functionality.
+// ===========================================================================
+class BasicAddTestCase : public TestCase
+{
+public:
+ BasicAddTestCase ();
+ virtual ~BasicAddTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+BasicAddTestCase::BasicAddTestCase ()
+ : TestCase ("Check low level Names::Add and Names::FindName functionality")
+{
+}
+
+BasicAddTestCase::~BasicAddTestCase ()
+{
+}
+
+void
+BasicAddTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+BasicAddTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add (Ptr<Object> (0, false), "Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add (Ptr<Object> (0, false), "Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add (objectOne, "Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add (objectTwo, "Child", childOfObjectTwo);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
+
+ found = Names::FindName (objectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ found = Names::FindName (childOfObjectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can correctly use a
+// string context in the most basic ways
+//
+// Add (std::string context, std::string name, Ptr<Object> object);
+//
+// High level path-based functions will translate into this form, so this is
+// the second most basic Add functionality.
+// ===========================================================================
+class StringContextAddTestCase : public TestCase
+{
+public:
+ StringContextAddTestCase ();
+ virtual ~StringContextAddTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+StringContextAddTestCase::StringContextAddTestCase ()
+ : TestCase ("Check string context Names::Add and Names::FindName functionality")
+
+{
+}
+
+StringContextAddTestCase::~StringContextAddTestCase ()
+{
+}
+
+void
+StringContextAddTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+StringContextAddTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names", "Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names", "Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name One", "Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name Two", "Child", childOfObjectTwo);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
+
+ found = Names::FindName (objectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ found = Names::FindName (childOfObjectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can correctly use a
+// fully qualified path to add assocations
+//
+// Add (std::string name, Ptr<Object> object);
+// ===========================================================================
+class FullyQualifiedAddTestCase : public TestCase
+{
+public:
+ FullyQualifiedAddTestCase ();
+ virtual ~FullyQualifiedAddTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+FullyQualifiedAddTestCase::FullyQualifiedAddTestCase ()
+ : TestCase ("Check fully qualified path Names::Add and Names::FindName functionality")
+
+{
+}
+
+FullyQualifiedAddTestCase::~FullyQualifiedAddTestCase ()
+{
+}
+
+void
+FullyQualifiedAddTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+FullyQualifiedAddTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
+
+ found = Names::FindName (objectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ found = Names::FindName (childOfObjectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can correctly use a
+// relative path to add assocations. This functionality is provided as a
+// convenience so clients don't always have to provide the name service
+// namespace name in all of their strings.
+//
+//
+// Add (std::string name, Ptr<Object> object);
+// ===========================================================================
+class RelativeAddTestCase : public TestCase
+{
+public:
+ RelativeAddTestCase ();
+ virtual ~RelativeAddTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+RelativeAddTestCase::RelativeAddTestCase ()
+ : TestCase ("Check relative path Names::Add and Names::FindName functionality")
+
+{
+}
+
+RelativeAddTestCase::~RelativeAddTestCase ()
+{
+}
+
+void
+RelativeAddTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+RelativeAddTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two/Child", childOfObjectTwo);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name One", "Could not Names::Add and Names::FindName an Object");
+
+ found = Names::FindName (objectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name Two", "Could not Names::Add and Names::FindName a second Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ found = Names::FindName (childOfObjectTwo);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can rename objects in
+// its most basic way, which is
+//
+// Rename (Ptr<Object> context, std::string oldname, std::string newname);
+//
+// All other rename functions will just translate into this form, so this is the
+// most basic rename functionality.
+// ===========================================================================
+class BasicRenameTestCase : public TestCase
+{
+public:
+ BasicRenameTestCase ();
+ virtual ~BasicRenameTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+BasicRenameTestCase::BasicRenameTestCase ()
+ : TestCase ("Check low level Names::Rename functionality")
+{
+}
+
+BasicRenameTestCase::~BasicRenameTestCase ()
+{
+}
+
+void
+BasicRenameTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+BasicRenameTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add (Ptr<Object> (0, false), "Name", objectOne);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add (objectOne, "Child", childOfObjectOne);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
+
+ Names::Rename (Ptr<Object> (0, false), "Name", "New Name");
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ Names::Rename (objectOne, "Child", "New Child");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can rename objects
+// using a string context
+//
+// Rename (std::string context, std::string oldname, std::string newname);
+// ===========================================================================
+class StringContextRenameTestCase : public TestCase
+{
+public:
+ StringContextRenameTestCase ();
+ virtual ~StringContextRenameTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+StringContextRenameTestCase::StringContextRenameTestCase ()
+ : TestCase ("Check string context-based Names::Rename functionality")
+{
+}
+
+StringContextRenameTestCase::~StringContextRenameTestCase ()
+{
+}
+
+void
+StringContextRenameTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+StringContextRenameTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names", "Name", objectOne);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name", "Child", childOfObjectOne);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
+
+ Names::Rename ("/Names", "Name", "New Name");
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ Names::Rename ("/Names/New Name", "Child", "New Child");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can rename objects
+// using a fully qualified path name
+//
+// Rename (std::string oldpath, std::string newname);
+// ===========================================================================
+class FullyQualifiedRenameTestCase : public TestCase
+{
+public:
+ FullyQualifiedRenameTestCase ();
+ virtual ~FullyQualifiedRenameTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+FullyQualifiedRenameTestCase::FullyQualifiedRenameTestCase ()
+ : TestCase ("Check fully qualified path Names::Rename functionality")
+{
+}
+
+FullyQualifiedRenameTestCase::~FullyQualifiedRenameTestCase ()
+{
+}
+
+void
+FullyQualifiedRenameTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+FullyQualifiedRenameTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name", objectOne);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name/Child", childOfObjectOne);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
+
+ Names::Rename ("/Names/Name", "New Name");
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ Names::Rename ("/Names/New Name/Child", "New Child");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can rename objects
+// using a relaltive path name
+//
+// Rename (std::string oldpath, std::string newname);
+// ===========================================================================
+class RelativeRenameTestCase : public TestCase
+{
+public:
+ RelativeRenameTestCase ();
+ virtual ~RelativeRenameTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+RelativeRenameTestCase::RelativeRenameTestCase ()
+ : TestCase ("Check relative path Names::Rename functionality")
+{
+}
+
+RelativeRenameTestCase::~RelativeRenameTestCase ()
+{
+}
+
+void
+RelativeRenameTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+RelativeRenameTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name", objectOne);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("Name/Child", childOfObjectOne);
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Name", "Could not Names::Add and Names::FindName an Object");
+
+ Names::Rename ("Name", "New Name");
+
+ found = Names::FindName (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Name", "Could not Names::Rename an Object");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "Child", "Could not Names::Add and Names::FindName a child Object");
+
+ Names::Rename ("New Name/Child", "New Child");
+
+ found = Names::FindName (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "New Child", "Could not Names::Rename a child Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can look up an object
+// and return its fully qualified path name
+//
+// FindPath (Ptr<Object> object);
+// ===========================================================================
+class FindPathTestCase : public TestCase
+{
+public:
+ FindPathTestCase ();
+ virtual ~FindPathTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+FindPathTestCase::FindPathTestCase ()
+ : TestCase ("Check Names::FindPath functionality")
+{
+}
+
+FindPathTestCase::~FindPathTestCase ()
+{
+}
+
+void
+FindPathTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+FindPathTestCase::DoRun (void)
+{
+ std::string found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name", objectOne);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name/Child", childOfObjectOne);
+
+ found = Names::FindPath (objectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name", "Could not Names::Add and Names::FindPath an Object");
+
+ found = Names::FindPath (childOfObjectOne);
+ NS_TEST_ASSERT_MSG_EQ (found, "/Names/Name/Child", "Could not Names::Add and Names::FindPath a child Object");
+
+ Ptr<TestObject> objectNotThere = CreateObject<TestObject> ();
+ found = Names::FindPath (objectNotThere);
+ NS_TEST_ASSERT_MSG_EQ (found, "", "Unexpectedly found a non-existent Object");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can find Objects using
+// the lowest level find function, which is:
+//
+// Find (Ptr<Object> context, std::string name);
+// ===========================================================================
+class BasicFindTestCase : public TestCase
+{
+public:
+ BasicFindTestCase ();
+ virtual ~BasicFindTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+BasicFindTestCase::BasicFindTestCase ()
+ : TestCase ("Check low level Names::Find functionality")
+{
+}
+
+BasicFindTestCase::~BasicFindTestCase ()
+{
+}
+
+void
+BasicFindTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+BasicFindTestCase::DoRun (void)
+{
+ Ptr<TestObject> found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two/Child", childOfObjectTwo);
+
+ found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name One");
+ NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via object context");
+
+ found = Names::Find<TestObject> (Ptr<Object> (0, false), "Name Two");
+ NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via object context");
+
+ found = Names::Find<TestObject> (objectOne, "Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via object context");
+
+ found = Names::Find<TestObject> (objectTwo, "Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via object context");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can find Objects using
+// a string context-based find function, which is:
+//
+// Find (std::string context, std::string name);
+// ===========================================================================
+class StringContextFindTestCase : public TestCase
+{
+public:
+ StringContextFindTestCase ();
+ virtual ~StringContextFindTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+StringContextFindTestCase::StringContextFindTestCase ()
+ : TestCase ("Check string context-based Names::Find functionality")
+{
+}
+
+StringContextFindTestCase::~StringContextFindTestCase ()
+{
+}
+
+void
+StringContextFindTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+StringContextFindTestCase::DoRun (void)
+{
+ Ptr<TestObject> found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two/Child", childOfObjectTwo);
+
+ found = Names::Find<TestObject> ("/Names", "Name One");
+ NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
+
+ found = Names::Find<TestObject> ("/Names", "Name Two");
+ NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
+
+ found = Names::Find<TestObject> ("/Names/Name One", "Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
+
+ found = Names::Find<TestObject> ("/Names/Name Two", "Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can find Objects using
+// a fully qualified path name-based find function, which is:
+//
+// Find (std::string name);
+// ===========================================================================
+class FullyQualifiedFindTestCase : public TestCase
+{
+public:
+ FullyQualifiedFindTestCase ();
+ virtual ~FullyQualifiedFindTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+FullyQualifiedFindTestCase::FullyQualifiedFindTestCase ()
+ : TestCase ("Check fully qualified path Names::Find functionality")
+{
+}
+
+FullyQualifiedFindTestCase::~FullyQualifiedFindTestCase ()
+{
+}
+
+void
+FullyQualifiedFindTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+FullyQualifiedFindTestCase::DoRun (void)
+{
+ Ptr<TestObject> found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("/Names/Name Two/Child", childOfObjectTwo);
+
+ found = Names::Find<TestObject> ("/Names/Name One");
+ NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
+
+ found = Names::Find<TestObject> ("/Names/Name Two");
+ NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
+
+ found = Names::Find<TestObject> ("/Names/Name One/Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
+
+ found = Names::Find<TestObject> ("/Names/Name Two/Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can find Objects using
+// a relative path name-based find function, which is:
+//
+// Find (std::string name);
+// ===========================================================================
+class RelativeFindTestCase : public TestCase
+{
+public:
+ RelativeFindTestCase ();
+ virtual ~RelativeFindTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+RelativeFindTestCase::RelativeFindTestCase ()
+ : TestCase ("Check relative path Names::Find functionality")
+{
+}
+
+RelativeFindTestCase::~RelativeFindTestCase ()
+{
+}
+
+void
+RelativeFindTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+RelativeFindTestCase::DoRun (void)
+{
+ Ptr<TestObject> found;
+
+ Ptr<TestObject> objectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One", objectOne);
+
+ Ptr<TestObject> objectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two", objectTwo);
+
+ Ptr<TestObject> childOfObjectOne = CreateObject<TestObject> ();
+ Names::Add ("Name One/Child", childOfObjectOne);
+
+ Ptr<TestObject> childOfObjectTwo = CreateObject<TestObject> ();
+ Names::Add ("Name Two/Child", childOfObjectTwo);
+
+ found = Names::Find<TestObject> ("Name One");
+ NS_TEST_ASSERT_MSG_EQ (found, objectOne, "Could not find a previously named Object via string context");
+
+ found = Names::Find<TestObject> ("Name Two");
+ NS_TEST_ASSERT_MSG_EQ (found, objectTwo, "Could not find a previously named Object via stribng context");
+
+ found = Names::Find<TestObject> ("Name One/Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectOne, "Could not find a previously named child Object via string context");
+
+ found = Names::Find<TestObject> ("Name Two/Child");
+ NS_TEST_ASSERT_MSG_EQ (found, childOfObjectTwo, "Could not find a previously named child Object via string context");
+
+ return false;
+}
+
+// ===========================================================================
+// Test case to make sure that the Object Name Service can find Objects using
+// a second type.
+// ===========================================================================
+class AlternateFindTestCase : public TestCase
+{
+public:
+ AlternateFindTestCase ();
+ virtual ~AlternateFindTestCase ();
+
+private:
+ virtual bool DoRun (void);
+ virtual void DoTeardown (void);
+};
+
+AlternateFindTestCase::AlternateFindTestCase ()
+ : TestCase ("Check GetObject operation in Names::Find")
+{
+}
+
+AlternateFindTestCase::~AlternateFindTestCase ()
+{
+}
+
+void
+AlternateFindTestCase::DoTeardown (void)
+{
+ Names::Clear ();
+}
+
+bool
+AlternateFindTestCase::DoRun (void)
+{
+ Ptr<TestObject> testObject = CreateObject<TestObject> ();
+ Names::Add ("Test Object", testObject);
+
+ Ptr<AlternateTestObject> alternateTestObject = CreateObject<AlternateTestObject> ();
+ Names::Add ("Alternate Test Object", alternateTestObject);
+
+ Ptr<TestObject> foundTestObject;
+ Ptr<AlternateTestObject> foundAlternateTestObject;
+
+ foundTestObject = Names::Find<TestObject> ("Test Object");
+ NS_TEST_ASSERT_MSG_EQ (foundTestObject, testObject,
+ "Could not find a previously named TestObject via GetObject");
+
+ foundAlternateTestObject = Names::Find<AlternateTestObject> ("Alternate Test Object");
+ NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, alternateTestObject,
+ "Could not find a previously named AlternateTestObject via GetObject");
+
+
+ foundAlternateTestObject = Names::Find<AlternateTestObject> ("Test Object");
+ NS_TEST_ASSERT_MSG_EQ (foundAlternateTestObject, 0,
+ "Unexpectedly able to GetObject<AlternateTestObject> on a TestObject");
+
+ foundTestObject = Names::Find<TestObject> ("Alternate Test Object");
+ NS_TEST_ASSERT_MSG_EQ (foundTestObject, 0,
+ "Unexpectedly able to GetObject<TestObject> on an AlternateTestObject");
+
+ return false;
+}
+
+class NamesTestSuite : public TestSuite
+{
+public:
+ NamesTestSuite ();
+};
+
+NamesTestSuite::NamesTestSuite ()
+ : TestSuite ("object-name-service", UNIT)
+{
+ AddTestCase (new BasicAddTestCase);
+ AddTestCase (new StringContextAddTestCase);
+ AddTestCase (new FullyQualifiedAddTestCase);
+ AddTestCase (new RelativeAddTestCase);
+ AddTestCase (new BasicRenameTestCase);
+ AddTestCase (new StringContextRenameTestCase);
+ AddTestCase (new FullyQualifiedRenameTestCase);
+ AddTestCase (new RelativeRenameTestCase);
+ AddTestCase (new FindPathTestCase);
+ AddTestCase (new BasicFindTestCase);
+ AddTestCase (new StringContextFindTestCase);
+ AddTestCase (new FullyQualifiedFindTestCase);
+ AddTestCase (new RelativeFindTestCase);
+ AddTestCase (new AlternateFindTestCase);
+}
+
+NamesTestSuite namesTestSuite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/ptr-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,274 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2005,2006 INRIA
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
+ */
+
+#include "model/test.h"
+#include "model/ptr.h"
+
+namespace ns3 {
+
+class PtrTestCase;
+
+class Base
+{
+public:
+ Base ();
+ virtual ~Base ();
+ void Ref (void) const;
+ void Unref (void) const;
+private:
+ mutable uint32_t m_count;
+};
+
+class NoCount : public Base
+{
+public:
+ NoCount (PtrTestCase *test);
+ ~NoCount ();
+ void Nothing (void) const;
+private:
+ PtrTestCase *m_test;
+};
+
+
+class PtrTestCase : public TestCase
+{
+public:
+ PtrTestCase ();
+ void DestroyNotify (void);
+private:
+ virtual bool DoRun (void);
+ Ptr<NoCount> CallTest (Ptr<NoCount> p);
+ Ptr<NoCount> const CallTestConst (Ptr<NoCount> const p);
+ uint32_t m_nDestroyed;
+};
+
+
+Base::Base ()
+ : m_count (1)
+{}
+Base::~Base ()
+{}
+void
+Base::Ref (void) const
+{
+ m_count++;
+}
+void
+Base::Unref (void) const
+{
+ m_count--;
+ if (m_count == 0)
+ {
+ delete this;
+ }
+}
+
+NoCount::NoCount (PtrTestCase *test)
+ : m_test (test)
+{}
+NoCount::~NoCount ()
+{
+ m_test->DestroyNotify ();
+}
+void
+NoCount::Nothing () const
+{}
+
+
+
+PtrTestCase::PtrTestCase (void)
+ : TestCase ("Sanity checking of Ptr<>")
+{}
+void
+PtrTestCase::DestroyNotify (void)
+{
+ m_nDestroyed++;
+}
+Ptr<NoCount>
+PtrTestCase::CallTest (Ptr<NoCount> p)
+{
+ return p;
+}
+
+Ptr<NoCount> const
+PtrTestCase::CallTestConst (Ptr<NoCount> const p)
+{
+ return p;
+}
+
+
+bool
+PtrTestCase::DoRun (void)
+{
+ m_nDestroyed = false;
+ {
+ Ptr<NoCount> p = Create<NoCount> (this);
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p;
+ p = Create<NoCount> (this);
+ p = p;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ p1 = Create<NoCount> (this);
+ Ptr<NoCount> p2 = p1;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ p1 = Create<NoCount> (this);
+ Ptr<NoCount> p2;
+ p2 = p1;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ p1 = Create<NoCount> (this);
+ Ptr<NoCount> p2 = Create<NoCount> (this);
+ p2 = p1;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ p1 = Create<NoCount> (this);
+ Ptr<NoCount> p2;
+ p2 = Create<NoCount> (this);
+ p2 = p1;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ p1 = Create<NoCount> (this);
+ p1 = Create<NoCount> (this);
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ {
+ Ptr<NoCount> p2;
+ p1 = Create<NoCount> (this);
+ p2 = Create<NoCount> (this);
+ p2 = p1;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p1;
+ {
+ Ptr<NoCount> p2;
+ p1 = Create<NoCount> (this);
+ p2 = Create<NoCount> (this);
+ p2 = CallTest (p1);
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 2, "XXX");
+
+ {
+ Ptr<NoCount> p1;
+ Ptr<NoCount> const p2 = CallTest (p1);
+ Ptr<NoCount> const p3 = CallTestConst (p1);
+ Ptr<NoCount> p4 = CallTestConst (p1);
+ Ptr<NoCount const> p5 = p4;
+ //p4 = p5; You cannot make a const pointer be a non-const pointer.
+ // but if you use ConstCast, you can.
+ p4 = ConstCast<NoCount> (p5);
+ p5 = p1;
+ Ptr<NoCount> p;
+ if (p == 0)
+ {}
+ if (p != 0)
+ {}
+ if (0 == p)
+ {}
+ if (0 != p)
+ {}
+ if (p)
+ {}
+ if (!p)
+ {}
+ }
+
+ m_nDestroyed = 0;
+ {
+ NoCount *raw;
+ {
+ Ptr<NoCount> p = Create<NoCount> (this);
+ {
+ Ptr<NoCount const> p1 = p;
+ }
+ raw = GetPointer (p);
+ p = 0;
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 0, "XXX");
+ delete raw;
+ }
+
+ m_nDestroyed = 0;
+ {
+ Ptr<NoCount> p = Create<NoCount> (this);
+ const NoCount *v1 = PeekPointer (p);
+ NoCount *v2 = PeekPointer (p);
+ v1->Nothing ();
+ v2->Nothing ();
+ }
+ NS_TEST_EXPECT_MSG_EQ (m_nDestroyed, 1, "XXX");
+
+ {
+ Ptr<Base> p0 = Create<NoCount> (this);
+ Ptr<NoCount> p1 = Create<NoCount> (this);
+ NS_TEST_EXPECT_MSG_EQ ((p0 == p1), false, "operator == failed");
+ NS_TEST_EXPECT_MSG_EQ ((p0 != p1), true, "operator != failed");
+ }
+
+ return false;
+}
+
+static class PtrTestSuite : public TestSuite
+{
+public:
+ PtrTestSuite ()
+ : TestSuite ("ptr", UNIT)
+ {
+ AddTestCase (new PtrTestCase ());
+ }
+} g_ptrTestSuite;
+
+} // namespace ns3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/rng-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,434 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include <math.h>
+#include <gsl/gsl_cdf.h>
+#include <gsl/gsl_histogram.h>
+#include <time.h>
+#include <fstream>
+
+#include "model/test.h"
+#include "model/random-variable.h"
+
+using namespace ns3;
+
+void
+FillHistoRangeUniformly (double *array, uint32_t n, double start, double end)
+{
+ double increment = (end - start) / (n - 1.);
+ double d = start;
+
+ for (uint32_t i = 0; i < n; ++i)
+ {
+ array[i] = d;
+ d += increment;
+ }
+}
+
+// ===========================================================================
+// Test case for uniform distribution random number generator
+// ===========================================================================
+class RngUniformTestCase : public TestCase
+{
+public:
+ static const uint32_t N_RUNS = 5;
+ static const uint32_t N_BINS = 50;
+ static const uint32_t N_MEASUREMENTS = 1000000;
+
+ RngUniformTestCase ();
+ virtual ~RngUniformTestCase ();
+
+ double ChiSquaredTest (UniformVariable &u);
+
+private:
+ virtual bool DoRun (void);
+};
+
+RngUniformTestCase::RngUniformTestCase ()
+ : TestCase ("Uniform Random Number Generator")
+{
+}
+
+RngUniformTestCase::~RngUniformTestCase ()
+{
+}
+
+double
+RngUniformTestCase::ChiSquaredTest (UniformVariable &u)
+{
+ gsl_histogram * h = gsl_histogram_alloc (N_BINS);
+ gsl_histogram_set_ranges_uniform (h, 0., 1.);
+
+ for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
+ {
+ gsl_histogram_increment (h, u.GetValue ());
+ }
+
+ double tmp[N_BINS];
+
+ double expected = ((double)N_MEASUREMENTS / (double)N_BINS);
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ tmp[i] = gsl_histogram_get (h, i);
+ tmp[i] -= expected;
+ tmp[i] *= tmp[i];
+ tmp[i] /= expected;
+ }
+
+ gsl_histogram_free (h);
+
+ double chiSquared = 0;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ chiSquared += tmp[i];
+ }
+
+ return chiSquared;
+}
+
+bool
+RngUniformTestCase::DoRun (void)
+{
+ SeedManager::SetSeed (time (0));
+
+ double sum = 0.;
+ double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
+
+ for (uint32_t i = 0; i < N_RUNS; ++i)
+ {
+ UniformVariable u;
+ double result = ChiSquaredTest (u);
+ sum += result;
+ }
+
+ sum /= (double)N_RUNS;
+
+ NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
+ return false;
+}
+
+// ===========================================================================
+// Test case for normal distribution random number generator
+// ===========================================================================
+class RngNormalTestCase : public TestCase
+{
+public:
+ static const uint32_t N_RUNS = 5;
+ static const uint32_t N_BINS = 50;
+ static const uint32_t N_MEASUREMENTS = 1000000;
+
+ RngNormalTestCase ();
+ virtual ~RngNormalTestCase ();
+
+ double ChiSquaredTest (NormalVariable &n);
+
+private:
+ virtual bool DoRun (void);
+};
+
+RngNormalTestCase::RngNormalTestCase ()
+ : TestCase ("Normal Random Number Generator")
+{
+}
+
+RngNormalTestCase::~RngNormalTestCase ()
+{
+}
+
+double
+RngNormalTestCase::ChiSquaredTest (NormalVariable &n)
+{
+ gsl_histogram * h = gsl_histogram_alloc (N_BINS);
+
+ double range[N_BINS + 1];
+ FillHistoRangeUniformly (range, N_BINS + 1, -4., 4.);
+ range[0] = -std::numeric_limits<double>::max ();
+ range[N_BINS] = std::numeric_limits<double>::max ();
+
+ gsl_histogram_set_ranges (h, range, N_BINS + 1);
+
+ double expected[N_BINS];
+
+ double sigma = 1.;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ expected[i] = gsl_cdf_gaussian_P (range[i + 1], sigma) - gsl_cdf_gaussian_P (range[i], sigma);
+ expected[i] *= N_MEASUREMENTS;
+ }
+
+ for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
+ {
+ gsl_histogram_increment (h, n.GetValue ());
+ }
+
+ double tmp[N_BINS];
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ tmp[i] = gsl_histogram_get (h, i);
+ tmp[i] -= expected[i];
+ tmp[i] *= tmp[i];
+ tmp[i] /= expected[i];
+ }
+
+ gsl_histogram_free (h);
+
+ double chiSquared = 0;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ chiSquared += tmp[i];
+ }
+
+ return chiSquared;
+}
+
+bool
+RngNormalTestCase::DoRun (void)
+{
+ SeedManager::SetSeed (time (0));
+
+ double sum = 0.;
+ double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
+
+ for (uint32_t i = 0; i < N_RUNS; ++i)
+ {
+ NormalVariable n;
+ double result = ChiSquaredTest (n);
+ sum += result;
+ }
+
+ sum /= (double)N_RUNS;
+
+ NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
+ return false;
+}
+
+// ===========================================================================
+// Test case for exponential distribution random number generator
+// ===========================================================================
+class RngExponentialTestCase : public TestCase
+{
+public:
+ static const uint32_t N_RUNS = 5;
+ static const uint32_t N_BINS = 50;
+ static const uint32_t N_MEASUREMENTS = 1000000;
+
+ RngExponentialTestCase ();
+ virtual ~RngExponentialTestCase ();
+
+ double ChiSquaredTest (ExponentialVariable &n);
+
+private:
+ virtual bool DoRun (void);
+};
+
+RngExponentialTestCase::RngExponentialTestCase ()
+ : TestCase ("Exponential Random Number Generator")
+{
+}
+
+RngExponentialTestCase::~RngExponentialTestCase ()
+{
+}
+
+double
+RngExponentialTestCase::ChiSquaredTest (ExponentialVariable &e)
+{
+ gsl_histogram * h = gsl_histogram_alloc (N_BINS);
+
+ double range[N_BINS + 1];
+ FillHistoRangeUniformly (range, N_BINS + 1, 0., 10.);
+ range[N_BINS] = std::numeric_limits<double>::max ();
+
+ gsl_histogram_set_ranges (h, range, N_BINS + 1);
+
+ double expected[N_BINS];
+
+ double mu = 1.;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ expected[i] = gsl_cdf_exponential_P (range[i + 1], mu) - gsl_cdf_exponential_P (range[i], mu);
+ expected[i] *= N_MEASUREMENTS;
+ }
+
+ for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
+ {
+ gsl_histogram_increment (h, e.GetValue ());
+ }
+
+ double tmp[N_BINS];
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ tmp[i] = gsl_histogram_get (h, i);
+ tmp[i] -= expected[i];
+ tmp[i] *= tmp[i];
+ tmp[i] /= expected[i];
+ }
+
+ gsl_histogram_free (h);
+
+ double chiSquared = 0;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ chiSquared += tmp[i];
+ }
+
+ return chiSquared;
+}
+
+bool
+RngExponentialTestCase::DoRun (void)
+{
+ SeedManager::SetSeed (time (0));
+
+ double sum = 0.;
+ double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
+
+ for (uint32_t i = 0; i < N_RUNS; ++i)
+ {
+ ExponentialVariable e;
+ double result = ChiSquaredTest (e);
+ sum += result;
+ }
+
+ sum /= (double)N_RUNS;
+
+ NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
+ return false;
+}
+
+// ===========================================================================
+// Test case for pareto distribution random number generator
+// ===========================================================================
+class RngParetoTestCase : public TestCase
+{
+public:
+ static const uint32_t N_RUNS = 5;
+ static const uint32_t N_BINS = 50;
+ static const uint32_t N_MEASUREMENTS = 1000000;
+
+ RngParetoTestCase ();
+ virtual ~RngParetoTestCase ();
+
+ double ChiSquaredTest (ParetoVariable &p);
+
+private:
+ virtual bool DoRun (void);
+};
+
+RngParetoTestCase::RngParetoTestCase ()
+ : TestCase ("Pareto Random Number Generator")
+{
+}
+
+RngParetoTestCase::~RngParetoTestCase ()
+{
+}
+
+double
+RngParetoTestCase::ChiSquaredTest (ParetoVariable &p)
+{
+ gsl_histogram * h = gsl_histogram_alloc (N_BINS);
+
+ double range[N_BINS + 1];
+ FillHistoRangeUniformly (range, N_BINS + 1, 1., 10.);
+ range[N_BINS] = std::numeric_limits<double>::max ();
+
+ gsl_histogram_set_ranges (h, range, N_BINS + 1);
+
+ double expected[N_BINS];
+
+ double a = 1.5;
+ double b = 0.33333333;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ expected[i] = gsl_cdf_pareto_P (range[i + 1], a, b) - gsl_cdf_pareto_P (range[i], a, b);
+ expected[i] *= N_MEASUREMENTS;
+ }
+
+ for (uint32_t i = 0; i < N_MEASUREMENTS; ++i)
+ {
+ gsl_histogram_increment (h, p.GetValue ());
+ }
+
+ double tmp[N_BINS];
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ tmp[i] = gsl_histogram_get (h, i);
+ tmp[i] -= expected[i];
+ tmp[i] *= tmp[i];
+ tmp[i] /= expected[i];
+ }
+
+ gsl_histogram_free (h);
+
+ double chiSquared = 0;
+
+ for (uint32_t i = 0; i < N_BINS; ++i)
+ {
+ chiSquared += tmp[i];
+ }
+
+ return chiSquared;
+}
+
+bool
+RngParetoTestCase::DoRun (void)
+{
+ SeedManager::SetSeed (time (0));
+
+ double sum = 0.;
+ double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS);
+
+ for (uint32_t i = 0; i < N_RUNS; ++i)
+ {
+ ParetoVariable e;
+ double result = ChiSquaredTest (e);
+ sum += result;
+ }
+
+ sum /= (double)N_RUNS;
+
+ NS_TEST_ASSERT_MSG_LT (sum, maxStatistic, "Chi-squared statistic out of range");
+ return false;
+}
+
+class RngTestSuite : public TestSuite
+{
+public:
+ RngTestSuite ();
+};
+
+RngTestSuite::RngTestSuite ()
+ : TestSuite ("random-number-generators", UNIT)
+{
+ AddTestCase (new RngUniformTestCase);
+ AddTestCase (new RngNormalTestCase);
+ AddTestCase (new RngExponentialTestCase);
+ AddTestCase (new RngParetoTestCase);
+}
+
+RngTestSuite rngTestSuite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/traced-callback-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,125 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "model/test.h"
+#include "model/traced-callback.h"
+
+using namespace ns3;
+
+class BasicTracedCallbackTestCase : public TestCase
+{
+public:
+ BasicTracedCallbackTestCase ();
+ virtual ~BasicTracedCallbackTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+
+ void CbOne (uint8_t a, double b);
+ void CbTwo (uint8_t a, double b);
+
+ bool m_one;
+ bool m_two;
+};
+
+BasicTracedCallbackTestCase::BasicTracedCallbackTestCase ()
+ : TestCase ("Check basic TracedCallback operation")
+{
+}
+
+void
+BasicTracedCallbackTestCase::CbOne (uint8_t a, double b)
+{
+ m_one = true;
+}
+
+void
+BasicTracedCallbackTestCase::CbTwo (uint8_t a, double b)
+{
+ m_two = true;
+}
+
+bool
+BasicTracedCallbackTestCase::DoRun (void)
+{
+ //
+ // Create a traced callback and connect it up to our target methods. All that
+ // these methods do is to set corresponding member variables m_one and m_two.
+ //
+ TracedCallback<uint8_t, double> trace;
+
+ //
+ // Connect both callbacks to their respective test methods. If we hit the
+ // trace, both callbacks should be called and the two variables should be set
+ // to true.
+ //
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ //
+ // If we now disconnect callback one then only callback two should be called.
+ //
+ trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ //
+ // If we now disconnect callback two then neither callback should be called.
+ //
+ trace.DisconnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, false, "Callback CbOne unexpectedly called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, false, "Callback CbTwo unexpectedly called");
+
+ //
+ // If we connect them back up, then both callbacks should be called.
+ //
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbOne, this));
+ trace.ConnectWithoutContext (MakeCallback (&BasicTracedCallbackTestCase::CbTwo, this));
+ m_one = false;
+ m_two = false;
+ trace (1, 2);
+ NS_TEST_ASSERT_MSG_EQ (m_one, true, "Callback CbOne not called");
+ NS_TEST_ASSERT_MSG_EQ (m_two, true, "Callback CbTwo not called");
+
+ return GetErrorStatus ();
+}
+
+class TracedCallbackTestSuite : public TestSuite
+{
+public:
+ TracedCallbackTestSuite ();
+};
+
+TracedCallbackTestSuite::TracedCallbackTestSuite ()
+ : TestSuite ("traced-callback", UNIT)
+{
+ AddTestCase (new BasicTracedCallbackTestCase);
+}
+
+TracedCallbackTestSuite tracedCallbackTestSuite;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/simulator/test/type-traits-test-suite.cc Sat Dec 18 13:32:36 2010 -0800
@@ -0,0 +1,66 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * Copyright (c) 2009 University of Washington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation;
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "model/type-traits.h"
+#include "model/test.h"
+
+namespace ns3 {
+
+class TypeTraitsTestCase : public TestCase
+{
+public:
+ TypeTraitsTestCase ();
+ virtual ~TypeTraitsTestCase () {}
+
+private:
+ virtual bool DoRun (void);
+};
+
+TypeTraitsTestCase::TypeTraitsTestCase (void)
+ : TestCase ("Check type traits")
+{
+}
+
+bool
+TypeTraitsTestCase::DoRun (void)
+{
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void)>::IsPointerToMember, 1, "Check");
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void) const>::IsPointerToMember, 1, "Check");
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int)>::IsPointerToMember, 1, "Check");
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int) const>::IsPointerToMember, 1, "Check");
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (void) const>::PointerToMemberTraits::nArgs, 0, "Check");
+ NS_TEST_ASSERT_MSG_EQ (TypeTraits<void (TypeTraitsTestCase::*) (int) const>::PointerToMemberTraits::nArgs, 1, "Check");
+
+ return GetErrorStatus ();
+}
+
+class TypeTraitsTestSuite : public TestSuite
+{
+public:
+ TypeTraitsTestSuite ();
+};
+
+TypeTraitsTestSuite::TypeTraitsTestSuite ()
+ : TestSuite ("type-traits", UNIT)
+{
+ AddTestCase (new TypeTraitsTestCase);
+}
+
+TypeTraitsTestSuite typeTraitsTestSuite;
+
+} // namespace ns3
--- a/modules/simulator/wscript Thu Dec 16 09:55:26 2010 -0800
+++ b/modules/simulator/wscript Sat Dec 18 13:32:36 2010 -0800
@@ -117,12 +117,6 @@
'model/callback.cc',
'model/names.cc',
'model/vector.cc',
- 'model/attribute-test-suite.cc',
- 'model/callback-test-suite.cc',
- 'model/names-test-suite.cc',
- 'model/type-traits-test-suite.cc',
- 'model/traced-callback-test-suite.cc',
- 'model/ptr-test-suite.cc',
'model/fatal-impl.cc',
'model/high-precision.cc',
'model/time-base.cc',
@@ -144,6 +138,16 @@
'model/make-event.cc',
]
+ sim_test = bld.create_ns3_module_test_library('simulator', ['simulator'])
+ sim_test.source = [
+ 'test/attribute-test-suite.cc',
+ 'test/callback-test-suite.cc',
+ 'test/names-test-suite.cc',
+ 'test/type-traits-test-suite.cc',
+ 'test/traced-callback-test-suite.cc',
+ 'test/ptr-test-suite.cc',
+ ]
+
headers = bld.new_task_gen('ns3header')
headers.module = 'simulator'
headers.source = [
@@ -228,7 +232,8 @@
'model/unix-system-mutex.cc',
'model/unix-system-condition.cc',
])
- sim.uselib = 'PTHREAD'
+ sim .uselib = 'PTHREAD'
+ sim_test.uselib = 'PTHREAD'
headers.source.extend([
'model/system-mutex.h',
'model/system-thread.h',
@@ -236,8 +241,9 @@
])
if bld.env['ENABLE_GSL']:
- sim.uselib = sim.uselib + ' GSL GSLCBLAS M'
- sim.source.extend(['model/rng-test-suite.cc'])
+ sim.uselib = sim.uselib + ' GSL GSLCBLAS M'
+ sim_test.uselib = sim_test.uselib + ' GSL GSLCBLAS M'
+ sim_test.source.extend(['test/rng-test-suite.cc'])
env = bld.env_of_name('default')
if env['USE_HIGH_PRECISION_DOUBLE']:
@@ -264,5 +270,6 @@
'model/realtime-simulator-impl.cc',
'model/wall-clock-synchronizer.cc',
])
- sim.uselib = sim.uselib + ' RT'
+ sim .uselib = sim.uselib + ' RT'
+ sim_test.uselib = sim_test.uselib + ' RT'
--- a/modules/wscript Thu Dec 16 09:55:26 2010 -0800
+++ b/modules/wscript Sat Dec 18 13:32:36 2010 -0800
@@ -132,6 +132,25 @@
module.env.append_value('CCDEFINES', "NS3_MODULE_COMPILATION")
return module
+def create_ns3_module_test_library(bld, name, dependencies=()):
+ # Create an ns3 module for the test library.
+ library_name = name + "-test"
+ library = bld.create_ns3_module(library_name, dependencies)
+
+ # Modify attributes for the test library that are different from a
+ # normal module.
+ del library.is_ns3_module
+ library.is_ns3_module_test_library = True
+ library.module_name = 'ns3-' + name
+
+ # Set the include path from the build directory to modules.
+ relative_path_from_build_to_here = bld.path.relpath_gen(bld.bldnode)
+ include_flag = '-I' + relative_path_from_build_to_here
+ library.env.append_value('CXXFLAGS', include_flag)
+ library.env.append_value('CCFLAGS', include_flag)
+
+ return library
+
def create_obj(bld, *args):
warnings.warn("(in %s) Use bld.new_task_gen(...) now, instead of bld.create_obj(...)" % str(bld.path),
DeprecationWarning, stacklevel=2)
@@ -139,6 +158,7 @@
def build(bld):
bld.create_ns3_module = types.MethodType(create_ns3_module, bld)
+ bld.create_ns3_module_test_library = types.MethodType(create_ns3_module_test_library, bld)
bld.create_obj = types.MethodType(create_obj, bld)
bld.add_subdirs(list(all_modules))
--- a/util.py Thu Dec 16 09:55:26 2010 -0800
+++ b/util.py Sat Dec 18 13:32:36 2010 -0800
@@ -33,7 +33,8 @@
parsing_multiline_list = True
else:
# Evaluate the list once its end is reached.
- list = eval(list_string.split('=')[1].strip())
+ # Make the split function only split it once.
+ list = eval(list_string.split('=', 1)[1].strip())
break
# Close the file
--- a/wscript Thu Dec 16 09:55:26 2010 -0800
+++ b/wscript Sat Dec 18 13:32:36 2010 -0800
@@ -604,6 +604,10 @@
if hasattr(obj, "is_ns3_module") and obj.name not in modules:
exclude_taskgen(bld, obj) # kill the module
+ # disable the module test libraries
+ if hasattr(obj, "is_ns3_module_test_library") and obj.module_name not in modules:
+ exclude_taskgen(bld, obj) # kill the module test library
+
# disable the ns3header_taskgen
if type(obj).__name__ == 'ns3header_taskgen':
if ("ns3-%s" % obj.module) not in modules: