diff --git a/src/core/test/attribute-container-test-suite.cc b/src/core/test/attribute-container-test-suite.cc index 00ef11f8b..0a2b12a25 100644 --- a/src/core/test/attribute-container-test-suite.cc +++ b/src/core/test/attribute-container-test-suite.cc @@ -7,7 +7,6 @@ */ #include "ns3/attribute-container.h" -#include "ns3/data-rate.h" #include "ns3/double.h" #include "ns3/integer.h" #include "ns3/log.h" @@ -84,9 +83,6 @@ class AttributeContainerObject : public Object */ std::vector GetIntVec() const; - std::tuple m_tupleRatesString; //!< tuple of two data rates - //!< and a string - private: std::list m_doublelist; //!< List of doubles. std::vector m_intvec; //!< Vector of ints. @@ -154,17 +150,7 @@ AttributeContainerObject::GetTypeId() MakeAttributeContainerChecker( MakePairChecker>( MakeIntegerChecker(), - MakeAttributeContainerChecker(MakeIntegerChecker())))) - .AddAttribute( - "TupleRatesString", - "An example of tuple of two data rates (comprising value and unit, possibly " - "separated by a white space) and a string (possibly containing a white space).", - StringValue("{1 Mb/s, 10kb/s, test string}"), - MakeTupleAccessor( - &AttributeContainerObject::m_tupleRatesString), - MakeTupleChecker(MakeDataRateChecker(), - MakeDataRateChecker(), - MakeStringChecker())); + MakeAttributeContainerChecker(MakeIntegerChecker())))); return tid; } @@ -556,19 +542,6 @@ AttributeContainerSetGetTestCase::DoRun() ++iter; } } - - { - // check that the tuple of two data rates and a string was correctly initialized - NS_TEST_EXPECT_MSG_EQ(std::get<0>(obj->m_tupleRatesString), - DataRate(1e6), - "Unexpected value for the first data rate"); - NS_TEST_EXPECT_MSG_EQ(std::get<1>(obj->m_tupleRatesString), - DataRate(1e4), - "Unexpected value for the second data rate"); - NS_TEST_EXPECT_MSG_EQ(std::get<2>(obj->m_tupleRatesString), - "test string", - "Unexpected value for the string"); - } } /** diff --git a/src/network/test/test-data-rate.cc b/src/network/test/test-data-rate.cc index 64e3ffe44..ea62cc41b 100644 --- a/src/network/test/test-data-rate.cc +++ b/src/network/test/test-data-rate.cc @@ -10,6 +10,7 @@ #include "ns3/log.h" #include "ns3/simulator.h" #include "ns3/test.h" +#include "ns3/tuple.h" using namespace ns3; @@ -258,6 +259,86 @@ DataRateTestCase2::DoRun() MultiplicationDoubleTest("6Gb/s", 1.0 / 7.0, "857142857.14b/s"); } +/** + * @ingroup network-test + * @ingroup tests + * + * Object with an attribute that is a tuple of data rates and a string. + */ +class DataRateTupleObject : public Object +{ + public: + ~DataRateTupleObject() override = default; + + /** + * @brief Get the type ID. + * @return The object TypeId. + */ + static TypeId GetTypeId(); + + std::tuple m_tupleRatesString; //!< tuple of two data rates + //!< and a string +}; + +TypeId +DataRateTupleObject::GetTypeId() +{ + static TypeId tid = + TypeId("ns3::DataRateTupleObject") + .SetParent() + .SetGroupName("Test") + .AddConstructor() + .AddAttribute( + "TupleRatesString", + "An example of tuple of two data rates (comprising value and unit, possibly " + "separated by a white space) and a string (possibly containing a white space).", + StringValue("{1 Mb/s, 10kb/s, test string}"), + MakeTupleAccessor( + &DataRateTupleObject::m_tupleRatesString), + MakeTupleChecker(MakeDataRateChecker(), + MakeDataRateChecker(), + MakeStringChecker())); + return tid; +} + +/** + * @ingroup network-test + * @ingroup tests + * + * Attribute set and get TestCase. + */ +class DataRateTupleSetGetTestCase : public TestCase +{ + public: + DataRateTupleSetGetTestCase(); + ~DataRateTupleSetGetTestCase() override = default; + + private: + void DoRun() override; +}; + +DataRateTupleSetGetTestCase::DataRateTupleSetGetTestCase() + : TestCase("test attribute set and get") +{ +} + +void +DataRateTupleSetGetTestCase::DoRun() +{ + Ptr obj = CreateObject(); + + // check that the tuple of two data rates and a string was correctly initialized + NS_TEST_EXPECT_MSG_EQ(std::get<0>(obj->m_tupleRatesString), + DataRate(1e6), + "Unexpected value for the first data rate"); + NS_TEST_EXPECT_MSG_EQ(std::get<1>(obj->m_tupleRatesString), + DataRate(1e4), + "Unexpected value for the second data rate"); + NS_TEST_EXPECT_MSG_EQ(std::get<2>(obj->m_tupleRatesString), + "test string", + "Unexpected value for the string"); +} + /** * @ingroup network-test * @ingroup tests @@ -275,6 +356,7 @@ DataRateTestSuite::DataRateTestSuite() { AddTestCase(new DataRateTestCase1(), TestCase::Duration::QUICK); AddTestCase(new DataRateTestCase2(), TestCase::Duration::QUICK); + AddTestCase(new DataRateTupleSetGetTestCase(), TestCase::Duration::QUICK); } static DataRateTestSuite sDataRateTestSuite; //!< Static variable for test initialization