22 #include "ns3/object.h" 23 #include "ns3/object-factory.h" 24 #include "ns3/assert.h" 57 .SetGroupName (
"Core")
81 .SetGroupName (
"Core")
82 .HideFromDocumentation ()
109 .SetGroupName (
"Core")
133 .SetGroupName (
"Core")
134 .HideFromDocumentation ()
171 virtual void DoRun (
void);
175 :
TestCase (
"Check CreateObject<Type> template function")
192 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (), baseA,
"GetObject() of same type returns different Ptr");
197 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"GetObject() of unrelated type returns nonzero pointer");
203 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), 0,
"GetObject() of unrelated returns nonzero Ptr");
205 baseA = CreateObject<DerivedA> ();
218 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), baseA,
"GetObject() of the original type returns different Ptr");
224 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<BaseA> (DerivedA::GetTypeId ()), baseA,
"GetObject returns different Ptr");
240 virtual void DoRun (
void);
244 :
TestCase (
"Check Object aggregation functionality")
267 baseA->AggregateObject (baseB);
273 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseA) for BaseA Object");
279 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseA");
284 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
290 NS_TEST_ASSERT_MSG_EQ (baseA->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseA");
295 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
301 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedB> (), 0,
"Unexpectedly found a DerivedB through baseB");
307 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
313 NS_TEST_ASSERT_MSG_EQ (baseB->GetObject<DerivedA> (), 0,
"Unexpectedly found a DerivedA through baseB");
321 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
326 baseA = CreateObject<DerivedA> ();
329 baseB = CreateObject<DerivedB> ();
337 baseA->AggregateObject (baseB);
342 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseA) for DerivedB Object");
348 NS_TEST_ASSERT_MSG_NE (baseA->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseA) for BaseB Object");
353 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseB) for DerivedA Object");
359 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseB) for BaseA Object");
368 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<BaseA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
369 NS_TEST_ASSERT_MSG_NE (baseBCopy->GetObject<DerivedA> (), 0,
"Cannot GetObject (through baseBCopy) for a BaseA Object");
375 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<DerivedB> (), 0,
"Cannot GetObject (through baseB) for DerivedB Object");
381 NS_TEST_ASSERT_MSG_NE (baseB->GetObject<BaseB> (), 0,
"Cannot GetObject (through baseB) for BaseB Object");
388 baseA = CreateObject<BaseA> ();
391 baseB = CreateObject<BaseB> ();
394 baseA->AggregateObject (baseB);
397 baseA = baseB->GetObject<BaseA> ();
414 virtual void DoRun (
void);
418 :
TestCase (
"Check ObjectFactory functionality")
452 factory.
SetTypeId (DerivedA::GetTypeId ());
Smart pointer class similar to boost::intrusive_ptr.
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
ObjectFactoryTestCase()
Constructor.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
static ns3::TypeId GetTypeId(void)
Register this type.
virtual ~AggregateObjectTestCase()
Destructor.
virtual ~ObjectFactoryTestCase()
Destructor.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Test we can aggregate Objects.
virtual void DoDispose(void)
Destructor implementation.
ObjectTestSuite()
Constructor.
virtual void DoDispose(void)
Destructor implementation.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
#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 ObjectTestSuite g_objectTestSuite
ObjectTestSuite instance variable.
static ns3::TypeId GetTypeId(void)
Register this type.
Test we can make Objects using CreateObject.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static ns3::TypeId GetTypeId(void)
Register this type.
The Test Suite that glues the Test Cases together.
Test an Object factory can create Objects.
CreateObjectTestCase()
Constructor.
virtual void DoRun(void)
Implementation to actually run this TestCase.
Instantiate subclasses of ns3::Object.
#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...
virtual ~CreateObjectTestCase()
Destructor.
A base class which provides memory management and object aggregation.
static ns3::TypeId GetTypeId(void)
Register this type.
AggregateObjectTestCase()
Constructor.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
TypeId HideFromDocumentation(void)
Hide this TypeId from documentation.