diff --git a/src/core/test/config-test-suite.cc b/src/core/test/config-test-suite.cc index 273ba369c..dec1fc8da 100644 --- a/src/core/test/config-test-suite.cc +++ b/src/core/test/config-test-suite.cc @@ -138,6 +138,67 @@ ConfigTestObject::GetB (void) const return m_b; } +// Other test objects +// + +class DerivedConfigTestObject : public ConfigTestObject +{ +public: + static TypeId GetTypeId (void); + DerivedConfigTestObject (void) {} + virtual ~DerivedConfigTestObject (void) {} +}; + +TypeId +DerivedConfigTestObject::GetTypeId (void) +{ + static TypeId tid = TypeId ("DerivedConfigTestObject") + .SetParent () + ; + return tid; +} + +class BaseConfigObject : public Object +{ +public: + static TypeId GetTypeId (void); + BaseConfigObject (void) {} + virtual ~BaseConfigObject (void) {} +private: + int8_t m_x; +}; + +TypeId +BaseConfigObject::GetTypeId (void) +{ + static TypeId tid = TypeId ("BaseConfigObject") + .SetParent () + .AddAttribute ("X", "", + IntegerValue (10), + MakeIntegerAccessor (&BaseConfigObject::m_x), + MakeIntegerChecker ()) + ; + return tid; +} + +class DerivedConfigObject : public BaseConfigObject +{ +public: + static TypeId GetTypeId (void); + DerivedConfigObject (void) {} + virtual ~DerivedConfigObject (void) {} +}; + +TypeId +DerivedConfigObject::GetTypeId (void) +{ + static TypeId tid = TypeId ("DerivedConfigObject") + .SetParent () + ; + return tid; +} + + // =========================================================================== // Test for the ability to register and use a root namespace // =========================================================================== @@ -606,6 +667,58 @@ ObjectVectorTraceConfigTestCase::DoRun (void) NS_TEST_ASSERT_MSG_EQ (m_path, "/NodeA/NodeB/NodesB/1/Source", "Trace 1 did not provide expected context"); } +// =========================================================================== +// Test for the ability to search attributes of parent classes +// when Resolver searches for attributes in a derived class object. +// This test passes with the patch found in +// https://www.nsnam.org/bugzilla/show_bug.cgi?id=1673 +// (also reported in https://www.nsnam.org/bugzilla/show_bug.cgi?id=1959) +// =========================================================================== +class SearchAttributesOfParentObjectsTestCase : public TestCase +{ +public: + SearchAttributesOfParentObjectsTestCase (); + virtual ~SearchAttributesOfParentObjectsTestCase () {} + +private: + virtual void DoRun (void); + +}; + +SearchAttributesOfParentObjectsTestCase::SearchAttributesOfParentObjectsTestCase () + : TestCase ("Check that attributes of base class are searchable from paths including objects of derived class") +{ +} + +void +SearchAttributesOfParentObjectsTestCase::DoRun (void) +{ + IntegerValue iv; + // + // Create a root namespace object that doesn't have attributes but + // whose parent class has 'NodeA' attribute + // + Ptr root = CreateObject (); + Config::RegisterRootNamespaceObject (root); + + // + // Instantiate /NodeA + // + Ptr a = CreateObject (); + root->SetNodeA (a); + + // + // BaseConfigObject has attribute X, but we aggregate DerivedConfigObject + // instead + // + Ptr derived = CreateObject (); + a->AggregateObject (derived); + Config::Set ("/NodeA/$DerivedConfigObject/X", IntegerValue (42)); + derived->GetAttribute ("X", iv); + NS_TEST_ASSERT_MSG_EQ (iv.Get (), 42, "Object Attribute \"X\" not settable in derived class"); + +} + // =========================================================================== // The Test Suite that glues all of the Test Cases together. // =========================================================================== @@ -621,6 +734,7 @@ ConfigTestSuite::ConfigTestSuite () AddTestCase (new RootNamespaceConfigTestCase, TestCase::QUICK); AddTestCase (new UnderRootNamespaceConfigTestCase, TestCase::QUICK); AddTestCase (new ObjectVectorConfigTestCase, TestCase::QUICK); + AddTestCase (new SearchAttributesOfParentObjectsTestCase, TestCase::QUICK); } static ConfigTestSuite configTestSuite;