22 #include "ns3/object.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/assert.h"
39 .SetGroupName (
"Core")
40 .HideFromDocumentation ()
41 .AddConstructor<
BaseA> ();
60 .SetGroupName (
"Core")
61 .HideFromDocumentation ()
83 .SetGroupName (
"Core")
84 .HideFromDocumentation ()
85 .AddConstructor<
BaseB> ();
104 .SetGroupName (
"Core")
105 .HideFromDocumentation ()
135 virtual void DoRun (
void);
139 :
TestCase (
"Check CreateObject<Type> template function")
156 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"GetObject() of same type returns different Ptr");
161 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"GetObject() of unrelated type returns nonzero pointer");
167 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"GetObject() of unrelated returns nonzero Ptr");
169 baseA = CreateObject<DerivedA> ();
182 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA,
"GetObject() of the original type returns different Ptr");
188 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA,
"GetObject returns different Ptr");
201 virtual void DoRun (
void);
205 :
TestCase (
"Check Object aggregation functionality")
228 baseA->AggregateObject (baseB);
234 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseA) for BaseA Object");
240 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseA");
245 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
251 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseA");
256 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
262 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseB");
268 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
274 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseB");
282 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
287 baseA = CreateObject<DerivedA> ();
290 baseB = CreateObject<DerivedB> ();
298 baseA->AggregateObject (baseB);
303 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseA) for DerivedB Object");
309 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
314 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseB) for DerivedA Object");
320 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
329 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
330 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
336 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseB) for DerivedB Object");
342 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
349 baseA = CreateObject<BaseA> ();
352 baseB = CreateObject<BaseB> ();
355 baseA->AggregateObject (baseB);
358 baseA = baseB->GetObject<BaseA> ();
372 virtual void DoRun (
void);
376 :
TestCase (
"Check ObjectFactory functionality")
410 factory.
SetTypeId (DerivedA::GetTypeId ());
virtual void Dispose(void)
virtual void Dispose(void)
Smart pointer class similar to boost::intrusive_ptr.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
static ObjectTestSuite objectTestSuite
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
static ns3::TypeId GetTypeId(void)
Register this type.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
virtual ~CreateObjectTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void Dispose(void)
virtual ~AggregateObjectTestCase()
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
#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.
static ns3::TypeId GetTypeId(void)
Register this type.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static ns3::TypeId GetTypeId(void)
Register this type.
virtual ~ObjectFactoryTestCase()
virtual void DoRun(void)
Implementation to actually run this TestCase.
Instantiate subclasses of ns3::Object.
virtual void Dispose(void)
#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...
A base class which provides memory management and object aggregation.
static ns3::TypeId GetTypeId(void)
Register this type.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
AggregateObjectTestCase()