22 #include "ns3/object.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/assert.h"
57 .SetGroupName (
"Core")
82 .SetGroupName (
"Core")
83 .HideFromDocumentation ()
113 .SetGroupName (
"Core")
138 .SetGroupName (
"Core")
139 .HideFromDocumentation ()
179 virtual void DoRun (
void);
183 :
TestCase (
"Check CreateObject<Type> template function")
198 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"GetObject() of same type returns different Ptr");
203 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"GetObject() of unrelated type returns nonzero pointer");
209 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"GetObject() of unrelated returns nonzero Ptr");
211 baseA = CreateObject<DerivedA> ();
224 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA,
"GetObject() of the original type returns different Ptr");
230 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA,
"GetObject returns different Ptr");
246 virtual void DoRun (
void);
250 :
TestCase (
"Check Object aggregation functionality")
271 baseA->AggregateObject (baseB);
277 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseA) for BaseA Object");
283 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseA");
288 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
294 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseA");
299 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
305 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseB");
311 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
317 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseB");
325 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
330 baseA = CreateObject<DerivedA> ();
333 baseB = CreateObject<DerivedB> ();
341 baseA->AggregateObject (baseB);
346 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseA) for DerivedB Object");
352 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
357 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseB) for DerivedA Object");
363 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
372 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
373 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
379 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseB) for DerivedB Object");
385 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
392 baseA = CreateObject<BaseA> ();
395 baseB = CreateObject<BaseB> ();
398 baseA->AggregateObject (baseB);
401 baseA = baseB->GetObject<BaseA> ();
418 virtual void DoRun (
void);
422 :
TestCase (
"Check ObjectFactory functionality")
454 factory.
SetTypeId (DerivedA::GetTypeId ());
static ns3::TypeId GetTypeId(void)
Register this type.
static ns3::TypeId GetTypeId(void)
Register this type.
virtual void DoDispose(void)
Destructor implementation.
static ns3::TypeId GetTypeId(void)
Register this type.
static ns3::TypeId GetTypeId(void)
Register this type.
virtual void DoDispose(void)
Destructor implementation.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
A base class which provides memory management and object aggregation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
a unique identifier for an interface.
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Test we can aggregate Objects.
AggregateObjectTestCase()
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual ~AggregateObjectTestCase()
Destructor.
Test we can make Objects using CreateObject.
CreateObjectTestCase()
Constructor.
virtual ~CreateObjectTestCase()
Destructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Test an Object factory can create Objects.
virtual ~ObjectFactoryTestCase()
Destructor.
ObjectFactoryTestCase()
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
The Test Suite that glues the Test Cases together.
ObjectTestSuite()
Constructor.
static ObjectTestSuite g_objectTestSuite
ObjectTestSuite instance variable.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.