22 #include "ns3/object.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/assert.h"
111 virtual void DoRun (
void);
115 :
TestCase (
"Check CreateObject<Type> template function")
132 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"GetObject() of same type returns different Ptr");
137 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"GetObject() of unrelated type returns nonzero pointer");
143 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"GetObject() of unrelated returns nonzero Ptr");
145 baseA = CreateObject<DerivedA> ();
158 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA,
"GetObject() of the original type returns different Ptr");
164 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA,
"GetObject returns different Ptr");
177 virtual void DoRun (
void);
181 :
TestCase (
"Check Object aggregation functionality")
204 baseA->AggregateObject (baseB);
210 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseA) for BaseA Object");
216 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseA");
221 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
227 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseA");
232 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
238 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseB");
244 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
250 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseB");
258 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
263 baseA = CreateObject<DerivedA> ();
266 baseB = CreateObject<DerivedB> ();
274 baseA->AggregateObject (baseB);
279 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseA) for DerivedB Object");
285 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
290 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseB) for DerivedA Object");
296 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
305 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
306 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
312 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseB) for DerivedB Object");
318 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
325 baseA = CreateObject<BaseA> ();
328 baseB = CreateObject<BaseB> ();
331 baseA->AggregateObject (baseB);
334 baseA = baseB->GetObject<BaseA> ();
348 virtual void DoRun (
void);
352 :
TestCase (
"Check ObjectFactory functionality")
386 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)
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.