core (fixes #349): Warn about Config::SetDefault() of deprecated attribute
This commit is contained in:
committed by
Tom Henderson
parent
8137af04f0
commit
854ca2ed34
@@ -870,6 +870,8 @@ bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
struct TypeId::AttributeInformation info;
|
||||
tid.LookupAttributeByName(paramName, &info);
|
||||
for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
|
||||
{
|
||||
struct TypeId::AttributeInformation tmp = tid.GetAttribute (j);
|
||||
|
||||
@@ -228,6 +228,12 @@ public:
|
||||
TimeValue (Seconds (-2)),
|
||||
MakeTimeAccessor (&AttributeObjectTest::m_timeWithBounds),
|
||||
MakeTimeChecker (Seconds (-5), Seconds (10)))
|
||||
.AddAttribute ("TestDeprecated", "help text",
|
||||
BooleanValue (false),
|
||||
MakeBooleanAccessor (&AttributeObjectTest::m_boolTestDeprecated),
|
||||
MakeBooleanChecker (),
|
||||
TypeId::DEPRECATED,
|
||||
"DEPRECATED test working.")
|
||||
;
|
||||
|
||||
return tid;
|
||||
@@ -320,6 +326,7 @@ private:
|
||||
|
||||
bool m_boolTestA;
|
||||
bool m_boolTest;
|
||||
bool m_boolTestDeprecated;
|
||||
int16_t m_int16;
|
||||
int16_t m_int16WithBounds;
|
||||
int16_t m_int16SetGet;
|
||||
@@ -424,6 +431,20 @@ AttributeTestCase<BooleanValue>::DoRun (void)
|
||||
ok = CheckGetCodePaths (p, "TestBoolName", "true", BooleanValue (true));
|
||||
NS_TEST_ASSERT_MSG_EQ (ok, true, "Attribute not set properly by default value");
|
||||
|
||||
std::string expected ("Attribute 'TestDeprecated' is deprecated: DEPRECATED test working.\n");
|
||||
// Temporarily redirect std::cerr to a stringstream
|
||||
std::stringstream buffer;
|
||||
std::streambuf *oldBuffer = std::cerr.rdbuf (buffer.rdbuf());
|
||||
// Cause the deprecation warning to be sent to the stringstream
|
||||
Config::SetDefault ("ns3::AttributeObjectTest::TestDeprecated", BooleanValue (true));
|
||||
|
||||
// Compare the obtained actual string with the expected string.
|
||||
NS_TEST_ASSERT_MSG_EQ (buffer.str (), expected, "Deprecated attribute not working");
|
||||
// Restore cerr to its original stream buffer
|
||||
std::cerr.rdbuf (oldBuffer);
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Set the default value of the BooleanValue the other way and create an object.
|
||||
// The new default value should stick.
|
||||
|
||||
Reference in New Issue
Block a user