22 #include "ns3/object.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/assert.h"
115 virtual void DoRun (
void);
119 :
TestCase (
"Check CreateObject<Type> template function")
136 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"GetObject() of same type returns different Ptr");
141 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"GetObject() of unrelated type returns nonzero pointer");
147 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"GetObject() of unrelated returns nonzero Ptr");
149 baseA = CreateObject<DerivedA> ();
162 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA,
"GetObject() of the original type returns different Ptr");
168 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA,
"GetObject returns different Ptr");
181 virtual void DoRun (
void);
185 :
TestCase (
"Check Object aggregation functionality")
208 baseA->AggregateObject (baseB);
214 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseA) for BaseA Object");
220 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseA");
225 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
231 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseA");
236 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
242 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseB");
248 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
254 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseB");
262 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
267 baseA = CreateObject<DerivedA> ();
270 baseB = CreateObject<DerivedB> ();
278 baseA->AggregateObject (baseB);
283 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseA) for DerivedB Object");
289 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
294 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseB) for DerivedA Object");
300 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
309 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
310 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
316 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseB) for DerivedB Object");
322 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
329 baseA = CreateObject<BaseA> ();
332 baseB = CreateObject<BaseB> ();
335 baseA->AggregateObject (baseB);
338 baseA = baseB->GetObject<BaseA> ();
352 virtual void DoRun (
void);
356 :
TestCase (
"Check ObjectFactory functionality")
390 factory.
SetTypeId (DerivedA::GetTypeId ());
virtual void Dispose(void)
virtual void Dispose(void)
smart pointer class similar to boost::intrusive_ptr
TypeId AddConstructor(void)
virtual ~AggregateObjectTestCase()
static ns3::TypeId GetTypeId(void)
void SetTypeId(TypeId tid)
#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...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
virtual ~CreateObjectTestCase()
virtual void Dispose(void)
static ObjectTestSuite objectTestSuite
Ptr< Object > Create(void) const
static ns3::TypeId GetTypeId(void)
static ns3::TypeId GetTypeId(void)
AggregateObjectTestCase()
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
instantiate subclasses of ns3::Object.
virtual void Dispose(void)
virtual ~ObjectFactoryTestCase()
a base class which provides memory management and object aggregation
static ns3::TypeId GetTypeId(void)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
virtual void DoRun(void)
Implementation to actually run this TestCase.
#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.
TypeId HideFromDocumentation(void)
virtual void DoRun(void)
Implementation to actually run this TestCase.
virtual void DoRun(void)
Implementation to actually run this TestCase.