22 #include "ns3/object.h"
23 #include "ns3/object-factory.h"
24 #include "ns3/assert.h"
34 .HideFromDocumentation ()
40 virtual void Dispose (
void) {}
49 .HideFromDocumentation ()
55 virtual void Dispose (
void) {
66 .HideFromDocumentation ()
72 virtual void Dispose (
void) {}
81 .HideFromDocumentation ()
87 virtual void Dispose (
void) {
92 NS_OBJECT_ENSURE_REGISTERED (
BaseA);
93 NS_OBJECT_ENSURE_REGISTERED (
DerivedA);
94 NS_OBJECT_ENSURE_REGISTERED (
BaseB);
95 NS_OBJECT_ENSURE_REGISTERED (
DerivedB);
111 virtual void DoRun (
void);
114 CreateObjectTestCase::CreateObjectTestCase ()
115 :
TestCase (
"Check CreateObject<Type> template function")
119 CreateObjectTestCase::~CreateObjectTestCase ()
127 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to CreateObject<BaseA>");
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> ();
146 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to CreateObject<DerivedA> with implicit cast to BaseA");
152 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"Unable to GetObject<BaseA> on BaseA");
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);
180 AggregateObjectTestCase::AggregateObjectTestCase ()
181 :
TestCase (
"Check Object aggregation functionality")
185 AggregateObjectTestCase::~AggregateObjectTestCase ()
193 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to CreateObject<BaseA>");
196 NS_TEST_ASSERT_MSG_NE (baseB, 0,
"Unable to CreateObject<BaseB>");
199 NS_TEST_ASSERT_MSG_NE (baseBCopy, 0,
"Unable to copy BaseB");
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> ();
264 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to CreateObject<DerivedA> with implicit cast to BaseA");
266 baseB = CreateObject<DerivedB> ();
267 NS_TEST_ASSERT_MSG_NE (baseB, 0,
"Unable to CreateObject<DerivedB> with implicit cast to BaseB");
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> ();
326 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to CreateObject<BaseA>");
328 baseB = CreateObject<BaseB> ();
329 NS_TEST_ASSERT_MSG_NE (baseB, 0,
"Unable to CreateObject<BaseA>");
331 baseA->AggregateObject (baseB);
334 baseA = baseB->GetObject<BaseA> ();
335 NS_TEST_ASSERT_MSG_NE (baseA, 0,
"Unable to GetObject on released object");
348 virtual void DoRun (
void);
351 ObjectFactoryTestCase::ObjectFactoryTestCase ()
352 :
TestCase (
"Check ObjectFactory functionality")
356 ObjectFactoryTestCase::~ObjectFactoryTestCase ()
370 NS_TEST_ASSERT_MSG_NE (a, 0,
"Unable to factory.Create() a BaseA");
375 NS_TEST_ASSERT_MSG_EQ (a->
GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"BaseA is unexpectedly a DerivedA also");
380 NS_TEST_ASSERT_MSG_EQ (a->
GetObject<DerivedA> (), 0,
"BaseA unexpectedly responds to GetObject for DerivedA");
386 factory.
SetTypeId (DerivedA::GetTypeId ());
393 NS_TEST_ASSERT_MSG_EQ (a->
GetObject<BaseA> (), a,
"Unable to use GetObject as dynamic_cast<BaseA>()");
400 NS_TEST_ASSERT_MSG_EQ (a->
GetObject<BaseA> (DerivedA::GetTypeId ()), a,
"GetObject with implied cast returns different Ptr");
407 NS_TEST_ASSERT_MSG_NE (a->
GetObject<DerivedA> (), 0,
"Unexpectedly able to work around C++ type system");
419 ObjectTestSuite::ObjectTestSuite ()
427 static ObjectTestSuite objectTestSuite;
smart pointer class similar to boost::intrusive_ptr
TypeId AddConstructor(void)
void SetTypeId(TypeId tid)
Ptr< Object > Create(void) const
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
instantiate subclasses of ns3::Object.
a base class which provides memory management and object aggregation
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.
virtual void DoRun(void)
Implementation to actually run this test case.