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)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
static ObjectTestSuite objectTestSuite
static ns3::TypeId GetTypeId(void)
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)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static ns3::TypeId GetTypeId(void)
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)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
AggregateObjectTestCase()
TypeId HideFromDocumentation(void)