diff --git a/groups/nts/ntsa/ntsa_abstract.t.cpp b/groups/nts/ntsa/ntsa_abstract.t.cpp index 2967208a..29591c06 100644 --- a/groups/nts/ntsa/ntsa_abstract.t.cpp +++ b/groups/nts/ntsa/ntsa_abstract.t.cpp @@ -13,9 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntscfg_abstract_t_cpp, "$Id$ $CSID$") + #include -#include #include #include #include @@ -27,6 +31,130 @@ using namespace BloombergLP; +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntscfg::Abstract'. +class AbstractTest +{ + struct UnsignedIntegerData { + bsl::size_t variationIndex; + bsl::size_t variationCount; + bsl::uint64_t lhs; + bsl::uint64_t rhs; + + bool multiplicationWouldOverflow() const + { + if (rhs != 0 && lhs > UINT64_MAX / rhs) { + return true; + } + + return false; + } + }; + + typedef bsl::vector UnsignedIntegerDataVector; + + struct SignedIntegerData { + bsl::size_t variationIndex; + bsl::size_t variationCount; + bsl::int64_t lhs; + bsl::int64_t rhs; + + bool multiplicationWouldOverflow() const + { + if (lhs > 0 && rhs > 0 && lhs > INT64_MAX / rhs) { + return true; + } + + if (lhs < 0 && rhs > 0 && lhs < INT64_MIN / rhs) { + return true; + } + + if (lhs > 0 && rhs < 0 && rhs < INT64_MIN / lhs) { + return true; + } + + if (lhs < 0 && rhs < 0 && lhs < INT64_MAX / rhs) { + return true; + } + + return false; + } + }; + + typedef bsl::vector SignedIntegerDataVector; + + struct HardwareIntegerEncodingData { + HardwareIntegerEncodingData(const bsl::uint8_t* data, + bsl::size_t size, + bsl::int64_t value) + : d_encoding(data, data + size) + , d_value(value) + { + } + + bsl::vector d_encoding; + bsl::int64_t d_value; + }; + + struct SoftwareIntegerEncodingData { + SoftwareIntegerEncodingData(const bsl::uint8_t* data, + bsl::size_t size, + bsl::string value) + : d_encoding(data, data + size) + , d_value(value) + { + } + + bsl::vector d_encoding; + bsl::string d_value; + }; + + private: + static void loadUnsignedIntegerData(UnsignedIntegerDataVector* result); + static void loadSignedIntegerData(SignedIntegerDataVector* result); + + static void verifyNativeMath(); + static void verifyBase(); + static void verifyRepresentation(); + + static void verifyDecoderUtilityTag(); + static void verifyDecoderUtilityLength(); + static void verifyDecoderUtilityInteger(); + static void verifyDecoderUtilityDatetime(); + + static void verifyEncoderUtilityTag(); + static void verifyEncoderUtilityLength(); + static void verifyEncoderUtilityInteger(); + static void verifyEncoderUtilityDatetime(); + + public: + // Verify the fundamental mechanisms used to build abstract integers. + static void verifyPrerequisites(); + + static void verifyUnsignedIntegerAdd(); + static void verifyUnsignedIntegerSubtract(); + static void verifyUnsignedIntegerMultiply(); + static void verifyUnsignedIntegerDivide(); + static void verifyUnsignedIntegerFacilities(); + + static void verifySignedIntegerAdd(); + static void verifySignedIntegerSubtract(); + static void verifySignedIntegerMultiply(); + static void verifySignedIntegerDivide(); + static void verifySignedIntegerFacilities(); + + static void verifyDecoderUtility(); + static void verifyEncoderUtility(); + + static void verifyHardwareIntegerCodec(); + static void verifySoftwareIntegerCodec(); + + static void verifyObjectIdentifier(); + static void verifyBitString(); +}; + // #define NTSA_ABSTRACT_TEST_VARIATION 1 #define NTSA_ABSTRACT_INTEGER_LOG_INTEGRAL_OPERATION(operation, \ @@ -84,123 +212,7 @@ using namespace BloombergLP; << NTSCFG_TEST_LOG_END; \ } while (false) -namespace test { - -struct UnsignedIntegerData { - bsl::size_t variationIndex; - bsl::size_t variationCount; - bsl::uint64_t lhs; - bsl::uint64_t rhs; - - bool multiplicationWouldOverflow() const - { - if (rhs != 0 && lhs > UINT64_MAX / rhs) { - return true; - } - - return false; - } -}; - -typedef bsl::vector UnsignedIntegerDataVector; - -struct SignedIntegerData { - bsl::size_t variationIndex; - bsl::size_t variationCount; - bsl::int64_t lhs; - bsl::int64_t rhs; - - bool multiplicationWouldOverflow() const - { - if (lhs > 0 && rhs > 0 && lhs > INT64_MAX / rhs) { - return true; - } - - if (lhs < 0 && rhs > 0 && lhs < INT64_MIN / rhs) { - return true; - } - - if (lhs > 0 && rhs < 0 && rhs < INT64_MIN / lhs) { - return true; - } - - if (lhs < 0 && rhs < 0 && lhs < INT64_MAX / rhs) { - return true; - } - - return false; - } -}; - -typedef bsl::vector SignedIntegerDataVector; - -struct HardwareIntegerEncodingData { - HardwareIntegerEncodingData(const bsl::uint8_t* data, - bsl::size_t size, - bsl::int64_t value) - : d_encoding(data, data + size) - , d_value(value) - { - } - - bsl::vector d_encoding; - bsl::int64_t d_value; -}; - - -struct SoftwareIntegerEncodingData { - SoftwareIntegerEncodingData(const bsl::uint8_t* data, - bsl::size_t size, - bsl::string value) - : d_encoding(data, data + size) - , d_value(value) - { - } - - bsl::vector d_encoding; - bsl::string d_value; -}; - -// Provide implementations of test cases. -class Case -{ - private: - static void loadUnsignedIntegerData(UnsignedIntegerDataVector* result); - static void loadSignedIntegerData(SignedIntegerDataVector* result); - - static void verifyNativeMath(bslma::Allocator* allocator); - static void verifyBase(bslma::Allocator* allocator); - static void verifyRepresentation(bslma::Allocator* allocator); - - static void verifyDecoderUtilityTag(bslma::Allocator* allocator); - static void verifyDecoderUtilityLength(bslma::Allocator* allocator); - static void verifyDecoderUtilityInteger(bslma::Allocator* allocator); - static void verifyDecoderUtilityDatetime(bslma::Allocator* allocator); - - static void verifyEncoderUtilityTag(bslma::Allocator* allocator); - static void verifyEncoderUtilityLength(bslma::Allocator* allocator); - static void verifyEncoderUtilityInteger(bslma::Allocator* allocator); - static void verifyEncoderUtilityDatetime(bslma::Allocator* allocator); - - public: - // Verify the fundamental mechanisms used to build abstract integers. - static void verifyPrerequisites(bslma::Allocator* allocator); - - static void verifyUnsignedIntegerAdd(bslma::Allocator* allocator); - static void verifyUnsignedIntegerSubtract(bslma::Allocator* allocator); - static void verifyUnsignedIntegerMultiply(bslma::Allocator* allocator); - static void verifyUnsignedIntegerDivide(bslma::Allocator* allocator); - - static void verifySignedIntegerAdd(bslma::Allocator* allocator); - static void verifySignedIntegerSubtract(bslma::Allocator* allocator); - static void verifySignedIntegerMultiply(bslma::Allocator* allocator); - static void verifySignedIntegerDivide(bslma::Allocator* allocator); - - static void verifyDecoderUtility(bslma::Allocator* allocator); - static void verifyEncoderUtility(bslma::Allocator* allocator); -}; - -void Case::loadUnsignedIntegerData(UnsignedIntegerDataVector* result) +void AbstractTest::loadUnsignedIntegerData(UnsignedIntegerDataVector* result) { result->clear(); @@ -255,7 +267,7 @@ void Case::loadUnsignedIntegerData(UnsignedIntegerDataVector* result) } } -void Case::loadSignedIntegerData(SignedIntegerDataVector* result) +void AbstractTest::loadSignedIntegerData(SignedIntegerDataVector* result) { result->clear(); @@ -311,7 +323,7 @@ void Case::loadSignedIntegerData(SignedIntegerDataVector* result) } } -void Case::verifyNativeMath(bslma::Allocator* allocator) +void AbstractTest::verifyNativeMath() { { bsl::uint64_t a = 1; @@ -336,7 +348,7 @@ void Case::verifyNativeMath(bslma::Allocator* allocator) } } -void Case::verifyBase(bslma::Allocator* allocator) +void AbstractTest::verifyBase() { { bsl::uint64_t radix = ntsa::AbstractIntegerBase::radix( @@ -373,7 +385,7 @@ void Case::verifyBase(bslma::Allocator* allocator) } } -void Case::verifyRepresentation(bslma::Allocator* allocator) +void AbstractTest::verifyRepresentation() { typedef bsl::vector BaseVector; BaseVector baseVector; @@ -387,8 +399,8 @@ void Case::verifyRepresentation(bslma::Allocator* allocator) for (bsl::size_t i = 0; i < baseVector.size(); ++i) { const ntsa::AbstractIntegerBase::Value base = baseVector[i]; - ntsa::AbstractIntegerRepresentation rep(base, allocator); - NTSCFG_TEST_EQ(rep.allocator(), allocator); + ntsa::AbstractIntegerRepresentation rep(base, NTSCFG_TEST_ALLOCATOR); + NTSCFG_TEST_EQ(rep.allocator(), NTSCFG_TEST_ALLOCATOR); NTSCFG_TEST_EQ(rep.size(), 0); NTSCFG_TEST_EQ(rep.base(), base); @@ -399,25 +411,20 @@ void Case::verifyRepresentation(bslma::Allocator* allocator) } } -void Case::verifyDecoderUtilityTag(bslma::Allocator* allocator) +void AbstractTest::verifyDecoderUtilityTag() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyDecoderUtilityLength(bslma::Allocator* allocator) +void AbstractTest::verifyDecoderUtilityLength() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyDecoderUtilityInteger(bslma::Allocator* allocator) +void AbstractTest::verifyDecoderUtilityInteger() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyDecoderUtilityDatetime(bslma::Allocator* allocator) +void AbstractTest::verifyDecoderUtilityDatetime() { - NTSCFG_WARNING_UNUSED(allocator); - ntsa::Error error; // UTC TIME @@ -749,40 +756,36 @@ void Case::verifyDecoderUtilityDatetime(bslma::Allocator* allocator) } } -void Case::verifyEncoderUtilityTag(bslma::Allocator* allocator) +void AbstractTest::verifyEncoderUtilityTag() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyEncoderUtilityLength(bslma::Allocator* allocator) +void AbstractTest::verifyEncoderUtilityLength() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyEncoderUtilityInteger(bslma::Allocator* allocator) +void AbstractTest::verifyEncoderUtilityInteger() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyEncoderUtilityDatetime(bslma::Allocator* allocator) +void AbstractTest::verifyEncoderUtilityDatetime() { - NTSCFG_WARNING_UNUSED(allocator); } -void Case::verifyPrerequisites(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyPrerequisites) { - verifyNativeMath(allocator); - verifyBase(allocator); - verifyRepresentation(allocator); + verifyNativeMath(); + verifyBase(); + verifyRepresentation(); } -void Case::verifyUnsignedIntegerAdd(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyUnsignedIntegerAdd) { - test::UnsignedIntegerDataVector dataVector(allocator); - test::Case::loadUnsignedIntegerData(&dataVector); + UnsignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadUnsignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::UnsignedIntegerData data = dataVector[i]; + UnsignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -790,10 +793,10 @@ void Case::verifyUnsignedIntegerAdd(bslma::Allocator* allocator) } #endif - ntsa::AbstractIntegerQuantity lhs(data.lhs, allocator); - ntsa::AbstractIntegerQuantity rhs(data.rhs, allocator); + ntsa::AbstractIntegerQuantity lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractIntegerQuantity rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractIntegerQuantity sum(allocator); + ntsa::AbstractIntegerQuantity sum(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerQuantityUtil::add(&sum, lhs, rhs); @@ -810,13 +813,13 @@ void Case::verifyUnsignedIntegerAdd(bslma::Allocator* allocator) } } -void Case::verifyUnsignedIntegerSubtract(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyUnsignedIntegerSubtract) { - test::UnsignedIntegerDataVector dataVector(allocator); - test::Case::loadUnsignedIntegerData(&dataVector); + UnsignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadUnsignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::UnsignedIntegerData data = dataVector[i]; + UnsignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -824,10 +827,10 @@ void Case::verifyUnsignedIntegerSubtract(bslma::Allocator* allocator) } #endif - ntsa::AbstractIntegerQuantity lhs(data.lhs, allocator); - ntsa::AbstractIntegerQuantity rhs(data.rhs, allocator); + ntsa::AbstractIntegerQuantity lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractIntegerQuantity rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractIntegerQuantity difference(allocator); + ntsa::AbstractIntegerQuantity difference(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerQuantityUtil::subtract(&difference, lhs, rhs); @@ -850,13 +853,13 @@ void Case::verifyUnsignedIntegerSubtract(bslma::Allocator* allocator) } } -void Case::verifyUnsignedIntegerMultiply(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyUnsignedIntegerMultiply) { - test::UnsignedIntegerDataVector dataVector(allocator); - test::Case::loadUnsignedIntegerData(&dataVector); + UnsignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadUnsignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::UnsignedIntegerData data = dataVector[i]; + UnsignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -870,10 +873,10 @@ void Case::verifyUnsignedIntegerMultiply(bslma::Allocator* allocator) continue; } - ntsa::AbstractIntegerQuantity lhs(data.lhs, allocator); - ntsa::AbstractIntegerQuantity rhs(data.rhs, allocator); + ntsa::AbstractIntegerQuantity lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractIntegerQuantity rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractIntegerQuantity product(allocator); + ntsa::AbstractIntegerQuantity product(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerQuantityUtil::multiply(&product, lhs, rhs); @@ -890,13 +893,13 @@ void Case::verifyUnsignedIntegerMultiply(bslma::Allocator* allocator) } } -void Case::verifyUnsignedIntegerDivide(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyUnsignedIntegerDivide) { - test::UnsignedIntegerDataVector dataVector(allocator); - test::Case::loadUnsignedIntegerData(&dataVector); + UnsignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadUnsignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::UnsignedIntegerData data = dataVector[i]; + UnsignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -908,11 +911,11 @@ void Case::verifyUnsignedIntegerDivide(bslma::Allocator* allocator) continue; } - ntsa::AbstractIntegerQuantity lhs(data.lhs, allocator); - ntsa::AbstractIntegerQuantity rhs(data.rhs, allocator); + ntsa::AbstractIntegerQuantity lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractIntegerQuantity rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractIntegerQuantity q(allocator); - ntsa::AbstractIntegerQuantity r(allocator); + ntsa::AbstractIntegerQuantity q(NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractIntegerQuantity r(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerQuantityUtil::divide(&q, &r, lhs, rhs); @@ -936,13 +939,17 @@ void Case::verifyUnsignedIntegerDivide(bslma::Allocator* allocator) } } -void Case::verifySignedIntegerAdd(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyUnsignedIntegerFacilities) { - test::SignedIntegerDataVector dataVector(allocator); - test::Case::loadSignedIntegerData(&dataVector); +} + +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySignedIntegerAdd) +{ + SignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadSignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::SignedIntegerData data = dataVector[i]; + SignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -950,10 +957,10 @@ void Case::verifySignedIntegerAdd(bslma::Allocator* allocator) } #endif - ntsa::AbstractInteger lhs(data.lhs, allocator); - ntsa::AbstractInteger rhs(data.rhs, allocator); + ntsa::AbstractInteger lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractInteger rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractInteger sum(allocator); + ntsa::AbstractInteger sum(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerUtil::add(&sum, lhs, rhs); @@ -968,13 +975,13 @@ void Case::verifySignedIntegerAdd(bslma::Allocator* allocator) } } -void Case::verifySignedIntegerSubtract(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySignedIntegerSubtract) { - test::SignedIntegerDataVector dataVector(allocator); - test::Case::loadSignedIntegerData(&dataVector); + SignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadSignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::SignedIntegerData data = dataVector[i]; + SignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -982,10 +989,10 @@ void Case::verifySignedIntegerSubtract(bslma::Allocator* allocator) } #endif - ntsa::AbstractInteger lhs(data.lhs, allocator); - ntsa::AbstractInteger rhs(data.rhs, allocator); + ntsa::AbstractInteger lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractInteger rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractInteger difference(allocator); + ntsa::AbstractInteger difference(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerUtil::subtract(&difference, lhs, rhs); @@ -1000,13 +1007,13 @@ void Case::verifySignedIntegerSubtract(bslma::Allocator* allocator) } } -void Case::verifySignedIntegerMultiply(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySignedIntegerMultiply) { - test::SignedIntegerDataVector dataVector(allocator); - test::Case::loadSignedIntegerData(&dataVector); + SignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadSignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::SignedIntegerData data = dataVector[i]; + SignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -1020,10 +1027,10 @@ void Case::verifySignedIntegerMultiply(bslma::Allocator* allocator) continue; } - ntsa::AbstractInteger lhs(data.lhs, allocator); - ntsa::AbstractInteger rhs(data.rhs, allocator); + ntsa::AbstractInteger lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractInteger rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractInteger product(allocator); + ntsa::AbstractInteger product(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerUtil::multiply(&product, lhs, rhs); @@ -1038,13 +1045,13 @@ void Case::verifySignedIntegerMultiply(bslma::Allocator* allocator) } } -void Case::verifySignedIntegerDivide(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySignedIntegerDivide) { - test::SignedIntegerDataVector dataVector(allocator); - test::Case::loadSignedIntegerData(&dataVector); + SignedIntegerDataVector dataVector(NTSCFG_TEST_ALLOCATOR); + loadSignedIntegerData(&dataVector); for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - test::SignedIntegerData data = dataVector[i]; + SignedIntegerData data = dataVector[i]; #if defined(NTSA_ABSTRACT_TEST_VARIATION) if (data.variationIndex != NTSA_ABSTRACT_TEST_VARIATION) { @@ -1056,11 +1063,11 @@ void Case::verifySignedIntegerDivide(bslma::Allocator* allocator) continue; } - ntsa::AbstractInteger lhs(data.lhs, allocator); - ntsa::AbstractInteger rhs(data.rhs, allocator); + ntsa::AbstractInteger lhs(data.lhs, NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractInteger rhs(data.rhs, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractInteger q(allocator); - ntsa::AbstractInteger r(allocator); + ntsa::AbstractInteger q(NTSCFG_TEST_ALLOCATOR); + ntsa::AbstractInteger r(NTSCFG_TEST_ALLOCATOR); ntsa::AbstractIntegerUtil::divide(&q, &r, lhs, rhs); @@ -1080,939 +1087,714 @@ void Case::verifySignedIntegerDivide(bslma::Allocator* allocator) } } -void Case::verifyDecoderUtility(bslma::Allocator* allocator) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySignedIntegerFacilities) { - Case::verifyDecoderUtilityTag(allocator); - Case::verifyDecoderUtilityLength(allocator); - Case::verifyDecoderUtilityInteger(allocator); - Case::verifyDecoderUtilityDatetime(allocator); -} - -void Case::verifyEncoderUtility(bslma::Allocator* allocator) -{ - Case::verifyEncoderUtilityTag(allocator); - Case::verifyEncoderUtilityLength(allocator); - Case::verifyEncoderUtilityInteger(allocator); - Case::verifyEncoderUtilityDatetime(allocator); -} - -} // close namespace test + // Test parse/generate. -NTSCFG_TEST_CASE(1) -{ - // Test prerequisites. - - ntscfg::TestAllocator ta; { - test::Case::verifyPrerequisites(&ta); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse(""); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(2) -{ - // Test abstract unsigned integer addition. - - ntscfg::TestAllocator ta; { - test::Case::verifyUnsignedIntegerAdd(&ta); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse("+"); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(3) -{ - // Test abstract unsigned integer subtraction. - - ntscfg::TestAllocator ta; - { - test::Case::verifyUnsignedIntegerSubtract(&ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(4) -{ - // Test abstract unsigned integer multiplication. - - ntscfg::TestAllocator ta; { - test::Case::verifyUnsignedIntegerMultiply(&ta); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse("-"); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(5) -{ - // Test abstract unsigned integer division. - - ntscfg::TestAllocator ta; { - test::Case::verifyUnsignedIntegerDivide(&ta); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse("0x"); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(6) -{ - // Test abstract unsigned integer facilities. - - // Test default constructor - // Test copy constructor - // Test move constructor - // Test assignment operator - // Test move-assignment operator - // Test move-assignment operator. - // Test 'reset' - // Test 'move' - - // Test 'parse/generate' - // Test 'equals' - // Test 'less' - // Test 'hash' - // Test 'print' - - ntscfg::TestAllocator ta; { + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse("+0x"); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(7) -{ - // Test abstract signed integer addition. - ntscfg::TestAllocator ta; { - test::Case::verifySignedIntegerAdd(&ta); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse("-0x"); + NTSCFG_TEST_FALSE(valid); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(8) -{ - // Test abstract signed integer subtraction. - ntscfg::TestAllocator ta; { - test::Case::verifySignedIntegerSubtract(&ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + bsl::string input = "0"; -NTSCFG_TEST_CASE(9) -{ - // Test abstract signed integer multiplication. + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse(input); + NTSCFG_TEST_TRUE(valid); - ntscfg::TestAllocator ta; - { - test::Case::verifySignedIntegerMultiply(&ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + bsl::string output; + number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); -NTSCFG_TEST_CASE(10) -{ - // Test abstract signed integer division. - - ntscfg::TestAllocator ta; - { - test::Case::verifySignedIntegerDivide(&ta); + NTSCFG_TEST_EQ(output, input); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(11) -{ - // Test abstract signed integer facilities. - - // Test default constructor - // Test copy constructor - // Test move constructor - // Test assignment operator - // Test move-assignment operator - // Test move-assignment operator. - // Test 'reset' - // Test 'move' - - // Test 'parse/generate' - // Test 'equals' - // Test 'less' - // Test 'hash' - // Test 'print' - - ntscfg::TestAllocator ta; { - // Test parse/generate. - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse(""); - NTSCFG_TEST_FALSE(valid); - } - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse("+"); - NTSCFG_TEST_FALSE(valid); - } - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse("-"); - NTSCFG_TEST_FALSE(valid); - } - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse("0x"); - NTSCFG_TEST_FALSE(valid); - } - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse("+0x"); - NTSCFG_TEST_FALSE(valid); - } - - { - ntsa::AbstractInteger number(&ta); - bool valid = number.parse("-0x"); - NTSCFG_TEST_FALSE(valid); - } - - { - bsl::string input = "0"; + bsl::string input = "123"; - ntsa::AbstractInteger number(&ta); - bool valid = number.parse(input); - NTSCFG_TEST_TRUE(valid); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse(input); + NTSCFG_TEST_TRUE(valid); - bsl::string output; - number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); + bsl::string output; + number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); - NTSCFG_TEST_EQ(output, input); - } - - { - bsl::string input = "123"; - - ntsa::AbstractInteger number(&ta); - bool valid = number.parse(input); - NTSCFG_TEST_TRUE(valid); - - bsl::string output; - number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); - - NTSCFG_TEST_EQ(output, input); - } + NTSCFG_TEST_EQ(output, input); + } - { - bsl::string input = "-123"; + { + bsl::string input = "-123"; - ntsa::AbstractInteger number(&ta); - bool valid = number.parse(input); - NTSCFG_TEST_TRUE(valid); + ntsa::AbstractInteger number(NTSCFG_TEST_ALLOCATOR); + bool valid = number.parse(input); + NTSCFG_TEST_TRUE(valid); - bsl::string output; - number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); + bsl::string output; + number.generate(&output, ntsa::AbstractIntegerBase::e_DECIMAL); - NTSCFG_TEST_EQ(output, input); - } + NTSCFG_TEST_EQ(output, input); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(12) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyDecoderUtility) { - // Test decoder utilities + verifyDecoderUtilityTag(); + verifyDecoderUtilityLength(); + verifyDecoderUtilityInteger(); + verifyDecoderUtilityDatetime(); +} - ntscfg::TestAllocator ta; - { - test::Case::verifyDecoderUtility(&ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyEncoderUtility) +{ + verifyEncoderUtilityTag(); + verifyEncoderUtilityLength(); + verifyEncoderUtilityInteger(); + verifyEncoderUtilityDatetime(); } -NTSCFG_TEST_CASE(13) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyHardwareIntegerCodec) { - // Test encoder utilities + ntsa::Error error; + + typedef HardwareIntegerEncodingData EncodingData; + bsl::vector dataVector; - ntscfg::TestAllocator ta; { - test::Case::verifyEncoderUtility(&ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // CONSTRUCTED { INTEGER(0) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x00}; -NTSCFG_TEST_CASE(14) -{ - // Test abstract syntax decoding: hardware integers. + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 0)); + } - ntscfg::TestAllocator ta; { - ntsa::Error error; + // CONSTRUCTED { INTEGER(1) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x01}; - typedef test::HardwareIntegerEncodingData EncodingData; - bsl::vector dataVector; + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 1)); + } - { - // CONSTRUCTED { INTEGER(0) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x00}; + { + // CONSTRUCTED { INTEGER(-1) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xff}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 0)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -1)); + } - { - // CONSTRUCTED { INTEGER(1) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x01}; + { + // CONSTRUCTED { INTEGER(2) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x02}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 1)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 2)); + } - { - // CONSTRUCTED { INTEGER(-1) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xff}; + { + // CONSTRUCTED { INTEGER(-2) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfe}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -1)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -2)); + } - { - // CONSTRUCTED { INTEGER(2) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x02}; + { + // CONSTRUCTED { INTEGER(3) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x03}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 2)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 3)); + } - { - // CONSTRUCTED { INTEGER(-2) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfe}; + { + // CONSTRUCTED { INTEGER(-3) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfd}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -2)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -3)); + } - { - // CONSTRUCTED { INTEGER(3) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x03}; + { + // CONSTRUCTED { INTEGER(11927552) } + const bsl::uint8_t k_DER[] = + {0x30, 0x06, 0x02, 0x04, 0x00, 0xb6, 0x00, 0x00}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 3)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 11927552)); + } - { - // CONSTRUCTED { INTEGER(-3) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfd}; + { + // CONSTRUCTED { INTEGER(-11927552) } + const bsl::uint8_t k_DER[] = + {0x30, 0x06, 0x02, 0x04, 0xff, 0x4a, 0x00, 0x00}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -3)); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -11927552)); + } - { - // CONSTRUCTED { INTEGER(11927552) } - const bsl::uint8_t k_DER[] = - {0x30, 0x06, 0x02, 0x04, 0x00, 0xb6, 0x00, 0x00}; + for (bsl::size_t i = 0; i < dataVector.size(); ++i) { + const EncodingData& data = dataVector[i]; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, 11927552)); - } + bdlsb::FixedMemInStreamBuf isb( + reinterpret_cast(&data.d_encoding.front()), + data.d_encoding.size()); + + ntsa::AbstractSyntaxDecoder decoder(&isb, NTSCFG_TEST_ALLOCATOR); { - // CONSTRUCTED { INTEGER(-11927552) } - const bsl::uint8_t k_DER[] = - {0x30, 0x06, 0x02, 0x04, 0xff, 0x4a, 0x00, 0x00}; + ntsa::AbstractSyntaxDecoderFrame contextOuter; + error = decoder.decodeTag(&contextOuter); + NTSCFG_TEST_OK(error); - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, -11927552)); - } + NTSCFG_TEST_LOG_DEBUG << "Context = " << contextOuter + << NTSCFG_TEST_LOG_END; - for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - const EncodingData& data = dataVector[i]; + NTSCFG_TEST_EQ(contextOuter.tagClass(), + ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - bdlsb::FixedMemInStreamBuf isb( - reinterpret_cast(&data.d_encoding.front()), - data.d_encoding.size()); + NTSCFG_TEST_EQ(contextOuter.tagType(), + ntsa::AbstractSyntaxTagType::e_CONSTRUCTED); - ntsa::AbstractSyntaxDecoder decoder(&isb, &ta); + NTSCFG_TEST_EQ(contextOuter.contentLength().has_value(), true); { - ntsa::AbstractSyntaxDecoderFrame contextOuter; - error = decoder.decodeTag(&contextOuter); + ntsa::AbstractSyntaxDecoderFrame contextInner; + error = decoder.decodeTag(&contextInner); NTSCFG_TEST_OK(error); - NTSCFG_TEST_LOG_DEBUG << "Context = " << contextOuter + NTSCFG_TEST_LOG_DEBUG << "Context = " << contextInner << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(contextOuter.tagClass(), + NTSCFG_TEST_EQ(contextInner.tagClass(), ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - NTSCFG_TEST_EQ(contextOuter.tagType(), - ntsa::AbstractSyntaxTagType::e_CONSTRUCTED); - - NTSCFG_TEST_EQ(contextOuter.contentLength().has_value(), true); - - { - ntsa::AbstractSyntaxDecoderFrame contextInner; - error = decoder.decodeTag(&contextInner); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_LOG_DEBUG << "Context = " << contextInner - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(contextInner.tagClass(), - ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - - NTSCFG_TEST_EQ(contextInner.tagType(), - ntsa::AbstractSyntaxTagType::e_PRIMITIVE); + NTSCFG_TEST_EQ(contextInner.tagType(), + ntsa::AbstractSyntaxTagType::e_PRIMITIVE); - NTSCFG_TEST_EQ(contextInner.contentLength().has_value(), - true); + NTSCFG_TEST_EQ(contextInner.contentLength().has_value(), true); - bsl::int32_t value = - bsl::numeric_limits::max(); - error = decoder.decodeValue(&value); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_LOG_DEBUG << "Value = " << value - << NTSCFG_TEST_LOG_END; + bsl::int32_t value = bsl::numeric_limits::max(); + error = decoder.decodeValue(&value); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(value, data.d_value); + NTSCFG_TEST_LOG_DEBUG << "Value = " << value + << NTSCFG_TEST_LOG_END; - error = decoder.decodeTagComplete(); - NTSCFG_TEST_OK(error); - } + NTSCFG_TEST_EQ(value, data.d_value); error = decoder.decodeTagComplete(); NTSCFG_TEST_OK(error); } - bdlsb::MemOutStreamBuf osb(&ta); + error = decoder.decodeTagComplete(); + NTSCFG_TEST_OK(error); + } + + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractSyntaxEncoder encoder(&osb, &ta); + ntsa::AbstractSyntaxEncoder encoder(&osb, NTSCFG_TEST_ALLOCATOR); - error = - encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, + error = encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, ntsa::AbstractSyntaxTagType::e_CONSTRUCTED, ntsa::AbstractSyntaxTagNumber::e_SEQUENCE); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - error = - encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, + error = encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, ntsa::AbstractSyntaxTagType::e_PRIMITIVE, ntsa::AbstractSyntaxTagNumber::e_INTEGER); - NTSCFG_TEST_OK(error); - - error = encoder.encodeValue(data.d_value); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - error = encoder.encodeTagComplete(); - NTSCFG_TEST_OK(error); + error = encoder.encodeValue(data.d_value); + NTSCFG_TEST_OK(error); - error = encoder.encodeTagComplete(); - NTSCFG_TEST_OK(error); + error = encoder.encodeTagComplete(); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + error = encoder.encodeTagComplete(); + NTSCFG_TEST_OK(error); - bsl::vector encoding( - reinterpret_cast(osb.data()), - reinterpret_cast(osb.data()) + - osb.length()); + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bool sameEncoding = encoding == data.d_encoding; - if (!sameEncoding) { - NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(data.d_value, - data.d_encoding, - encoding); - } + bsl::vector encoding( + reinterpret_cast(osb.data()), + reinterpret_cast(osb.data()) + osb.length()); - NTSCFG_TEST_TRUE(sameEncoding); + bool sameEncoding = encoding == data.d_encoding; + if (!sameEncoding) { + NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(data.d_value, + data.d_encoding, + encoding); } + + NTSCFG_TEST_TRUE(sameEncoding); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(15) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifySoftwareIntegerCodec) { - // Test abstract syntax decoding: abstract integers. + ntsa::Error error; + + typedef SoftwareIntegerEncodingData EncodingData; + bsl::vector dataVector; - ntscfg::TestAllocator ta; { - ntsa::Error error; + // CONSTRUCTED { INTEGER(0) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x00}; - typedef test::SoftwareIntegerEncodingData EncodingData; - bsl::vector dataVector; + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "0")); + } - { - // CONSTRUCTED { INTEGER(0) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x00}; + { + // CONSTRUCTED { INTEGER(1) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x01}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "0")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "1")); + } - { - // CONSTRUCTED { INTEGER(1) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x01}; + { + // CONSTRUCTED { k_DER(-1) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xff}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "1")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-1")); + } - { - // CONSTRUCTED { k_DER(-1) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xff}; + { + // CONSTRUCTED { INTEGER(2) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x02}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-1")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "2")); + } - { - // CONSTRUCTED { INTEGER(2) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x02}; + { + // CONSTRUCTED { INTEGER(-2) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfe}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "2")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-2")); + } - { - // CONSTRUCTED { INTEGER(-2) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfe}; + { + // CONSTRUCTED { INTEGER(3) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x03}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-2")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "3")); + } - { - // CONSTRUCTED { INTEGER(3) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0x03}; + { + // CONSTRUCTED { INTEGER(-3) } + const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfd}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "3")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-3")); + } - { - // CONSTRUCTED { INTEGER(-3) } - const bsl::uint8_t k_DER[] = {0x30, 0x03, 0x02, 0x01, 0xfd}; + { + // CONSTRUCTED { INTEGER(11927552) } + const bsl::uint8_t k_DER[] = + {0x30, 0x06, 0x02, 0x04, 0x00, 0xb6, 0x00, 0x00}; - dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-3")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "11927552")); + } - { - // CONSTRUCTED { INTEGER(11927552) } - const bsl::uint8_t k_DER[] = - {0x30, 0x06, 0x02, 0x04, 0x00, 0xb6, 0x00, 0x00}; + { + // CONSTRUCTED { INTEGER(-11927552) } + const bsl::uint8_t k_DER[] = + {0x30, 0x06, 0x02, 0x04, 0xff, 0x4a, 0x00, 0x00}; - dataVector.push_back( - EncodingData(k_DER, sizeof k_DER, "11927552")); - } + dataVector.push_back(EncodingData(k_DER, sizeof k_DER, "-11927552")); + } - { - // CONSTRUCTED { INTEGER(-11927552) } - const bsl::uint8_t k_DER[] = - {0x30, 0x06, 0x02, 0x04, 0xff, 0x4a, 0x00, 0x00}; + for (bsl::size_t i = 0; i < dataVector.size(); ++i) { + const EncodingData& data = dataVector[i]; - dataVector.push_back( - EncodingData(k_DER, sizeof k_DER, "-11927552")); - } + bdlsb::FixedMemInStreamBuf isb( + reinterpret_cast(&data.d_encoding.front()), + data.d_encoding.size()); - for (bsl::size_t i = 0; i < dataVector.size(); ++i) { - const EncodingData& data = dataVector[i]; + ntsa::AbstractSyntaxDecoder decoder(&isb, NTSCFG_TEST_ALLOCATOR); - bdlsb::FixedMemInStreamBuf isb( - reinterpret_cast(&data.d_encoding.front()), - data.d_encoding.size()); + ntsa::AbstractInteger value(NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractSyntaxDecoder decoder(&isb, &ta); + { + ntsa::AbstractSyntaxDecoderFrame contextOuter; + error = decoder.decodeTag(&contextOuter); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_LOG_DEBUG << "Context = " << contextOuter + << NTSCFG_TEST_LOG_END; - ntsa::AbstractInteger value(&ta); + NTSCFG_TEST_EQ(contextOuter.tagClass(), + ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); + + NTSCFG_TEST_EQ(contextOuter.tagType(), + ntsa::AbstractSyntaxTagType::e_CONSTRUCTED); + + NTSCFG_TEST_EQ(contextOuter.contentLength().has_value(), true); { - ntsa::AbstractSyntaxDecoderFrame contextOuter; - error = decoder.decodeTag(&contextOuter); + ntsa::AbstractSyntaxDecoderFrame contextInner; + error = decoder.decodeTag(&contextInner); NTSCFG_TEST_OK(error); - NTSCFG_TEST_LOG_DEBUG << "Context = " << contextOuter + NTSCFG_TEST_LOG_DEBUG << "Context = " << contextInner << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(contextOuter.tagClass(), + NTSCFG_TEST_EQ(contextInner.tagClass(), ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - NTSCFG_TEST_EQ(contextOuter.tagType(), - ntsa::AbstractSyntaxTagType::e_CONSTRUCTED); - - NTSCFG_TEST_EQ(contextOuter.contentLength().has_value(), true); + NTSCFG_TEST_EQ(contextInner.tagType(), + ntsa::AbstractSyntaxTagType::e_PRIMITIVE); - { - ntsa::AbstractSyntaxDecoderFrame contextInner; - error = decoder.decodeTag(&contextInner); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(contextInner.contentLength().has_value(), true); - NTSCFG_TEST_LOG_DEBUG << "Context = " << contextInner - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(contextInner.tagClass(), - ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - - NTSCFG_TEST_EQ(contextInner.tagType(), - ntsa::AbstractSyntaxTagType::e_PRIMITIVE); - - NTSCFG_TEST_EQ(contextInner.contentLength().has_value(), - true); - - error = decoder.decodeValue(&value); - NTSCFG_TEST_OK(error); + error = decoder.decodeValue(&value); + NTSCFG_TEST_OK(error); - bsl::string valueString; - value.generate(&valueString, - ntsa::AbstractIntegerBase::e_DECIMAL); + bsl::string valueString; + value.generate(&valueString, + ntsa::AbstractIntegerBase::e_DECIMAL); - NTSCFG_TEST_LOG_DEBUG << "Value = " << valueString - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Value = " << valueString + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(valueString, data.d_value); - - error = decoder.decodeTagComplete(); - NTSCFG_TEST_OK(error); - } + NTSCFG_TEST_EQ(valueString, data.d_value); error = decoder.decodeTagComplete(); NTSCFG_TEST_OK(error); } - bdlsb::MemOutStreamBuf osb(&ta); + error = decoder.decodeTagComplete(); + NTSCFG_TEST_OK(error); + } + + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractSyntaxEncoder encoder(&osb, &ta); + ntsa::AbstractSyntaxEncoder encoder(&osb, NTSCFG_TEST_ALLOCATOR); - error = - encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, + error = encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, ntsa::AbstractSyntaxTagType::e_CONSTRUCTED, ntsa::AbstractSyntaxTagNumber::e_SEQUENCE); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - error = - encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, + error = encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, ntsa::AbstractSyntaxTagType::e_PRIMITIVE, ntsa::AbstractSyntaxTagNumber::e_INTEGER); - NTSCFG_TEST_OK(error); - - error = encoder.encodeValue(value); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - error = encoder.encodeTagComplete(); - NTSCFG_TEST_OK(error); + error = encoder.encodeValue(value); + NTSCFG_TEST_OK(error); - error = encoder.encodeTagComplete(); - NTSCFG_TEST_OK(error); + error = encoder.encodeTagComplete(); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + error = encoder.encodeTagComplete(); + NTSCFG_TEST_OK(error); - bsl::vector encoding( - reinterpret_cast(osb.data()), - reinterpret_cast(osb.data()) + - osb.length()); + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bool sameEncoding = encoding == data.d_encoding; - if (!sameEncoding) { - NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(value, - data.d_encoding, - encoding); - } + bsl::vector encoding( + reinterpret_cast(osb.data()), + reinterpret_cast(osb.data()) + osb.length()); - NTSCFG_TEST_TRUE(sameEncoding); + bool sameEncoding = encoding == data.d_encoding; + if (!sameEncoding) { + NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(value, + data.d_encoding, + encoding); } + + NTSCFG_TEST_TRUE(sameEncoding); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyObjectIdentifier) { - // Test abstract object identifier codec + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; + const bsl::uint8_t k_ENCODING[] = { + 0x06, 0x21, 0x2a, 0x03, 0x04, 0x81, 0x7e, 0x81, 0x7f, 0x82, 0x00, 0x83, + 0xff, 0x7e, 0x83, 0xff, 0x7f, 0x84, 0x80, 0x00, 0x8f, 0xff, 0xff, 0xff, + 0x7e, 0x8f, 0xff, 0xff, 0xff, 0x7f, 0x90, 0x80, 0x80, 0x80, 0x00}; - const bsl::uint8_t k_ENCODING[] = { - 0x06, 0x21, 0x2a, 0x03, 0x04, 0x81, 0x7e, 0x81, 0x7f, - 0x82, 0x00, 0x83, 0xff, 0x7e, 0x83, 0xff, 0x7f, 0x84, - 0x80, 0x00, 0x8f, 0xff, 0xff, 0xff, 0x7e, 0x8f, 0xff, - 0xff, 0xff, 0x7f, 0x90, 0x80, 0x80, 0x80, 0x00}; + bdlsb::FixedMemInStreamBuf isb(reinterpret_cast(k_ENCODING), + sizeof k_ENCODING); - bdlsb::FixedMemInStreamBuf isb( - reinterpret_cast(k_ENCODING), - sizeof k_ENCODING); + ntsa::AbstractSyntaxDecoder decoder(&isb, NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractSyntaxDecoder decoder(&isb, &ta); + ntsa::AbstractObjectIdentifier value(NTSCFG_TEST_ALLOCATOR); - ntsa::AbstractObjectIdentifier value(&ta); + ntsa::AbstractSyntaxDecoderFrame decoderFrame; + error = decoder.decodeTag(&decoderFrame); + NTSCFG_TEST_OK(error); - ntsa::AbstractSyntaxDecoderFrame decoderFrame; - error = decoder.decodeTag(&decoderFrame); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_LOG_DEBUG << "Context = " << decoderFrame + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Context = " << decoderFrame - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_EQ(decoderFrame.tagClass(), + ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); - NTSCFG_TEST_EQ(decoderFrame.tagClass(), - ntsa::AbstractSyntaxTagClass::e_UNIVERSAL); + NTSCFG_TEST_EQ(decoderFrame.tagType(), + ntsa::AbstractSyntaxTagType::e_PRIMITIVE); - NTSCFG_TEST_EQ(decoderFrame.tagType(), - ntsa::AbstractSyntaxTagType::e_PRIMITIVE); + NTSCFG_TEST_EQ(decoderFrame.contentLength().has_value(), true); - NTSCFG_TEST_EQ(decoderFrame.contentLength().has_value(), true); + error = decoder.decodeValue(&value); + NTSCFG_TEST_OK(error); - error = decoder.decodeValue(&value); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_LOG_DEBUG << "Value = " << value << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Value = " << value << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(value.size(), 13); - - NTSCFG_TEST_EQ(value.get(0), 1); - NTSCFG_TEST_EQ(value.get(1), 2); - NTSCFG_TEST_EQ(value.get(2), 3); - NTSCFG_TEST_EQ(value.get(3), 4); - NTSCFG_TEST_EQ(value.get(4), 254); - NTSCFG_TEST_EQ(value.get(5), 255); - NTSCFG_TEST_EQ(value.get(6), 256); - NTSCFG_TEST_EQ(value.get(7), 65534); - NTSCFG_TEST_EQ(value.get(8), 65535); - NTSCFG_TEST_EQ(value.get(9), 65536); - NTSCFG_TEST_EQ(value.get(10), 4294967294); - NTSCFG_TEST_EQ(value.get(11), 4294967295); - NTSCFG_TEST_EQ(value.get(12), 4294967296ULL); - - error = decoder.decodeTagComplete(); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(value.size(), 13); - bdlsb::MemOutStreamBuf osb(&ta); + NTSCFG_TEST_EQ(value.get(0), 1); + NTSCFG_TEST_EQ(value.get(1), 2); + NTSCFG_TEST_EQ(value.get(2), 3); + NTSCFG_TEST_EQ(value.get(3), 4); + NTSCFG_TEST_EQ(value.get(4), 254); + NTSCFG_TEST_EQ(value.get(5), 255); + NTSCFG_TEST_EQ(value.get(6), 256); + NTSCFG_TEST_EQ(value.get(7), 65534); + NTSCFG_TEST_EQ(value.get(8), 65535); + NTSCFG_TEST_EQ(value.get(9), 65536); + NTSCFG_TEST_EQ(value.get(10), 4294967294); + NTSCFG_TEST_EQ(value.get(11), 4294967295); + NTSCFG_TEST_EQ(value.get(12), 4294967296ULL); - ntsa::AbstractSyntaxEncoder encoder(&osb, &ta); + error = decoder.decodeTagComplete(); + NTSCFG_TEST_OK(error); - error = encoder.encodeTag( - ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, - ntsa::AbstractSyntaxTagType::e_PRIMITIVE, - ntsa::AbstractSyntaxTagNumber::e_OBJECT_IDENTIFIER); - NTSCFG_TEST_OK(error); + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - error = encoder.encodeValue(value); - NTSCFG_TEST_OK(error); + ntsa::AbstractSyntaxEncoder encoder(&osb, NTSCFG_TEST_ALLOCATOR); - error = encoder.encodeTagComplete(); - NTSCFG_TEST_OK(error); + error = + encoder.encodeTag(ntsa::AbstractSyntaxTagClass::e_UNIVERSAL, + ntsa::AbstractSyntaxTagType::e_PRIMITIVE, + ntsa::AbstractSyntaxTagNumber::e_OBJECT_IDENTIFIER); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + error = encoder.encodeValue(value); + NTSCFG_TEST_OK(error); - bsl::vector encoding( - reinterpret_cast(osb.data()), - reinterpret_cast(osb.data()) + osb.length()); + error = encoder.encodeTagComplete(); + NTSCFG_TEST_OK(error); - bsl::vector expectedEncoding( - reinterpret_cast(k_ENCODING), - reinterpret_cast(k_ENCODING) + - sizeof k_ENCODING); + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bool sameEncoding = encoding == expectedEncoding; - if (!sameEncoding) { - NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(value, - expectedEncoding, - encoding); - } + bsl::vector encoding( + reinterpret_cast(osb.data()), + reinterpret_cast(osb.data()) + osb.length()); - NTSCFG_TEST_TRUE(sameEncoding); + bsl::vector expectedEncoding( + reinterpret_cast(k_ENCODING), + reinterpret_cast(k_ENCODING) + sizeof k_ENCODING); + + bool sameEncoding = encoding == expectedEncoding; + if (!sameEncoding) { + NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH(value, + expectedEncoding, + encoding); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(sameEncoding); } -NTSCFG_TEST_CASE(17) +NTSCFG_TEST_FUNCTION(ntsa::AbstractTest::verifyBitString) { - // Test abstract bit string + ntsa::Error error; - ntscfg::TestAllocator ta; { - ntsa::Error error; + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - { - ntsa::AbstractBitString v(&ta); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); - - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(0, 1); + v.setBit(0, 1); - NTSCFG_TEST_EQ(v.getBit(0), 1); - NTSCFG_TEST_EQ(v.getBit(1), 0); + NTSCFG_TEST_EQ(v.getBit(0), 1); + NTSCFG_TEST_EQ(v.getBit(1), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(1, 1); + v.setBit(1, 1); - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 1); - NTSCFG_TEST_EQ(v.getBit(2), 0); + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 1); + NTSCFG_TEST_EQ(v.getBit(2), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(2, 1); + v.setBit(2, 1); - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 0); - NTSCFG_TEST_EQ(v.getBit(2), 1); - NTSCFG_TEST_EQ(v.getBit(3), 0); + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 0); + NTSCFG_TEST_EQ(v.getBit(2), 1); + NTSCFG_TEST_EQ(v.getBit(3), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(8, 1); + v.setBit(8, 1); - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 0); - NTSCFG_TEST_EQ(v.getBit(2), 0); - NTSCFG_TEST_EQ(v.getBit(3), 0); - NTSCFG_TEST_EQ(v.getBit(4), 0); - NTSCFG_TEST_EQ(v.getBit(5), 0); - NTSCFG_TEST_EQ(v.getBit(6), 0); - NTSCFG_TEST_EQ(v.getBit(7), 0); + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 0); + NTSCFG_TEST_EQ(v.getBit(2), 0); + NTSCFG_TEST_EQ(v.getBit(3), 0); + NTSCFG_TEST_EQ(v.getBit(4), 0); + NTSCFG_TEST_EQ(v.getBit(5), 0); + NTSCFG_TEST_EQ(v.getBit(6), 0); + NTSCFG_TEST_EQ(v.getBit(7), 0); - NTSCFG_TEST_EQ(v.getBit(8), 1); - NTSCFG_TEST_EQ(v.getBit(9), 0); + NTSCFG_TEST_EQ(v.getBit(8), 1); + NTSCFG_TEST_EQ(v.getBit(9), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(9, 1); + v.setBit(9, 1); - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 0); - NTSCFG_TEST_EQ(v.getBit(2), 0); - NTSCFG_TEST_EQ(v.getBit(3), 0); - NTSCFG_TEST_EQ(v.getBit(4), 0); - NTSCFG_TEST_EQ(v.getBit(5), 0); - NTSCFG_TEST_EQ(v.getBit(6), 0); - NTSCFG_TEST_EQ(v.getBit(7), 0); + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 0); + NTSCFG_TEST_EQ(v.getBit(2), 0); + NTSCFG_TEST_EQ(v.getBit(3), 0); + NTSCFG_TEST_EQ(v.getBit(4), 0); + NTSCFG_TEST_EQ(v.getBit(5), 0); + NTSCFG_TEST_EQ(v.getBit(6), 0); + NTSCFG_TEST_EQ(v.getBit(7), 0); - NTSCFG_TEST_EQ(v.getBit(8), 0); - NTSCFG_TEST_EQ(v.getBit(9), 1); - NTSCFG_TEST_EQ(v.getBit(10), 0); + NTSCFG_TEST_EQ(v.getBit(8), 0); + NTSCFG_TEST_EQ(v.getBit(9), 1); + NTSCFG_TEST_EQ(v.getBit(10), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); - v.setBit(10, 1); + v.setBit(10, 1); - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 0); - NTSCFG_TEST_EQ(v.getBit(2), 0); - NTSCFG_TEST_EQ(v.getBit(3), 0); - NTSCFG_TEST_EQ(v.getBit(4), 0); - NTSCFG_TEST_EQ(v.getBit(5), 0); - NTSCFG_TEST_EQ(v.getBit(6), 0); - NTSCFG_TEST_EQ(v.getBit(7), 0); + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 0); + NTSCFG_TEST_EQ(v.getBit(2), 0); + NTSCFG_TEST_EQ(v.getBit(3), 0); + NTSCFG_TEST_EQ(v.getBit(4), 0); + NTSCFG_TEST_EQ(v.getBit(5), 0); + NTSCFG_TEST_EQ(v.getBit(6), 0); + NTSCFG_TEST_EQ(v.getBit(7), 0); - NTSCFG_TEST_EQ(v.getBit(8), 0); - NTSCFG_TEST_EQ(v.getBit(9), 0); - NTSCFG_TEST_EQ(v.getBit(10), 1); - NTSCFG_TEST_EQ(v.getBit(11), 0); + NTSCFG_TEST_EQ(v.getBit(8), 0); + NTSCFG_TEST_EQ(v.getBit(9), 0); + NTSCFG_TEST_EQ(v.getBit(10), 1); + NTSCFG_TEST_EQ(v.getBit(11), 0); - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; + } - { - ntsa::AbstractBitString v(&ta); - - NTSCFG_TEST_ASSERT(v.numBytes() == 0); - NTSCFG_TEST_ASSERT(v.numBits() == 0); - - v.setBit(0, 0); - v.setBit(1, 1); - v.setBit(2, 0); - v.setBit(3, 1); - v.setBit(4, 1); - v.setBit(5, 0); - v.setBit(6, 1); - v.setBit(7, 1); - - v.setBit(8, 1); - v.setBit(9, 0); - v.setBit(10, 1); - - NTSCFG_TEST_EQ(v.getBit(0), 0); - NTSCFG_TEST_EQ(v.getBit(1), 1); - NTSCFG_TEST_EQ(v.getBit(2), 0); - NTSCFG_TEST_EQ(v.getBit(3), 1); - NTSCFG_TEST_EQ(v.getBit(4), 1); - NTSCFG_TEST_EQ(v.getBit(5), 0); - NTSCFG_TEST_EQ(v.getBit(6), 1); - NTSCFG_TEST_EQ(v.getBit(7), 1); - - NTSCFG_TEST_EQ(v.getBit(8), 1); - NTSCFG_TEST_EQ(v.getBit(9), 0); - NTSCFG_TEST_EQ(v.getBit(10), 1); - NTSCFG_TEST_EQ(v.getBit(11), 0); - - NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; - } + { + ntsa::AbstractBitString v(NTSCFG_TEST_ALLOCATOR); + + NTSCFG_TEST_ASSERT(v.numBytes() == 0); + NTSCFG_TEST_ASSERT(v.numBits() == 0); + + v.setBit(0, 0); + v.setBit(1, 1); + v.setBit(2, 0); + v.setBit(3, 1); + v.setBit(4, 1); + v.setBit(5, 0); + v.setBit(6, 1); + v.setBit(7, 1); + + v.setBit(8, 1); + v.setBit(9, 0); + v.setBit(10, 1); + + NTSCFG_TEST_EQ(v.getBit(0), 0); + NTSCFG_TEST_EQ(v.getBit(1), 1); + NTSCFG_TEST_EQ(v.getBit(2), 0); + NTSCFG_TEST_EQ(v.getBit(3), 1); + NTSCFG_TEST_EQ(v.getBit(4), 1); + NTSCFG_TEST_EQ(v.getBit(5), 0); + NTSCFG_TEST_EQ(v.getBit(6), 1); + NTSCFG_TEST_EQ(v.getBit(7), 1); + + NTSCFG_TEST_EQ(v.getBit(8), 1); + NTSCFG_TEST_EQ(v.getBit(9), 0); + NTSCFG_TEST_EQ(v.getBit(10), 1); + NTSCFG_TEST_EQ(v.getBit(11), 0); + + NTSCFG_TEST_LOG_DEBUG << "V = " << v << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); // Test prerequisites - - NTSCFG_TEST_REGISTER(2); // Test abstract unsigned integer addition - NTSCFG_TEST_REGISTER(3); // Test abstract unsigned integer subtraction - NTSCFG_TEST_REGISTER(4); // Test abstract unsigned integer multiplication - NTSCFG_TEST_REGISTER(5); // Test abstract unsigned integer division - NTSCFG_TEST_REGISTER(6); // Test abstract unsigned integer facilities - - NTSCFG_TEST_REGISTER(7); // Test abstract signed integer addition - NTSCFG_TEST_REGISTER(8); // Test abstract signed integer subtraction - NTSCFG_TEST_REGISTER(9); // Test abstract signed integer multiplication - NTSCFG_TEST_REGISTER(10); // Test abstract signed integer division - NTSCFG_TEST_REGISTER(11); // Test abstract signed integer facilities - - NTSCFG_TEST_REGISTER(12); // Test decoder utilities - NTSCFG_TEST_REGISTER(13); // Test encoder utilities +#undef NTSA_ABSTRACT_INTEGER_LOG_INTEGRAL_OPERATION +#undef NTSA_ABSTRACT_INTEGER_LOG_ADD +#undef NTSA_ABSTRACT_INTEGER_LOG_SUBTRACT +#undef NTSA_ABSTRACT_INTEGER_LOG_MULTIPLY +#undef NTSA_ABSTRACT_INTEGER_LOG_DIVIDE +#undef NTSA_ABSTRACT_TEST_LOG_ENCODING_MISMATCH - NTSCFG_TEST_REGISTER(14); // Test hardware signed integer codec - NTSCFG_TEST_REGISTER(15); // Test abstract signed integer codec - - NTSCFG_TEST_REGISTER(16); // Test abstract object identifier codec - - NTSCFG_TEST_REGISTER(17); // Test abstract bit string -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_adapter.t.cpp b/groups/nts/ntsa/ntsa_adapter.t.cpp new file mode 100644 index 00000000..9334725d --- /dev/null +++ b/groups/nts/ntsa/ntsa_adapter.t.cpp @@ -0,0 +1,41 @@ +// Copyright 2020-2023 Bloomberg Finance L.P. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +BSLS_IDENT_RCSID(ntsa_adapter_t_cpp, "$Id$ $CSID$") + +#include + +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Adapter'. +class AdapterTest +{ + public: + // TODO + static void verify(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::AdapterTest::verify) +{ +} + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_buffer.cpp b/groups/nts/ntsa/ntsa_buffer.cpp index e658abc4..565239b6 100644 --- a/groups/nts/ntsa/ntsa_buffer.cpp +++ b/groups/nts/ntsa/ntsa_buffer.cpp @@ -299,7 +299,7 @@ void ConstBuffer::copy(bdlbb::Blob* blob, BSLS_ASSERT(0 < currentVecAvailable); } - int currentVecOffset = static_cast(offset) - prefixLength; + int currentVecOffset = static_cast(offset) - prefixLength; currentVecAvailable -= currentVecOffset; BSLS_ASSERT(0 <= currentVecOffset); BSLS_ASSERT(0 < currentVecAvailable); @@ -318,7 +318,7 @@ void ConstBuffer::copy(bdlbb::Blob* blob, // Compute number of bytes available to read or write in current vec or // buffer. This must be done *after* setting the blob length. - int currentBufAvailable = blob->buffer(currentBufIndex).size(); + int currentBufAvailable = blob->buffer(currentBufIndex).size(); currentBufAvailable -= currentBufOffset; BSLS_ASSERT(0 < currentBufAvailable); @@ -337,11 +337,11 @@ void ConstBuffer::copy(bdlbb::Blob* blob, int numBytesCopied = bsl::min(currentVecAvailable, currentBufAvailable); - bsl::memcpy(blob->buffer(currentBufIndex).data() + currentBufOffset, - static_cast( - bufferArray[currentVecIndex].buffer()) + - currentVecOffset, - numBytesCopied); + bsl::memcpy( + blob->buffer(currentBufIndex).data() + currentBufOffset, + static_cast(bufferArray[currentVecIndex].buffer()) + + currentVecOffset, + numBytesCopied); currentBufOffset += numBytesCopied; currentVecOffset += numBytesCopied; @@ -352,8 +352,8 @@ void ConstBuffer::copy(bdlbb::Blob* blob, return; } currentVecAvailable = - NTSCFG_WARNING_NARROW( - int, bufferArray[currentVecIndex].length()); + NTSCFG_WARNING_NARROW(int, + bufferArray[currentVecIndex].length()); } else { currentVecAvailable -= numBytesCopied; diff --git a/groups/nts/ntsa/ntsa_buffer.t.cpp b/groups/nts/ntsa/ntsa_buffer.t.cpp index 68d0176d..eba74e3f 100644 --- a/groups/nts/ntsa/ntsa_buffer.t.cpp +++ b/groups/nts/ntsa/ntsa_buffer.t.cpp @@ -13,14 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -#include -#include -#include -#include -#include + +#include +BSLS_IDENT_RCSID(ntscfg_buffer_t_cpp, "$Id$ $CSID$") + +#include #if defined(BSLS_PLATFORM_OS_UNIX) #include @@ -33,113 +31,87 @@ #endif using namespace BloombergLP; -using namespace ntsa; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- - -namespace test { - -/// Define a type alias for a non-modifiable buffer sequence. -typedef ntsa::ConstBufferSequence ConstBufferSequence; - -/// Define a type alias for a modifiable buffer sequence. -typedef ntsa::MutableBufferSequence MutableBufferSequence; - -/// Provide a suite of utilities for generating test data. -/// This struct is completely thread safe. -struct DataUtil { - /// Return the byte at the specified 'position' in the specified - /// 'dataset'. - static char generateByte(bsl::size_t position, bsl::size_t dataset); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bsl::string* result, - bsl::size_t size, - bsl::size_t offset = 0, - bsl::size_t dataset = 0); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bdlbb::Blob* result, - bsl::size_t size, - bsl::size_t offset = 0, - bsl::size_t dataset = 0); -}; +namespace BloombergLP { +namespace ntsa { -char DataUtil::generateByte(bsl::size_t position, bsl::size_t dataset) +// Provide tests for 'ntscfg::BufferTest'. +class BufferTest { - struct { - const char* source; - bsl::size_t length; - } DATA[] = { - {"abcdefghijklmnopqrstuvwxyz", 26}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26} - }; - - enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; - - dataset = dataset % NUM_DATA; - return DATA[dataset].source[position % DATA[dataset].length]; -} + /// Define a type alias for a non-modifiable buffer sequence. + typedef ntsa::ConstBufferSequence ConstBufferSequence; -void DataUtil::generateData(bsl::string* result, - bsl::size_t size, - bsl::size_t offset, - bsl::size_t dataset) -{ - result->clear(); - result->resize(size); + /// Define a type alias for a modifiable buffer sequence. + typedef ntsa::MutableBufferSequence + MutableBufferSequence; - for (bsl::size_t i = offset; i < offset + size; ++i) { - (*result)[i] = generateByte(offset + i, dataset); - } -} + public: + // Verify system structure layout and value semantics. + static void verifyCase1(); -void DataUtil::generateData(bdlbb::Blob* result, - bsl::size_t size, - bsl::size_t offset, - bsl::size_t dataset) -{ - result->removeAll(); - result->setLength(static_cast(size)); + // Empty + static void verifyCase2(); - bsl::size_t k = 0; + // [ ] + static void verifyCase3(); - for (int i = 0; i < result->numDataBuffers(); ++i) { - const bdlbb::BlobBuffer& buffer = result->buffer(i); + // [X] + static void verifyCase4(); - bsl::size_t numBytesToWrite = i == result->numDataBuffers() - 1 - ? result->lastDataBufferLength() - : buffer.size(); + // [ ][ ] + static void verifyCase5(); - for (bsl::size_t j = 0; j < numBytesToWrite; ++j) { - buffer.data()[j] = generateByte(offset + k, dataset); - ++k; - } - } -} + // [X][ ] + static void verifyCase6(); -} // close namespace 'test' + // [X][X] + static void verifyCase7(); -NTSCFG_TEST_CASE(1) -{ - // Concern: System structure layout and value semantics - // Plan: + // [ ] + static void verifyCase8(); + + // [X ] + static void verifyCase9(); + + // [XX] + static void verifyCase10(); + + // [ ][ ] + static void verifyCase11(); + + // [X ][ ] + static void verifyCase12(); + + // [XX][ ] + static void verifyCase13(); + // [XX][X ] + static void verifyCase14(); + + // [XX][XX] + static void verifyCase15(); + + // Gathering buffers from a blob + static void verifyCase16(); + + // Scattering buffers to a blob + static void verifyCase17(); + + // Copying data from mutable buffers to a blob + static void verifyCase18(); + + // Copying data from immutable buffers to a blob + static void verifyCase19(); + + // Usage example 1 + static void verifyCase20(); + + // Usage example 2 + static void verifyCase21(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase1) +{ // MutableBuffer structure definition. { @@ -340,807 +312,685 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase2) { - // Concern: Buffer sequence: Empty - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(blob.length(), 0); - NTSCFG_TEST_EQ(blob.totalSize(), 0); + NTSCFG_TEST_EQ(blob.length(), 0); + NTSCFG_TEST_EQ(blob.totalSize(), 0); - { - test::ConstBufferSequence bufferSequence(&blob); + { + ConstBufferSequence bufferSequence(&blob); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it == et); - } + NTSCFG_TEST_TRUE(it == et); + } - { - test::MutableBufferSequence bufferSequence(&blob); + { + MutableBufferSequence bufferSequence(&blob); - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it == et); - } + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase3) { - // Concern: Buffer sequence: [ ] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + blob.setLength(1); + blob.setLength(0); - blob.setLength(1); - blob.setLength(0); + NTSCFG_TEST_EQ(blob.length(), 0); + NTSCFG_TEST_EQ(blob.totalSize(), 1); - NTSCFG_TEST_EQ(blob.length(), 0); - NTSCFG_TEST_EQ(blob.totalSize(), 1); - - { - test::ConstBufferSequence bufferSequence(&blob); - - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - test::MutableBufferSequence bufferSequence(&blob); + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase4) { - // Concern: Buffer sequence: [X] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - blob.setLength(1); - blob.setLength(0); + blob.setLength(1); + blob.setLength(0); - bdlbb::BlobUtil::append(&blob, "X", 1); + bdlbb::BlobUtil::append(&blob, "X", 1); - NTSCFG_TEST_EQ(blob.length(), 1); - NTSCFG_TEST_EQ(blob.totalSize(), 1); + NTSCFG_TEST_EQ(blob.length(), 1); + NTSCFG_TEST_EQ(blob.totalSize(), 1); - { - test::ConstBufferSequence bufferSequence(&blob); - - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } + + { + MutableBufferSequence bufferSequence(&blob); - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it == et); - } + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase5) { - // Concern: Buffer sequence: [ ][ ] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + blob.setLength(2); + blob.setLength(0); - blob.setLength(2); - blob.setLength(0); + NTSCFG_TEST_EQ(blob.length(), 0); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - NTSCFG_TEST_EQ(blob.length(), 0); - NTSCFG_TEST_EQ(blob.totalSize(), 2); - - { - test::ConstBufferSequence bufferSequence(&blob); - - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - test::MutableBufferSequence bufferSequence(&blob); + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); + } - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase6) { - // Concern: Buffer sequence: [X][ ] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - blob.setLength(2); - blob.setLength(0); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::BlobUtil::append(&blob, "X", 1); + blob.setLength(2); + blob.setLength(0); - NTSCFG_TEST_EQ(blob.length(), 1); - NTSCFG_TEST_EQ(blob.totalSize(), 2); + bdlbb::BlobUtil::append(&blob, "X", 1); - { - test::ConstBufferSequence bufferSequence(&blob); + NTSCFG_TEST_EQ(blob.length(), 1); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase7) { - // Concern: Buffer sequence: [X][X] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(1, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - blob.setLength(2); - blob.setLength(0); + blob.setLength(2); + blob.setLength(0); - bdlbb::BlobUtil::append(&blob, "XX", 2); + bdlbb::BlobUtil::append(&blob, "XX", 2); - NTSCFG_TEST_EQ(blob.length(), 2); - NTSCFG_TEST_EQ(blob.totalSize(), 2); + NTSCFG_TEST_EQ(blob.length(), 2); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - { - test::ConstBufferSequence bufferSequence(&blob); + { + ConstBufferSequence bufferSequence(&blob); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it != et); + NTSCFG_TEST_TRUE(it != et); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } - - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); + } - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); + + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(8) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase8) { - // Concern: Buffer sequence: [ ] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - blob.setLength(2); - blob.setLength(0); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(blob.length(), 0); - NTSCFG_TEST_EQ(blob.totalSize(), 2); + blob.setLength(2); + blob.setLength(0); - { - test::ConstBufferSequence bufferSequence(&blob); + NTSCFG_TEST_EQ(blob.length(), 0); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - test::MutableBufferSequence bufferSequence(&blob); + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(9) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase9) { - // Concern: Buffer sequence: [X ] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - blob.setLength(2); - blob.setLength(0); + blob.setLength(2); + blob.setLength(0); - bdlbb::BlobUtil::append(&blob, "X", 1); + bdlbb::BlobUtil::append(&blob, "X", 1); - NTSCFG_TEST_EQ(blob.length(), 1); - NTSCFG_TEST_EQ(blob.totalSize(), 2); + NTSCFG_TEST_EQ(blob.length(), 1); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - { - test::ConstBufferSequence bufferSequence(&blob); - - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data() + 1); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data() + 1); + NTSCFG_TEST_TRUE(buffer.size() == 1); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(10) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase10) { - // Concern: Buffer sequence: [XX] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - blob.setLength(2); - blob.setLength(0); + blob.setLength(2); + blob.setLength(0); - bdlbb::BlobUtil::append(&blob, "XX", 2); + bdlbb::BlobUtil::append(&blob, "XX", 2); - NTSCFG_TEST_EQ(blob.length(), 2); - NTSCFG_TEST_EQ(blob.totalSize(), 2); - - { - test::ConstBufferSequence bufferSequence(&blob); + NTSCFG_TEST_EQ(blob.length(), 2); + NTSCFG_TEST_EQ(blob.totalSize(), 2); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); + + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(11) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase11) { - // Concern: Buffer sequence: [ ][ ] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - blob.setLength(4); - blob.setLength(0); + blob.setLength(4); + blob.setLength(0); - NTSCFG_TEST_EQ(blob.length(), 0); - NTSCFG_TEST_EQ(blob.totalSize(), 4); + NTSCFG_TEST_EQ(blob.length(), 0); + NTSCFG_TEST_EQ(blob.totalSize(), 4); - { - test::ConstBufferSequence bufferSequence(&blob); + { + ConstBufferSequence bufferSequence(&blob); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it == et); - } + NTSCFG_TEST_TRUE(it == et); + } - { - test::MutableBufferSequence bufferSequence(&blob); + { + MutableBufferSequence bufferSequence(&blob); - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it != et); + NTSCFG_TEST_TRUE(it != et); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } - - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); + } - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(12) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase12) { - // Concern: Buffer sequence: [X ][ ] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + blob.setLength(4); + blob.setLength(0); - blob.setLength(4); - blob.setLength(0); + bdlbb::BlobUtil::append(&blob, "X", 1); - bdlbb::BlobUtil::append(&blob, "X", 1); + NTSCFG_TEST_EQ(blob.length(), 1); + NTSCFG_TEST_EQ(blob.totalSize(), 4); - NTSCFG_TEST_EQ(blob.length(), 1); - NTSCFG_TEST_EQ(blob.totalSize(), 4); - - { - test::ConstBufferSequence bufferSequence(&blob); + { + ConstBufferSequence bufferSequence(&blob); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it != et); + NTSCFG_TEST_TRUE(it != et); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } - - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data() + 1); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data() + 1); + NTSCFG_TEST_TRUE(buffer.size() == 1); + } - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(13) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase13) { - // Concern: Buffer sequence: [XX][ ] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - blob.setLength(4); - blob.setLength(0); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::BlobUtil::append(&blob, "XX", 2); + blob.setLength(4); + blob.setLength(0); - NTSCFG_TEST_EQ(blob.length(), 2); - NTSCFG_TEST_EQ(blob.totalSize(), 4); + bdlbb::BlobUtil::append(&blob, "XX", 2); - { - test::ConstBufferSequence bufferSequence(&blob); + NTSCFG_TEST_EQ(blob.length(), 2); + NTSCFG_TEST_EQ(blob.totalSize(), 4); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(14) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase14) { - // Concern: Buffer sequence: [XX][X ] - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + blob.setLength(4); + blob.setLength(0); - blob.setLength(4); - blob.setLength(0); + bdlbb::BlobUtil::append(&blob, "XXX", 3); - bdlbb::BlobUtil::append(&blob, "XXX", 3); + NTSCFG_TEST_EQ(blob.length(), 3); + NTSCFG_TEST_EQ(blob.totalSize(), 4); - NTSCFG_TEST_EQ(blob.length(), 3); - NTSCFG_TEST_EQ(blob.totalSize(), 4); - - { - test::ConstBufferSequence bufferSequence(&blob); + { + ConstBufferSequence bufferSequence(&blob); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - NTSCFG_TEST_TRUE(it != et); + NTSCFG_TEST_TRUE(it != et); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } - - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); + } - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 1); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::MutableBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data() + 1); - NTSCFG_TEST_TRUE(buffer.size() == 1); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::MutableBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data() + 1); + NTSCFG_TEST_TRUE(buffer.size() == 1); } + + ++it; + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(15) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase15) { - // Concern: Buffer sequence: [XX][XX] - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(2, &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(2, NTSCFG_TEST_ALLOCATOR); - blob.setLength(4); - blob.setLength(0); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::BlobUtil::append(&blob, "XXXX", 4); + blob.setLength(4); + blob.setLength(0); - NTSCFG_TEST_EQ(blob.length(), 4); - NTSCFG_TEST_EQ(blob.totalSize(), 4); + bdlbb::BlobUtil::append(&blob, "XXXX", 4); - { - test::ConstBufferSequence bufferSequence(&blob); + NTSCFG_TEST_EQ(blob.length(), 4); + NTSCFG_TEST_EQ(blob.totalSize(), 4); - test::ConstBufferSequence::Iterator it = bufferSequence.begin(); - test::ConstBufferSequence::Iterator et = bufferSequence.end(); + { + ConstBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it != et); + ConstBufferSequence::Iterator it = bufferSequence.begin(); + ConstBufferSequence::Iterator et = bufferSequence.end(); - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it != et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(0).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); + } - { - ntsa::ConstBuffer buffer = *it; - NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); - NTSCFG_TEST_TRUE(buffer.size() == 2); - } + ++it; + NTSCFG_TEST_TRUE(it != et); - ++it; - NTSCFG_TEST_TRUE(it == et); + { + ntsa::ConstBuffer buffer = *it; + NTSCFG_TEST_TRUE(buffer.data() == blob.buffer(1).data()); + NTSCFG_TEST_TRUE(buffer.size() == 2); } - { - test::MutableBufferSequence bufferSequence(&blob); + ++it; + NTSCFG_TEST_TRUE(it == et); + } - test::MutableBufferSequence::Iterator it = bufferSequence.begin(); - test::MutableBufferSequence::Iterator et = bufferSequence.end(); + { + MutableBufferSequence bufferSequence(&blob); - NTSCFG_TEST_TRUE(it == et); - } + MutableBufferSequence::Iterator it = bufferSequence.begin(); + MutableBufferSequence::Iterator et = bufferSequence.end(); + + NTSCFG_TEST_TRUE(it == et); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase16) { - // Concern: Gathering buffers from a blob. - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(17) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase17) { - // Concern: Scattering buffers to a blob. - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(18) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase18) { - // Concern: Copying data from mutable buffers to a blob. - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(19) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase19) { - // Concern: Copying data from immutable buffers to a blob. - // Plan: - const int MIN_SOURCE_BUFFER_SIZE = 1; const int MAX_SOURCE_BUFFER_SIZE = 16; @@ -1150,225 +1000,170 @@ NTSCFG_TEST_CASE(19) const int MIN_MESSAGE_SIZE = 1; const int MAX_MESSAGE_SIZE = 64; - ntscfg::TestAllocator ta; + for (int messageSize = MIN_MESSAGE_SIZE; messageSize <= MAX_MESSAGE_SIZE; + ++messageSize) { - for (int messageSize = MIN_MESSAGE_SIZE; - messageSize <= MAX_MESSAGE_SIZE; - ++messageSize) + NTSCFG_TEST_LOG_DEBUG << "Testing message size " << messageSize + << NTSCFG_TEST_LOG_END; + + for (int sourceBufferSize = MIN_SOURCE_BUFFER_SIZE; + sourceBufferSize <= MAX_SOURCE_BUFFER_SIZE; + ++sourceBufferSize) { - NTSCFG_TEST_LOG_DEBUG << "Testing message size " << messageSize - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Testing source buffer size " + << sourceBufferSize << NTSCFG_TEST_LOG_END; - for (int sourceBufferSize = MIN_SOURCE_BUFFER_SIZE; - sourceBufferSize <= MAX_SOURCE_BUFFER_SIZE; - ++sourceBufferSize) - { - NTSCFG_TEST_LOG_DEBUG << "Testing source buffer size " - << sourceBufferSize - << NTSCFG_TEST_LOG_END; + bdlbb::PooledBlobBufferFactory sourceBlobBufferFactory( + sourceBufferSize, + NTSCFG_TEST_ALLOCATOR); - bdlbb::PooledBlobBufferFactory sourceBlobBufferFactory( - sourceBufferSize, - &ta); + bdlbb::Blob sourceBlob(&sourceBlobBufferFactory, + NTSCFG_TEST_ALLOCATOR); + ntscfg::TestDataUtil::generateData(&sourceBlob, messageSize); - bdlbb::Blob sourceBlob(&sourceBlobBufferFactory, &ta); - test::DataUtil::generateData(&sourceBlob, messageSize); + bsl::vector sourceBufferArray; + sourceBufferArray.resize(sourceBlob.numDataBuffers()); - bsl::vector sourceBufferArray; - sourceBufferArray.resize(sourceBlob.numDataBuffers()); + bsl::size_t numSourceBuffers; + bsl::size_t numSourceBytes; - bsl::size_t numSourceBuffers; - bsl::size_t numSourceBytes; + ntsa::ConstBuffer::gather(&numSourceBuffers, + &numSourceBytes, + &sourceBufferArray[0], + sourceBufferArray.size(), + sourceBlob, + MAX_MESSAGE_SIZE); - ntsa::ConstBuffer::gather(&numSourceBuffers, - &numSourceBytes, - &sourceBufferArray[0], - sourceBufferArray.size(), - sourceBlob, - MAX_MESSAGE_SIZE); + NTSCFG_TEST_EQ(numSourceBuffers, sourceBlob.numDataBuffers()); + NTSCFG_TEST_EQ(numSourceBytes, sourceBlob.length()); - NTSCFG_TEST_EQ(numSourceBuffers, sourceBlob.numDataBuffers()); - NTSCFG_TEST_EQ(numSourceBytes, sourceBlob.length()); + for (int destinationBufferSize = MIN_DESTINATION_BUFFER_SIZE; + destinationBufferSize <= MAX_DESTINATION_BUFFER_SIZE; + ++destinationBufferSize) + { + NTSCFG_TEST_LOG_DEBUG << "Testing destination buffer size " + << destinationBufferSize + << NTSCFG_TEST_LOG_END; + + bdlbb::PooledBlobBufferFactory destinationBlobBufferFactory( + destinationBufferSize, + NTSCFG_TEST_ALLOCATOR); - for (int destinationBufferSize = MIN_DESTINATION_BUFFER_SIZE; - destinationBufferSize <= MAX_DESTINATION_BUFFER_SIZE; - ++destinationBufferSize) - { - NTSCFG_TEST_LOG_DEBUG << "Testing destination buffer size " - << destinationBufferSize - << NTSCFG_TEST_LOG_END; + for (int offset = 0; offset < sourceBlob.length(); ++offset) { + bdlbb::Blob truncatedSourceBlob = sourceBlob; + bdlbb::BlobUtil::erase(&truncatedSourceBlob, 0, offset); - bdlbb::PooledBlobBufferFactory - destinationBlobBufferFactory(destinationBufferSize, - &ta); + { + bdlbb::Blob destinationBlob( + &destinationBlobBufferFactory, + NTSCFG_TEST_ALLOCATOR); + + ntsa::ConstBuffer::copy(&destinationBlob, + &sourceBufferArray[0], + sourceBufferArray.size(), + offset); + + NTSCFG_TEST_EQ(destinationBlob.length(), + truncatedSourceBlob.length()); + + NTSCFG_TEST_EQ( + bdlbb::BlobUtil::compare(destinationBlob, + truncatedSourceBlob), + 0); + } - for (int offset = 0; offset < sourceBlob.length(); - ++offset) { - bdlbb::Blob truncatedSourceBlob = sourceBlob; - bdlbb::BlobUtil::erase(&truncatedSourceBlob, - 0, - offset); - - { - bdlbb::Blob destinationBlob( - &destinationBlobBufferFactory, - &ta); - - ntsa::ConstBuffer::copy(&destinationBlob, - &sourceBufferArray[0], - sourceBufferArray.size(), - offset); - - NTSCFG_TEST_EQ(destinationBlob.length(), - truncatedSourceBlob.length()); - - NTSCFG_TEST_EQ( - bdlbb::BlobUtil::compare(destinationBlob, - truncatedSourceBlob), - 0); - } - - { - bdlbb::Blob destinationBlob( - &destinationBlobBufferFactory, - &ta); - - ntsa::MutableBuffer::copy( - &destinationBlob, - reinterpret_cast( - &sourceBufferArray[0]), - sourceBufferArray.size(), - offset); - - NTSCFG_TEST_EQ(destinationBlob.length(), - truncatedSourceBlob.length()); - - NTSCFG_TEST_EQ( - bdlbb::BlobUtil::compare(destinationBlob, - truncatedSourceBlob), - 0); - } + bdlbb::Blob destinationBlob( + &destinationBlobBufferFactory, + NTSCFG_TEST_ALLOCATOR); + + ntsa::MutableBuffer::copy( + &destinationBlob, + reinterpret_cast( + &sourceBufferArray[0]), + sourceBufferArray.size(), + offset); + + NTSCFG_TEST_EQ(destinationBlob.length(), + truncatedSourceBlob.length()); + + NTSCFG_TEST_EQ( + bdlbb::BlobUtil::compare(destinationBlob, + truncatedSourceBlob), + 0); } } } } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(20) +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase20) { - // Concern: Usage example 1 - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(8, NTSCFG_TEST_ALLOCATOR); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(8, &ta); - bdlbb::Blob blob(&blobBufferFactory, &ta); - - bdlbb::BlobUtil::append(&blob, "Hello, world!", 0, 13); - - BSLS_ASSERT(blob.numBuffers() == 2); - - const bdlbb::BlobBuffer& blobBuffer1 = blob.buffer(0); - const bdlbb::BlobBuffer& blobBuffer2 = blob.buffer(1); - - ntsa::ConstBufferSequence constBufferSequence( - &blob); + bdlbb::BlobUtil::append(&blob, "Hello, world!", 0, 13); - ntsa::ConstBufferSequence::Iterator it; + BSLS_ASSERT(blob.numBuffers() == 2); - it = constBufferSequence.begin(); - BSLS_ASSERT(it != constBufferSequence.end()); + const bdlbb::BlobBuffer& blobBuffer1 = blob.buffer(0); + const bdlbb::BlobBuffer& blobBuffer2 = blob.buffer(1); - { - ntsa::ConstBuffer constBuffer = *it; - BSLS_ASSERT(constBuffer.data() == blobBuffer1.data()); - BSLS_ASSERT(constBuffer.size() == 8); - } + ntsa::ConstBufferSequence constBufferSequence(&blob); - ++it; - BSLS_ASSERT(it != constBufferSequence.end()); + ntsa::ConstBufferSequence::Iterator it; - { - ntsa::ConstBuffer constBuffer = *it; - BSLS_ASSERT(constBuffer.data() == blobBuffer2.data()); - BSLS_ASSERT(constBuffer.size() == 5); - } + it = constBufferSequence.begin(); + BSLS_ASSERT(it != constBufferSequence.end()); - ++it; - BSLS_ASSERT(it == constBufferSequence.end()); + { + ntsa::ConstBuffer constBuffer = *it; + BSLS_ASSERT(constBuffer.data() == blobBuffer1.data()); + BSLS_ASSERT(constBuffer.size() == 8); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(21) -{ - // Concern: Usage example 2 - // Plan: + ++it; + BSLS_ASSERT(it != constBufferSequence.end()); - ntscfg::TestAllocator ta; { - bdlbb::PooledBlobBufferFactory blobBufferFactory(8, &ta); - bdlbb::Blob blob(&blobBufferFactory, &ta); - - bdlbb::BlobUtil::append(&blob, "Hello, world!", 0, 13); - - BSLS_ASSERT(blob.numBuffers() == 2); - - const bdlbb::BlobBuffer& blobBuffer2 = blob.buffer(1); - - ntsa::MutableBufferSequence mutableBufferSequence( - &blob); - - ntsa::MutableBufferSequence::Iterator it; - - it = mutableBufferSequence.begin(); - BSLS_ASSERT(it != mutableBufferSequence.end()); - - { - ntsa::MutableBuffer mutableBuffer = *it; - BSLS_ASSERT(mutableBuffer.data() == blobBuffer2.data() + 5); - BSLS_ASSERT(mutableBuffer.size() == 3); - } - - ++it; - BSLS_ASSERT(it == mutableBufferSequence.end()); + ntsa::ConstBuffer constBuffer = *it; + BSLS_ASSERT(constBuffer.data() == blobBuffer2.data()); + BSLS_ASSERT(constBuffer.size() == 5); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + ++it; + BSLS_ASSERT(it == constBufferSequence.end()); } -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::BufferTest::verifyCase21) { - NTSCFG_TEST_REGISTER(1); // Value semantics + bdlbb::PooledBlobBufferFactory blobBufferFactory(8, NTSCFG_TEST_ALLOCATOR); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_REGISTER(2); // Empty + bdlbb::BlobUtil::append(&blob, "Hello, world!", 0, 13); - NTSCFG_TEST_REGISTER(3); // [ ] - NTSCFG_TEST_REGISTER(4); // [X] + BSLS_ASSERT(blob.numBuffers() == 2); - NTSCFG_TEST_REGISTER(5); // [ ][ ] - NTSCFG_TEST_REGISTER(6); // [X][ ] - NTSCFG_TEST_REGISTER(7); // [X][X] + const bdlbb::BlobBuffer& blobBuffer2 = blob.buffer(1); - NTSCFG_TEST_REGISTER(8); // [ ] - NTSCFG_TEST_REGISTER(9); // [X ] - NTSCFG_TEST_REGISTER(10); // [XX] + ntsa::MutableBufferSequence mutableBufferSequence( + &blob); - NTSCFG_TEST_REGISTER(11); // [ ][ ] - NTSCFG_TEST_REGISTER(12); // [X ][ ] - NTSCFG_TEST_REGISTER(13); // [XX][ ] - NTSCFG_TEST_REGISTER(14); // [XX][X ] - NTSCFG_TEST_REGISTER(15); // [XX][XX] + ntsa::MutableBufferSequence::Iterator it; + it = mutableBufferSequence.begin(); + BSLS_ASSERT(it != mutableBufferSequence.end()); - NTSCFG_TEST_REGISTER(16); // Gathering buffers from a blob - NTSCFG_TEST_REGISTER(17); // Scattering buffers to a blob - NTSCFG_TEST_REGISTER(18); // Copying data from mutable buffers to a blob - NTSCFG_TEST_REGISTER(19); // Copying data from immutable buffers to a blob + { + ntsa::MutableBuffer mutableBuffer = *it; + BSLS_ASSERT(mutableBuffer.data() == blobBuffer2.data() + 5); + BSLS_ASSERT(mutableBuffer.size() == 3); + } - NTSCFG_TEST_REGISTER(20); // Usage example 1 - NTSCFG_TEST_REGISTER(21); // Usage example 2 + ++it; + BSLS_ASSERT(it == mutableBufferSequence.end()); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_data.t.cpp b/groups/nts/ntsa/ntsa_data.t.cpp index 82f3d457..dd6b8e69 100644 --- a/groups/nts/ntsa/ntsa_data.t.cpp +++ b/groups/nts/ntsa/ntsa_data.t.cpp @@ -13,41 +13,37 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntsa_data_t_cpp, "$Id$ $CSID$") + #include #include -#include - -#include -#include -#include -#include -#include -#include -#include using namespace BloombergLP; -using namespace ntsa; -namespace test { +namespace BloombergLP { +namespace ntsa { -const bsl::size_t BLOB_BUFFER_SIZE = 4; +// Provide tests for 'ntsa::Data'. +class DataTest +{ + static const bsl::size_t k_BLOB_BUFFER_SIZE; -const char DATA[] = "Hello, world!"; -const bsl::size_t DATA_SIZE = sizeof(DATA) - 1; + static const char k_DATA[]; + static const bsl::size_t k_DATA_SIZE; -const char DATA_A[] = "Hello, world! "; -const bsl::size_t DATA_A_SIZE = sizeof(DATA_A) - 1; + static const char k_DATA_A[]; + static const bsl::size_t k_DATA_A_SIZE; -const char DATA_B[] = "This is a test of the data utility algorithms. "; -const bsl::size_t DATA_B_SIZE = sizeof(DATA_B) - 1; + static const char k_DATA_B[]; + static const bsl::size_t k_DATA_B_SIZE; -const char DATA_C[] = "The blob should match its expected value. "; -const bsl::size_t DATA_C_SIZE = sizeof(DATA_C) - 1; + static const char k_DATA_C[]; + static const bsl::size_t k_DATA_C_SIZE; -/// Provide utilities for comparing the contents of a blob -/// for the purposes of this test driver. -struct BlobUtil { /// Return true if the contents of the specified 'blob' equals the /// contents of the specified 'string', otherwise return false. static bool equals(const bdlbb::Blob& blob, const bsl::string& string); @@ -60,9 +56,133 @@ struct BlobUtil { const bsl::string& stringA, const bsl::string& stringB, const bsl::string& stringC); + + public: + // Verify selection: undefined. + static void verifyCase1(); + + // Verify selection: bdlbb::BlobBuffer + static void verifyCase2(); + + // Verify selection: ntsa::ConstBuffer + static void verifyCase3(); + + // Verify selection: ntsa::ConstBufferArray + static void verifyCase4(); + + // Verify selection: ntsa::ConstBufferPtrArray + static void verifyCase5(); + + // Verify selection: ntsa::MutableBuffer + static void verifyCase6(); + + // Verify selection: ntsa::MutableBufferArray + static void verifyCase7(); + + // Verify selection: ntsa::MutableBufferPtrArray + static void verifyCase8(); + + // Verify selection: bdlbb::Blob + static void verifyCase9(); + + // Verify selection: bsl::shared_ptr + static void verifyCase10(); + + // Verify selection: bsl::string + static void verifyCase11(); + + // Verify selection: ntsa::File + static void verifyCase12(); + + // Verify append: undefined + static void verifyCase13(); + + // Verify append: bdlbb::BlobBuffer + static void verifyCase14(); + + // Verify append: ntsa::ConstBuffer + static void verifyCase15(); + + // Verify append: ntsa::ConstBufferArray + static void verifyCase16(); + + // Verify append: ntsa::ConstBufferPtrArray + static void verifyCase17(); + + // Verify append: ntsa::MutableBuffer + static void verifyCase18(); + + // Verify append: ntsa::MutableBufferArray + static void verifyCase19(); + + // Verify append: ntsa::MutableBufferPtrArray + static void verifyCase20(); + + // Verify append: bdlbb::Blob + static void verifyCase21(); + + // Verify append: bsl::shared_ptr + static void verifyCase22(); + + // Verify append: bsl::string + static void verifyCase23(); + + // Verify append: ntsa::File + static void verifyCase24(); + + // Verify copy: undefined + static void verifyCase25(); + + // Verify copy: bdlbb::BlobBuffer + static void verifyCase26(); + + // Verify copy: ntsa::ConstBuffer + static void verifyCase27(); + + // Verify copy: ntsa::ConstBufferArray + static void verifyCase28(); + + // Verify copy: ntsa::ConstBufferPtrArray + static void verifyCase29(); + + // Verify copy: ntsa::MutableBuffer + static void verifyCase30(); + + // Verify copy: ntsa::MutableBufferArray + static void verifyCase31(); + + // Verify copy: ntsa::MutableBufferPtrArray + static void verifyCase32(); + + // Verify copy: bdlbb::Blob + static void verifyCase33(); + + // Verify copy: bsl::shared_ptr + static void verifyCase34(); + + // Verify copy: bsl::string + static void verifyCase35(); + + // Verify copy: ntsa::File + static void verifyCase36(); }; -bool BlobUtil::equals(const bdlbb::Blob& blob, const bsl::string& string) +const bsl::size_t DataTest::k_BLOB_BUFFER_SIZE = 4; + +const char DataTest::k_DATA[] = "Hello, world!"; +const bsl::size_t DataTest::k_DATA_SIZE = sizeof(DataTest::k_DATA) - 1; + +const char DataTest::k_DATA_A[] = "Hello, world! "; +const bsl::size_t DataTest::k_DATA_A_SIZE = sizeof(DataTest::k_DATA_A) - 1; + +const char DataTest::k_DATA_B[] = + "This is a test of the data utility algorithms. "; +const bsl::size_t DataTest::k_DATA_B_SIZE = sizeof(DataTest::k_DATA_B) - 1; + +const char DataTest::k_DATA_C[] = "The blob should match its expected value. "; +const bsl::size_t DataTest::k_DATA_C_SIZE = sizeof(DataTest::k_DATA_C) - 1; + +bool DataTest::equals(const bdlbb::Blob& blob, const bsl::string& string) { bsl::string blobAsString; { @@ -83,1112 +203,765 @@ bool BlobUtil::equals(const bdlbb::Blob& blob, const bsl::string& string) return true; } -bool BlobUtil::equals(const bdlbb::Blob& blob, +bool DataTest::equals(const bdlbb::Blob& blob, const bsl::string& stringA, const bsl::string& stringB, const bsl::string& stringC) { - return BlobUtil::equals(blob, stringA + stringB + stringC); + return DataTest::equals(blob, stringA + stringB + stringC); } -} // close namespace test - -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase1) { - // Concern: undefined - // Plan: + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - ntsa::Data data(&ta); - - NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_UNDEFINED); - NTSCFG_TEST_TRUE(data.isUndefined()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_UNDEFINED); + NTSCFG_TEST_TRUE(data.isUndefined()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase2) { - // Concern: bdlbb::BlobBuffer - // Plan: + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; + bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); { - ntsa::Data data(&ta); - - bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); - { - bsl::shared_ptr blobBufferData( - static_cast(ta.allocate(64)), - &ta, - 0); + bsl::shared_ptr blobBufferData( + static_cast(NTSCFG_TEST_ALLOCATOR->allocate(64)), + NTSCFG_TEST_ALLOCATOR, + 0); - blobBuffer.reset(blobBufferData, 64); - } - - NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_BLOB_BUFFER); - NTSCFG_TEST_TRUE(data.isBlobBuffer()); + blobBuffer.reset(blobBufferData, 64); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_BLOB_BUFFER); + NTSCFG_TEST_TRUE(data.isBlobBuffer()); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase3) { - // Concern: ntsa::ConstBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase4) { - // Concern: ntsa::ConstBufferArray - // Plan: + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; + ntsa::ConstBufferArray& constBufferArray = data.makeConstBufferArray(); { - ntsa::Data data(&ta); - - ntsa::ConstBufferArray& constBufferArray = data.makeConstBufferArray(); - { - bsl::vector region1(128); - bsl::vector region2(256); - bsl::vector region3(512); + bsl::vector region1(128); + bsl::vector region2(256); + bsl::vector region3(512); - constBufferArray.append(®ion1.front(), region1.size()); - constBufferArray.append(®ion2.front(), region2.size()); - constBufferArray.append(®ion3.front(), region3.size()); + constBufferArray.append(®ion1.front(), region1.size()); + constBufferArray.append(®ion2.front(), region2.size()); + constBufferArray.append(®ion3.front(), region3.size()); - NTSCFG_TEST_EQ(constBufferArray.numBuffers(), 3); + NTSCFG_TEST_EQ(constBufferArray.numBuffers(), 3); - NTSCFG_TEST_TRUE(constBufferArray.buffer(0).data() == - ®ion1.front()); + NTSCFG_TEST_TRUE(constBufferArray.buffer(0).data() == + ®ion1.front()); - NTSCFG_TEST_TRUE(constBufferArray.buffer(1).data() == - ®ion2.front()); + NTSCFG_TEST_TRUE(constBufferArray.buffer(1).data() == + ®ion2.front()); - NTSCFG_TEST_TRUE(constBufferArray.buffer(2).data() == - ®ion3.front()); - } - - NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_CONST_BUFFER_ARRAY); - NTSCFG_TEST_TRUE(data.isConstBufferArray()); + NTSCFG_TEST_TRUE(constBufferArray.buffer(2).data() == + ®ion3.front()); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_EQ(data.type(), ntsa::DataType::e_CONST_BUFFER_ARRAY); + NTSCFG_TEST_TRUE(data.isConstBufferArray()); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase5) { - // Concern: ntsa::ConstBufferPtrArray - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase6) { - // Concern: ntsa::MutableBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase7) { - // Concern: ntsa::MutableBufferArray - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(8) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase8) { - // Concern: ntsa::MutableBufferPtrArray - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(9) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase9) { - // Concern: bdlbb::Blob - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(1024, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory(1024, &ta); - - ntsa::Data data(&blobBufferFactory, &ta); + ntsa::Data data(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob& blob = data.makeBlob(); - bdlbb::BlobUtil::append(&blob, "Hello, world!", 13); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + bdlbb::Blob& blob = data.makeBlob(); + bdlbb::BlobUtil::append(&blob, "Hello, world!", 13); } -NTSCFG_TEST_CASE(10) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase10) { - // Concern: bsl::shared_ptr - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(11) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase11) { - // Concern: bsl::string - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(12) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase12) { - // Concern: ntsa::File - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(13) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase13) { - // Concern: Append: undefined - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - { - ntsa::Data data(&ta); - ntsa::DataUtil::append(&blob, data); - } - - NTSCFG_TEST_EQ(blob.length(), 0); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_EQ(blob.length(), 0); } -NTSCFG_TEST_CASE(14) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase14) { - // Concern: Append: bdlbb::BlobBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); - - bsl::shared_ptr blobBufferData( - static_cast(ta.allocate(test::DATA_SIZE)), - &ta, - 0); + bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); - bsl::memcpy(blobBufferData.get(), test::DATA, test::DATA_SIZE); - blobBuffer.reset(blobBufferData, test::DATA_SIZE); - } + bsl::shared_ptr blobBufferData( + static_cast( + NTSCFG_TEST_ALLOCATOR->allocate(k_DATA_SIZE)), + NTSCFG_TEST_ALLOCATOR, + 0); - ntsa::DataUtil::append(&blob, data); + bsl::memcpy(blobBufferData.get(), k_DATA, k_DATA_SIZE); + blobBuffer.reset(blobBufferData, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(15) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase15) { - // Concern: Append: ntsa::ConstBuffer - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBuffer& constBuffer = data.makeConstBuffer(); - constBuffer.setBuffer(test::DATA, test::DATA_SIZE); - } - - ntsa::DataUtil::append(&blob, data); + ntsa::ConstBuffer& constBuffer = data.makeConstBuffer(); + constBuffer.setBuffer(k_DATA, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase16) { - // Concern: Append: ntsa::ConstBufferArray - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBufferArray& constBufferArray = - data.makeConstBufferArray(); - - constBufferArray.append(test::DATA_A, test::DATA_A_SIZE); - constBufferArray.append(test::DATA_B, test::DATA_B_SIZE); - constBufferArray.append(test::DATA_C, test::DATA_C_SIZE); - } + ntsa::ConstBufferArray& constBufferArray = + data.makeConstBufferArray(); - ntsa::DataUtil::append(&blob, data); + constBufferArray.append(k_DATA_A, k_DATA_A_SIZE); + constBufferArray.append(k_DATA_B, k_DATA_B_SIZE); + constBufferArray.append(k_DATA_C, k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(17) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase17) { - // Concern: Append: ntsa::ConstBufferPtrArray - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - ntsa::ConstBuffer constBufferArray[3]; - constBufferArray[0].setBuffer(test::DATA_A, test::DATA_A_SIZE); - constBufferArray[1].setBuffer(test::DATA_B, test::DATA_B_SIZE); - constBufferArray[2].setBuffer(test::DATA_C, test::DATA_C_SIZE); + ntsa::ConstBuffer constBufferArray[3]; + constBufferArray[0].setBuffer(k_DATA_A, k_DATA_A_SIZE); + constBufferArray[1].setBuffer(k_DATA_B, k_DATA_B_SIZE); + constBufferArray[2].setBuffer(k_DATA_C, k_DATA_C_SIZE); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBufferPtrArray& constBufferPtrArray = - data.makeConstBufferPtrArray(); + ntsa::ConstBufferPtrArray& constBufferPtrArray = + data.makeConstBufferPtrArray(); - constBufferPtrArray.assign(constBufferArray, 3); - } - - ntsa::DataUtil::append(&blob, data); + constBufferPtrArray.assign(constBufferArray, 3); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(18) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase18) { - // Concern: Append: ntsa::MutableBuffer - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); - - bsl::string mutableBufferStorage = test::DATA; + bsl::string mutableBufferStorage = k_DATA; + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBuffer& mutableBuffer = data.makeMutableBuffer(); + ntsa::MutableBuffer& mutableBuffer = data.makeMutableBuffer(); - mutableBuffer.setBuffer(&mutableBufferStorage[0], - mutableBufferStorage.size()); - } - - ntsa::DataUtil::append(&blob, data); + mutableBuffer.setBuffer(&mutableBufferStorage[0], + mutableBufferStorage.size()); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(19) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase19) { - // Concern: Append: ntsa::MutableBufferArray - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bsl::string mutableBufferStorageA = test::DATA_A; - bsl::string mutableBufferStorageB = test::DATA_B; - bsl::string mutableBufferStorageC = test::DATA_C; + bsl::string mutableBufferStorageA = k_DATA_A; + bsl::string mutableBufferStorageB = k_DATA_B; + bsl::string mutableBufferStorageC = k_DATA_C; + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBufferArray& mutableBufferArray = - data.makeMutableBufferArray(); - - mutableBufferArray.append(&mutableBufferStorageA[0], - mutableBufferStorageA.size()); + ntsa::MutableBufferArray& mutableBufferArray = + data.makeMutableBufferArray(); - mutableBufferArray.append(&mutableBufferStorageB[0], - mutableBufferStorageB.size()); + mutableBufferArray.append(&mutableBufferStorageA[0], + mutableBufferStorageA.size()); - mutableBufferArray.append(&mutableBufferStorageC[0], - mutableBufferStorageC.size()); - } + mutableBufferArray.append(&mutableBufferStorageB[0], + mutableBufferStorageB.size()); - ntsa::DataUtil::append(&blob, data); + mutableBufferArray.append(&mutableBufferStorageC[0], + mutableBufferStorageC.size()); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(20) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase20) { - // Concern: Append: ntsa::MutableBufferPtrArray - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bsl::string mutableBufferStorageA = test::DATA_A; - bsl::string mutableBufferStorageB = test::DATA_B; - bsl::string mutableBufferStorageC = test::DATA_C; + bsl::string mutableBufferStorageA = k_DATA_A; + bsl::string mutableBufferStorageB = k_DATA_B; + bsl::string mutableBufferStorageC = k_DATA_C; - ntsa::MutableBuffer mutableBufferArray[3]; + ntsa::MutableBuffer mutableBufferArray[3]; - mutableBufferArray[0].setBuffer(&mutableBufferStorageA[0], - mutableBufferStorageA.size()); + mutableBufferArray[0].setBuffer(&mutableBufferStorageA[0], + mutableBufferStorageA.size()); - mutableBufferArray[1].setBuffer(&mutableBufferStorageB[0], - mutableBufferStorageB.size()); + mutableBufferArray[1].setBuffer(&mutableBufferStorageB[0], + mutableBufferStorageB.size()); - mutableBufferArray[2].setBuffer(&mutableBufferStorageC[0], - mutableBufferStorageC.size()); + mutableBufferArray[2].setBuffer(&mutableBufferStorageC[0], + mutableBufferStorageC.size()); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBufferPtrArray& mutableBufferPtrArray = - data.makeMutableBufferPtrArray(); - - mutableBufferPtrArray.assign(mutableBufferArray, 3); - } + ntsa::MutableBufferPtrArray& mutableBufferPtrArray = + data.makeMutableBufferPtrArray(); - ntsa::DataUtil::append(&blob, data); + mutableBufferPtrArray.assign(mutableBufferArray, 3); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(21) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase21) { - // Concern: Append: bdlbb::Blob - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&blobBufferFactory, &ta); - { - bdlbb::Blob& dataBlob = data.makeBlob(); - - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_A, - test::DATA_A_SIZE); - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_B, - test::DATA_B_SIZE); - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_C, - test::DATA_C_SIZE); - } - - ntsa::DataUtil::append(&blob, data); + bdlbb::Blob& dataBlob = data.makeBlob(); + + bdlbb::BlobUtil::append(&dataBlob, k_DATA_A, k_DATA_A_SIZE); + bdlbb::BlobUtil::append(&dataBlob, k_DATA_B, k_DATA_B_SIZE); + bdlbb::BlobUtil::append(&dataBlob, k_DATA_C, k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(22) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase22) { - // Concern: Append: bsl::shared_ptr - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&blobBufferFactory, &ta); - { - bsl::shared_ptr& dataSharedBlob = - data.makeSharedBlob(); - dataSharedBlob.createInplace(&ta, &blobBufferFactory, &ta); - - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_A, - test::DATA_A_SIZE); - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_B, - test::DATA_B_SIZE); - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_C, - test::DATA_C_SIZE); - } - - ntsa::DataUtil::append(&blob, data); + bsl::shared_ptr& dataSharedBlob = + data.makeSharedBlob(); + dataSharedBlob.createInplace(NTSCFG_TEST_ALLOCATOR, + &blobBufferFactory, + NTSCFG_TEST_ALLOCATOR); + + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_A, + k_DATA_A_SIZE); + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_B, + k_DATA_B_SIZE); + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_C, + k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(23) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase23) { - // Concern: Append: bsl::string - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - bsl::string& dataString = data.makeString(); - dataString.assign(test::DATA, test::DATA_SIZE); - } - - ntsa::DataUtil::append(&blob, data); + bsl::string& dataString = data.makeString(); + dataString.assign(k_DATA, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::append(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(24) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase24) { - // Concern: Append: ntsa::File - // Plan: + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - ntsa::TemporaryFile tempFile(&ta); + ntsa::TemporaryFile tempFile(NTSCFG_TEST_ALLOCATOR); - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - error = tempFile.write(bsl::string(test::DATA, test::DATA_SIZE)); - NTSCFG_TEST_OK(error); + error = tempFile.write(bsl::string(k_DATA, k_DATA_SIZE)); + NTSCFG_TEST_OK(error); - bdls::FilesystemUtil::FileDescriptor fileDescriptor = - bdls::FilesystemUtil::open(tempFile.path().c_str(), - bdls::FilesystemUtil::e_OPEN, - bdls::FilesystemUtil::e_READ_ONLY); + bdls::FilesystemUtil::FileDescriptor fileDescriptor = + bdls::FilesystemUtil::open(tempFile.path().c_str(), + bdls::FilesystemUtil::e_OPEN, + bdls::FilesystemUtil::e_READ_ONLY); - NTSCFG_TEST_NE(fileDescriptor, bdls::FilesystemUtil::k_INVALID_FD); + NTSCFG_TEST_NE(fileDescriptor, bdls::FilesystemUtil::k_INVALID_FD); - ntsa::Data data(&ta); - { - ntsa::File& file = data.makeFile(); + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); + { + ntsa::File& file = data.makeFile(); - file.setDescriptor(fileDescriptor); - file.setBytesRemaining(test::DATA_SIZE); - } + file.setDescriptor(fileDescriptor); + file.setBytesRemaining(k_DATA_SIZE); + } - ntsa::DataUtil::append(&blob, data); + ntsa::DataUtil::append(&blob, data); - bdls::FilesystemUtil::close(fileDescriptor); + bdls::FilesystemUtil::close(fileDescriptor); - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(25) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase25) { - // Concern: Copy: undefined - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - { - ntsa::Data data(&ta); - ntsa::DataUtil::copy(&blob, data); - } - - NTSCFG_TEST_EQ(blob.length(), 0); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_EQ(blob.length(), 0); } -NTSCFG_TEST_CASE(26) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase26) { - // Concern: Copy: bdlbb::BlobBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); - - bsl::shared_ptr blobBufferData( - static_cast(ta.allocate(test::DATA_SIZE)), - &ta, - 0); + bdlbb::BlobBuffer& blobBuffer = data.makeBlobBuffer(); - bsl::memcpy(blobBufferData.get(), test::DATA, test::DATA_SIZE); - blobBuffer.reset(blobBufferData, test::DATA_SIZE); - } + bsl::shared_ptr blobBufferData( + static_cast( + NTSCFG_TEST_ALLOCATOR->allocate(k_DATA_SIZE)), + NTSCFG_TEST_ALLOCATOR, + 0); - ntsa::DataUtil::copy(&blob, data); + bsl::memcpy(blobBufferData.get(), k_DATA, k_DATA_SIZE); + blobBuffer.reset(blobBufferData, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(27) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase27) { - // Concern: Copy: ntsa::ConstBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBuffer& constBuffer = data.makeConstBuffer(); - constBuffer.setBuffer(test::DATA, test::DATA_SIZE); - } - - ntsa::DataUtil::copy(&blob, data); + ntsa::ConstBuffer& constBuffer = data.makeConstBuffer(); + constBuffer.setBuffer(k_DATA, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(28) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase28) { - // Concern: Copy: ntsa::ConstBufferArray - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBufferArray& constBufferArray = - data.makeConstBufferArray(); - - constBufferArray.append(test::DATA_A, test::DATA_A_SIZE); - constBufferArray.append(test::DATA_B, test::DATA_B_SIZE); - constBufferArray.append(test::DATA_C, test::DATA_C_SIZE); - } + ntsa::ConstBufferArray& constBufferArray = + data.makeConstBufferArray(); - ntsa::DataUtil::copy(&blob, data); + constBufferArray.append(k_DATA_A, k_DATA_A_SIZE); + constBufferArray.append(k_DATA_B, k_DATA_B_SIZE); + constBufferArray.append(k_DATA_C, k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(29) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase29) { - // Concern: Copy: ntsa::ConstBufferPtrArray - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - ntsa::ConstBuffer constBufferArray[3]; - constBufferArray[0].setBuffer(test::DATA_A, test::DATA_A_SIZE); - constBufferArray[1].setBuffer(test::DATA_B, test::DATA_B_SIZE); - constBufferArray[2].setBuffer(test::DATA_C, test::DATA_C_SIZE); + ntsa::ConstBuffer constBufferArray[3]; + constBufferArray[0].setBuffer(k_DATA_A, k_DATA_A_SIZE); + constBufferArray[1].setBuffer(k_DATA_B, k_DATA_B_SIZE); + constBufferArray[2].setBuffer(k_DATA_C, k_DATA_C_SIZE); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::ConstBufferPtrArray& constBufferPtrArray = - data.makeConstBufferPtrArray(); - - constBufferPtrArray.assign(constBufferArray, 3); - } + ntsa::ConstBufferPtrArray& constBufferPtrArray = + data.makeConstBufferPtrArray(); - ntsa::DataUtil::copy(&blob, data); + constBufferPtrArray.assign(constBufferArray, 3); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(30) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase30) { - // Concern: Copy: ntsa::MutableBuffer - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bsl::string mutableBufferStorage = test::DATA; + bsl::string mutableBufferStorage = k_DATA; + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBuffer& mutableBuffer = data.makeMutableBuffer(); - - mutableBuffer.setBuffer(&mutableBufferStorage[0], - mutableBufferStorage.size()); - } + ntsa::MutableBuffer& mutableBuffer = data.makeMutableBuffer(); - ntsa::DataUtil::copy(&blob, data); + mutableBuffer.setBuffer(&mutableBufferStorage[0], + mutableBufferStorage.size()); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(31) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase31) { - // Concern: Copy: ntsa::MutableBufferArray - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); - - bsl::string mutableBufferStorageA = test::DATA_A; - bsl::string mutableBufferStorageB = test::DATA_B; - bsl::string mutableBufferStorageC = test::DATA_C; + bsl::string mutableBufferStorageA = k_DATA_A; + bsl::string mutableBufferStorageB = k_DATA_B; + bsl::string mutableBufferStorageC = k_DATA_C; + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBufferArray& mutableBufferArray = - data.makeMutableBufferArray(); - - mutableBufferArray.append(&mutableBufferStorageA[0], - mutableBufferStorageA.size()); + ntsa::MutableBufferArray& mutableBufferArray = + data.makeMutableBufferArray(); - mutableBufferArray.append(&mutableBufferStorageB[0], - mutableBufferStorageB.size()); + mutableBufferArray.append(&mutableBufferStorageA[0], + mutableBufferStorageA.size()); - mutableBufferArray.append(&mutableBufferStorageC[0], - mutableBufferStorageC.size()); - } + mutableBufferArray.append(&mutableBufferStorageB[0], + mutableBufferStorageB.size()); - ntsa::DataUtil::copy(&blob, data); + mutableBufferArray.append(&mutableBufferStorageC[0], + mutableBufferStorageC.size()); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(32) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase32) { - // Concern: Copy: ntsa::MutableBufferPtrArray - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - bsl::string mutableBufferStorageA = test::DATA_A; - bsl::string mutableBufferStorageB = test::DATA_B; - bsl::string mutableBufferStorageC = test::DATA_C; + bsl::string mutableBufferStorageA = k_DATA_A; + bsl::string mutableBufferStorageB = k_DATA_B; + bsl::string mutableBufferStorageC = k_DATA_C; - ntsa::MutableBuffer mutableBufferArray[3]; + ntsa::MutableBuffer mutableBufferArray[3]; - mutableBufferArray[0].setBuffer(&mutableBufferStorageA[0], - mutableBufferStorageA.size()); + mutableBufferArray[0].setBuffer(&mutableBufferStorageA[0], + mutableBufferStorageA.size()); - mutableBufferArray[1].setBuffer(&mutableBufferStorageB[0], - mutableBufferStorageB.size()); + mutableBufferArray[1].setBuffer(&mutableBufferStorageB[0], + mutableBufferStorageB.size()); - mutableBufferArray[2].setBuffer(&mutableBufferStorageC[0], - mutableBufferStorageC.size()); + mutableBufferArray[2].setBuffer(&mutableBufferStorageC[0], + mutableBufferStorageC.size()); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - ntsa::MutableBufferPtrArray& mutableBufferPtrArray = - data.makeMutableBufferPtrArray(); + ntsa::MutableBufferPtrArray& mutableBufferPtrArray = + data.makeMutableBufferPtrArray(); - mutableBufferPtrArray.assign(mutableBufferArray, 3); - } - - ntsa::DataUtil::copy(&blob, data); + mutableBufferPtrArray.assign(mutableBufferArray, 3); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(33) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase33) { - // Concern: Copy: bdlbb::Blob - // Plan: - - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&blobBufferFactory, &ta); - { - bdlbb::Blob& dataBlob = data.makeBlob(); - - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_A, - test::DATA_A_SIZE); - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_B, - test::DATA_B_SIZE); - bdlbb::BlobUtil::append(&dataBlob, - test::DATA_C, - test::DATA_C_SIZE); - } - - ntsa::DataUtil::copy(&blob, data); + bdlbb::Blob& dataBlob = data.makeBlob(); + + bdlbb::BlobUtil::append(&dataBlob, k_DATA_A, k_DATA_A_SIZE); + bdlbb::BlobUtil::append(&dataBlob, k_DATA_B, k_DATA_B_SIZE); + bdlbb::BlobUtil::append(&dataBlob, k_DATA_C, k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(34) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase34) { - // Concern: Copy: bsl::shared_ptr - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&blobBufferFactory, &ta); - { - bsl::shared_ptr& dataSharedBlob = - data.makeSharedBlob(); - dataSharedBlob.createInplace(&ta, &blobBufferFactory, &ta); - - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_A, - test::DATA_A_SIZE); - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_B, - test::DATA_B_SIZE); - bdlbb::BlobUtil::append(dataSharedBlob.get(), - test::DATA_C, - test::DATA_C_SIZE); - } - - ntsa::DataUtil::copy(&blob, data); + bsl::shared_ptr& dataSharedBlob = + data.makeSharedBlob(); + dataSharedBlob.createInplace(NTSCFG_TEST_ALLOCATOR, + &blobBufferFactory, + NTSCFG_TEST_ALLOCATOR); + + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_A, + k_DATA_A_SIZE); + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_B, + k_DATA_B_SIZE); + bdlbb::BlobUtil::append(dataSharedBlob.get(), + k_DATA_C, + k_DATA_C_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, - test::DATA_A, - test::DATA_B, - test::DATA_C)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE( + ntsa::DataTest::equals(blob, k_DATA_A, k_DATA_B, k_DATA_C)); } -NTSCFG_TEST_CASE(35) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase35) { - // Concern: Copy: bsl::string - // Plan: + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - ntscfg::TestAllocator ta; - { - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); - - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); + { + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); { - ntsa::Data data(&ta); - { - bsl::string& dataString = data.makeString(); - dataString.assign(test::DATA, test::DATA_SIZE); - } - - ntsa::DataUtil::copy(&blob, data); + bsl::string& dataString = data.makeString(); + dataString.assign(k_DATA, k_DATA_SIZE); } - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); + ntsa::DataUtil::copy(&blob, data); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_CASE(36) +NTSCFG_TEST_FUNCTION(ntsa::DataTest::verifyCase36) { - // Concern: Copy: ntsa::File - // Plan: - - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - ntsa::TemporaryFile tempFile(&ta); + ntsa::TemporaryFile tempFile(NTSCFG_TEST_ALLOCATOR); - bdlbb::PooledBlobBufferFactory blobBufferFactory( - test::BLOB_BUFFER_SIZE, - &ta); + bdlbb::PooledBlobBufferFactory blobBufferFactory(k_BLOB_BUFFER_SIZE, + NTSCFG_TEST_ALLOCATOR); - bdlbb::Blob blob(&blobBufferFactory, &ta); + bdlbb::Blob blob(&blobBufferFactory, NTSCFG_TEST_ALLOCATOR); - error = tempFile.write(bsl::string(test::DATA, test::DATA_SIZE)); - NTSCFG_TEST_OK(error); + error = tempFile.write(bsl::string(k_DATA, k_DATA_SIZE)); + NTSCFG_TEST_OK(error); - bdls::FilesystemUtil::FileDescriptor fileDescriptor = - bdls::FilesystemUtil::open(tempFile.path().c_str(), - bdls::FilesystemUtil::e_OPEN, - bdls::FilesystemUtil::e_READ_ONLY); + bdls::FilesystemUtil::FileDescriptor fileDescriptor = + bdls::FilesystemUtil::open(tempFile.path().c_str(), + bdls::FilesystemUtil::e_OPEN, + bdls::FilesystemUtil::e_READ_ONLY); - NTSCFG_TEST_NE(fileDescriptor, bdls::FilesystemUtil::k_INVALID_FD); + NTSCFG_TEST_NE(fileDescriptor, bdls::FilesystemUtil::k_INVALID_FD); - ntsa::Data data(&ta); - { - ntsa::File& file = data.makeFile(); + ntsa::Data data(NTSCFG_TEST_ALLOCATOR); + { + ntsa::File& file = data.makeFile(); - file.setDescriptor(fileDescriptor); - file.setBytesRemaining(test::DATA_SIZE); - } + file.setDescriptor(fileDescriptor); + file.setBytesRemaining(k_DATA_SIZE); + } - error = ntsa::DataUtil::copy(&blob, data); - NTSCFG_TEST_OK(error); + error = ntsa::DataUtil::copy(&blob, data); + NTSCFG_TEST_OK(error); - bdls::FilesystemUtil::close(fileDescriptor); + bdls::FilesystemUtil::close(fileDescriptor); - NTSCFG_TEST_TRUE(test::BlobUtil::equals(blob, test::DATA)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_TRUE(ntsa::DataTest::equals(blob, k_DATA)); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); - NTSCFG_TEST_REGISTER(8); - NTSCFG_TEST_REGISTER(9); - NTSCFG_TEST_REGISTER(10); - NTSCFG_TEST_REGISTER(11); - NTSCFG_TEST_REGISTER(12); - - NTSCFG_TEST_REGISTER(13); - NTSCFG_TEST_REGISTER(14); - NTSCFG_TEST_REGISTER(15); - NTSCFG_TEST_REGISTER(16); - NTSCFG_TEST_REGISTER(17); - NTSCFG_TEST_REGISTER(18); - NTSCFG_TEST_REGISTER(19); - NTSCFG_TEST_REGISTER(20); - NTSCFG_TEST_REGISTER(21); - NTSCFG_TEST_REGISTER(22); - NTSCFG_TEST_REGISTER(23); - NTSCFG_TEST_REGISTER(24); - - NTSCFG_TEST_REGISTER(25); - NTSCFG_TEST_REGISTER(26); - NTSCFG_TEST_REGISTER(27); - NTSCFG_TEST_REGISTER(28); - NTSCFG_TEST_REGISTER(29); - NTSCFG_TEST_REGISTER(30); - NTSCFG_TEST_REGISTER(31); - NTSCFG_TEST_REGISTER(32); - NTSCFG_TEST_REGISTER(33); - NTSCFG_TEST_REGISTER(34); - NTSCFG_TEST_REGISTER(35); - NTSCFG_TEST_REGISTER(36); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_datatype.t.cpp b/groups/nts/ntsa/ntsa_datatype.t.cpp index f4eb508b..614caf5e 100644 --- a/groups/nts/ntsa/ntsa_datatype.t.cpp +++ b/groups/nts/ntsa/ntsa_datatype.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_datatype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::DataType'. +class DataTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::DataTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_distinguishedname.t.cpp b/groups/nts/ntsa/ntsa_distinguishedname.t.cpp index 85581b99..e9822ad4 100644 --- a/groups/nts/ntsa/ntsa_distinguishedname.t.cpp +++ b/groups/nts/ntsa/ntsa_distinguishedname.t.cpp @@ -13,168 +13,146 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_distinguishedname_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include + +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::DistinguishedName'. +class DistinguishedNameTest { - // Concern: Test 'generate' - // Plan: + public: + // Verify generation. + static void verifyGenerate(); - ntscfg::TestAllocator ta; - { - typedef ntsa::DistinguishedName DN; + // Verify parsing. + static void verifyParse(); - DN identity(&ta); + // Verify usage. + static void verifyUsage(); +}; - identity["CN"].addAttribute("John Doe"); - identity["O"].addAttribute("Technical Corporation"); - identity["OU"].addAttribute("Engineering"); +NTSCFG_TEST_FUNCTION(ntsa::DistinguishedNameTest::verifyGenerate) +{ + typedef ntsa::DistinguishedName DN; + + DN identity(NTSCFG_TEST_ALLOCATOR); - bsl::string result; - int rc = identity.generate(&result); - NTSCFG_TEST_EQ(rc, 0); + identity["CN"].addAttribute("John Doe"); + identity["O"].addAttribute("Technical Corporation"); + identity["OU"].addAttribute("Engineering"); - NTSCFG_TEST_LOG_DEBUG << "Generated distinguished name = " << result - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + bsl::string result; + int rc = identity.generate(&result); + NTSCFG_TEST_EQ(rc, 0); + + NTSCFG_TEST_LOG_DEBUG << "Generated distinguished name = " << result + << NTSCFG_TEST_LOG_END; } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::DistinguishedNameTest::verifyParse) { - // Concern: Test 'parse' - // Plan: - - ntscfg::TestAllocator ta; - { - typedef ntsa::DistinguishedName DN; + typedef ntsa::DistinguishedName DN; - bsl::string NAME = - "CN=John Doe,O=Technical Corporation,OU=Engineering"; + bsl::string NAME = "CN=John Doe,O=Technical Corporation,OU=Engineering"; - DN identity(&ta); + DN identity(NTSCFG_TEST_ALLOCATOR); - int rc = identity.parse(NAME); - NTSCFG_TEST_EQ(0, rc); + int rc = identity.parse(NAME); + NTSCFG_TEST_EQ(0, rc); - NTSCFG_TEST_LOG_DEBUG << "Parsed distinguished name = " << identity - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsed distinguished name = " << identity + << NTSCFG_TEST_LOG_END; - DN::Component* component; + DN::Component* component; - NTSCFG_TEST_EQ(0, identity.find(&component, "CN")); - NTSCFG_TEST_NE(static_cast(0), component); - NTSCFG_TEST_EQ(1, component->numAttributes()); - NTSCFG_TEST_EQ("John Doe", (*component)[0]); + NTSCFG_TEST_EQ(0, identity.find(&component, "CN")); + NTSCFG_TEST_NE(static_cast(0), component); + NTSCFG_TEST_EQ(1, component->numAttributes()); + NTSCFG_TEST_EQ("John Doe", (*component)[0]); - NTSCFG_TEST_EQ(0, identity.find(&component, "O")); - NTSCFG_TEST_NE(static_cast(0), component); - NTSCFG_TEST_EQ(1, component->numAttributes()); - NTSCFG_TEST_EQ("Technical Corporation", (*component)[0]); + NTSCFG_TEST_EQ(0, identity.find(&component, "O")); + NTSCFG_TEST_NE(static_cast(0), component); + NTSCFG_TEST_EQ(1, component->numAttributes()); + NTSCFG_TEST_EQ("Technical Corporation", (*component)[0]); - NTSCFG_TEST_EQ(0, identity.find(&component, "OU")); - NTSCFG_TEST_NE(static_cast(0), component); - NTSCFG_TEST_EQ(1, component->numAttributes()); - NTSCFG_TEST_EQ("Engineering", (*component)[0]); + NTSCFG_TEST_EQ(0, identity.find(&component, "OU")); + NTSCFG_TEST_NE(static_cast(0), component); + NTSCFG_TEST_EQ(1, component->numAttributes()); + NTSCFG_TEST_EQ("Engineering", (*component)[0]); - NAME = "/CN=TEST.AUTHORITY/O=Technical Corporation"; + NAME = "/CN=TEST.AUTHORITY/O=Technical Corporation"; - rc = identity.parse(NAME); - NTSCFG_TEST_EQ(0, rc); + rc = identity.parse(NAME); + NTSCFG_TEST_EQ(0, rc); - NTSCFG_TEST_LOG_DEBUG << "Parsed distinguished name = " << identity - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsed distinguished name = " << identity + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(0, identity.find(&component, "CN")); - NTSCFG_TEST_NE(static_cast(0), component); - NTSCFG_TEST_EQ(1, component->numAttributes()); - NTSCFG_TEST_EQ("TEST.AUTHORITY", (*component)[0]); + NTSCFG_TEST_EQ(0, identity.find(&component, "CN")); + NTSCFG_TEST_NE(static_cast(0), component); + NTSCFG_TEST_EQ(1, component->numAttributes()); + NTSCFG_TEST_EQ("TEST.AUTHORITY", (*component)[0]); - NTSCFG_TEST_EQ(0, identity.find(&component, "O")); - NTSCFG_TEST_NE(static_cast(0), component); - NTSCFG_TEST_EQ(1, component->numAttributes()); - NTSCFG_TEST_EQ("Technical Corporation", (*component)[0]); + NTSCFG_TEST_EQ(0, identity.find(&component, "O")); + NTSCFG_TEST_NE(static_cast(0), component); + NTSCFG_TEST_EQ(1, component->numAttributes()); + NTSCFG_TEST_EQ("Technical Corporation", (*component)[0]); - NAME = "/"; - rc = identity.parse(NAME); - NTSCFG_TEST_EQ(0, rc); + NAME = "/"; + rc = identity.parse(NAME); + NTSCFG_TEST_EQ(0, rc); - NAME = "//"; - rc = identity.parse(NAME); - NTSCFG_TEST_EQ(0, rc); + NAME = "//"; + rc = identity.parse(NAME); + NTSCFG_TEST_EQ(0, rc); - NAME = "////"; - rc = identity.parse(NAME); - NTSCFG_TEST_EQ(0, rc); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NAME = "////"; + rc = identity.parse(NAME); + NTSCFG_TEST_EQ(0, rc); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::DistinguishedNameTest::verifyUsage) { - // Concern: Usage example - // Plan: + typedef ntsa::DistinguishedName DN; - ntscfg::TestAllocator ta; - { - typedef ntsa::DistinguishedName DN; + DN identity(NTSCFG_TEST_ALLOCATOR); - DN identity(&ta); + identity[DN::e_COMMON_NAME].addAttribute("John Doe"); + identity[DN::e_STREET_ADDRESS].addAttribute("127 Main Street"); + identity[DN::e_LOCALITY_NAME].addAttribute("Anytown"); + identity[DN::e_STATE].addAttribute("NY"); + identity[DN::e_COUNTRY_NAME].addAttribute("USA"); + identity["DC"].addAttribute("example"); + identity["DC"].addAttribute("com"); - identity[DN::e_COMMON_NAME].addAttribute("John Doe"); - identity[DN::e_STREET_ADDRESS].addAttribute("127 Main Street"); - identity[DN::e_LOCALITY_NAME].addAttribute("Anytown"); - identity[DN::e_STATE].addAttribute("NY"); - identity[DN::e_COUNTRY_NAME].addAttribute("USA"); - identity["DC"].addAttribute("example"); - identity["DC"].addAttribute("com"); + NTSCFG_TEST_LOG_DEBUG << "DistinguishedName = " << identity + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "DistinguishedName = " << identity - << NTSCFG_TEST_LOG_END; + DN::Component* rdn; - DN::Component* rdn; + NTSCFG_TEST_EQ(0, identity.find(&rdn, "CN")); + NTSCFG_TEST_EQ(1, rdn->numAttributes()); + NTSCFG_TEST_EQ("John Doe", (*rdn)[0]); - NTSCFG_TEST_EQ(0, identity.find(&rdn, "CN")); - NTSCFG_TEST_EQ(1, rdn->numAttributes()); - NTSCFG_TEST_EQ("John Doe", (*rdn)[0]); + NTSCFG_TEST_EQ(0, identity.find(&rdn, DN::e_DOMAIN_COMPONENT)); + NTSCFG_TEST_EQ(2, rdn->numAttributes()); + NTSCFG_TEST_EQ("example", (*rdn)[0]); + NTSCFG_TEST_EQ("com", (*rdn)[1]); - NTSCFG_TEST_EQ(0, identity.find(&rdn, DN::e_DOMAIN_COMPONENT)); - NTSCFG_TEST_EQ(2, rdn->numAttributes()); - NTSCFG_TEST_EQ("example", (*rdn)[0]); - NTSCFG_TEST_EQ("com", (*rdn)[1]); + bsl::string description; + NTSCFG_TEST_EQ(0, identity.generate(&description)); - bsl::string description; - NTSCFG_TEST_EQ(0, identity.generate(&description)); - - NTSCFG_TEST_LOG_DEBUG << "Description: " << description - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_LOG_DEBUG << "Description: " << description + << NTSCFG_TEST_LOG_END; } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_domainname.h b/groups/nts/ntsa/ntsa_domainname.h index fca79085..f12035e7 100644 --- a/groups/nts/ntsa/ntsa_domainname.h +++ b/groups/nts/ntsa/ntsa_domainname.h @@ -304,8 +304,7 @@ bsl::string DomainName::text() const } template -NTSCFG_INLINE -void DomainName::hash(HASH_ALGORITHM& algorithm) const +NTSCFG_INLINE void DomainName::hash(HASH_ALGORITHM& algorithm) const { using bslh::hashAppend; algorithm(d_buffer, d_size); @@ -336,8 +335,8 @@ bool operator<(const DomainName& lhs, const DomainName& rhs) } template -NTSCFG_INLINE -void hashAppend(HASH_ALGORITHM& algorithm, const DomainName& value) +NTSCFG_INLINE void hashAppend(HASH_ALGORITHM& algorithm, + const DomainName& value) { value.hash(algorithm); } diff --git a/groups/nts/ntsa/ntsa_domainname.t.cpp b/groups/nts/ntsa/ntsa_domainname.t.cpp index 4a3bf47a..f3d31393 100644 --- a/groups/nts/ntsa/ntsa_domainname.t.cpp +++ b/groups/nts/ntsa/ntsa_domainname.t.cpp @@ -13,32 +13,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_domainname_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include + +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::DomainName'. +class DomainNameTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); + // TODO + static void verifyCase2(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::DomainNameTest::verifyCase1) +{ bool valid; bool equals; bool less; @@ -197,11 +196,8 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::DomainNameTest::verifyCase2) { - // Concern: - // Plan: - ntsa::DomainName domainName1("one", "example.com"); ntsa::DomainName domainName2("two", "example.com"); @@ -212,9 +208,5 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_EQ(domainNameSet.size(), 2); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_endpoint.cpp b/groups/nts/ntsa/ntsa_endpoint.cpp index c62914a7..d3b82b9a 100644 --- a/groups/nts/ntsa/ntsa_endpoint.cpp +++ b/groups/nts/ntsa/ntsa_endpoint.cpp @@ -226,7 +226,7 @@ bsl::ostream& Endpoint::print(bsl::ostream& stream, const bdlat_SelectionInfo* Endpoint::lookupSelectionInfo(int id) { - const int numSelections = + const int numSelections = sizeof(SELECTION_INFO_ARRAY) / sizeof(SELECTION_INFO_ARRAY[0]); if (id < 0 || id >= numSelections) { @@ -236,17 +236,16 @@ const bdlat_SelectionInfo* Endpoint::lookupSelectionInfo(int id) return &SELECTION_INFO_ARRAY[id]; } -const bdlat_SelectionInfo* Endpoint::lookupSelectionInfo( - const char* name, - int nameLength) +const bdlat_SelectionInfo* Endpoint::lookupSelectionInfo(const char* name, + int nameLength) { - const bsl::size_t numSelections = + const bsl::size_t numSelections = sizeof(SELECTION_INFO_ARRAY) / sizeof(SELECTION_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numSelections; ++i) { const bdlat_SelectionInfo& selectionInfo = SELECTION_INFO_ARRAY[i]; if (selectionInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(selectionInfo.d_name_p, name, nameLength); if (compare == 0) { return &selectionInfo; diff --git a/groups/nts/ntsa/ntsa_endpoint.h b/groups/nts/ntsa/ntsa_endpoint.h index b178f652..a5191dee 100644 --- a/groups/nts/ntsa/ntsa_endpoint.h +++ b/groups/nts/ntsa/ntsa_endpoint.h @@ -27,9 +27,9 @@ BSLS_IDENT("$Id: $") #include #include #include -#include -#include #include +#include +#include #include #include #include @@ -261,50 +261,50 @@ class Endpoint int level = 0, int spacesPerLevel = 4) const; - /// Set the value of this object to be the default for the selection - /// indicated by the specified 'id'. Return 0 on success, and non-zero - /// value otherwise (i.e., the selection is not found). + /// Set the value of this object to be the default for the selection + /// indicated by the specified 'id'. Return 0 on success, and non-zero + /// value otherwise (i.e., the selection is not found). int makeSelection(int id); - /// Set the value of this object to be the default for the selection - /// indicated by the specified 'name' of the specified 'nameLength'. - /// Return 0 on success, and non-zero value otherwise (i.e., the selection - /// is not found). + /// Set the value of this object to be the default for the selection + /// indicated by the specified 'name' of the specified 'nameLength'. + /// Return 0 on success, and non-zero value otherwise (i.e., the selection + /// is not found). int makeSelection(const char* name, int nameLength); - /// Return the selection ID of the current selection in the choice. + /// Return the selection ID of the current selection in the choice. int selectionId() const; - /// Invoke the specified 'manipulator' on the address of the modifiable - /// selection, supplying 'manipulator' with the corresponding selection - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if this object has a defined selection, and -1 - /// otherwise. + /// Invoke the specified 'manipulator' on the address of the modifiable + /// selection, supplying 'manipulator' with the corresponding selection + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if this object has a defined selection, and -1 + /// otherwise. template int manipulateSelection(MANIPULATOR& manipulator); - /// Invoke the specified 'accessor' on the non-modifiable selection, - /// supplying 'accessor' with the corresponding selection information - /// structure. Return the value returned from the invocation of 'accessor' - /// if this object has a defined selection, and -1 otherwise. + /// Invoke the specified 'accessor' on the non-modifiable selection, + /// supplying 'accessor' with the corresponding selection information + /// structure. Return the value returned from the invocation of 'accessor' + /// if this object has a defined selection, and -1 otherwise. template int accessSelection(ACCESSOR& accessor) const; - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[15]; - /// The selection info array, indexed by selection index. + /// The selection info array, indexed by selection index. static const bdlat_SelectionInfo SELECTION_INFO_ARRAY[3]; - /// Return selection information for the selection indicated by the - /// specified 'id' if the selection exists, and 0 otherwise. + /// Return selection information for the selection indicated by the + /// specified 'id' if the selection exists, and 0 otherwise. static const bdlat_SelectionInfo* lookupSelectionInfo(int id); - /// Return selection information for the selection indicated by the - /// specified 'name' of the specified 'nameLength' if the selection - /// exists, and 0 otherwise. - static const bdlat_SelectionInfo* lookupSelectionInfo( - const char* name, int nameLength); + /// Return selection information for the selection indicated by the + /// specified 'name' of the specified 'nameLength' if the selection + /// exists, and 0 otherwise. + static const bdlat_SelectionInfo* lookupSelectionInfo(const char* name, + int nameLength); /// Defines the traits of this type. These traits can be used to select, /// at compile-time, the most efficient algorithm to manipulate objects @@ -627,7 +627,7 @@ int Endpoint::makeSelection(int id) NTSCFG_INLINE int Endpoint::makeSelection(const char* name, int nameLength) { - const bdlat_SelectionInfo *selectionInfo = + const bdlat_SelectionInfo* selectionInfo = ntsa::Endpoint::lookupSelectionInfo(name, nameLength); if (selectionInfo == 0) { return -1; @@ -673,8 +673,8 @@ template int Endpoint::accessSelection(ACCESSOR& accessor) const { int rc; - - const bdlat_SelectionInfo *selectionInfo = + + const bdlat_SelectionInfo* selectionInfo = ntsa::Endpoint::lookupSelectionInfo(d_type); if (selectionInfo == 0) { return -1; diff --git a/groups/nts/ntsa/ntsa_endpoint.t.cpp b/groups/nts/ntsa/ntsa_endpoint.t.cpp index e9bcf7d8..2da33024 100644 --- a/groups/nts/ntsa/ntsa_endpoint.t.cpp +++ b/groups/nts/ntsa/ntsa_endpoint.t.cpp @@ -13,38 +13,45 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include + +#include +BSLS_IDENT_RCSID(ntsa_endpoint_t_cpp, "$Id$ $CSID$") + +#include + #include #include #include #include -#include -#include -#include -#include using namespace BloombergLP; -using namespace ntsa; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Endpoint'. +class EndpointTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + // TODO + static void verifyCase5(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::EndpointTest::verifyCase1) +{ const bsl::string e = "127.0.0.1:12345"; { @@ -93,11 +100,8 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::EndpointTest::verifyCase2) { - // Concern: - // Plan: - { const bsl::string e = "[::1]:12345"; @@ -181,11 +185,8 @@ NTSCFG_TEST_CASE(2) } } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::EndpointTest::verifyCase3) { - // Concern: - // Plan: - const bsl::string e = "/tmp/server"; ntsa::Endpoint endpoint(e); @@ -206,114 +207,99 @@ NTSCFG_TEST_CASE(3) } } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::EndpointTest::verifyCase4) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::Endpoint e1("10.26.55.100:12345"); - ntsa::Endpoint e2; + ntsa::Endpoint e1("10.26.55.100:12345"); + ntsa::Endpoint e2; - bdlsb::MemOutStreamBuf osb(&ta); + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - balber::BerEncoder encoder(0, &ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerEncoder encoder(0, NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" - << bdlb::PrintStringHexDumper( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" + << bdlb::PrintStringHexDumper( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - balber::BerDecoder decoder(0, &ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerDecoder decoder(0, NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2, e1); + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); + + NTSCFG_TEST_EQ(e2, e1); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::EndpointTest::verifyCase5) { int rc; - ntscfg::TestAllocator ta; - { - bsl::vector e1(&ta); - bsl::vector e2(&ta); - - e1.push_back(ntsa::Endpoint("10.26.55.100:12345")); + bsl::vector e1(NTSCFG_TEST_ALLOCATOR); + bsl::vector e2(NTSCFG_TEST_ALLOCATOR); - bdlsb::MemOutStreamBuf osb; + e1.push_back(ntsa::Endpoint("10.26.55.100:12345")); - baljsn::Encoder encoder(&ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::MemOutStreamBuf osb; - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Encoder encoder(NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded: " - << bsl::string_view( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded: " + << bsl::string_view( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - baljsn::Decoder decoder(&ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Decoder decoder(NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2.size(), e1.size()); + NTSCFG_TEST_EQ(rc, 0); + } - for (bsl::size_t i = 0; i < e1.size(); ++i) { - NTSCFG_TEST_EQ(e2[i], e1[i]); - } + NTSCFG_TEST_EQ(e2.size(), e1.size()); + + for (bsl::size_t i = 0; i < e1.size(); ++i) { + NTSCFG_TEST_EQ(e2[i], e1[i]); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_endpointtype.t.cpp b/groups/nts/ntsa/ntsa_endpointtype.t.cpp index 5d99de6b..f1bfa019 100644 --- a/groups/nts/ntsa/ntsa_endpointtype.t.cpp +++ b/groups/nts/ntsa/ntsa_endpointtype.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_endpointtype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::EndpointType'. +class EndpointTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::EndpointTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_error.t.cpp b/groups/nts/ntsa/ntsa_error.t.cpp index 65f76689..b5095529 100644 --- a/groups/nts/ntsa/ntsa_error.t.cpp +++ b/groups/nts/ntsa/ntsa_error.t.cpp @@ -13,30 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -using namespace BloombergLP; +#include +BSLS_IDENT_RCSID(ntsa_error_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Error'. +class ErrorTest { -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::ErrorTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ethernetaddress.cpp b/groups/nts/ntsa/ntsa_ethernetaddress.cpp index b289d016..2f76e5fc 100644 --- a/groups/nts/ntsa/ntsa_ethernetaddress.cpp +++ b/groups/nts/ntsa/ntsa_ethernetaddress.cpp @@ -19,11 +19,11 @@ BSLS_IDENT_RCSID(ntsa_ethernetaddress_cpp, "$Id$ $CSID$") #include -#include -#include #include #include +#include #include +#include namespace BloombergLP { namespace ntsa { @@ -33,8 +33,7 @@ namespace { void throwEthernetInvalidFormat(const bslstl::StringRef& text) { bsl::stringstream ss; - ss << "Failed to parse Ethernet address: the text '" - << text + ss << "Failed to parse Ethernet address: the text '" << text << "' is invalid"; NTSCFG_THROW(ss.str()); @@ -109,14 +108,11 @@ bool EthernetAddress::parse(const bslstl::StringRef& text) const char ch1 = *current++; const char ch2 = *current++; - const bsl::uint8_t hi = static_cast(bsl::isdigit(ch1) - ? ch1 - '0' - : bsl::tolower(ch1) - 'a' + 10); - - const bsl::uint8_t lo = static_cast(bsl::isdigit(ch2) - ? ch2 - '0' - : bsl::tolower(ch2) - 'a' + 10); + const bsl::uint8_t hi = static_cast( + bsl::isdigit(ch1) ? ch1 - '0' : bsl::tolower(ch1) - 'a' + 10); + const bsl::uint8_t lo = static_cast( + bsl::isdigit(ch2) ? ch2 - '0' : bsl::tolower(ch2) - 'a' + 10); d_value[i] = hi << 4 | lo; } @@ -124,8 +120,7 @@ bool EthernetAddress::parse(const bslstl::StringRef& text) return true; } -bsl::size_t EthernetAddress::format(char* buffer, - bsl::size_t capacity) const +bsl::size_t EthernetAddress::format(char* buffer, bsl::size_t capacity) const { if (capacity < ntsa::EthernetAddress::MAX_TEXT_LENGTH + 1) { if (capacity > 0) { @@ -168,8 +163,8 @@ bsl::size_t EthernetAddress::format(char* buffer, } bsl::ostream& EthernetAddress::print(bsl::ostream& stream, - int level, - int spacesPerLevel) const + int level, + int spacesPerLevel) const { char buffer[ntsa::EthernetAddress::MAX_TEXT_LENGTH + 1]; const bsl::size_t size = EthernetAddress::format(buffer, sizeof buffer); diff --git a/groups/nts/ntsa/ntsa_ethernetaddress.h b/groups/nts/ntsa/ntsa_ethernetaddress.h index d44f82f7..0a26b47d 100644 --- a/groups/nts/ntsa/ntsa_ethernetaddress.h +++ b/groups/nts/ntsa/ntsa_ethernetaddress.h @@ -40,7 +40,7 @@ class EthernetAddress { bsl::uint8_t d_value[6]; -public: + public: /// Declare constants used by this implementation. enum Constant { /// The maximum required capacity of a buffer to store the longest @@ -68,8 +68,8 @@ class EthernetAddress /// Create a new Ethernet address having the same value as the specified /// 'original' object. Assign an unspecified but valid value to the /// 'original' original. - EthernetAddress( - bslmf::MovableRef original) NTSCFG_NOEXCEPT; + EthernetAddress(bslmf::MovableRef original) + NTSCFG_NOEXCEPT; /// Create a new Ethernet address with the same value as the specified /// 'original' object. @@ -110,13 +110,11 @@ class EthernetAddress /// Copy the value of this object to the representation in the specified /// 'destination' having the specified 'capacity'. Return the number of /// bytes written. - bsl::size_t copyTo(void* destination, - bsl::size_t capacity) const; + bsl::size_t copyTo(void* destination, bsl::size_t capacity) const; /// Format the IPv4 address into the specified 'buffer' having the /// specified 'capacity'. Return the number of bytes written. - bsl::size_t format(char* buffer, - bsl::size_t capacity) const; + bsl::size_t format(char* buffer, bsl::size_t capacity) const; /// Return the string representation of this object. bsl::string text() const; @@ -229,8 +227,8 @@ EthernetAddress::EthernetAddress(bsl::uint8_t byte0, } NTSCFG_INLINE -EthernetAddress::EthernetAddress( - bslmf::MovableRef original) NTSCFG_NOEXCEPT +EthernetAddress::EthernetAddress(bslmf::MovableRef original) + NTSCFG_NOEXCEPT { bsl::memcpy(d_value, NTSCFG_MOVE_FROM(original, d_value), sizeof d_value); NTSCFG_MOVE_RESET(original); @@ -248,8 +246,8 @@ EthernetAddress::~EthernetAddress() } NTSCFG_INLINE -EthernetAddress& EthernetAddress::operator=(bslmf::MovableRef other) - NTSCFG_NOEXCEPT +EthernetAddress& EthernetAddress::operator=( + bslmf::MovableRef other) NTSCFG_NOEXCEPT { bsl::memcpy(d_value, NTSCFG_MOVE_FROM(other, d_value), sizeof d_value); NTSCFG_MOVE_RESET(other); @@ -302,8 +300,7 @@ bool EthernetAddress::less(const EthernetAddress& other) const } template -NTSCFG_INLINE -void EthernetAddress::hash(HASH_ALGORITHM& algorithm) const +NTSCFG_INLINE void EthernetAddress::hash(HASH_ALGORITHM& algorithm) const { algorithm(reinterpret_cast(d_value), sizeof d_value); } @@ -340,8 +337,8 @@ bool operator<(const EthernetAddress& lhs, const EthernetAddress& rhs) } template -NTSCFG_INLINE -void hashAppend(HASH_ALGORITHM& algorithm, const EthernetAddress& value) +NTSCFG_INLINE void hashAppend(HASH_ALGORITHM& algorithm, + const EthernetAddress& value) { value.hash(algorithm); } diff --git a/groups/nts/ntsa/ntsa_ethernetaddress.t.cpp b/groups/nts/ntsa/ntsa_ethernetaddress.t.cpp index 71c27483..14e0a8ae 100644 --- a/groups/nts/ntsa/ntsa_ethernetaddress.t.cpp +++ b/groups/nts/ntsa/ntsa_ethernetaddress.t.cpp @@ -13,59 +13,55 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_ethernetaddress_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -using namespace ntsa; -NTSCFG_TEST_CASE(1) -{ - // Concern: - // Plan: +namespace BloombergLP { +namespace ntsa { - ntscfg::TestAllocator ta; - { - ntsa::EthernetAddress address1; +// Provide tests for 'ntsa::EthernetAddress'. +class EthernetAddressTest +{ + public: + // TODO + static void verify(); +}; - address1[0] = 0xb8; - address1[1] = 0xe6; - address1[2] = 0x0c; - address1[3] = 0x06; - address1[4] = 0x3c; - address1[5] = 0x7b; +NTSCFG_TEST_FUNCTION(ntsa::EthernetAddressTest::verify) +{ + ntsa::EthernetAddress address1; - NTSCFG_TEST_LOG_DEBUG << "Address1 = " << address1 - << NTSCFG_TEST_LOG_END; + address1[0] = 0xb8; + address1[1] = 0xe6; + address1[2] = 0x0c; + address1[3] = 0x06; + address1[4] = 0x3c; + address1[5] = 0x7b; - char buffer[ntsa::EthernetAddress::MAX_TEXT_LENGTH + 1]; - bsl::memset(buffer, 0, sizeof buffer); + NTSCFG_TEST_LOG_DEBUG << "Address1 = " << address1 << NTSCFG_TEST_LOG_END; - bsl::size_t n = address1.format(buffer, sizeof buffer); - NTSCFG_TEST_EQ(n, ntsa::EthernetAddress::MAX_TEXT_LENGTH); + char buffer[ntsa::EthernetAddress::MAX_TEXT_LENGTH + 1]; + bsl::memset(buffer, 0, sizeof buffer); - ntsa::EthernetAddress address2; + bsl::size_t n = address1.format(buffer, sizeof buffer); + NTSCFG_TEST_EQ(n, ntsa::EthernetAddress::MAX_TEXT_LENGTH); - bool result = address2.parse( - bslstl::StringRef(buffer, ntsa::EthernetAddress::MAX_TEXT_LENGTH)); - NTSCFG_TEST_TRUE(result); + ntsa::EthernetAddress address2; - NTSCFG_TEST_LOG_DEBUG << "Address2 = " << address2 - << NTSCFG_TEST_LOG_END; + bool result = address2.parse( + bslstl::StringRef(buffer, ntsa::EthernetAddress::MAX_TEXT_LENGTH)); + NTSCFG_TEST_TRUE(result); - NTSCFG_TEST_EQ(address1, address2); + NTSCFG_TEST_LOG_DEBUG << "Address2 = " << address2 << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_EQ(address1, address2); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ethernetheader.cpp b/groups/nts/ntsa/ntsa_ethernetheader.cpp index d7d3ea93..d297c044 100644 --- a/groups/nts/ntsa/ntsa_ethernetheader.cpp +++ b/groups/nts/ntsa/ntsa_ethernetheader.cpp @@ -28,8 +28,8 @@ namespace ntsa { bool EthernetHeader::equals(const EthernetHeader& other) const { - return d_source == other.d_source && - d_destination == other.d_destination && + return d_source == other.d_source && + d_destination == other.d_destination && d_protocol == other.d_protocol; } diff --git a/groups/nts/ntsa/ntsa_ethernetheader.h b/groups/nts/ntsa/ntsa_ethernetheader.h index 1017200b..fbef139f 100644 --- a/groups/nts/ntsa/ntsa_ethernetheader.h +++ b/groups/nts/ntsa/ntsa_ethernetheader.h @@ -76,19 +76,19 @@ class EthernetHeader /// construction. void reset(); - /// Set the source address to the specified 'value'. + /// Set the source address to the specified 'value'. void setSource(const ntsa::EthernetAddress& value); - /// Set the destination address to the specified 'value'. + /// Set the destination address to the specified 'value'. void setDestination(const ntsa::EthernetAddress& value); - /// Set the protocol to the specified 'value'. + /// Set the protocol to the specified 'value'. void setProtocol(ntsa::EthernetProtocol::Value value); - /// Return the source address. + /// Return the source address. const ntsa::EthernetAddress& source() const; - /// Return the destination address. + /// Return the destination address. const ntsa::EthernetAddress& destination() const; /// Return the protocol. @@ -178,11 +178,10 @@ EthernetHeader::EthernetHeader() } NTSCFG_INLINE -EthernetHeader::EthernetHeader( - bslmf::MovableRef original) NTSCFG_NOEXCEPT -: d_source(NTSCFG_MOVE_FROM(original, d_source)) -, d_destination(NTSCFG_MOVE_FROM(original, d_destination)) -, d_protocol(NTSCFG_MOVE_FROM(original, d_protocol)) +EthernetHeader::EthernetHeader(bslmf::MovableRef original) + NTSCFG_NOEXCEPT : d_source(NTSCFG_MOVE_FROM(original, d_source)), + d_destination(NTSCFG_MOVE_FROM(original, d_destination)), + d_protocol(NTSCFG_MOVE_FROM(original, d_protocol)) { NTSCFG_MOVE_RESET(original); } @@ -216,9 +215,9 @@ EthernetHeader& EthernetHeader::operator=( NTSCFG_INLINE EthernetHeader& EthernetHeader::operator=(const EthernetHeader& other) { - d_source = other.d_source; + d_source = other.d_source; d_destination = other.d_destination; - d_protocol = other.d_protocol; + d_protocol = other.d_protocol; return *this; } @@ -300,7 +299,7 @@ bool operator<(const EthernetHeader& lhs, const EthernetHeader& rhs) } template -NTSCFG_INLINE void hashAppend(HASH_ALGORITHM& algorithm, +NTSCFG_INLINE void hashAppend(HASH_ALGORITHM& algorithm, const EthernetHeader& value) { value.hash(algorithm); diff --git a/groups/nts/ntsa/ntsa_ethernetheader.t.cpp b/groups/nts/ntsa/ntsa_ethernetheader.t.cpp index e2c3f3a6..b034129d 100644 --- a/groups/nts/ntsa/ntsa_ethernetheader.t.cpp +++ b/groups/nts/ntsa/ntsa_ethernetheader.t.cpp @@ -13,12 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include BSLS_IDENT_RCSID(ntsa_ethernetheader_t_cpp, "$Id$ $CSID$") -#include +#include using namespace BloombergLP; @@ -36,7 +36,7 @@ class EthernetHeaderTest static void verifyUsage(); }; -void EthernetHeaderTest::verifyTypeTraits() +NTSCFG_TEST_FUNCTION(ntsa::EthernetHeaderTest::verifyTypeTraits) { const bool isBitwiseInitializable = NTSCFG_TYPE_CHECK_BITWISE_INITIALIZABLE(ntsa::EthernetHeader); @@ -54,7 +54,7 @@ void EthernetHeaderTest::verifyTypeTraits() NTSCFG_TEST_TRUE(isBitwiseCopyable); } -void EthernetHeaderTest::verifyUsage() +NTSCFG_TEST_FUNCTION(ntsa::EthernetHeaderTest::verifyUsage) { ntsa::EthernetHeader header; @@ -67,10 +67,3 @@ void EthernetHeaderTest::verifyUsage() } // close namespace ntsa } // close namespace BloombergLP - -NTSCFG_TEST_SUITE -{ - NTSCFG_TEST_FUNCTION(&ntsa::EthernetHeaderTest::verifyTypeTraits); - NTSCFG_TEST_FUNCTION(&ntsa::EthernetHeaderTest::verifyUsage); -} -NTSCFG_TEST_SUITE_END; diff --git a/groups/nts/ntsa/ntsa_ethernetprotocol.cpp b/groups/nts/ntsa/ntsa_ethernetprotocol.cpp index d9726d59..0a45a5ce 100644 --- a/groups/nts/ntsa/ntsa_ethernetprotocol.cpp +++ b/groups/nts/ntsa/ntsa_ethernetprotocol.cpp @@ -38,7 +38,7 @@ int EthernetProtocol::fromInt(EthernetProtocol::Value* result, int number) } } -int EthernetProtocol::fromString(EthernetProtocol::Value* result, +int EthernetProtocol::fromString(EthernetProtocol::Value* result, const bslstl::StringRef& string) { if (bdlb::String::areEqualCaseless(string, "UNDEFINED")) { @@ -89,7 +89,7 @@ const char* EthernetProtocol::toString(EthernetProtocol::Value value) return 0; } -bsl::ostream& EthernetProtocol::print(bsl::ostream& stream, +bsl::ostream& EthernetProtocol::print(bsl::ostream& stream, EthernetProtocol::Value value) { return stream << toString(value); diff --git a/groups/nts/ntsa/ntsa_ethernetprotocol.t.cpp b/groups/nts/ntsa/ntsa_ethernetprotocol.t.cpp index 05d03e2a..508a4462 100644 --- a/groups/nts/ntsa/ntsa_ethernetprotocol.t.cpp +++ b/groups/nts/ntsa/ntsa_ethernetprotocol.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_ethernetprotocol_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::EthernetProtocol'. +class EthernetProtocolTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::EthernetProtocolTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_event.t.cpp b/groups/nts/ntsa/ntsa_event.t.cpp index 8303ccc2..26955138 100644 --- a/groups/nts/ntsa/ntsa_event.t.cpp +++ b/groups/nts/ntsa/ntsa_event.t.cpp @@ -13,16 +13,41 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include +#include +BSLS_IDENT_RCSID(ntsa_event_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Event'. +class EventTest { + public: // Concern: ntsa::Event stores the event types and correctly reports // whether the event type has occurred. + static void verifyCase1(); + + // Concern: Events for the same socket may be merged together. + static void verifyCase2(); + + // Concern: Events for different sockets may not be merged together. + static void verifyCase3(); + + // Concern: The event set stores and merges socket events. + static void verifyCase4(); + + // Concern: The event set is iteratable. + static void verifyCase5(); +}; +NTSCFG_TEST_FUNCTION(ntsa::EventTest::verifyCase1) +{ const ntsa::Handle k_SOCKET = 10; const ntsa::Handle k_SOCKET_INVALID = ntsa::k_INVALID_HANDLE; @@ -125,10 +150,8 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(event.error(), ntsa::Error(ntsa::Error::e_INVALID)); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::EventTest::verifyCase2) { - // Concern: Events for the same socket may be merged together. - ntsa::Error error; const ntsa::Handle k_SOCKET = 10; @@ -157,10 +180,8 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_TRUE(eventA.isWritable()); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::EventTest::verifyCase3) { - // Concern: Events for different sockets may not be merged together. - ntsa::Error error; const ntsa::Handle k_SOCKET_A = 10; @@ -190,128 +211,107 @@ NTSCFG_TEST_CASE(3) NTSCFG_TEST_FALSE(eventA.isWritable()); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::EventTest::verifyCase4) { - // Concern: The event set stores and merges socket events. - - ntscfg::TestAllocator ta; - { - const ntsa::Handle k_SOCKET_A = 10; - const ntsa::Handle k_SOCKET_B = 100; - const ntsa::Handle k_SOCKET_C = 1000; + const ntsa::Handle k_SOCKET_A = 10; + const ntsa::Handle k_SOCKET_B = 100; + const ntsa::Handle k_SOCKET_C = 1000; - ntsa::EventSet eventSet(&ta); + ntsa::EventSet eventSet(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(eventSet.size(), 0); + NTSCFG_TEST_EQ(eventSet.size(), 0); - { - ntsa::Event event; - event.setHandle(k_SOCKET_C); - event.setReadable(); + { + ntsa::Event event; + event.setHandle(k_SOCKET_C); + event.setReadable(); - eventSet.merge(event); - } + eventSet.merge(event); + } - NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_EQ(eventSet.size(), 1); - { - ntsa::Event event; - event.setHandle(k_SOCKET_C); - event.setWritable(); + { + ntsa::Event event; + event.setHandle(k_SOCKET_C); + event.setWritable(); - eventSet.merge(event); - } + eventSet.merge(event); + } - NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_EQ(eventSet.size(), 1); - { - ntsa::Event event; - event.setHandle(k_SOCKET_B); - event.setWritable(); + { + ntsa::Event event; + event.setHandle(k_SOCKET_B); + event.setWritable(); - eventSet.merge(event); - } + eventSet.merge(event); + } - NTSCFG_TEST_EQ(eventSet.size(), 2); + NTSCFG_TEST_EQ(eventSet.size(), 2); - { - ntsa::Event event; - event.setHandle(k_SOCKET_A); - event.setReadable(); + { + ntsa::Event event; + event.setHandle(k_SOCKET_A); + event.setReadable(); - eventSet.merge(event); - } + eventSet.merge(event); + } - NTSCFG_TEST_EQ(eventSet.size(), 3); + NTSCFG_TEST_EQ(eventSet.size(), 3); - NTSCFG_TEST_TRUE(eventSet.isReadable(k_SOCKET_A)); - NTSCFG_TEST_FALSE(eventSet.isWritable(k_SOCKET_A)); + NTSCFG_TEST_TRUE(eventSet.isReadable(k_SOCKET_A)); + NTSCFG_TEST_FALSE(eventSet.isWritable(k_SOCKET_A)); - NTSCFG_TEST_FALSE(eventSet.isReadable(k_SOCKET_B)); - NTSCFG_TEST_TRUE(eventSet.isWritable(k_SOCKET_B)); + NTSCFG_TEST_FALSE(eventSet.isReadable(k_SOCKET_B)); + NTSCFG_TEST_TRUE(eventSet.isWritable(k_SOCKET_B)); - NTSCFG_TEST_TRUE(eventSet.isReadable(k_SOCKET_C)); - NTSCFG_TEST_TRUE(eventSet.isWritable(k_SOCKET_C)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_TRUE(eventSet.isReadable(k_SOCKET_C)); + NTSCFG_TEST_TRUE(eventSet.isWritable(k_SOCKET_C)); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::EventTest::verifyCase5) { - // Concern: The event set is iteratable. - - ntscfg::TestAllocator ta; - { - const ntsa::Handle k_SOCKET_A = 10; - const ntsa::Handle k_SOCKET_B = 100; - const ntsa::Handle k_SOCKET_C = 1000; + const ntsa::Handle k_SOCKET_A = 10; + const ntsa::Handle k_SOCKET_B = 100; + const ntsa::Handle k_SOCKET_C = 1000; - ntsa::EventSet eventSet(&ta); + ntsa::EventSet eventSet(NTSCFG_TEST_ALLOCATOR); - eventSet.setReadable(k_SOCKET_C); - eventSet.setWritable(k_SOCKET_C); - eventSet.setWritable(k_SOCKET_B); - eventSet.setReadable(k_SOCKET_A); + eventSet.setReadable(k_SOCKET_C); + eventSet.setWritable(k_SOCKET_C); + eventSet.setWritable(k_SOCKET_B); + eventSet.setReadable(k_SOCKET_A); - NTSCFG_TEST_LOG_DEBUG << "Event set = " << eventSet - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Event set = " << eventSet << NTSCFG_TEST_LOG_END; - typedef bsl::vector EventVector; - EventVector eventVector(&ta); + typedef bsl::vector EventVector; + EventVector eventVector(NTSCFG_TEST_ALLOCATOR); - for (ntsa::EventSet::const_iterator it = eventSet.cbegin(); - it != eventSet.cend(); - ++it) - { - const ntsa::Event& event = *it; + for (ntsa::EventSet::const_iterator it = eventSet.cbegin(); + it != eventSet.cend(); + ++it) + { + const ntsa::Event& event = *it; - NTSCFG_TEST_LOG_DEBUG << "Event = " << event - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Event = " << event << NTSCFG_TEST_LOG_END; - eventVector.push_back(event); - } + eventVector.push_back(event); + } - NTSCFG_TEST_EQ(eventVector.size(), 3); + NTSCFG_TEST_EQ(eventVector.size(), 3); - NTSCFG_TEST_EQ(eventVector[0].handle(), k_SOCKET_A); - NTSCFG_TEST_TRUE(eventVector[0].isReadable()); + NTSCFG_TEST_EQ(eventVector[0].handle(), k_SOCKET_A); + NTSCFG_TEST_TRUE(eventVector[0].isReadable()); - NTSCFG_TEST_EQ(eventVector[1].handle(), k_SOCKET_B); - NTSCFG_TEST_TRUE(eventVector[1].isWritable()); + NTSCFG_TEST_EQ(eventVector[1].handle(), k_SOCKET_B); + NTSCFG_TEST_TRUE(eventVector[1].isWritable()); - NTSCFG_TEST_EQ(eventVector[2].handle(), k_SOCKET_C); - NTSCFG_TEST_TRUE(eventVector[2].isReadable()); - NTSCFG_TEST_TRUE(eventVector[2].isWritable()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_EQ(eventVector[2].handle(), k_SOCKET_C); + NTSCFG_TEST_TRUE(eventVector[2].isReadable()); + NTSCFG_TEST_TRUE(eventVector[2].isWritable()); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_file.t.cpp b/groups/nts/ntsa/ntsa_file.t.cpp index 11f7a1f0..9b1c6794 100644 --- a/groups/nts/ntsa/ntsa_file.t.cpp +++ b/groups/nts/ntsa/ntsa_file.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_file_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::File'. +class FileTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::FileTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_guid.t.cpp b/groups/nts/ntsa/ntsa_guid.t.cpp index 8bbcdef0..d7f7c702 100644 --- a/groups/nts/ntsa/ntsa_guid.t.cpp +++ b/groups/nts/ntsa/ntsa_guid.t.cpp @@ -13,274 +13,137 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntsa_guid_t_cpp, "$Id$ $CSID$") + #include -#include +using namespace BloombergLP; -#include +namespace BloombergLP { +namespace ntsa { -#include +// Provide tests for 'ntsa::Guid'. +class GuidTest +{ + public: + // Test concern: various text representations of GUIDs are valid. + static void verifyTextRepresentations(); -#include -#include -#include -#include + // Test concern: generated GUIDs are unique according to the definition and + // properties of the implementation. + static void verifyGeneration(); -#if defined(BSLS_PLATFORM__OS_WINDOWS) -#include -#endif + // Test concern: 'writeText' does not null-terminate its output. + static void verifyWriteText(); -using namespace BloombergLP; + // Test concern: GUIDs may be generated, compared, and have their binary + // and textual representations written to buffers. + static void verifyBasicOperations(); +}; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// This test driver ensures the basic properties of the GUIDs generated by -// this component: they may be generated, parsed from various representations, -// compared, and formatted. -//----------------------------------------------------------------------------- - -//============================================================================= -// STANDARD BDE ASSERT TEST MACRO -//----------------------------------------------------------------------------- -static int testStatus = 0; - -static void aSsErT(int c, const char* s, int i) +NTSCFG_TEST_FUNCTION(ntsa::GuidTest::verifyTextRepresentations) { - if (c) { - bsl::cout << "Error " << __FILE__ << "(" << i << "): " << s - << " (failed)" << bsl::endl; - if (0 <= testStatus && testStatus <= 100) - ++testStatus; - } + NTSCFG_TEST_TRUE(ntsa::Guid::isValidTextRepresentation( + "E7D7031011BB95370000699A7E0A0400")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "E7D7031011BB95370000699A7E0A040")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "E7D7031011BB95370000699A7E0A040z")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "E7D7031011BB95370000699A7E0A04x0")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "x7D7031011BB95370000699A7E0A0400")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "ExD7031011BB95370000699A7E0A0400")); + NTSCFG_TEST_FALSE(ntsa::Guid::isValidTextRepresentation( + "172.17.1.20:7231:18FEB2011_18:02:17.402393")); } -#define ASSERT(X) \ - { \ - aSsErT(!(X), #X, __LINE__); \ - } +NTSCFG_TEST_FUNCTION(ntsa::GuidTest::verifyGeneration) +{ + ntsa::Guid guid1(ntsa::Guid::generate()); + ntsa::Guid guid2(ntsa::Guid::generate()); -//============================================================================= -// STANDARD BDE LOOP-ASSERT TEST MACROS -//----------------------------------------------------------------------------- -#define LOOP_ASSERT(I, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ - } + NTSCFG_TEST_NE(guid1, guid2); -#define LOOP2_ASSERT(I, J, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\t" << #J << ": " << J << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ + bsl::string guidString1; + { + bsl::ostringstream ss; + ss << guid1; + guidString1 = ss.str(); } -#define LOOP3_ASSERT(I, J, K, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\t" << #J << ": " << J << "\t" \ - << #K << ": " << K << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ + bsl::string guidString2; + { + bsl::ostringstream ss; + ss << guid2; + guidString2 = ss.str(); } -//============================================================================= -// SEMI-STANDARD TEST OUTPUT MACROS -//----------------------------------------------------------------------------- -#define P(X) bsl::cout << #X " = " << (X) << bsl::endl; -#define Q(X) bsl::cout << "<| " #X " |>" << bsl::endl; -#define P_(X) bsl::cout << #X " = " << (X) << ", " << bsl::flush; -#define L_ __LINE__ -#define NL "\n" -#define T_() bsl::cout << " " << bsl::flush; - -//============================================================================= -// GLOBAL TYPEDEFS/CONSTANTS FOR TESTING -//----------------------------------------------------------------------------- - -static int verbose = 0; -static int veryVerbose = 0; -static int veryVeryVerbose = 0; -static int veryVeryVeryVerbose = 0; - -//============================================================================= -// HELPER FUNCTIONS AND CLASSES -//----------------------------------------------------------------------------- - -//============================================================================= -// MAIN PROGRAM -//----------------------------------------------------------------------------- - -int main(int argc, char* argv[]) + NTSCFG_TEST_FALSE(guidString1.empty()); + NTSCFG_TEST_FALSE(guidString2.empty()); + + NTSCFG_TEST_NE(guidString1, guidString2); +} + +NTSCFG_TEST_FUNCTION(ntsa::GuidTest::verifyWriteText) { -#if defined(BSLS_PLATFORM__OS_WINDOWS) - WSADATA wsa; - bsl::memset(&wsa, 0, sizeof wsa); - WSAStartup(MAKEWORD(2, 2), &wsa); -#endif - - int test = argc > 1 ? bsl::atoi(argv[1]) : 0; - verbose = (argc > 2); - veryVerbose = (argc > 3); - veryVeryVerbose = (argc > 4); - veryVeryVeryVerbose = (argc > 5); - bsl::cout << "TEST " << __FILE__ << " CASE " << test << bsl::endl; - ; - - switch (test) { - case 0: // Zero is always the leading case. - case 4: { - // TESTING BASIC OPERATIONS - // - // Concerns: - // GUIDs may be generated, compared, and have their binary and - // textual representations written to buffers. - - ntsa::Guid guid1(ntsa::Guid::generate()); - ntsa::Guid guid2(ntsa::Guid::generate()); - ntsa::Guid invalidGuid3; - ntsa::Guid invalidGuid4; - ntsa::Guid invalidGuid5(invalidGuid3); - - if (verbose) { - bsl::cout << "guid1:" << guid1 << " guid2:" << guid2 - << " invalidGuid3:" << invalidGuid3 - << " invalidGuid4:" << invalidGuid4 - << " invalidGuid5:" << invalidGuid5 << bsl::endl; - } - - ASSERT(!invalidGuid3.valid()); - ASSERT(!invalidGuid4.valid()); - ASSERT(!invalidGuid5.valid()); - - ASSERT(guid1 != guid2); - ASSERT((guid1 < guid2) == (guid2 > guid1)); - ASSERT((guid1 > guid2) == (guid2 < guid1)); - ntsa::Guid guid1eq(guid1); - ASSERT(guid1 == guid1eq); - - ASSERT(invalidGuid3 == invalidGuid4); - ASSERT(guid1 != invalidGuid3); - ASSERT(invalidGuid3 != guid1); - - ASSERT(guid1.compare(invalidGuid3) != invalidGuid3.compare(guid1)); - ASSERT(guid2.compare(invalidGuid3) != invalidGuid3.compare(guid2)); - - char binary[ntsa::Guid::SIZE_BINARY]; - guid1.writeBinary(binary); - - ntsa::Guid guid1bin(ntsa::Guid::BinaryRepresentation(), binary); - - ASSERT(guid1 == guid1bin); - - char text[ntsa::Guid::SIZE_TEXT + 1] = {0}; - guid1.writeText(text); - - if (verbose) { - bsl::cout << "Text rep: '" << text << "'" << bsl::endl; - } - - ntsa::Guid guid1text(ntsa::Guid::TextRepresentation(), text); - - ASSERT(guid1 == guid1text); - - } break; - case 3: { - // TESTING TEXT TERMINATION - // - // Concerns: - // writeText does not null-terminate its output. - - ntsa::Guid guid(ntsa::Guid::generate()); - char text[ntsa::Guid::SIZE_TEXT + 1]; - char magic = - static_cast(bdls::ProcessUtil::getProcessId() & 0xFF); - text[ntsa::Guid::SIZE_TEXT] = magic; - guid.writeText(text); - ASSERT(magic == text[ntsa::Guid::SIZE_TEXT]); - - } break; - case 2: { - // TESTING GUID GENERATION - // - // Concerns: - // Generated GUIDs are unique according to the definition and - // properties of the implementation. - - ntsa::Guid guid1(ntsa::Guid::generate()); - if (verbose) { - bsl::cout << "guid1 = " << guid1 << bsl::endl; - } - - ntsa::Guid guid2(ntsa::Guid::generate()); - if (verbose) { - bsl::cout << "guid2 = " << guid2 << bsl::endl; - } - - ASSERT(guid1 != guid2); - - bsl::string guidString1; - { - bsl::ostringstream ss; - ss << guid1; - guidString1 = ss.str(); - } - - bsl::string guidString2; - { - bsl::ostringstream ss; - ss << guid2; - guidString2 = ss.str(); - } - - ASSERT(!guidString1.empty()); - ASSERT(!guidString2.empty()); - - ASSERT(guidString1 != guidString2); - - } break; - case 1: { - // TESTING VALID TEXT REPRESENTATIONS - // - // Concerns: - // Various text representations of GUIDs are valid. - - ASSERT(ntsa::Guid::isValidTextRepresentation( - "E7D7031011BB95370000699A7E0A0400")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "E7D7031011BB95370000699A7E0A040")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "E7D7031011BB95370000699A7E0A040z")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "E7D7031011BB95370000699A7E0A04x0")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "x7D7031011BB95370000699A7E0A0400")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "ExD7031011BB95370000699A7E0A0400")); - ASSERT(!ntsa::Guid::isValidTextRepresentation( - "172.17.1.20:7231:18FEB2011_18:02:17.402393")); - - } break; - default: { - bsl::cerr << "WARNING: CASE `" << test << "' NOT FOUND." << bsl::endl; - testStatus = -1; - } - } + ntsa::Guid guid(ntsa::Guid::generate()); - if (testStatus > 0) { - bsl::cerr << "Error, non-zero test status = " << testStatus << "." - << bsl::endl; - } + const char magic = + static_cast(bdls::ProcessUtil::getProcessId() & 0xFF); -#if defined(BSLS_PLATFORM__OS_WINDOWS) - WSACleanup(); -#endif + char text[ntsa::Guid::SIZE_TEXT + 1]; + text[ntsa::Guid::SIZE_TEXT] = magic; - return testStatus; + guid.writeText(text); + + NTSCFG_TEST_EQ(magic, text[ntsa::Guid::SIZE_TEXT]); +} + +NTSCFG_TEST_FUNCTION(ntsa::GuidTest::verifyBasicOperations) +{ + ntsa::Guid guid1(ntsa::Guid::generate()); + ntsa::Guid guid2(ntsa::Guid::generate()); + ntsa::Guid invalidGuid3; + ntsa::Guid invalidGuid4; + ntsa::Guid invalidGuid5(invalidGuid3); + + NTSCFG_TEST_FALSE(invalidGuid3.valid()); + NTSCFG_TEST_FALSE(invalidGuid4.valid()); + NTSCFG_TEST_FALSE(invalidGuid5.valid()); + + NTSCFG_TEST_NE(guid1, guid2); + NTSCFG_TEST_TRUE((guid1 < guid2) == (guid2 > guid1)); + NTSCFG_TEST_TRUE((guid1 > guid2) == (guid2 < guid1)); + + ntsa::Guid guid1eq(guid1); + NTSCFG_TEST_EQ(guid1, guid1eq); + + NTSCFG_TEST_EQ(invalidGuid3, invalidGuid4); + NTSCFG_TEST_NE(guid1, invalidGuid3); + NTSCFG_TEST_NE(invalidGuid3, guid1); + + NTSCFG_TEST_NE(guid1.compare(invalidGuid3), invalidGuid3.compare(guid1)); + NTSCFG_TEST_NE(guid2.compare(invalidGuid3), invalidGuid3.compare(guid2)); + + char binary[ntsa::Guid::SIZE_BINARY]; + guid1.writeBinary(binary); + + ntsa::Guid guid1bin(ntsa::Guid::BinaryRepresentation(), binary); + + NTSCFG_TEST_EQ(guid1, guid1bin); + + char text[ntsa::Guid::SIZE_TEXT + 1] = {0}; + guid1.writeText(text); + + ntsa::Guid guid1text(ntsa::Guid::TextRepresentation(), text); + + NTSCFG_TEST_EQ(guid1, guid1text); } + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_handle.t.cpp b/groups/nts/ntsa/ntsa_handle.t.cpp index 5efbbe77..47939eb6 100644 --- a/groups/nts/ntsa/ntsa_handle.t.cpp +++ b/groups/nts/ntsa/ntsa_handle.t.cpp @@ -13,9 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include + +#include +BSLS_IDENT_RCSID(ntsa_handle_t_cpp, "$Id$ $CSID$") + +#include #if defined(BSLS_PLATFORM_OS_UNIX) #include @@ -28,20 +31,18 @@ using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +// Provide tests for 'ntsa::Handle'. +class HandleTest +{ + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsa::HandleTest::verify) { #if defined(BSLS_PLATFORM_OS_UNIX) BSLMF_ASSERT(sizeof(ntsa::Handle) == sizeof(int)); @@ -50,8 +51,5 @@ NTSCFG_TEST_CASE(1) #endif } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_host.cpp b/groups/nts/ntsa/ntsa_host.cpp index f8ac11a3..325ee995 100644 --- a/groups/nts/ntsa/ntsa_host.cpp +++ b/groups/nts/ntsa/ntsa_host.cpp @@ -342,7 +342,7 @@ bsl::ostream& Host::print(bsl::ostream& stream, const bdlat_SelectionInfo* Host::lookupSelectionInfo(int id) { - const int numSelections = + const int numSelections = sizeof(SELECTION_INFO_ARRAY) / sizeof(SELECTION_INFO_ARRAY[0]); if (id < 0 || id >= numSelections) { @@ -352,17 +352,16 @@ const bdlat_SelectionInfo* Host::lookupSelectionInfo(int id) return &SELECTION_INFO_ARRAY[id]; } -const bdlat_SelectionInfo* Host::lookupSelectionInfo( - const char* name, - int nameLength) +const bdlat_SelectionInfo* Host::lookupSelectionInfo(const char* name, + int nameLength) { - const bsl::size_t numSelections = + const bsl::size_t numSelections = sizeof(SELECTION_INFO_ARRAY) / sizeof(SELECTION_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numSelections; ++i) { const bdlat_SelectionInfo& selectionInfo = SELECTION_INFO_ARRAY[i]; if (selectionInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(selectionInfo.d_name_p, name, nameLength); if (compare == 0) { return &selectionInfo; diff --git a/groups/nts/ntsa/ntsa_host.h b/groups/nts/ntsa/ntsa_host.h index 68b418fd..3ed62751 100644 --- a/groups/nts/ntsa/ntsa_host.h +++ b/groups/nts/ntsa/ntsa_host.h @@ -21,13 +21,13 @@ BSLS_IDENT("$Id: $") #include #include -#include #include +#include #include #include -#include -#include #include +#include +#include #include #include #include @@ -241,50 +241,50 @@ class Host int level = 0, int spacesPerLevel = 4) const; - /// Set the value of this object to be the default for the selection - /// indicated by the specified 'id'. Return 0 on success, and non-zero - /// value otherwise (i.e., the selection is not found). + /// Set the value of this object to be the default for the selection + /// indicated by the specified 'id'. Return 0 on success, and non-zero + /// value otherwise (i.e., the selection is not found). int makeSelection(int id); - /// Set the value of this object to be the default for the selection - /// indicated by the specified 'name' of the specified 'nameLength'. - /// Return 0 on success, and non-zero value otherwise (i.e., the selection - /// is not found). + /// Set the value of this object to be the default for the selection + /// indicated by the specified 'name' of the specified 'nameLength'. + /// Return 0 on success, and non-zero value otherwise (i.e., the selection + /// is not found). int makeSelection(const char* name, int nameLength); - /// Return the selection ID of the current selection in the choice. + /// Return the selection ID of the current selection in the choice. int selectionId() const; - /// Invoke the specified 'manipulator' on the address of the modifiable - /// selection, supplying 'manipulator' with the corresponding selection - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if this object has a defined selection, and -1 - /// otherwise. + /// Invoke the specified 'manipulator' on the address of the modifiable + /// selection, supplying 'manipulator' with the corresponding selection + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if this object has a defined selection, and -1 + /// otherwise. template int manipulateSelection(MANIPULATOR& manipulator); - /// Invoke the specified 'accessor' on the non-modifiable selection, - /// supplying 'accessor' with the corresponding selection information - /// structure. Return the value returned from the invocation of 'accessor' - /// if this object has a defined selection, and -1 otherwise. + /// Invoke the specified 'accessor' on the non-modifiable selection, + /// supplying 'accessor' with the corresponding selection information + /// structure. Return the value returned from the invocation of 'accessor' + /// if this object has a defined selection, and -1 otherwise. template int accessSelection(ACCESSOR& accessor) const; - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[11]; - /// The selection info array, indexed by selection index. + /// The selection info array, indexed by selection index. static const bdlat_SelectionInfo SELECTION_INFO_ARRAY[4]; - /// Return selection information for the selection indicated by the - /// specified 'id' if the selection exists, and 0 otherwise. + /// Return selection information for the selection indicated by the + /// specified 'id' if the selection exists, and 0 otherwise. static const bdlat_SelectionInfo* lookupSelectionInfo(int id); - /// Return selection information for the selection indicated by the - /// specified 'name' of the specified 'nameLength' if the selection - /// exists, and 0 otherwise. - static const bdlat_SelectionInfo* lookupSelectionInfo( - const char* name, int nameLength); + /// Return selection information for the selection indicated by the + /// specified 'name' of the specified 'nameLength' if the selection + /// exists, and 0 otherwise. + static const bdlat_SelectionInfo* lookupSelectionInfo(const char* name, + int nameLength); /// Defines the traits of this type. These traits can be used to select, /// at compile-time, the most efficient algorithm to manipulate objects @@ -469,7 +469,7 @@ int Host::makeSelection(int id) NTSCFG_INLINE int Host::makeSelection(const char* name, int nameLength) { - const bdlat_SelectionInfo *selectionInfo = + const bdlat_SelectionInfo* selectionInfo = ntsa::Host::lookupSelectionInfo(name, nameLength); if (selectionInfo == 0) { return -1; @@ -531,8 +531,8 @@ template int Host::accessSelection(ACCESSOR& accessor) const { int rc; - - const bdlat_SelectionInfo *selectionInfo = + + const bdlat_SelectionInfo* selectionInfo = ntsa::Host::lookupSelectionInfo(d_type); if (selectionInfo == 0) { return -1; diff --git a/groups/nts/ntsa/ntsa_host.t.cpp b/groups/nts/ntsa/ntsa_host.t.cpp index 69dc8af2..220cb071 100644 --- a/groups/nts/ntsa/ntsa_host.t.cpp +++ b/groups/nts/ntsa/ntsa_host.t.cpp @@ -13,233 +13,210 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include + +#include +BSLS_IDENT_RCSID(ntsa_host_t_cpp, "$Id$ $CSID$") + +#include + #include #include #include #include -#include -#include -#include -#include -#include -#include using namespace BloombergLP; -using namespace ntsa; - -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Host'. +class HostTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); - ntscfg::TestAllocator ta; + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::HostTest::verifyCase1) +{ { + ntsa::Host host; + bool valid = host.parse("192.168.1.250"); + NTSCFG_TEST_ASSERT(valid); + NTSCFG_TEST_ASSERT(host.isIp()); + NTSCFG_TEST_ASSERT(host.ip().isV4()); + { - ntsa::Host host; - bool valid = host.parse("192.168.1.250"); - NTSCFG_TEST_ASSERT(valid); - NTSCFG_TEST_ASSERT(host.isIp()); - NTSCFG_TEST_ASSERT(host.ip().isV4()); - - { - bsl::stringstream ss; - ss << host; - - BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); - } + bsl::stringstream ss; + ss << host; + + BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); } + } + + { + ntsa::Host host; + bool valid = host.parse("2001:41c0::645:a65e:60ff:feda:589d"); + NTSCFG_TEST_ASSERT(valid); + NTSCFG_TEST_ASSERT(host.isIp()); + NTSCFG_TEST_ASSERT(host.ip().isV6()); { - ntsa::Host host; - bool valid = host.parse("2001:41c0::645:a65e:60ff:feda:589d"); - NTSCFG_TEST_ASSERT(valid); - NTSCFG_TEST_ASSERT(host.isIp()); - NTSCFG_TEST_ASSERT(host.ip().isV6()); - - { - bsl::stringstream ss; - ss << host; - - BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); - } + bsl::stringstream ss; + ss << host; + + BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); } + } - { - ntsa::Host host; - bool valid = host.parse("localhost"); - NTSCFG_TEST_ASSERT(valid); - NTSCFG_TEST_ASSERT(host.isDomainName()); + { + ntsa::Host host; + bool valid = host.parse("localhost"); + NTSCFG_TEST_ASSERT(valid); + NTSCFG_TEST_ASSERT(host.isDomainName()); - { - bsl::stringstream ss; - ss << host; + { + bsl::stringstream ss; + ss << host; - BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); - } + BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); } + } - { - ntsa::Host host; - bool valid = host.parse("localhost.localdomain"); - NTSCFG_TEST_ASSERT(valid); - NTSCFG_TEST_ASSERT(host.isDomainName()); + { + ntsa::Host host; + bool valid = host.parse("localhost.localdomain"); + NTSCFG_TEST_ASSERT(valid); + NTSCFG_TEST_ASSERT(host.isDomainName()); - { - bsl::stringstream ss; - ss << host; + { + bsl::stringstream ss; + ss << host; - BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); - } + BSLS_LOG_DEBUG("Host = %s", ss.str().c_str()); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::HostTest::verifyCase2) { - // Concern: - // Plan: + ntsa::Host host1("192.168.1.250"); + ntsa::Host host2("2001:41c0::645:a65e:60ff:feda:589d"); + ntsa::Host host3("localhost.localdomain"); - ntscfg::TestAllocator ta; - { - ntsa::Host host1("192.168.1.250"); - ntsa::Host host2("2001:41c0::645:a65e:60ff:feda:589d"); - ntsa::Host host3("localhost.localdomain"); + bsl::unordered_set hostSet; + hostSet.insert(host1); + hostSet.insert(host2); + hostSet.insert(host3); - bsl::unordered_set hostSet; - hostSet.insert(host1); - hostSet.insert(host2); - hostSet.insert(host3); - - NTSCFG_TEST_ASSERT(hostSet.size() == 3); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_ASSERT(hostSet.size() == 3); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::HostTest::verifyCase3) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::Host e1("10.26.55.100"); - ntsa::Host e2; - - bdlsb::MemOutStreamBuf osb(&ta); + ntsa::Host e1("10.26.55.100"); + ntsa::Host e2; - balber::BerEncoder encoder(0, &ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerEncoder encoder(0, NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" - << bdlb::PrintStringHexDumper( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" + << bdlb::PrintStringHexDumper( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - balber::BerDecoder decoder(0, &ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerDecoder decoder(0, NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2, e1); + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); + + NTSCFG_TEST_EQ(e2, e1); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::HostTest::verifyCase4) { int rc; - ntscfg::TestAllocator ta; - { - bsl::vector e1(&ta); - bsl::vector e2(&ta); + bsl::vector e1(NTSCFG_TEST_ALLOCATOR); + bsl::vector e2(NTSCFG_TEST_ALLOCATOR); - e1.push_back(ntsa::Host("ntf.example.com")); - e1.push_back(ntsa::Host("10.26.55.100")); - e1.push_back(ntsa::Host("/tmp/ntf/socket")); + e1.push_back(ntsa::Host("ntf.example.com")); + e1.push_back(ntsa::Host("10.26.55.100")); + e1.push_back(ntsa::Host("/tmp/ntf/socket")); - bdlsb::MemOutStreamBuf osb; + bdlsb::MemOutStreamBuf osb; - baljsn::Encoder encoder(&ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Encoder encoder(NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded: " - << bsl::string_view( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded: " + << bsl::string_view( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - baljsn::Decoder decoder(&ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Decoder decoder(NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2.size(), e1.size()); + NTSCFG_TEST_EQ(rc, 0); + } - for (bsl::size_t i = 0; i < e1.size(); ++i) { - NTSCFG_TEST_EQ(e2[i], e1[i]); - } + NTSCFG_TEST_EQ(e2.size(), e1.size()); + + for (bsl::size_t i = 0; i < e1.size(); ++i) { + NTSCFG_TEST_EQ(e2[i], e1[i]); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_hosttype.t.cpp b/groups/nts/ntsa/ntsa_hosttype.t.cpp index 7556f3fa..e37aa95a 100644 --- a/groups/nts/ntsa/ntsa_hosttype.t.cpp +++ b/groups/nts/ntsa/ntsa_hosttype.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_hosttype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::HostType'. +class HostTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::HostTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_id.t.cpp b/groups/nts/ntsa/ntsa_id.t.cpp index 80b5f0ca..a2a4ab67 100644 --- a/groups/nts/ntsa/ntsa_id.t.cpp +++ b/groups/nts/ntsa/ntsa_id.t.cpp @@ -13,197 +13,86 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include +#include +BSLS_IDENT_RCSID(ntsa_id_t_cpp, "$Id$ $CSID$") -#include -#include -#include -#include +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// This test driver ensures the basic properties of the locally-unique -// identifier generation system: that new objects are automatically assigned -// identifiers unique to the current process, that objects are properly -// formatted when written to streams, and that copy-construction does not -// generate new identifiers. -//----------------------------------------------------------------------------- - -//============================================================================= -// STANDARD BDE ASSERT TEST MACRO -//----------------------------------------------------------------------------- -static int testStatus = 0; - -static void aSsErT(int c, const char* s, int i) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Id'. +class IdTest { - if (c) { - bsl::cout << "Error " << __FILE__ << "(" << i << "): " << s - << " (failed)" << bsl::endl; - if (0 <= testStatus && testStatus <= 100) - ++testStatus; - } -} + public: + // TODO + static void verify(); +}; -#define ASSERT(X) \ - { \ - aSsErT(!(X), #X, __LINE__); \ +NTSCFG_TEST_FUNCTION(ntsa::IdTest::verify) +{ + // TESTING OBJECT ID CREATION + // + // Concerns: + // Objects that automatically generated identifiers unique within + // the current process. Copy construction does not generate new + // values. Object are properly formatted when written to streams. + // + // Plan: + // This test plan assumes that no other objects in this process + // have previously called 'ntsa::Id::generate()'. First, + // create two 'ntsa::Id's. Ensure they have been assigned + // integer identifiers monitonically increasing starting at 1. + // Ensure the objects are properly formatted when written to streams. + // Ensure that copy construction does not generate new identifiers; + // a copy-constructed 'ntsa::Id' conceptually identifies the + // same object as the value from which it was constructed. + + // Generate the first locally-unique identifier to this process and + // ensure it is assigned the integer value 1. + + ntsa::Id id1(ntsa::Id::generate()); + NTSCFG_TEST_EQ(static_cast(id1), 1); + + { + bsl::ostringstream ss; + ss << id1; + NTSCFG_TEST_EQ(ss.str(), "id:000001"); } -//============================================================================= -// STANDARD BDE LOOP-ASSERT TEST MACROS -//----------------------------------------------------------------------------- -#define LOOP_ASSERT(I, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ - } + // Generate the second locally-unique identifier to this process and + // ensure it is assigned the integer value 1. -#define LOOP2_ASSERT(I, J, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\t" << #J << ": " << J << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ + ntsa::Id id2(ntsa::Id::generate()); + NTSCFG_TEST_EQ(static_cast(id2), 2); + { + bsl::ostringstream ss; + ss << id2; + NTSCFG_TEST_EQ(ss.str(), "id:000002"); } -#define LOOP3_ASSERT(I, J, K, X) \ - { \ - if (!(X)) { \ - bsl::cout << #I << ": " << I << "\t" << #J << ": " << J << "\t" \ - << #K << ": " << K << "\n"; \ - aSsErT(1, #X, __LINE__); \ - } \ - } + // Ensure that the two identifiers do not have the same value. -//============================================================================= -// SEMI-STANDARD TEST OUTPUT MACROS -//----------------------------------------------------------------------------- -#define P(X) bsl::cout << #X " = " << (X) << bsl::endl; -#define Q(X) bsl::cout << "<| " #X " |>" << bsl::endl; -#define P_(X) bsl::cout << #X " = " << (X) << ", " << bsl::flush; -#define L_ __LINE__ -#define NL "\n" -#define T_() bsl::cout << " " << bsl::flush; - -//============================================================================= -// GLOBAL TYPEDEFS/CONSTANTS FOR TESTING -//----------------------------------------------------------------------------- - -static int verbose = 0; -static int veryVerbose = 0; -static int veryVeryVerbose = 0; -static int veryVeryVeryVerbose = 0; - -//============================================================================= -// HELPER FUNCTIONS AND CLASSES -//----------------------------------------------------------------------------- - -//============================================================================= -// MAIN PROGRAM -//----------------------------------------------------------------------------- - -int main(int argc, char* argv[]) -{ - int test = argc > 1 ? bsl::atoi(argv[1]) : 0; - verbose = (argc > 2); - veryVerbose = (argc > 3); - veryVeryVerbose = (argc > 4); - veryVeryVeryVerbose = (argc > 5); - bsl::cout << "TEST " << __FILE__ << " CASE " << test << bsl::endl; - ; - - switch (test) { - case 0: // Zero is always the leading case. - case 1: { - // TESTING OBJECT ID CREATION - // - // Concerns: - // Objects that automatically generated identifiers unique within - // the current process. Copy construction does not generate new - // values. Object are properly formatted when written to streams. - // - // Plan: - // This test plan assumes that no other objects in this process - // have previously called 'ntsa::Id::generate()'. First, - // create two 'ntsa::Id's. Ensure they have been assigned - // integer identifiers monitonically increasing starting at 1. - // Ensure the objects are properly formatted when written to streams. - // Ensure that copy construction does not generate new identifiers; - // a copy-constructed 'ntsa::Id' conceptually identifies the - // same object as the value from which it was constructed. - - // Generate the first locally-unique identifier to this process and - // ensure it is assigned the integer value 1. - - ntsa::Id id1(ntsa::Id::generate()); - if (verbose) { - bsl::cout << "id1 = " << id1 << bsl::endl; - } - ASSERT(static_cast(id1) == 1); - { - bsl::ostringstream ss; - ss << id1; - ASSERT(ss.str() == "id:000001"); - } - - // Generate the second locally-unique identifier to this process and - // ensure it is assigned the integer value 1. - - ntsa::Id id2(ntsa::Id::generate()); - if (verbose) { - bsl::cout << "id2 = " << id2 << bsl::endl; - } - ASSERT(static_cast(id2) == 2); - { - bsl::ostringstream ss; - ss << id2; - ASSERT(ss.str() == "id:000002"); - } - - // Ensure that the two identifiers do not have the same value. - - ASSERT(id1 != id2); - - // Copy construct the first identifier and ensure it has the same - // value as the original value: copy-construction does not generate - // an new unique value. - - ntsa::Id id1copy(id1); - if (verbose) { - bsl::cout << "id1copy = " << id1copy << bsl::endl; - } - ASSERT(id1 == id1copy); - - // Copy construct the second identifier and ensure it has the same - // value as the original value: copy-construction does not generate - // an new unique value. - - ntsa::Id id2copy(id2); - if (verbose) { - bsl::cout << "id2copy = " << id2copy << bsl::endl; - } - ASSERT(id2 == id2copy); - } break; - default: { - bsl::cerr << "WARNING: CASE `" << test << "' NOT FOUND." << bsl::endl; - testStatus = -1; - } - } + NTSCFG_TEST_NE(id1, id2); - if (testStatus > 0) { - bsl::cerr << "Error, non-zero test status = " << testStatus << "." - << bsl::endl; - } - return testStatus; + // Copy construct the first identifier and ensure it has the same + // value as the original value: copy-construction does not generate + // an new unique value. + + ntsa::Id id1copy(id1); + NTSCFG_TEST_EQ(id1, id1copy); + + // Copy construct the second identifier and ensure it has the same + // value as the original value: copy-construction does not generate + // an new unique value. + + ntsa::Id id2copy(id2); + NTSCFG_TEST_EQ(id2, id2copy); } + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_interest.t.cpp b/groups/nts/ntsa/ntsa_interest.t.cpp index da3ca1c5..b9e86c36 100644 --- a/groups/nts/ntsa/ntsa_interest.t.cpp +++ b/groups/nts/ntsa/ntsa_interest.t.cpp @@ -13,128 +13,62 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -using namespace BloombergLP; - -namespace test { - -// Ensure the specified 'socket' is not found in the specified 'interestSet'. -void ensureNotFound(const ntsa::InterestSet& interestSet, ntsa::Handle socket) -{ - NTSCFG_TEST_FALSE(interestSet.contains(socket)); - - ntsa::Interest interest; - bool found = interestSet.find(&interest, socket); - NTSCFG_TEST_FALSE(found); -} - -// Ensure the specified 'socket' is found in the specified 'interestSet' but -// there is interest in neither readability nor writability. -void ensureWantNone(const ntsa::InterestSet& interestSet, ntsa::Handle socket) -{ - NTSCFG_TEST_TRUE(interestSet.contains(socket)); - - ntsa::Interest interest; - bool found = interestSet.find(&interest, socket); - - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_EQ(interest.handle(), socket); - - NTSCFG_TEST_FALSE(interest.wantReadable()); - NTSCFG_TEST_FALSE(interest.wantWritable()); - NTSCFG_TEST_FALSE(interest.wantAny()); - NTSCFG_TEST_FALSE(interest.wantBoth()); - NTSCFG_TEST_TRUE(interest.wantNone()); - - NTSCFG_TEST_FALSE(interestSet.wantReadable(socket)); - NTSCFG_TEST_FALSE(interestSet.wantWritable(socket)); - NTSCFG_TEST_FALSE(interestSet.wantAny(socket)); - NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); - NTSCFG_TEST_TRUE(interestSet.wantNone(socket)); -} - -// Ensure the specified 'socket' is found in the specified 'interestSet' with -// interest in readability but not writability. -void ensureWantReadable(const ntsa::InterestSet& interestSet, - ntsa::Handle socket) -{ - NTSCFG_TEST_TRUE(interestSet.contains(socket)); - - ntsa::Interest interest; - bool found = interestSet.find(&interest, socket); - - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_EQ(interest.handle(), socket); - - NTSCFG_TEST_TRUE(interest.wantReadable()); - NTSCFG_TEST_FALSE(interest.wantWritable()); - NTSCFG_TEST_TRUE(interest.wantAny()); - NTSCFG_TEST_FALSE(interest.wantBoth()); - NTSCFG_TEST_FALSE(interest.wantNone()); - - NTSCFG_TEST_TRUE(interestSet.wantReadable(socket)); - NTSCFG_TEST_FALSE(interestSet.wantWritable(socket)); - NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); - NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); - NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); -} +#include +BSLS_IDENT_RCSID(ntsa_interest_t_cpp, "$Id$ $CSID$") -// Ensure the specified 'socket' is found in the specified 'interestSet' with -// interest in writability but not readability. -void ensureWantWritable(const ntsa::InterestSet& interestSet, - ntsa::Handle socket) -{ - NTSCFG_TEST_TRUE(interestSet.contains(socket)); - - ntsa::Interest interest; - bool found = interestSet.find(&interest, socket); - - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_EQ(interest.handle(), socket); +#include - NTSCFG_TEST_FALSE(interest.wantReadable()); - NTSCFG_TEST_TRUE(interest.wantWritable()); - NTSCFG_TEST_TRUE(interest.wantAny()); - NTSCFG_TEST_FALSE(interest.wantBoth()); - NTSCFG_TEST_FALSE(interest.wantNone()); +using namespace BloombergLP; - NTSCFG_TEST_FALSE(interestSet.wantReadable(socket)); - NTSCFG_TEST_TRUE(interestSet.wantWritable(socket)); - NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); - NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); - NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); -} +namespace BloombergLP { +namespace ntsa { -// Ensure the specified 'socket' is found in the specified 'interestSet' with -// interest in both readability and writability. -void ensureWantBoth(const ntsa::InterestSet& interestSet, ntsa::Handle socket) +// Provide tests for 'ntsa::Interest'. +class InterestTest { - NTSCFG_TEST_TRUE(interestSet.contains(socket)); - - ntsa::Interest interest; - bool found = interestSet.find(&interest, socket); - - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_EQ(interest.handle(), socket); - - NTSCFG_TEST_TRUE(interest.wantReadable()); - NTSCFG_TEST_TRUE(interest.wantWritable()); - NTSCFG_TEST_TRUE(interest.wantAny()); - NTSCFG_TEST_TRUE(interest.wantBoth()); - NTSCFG_TEST_FALSE(interest.wantNone()); - - NTSCFG_TEST_TRUE(interestSet.wantReadable(socket)); - NTSCFG_TEST_TRUE(interestSet.wantWritable(socket)); - NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); - NTSCFG_TEST_TRUE(interestSet.wantBoth(socket)); - NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); -} - -} // close namespace test - -NTSCFG_TEST_CASE(1) + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + private: + // Ensure the specified 'socket' is not found in the specified + // 'interestSet'. + static void ensureNotFound(const ntsa::InterestSet& interestSet, + ntsa::Handle socket); + + // Ensure the specified 'socket' is found in the specified 'interestSet' + // but there is interest in neither readability nor writability. + static void ensureWantNone(const ntsa::InterestSet& interestSet, + ntsa::Handle socket); + + // Ensure the specified 'socket' is found in the specified 'interestSet' + // with interest in readability but not writability. + static void ensureWantReadable(const ntsa::InterestSet& interestSet, + ntsa::Handle socket); + + // Ensure the specified 'socket' is found in the specified 'interestSet' + // with interest in writability but not readability. + static void ensureWantWritable(const ntsa::InterestSet& interestSet, + ntsa::Handle socket); + + // Ensure the specified 'socket' is found in the specified 'interestSet' with + // interest in both readability and writability. + static void ensureWantBoth(const ntsa::InterestSet& interestSet, + ntsa::Handle socket); +}; + +NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase1) { // Concern: ntsa::Interest stores the readable and writable states and // correctly reports whether there is interest in readability, writability, @@ -275,472 +209,556 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_TRUE(interest.wantNone()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) { - // Concern: - // Plan: + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - const ntsa::Handle k_SOCKET_MIN = 1; - const ntsa::Handle k_SOCKET_MAX = 32; + const ntsa::Handle k_SOCKET_MIN = 1; + const ntsa::Handle k_SOCKET_MAX = 32; - // Create an interest set. + // Create an interest set. - ntsa::InterestSet interestSet(&ta); + ntsa::InterestSet interestSet(NTSCFG_TEST_ALLOCATOR); - // Ensure the interest set is initially empty. + // Ensure the interest set is initially empty. - NTSCFG_TEST_TRUE(interestSet.empty()); + NTSCFG_TEST_TRUE(interestSet.empty()); - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - test::ensureNotFound(interestSet, i); - } + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + InterestTest::ensureNotFound(interestSet, i); + } - // Attach each socket to the interest set. + // Attach each socket to the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.attach(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.attach(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureNotFound(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureNotFound(interestSet, j); } } + } - // Gain interest in readability of each socket in the interest set. + // Gain interest in readability of each socket in the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantReadable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantReadable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - // Lose interest in readability of each socket in the interest set. + // Lose interest in readability of each socket in the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantReadable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantReadable(interestSet, j); } } + } - // Gain interest in writability of each socket in the interest set. + // Gain interest in writability of each socket in the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantWritable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantWritable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - // Lose interest in writability of each socket in the interest set. + // Lose interest in writability of each socket in the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantWritable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantWritable(interestSet, j); } } + } - // Gain interest in readability then writability of each socket in - // the interest set. + // Gain interest in readability then writability of each socket in + // the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantReadable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantReadable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantBoth(interestSet, j); - } - else { - test::ensureWantReadable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantBoth(interestSet, j); + } + else { + InterestTest::ensureWantReadable(interestSet, j); } } + } - // Lose interest in readability then writability of each socket in the - // interest set. + // Lose interest in readability then writability of each socket in the + // interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantWritable(interestSet, j); - } - else { - test::ensureWantBoth(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantWritable(interestSet, j); + } + else { + InterestTest::ensureWantBoth(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantWritable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantWritable(interestSet, j); } } + } - // Gain interest in readability then writability of each socket in - // the interest set. + // Gain interest in readability then writability of each socket in + // the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantReadable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantReadable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantBoth(interestSet, j); - } - else { - test::ensureWantReadable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantBoth(interestSet, j); + } + else { + InterestTest::ensureWantReadable(interestSet, j); } } + } - // Lose interest in writability then readability of each socket in the - // interest set. + // Lose interest in writability then readability of each socket in the + // interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantReadable(interestSet, j); - } - else { - test::ensureWantBoth(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantReadable(interestSet, j); + } + else { + InterestTest::ensureWantBoth(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantReadable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantReadable(interestSet, j); } } + } - // Gain interest in writability then readability of each socket in - // the interest set. + // Gain interest in writability then readability of each socket in + // the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantWritable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantWritable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantBoth(interestSet, j); - } - else { - test::ensureWantWritable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantBoth(interestSet, j); + } + else { + InterestTest::ensureWantWritable(interestSet, j); } } + } - // Lose interest in writability then readability of each socket in the - // interest set. + // Lose interest in writability then readability of each socket in the + // interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantReadable(interestSet, j); - } - else { - test::ensureWantBoth(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantReadable(interestSet, j); + } + else { + InterestTest::ensureWantBoth(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantReadable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantReadable(interestSet, j); } } + } - // Gain interest in writability then readability of each socket in - // the interest set. + // Gain interest in writability then readability of each socket in + // the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantWritable(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantWritable(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.showReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.showReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantBoth(interestSet, j); - } - else { - test::ensureWantWritable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantBoth(interestSet, j); + } + else { + InterestTest::ensureWantWritable(interestSet, j); } } + } - // Lose interest in readability then writability of each socket in the - // interest set. + // Lose interest in readability then writability of each socket in the + // interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideReadable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideReadable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantWritable(interestSet, j); - } - else { - test::ensureWantBoth(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantWritable(interestSet, j); + } + else { + InterestTest::ensureWantBoth(interestSet, j); } } + } - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.hideWritable(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.hideWritable(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureWantNone(interestSet, j); - } - else { - test::ensureWantWritable(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureWantNone(interestSet, j); + } + else { + InterestTest::ensureWantWritable(interestSet, j); } } + } - // Detach each socket to the interest set. + // Detach each socket to the interest set. - for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - error = interestSet.detach(i); - NTSCFG_TEST_OK(error); + for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { + error = interestSet.detach(i); + NTSCFG_TEST_OK(error); - for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { - if (j <= i) { - test::ensureNotFound(interestSet, j); - } - else { - test::ensureWantNone(interestSet, j); - } + for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { + if (j <= i) { + InterestTest::ensureNotFound(interestSet, j); + } + else { + InterestTest::ensureWantNone(interestSet, j); } } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase3) { // Concern: Sockets are not automatically attached to the interest set // if interest is attempted to be gained on an un-attached socket. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - const ntsa::Handle k_SOCKET_A = 10; - const ntsa::Handle k_SOCKET_X = 1000; + const ntsa::Handle k_SOCKET_A = 10; + const ntsa::Handle k_SOCKET_X = 1000; - ntsa::InterestSet interestSet(&ta); + ntsa::InterestSet interestSet(NTSCFG_TEST_ALLOCATOR); - error = interestSet.attach(k_SOCKET_A); - NTSCFG_TEST_OK(error); + error = interestSet.attach(k_SOCKET_A); + NTSCFG_TEST_OK(error); - error = interestSet.showReadable(k_SOCKET_A); - NTSCFG_TEST_OK(error); + error = interestSet.showReadable(k_SOCKET_A); + NTSCFG_TEST_OK(error); - error = interestSet.showWritable(k_SOCKET_A); - NTSCFG_TEST_OK(error); + error = interestSet.showWritable(k_SOCKET_A); + NTSCFG_TEST_OK(error); - error = interestSet.showReadable(k_SOCKET_X); - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); + error = interestSet.showReadable(k_SOCKET_X); + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - error = interestSet.showWritable(k_SOCKET_X); - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + error = interestSet.showWritable(k_SOCKET_X); + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase4) { // Concern: The interest set is iteratable. - ntscfg::TestAllocator ta; + const ntsa::Handle k_SOCKET_A = 10; + const ntsa::Handle k_SOCKET_B = 100; + const ntsa::Handle k_SOCKET_C = 1000; + const ntsa::Handle k_SOCKET_D = 10000; + + ntsa::InterestSet interestSet(NTSCFG_TEST_ALLOCATOR); + + interestSet.attach(k_SOCKET_A); + interestSet.attach(k_SOCKET_B); + interestSet.attach(k_SOCKET_C); + interestSet.attach(k_SOCKET_D); + + interestSet.showReadable(k_SOCKET_B); + interestSet.showWritable(k_SOCKET_C); + interestSet.showReadable(k_SOCKET_D); + interestSet.showWritable(k_SOCKET_D); + + NTSCFG_TEST_LOG_DEBUG << "Interest set = " << interestSet + << NTSCFG_TEST_LOG_END; + + typedef bsl::vector InterestVector; + InterestVector interestVector(NTSCFG_TEST_ALLOCATOR); + + for (ntsa::InterestSet::const_iterator it = interestSet.cbegin(); + it != interestSet.cend(); + ++it) { - const ntsa::Handle k_SOCKET_A = 10; - const ntsa::Handle k_SOCKET_B = 100; - const ntsa::Handle k_SOCKET_C = 1000; - const ntsa::Handle k_SOCKET_D = 10000; + const ntsa::Interest& interest = *it; - ntsa::InterestSet interestSet(&ta); + NTSCFG_TEST_LOG_DEBUG << "Interest = " << *it << NTSCFG_TEST_LOG_END; - interestSet.attach(k_SOCKET_A); - interestSet.attach(k_SOCKET_B); - interestSet.attach(k_SOCKET_C); - interestSet.attach(k_SOCKET_D); + interestVector.push_back(interest); + } - interestSet.showReadable(k_SOCKET_B); - interestSet.showWritable(k_SOCKET_C); - interestSet.showReadable(k_SOCKET_D); - interestSet.showWritable(k_SOCKET_D); + NTSCFG_TEST_EQ(interestVector.size(), 4); - NTSCFG_TEST_LOG_DEBUG << "Interest set = " << interestSet - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_EQ(interestVector[0].handle(), k_SOCKET_A); + NTSCFG_TEST_TRUE(interestVector[0].wantNone()); - typedef bsl::vector InterestVector; - InterestVector interestVector(&ta); + NTSCFG_TEST_EQ(interestVector[1].handle(), k_SOCKET_B); + NTSCFG_TEST_TRUE(interestVector[1].wantReadable()); - for (ntsa::InterestSet::const_iterator it = interestSet.cbegin(); - it != interestSet.cend(); - ++it) - { - const ntsa::Interest& interest = *it; + NTSCFG_TEST_EQ(interestVector[2].handle(), k_SOCKET_C); + NTSCFG_TEST_TRUE(interestVector[2].wantWritable()); - NTSCFG_TEST_LOG_DEBUG << "Interest = " << *it - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_EQ(interestVector[3].handle(), k_SOCKET_D); + NTSCFG_TEST_TRUE(interestVector[3].wantBoth()); +} - interestVector.push_back(interest); - } +void InterestTest::ensureNotFound(const ntsa::InterestSet& interestSet, + ntsa::Handle socket) +{ + NTSCFG_TEST_FALSE(interestSet.contains(socket)); - NTSCFG_TEST_EQ(interestVector.size(), 4); + ntsa::Interest interest; + bool found = interestSet.find(&interest, socket); + NTSCFG_TEST_FALSE(found); +} - NTSCFG_TEST_EQ(interestVector[0].handle(), k_SOCKET_A); - NTSCFG_TEST_TRUE(interestVector[0].wantNone()); +void InterestTest::ensureWantNone(const ntsa::InterestSet& interestSet, + ntsa::Handle socket) +{ + NTSCFG_TEST_TRUE(interestSet.contains(socket)); - NTSCFG_TEST_EQ(interestVector[1].handle(), k_SOCKET_B); - NTSCFG_TEST_TRUE(interestVector[1].wantReadable()); + ntsa::Interest interest; + bool found = interestSet.find(&interest, socket); - NTSCFG_TEST_EQ(interestVector[2].handle(), k_SOCKET_C); - NTSCFG_TEST_TRUE(interestVector[2].wantWritable()); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_EQ(interest.handle(), socket); - NTSCFG_TEST_EQ(interestVector[3].handle(), k_SOCKET_D); - NTSCFG_TEST_TRUE(interestVector[3].wantBoth()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_FALSE(interest.wantReadable()); + NTSCFG_TEST_FALSE(interest.wantWritable()); + NTSCFG_TEST_FALSE(interest.wantAny()); + NTSCFG_TEST_FALSE(interest.wantBoth()); + NTSCFG_TEST_TRUE(interest.wantNone()); + + NTSCFG_TEST_FALSE(interestSet.wantReadable(socket)); + NTSCFG_TEST_FALSE(interestSet.wantWritable(socket)); + NTSCFG_TEST_FALSE(interestSet.wantAny(socket)); + NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); + NTSCFG_TEST_TRUE(interestSet.wantNone(socket)); } -NTSCFG_TEST_DRIVER +void InterestTest::ensureWantReadable(const ntsa::InterestSet& interestSet, + ntsa::Handle socket) { - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); + NTSCFG_TEST_TRUE(interestSet.contains(socket)); + + ntsa::Interest interest; + bool found = interestSet.find(&interest, socket); + + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_EQ(interest.handle(), socket); + + NTSCFG_TEST_TRUE(interest.wantReadable()); + NTSCFG_TEST_FALSE(interest.wantWritable()); + NTSCFG_TEST_TRUE(interest.wantAny()); + NTSCFG_TEST_FALSE(interest.wantBoth()); + NTSCFG_TEST_FALSE(interest.wantNone()); + + NTSCFG_TEST_TRUE(interestSet.wantReadable(socket)); + NTSCFG_TEST_FALSE(interestSet.wantWritable(socket)); + NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); + NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); + NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); } -NTSCFG_TEST_DRIVER_END; + +void InterestTest::ensureWantWritable(const ntsa::InterestSet& interestSet, + ntsa::Handle socket) +{ + NTSCFG_TEST_TRUE(interestSet.contains(socket)); + + ntsa::Interest interest; + bool found = interestSet.find(&interest, socket); + + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_EQ(interest.handle(), socket); + + NTSCFG_TEST_FALSE(interest.wantReadable()); + NTSCFG_TEST_TRUE(interest.wantWritable()); + NTSCFG_TEST_TRUE(interest.wantAny()); + NTSCFG_TEST_FALSE(interest.wantBoth()); + NTSCFG_TEST_FALSE(interest.wantNone()); + + NTSCFG_TEST_FALSE(interestSet.wantReadable(socket)); + NTSCFG_TEST_TRUE(interestSet.wantWritable(socket)); + NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); + NTSCFG_TEST_FALSE(interestSet.wantBoth(socket)); + NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); +} + +void InterestTest::ensureWantBoth(const ntsa::InterestSet& interestSet, + ntsa::Handle socket) +{ + NTSCFG_TEST_TRUE(interestSet.contains(socket)); + + ntsa::Interest interest; + bool found = interestSet.find(&interest, socket); + + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_EQ(interest.handle(), socket); + + NTSCFG_TEST_TRUE(interest.wantReadable()); + NTSCFG_TEST_TRUE(interest.wantWritable()); + NTSCFG_TEST_TRUE(interest.wantAny()); + NTSCFG_TEST_TRUE(interest.wantBoth()); + NTSCFG_TEST_FALSE(interest.wantNone()); + + NTSCFG_TEST_TRUE(interestSet.wantReadable(socket)); + NTSCFG_TEST_TRUE(interestSet.wantWritable(socket)); + NTSCFG_TEST_TRUE(interestSet.wantAny(socket)); + NTSCFG_TEST_TRUE(interestSet.wantBoth(socket)); + NTSCFG_TEST_FALSE(interestSet.wantNone(socket)); +} + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipaddress.t.cpp b/groups/nts/ntsa/ntsa_ipaddress.t.cpp index b17d9b95..8f6c93c4 100644 --- a/groups/nts/ntsa/ntsa_ipaddress.t.cpp +++ b/groups/nts/ntsa/ntsa_ipaddress.t.cpp @@ -13,47 +13,53 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_ipaddress_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::IpAddress'. +class IpAddressTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTest::verifyCase1) +{ ntsa::IpAddress ipAddress("127.0.0.1"); NTSCFG_TEST_TRUE(ipAddress.isV4()); NTSCFG_TEST_EQ(ipAddress.v4(), ntsa::Ipv4Address::loopback()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTest::verifyCase2) { - // Concern: - // Plan: - ntsa::IpAddress ipAddress("::1"); NTSCFG_TEST_TRUE(ipAddress.isV6()); NTSCFG_TEST_EQ(ipAddress.v6(), ntsa::Ipv6Address::loopback()); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTest::verifyCase3) { ntsa::IpAddress ipAddress("123.45.67.89"); @@ -62,7 +68,7 @@ NTSCFG_TEST_CASE(3) NTSCFG_TEST_TRUE(ipAddress.isUndefined()); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTest::verifyCase4) { ntsa::IpAddress ipAddress; @@ -73,7 +79,7 @@ NTSCFG_TEST_CASE(4) NTSCFG_TEST_EQ(ipAddress.v4(), ntsa::Ipv4Address(ipv4)); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTest::verifyCase5) { ntsa::IpAddress ipAddress; @@ -84,12 +90,5 @@ NTSCFG_TEST_CASE(5) NTSCFG_TEST_EQ(ipAddress.v6(), ntsa::Ipv6Address(ipv6)); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipaddresstype.t.cpp b/groups/nts/ntsa/ntsa_ipaddresstype.t.cpp index 7d98843a..7d2c3b1f 100644 --- a/groups/nts/ntsa/ntsa_ipaddresstype.t.cpp +++ b/groups/nts/ntsa/ntsa_ipaddresstype.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_ipaddresstype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::IpAddressType'. +class IpAddressTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::IpAddressTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipendpoint.cpp b/groups/nts/ntsa/ntsa_ipendpoint.cpp index 6900f8b9..f30b92e1 100644 --- a/groups/nts/ntsa/ntsa_ipendpoint.cpp +++ b/groups/nts/ntsa/ntsa_ipendpoint.cpp @@ -332,7 +332,7 @@ bool operator<(const IpEndpoint& lhs, const IpEndpoint& rhs) const bdlat_AttributeInfo* IpEndpoint::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -342,17 +342,16 @@ const bdlat_AttributeInfo* IpEndpoint::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* IpEndpoint::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* IpEndpoint::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; diff --git a/groups/nts/ntsa/ntsa_ipendpoint.h b/groups/nts/ntsa/ntsa_ipendpoint.h index c93c8baa..a8476bbb 100644 --- a/groups/nts/ntsa/ntsa_ipendpoint.h +++ b/groups/nts/ntsa/ntsa_ipendpoint.h @@ -23,10 +23,10 @@ BSLS_IDENT("$Id: $") #include #include #include -#include -#include #include #include +#include +#include #include #include #include @@ -67,10 +67,7 @@ namespace ntsa { /// @ingroup module_ntsa_identity class IpEndpoint { - enum { - e_ATTRIBUTE_ID_HOST = 0, - e_ATTRIBUTE_ID_PORT = 1 - }; + enum { e_ATTRIBUTE_ID_HOST = 0, e_ATTRIBUTE_ID_PORT = 1 }; ntsa::IpAddress d_host; ntsa::Port d_port; @@ -189,59 +186,59 @@ class IpEndpoint int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; /// Return the IPv4 address that represents any address. @@ -268,20 +265,20 @@ class IpEndpoint /// Return the port number that represents any port. static ntsa::Port anyPort(); - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[17]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[2]; /// Defines the traits of this type. These traits can be used to select, @@ -486,11 +483,11 @@ int IpEndpoint::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int IpEndpoint::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, - int nameLength) +int IpEndpoint::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, + int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::IpEndpoint::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -524,7 +521,7 @@ int IpEndpoint::accessAttribute(ACCESSOR& accessor, int id) const if (id == e_ATTRIBUTE_ID_HOST) { bsl::string host = d_host.text(); - rc = accessor(host, ATTRIBUTE_INFO_ARRAY[id]); + rc = accessor(host, ATTRIBUTE_INFO_ARRAY[id]); if (rc != 0) { return rc; } @@ -548,11 +545,11 @@ int IpEndpoint::accessAttribute(ACCESSOR& accessor, int id) const } template -int IpEndpoint::accessAttribute(ACCESSOR& accessor, - const char* name, - int nameLength) const +int IpEndpoint::accessAttribute(ACCESSOR& accessor, + const char* name, + int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::IpEndpoint::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; diff --git a/groups/nts/ntsa/ntsa_ipendpoint.t.cpp b/groups/nts/ntsa/ntsa_ipendpoint.t.cpp index 8dc5f9cf..99c71ba4 100644 --- a/groups/nts/ntsa/ntsa_ipendpoint.t.cpp +++ b/groups/nts/ntsa/ntsa_ipendpoint.t.cpp @@ -13,37 +13,42 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include + +#include +BSLS_IDENT_RCSID(ntsa_ipendpoint_t_cpp, "$Id$ $CSID$") + +#include + #include #include #include #include -#include -#include -#include using namespace BloombergLP; -using namespace ntsa; - -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::IpEndpoint'. +class IpEndpointTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::IpEndpointTest::verifyCase1) +{ ntsa::IpEndpoint ipEndpoint("127.0.0.1:12345"); NTSCFG_TEST_TRUE(ipEndpoint.host().isV4()); @@ -51,11 +56,8 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(ipEndpoint.port(), 12345); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::IpEndpointTest::verifyCase2) { - // Concern: - // Plan: - ntsa::IpEndpoint ipEndpoint("[::1]:12345"); NTSCFG_TEST_TRUE(ipEndpoint.host().isV6()); @@ -63,113 +65,99 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_EQ(ipEndpoint.port(), 12345); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::IpEndpointTest::verifyCase3) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::IpEndpoint e1("10.26.55.100:12345"); - ntsa::IpEndpoint e2; + ntsa::IpEndpoint e1("10.26.55.100:12345"); + ntsa::IpEndpoint e2; - bdlsb::MemOutStreamBuf osb(&ta); + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - balber::BerEncoder encoder(0, &ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerEncoder encoder(0, NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" - << bdlb::PrintStringHexDumper( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" + << bdlb::PrintStringHexDumper( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - balber::BerDecoder decoder(0, &ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerDecoder decoder(0, NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2, e1); + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); + + NTSCFG_TEST_EQ(e2, e1); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::IpEndpointTest::verifyCase4) { int rc; - ntscfg::TestAllocator ta; - { - bsl::vector e1(&ta); - bsl::vector e2(&ta); + bsl::vector e1(NTSCFG_TEST_ALLOCATOR); + bsl::vector e2(NTSCFG_TEST_ALLOCATOR); - e1.push_back(ntsa::IpEndpoint("10.26.55.100:12345")); + e1.push_back(ntsa::IpEndpoint("10.26.55.100:12345")); - bdlsb::MemOutStreamBuf osb(&ta); + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - baljsn::Encoder encoder(&ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Encoder encoder(NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded: " - << bsl::string_view( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded: " + << bsl::string_view( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - baljsn::Decoder decoder(&ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Decoder decoder(NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2.size(), e1.size()); + NTSCFG_TEST_EQ(rc, 0); + } - for (bsl::size_t i = 0; i < e1.size(); ++i) { - NTSCFG_TEST_EQ(e2[i], e1[i]); - } + NTSCFG_TEST_EQ(e2.size(), e1.size()); + + for (bsl::size_t i = 0; i < e1.size(); ++i) { + NTSCFG_TEST_EQ(e2[i], e1[i]); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipv4address.cpp b/groups/nts/ntsa/ntsa_ipv4address.cpp index 119d1906..fbad1569 100644 --- a/groups/nts/ntsa/ntsa_ipv4address.cpp +++ b/groups/nts/ntsa/ntsa_ipv4address.cpp @@ -25,7 +25,6 @@ BSLS_IDENT_RCSID(ntsa_ipv4address_cpp, "$Id$ $CSID$") #include #include - namespace BloombergLP { namespace ntsa { @@ -126,15 +125,15 @@ bool Ipv4Address::parse(const bslstl::StringRef& text) NTSCFG_NOEXCEPT } bsl::uint64_t numOctetsLeft = 4 - index; - if (numAtIndex >= bsl::pow(256,numOctetsLeft)) { + if (numAtIndex >= bsl::pow(256, numOctetsLeft)) { return false; } for (size_t oct = 0; oct < numOctetsLeft; ++oct) { - bsl::uint8_t octet = NTSCFG_WARNING_NARROW(bsl::uint8_t, - numAtIndex % 256); - newValue.d_asBytes[3 - oct] = octet; - numAtIndex /= 256; + bsl::uint8_t octet = + NTSCFG_WARNING_NARROW(bsl::uint8_t, numAtIndex % 256); + newValue.d_asBytes[3 - oct] = octet; + numAtIndex /= 256; } d_value.d_asDword = newValue.d_asDword; diff --git a/groups/nts/ntsa/ntsa_ipv4address.h b/groups/nts/ntsa/ntsa_ipv4address.h index 0bcacdee..4d0a5f93 100644 --- a/groups/nts/ntsa/ntsa_ipv4address.h +++ b/groups/nts/ntsa/ntsa_ipv4address.h @@ -228,13 +228,15 @@ bsl::ostream& operator<<(bsl::ostream& stream, const Ipv4Address& object); /// 'rhs', otherwise return false. /// /// @related ntsa::Ipv4Address -bool operator==(const Ipv4Address& lhs, const Ipv4Address& rhs) NTSCFG_NOEXCEPT; +bool operator==(const Ipv4Address& lhs, + const Ipv4Address& rhs) NTSCFG_NOEXCEPT; /// Return true if the specified 'lhs' does not have the same value as the /// specified 'rhs', otherwise return false. /// /// @related ntsa::Ipv4Address -bool operator!=(const Ipv4Address& lhs, const Ipv4Address& rhs) NTSCFG_NOEXCEPT; +bool operator!=(const Ipv4Address& lhs, + const Ipv4Address& rhs) NTSCFG_NOEXCEPT; /// Return true if the specified 'lhs' is "less than" the specified 'rhs', /// otherwise return false. diff --git a/groups/nts/ntsa/ntsa_ipv4address.t.cpp b/groups/nts/ntsa/ntsa_ipv4address.t.cpp index 32f494b3..bcdb8800 100644 --- a/groups/nts/ntsa/ntsa_ipv4address.t.cpp +++ b/groups/nts/ntsa/ntsa_ipv4address.t.cpp @@ -13,17 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include BSLS_IDENT_RCSID(ntsa_ipv4address_t_cpp, "$Id$ $CSID$") -#include -#include -#include -#include -#include -#include +#include using namespace BloombergLP; @@ -78,7 +73,7 @@ class Ipv4AddressTest static void verifyLoopback(); }; -void Ipv4AddressTest::verifyTypeTraits() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyTypeTraits) { const bool isBitwiseInitializable = NTSCFG_TYPE_CHECK_BITWISE_INITIALIZABLE(ntsa::Ipv4Address); @@ -101,7 +96,7 @@ void Ipv4AddressTest::verifyTypeTraits() NTSCFG_TEST_TRUE(isBitwiseComparable); } -void Ipv4AddressTest::verifyDefaultConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyDefaultConstructor) { ntsa::Ipv4Address u; @@ -111,7 +106,7 @@ void Ipv4AddressTest::verifyDefaultConstructor() NTSCFG_TEST_EQ(u[3], 0); } -void Ipv4AddressTest::verifyMoveConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyMoveConstructor) { ntsa::Ipv4Address u("1.2.3.4"); @@ -135,7 +130,7 @@ void Ipv4AddressTest::verifyMoveConstructor() #endif } -void Ipv4AddressTest::verifyCopyConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyCopyConstructor) { ntsa::Ipv4Address u("1.2.3.4"); @@ -152,7 +147,7 @@ void Ipv4AddressTest::verifyCopyConstructor() NTSCFG_TEST_EQ(v[3], 4); } -void Ipv4AddressTest::verifyOverloadConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyOverloadConstructor) { { bsl::uint32_t value = 0; @@ -180,7 +175,7 @@ void Ipv4AddressTest::verifyOverloadConstructor() } } -void Ipv4AddressTest::verifyCopyAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyCopyAssignment) { ntsa::Ipv4Address u("1.2.3.4"); @@ -204,7 +199,7 @@ void Ipv4AddressTest::verifyCopyAssignment() NTSCFG_TEST_EQ(v[3], 4); } -void Ipv4AddressTest::verifyMoveAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyMoveAssignment) { ntsa::Ipv4Address u("1.2.3.4"); @@ -235,7 +230,7 @@ void Ipv4AddressTest::verifyMoveAssignment() #endif } -void Ipv4AddressTest::verifyOverloadAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyOverloadAssignment) { ntsa::Ipv4Address u; @@ -252,7 +247,7 @@ void Ipv4AddressTest::verifyOverloadAssignment() NTSCFG_TEST_EQ(u[3], 4); } -void Ipv4AddressTest::verifyReset() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyReset) { ntsa::Ipv4Address u("1.2.3.4"); @@ -269,7 +264,7 @@ void Ipv4AddressTest::verifyReset() NTSCFG_TEST_EQ(u[3], 0); } -void Ipv4AddressTest::verifyParsing() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyParsing) { // Microsoft Visual Studio 2013 does not compile the array literal // initialization. @@ -344,7 +339,7 @@ void Ipv4AddressTest::verifyParsing() #endif } -void Ipv4AddressTest::verifyGeneration() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyGeneration) { // Microsoft Visual Studio 2013 does not compile the array literal // initialization. @@ -385,7 +380,7 @@ void Ipv4AddressTest::verifyGeneration() #endif } -void Ipv4AddressTest::verifyHashing() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyHashing) { ntsa::Ipv4Address address1("127.0.0.1"); ntsa::Ipv4Address address2("196.168.0.1"); @@ -397,7 +392,7 @@ void Ipv4AddressTest::verifyHashing() NTSCFG_TEST_EQ(addressSet.size(), 2); } -void Ipv4AddressTest::verifyComparison() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyComparison) { ntsa::Ipv4Address address1("10.0.0.11"); ntsa::Ipv4Address address2("11.0.0.10"); @@ -405,7 +400,7 @@ void Ipv4AddressTest::verifyComparison() NTSCFG_TEST_LT(address1, address2); } -void Ipv4AddressTest::verifyLoopback() +NTSCFG_TEST_FUNCTION(ntsa::Ipv4AddressTest::verifyLoopback) { ntsa::Ipv4Address address1("127.0.0.1"); ntsa::Ipv4Address address2 = ntsa::Ipv4Address::loopback(); @@ -423,22 +418,3 @@ void Ipv4AddressTest::verifyLoopback() } // close namespace ntsa } // close namespace BloombergLP - -NTSCFG_TEST_SUITE -{ - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyTypeTraits); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyDefaultConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyMoveConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyCopyConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyOverloadConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyCopyAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyMoveAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyOverloadAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyReset); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyParsing); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyGeneration); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyHashing); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyComparison); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv4AddressTest::verifyLoopback); -} -NTSCFG_TEST_SUITE_END; diff --git a/groups/nts/ntsa/ntsa_ipv4endpoint.t.cpp b/groups/nts/ntsa/ntsa_ipv4endpoint.t.cpp index daedc606..b6804884 100644 --- a/groups/nts/ntsa/ntsa_ipv4endpoint.t.cpp +++ b/groups/nts/ntsa/ntsa_ipv4endpoint.t.cpp @@ -13,39 +13,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_ipv4endpoint_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Ipv4Endpoint'. +class Ipv4EndpointTest { - // Concern: - // Plan: + public: + // TODO + static void verify(); +}; +NTSCFG_TEST_FUNCTION(ntsa::Ipv4EndpointTest::verify) +{ ntsa::Ipv4Endpoint ipv4Endpoint("127.0.0.1:12345"); NTSCFG_TEST_EQ(ipv4Endpoint.host(), ntsa::Ipv4Address::loopback()); NTSCFG_TEST_EQ(ipv4Endpoint.port(), 12345); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipv6address.t.cpp b/groups/nts/ntsa/ntsa_ipv6address.t.cpp index e6ce15e2..4271e8eb 100644 --- a/groups/nts/ntsa/ntsa_ipv6address.t.cpp +++ b/groups/nts/ntsa/ntsa_ipv6address.t.cpp @@ -13,17 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include BSLS_IDENT_RCSID(ntsa_ipv6address_t_cpp, "$Id$ $CSID$") -#include -#include -#include -#include -#include -#include +#include using namespace BloombergLP; @@ -81,7 +76,7 @@ class Ipv6AddressTest static void verifyComparison(); }; -void Ipv6AddressTest::verifyTypeTraits() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyTypeTraits) { const bool isBitwiseInitializable = NTSCFG_TYPE_CHECK_BITWISE_INITIALIZABLE(ntsa::Ipv6Address); @@ -104,7 +99,7 @@ void Ipv6AddressTest::verifyTypeTraits() NTSCFG_TEST_TRUE(isBitwiseComparable); } -void Ipv6AddressTest::verifyDefaultConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyDefaultConstructor) { ntsa::Ipv6Address u; @@ -113,7 +108,7 @@ void Ipv6AddressTest::verifyDefaultConstructor() NTSCFG_TEST_EQ(u.scopeId(), 0); } -void Ipv6AddressTest::verifyMoveConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyMoveConstructor) { ntsa::Ipv6Address u("2606:2800:220:1:248:1893:25c8:1946%123"); @@ -162,7 +157,7 @@ void Ipv6AddressTest::verifyMoveConstructor() #endif } -void Ipv6AddressTest::verifyCopyConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyCopyConstructor) { ntsa::Ipv6Address u("2606:2800:220:1:248:1893:25c8:1946%123"); @@ -205,11 +200,11 @@ void Ipv6AddressTest::verifyCopyConstructor() NTSCFG_TEST_EQ(v[0x0F], 0x46); } -void Ipv6AddressTest::verifyOverloadConstructor() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyOverloadConstructor) { } -void Ipv6AddressTest::verifyCopyAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyCopyAssignment) { ntsa::Ipv6Address u("2606:2800:220:1:248:1893:25c8:1946%123"); @@ -253,7 +248,7 @@ void Ipv6AddressTest::verifyCopyAssignment() NTSCFG_TEST_EQ(v[0x0F], 0x46); } -void Ipv6AddressTest::verifyMoveAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyMoveAssignment) { ntsa::Ipv6Address u("2606:2800:220:1:248:1893:25c8:1946%123"); @@ -303,11 +298,11 @@ void Ipv6AddressTest::verifyMoveAssignment() #endif } -void Ipv6AddressTest::verifyOverloadAssignment() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyOverloadAssignment) { } -void Ipv6AddressTest::verifyReset() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyReset) { ntsa::Ipv6Address u("2606:2800:220:1:248:1893:25c8:1946%123"); @@ -337,7 +332,7 @@ void Ipv6AddressTest::verifyReset() NTSCFG_TEST_EQ(u.scopeId(), 0); } -void Ipv6AddressTest::verifyFormatting() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyFormatting) { // a @@ -1136,7 +1131,7 @@ void Ipv6AddressTest::verifyFormatting() } } -void Ipv6AddressTest::verifyParsing() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyParsing) { // Microsoft Visual Studio 2013 does not compile the array literal // initialization. @@ -1347,7 +1342,7 @@ void Ipv6AddressTest::verifyParsing() #endif } -void Ipv6AddressTest::verifyParsingScopeId() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyParsingScopeId) { { ntsa::Ipv6Address address; @@ -1382,7 +1377,7 @@ void Ipv6AddressTest::verifyParsingScopeId() } } -void Ipv6AddressTest::verifyParsingAbbreviation() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyParsingAbbreviation) { { bslstl::StringRef INPUT("1:2:3:4:5:6:7:8"); @@ -1480,7 +1475,7 @@ void Ipv6AddressTest::verifyParsingAbbreviation() } } -void Ipv6AddressTest::verifyHashing() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyHashing) { ntsa::Ipv6Address address1("2606:2800:220:1:248:1893:25c8:1946"); ntsa::Ipv6Address address2("2001:41c0::1"); @@ -1492,29 +1487,9 @@ void Ipv6AddressTest::verifyHashing() NTSCFG_TEST_ASSERT(addressSet.size() == 2); } -void Ipv6AddressTest::verifyComparison() +NTSCFG_TEST_FUNCTION(ntsa::Ipv6AddressTest::verifyComparison) { } } // close namespace ntsa } // close namespace BloombergLP - -NTSCFG_TEST_SUITE -{ - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyTypeTraits); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyDefaultConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyMoveConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyCopyConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyOverloadConstructor); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyCopyAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyMoveAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyOverloadAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyReset); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyFormatting); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyParsing); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyParsingScopeId); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyParsingAbbreviation); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyHashing); - NTSCFG_TEST_FUNCTION(&ntsa::Ipv6AddressTest::verifyComparison); -} -NTSCFG_TEST_SUITE_END; diff --git a/groups/nts/ntsa/ntsa_ipv6endpoint.t.cpp b/groups/nts/ntsa/ntsa_ipv6endpoint.t.cpp index 33eebed8..d24bcee8 100644 --- a/groups/nts/ntsa/ntsa_ipv6endpoint.t.cpp +++ b/groups/nts/ntsa/ntsa_ipv6endpoint.t.cpp @@ -13,39 +13,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_ipv6endpoint_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Ipv6Endpoint'. +class Ipv6EndpointTest { - // Concern: - // Plan: + public: + // TODO + static void verify(); +}; +NTSCFG_TEST_FUNCTION(ntsa::Ipv6EndpointTest::verify) +{ ntsa::Ipv6Endpoint ipv6Endpoint("[::1]:12345"); NTSCFG_TEST_EQ(ipv6Endpoint.host(), ntsa::Ipv6Address::loopback()); NTSCFG_TEST_EQ(ipv6Endpoint.port(), 12345); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_ipv6scopeid.t.cpp b/groups/nts/ntsa/ntsa_ipv6scopeid.t.cpp index 34e4ca6c..455119d2 100644 --- a/groups/nts/ntsa/ntsa_ipv6scopeid.t.cpp +++ b/groups/nts/ntsa/ntsa_ipv6scopeid.t.cpp @@ -13,103 +13,89 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_ipv6scopeid_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Ipv6ScopeId'. +class Ipv6ScopeIdTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); - ntscfg::TestAllocator ta; - { - struct Data { - const char* d_text; - bsl::uint16_t d_value; - bool d_success; - } DATA[] = { - { "0", 0, true}, - { "1", 1, true}, - { "12", 12, true}, - { "123", 123, true}, - {"28588", 28588, true}, - {"65535", 65535, true}, - { "-1", 0, false}, - {"65536", 0, false} - }; + // TODO + static void verifyCase2(); +}; - enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; +NTSCFG_TEST_FUNCTION(ntsa::Ipv6ScopeIdTest::verifyCase1) +{ + struct Data { + const char* d_text; + bsl::uint16_t d_value; + bool d_success; + } DATA[] = { + { "0", 0, true}, + { "1", 1, true}, + { "12", 12, true}, + { "123", 123, true}, + {"28588", 28588, true}, + {"65535", 65535, true}, + { "-1", 0, false}, + {"65536", 0, false} + }; - for (bsl::size_t i = 0; i < NUM_DATA; ++i) { - ntsa::Ipv6ScopeId scopeId; - bool result = - ntsa::Ipv6ScopeIdUtil::parse(&scopeId, - DATA[i].d_text, - bsl::strlen(DATA[i].d_text)); - if (DATA[i].d_success) { - NTSCFG_TEST_TRUE(result); - NTSCFG_TEST_EQ(scopeId, DATA[i].d_value); - } - else { - NTSCFG_TEST_FALSE(result); - } + enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; + + for (bsl::size_t i = 0; i < NUM_DATA; ++i) { + ntsa::Ipv6ScopeId scopeId; + bool result = + ntsa::Ipv6ScopeIdUtil::parse(&scopeId, + DATA[i].d_text, + bsl::strlen(DATA[i].d_text)); + if (DATA[i].d_success) { + NTSCFG_TEST_TRUE(result); + NTSCFG_TEST_EQ(scopeId, DATA[i].d_value); + } + else { + NTSCFG_TEST_FALSE(result); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::Ipv6ScopeIdTest::verifyCase2) { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - struct Data { - bsl::uint16_t d_value; - const char* d_text; - } DATA[] = { - { 0, "0"}, - { 1, "1"}, - { 12, "12"}, - { 123, "123"}, - {28588, "28588"}, - {65535, "65535"} - }; + struct Data { + bsl::uint16_t d_value; + const char* d_text; + } DATA[] = { + { 0, "0"}, + { 1, "1"}, + { 12, "12"}, + { 123, "123"}, + {28588, "28588"}, + {65535, "65535"} + }; - enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; + enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; - for (bsl::size_t i = 0; i < NUM_DATA; ++i) { - char buffer[ntsa::Ipv6ScopeIdUtil::MAX_LENGTH + 1]; - bsl::size_t size = ntsa::Ipv6ScopeIdUtil::format(buffer, - sizeof buffer, - DATA[i].d_value); - NTSCFG_TEST_EQ(size, bsl::strlen(buffer)); - NTSCFG_TEST_EQ(0, bsl::strcmp(buffer, DATA[i].d_text)); - } + for (bsl::size_t i = 0; i < NUM_DATA; ++i) { + char buffer[ntsa::Ipv6ScopeIdUtil::MAX_LENGTH + 1]; + bsl::size_t size = ntsa::Ipv6ScopeIdUtil::format(buffer, + sizeof buffer, + DATA[i].d_value); + NTSCFG_TEST_EQ(size, bsl::strlen(buffer)); + NTSCFG_TEST_EQ(0, bsl::strcmp(buffer, DATA[i].d_text)); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_linger.t.cpp b/groups/nts/ntsa/ntsa_linger.t.cpp index 8dcd9b4f..9313753b 100644 --- a/groups/nts/ntsa/ntsa_linger.t.cpp +++ b/groups/nts/ntsa/ntsa_linger.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_linger_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Linger'. +class LingerTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::LingerTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_localname.cpp b/groups/nts/ntsa/ntsa_localname.cpp index 05f3ccef..c521efa0 100644 --- a/groups/nts/ntsa/ntsa_localname.cpp +++ b/groups/nts/ntsa/ntsa_localname.cpp @@ -277,7 +277,7 @@ ntsa::Error LocalName::generateUnique(ntsa::LocalName* name) const bdlat_AttributeInfo* LocalName::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -287,17 +287,16 @@ const bdlat_AttributeInfo* LocalName::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* LocalName::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* LocalName::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; diff --git a/groups/nts/ntsa/ntsa_localname.h b/groups/nts/ntsa/ntsa_localname.h index 5fceb816..26410e7a 100644 --- a/groups/nts/ntsa/ntsa_localname.h +++ b/groups/nts/ntsa/ntsa_localname.h @@ -22,10 +22,10 @@ BSLS_IDENT("$Id: $") #include #include #include -#include -#include #include #include +#include +#include #include #include #include @@ -62,10 +62,7 @@ class LocalName #endif private: - enum { - e_ATTRIBUTE_ID_PATH = 0, - e_ATTRIBUTE_ID_ABSTRACT = 1 - }; + enum { e_ATTRIBUTE_ID_PATH = 0, e_ATTRIBUTE_ID_ABSTRACT = 1 }; char d_path[k_MAX_PATH_LENGTH]; bsl::uint8_t d_size; @@ -159,59 +156,59 @@ class LocalName int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; /// Generate a unique local name. The name will be abstract if the @@ -225,20 +222,20 @@ class LocalName /// TMP directory is longer than sockaddr_un can store) static ntsa::Error generateUnique(ntsa::LocalName* name); - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[16]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[2]; /// Defines the traits of this type. These traits can be used to select, @@ -359,11 +356,11 @@ int LocalName::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int LocalName::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, +int LocalName::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::LocalName::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -397,7 +394,7 @@ int LocalName::accessAttribute(ACCESSOR& accessor, int id) const if (id == e_ATTRIBUTE_ID_PATH) { bsl::string path = this->value(); - rc = accessor(path, ATTRIBUTE_INFO_ARRAY[id]); + rc = accessor(path, ATTRIBUTE_INFO_ARRAY[id]); if (rc != 0) { return rc; } @@ -421,11 +418,11 @@ int LocalName::accessAttribute(ACCESSOR& accessor, int id) const } template -int LocalName::accessAttribute(ACCESSOR& accessor, - const char* name, +int LocalName::accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::LocalName::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; diff --git a/groups/nts/ntsa/ntsa_localname.t.cpp b/groups/nts/ntsa/ntsa_localname.t.cpp index 84792337..346e2c73 100644 --- a/groups/nts/ntsa/ntsa_localname.t.cpp +++ b/groups/nts/ntsa/ntsa_localname.t.cpp @@ -13,37 +13,54 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include + +#include +BSLS_IDENT_RCSID(ntsa_localname_t_cpp, "$Id$ $CSID$") + +#include + #include #include #include #include -#include -#include -#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { #if NTSCFG_BUILD_WITH_ADDRESS_FAMILY_LOCAL -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::LocalName'. +class LocalNameTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); + + // TODO + static void verifyCase6(); + + // TODO + static void verifyCase7(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase1) { // Concern: Local name explicitly set to an absolute path. - // Plan: { ntsa::LocalName localName; @@ -113,7 +130,7 @@ NTSCFG_TEST_CASE(1) #endif } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase2) { // Concern: Local name explicitly set to an absolute path. // Plan: @@ -212,7 +229,7 @@ NTSCFG_TEST_CASE(2) #endif } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase3) { // Concern: Local name generated from a unique GUID. // Plan: @@ -237,7 +254,7 @@ NTSCFG_TEST_CASE(3) } } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase4) { // Concern: Try to set explicitly value which is longer than can be stored // Plan: @@ -255,8 +272,7 @@ NTSCFG_TEST_CASE(4) { ntsa::LocalName localName; NTSCFG_TEST_OK(localName.setAbstract()); - NTSCFG_TEST_ERROR(localName.setValue(ss.str()), - ntsa::Error::e_LIMIT); + NTSCFG_TEST_ERROR(localName.setValue(ss.str()), ntsa::Error::e_LIMIT); } { ntsa::LocalName localName; @@ -267,8 +283,7 @@ NTSCFG_TEST_CASE(4) { ntsa::LocalName localName; NTSCFG_TEST_OK(localName.setValue(ss.str())); - NTSCFG_TEST_ERROR(localName.setAbstract(), - ntsa::Error::e_LIMIT); + NTSCFG_TEST_ERROR(localName.setAbstract(), ntsa::Error::e_LIMIT); } #endif @@ -287,7 +302,7 @@ NTSCFG_TEST_CASE(4) } } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase5) { // Concern: Test generateUniqueName fails if generated path is long enough // Notes: @@ -368,135 +383,106 @@ NTSCFG_TEST_CASE(5) } } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase6) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::LocalName e1; - e1.setValue("/tmp/ntf/test"); - - ntsa::LocalName e2; + ntsa::LocalName e1; + e1.setValue("/tmp/ntf/test"); - bdlsb::MemOutStreamBuf osb(&ta); + ntsa::LocalName e2; - balber::BerEncoder encoder(0, &ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerEncoder encoder(0, NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" - << bdlb::PrintStringHexDumper( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" + << bdlb::PrintStringHexDumper( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - balber::BerDecoder decoder(0, &ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerDecoder decoder(0, NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2, e1); + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); + + NTSCFG_TEST_EQ(e2, e1); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsa::LocalNameTest::verifyCase7) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::LocalName localName; - localName.setValue("/tmp/ntf/test"); - - bsl::vector e1(&ta); - bsl::vector e2(&ta); + ntsa::LocalName localName; + localName.setValue("/tmp/ntf/test"); - e1.push_back(localName); + bsl::vector e1(NTSCFG_TEST_ALLOCATOR); + bsl::vector e2(NTSCFG_TEST_ALLOCATOR); - bdlsb::MemOutStreamBuf osb(&ta); + e1.push_back(localName); - baljsn::Encoder encoder(&ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Encoder encoder(NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded: " - << bsl::string_view( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded: " + << bsl::string_view( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - baljsn::Decoder decoder(&ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } - - NTSCFG_TEST_EQ(e2.size(), e1.size()); + baljsn::Decoder decoder(NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - for (bsl::size_t i = 0; i < e1.size(); ++i) { - NTSCFG_TEST_EQ(e2[i], e1[i]); - } + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); -} -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); -} -NTSCFG_TEST_DRIVER_END; - -#else + NTSCFG_TEST_EQ(e2.size(), e1.size()); -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); + for (bsl::size_t i = 0; i < e1.size(); ++i) { + NTSCFG_TEST_EQ(e2[i], e1[i]); + } } -NTSCFG_TEST_DRIVER_END; #endif + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_message.t.cpp b/groups/nts/ntsa/ntsa_message.t.cpp index 254cdb7d..252567aa 100644 --- a/groups/nts/ntsa/ntsa_message.t.cpp +++ b/groups/nts/ntsa/ntsa_message.t.cpp @@ -13,56 +13,39 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -#include -#include -#include -#include - -using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include +BSLS_IDENT_RCSID(ntsa_message_t_cpp, "$Id$ $CSID$") -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +#include -namespace test { +using namespace BloombergLP; -const char s_buffer[1] = {0}; +namespace BloombergLP { +namespace ntsa { -const void* constBufferData(bsl::size_t bufferIndex) +// Provide tests for 'ntsa::Message'. +class MessageTest { - return &s_buffer[0] + bufferIndex; -} + public: + // TODO + static void verifyCase1(); -bsl::size_t constBufferSize(bsl::size_t bufferIndex) -{ - return 10 * bufferIndex; -} + // TODO + static void verifyCase2(); -void* mutableBufferData(bsl::size_t bufferIndex) -{ - return const_cast(&s_buffer[0]) + bufferIndex; -} + private: + static const char s_buffer[1]; -bsl::size_t mutableBufferSize(bsl::size_t bufferIndex) -{ - return 100 * bufferIndex; -} + static const void* constBufferData(bsl::size_t bufferIndex); + static bsl::size_t constBufferSize(bsl::size_t bufferIndex); -} // close namespace 'test' + static void* mutableBufferData(bsl::size_t bufferIndex); + static bsl::size_t mutableBufferSize(bsl::size_t bufferIndex); +}; -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsa::MessageTest::verifyCase1) { // Concern: The semantics of 'ntsa::ConstMessage' are correct. // Plan: @@ -70,63 +53,54 @@ NTSCFG_TEST_CASE(1) const bsl::size_t MAX_RESET_ITERATION = 2; const bsl::size_t MAX_BUFFER_INDEX = 64; - ntscfg::TestAllocator ta; - { - ntsa::ConstMessage constMessage(&ta); - - for (bsl::size_t resetIteration = 0; resetIteration < 2; - ++resetIteration) - { - NTSCFG_TEST_EQ(constMessage.endpoint(), ntsa::Endpoint()); - NTSCFG_TEST_EQ(constMessage.numBuffers(), 0); - NTSCFG_TEST_EQ(constMessage.size(), 0); - NTSCFG_TEST_EQ(constMessage.capacity(), 0); - - bsl::vector constBufferArray; + ntsa::ConstMessage constMessage(NTSCFG_TEST_ALLOCATOR); - for (bsl::size_t bufferIndex = 0; bufferIndex < MAX_BUFFER_INDEX; - ++bufferIndex) - { - ntsa::ConstBuffer constBuffer( - test::constBufferData(bufferIndex), - test::constBufferSize(bufferIndex)); + for (bsl::size_t resetIteration = 0; resetIteration < 2; ++resetIteration) + { + NTSCFG_TEST_EQ(constMessage.endpoint(), ntsa::Endpoint()); + NTSCFG_TEST_EQ(constMessage.numBuffers(), 0); + NTSCFG_TEST_EQ(constMessage.size(), 0); + NTSCFG_TEST_EQ(constMessage.capacity(), 0); - constMessage.appendBuffer(constBuffer); - constBufferArray.push_back(constBuffer); + bsl::vector constBufferArray; - bsl::size_t expectedNumBuffers = bufferIndex + 1; + for (bsl::size_t bufferIndex = 0; bufferIndex < MAX_BUFFER_INDEX; + ++bufferIndex) + { + ntsa::ConstBuffer constBuffer(constBufferData(bufferIndex), + constBufferSize(bufferIndex)); - NTSCFG_TEST_EQ(constMessage.numBuffers(), expectedNumBuffers); + constMessage.appendBuffer(constBuffer); + constBufferArray.push_back(constBuffer); - bsl::size_t expectedCapacity = 0; - for (bsl::size_t existingBufferIndex = 0; - existingBufferIndex <= bufferIndex; - ++existingBufferIndex) - { - NTSCFG_TEST_EQ( - constMessage.buffer(existingBufferIndex).data(), - constBufferArray[existingBufferIndex].data()); - NTSCFG_TEST_EQ( - constMessage.buffer(existingBufferIndex).size(), - constBufferArray[existingBufferIndex].size()); + bsl::size_t expectedNumBuffers = bufferIndex + 1; - expectedCapacity += - test::constBufferSize(existingBufferIndex); - } + NTSCFG_TEST_EQ(constMessage.numBuffers(), expectedNumBuffers); - bsl::size_t expectedSize = expectedCapacity; + bsl::size_t expectedCapacity = 0; + for (bsl::size_t existingBufferIndex = 0; + existingBufferIndex <= bufferIndex; + ++existingBufferIndex) + { + NTSCFG_TEST_EQ(constMessage.buffer(existingBufferIndex).data(), + constBufferArray[existingBufferIndex].data()); + NTSCFG_TEST_EQ(constMessage.buffer(existingBufferIndex).size(), + constBufferArray[existingBufferIndex].size()); - NTSCFG_TEST_EQ(constMessage.size(), expectedSize); - NTSCFG_TEST_EQ(constMessage.capacity(), expectedCapacity); + expectedCapacity += constBufferSize(existingBufferIndex); } - constMessage.reset(); + bsl::size_t expectedSize = expectedCapacity; + + NTSCFG_TEST_EQ(constMessage.size(), expectedSize); + NTSCFG_TEST_EQ(constMessage.capacity(), expectedCapacity); } + + constMessage.reset(); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::MessageTest::verifyCase2) { // Concern: The semantics of 'ntsa::MutableMessage' are correct. // Plan: @@ -134,66 +108,76 @@ NTSCFG_TEST_CASE(2) const bsl::size_t MAX_RESET_ITERATION = 2; const bsl::size_t MAX_BUFFER_INDEX = 64; - ntscfg::TestAllocator ta; + ntsa::MutableMessage mutableMessage(NTSCFG_TEST_ALLOCATOR); + + for (bsl::size_t resetIteration = 0; resetIteration < 2; ++resetIteration) { - ntsa::MutableMessage mutableMessage(&ta); + NTSCFG_TEST_EQ(mutableMessage.endpoint(), ntsa::Endpoint()); + NTSCFG_TEST_EQ(mutableMessage.numBuffers(), 0); + NTSCFG_TEST_EQ(mutableMessage.size(), 0); + NTSCFG_TEST_EQ(mutableMessage.capacity(), 0); + + bsl::vector mutableBufferArray; - for (bsl::size_t resetIteration = 0; resetIteration < 2; - ++resetIteration) + for (bsl::size_t bufferIndex = 0; bufferIndex < MAX_BUFFER_INDEX; + ++bufferIndex) { - NTSCFG_TEST_EQ(mutableMessage.endpoint(), ntsa::Endpoint()); - NTSCFG_TEST_EQ(mutableMessage.numBuffers(), 0); - NTSCFG_TEST_EQ(mutableMessage.size(), 0); - NTSCFG_TEST_EQ(mutableMessage.capacity(), 0); + ntsa::MutableBuffer mutableBuffer(mutableBufferData(bufferIndex), + mutableBufferSize(bufferIndex)); + + mutableMessage.appendBuffer(mutableBuffer); + mutableBufferArray.push_back(mutableBuffer); - bsl::vector mutableBufferArray; + bsl::size_t expectedNumBuffers = bufferIndex + 1; - for (bsl::size_t bufferIndex = 0; bufferIndex < MAX_BUFFER_INDEX; - ++bufferIndex) + NTSCFG_TEST_EQ(mutableMessage.numBuffers(), expectedNumBuffers); + + bsl::size_t expectedCapacity = 0; + for (bsl::size_t existingBufferIndex = 0; + existingBufferIndex <= bufferIndex; + ++existingBufferIndex) { - ntsa::MutableBuffer mutableBuffer( - test::mutableBufferData(bufferIndex), - test::mutableBufferSize(bufferIndex)); - - mutableMessage.appendBuffer(mutableBuffer); - mutableBufferArray.push_back(mutableBuffer); - - bsl::size_t expectedNumBuffers = bufferIndex + 1; - - NTSCFG_TEST_EQ(mutableMessage.numBuffers(), - expectedNumBuffers); - - bsl::size_t expectedCapacity = 0; - for (bsl::size_t existingBufferIndex = 0; - existingBufferIndex <= bufferIndex; - ++existingBufferIndex) - { - NTSCFG_TEST_EQ( - mutableMessage.buffer(existingBufferIndex).data(), - mutableBufferArray[existingBufferIndex].data()); - NTSCFG_TEST_EQ( - mutableMessage.buffer(existingBufferIndex).size(), - mutableBufferArray[existingBufferIndex].size()); - - expectedCapacity += - test::mutableBufferSize(existingBufferIndex); - } - - bsl::size_t expectedSize = 0; - - NTSCFG_TEST_EQ(mutableMessage.size(), expectedSize); - NTSCFG_TEST_EQ(mutableMessage.capacity(), expectedCapacity); + NTSCFG_TEST_EQ( + mutableMessage.buffer(existingBufferIndex).data(), + mutableBufferArray[existingBufferIndex].data()); + NTSCFG_TEST_EQ( + mutableMessage.buffer(existingBufferIndex).size(), + mutableBufferArray[existingBufferIndex].size()); + + expectedCapacity += mutableBufferSize(existingBufferIndex); } - mutableMessage.reset(); + bsl::size_t expectedSize = 0; + + NTSCFG_TEST_EQ(mutableMessage.size(), expectedSize); + NTSCFG_TEST_EQ(mutableMessage.capacity(), expectedCapacity); } + + mutableMessage.reset(); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_DRIVER +const char MessageTest::s_buffer[1] = {0}; + +const void* MessageTest::constBufferData(bsl::size_t bufferIndex) +{ + return &s_buffer[0] + bufferIndex; +} + +bsl::size_t MessageTest::constBufferSize(bsl::size_t bufferIndex) +{ + return 10 * bufferIndex; +} + +void* MessageTest::mutableBufferData(bsl::size_t bufferIndex) { - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); + return const_cast(&s_buffer[0]) + bufferIndex; +} + +bsl::size_t MessageTest::mutableBufferSize(bsl::size_t bufferIndex) +{ + return 100 * bufferIndex; } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_notification.t.cpp b/groups/nts/ntsa/ntsa_notification.t.cpp index a2b62a3e..d5015481 100644 --- a/groups/nts/ntsa/ntsa_notification.t.cpp +++ b/groups/nts/ntsa/ntsa_notification.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,14 +13,45 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include +#include +BSLS_IDENT_RCSID(ntsa_notification_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -using namespace ntsa; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Notification'. +class NotificationTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); + + // TODO + static void verifyCase6(); + + // TODO + static void verifyCase7(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase1) { const bsl::uint32_t id = 12; const TimestampType::Value tsType = TimestampType::e_ACKNOWLEDGED; @@ -42,7 +73,7 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(n.timestamp(), ts); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase2) { const bsl::uint32_t id = 123; const TimestampType::Value type = TimestampType::e_ACKNOWLEDGED; @@ -61,7 +92,7 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_EQ(n.type(), NotificationType::e_TIMESTAMP); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase3) { const bsl::uint32_t id = 456; const TimestampType::Value type = TimestampType::e_SENT; @@ -83,7 +114,7 @@ NTSCFG_TEST_CASE(3) NTSCFG_TEST_EQ(n.type(), NotificationType::e_UNDEFINED); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase4) { Notification n1; Notification n2; @@ -97,7 +128,7 @@ NTSCFG_TEST_CASE(4) NTSCFG_TEST_NE(n1, n2); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase5) { const bsl::uint32_t id = 456; const TimestampType::Value type = TimestampType::e_SENT; @@ -117,7 +148,7 @@ NTSCFG_TEST_CASE(5) NTSCFG_TEST_EQ(n2.timestamp(), t); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase6) { Notification n; NTSCFG_TEST_TRUE(n.isUndefined()); @@ -136,7 +167,7 @@ NTSCFG_TEST_CASE(6) NTSCFG_TEST_EQ(n.zeroCopy(), zc); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTest::verifyCase7) { ZeroCopy zc; zc.setFrom(1); @@ -154,14 +185,5 @@ NTSCFG_TEST_CASE(7) NTSCFG_TEST_EQ(n.type(), NotificationType::e_UNDEFINED); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_notificationqueue.t.cpp b/groups/nts/ntsa/ntsa_notificationqueue.t.cpp index 1d1d370e..580d4b81 100644 --- a/groups/nts/ntsa/ntsa_notificationqueue.t.cpp +++ b/groups/nts/ntsa/ntsa_notificationqueue.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,29 +13,41 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_notificationqueue_t_cpp, "$Id$ $CSID$") -#include +#include using namespace BloombergLP; -using namespace ntsa; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::NotificationQueue'. +class NotificationQueueTest { - bslma::TestAllocator ta; - { - NotificationQueue q(&ta); - - NTSCFG_TEST_EQ(q.handle(), ntsa::k_INVALID_HANDLE); - NTSCFG_TEST_TRUE(q.notifications().empty()); - } - BSLS_ASSERT_OPT(ta.numBlocksInUse() == 0); + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::NotificationQueueTest::verifyCase1) +{ + NotificationQueue q(NTSCFG_TEST_ALLOCATOR); + + NTSCFG_TEST_EQ(q.handle(), ntsa::k_INVALID_HANDLE); + NTSCFG_TEST_TRUE(q.notifications().empty()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::NotificationQueueTest::verifyCase2) { const Handle h = 5; Notification n1; @@ -46,24 +58,20 @@ NTSCFG_TEST_CASE(2) n2.makeTimestamp().setType(TimestampType::e_SENT); n3.makeTimestamp().setType(TimestampType::e_ACKNOWLEDGED); - bslma::TestAllocator ta; - { - NotificationQueue q(&ta); - q.setHandle(h); - q.addNotification(n1); - q.addNotification(n2); - q.addNotification(n3); - - NTSCFG_TEST_EQ(q.handle(), h); - NTSCFG_TEST_EQ(q.notifications().size(), 3); - NTSCFG_TEST_EQ(q.notifications().at(0), n1); - NTSCFG_TEST_EQ(q.notifications().at(1), n2); - NTSCFG_TEST_EQ(q.notifications().at(2), n3); - } - BSLS_ASSERT_OPT(ta.numBlocksInUse() == 0); + NotificationQueue q(NTSCFG_TEST_ALLOCATOR); + q.setHandle(h); + q.addNotification(n1); + q.addNotification(n2); + q.addNotification(n3); + + NTSCFG_TEST_EQ(q.handle(), h); + NTSCFG_TEST_EQ(q.notifications().size(), 3); + NTSCFG_TEST_EQ(q.notifications().at(0), n1); + NTSCFG_TEST_EQ(q.notifications().at(1), n2); + NTSCFG_TEST_EQ(q.notifications().at(2), n3); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::NotificationQueueTest::verifyCase3) { const Handle h = 6; Notification n1; @@ -71,49 +79,16 @@ NTSCFG_TEST_CASE(3) n1.makeTimestamp().setType(TimestampType::e_SCHEDULED); n2.makeTimestamp().setType(TimestampType::e_ACKNOWLEDGED); - bslma::TestAllocator ta; - { - NotificationQueue q(&ta); - q.setHandle(h); - q.addNotification(n1); + NotificationQueue q(NTSCFG_TEST_ALLOCATOR); + q.setHandle(h); + q.addNotification(n1); - NotificationQueue q2(q, &ta); - NTSCFG_TEST_EQ(q2, q); + NotificationQueue q2(q, NTSCFG_TEST_ALLOCATOR); + NTSCFG_TEST_EQ(q2, q); - q2.addNotification(n2); - NTSCFG_TEST_NE(q2, q); - } - BSLS_ASSERT_OPT(ta.numBlocksInUse() == 0); + q2.addNotification(n2); + NTSCFG_TEST_NE(q2, q); } -NTSCFG_TEST_CASE(4) -{ - /// NotificationQueue is allocated on stack inside reactor drivers with - /// help of bdlma::LocalSequentialAllocator. Currently - /// NotificationQueue::k_NUM_BYTES_TO_ALLOCATE is used as a constant to - /// allocate enough memory on the stack for the queue. If it happens - /// that size of ntsa::Notification (and thus size of - /// ntsa::NotificationQueue) is changed then eiher fix this comment and - /// comment above NotificationQueue::k_NUM_BYTES_TO_ALLOCATE (number of - /// notifications should be decreased) or make the constant bigger. - const int numNotifications = 32; - bslma::TestAllocator ta; - { - NotificationQueue q(&ta); - for (int i = 0; i < numNotifications; ++i) { - Notification n; - q.addNotification(n); - } - NTSCFG_TEST_LE(ta.numBytesInUse(), - NotificationQueue::k_NUM_BYTES_TO_ALLOCATE); - } -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_notificationtype.t.cpp b/groups/nts/ntsa/ntsa_notificationtype.t.cpp index 2cab0e9c..03d052e9 100644 --- a/groups/nts/ntsa/ntsa_notificationtype.t.cpp +++ b/groups/nts/ntsa/ntsa_notificationtype.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,87 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -using namespace BloombergLP; -using namespace ntsa; - -NTSCFG_TEST_CASE(1) -{ - NTSCFG_TEST_EQ( - bsl::strcmp(NotificationType::toString(NotificationType::e_UNDEFINED), - "UNDEFINED"), - 0); - NTSCFG_TEST_EQ( - bsl::strcmp(NotificationType::toString(NotificationType::e_TIMESTAMP), - "TIMESTAMP"), - 0); - NTSCFG_TEST_EQ( - bsl::strcmp(NotificationType::toString(NotificationType::e_ZERO_COPY), - "ZERO_COPY"), - 0); -} - -NTSCFG_TEST_CASE(2) -{ - NotificationType::Value v = NotificationType::e_TIMESTAMP; - - NTSCFG_TEST_EQ(NotificationType::fromInt(&v, -1), -1); - NTSCFG_TEST_EQ(v, NotificationType::e_TIMESTAMP); +#include +BSLS_IDENT_RCSID(ntsa_notificationtype_t_cpp, "$Id$ $CSID$") - NTSCFG_TEST_EQ(NotificationType::fromInt(&v, 0), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_UNDEFINED); +#include - NTSCFG_TEST_EQ(NotificationType::fromInt(&v, 1), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_TIMESTAMP); +using namespace BloombergLP; - NTSCFG_TEST_EQ(NotificationType::fromInt(&v, 2), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_ZERO_COPY); +namespace BloombergLP { +namespace ntsa { - NTSCFG_TEST_EQ(NotificationType::fromInt(&v, 3), -1); - NTSCFG_TEST_EQ(v, NotificationType::e_ZERO_COPY); -} - -NTSCFG_TEST_CASE(3) +// Provide tests for 'ntsa::NotificationType'. +class NotificationTypeTest { - const bsl::string undefined = "undefined"; - const bsl::string timestamp = "timestamp"; - const bsl::string zerocopy = "zero_copy"; - const bsl::string random = "random_string"; - - NotificationType::Value v = NotificationType::e_TIMESTAMP; - - NTSCFG_TEST_EQ(NotificationType::fromString(&v, random), -1); - NTSCFG_TEST_EQ(v, NotificationType::e_TIMESTAMP); + public: + // TODO + static void verify(); +}; - NTSCFG_TEST_EQ(NotificationType::fromString(&v, undefined), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_UNDEFINED); - - NTSCFG_TEST_EQ(NotificationType::fromString(&v, timestamp), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_TIMESTAMP); - - NTSCFG_TEST_EQ(NotificationType::fromString(&v, zerocopy), 0); - NTSCFG_TEST_EQ(v, NotificationType::e_ZERO_COPY); -} - -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::NotificationTypeTest::verify) { - bsl::stringstream ss; - - ss << NotificationType::e_TIMESTAMP << ", " - << NotificationType::e_UNDEFINED << ", " - << NotificationType::e_ZERO_COPY; - - NTSCFG_TEST_EQ(ss.str(), "TIMESTAMP, UNDEFINED, ZERO_COPY"); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_port.t.cpp b/groups/nts/ntsa/ntsa_port.t.cpp index 9eaec0bc..62831a2b 100644 --- a/groups/nts/ntsa/ntsa_port.t.cpp +++ b/groups/nts/ntsa/ntsa_port.t.cpp @@ -13,103 +13,87 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -#include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_port_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Port'. +class PortTest { - // Concern: - // Plan: + public: + // TODO + static void verifyCase1(); - ntscfg::TestAllocator ta; - { - struct Data { - const char* d_text; - bsl::uint16_t d_value; - bool d_success; - } DATA[] = { - { "0", 0, true}, - { "1", 1, true}, - { "12", 12, true}, - { "123", 123, true}, - {"28588", 28588, true}, - {"65535", 65535, true}, - { "-1", 0, false}, - {"65536", 0, false} - }; + // TODO + static void verifyCase2(); +}; - enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; +NTSCFG_TEST_FUNCTION(ntsa::PortTest::verifyCase1) +{ + struct Data { + const char* d_text; + bsl::uint16_t d_value; + bool d_success; + } DATA[] = { + { "0", 0, true}, + { "1", 1, true}, + { "12", 12, true}, + { "123", 123, true}, + {"28588", 28588, true}, + {"65535", 65535, true}, + { "-1", 0, false}, + {"65536", 0, false} + }; - for (bsl::size_t i = 0; i < NUM_DATA; ++i) { - ntsa::Port port; - bool result = ntsa::PortUtil::parse(&port, - DATA[i].d_text, - bsl::strlen(DATA[i].d_text)); - if (DATA[i].d_success) { - NTSCFG_TEST_TRUE(result); - NTSCFG_TEST_EQ(port, DATA[i].d_value); - } - else { - NTSCFG_TEST_FALSE(result); - } + enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; + + for (bsl::size_t i = 0; i < NUM_DATA; ++i) { + ntsa::Port port; + bool result = ntsa::PortUtil::parse(&port, + DATA[i].d_text, + bsl::strlen(DATA[i].d_text)); + if (DATA[i].d_success) { + NTSCFG_TEST_TRUE(result); + NTSCFG_TEST_EQ(port, DATA[i].d_value); + } + else { + NTSCFG_TEST_FALSE(result); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::PortTest::verifyCase2) { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - struct Data { - bsl::uint16_t d_value; - const char* d_text; - } DATA[] = { - { 0, "0"}, - { 1, "1"}, - { 12, "12"}, - { 123, "123"}, - {28588, "28588"}, - {65535, "65535"} - }; + struct Data { + bsl::uint16_t d_value; + const char* d_text; + } DATA[] = { + { 0, "0"}, + { 1, "1"}, + { 12, "12"}, + { 123, "123"}, + {28588, "28588"}, + {65535, "65535"} + }; - enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; + enum { NUM_DATA = sizeof(DATA) / sizeof(DATA[0]) }; - for (bsl::size_t i = 0; i < NUM_DATA; ++i) { - char buffer[ntsa::PortUtil::MAX_LENGTH + 1]; - bsl::size_t size = - ntsa::PortUtil::format(buffer, sizeof buffer, DATA[i].d_value); - NTSCFG_TEST_EQ(size, bsl::strlen(buffer)); - NTSCFG_TEST_EQ(0, bsl::strcmp(buffer, DATA[i].d_text)); - } + for (bsl::size_t i = 0; i < NUM_DATA; ++i) { + char buffer[ntsa::PortUtil::MAX_LENGTH + 1]; + bsl::size_t size = + ntsa::PortUtil::format(buffer, sizeof buffer, DATA[i].d_value); + NTSCFG_TEST_EQ(size, bsl::strlen(buffer)); + NTSCFG_TEST_EQ(0, bsl::strcmp(buffer, DATA[i].d_text)); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_receivecontext.t.cpp b/groups/nts/ntsa/ntsa_receivecontext.t.cpp index 80f65d86..7fcd4854 100644 --- a/groups/nts/ntsa/ntsa_receivecontext.t.cpp +++ b/groups/nts/ntsa/ntsa_receivecontext.t.cpp @@ -13,85 +13,69 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_receivecontext_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::ReceiveContext'. +class ReceiveContextTest { - // Concern: test set and get methods for sw and hw timestamps + public: + // TODO + static void verifyCase1(); - ntscfg::TestAllocator ta; - { - ntsa::ReceiveContext ctx; + // TODO + static void verifyCase2(); +}; - NTSCFG_TEST_TRUE(ctx.softwareTimestamp().isNull()); - NTSCFG_TEST_TRUE(ctx.hardwareTimestamp().isNull()); +NTSCFG_TEST_FUNCTION(ntsa::ReceiveContextTest::verifyCase1) +{ + ntsa::ReceiveContext ctx; + + NTSCFG_TEST_TRUE(ctx.softwareTimestamp().isNull()); + NTSCFG_TEST_TRUE(ctx.hardwareTimestamp().isNull()); - const bsls::TimeInterval swTs(100, 200); - const bsls::TimeInterval hwTs(300, 500); + const bsls::TimeInterval swTs(100, 200); + const bsls::TimeInterval hwTs(300, 500); - ctx.setSoftwareTimestamp(swTs); - ctx.setHardwareTimestamp(hwTs); + ctx.setSoftwareTimestamp(swTs); + ctx.setHardwareTimestamp(hwTs); - NTSCFG_TEST_FALSE(ctx.softwareTimestamp().isNull()); - NTSCFG_TEST_FALSE(ctx.hardwareTimestamp().isNull()); + NTSCFG_TEST_FALSE(ctx.softwareTimestamp().isNull()); + NTSCFG_TEST_FALSE(ctx.hardwareTimestamp().isNull()); - NTSCFG_TEST_EQ(ctx.softwareTimestamp().value(), swTs); - NTSCFG_TEST_EQ(ctx.hardwareTimestamp().value(), hwTs); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_EQ(ctx.softwareTimestamp().value(), swTs); + NTSCFG_TEST_EQ(ctx.hardwareTimestamp().value(), hwTs); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::ReceiveContextTest::verifyCase2) { - // Concern: test equals() method (timestamps related only) - - ntscfg::TestAllocator ta; - { - ntsa::ReceiveContext ctx1; - ntsa::ReceiveContext ctx2; + ntsa::ReceiveContext ctx1; + ntsa::ReceiveContext ctx2; - NTSCFG_TEST_TRUE(ctx1.equals(ctx2)); + NTSCFG_TEST_TRUE(ctx1.equals(ctx2)); - const bsls::TimeInterval bigTs(200, 0); - const bsls::TimeInterval smallTs(100, 0); + const bsls::TimeInterval bigTs(200, 0); + const bsls::TimeInterval smallTs(100, 0); - ctx1.setHardwareTimestamp(bigTs); - ctx2.setHardwareTimestamp(smallTs); + ctx1.setHardwareTimestamp(bigTs); + ctx2.setHardwareTimestamp(smallTs); - NTSCFG_TEST_TRUE(ctx2.less(ctx1)); + NTSCFG_TEST_TRUE(ctx2.less(ctx1)); - ctx1.setSoftwareTimestamp(smallTs); - ctx2.setSoftwareTimestamp(bigTs); + ctx1.setSoftwareTimestamp(smallTs); + ctx2.setSoftwareTimestamp(bigTs); - NTSCFG_TEST_TRUE(ctx1.less(ctx2)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_TRUE(ctx1.less(ctx2)); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_receiveoptions.t.cpp b/groups/nts/ntsa/ntsa_receiveoptions.t.cpp index d5457068..39b99454 100644 --- a/groups/nts/ntsa/ntsa_receiveoptions.t.cpp +++ b/groups/nts/ntsa/ntsa_receiveoptions.t.cpp @@ -13,152 +13,136 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_receiveoptions_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::ReceiveOptions'. +class ReceiveOptionsTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase3(); -NTSCFG_TEST_CASE(1) + // TODO + static void verifyCase4(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::ReceiveOptionsTest::verifyCase1) { // Concern: Test want/show/hide endpoint, timestamp, and foreign handles. - ntscfg::TestAllocator ta; - { - ntsa::ReceiveOptions opt; - NTSCFG_TEST_FALSE(opt.wantTimestamp()); - NTSCFG_TEST_TRUE(opt.wantEndpoint()); - - opt.hideEndpoint(); - opt.showTimestamp(); - NTSCFG_TEST_TRUE(opt.wantTimestamp()); - NTSCFG_TEST_FALSE(opt.wantEndpoint()); - - opt.showEndpoint(); - NTSCFG_TEST_TRUE(opt.wantTimestamp()); - NTSCFG_TEST_TRUE(opt.wantEndpoint()); - - opt.hideEndpoint(); - NTSCFG_TEST_TRUE(opt.wantTimestamp()); - NTSCFG_TEST_FALSE(opt.wantEndpoint()); - - opt.hideTimestamp(); - NTSCFG_TEST_FALSE(opt.wantTimestamp()); - NTSCFG_TEST_FALSE(opt.wantEndpoint()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntsa::ReceiveOptions opt; + NTSCFG_TEST_FALSE(opt.wantTimestamp()); + NTSCFG_TEST_TRUE(opt.wantEndpoint()); + + opt.hideEndpoint(); + opt.showTimestamp(); + NTSCFG_TEST_TRUE(opt.wantTimestamp()); + NTSCFG_TEST_FALSE(opt.wantEndpoint()); + + opt.showEndpoint(); + NTSCFG_TEST_TRUE(opt.wantTimestamp()); + NTSCFG_TEST_TRUE(opt.wantEndpoint()); + + opt.hideEndpoint(); + NTSCFG_TEST_TRUE(opt.wantTimestamp()); + NTSCFG_TEST_FALSE(opt.wantEndpoint()); + + opt.hideTimestamp(); + NTSCFG_TEST_FALSE(opt.wantTimestamp()); + NTSCFG_TEST_FALSE(opt.wantEndpoint()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::ReceiveOptionsTest::verifyCase2) { - // Concern: test equals() method (boolean options considered only) + // Concern: test equals() method (boolean options considered only). - ntscfg::TestAllocator ta; - { - ntsa::ReceiveOptions opt1; - ntsa::ReceiveOptions opt2; - NTSCFG_TEST_TRUE(opt1.equals(opt2)); + ntsa::ReceiveOptions opt1; + ntsa::ReceiveOptions opt2; + NTSCFG_TEST_TRUE(opt1.equals(opt2)); - opt1.showTimestamp(); - NTSCFG_TEST_FALSE(opt1.equals(opt2)); + opt1.showTimestamp(); + NTSCFG_TEST_FALSE(opt1.equals(opt2)); - opt2.showTimestamp(); - NTSCFG_TEST_TRUE(opt1.equals(opt2)); + opt2.showTimestamp(); + NTSCFG_TEST_TRUE(opt1.equals(opt2)); - opt2.hideEndpoint(); - opt1.hideEndpoint(); - NTSCFG_TEST_TRUE(opt1.equals(opt2)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + opt2.hideEndpoint(); + opt1.hideEndpoint(); + NTSCFG_TEST_TRUE(opt1.equals(opt2)); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::ReceiveOptionsTest::verifyCase3) { - // Concern: test less() method (boolean options considered only) + // Concern: test less() method (boolean options considered only). - ntscfg::TestAllocator ta; - { - ntsa::ReceiveOptions opt1; - ntsa::ReceiveOptions opt2; - NTSCFG_TEST_FALSE(opt1.less(opt2)); + ntsa::ReceiveOptions opt1; + ntsa::ReceiveOptions opt2; + NTSCFG_TEST_FALSE(opt1.less(opt2)); - opt1.showTimestamp(); - NTSCFG_TEST_FALSE(opt1.less(opt2)); + opt1.showTimestamp(); + NTSCFG_TEST_FALSE(opt1.less(opt2)); - opt2.hideEndpoint(); - NTSCFG_TEST_TRUE(opt2.less(opt1)); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + opt2.hideEndpoint(); + NTSCFG_TEST_TRUE(opt2.less(opt1)); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::ReceiveOptionsTest::verifyCase4) { // Concern: wantMetaData - ntscfg::TestAllocator ta; - { - ntsa::ReceiveOptions options; + ntsa::ReceiveOptions options; - NTSCFG_TEST_FALSE(options.wantTimestamp()); - NTSCFG_TEST_FALSE(options.wantForeignHandles()); - NTSCFG_TEST_FALSE(options.wantMetaData()); + NTSCFG_TEST_FALSE(options.wantTimestamp()); + NTSCFG_TEST_FALSE(options.wantForeignHandles()); + NTSCFG_TEST_FALSE(options.wantMetaData()); - options.showTimestamp(); + options.showTimestamp(); - NTSCFG_TEST_TRUE(options.wantTimestamp()); - NTSCFG_TEST_FALSE(options.wantForeignHandles()); - NTSCFG_TEST_TRUE(options.wantMetaData()); + NTSCFG_TEST_TRUE(options.wantTimestamp()); + NTSCFG_TEST_FALSE(options.wantForeignHandles()); + NTSCFG_TEST_TRUE(options.wantMetaData()); - options.reset(); + options.reset(); - NTSCFG_TEST_FALSE(options.wantTimestamp()); - NTSCFG_TEST_FALSE(options.wantForeignHandles()); - NTSCFG_TEST_FALSE(options.wantMetaData()); + NTSCFG_TEST_FALSE(options.wantTimestamp()); + NTSCFG_TEST_FALSE(options.wantForeignHandles()); + NTSCFG_TEST_FALSE(options.wantMetaData()); - options.showForeignHandles(); + options.showForeignHandles(); - NTSCFG_TEST_FALSE(options.wantTimestamp()); - NTSCFG_TEST_TRUE(options.wantForeignHandles()); - NTSCFG_TEST_TRUE(options.wantMetaData()); + NTSCFG_TEST_FALSE(options.wantTimestamp()); + NTSCFG_TEST_TRUE(options.wantForeignHandles()); + NTSCFG_TEST_TRUE(options.wantMetaData()); - options.reset(); + options.reset(); - NTSCFG_TEST_FALSE(options.wantTimestamp()); - NTSCFG_TEST_FALSE(options.wantForeignHandles()); - NTSCFG_TEST_FALSE(options.wantMetaData()); + NTSCFG_TEST_FALSE(options.wantTimestamp()); + NTSCFG_TEST_FALSE(options.wantForeignHandles()); + NTSCFG_TEST_FALSE(options.wantMetaData()); - options.showTimestamp(); - options.showForeignHandles(); + options.showTimestamp(); + options.showForeignHandles(); - NTSCFG_TEST_TRUE(options.wantTimestamp()); - NTSCFG_TEST_TRUE(options.wantForeignHandles()); - NTSCFG_TEST_TRUE(options.wantMetaData()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_TRUE(options.wantTimestamp()); + NTSCFG_TEST_TRUE(options.wantForeignHandles()); + NTSCFG_TEST_TRUE(options.wantMetaData()); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_sendcontext.t.cpp b/groups/nts/ntsa/ntsa_sendcontext.t.cpp index bb58d150..44db5a9a 100644 --- a/groups/nts/ntsa/ntsa_sendcontext.t.cpp +++ b/groups/nts/ntsa/ntsa_sendcontext.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_sendcontext_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::SendContext'. +class SendContextTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::SendContextTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_sendoptions.t.cpp b/groups/nts/ntsa/ntsa_sendoptions.t.cpp index f779376b..a2653cdb 100644 --- a/groups/nts/ntsa/ntsa_sendoptions.t.cpp +++ b/groups/nts/ntsa/ntsa_sendoptions.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_sendoptions_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::SendOptions'. +class SendOptionsTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::SendOptionsTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_socketconfig.t.cpp b/groups/nts/ntsa/ntsa_socketconfig.t.cpp index 664d458e..13cc60bc 100644 --- a/groups/nts/ntsa/ntsa_socketconfig.t.cpp +++ b/groups/nts/ntsa/ntsa_socketconfig.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_socketconfig_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::SocketConfig'. +class SocketConfigTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::SocketConfigTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_socketoption.t.cpp b/groups/nts/ntsa/ntsa_socketoption.t.cpp index b6591a4e..498e97fa 100644 --- a/groups/nts/ntsa/ntsa_socketoption.t.cpp +++ b/groups/nts/ntsa/ntsa_socketoption.t.cpp @@ -13,27 +13,33 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include + +#include +BSLS_IDENT_RCSID(ntsa_socketoption_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -using namespace ntsa; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +// Provide tests for 'ntsa::SocketOption'. +class SocketOptionTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); +}; -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsa::SocketOptionTest::verifyCase1) { // Concern: test timestampIncomingData option @@ -58,7 +64,7 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_FALSE(so.isTimestampIncomingData()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::SocketOptionTest::verifyCase2) { // Concern: test timestampOutgoingData option @@ -83,7 +89,7 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_FALSE(so.isTimestampOutgoingData()); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::SocketOptionTest::verifyCase3) { // Concern: test allowMsgZeroCopy option @@ -108,10 +114,5 @@ NTSCFG_TEST_CASE(3) NTSCFG_TEST_FALSE(so.isZeroCopy()); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_socketoptiontype.t.cpp b/groups/nts/ntsa/ntsa_socketoptiontype.t.cpp index 8e75b736..82a7a664 100644 --- a/groups/nts/ntsa/ntsa_socketoptiontype.t.cpp +++ b/groups/nts/ntsa/ntsa_socketoptiontype.t.cpp @@ -13,43 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_socketoptiontype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; -using namespace ntsa; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::SocketOptionType'. +class SocketOptionTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::SocketOptionTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_tcpcongestioncontrol.h b/groups/nts/ntsa/ntsa_tcpcongestioncontrol.h index 7ad5104d..08c1940d 100644 --- a/groups/nts/ntsa/ntsa_tcpcongestioncontrol.h +++ b/groups/nts/ntsa/ntsa_tcpcongestioncontrol.h @@ -186,8 +186,8 @@ NTSCFG_INLINE void TcpCongestionControl::hash(HASH_ALGORITHM& algorithm) const } template -NTSCFG_INLINE -void hashAppend(HASH_ALGORITHM& algorithm, const TcpCongestionControl& value) +NTSCFG_INLINE void hashAppend(HASH_ALGORITHM& algorithm, + const TcpCongestionControl& value) { value.hash(algorithm); } diff --git a/groups/nts/ntsa/ntsa_tcpcongestioncontrol.t.cpp b/groups/nts/ntsa/ntsa_tcpcongestioncontrol.t.cpp index a38cc2ff..86075b18 100644 --- a/groups/nts/ntsa/ntsa_tcpcongestioncontrol.t.cpp +++ b/groups/nts/ntsa/ntsa_tcpcongestioncontrol.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2024 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,12 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include BSLS_IDENT_RCSID(ntsa_tcpcongestioncontrol_t_cpp, "$Id$ $CSID$") -#include +#include using namespace BloombergLP; @@ -61,7 +61,7 @@ class TcpCongestionControlTest static void verifyWellKnownEnumerators(); }; -void TcpCongestionControlTest::verifyTypeTraits() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyTypeTraits) { const bool isAllocatorAware = NTSCFG_TYPE_CHECK_ALLOCATOR_AWARE(ntsa::TcpCongestionControl); @@ -69,7 +69,7 @@ void TcpCongestionControlTest::verifyTypeTraits() NTSCFG_TEST_TRUE(isAllocatorAware); } -void TcpCongestionControlTest::verifyDefaultConstructor() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyDefaultConstructor) { ntsa::TcpCongestionControl congestionControl(NTSCFG_TEST_ALLOCATOR); @@ -77,7 +77,7 @@ void TcpCongestionControlTest::verifyDefaultConstructor() NTSCFG_TEST_EQ(congestionControl.allocator(), NTSCFG_TEST_ALLOCATOR); } -void TcpCongestionControlTest::verifyMoveConstructor() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyMoveConstructor) { ntsa::TcpCongestionControl source(NTSCFG_TEST_ALLOCATOR); @@ -95,7 +95,7 @@ void TcpCongestionControlTest::verifyMoveConstructor() #endif } -void TcpCongestionControlTest::verifyCopyConstructor() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyCopyConstructor) { ntsa::TcpCongestionControl source(NTSCFG_TEST_ALLOCATOR); @@ -108,7 +108,7 @@ void TcpCongestionControlTest::verifyCopyConstructor() NTSCFG_TEST_EQ(destination.allocator(), NTSCFG_TEST_ALLOCATOR); } -void TcpCongestionControlTest::verifyOverloadConstructor() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyOverloadConstructor) { { ntsa::TcpCongestionControl source("debug", NTSCFG_TEST_ALLOCATOR); @@ -125,7 +125,7 @@ void TcpCongestionControlTest::verifyOverloadConstructor() } } -void TcpCongestionControlTest::verifyCopyAssignment() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyCopyAssignment) { ntsa::TcpCongestionControl source("debug", NTSCFG_TEST_ALLOCATOR); NTSCFG_TEST_EQ(source.algorithm(), "debug"); @@ -141,7 +141,7 @@ void TcpCongestionControlTest::verifyCopyAssignment() NTSCFG_TEST_EQ(destination.allocator(), bslma::Default::allocator()); } -void TcpCongestionControlTest::verifyMoveAssignment() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyMoveAssignment) { { ntsa::TcpCongestionControl source("debug", NTSCFG_TEST_ALLOCATOR); @@ -184,11 +184,11 @@ void TcpCongestionControlTest::verifyMoveAssignment() } } -void TcpCongestionControlTest::verifyOverloadAssignment() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyOverloadAssignment) { } -void TcpCongestionControlTest::verifyReset() +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlTest::verifyReset) { ntsa::TcpCongestionControl source("debug", NTSCFG_TEST_ALLOCATOR); NTSCFG_TEST_EQ(source.algorithm(), "debug"); @@ -200,7 +200,8 @@ void TcpCongestionControlTest::verifyReset() NTSCFG_TEST_EQ(source.allocator(), NTSCFG_TEST_ALLOCATOR); } -void TcpCongestionControlTest::verifyWellKnownEnumerators() +NTSCFG_TEST_FUNCTION( + ntsa::TcpCongestionControlTest::verifyWellKnownEnumerators) { ntsa::Error error; @@ -253,26 +254,3 @@ void TcpCongestionControlTest::verifyWellKnownEnumerators() } // close namespace ntsa } // close namespace BloombergLP - -NTSCFG_TEST_SUITE -{ - NTSCFG_TEST_FUNCTION(&ntsa::TcpCongestionControlTest::verifyTypeTraits); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyDefaultConstructor); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyMoveConstructor); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyCopyConstructor); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyOverloadConstructor); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyCopyAssignment); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyMoveAssignment); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyOverloadAssignment); - NTSCFG_TEST_FUNCTION(&ntsa::TcpCongestionControlTest::verifyReset); - NTSCFG_TEST_FUNCTION( - &ntsa::TcpCongestionControlTest::verifyWellKnownEnumerators); -} -NTSCFG_TEST_SUITE_END; diff --git a/groups/nts/ntsa/ntsa_tcpcongestioncontrolalgorithm.t.cpp b/groups/nts/ntsa/ntsa_tcpcongestioncontrolalgorithm.t.cpp index 5c69f112..ebc400e1 100644 --- a/groups/nts/ntsa/ntsa_tcpcongestioncontrolalgorithm.t.cpp +++ b/groups/nts/ntsa/ntsa_tcpcongestioncontrolalgorithm.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,53 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -using namespace BloombergLP; -using namespace ntsa; - -NTSCFG_TEST_CASE(1) -{ - NTSCFG_TEST_EQ(bsl::strcmp(TcpCongestionControlAlgorithm::toString( - TcpCongestionControlAlgorithm::e_RENO), - "reno"), - 0); - NTSCFG_TEST_EQ(bsl::strcmp(TcpCongestionControlAlgorithm::toString( - TcpCongestionControlAlgorithm::e_BBR), - "bbr"), - 0); - NTSCFG_TEST_EQ(bsl::strcmp(TcpCongestionControlAlgorithm::toString( - TcpCongestionControlAlgorithm::e_YEAH), - "yeah"), - 0); -} - -NTSCFG_TEST_CASE(2) -{ - TcpCongestionControlAlgorithm::Value v = - TcpCongestionControlAlgorithm::e_YEAH; - - NTSCFG_TEST_EQ(TcpCongestionControlAlgorithm::fromInt(&v, -1), -1); - NTSCFG_TEST_EQ(v, TcpCongestionControlAlgorithm::e_YEAH); +#include +BSLS_IDENT_RCSID(ntsa_tcpcongestioncontrolalgorithm_t_cpp, "$Id$ $CSID$") - NTSCFG_TEST_EQ(TcpCongestionControlAlgorithm::fromInt(&v, 0), 0); - NTSCFG_TEST_EQ(v, TcpCongestionControlAlgorithm::e_RENO); +#include - NTSCFG_TEST_EQ(TcpCongestionControlAlgorithm::fromInt(&v, 1), 0); - NTSCFG_TEST_EQ(v, TcpCongestionControlAlgorithm::e_CUBIC); +using namespace BloombergLP; - NTSCFG_TEST_EQ(TcpCongestionControlAlgorithm::fromInt(&v, 2), 0); - NTSCFG_TEST_EQ(v, TcpCongestionControlAlgorithm::e_BBR); +namespace BloombergLP { +namespace ntsa { - NTSCFG_TEST_EQ(TcpCongestionControlAlgorithm::fromInt(&v, 100), -1); - NTSCFG_TEST_EQ(v, TcpCongestionControlAlgorithm::e_BBR); -} +// Provide tests for 'ntsa::TcpCongestionControlAlgorithm'. +class TcpCongestionControlAlgorithmTest +{ + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::TcpCongestionControlAlgorithmTest::verify) { - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_temporary.t.cpp b/groups/nts/ntsa/ntsa_temporary.t.cpp index bff11f17..152ccc8e 100644 --- a/groups/nts/ntsa/ntsa_temporary.t.cpp +++ b/groups/nts/ntsa/ntsa_temporary.t.cpp @@ -13,89 +13,74 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsa_temporary_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Temporary'. +class TemporaryTest +{ + public: + // TODO + static void verifyCase1(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase2(); +}; -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsa::TemporaryTest::verifyCase1) { // Concern: A temporary directory is automatically created and removed // by a temporary directory guard. - ntscfg::TestAllocator ta; + bsl::string directoryPath; { - bsl::string directoryPath; - { - ntsa::TemporaryDirectory tempDirectory; - directoryPath = tempDirectory.path(); + ntsa::TemporaryDirectory tempDirectory; + directoryPath = tempDirectory.path(); - BSLS_LOG_DEBUG("Create temporary directory: %s", - directoryPath.c_str()); + BSLS_LOG_DEBUG("Create temporary directory: %s", + directoryPath.c_str()); - bsl::string filePath = tempDirectory.path(); - bdls::PathUtil::appendRaw(&filePath, "file.txt"); + bsl::string filePath = tempDirectory.path(); + bdls::PathUtil::appendRaw(&filePath, "file.txt"); - bsl::ofstream ofs(filePath.c_str()); - BSLS_ASSERT(ofs); + bsl::ofstream ofs(filePath.c_str()); + BSLS_ASSERT(ofs); - ofs << "Hello, world!" << bsl::endl; - } - - BSLS_ASSERT(!bdls::FilesystemUtil::exists(directoryPath)); + ofs << "Hello, world!" << bsl::endl; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + BSLS_ASSERT(!bdls::FilesystemUtil::exists(directoryPath)); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::TemporaryTest::verifyCase2) { // Concern: A temporary file is automatically created and removed // by a temporary file guard. - ntscfg::TestAllocator ta; + bsl::string filePath; { - bsl::string filePath; - { - ntsa::TemporaryFile tempFile; - filePath = tempFile.path(); - - BSLS_LOG_DEBUG("Create temporary file: %s", filePath.c_str()); + ntsa::TemporaryFile tempFile; + filePath = tempFile.path(); - bsl::ofstream ofs(filePath.c_str()); - BSLS_ASSERT(ofs); + BSLS_LOG_DEBUG("Create temporary file: %s", filePath.c_str()); - ofs << "Hello, world!"; - } + bsl::ofstream ofs(filePath.c_str()); + BSLS_ASSERT(ofs); - BSLS_ASSERT(!bdls::FilesystemUtil::exists(filePath)); + ofs << "Hello, world!"; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); + BSLS_ASSERT(!bdls::FilesystemUtil::exists(filePath)); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_timestamp.t.cpp b/groups/nts/ntsa/ntsa_timestamp.t.cpp index f47cd012..6b4686d6 100644 --- a/groups/nts/ntsa/ntsa_timestamp.t.cpp +++ b/groups/nts/ntsa/ntsa_timestamp.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,14 +13,36 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include +#include +BSLS_IDENT_RCSID(ntsa_timestamp_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -using namespace ntsa; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::Timestamp'. +class TimestampTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::TimestampTest::verifyCase1) { Timestamp t; NTSCFG_TEST_EQ(t.type(), TimestampType::e_UNDEFINED); @@ -28,7 +50,7 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(t.time(), bsls::TimeInterval()); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::TimestampTest::verifyCase2) { const bsl::uint32_t id = 123; const TimestampType::Value type = TimestampType::e_ACKNOWLEDGED; @@ -44,7 +66,7 @@ NTSCFG_TEST_CASE(2) NTSCFG_TEST_EQ(t.time(), time); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::TimestampTest::verifyCase3) { const bsl::uint32_t id = 456; const TimestampType::Value type = TimestampType::e_SENT; @@ -68,7 +90,7 @@ NTSCFG_TEST_CASE(3) NTSCFG_TEST_EQ(t2.time(), t3.time()); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::TimestampTest::verifyCase4) { const bsl::uint32_t id = 456; const TimestampType::Value type = TimestampType::e_SENT; @@ -100,11 +122,5 @@ NTSCFG_TEST_CASE(4) NTSCFG_TEST_EQ(t1, t2); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_timestamptype.t.cpp b/groups/nts/ntsa/ntsa_timestamptype.t.cpp index c42b3ff9..54ad3303 100644 --- a/groups/nts/ntsa/ntsa_timestamptype.t.cpp +++ b/groups/nts/ntsa/ntsa_timestamptype.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,96 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -using namespace BloombergLP; -using namespace ntsa; +#include +BSLS_IDENT_RCSID(ntsa_file_t_cpp, "$Id$ $CSID$") -NTSCFG_TEST_CASE(1) -{ - NTSCFG_TEST_EQ( - bsl::strcmp(TimestampType::toString(TimestampType::e_UNDEFINED), - "UNDEFINED"), - 0); - NTSCFG_TEST_EQ( - bsl::strcmp(TimestampType::toString(TimestampType::e_SCHEDULED), - "SCHEDULED"), - 0); - NTSCFG_TEST_EQ( - bsl::strcmp(TimestampType::toString(TimestampType::e_SENT), "SENT"), - 0); - NTSCFG_TEST_EQ( - bsl::strcmp(TimestampType::toString(TimestampType::e_ACKNOWLEDGED), - "ACKNOWLEDGED"), - 0); -} - -NTSCFG_TEST_CASE(2) -{ - TimestampType::Value v = TimestampType::e_SENT; - - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, -1), -1); - NTSCFG_TEST_EQ(v, TimestampType::e_SENT); - - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, 0), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_UNDEFINED); - - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, 1), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_SCHEDULED); +#include - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, 2), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_SENT); +using namespace BloombergLP; - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, 3), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_ACKNOWLEDGED); +namespace BloombergLP { +namespace ntsa { - NTSCFG_TEST_EQ(TimestampType::fromInt(&v, 4), -1); - NTSCFG_TEST_EQ(v, TimestampType::e_ACKNOWLEDGED); -} - -NTSCFG_TEST_CASE(3) +// Provide tests for 'ntsa::TimestampType'. +class TimestampTypeTest { - const bsl::string undefined = "undefined"; - const bsl::string scheduled = "scheduled"; - const bsl::string sent = "sent"; - const bsl::string acknowledged = "acknowledged"; - const bsl::string random = "random_string"; - - TimestampType::Value v = TimestampType::e_SENT; - - NTSCFG_TEST_EQ(TimestampType::fromString(&v, random), -1); - NTSCFG_TEST_EQ(v, TimestampType::e_SENT); - - NTSCFG_TEST_EQ(TimestampType::fromString(&v, undefined), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_UNDEFINED); - - NTSCFG_TEST_EQ(TimestampType::fromString(&v, scheduled), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_SCHEDULED); - - NTSCFG_TEST_EQ(TimestampType::fromString(&v, sent), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_SENT); + public: + // TODO + static void verify(); +}; - NTSCFG_TEST_EQ(TimestampType::fromString(&v, acknowledged), 0); - NTSCFG_TEST_EQ(v, TimestampType::e_ACKNOWLEDGED); -} - -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::TimestampTypeTest::verify) { - bsl::stringstream ss; - - ss << TimestampType::e_SCHEDULED << ", " << TimestampType::e_SENT << ", " - << TimestampType::e_ACKNOWLEDGED << ", " << TimestampType::e_UNDEFINED; - - NTSCFG_TEST_EQ(ss.str(), "SCHEDULED, SENT, ACKNOWLEDGED, UNDEFINED"); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_transport.cpp b/groups/nts/ntsa/ntsa_transport.cpp index 3fd148ba..1f7f1035 100644 --- a/groups/nts/ntsa/ntsa_transport.cpp +++ b/groups/nts/ntsa/ntsa_transport.cpp @@ -278,7 +278,7 @@ int Transport::fromString(Transport::Value* result, int Transport::fromString(Value* result, const char* string, int stringLength) { return Transport::fromString( - result, + result, bslstl::StringRef(string, static_cast(stringLength))); } diff --git a/groups/nts/ntsa/ntsa_transport.h b/groups/nts/ntsa/ntsa_transport.h index 8633eb6a..b0e2cd21 100644 --- a/groups/nts/ntsa/ntsa_transport.h +++ b/groups/nts/ntsa/ntsa_transport.h @@ -19,12 +19,12 @@ #include BSLS_IDENT("$Id: $") -#include -#include -#include #include #include #include +#include +#include +#include namespace BloombergLP { namespace ntsa { diff --git a/groups/nts/ntsa/ntsa_transport.t.cpp b/groups/nts/ntsa/ntsa_transport.t.cpp index 1259ecba..15831627 100644 --- a/groups/nts/ntsa/ntsa_transport.t.cpp +++ b/groups/nts/ntsa/ntsa_transport.t.cpp @@ -13,30 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -using namespace BloombergLP; +#include +BSLS_IDENT_RCSID(ntsa_transport_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include + +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsa::Transport'. +class TransportTest { -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsa::TransportTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_uri.cpp b/groups/nts/ntsa/ntsa_uri.cpp index 80c6a71c..908eb7a5 100644 --- a/groups/nts/ntsa/ntsa_uri.cpp +++ b/groups/nts/ntsa/ntsa_uri.cpp @@ -496,8 +496,8 @@ const bdlb::NullableValue& UriAuthority::port() const return d_port; } -const bdlb::NullableValue& -UriAuthority::transport() const +const bdlb::NullableValue& UriAuthority::transport() + const { return d_transport; } @@ -566,7 +566,7 @@ bsl::ostream& UriAuthority::print(bsl::ostream& stream, const bdlat_AttributeInfo* UriAuthority::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -576,17 +576,16 @@ const bdlat_AttributeInfo* UriAuthority::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* UriAuthority::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* UriAuthority::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; @@ -609,8 +608,6 @@ const bdlat_AttributeInfo UriAuthority::ATTRIBUTE_INFO_ARRAY[4] = }; // clang-format on - - bsl::ostream& operator<<(bsl::ostream& stream, const UriAuthority& object) { return object.print(stream, 0, -1); @@ -733,7 +730,7 @@ bsl::ostream& UriParameter::print(bsl::ostream& stream, const bdlat_AttributeInfo* UriParameter::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -743,17 +740,16 @@ const bdlat_AttributeInfo* UriParameter::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* UriParameter::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* UriParameter::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; @@ -934,7 +930,7 @@ bsl::ostream& UriQuery::print(bsl::ostream& stream, const bdlat_AttributeInfo* UriQuery::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -944,17 +940,16 @@ const bdlat_AttributeInfo* UriQuery::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* UriQuery::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* UriQuery::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; @@ -1701,14 +1696,13 @@ bsl::ostream& Uri::print(bsl::ostream& stream, stream << d_authority.value().host().value().ip().v4(); } else if (d_authority.value().host().value().ip().isV6()) { - stream << '[' - << d_authority.value().host().value().ip().v6() + stream << '[' + << d_authority.value().host().value().ip().v6() << ']'; } } else if (d_authority.value().host().value().isLocalName()) { - stream << '@' - << d_authority.value().host().value().localName() + stream << '@' << d_authority.value().host().value().localName() << '@'; } } @@ -1799,7 +1793,7 @@ bsl::ostream& Uri::print(bsl::ostream& stream, const bdlat_AttributeInfo* Uri::lookupAttributeInfo(int id) { - const int numAttributes = + const int numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); if (id < 0 || id >= numAttributes) { @@ -1809,17 +1803,16 @@ const bdlat_AttributeInfo* Uri::lookupAttributeInfo(int id) return &ATTRIBUTE_INFO_ARRAY[id]; } -const bdlat_AttributeInfo* Uri::lookupAttributeInfo( - const char* name, - int nameLength) +const bdlat_AttributeInfo* Uri::lookupAttributeInfo(const char* name, + int nameLength) { - const bsl::size_t numAttributes = + const bsl::size_t numAttributes = sizeof(ATTRIBUTE_INFO_ARRAY) / sizeof(ATTRIBUTE_INFO_ARRAY[0]); for (bsl::size_t i = 0; i < numAttributes; ++i) { const bdlat_AttributeInfo& attributeInfo = ATTRIBUTE_INFO_ARRAY[i]; if (attributeInfo.d_nameLength == nameLength) { - const int compare = + const int compare = bsl::memcmp(attributeInfo.d_name_p, name, nameLength); if (compare == 0) { return &attributeInfo; diff --git a/groups/nts/ntsa/ntsa_uri.h b/groups/nts/ntsa/ntsa_uri.h index df23ae37..f0636467 100644 --- a/groups/nts/ntsa/ntsa_uri.h +++ b/groups/nts/ntsa/ntsa_uri.h @@ -28,9 +28,9 @@ BSLS_IDENT("$Id: $") #include #include #include -#include #include #include +#include #include #include #include @@ -57,7 +57,7 @@ class UriAuthority e_ATTRIBUTE_ID_USER = 0, e_ATTRIBUTE_ID_HOST = 1, e_ATTRIBUTE_ID_PORT = 2, - e_ATTRIBUTE_ID_TRANSPORT = 3 + e_ATTRIBUTE_ID_TRANSPORT = 3 }; bdlb::NullableValue d_user; @@ -134,7 +134,7 @@ class UriAuthority /// Return the port specified in the authority portion of the URI. const bdlb::NullableValue& port() const; - /// Return the transport specified in the authority portion of the URI. + /// Return the transport specified in the authority portion of the URI. const bdlb::NullableValue& transport() const; /// Return true if this object has the same value as the specified @@ -160,75 +160,75 @@ class UriAuthority int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[19]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[4]; /// Defines the traits of this type. These traits can be used to select, @@ -281,10 +281,7 @@ void hashAppend(HASH_ALGORITHM& algorithm, const UriAuthority& value); /// @ingroup module_ntsa_identity class UriParameter { - enum { - e_ATTRIBUTE_ID_NAME = 0, - e_ATTRIBUTE_ID_VALUE = 1 - }; + enum { e_ATTRIBUTE_ID_NAME = 0, e_ATTRIBUTE_ID_VALUE = 1 }; bsl::string d_name; bdlb::NullableValue d_value; @@ -352,75 +349,75 @@ class UriParameter int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[19]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[2]; /// Defines the traits of this type. These traits can be used to select, @@ -472,9 +469,7 @@ void hashAppend(HASH_ALGORITHM& algorithm, const UriParameter& value); /// @ingroup module_ntsa_identity class UriQuery { - enum { - e_ATTRIBUTE_ID_PARAMETER = 0 - }; + enum { e_ATTRIBUTE_ID_PARAMETER = 0 }; bsl::vector d_parameterList; @@ -543,75 +538,75 @@ class UriQuery int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[15]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[1]; /// Defines the traits of this type. These traits can be used to select, @@ -822,75 +817,75 @@ class Uri int level = 0, int spacesPerLevel = 4) const; - /// Invoke the specified 'manipulator' sequentially on the address of each - /// (modifiable) attribute of this object, supplying 'manipulator' with - /// the corresponding attribute information structure until such - /// invocation returns a non-zero value. Return the value from the last - /// invocation of 'manipulator' (i.e., the invocation that terminated the - /// sequence). + /// Invoke the specified 'manipulator' sequentially on the address of each + /// (modifiable) attribute of this object, supplying 'manipulator' with + /// the corresponding attribute information structure until such + /// invocation returns a non-zero value. Return the value from the last + /// invocation of 'manipulator' (i.e., the invocation that terminated the + /// sequence). template int manipulateAttributes(MANIPULATOR& manipulator); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'id', supplying 'manipulator' - /// with the corresponding attribute information structure. Return the - /// value returned from the invocation of 'manipulator' if 'id' identifies - /// an attribute of this class, and -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'id', supplying 'manipulator' + /// with the corresponding attribute information structure. Return the + /// value returned from the invocation of 'manipulator' if 'id' identifies + /// an attribute of this class, and -1 otherwise. template int manipulateAttribute(MANIPULATOR& manipulator, int id); - /// Invoke the specified 'manipulator' on the address of the (modifiable) - /// attribute indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'manipulator' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'manipulator' if 'name' identifies an attribute of this class, and - /// -1 otherwise. + /// Invoke the specified 'manipulator' on the address of the (modifiable) + /// attribute indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'manipulator' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'manipulator' if 'name' identifies an attribute of this class, and + /// -1 otherwise. template - int manipulateAttribute(MANIPULATOR& manipulator, - const char* name, + int manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength); - /// Invoke the specified 'accessor' sequentially on each (non-modifiable) - /// attribute of this object, supplying 'accessor' with the corresponding - /// attribute information structure until such invocation returns a - /// non-zero value. Return the value from the last invocation of - /// 'accessor' (i.e., the invocation that terminated the sequence). + /// Invoke the specified 'accessor' sequentially on each (non-modifiable) + /// attribute of this object, supplying 'accessor' with the corresponding + /// attribute information structure until such invocation returns a + /// non-zero value. Return the value from the last invocation of + /// 'accessor' (i.e., the invocation that terminated the sequence). template int accessAttributes(ACCESSOR& accessor) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'id', supplying 'accessor' with - /// the corresponding attribute information structure. Return the value - /// returned from the invocation of 'accessor' if 'id' identifies an - /// attribute of this class, and -1 otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'id', supplying 'accessor' with + /// the corresponding attribute information structure. Return the value + /// returned from the invocation of 'accessor' if 'id' identifies an + /// attribute of this class, and -1 otherwise. template int accessAttribute(ACCESSOR& accessor, int id) const; - /// Invoke the specified 'accessor' on the (non-modifiable) attribute of - /// this object indicated by the specified 'name' of the specified - /// 'nameLength', supplying 'accessor' with the corresponding attribute - /// information structure. Return the value returned from the invocation - /// of 'accessor' if 'name' identifies an attribute of this class, and -1 - /// otherwise. + /// Invoke the specified 'accessor' on the (non-modifiable) attribute of + /// this object indicated by the specified 'name' of the specified + /// 'nameLength', supplying 'accessor' with the corresponding attribute + /// information structure. Return the value returned from the invocation + /// of 'accessor' if 'name' identifies an attribute of this class, and -1 + /// otherwise. template - int accessAttribute(ACCESSOR& accessor, - const char* name, + int accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const; - /// Return attribute information for the attribute indicated by the - /// specified 'id' if the attribute exists, and 0 otherwise. + /// Return attribute information for the attribute indicated by the + /// specified 'id' if the attribute exists, and 0 otherwise. static const bdlat_AttributeInfo* lookupAttributeInfo(int id); - /// Return attribute information for the attribute indicated by the - /// specified 'name' of the specified 'nameLength' if the attribute - /// exists, and 0 otherwise. - static const bdlat_AttributeInfo* lookupAttributeInfo( - const char* name, int nameLength); + /// Return attribute information for the attribute indicated by the + /// specified 'name' of the specified 'nameLength' if the attribute + /// exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, + int nameLength); - /// Return the compiler-independant name for this class. + /// Return the compiler-independant name for this class. static const char CLASS_NAME[10]; - /// The attribute info array, indexed by attribute index. + /// The attribute info array, indexed by attribute index. static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[5]; /// Defines the traits of this type. These traits can be used to select, @@ -1014,11 +1009,11 @@ int UriParameter::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int UriParameter::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, +int UriParameter::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriParameter::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1070,11 +1065,11 @@ int UriParameter::accessAttribute(ACCESSOR& accessor, int id) const } template -int UriParameter::accessAttribute(ACCESSOR& accessor, - const char* name, +int UriParameter::accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriParameter::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1115,11 +1110,11 @@ int UriQuery::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int UriQuery::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, - int nameLength) +int UriQuery::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, + int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriQuery::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1160,11 +1155,11 @@ int UriQuery::accessAttribute(ACCESSOR& accessor, int id) const } template -int UriQuery::accessAttribute(ACCESSOR& accessor, - const char* name, +int UriQuery::accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriQuery::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1238,11 +1233,11 @@ int UriAuthority::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int UriAuthority::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, +int UriAuthority::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriAuthority::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1316,11 +1311,11 @@ int UriAuthority::accessAttribute(ACCESSOR& accessor, int id) const } template -int UriAuthority::accessAttribute(ACCESSOR& accessor, - const char* name, +int UriAuthority::accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::UriAuthority::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1405,11 +1400,11 @@ int Uri::manipulateAttribute(MANIPULATOR& manipulator, int id) } template -int Uri::manipulateAttribute(MANIPULATOR& manipulator, - const char* name, +int Uri::manipulateAttribute(MANIPULATOR& manipulator, + const char* name, int nameLength) { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::Uri::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; @@ -1494,11 +1489,11 @@ int Uri::accessAttribute(ACCESSOR& accessor, int id) const } template -int Uri::accessAttribute(ACCESSOR& accessor, - const char* name, +int Uri::accessAttribute(ACCESSOR& accessor, + const char* name, int nameLength) const { - const bdlat_AttributeInfo* info = + const bdlat_AttributeInfo* info = ntsa::Uri::lookupAttributeInfo(name, nameLength); if (info == 0) { return -1; diff --git a/groups/nts/ntsa/ntsa_uri.t.cpp b/groups/nts/ntsa/ntsa_uri.t.cpp index c19e03f1..2f40dd55 100644 --- a/groups/nts/ntsa/ntsa_uri.t.cpp +++ b/groups/nts/ntsa/ntsa_uri.t.cpp @@ -13,946 +13,921 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntsa_uri_t_cpp, "$Id$ $CSID$") + #include -#include #include #include #include #include -#include -#include -#include -#include -#include -#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsa { -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +// Provide tests for 'ntsa::Uri'. +class UriTest +{ + public: + // TODO + static void verifyCase1(); -// clang-format off -struct { - int d_success; - const char *d_output; -} DATA[] = { + // TODO + static void verifyCase2(); - {1, "scheme://host"}, + // TODO + static void verifyCase3(); - {1, "scheme://host?k1=p1"}, - {1, "scheme://host?k1=p1&k2=p2"}, - {1, "scheme://host?k1=p1&k2=p2&k3=p3"}, + // TODO + static void verifyCase4(); - {1, "scheme://host#anchor"}, + // TODO + static void verifyCase5(); +}; - {1, "scheme://host?k1=p1#anchor"}, - {1, "scheme://host?k1=p1&k2=p2#anchor"}, - {1, "scheme://host?k1=p1&k2=p2&k3=p3#anchor"}, +NTSCFG_TEST_FUNCTION(ntsa::UriTest::verifyCase1) +{ + // clang-format off + struct { + int d_success; + const char *d_output; + } DATA[] = { - {1, "scheme://host:12345"}, + {1, "scheme://host"}, - {1, "scheme://host:12345?k1=p1"}, - {1, "scheme://host:12345?k1=p1&k2=p2"}, - {1, "scheme://host:12345?k1=p1&k2=p2&k3=p3"}, + {1, "scheme://host?k1=p1"}, + {1, "scheme://host?k1=p1&k2=p2"}, + {1, "scheme://host?k1=p1&k2=p2&k3=p3"}, - {1, "scheme://host:12345#anchor"}, + {1, "scheme://host#anchor"}, - {1, "scheme://host:12345?k1=p1#anchor"}, - {1, "scheme://host:12345?k1=p1&k2=p2#anchor"}, - {1, "scheme://host:12345?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://host?k1=p1#anchor"}, + {1, "scheme://host?k1=p1&k2=p2#anchor"}, + {1, "scheme://host?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://host:12345/path"}, - {1, "scheme://host:12345/path#anchor"}, + {1, "scheme://host:12345"}, - {1, "scheme://host:12345/path?k1=p1#anchor"}, - {1, "scheme://host:12345/path?k1=p1&k2=p2#anchor"}, - {1, "scheme://host:12345/path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://host:12345?k1=p1"}, + {1, "scheme://host:12345?k1=p1&k2=p2"}, + {1, "scheme://host:12345?k1=p1&k2=p2&k3=p3"}, - {1, "scheme://host:12345/path/to"}, - {1, "scheme://host:12345/path/to#anchor"}, + {1, "scheme://host:12345#anchor"}, - {1, "scheme://host:12345/path/to?k1=p1#anchor"}, - {1, "scheme://host:12345/path/to?k1=p1&k2=p2#anchor"}, - {1, "scheme://host:12345/path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://host:12345?k1=p1#anchor"}, + {1, "scheme://host:12345?k1=p1&k2=p2#anchor"}, + {1, "scheme://host:12345?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://host:12345/path/to/resource"}, - {1, "scheme://host:12345/path/to/resource#anchor"}, + {1, "scheme://host:12345/path"}, + {1, "scheme://host:12345/path#anchor"}, - {1, "scheme://host:12345/path/to/resource?k1=p1#anchor"}, - {1, "scheme://host:12345/path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "scheme://host:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://host:12345/path?k1=p1#anchor"}, + {1, "scheme://host:12345/path?k1=p1&k2=p2#anchor"}, + {1, "scheme://host:12345/path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host"}, + {1, "scheme://host:12345/path/to"}, + {1, "scheme://host:12345/path/to#anchor"}, - {1, "scheme://user@host?k1=p1"}, - {1, "scheme://user@host?k1=p1&k2=p2"}, - {1, "scheme://user@host?k1=p1&k2=p2&k3=p3"}, + {1, "scheme://host:12345/path/to?k1=p1#anchor"}, + {1, "scheme://host:12345/path/to?k1=p1&k2=p2#anchor"}, + {1, "scheme://host:12345/path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host#anchor"}, + {1, "scheme://host:12345/path/to/resource"}, + {1, "scheme://host:12345/path/to/resource#anchor"}, - {1, "scheme://user@host?k1=p1#anchor"}, - {1, "scheme://user@host?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://host:12345/path/to/resource?k1=p1#anchor"}, + {1, "scheme://host:12345/path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "scheme://host:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host/path"}, - {1, "scheme://user@host/path#anchor"}, + {1, "scheme://user@host"}, - {1, "scheme://user@host/path?k1=p1#anchor"}, - {1, "scheme://user@host/path?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host/path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host?k1=p1"}, + {1, "scheme://user@host?k1=p1&k2=p2"}, + {1, "scheme://user@host?k1=p1&k2=p2&k3=p3"}, - {1, "scheme://user@host/path/to"}, - {1, "scheme://user@host/path/to#anchor"}, + {1, "scheme://user@host#anchor"}, - {1, "scheme://user@host/path/to?k1=p1#anchor"}, - {1, "scheme://user@host/path/to?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host/path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host?k1=p1#anchor"}, + {1, "scheme://user@host?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host/path/to/resource"}, - {1, "scheme://user@host/path/to/resource#anchor"}, + {1, "scheme://user@host/path"}, + {1, "scheme://user@host/path#anchor"}, - {1, "scheme://user@host/path/to/resource?k1=p1#anchor"}, - {1, "scheme://user@host/path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host/path?k1=p1#anchor"}, + {1, "scheme://user@host/path?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host/path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host:12345"}, + {1, "scheme://user@host/path/to"}, + {1, "scheme://user@host/path/to#anchor"}, - {1, "scheme://user@host:12345?k1=p1"}, - {1, "scheme://user@host:12345?k1=p1&k2=p2"}, - {1, "scheme://user@host:12345?k1=p1&k2=p2&k3=p3"}, + {1, "scheme://user@host/path/to?k1=p1#anchor"}, + {1, "scheme://user@host/path/to?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host/path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host:12345#anchor"}, + {1, "scheme://user@host/path/to/resource"}, + {1, "scheme://user@host/path/to/resource#anchor"}, - {1, "scheme://user@host:12345?k1=p1#anchor"}, - {1, "scheme://user@host:12345?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host:12345?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host/path/to/resource?k1=p1#anchor"}, + {1, "scheme://user@host/path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host:12345/path"}, - {1, "scheme://user@host:12345/path#anchor"}, + {1, "scheme://user@host:12345"}, - {1, "scheme://user@host:12345/path?k1=p1#anchor"}, - {1, "scheme://user@host:12345/path?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host:12345/path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host:12345?k1=p1"}, + {1, "scheme://user@host:12345?k1=p1&k2=p2"}, + {1, "scheme://user@host:12345?k1=p1&k2=p2&k3=p3"}, - {1, "scheme://user@host:12345/path/to"}, - {1, "scheme://user@host:12345/path/to#anchor"}, + {1, "scheme://user@host:12345#anchor"}, - {1, "scheme://user@host:12345/path/to?k1=p1#anchor"}, - {1, "scheme://user@host:12345/path/to?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host:12345/path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host:12345?k1=p1#anchor"}, + {1, "scheme://user@host:12345?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host:12345?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme://user@host:12345/path/to/resource"}, - {1, "scheme://user@host:12345/path/to/resource#anchor"}, + {1, "scheme://user@host:12345/path"}, + {1, "scheme://user@host:12345/path#anchor"}, - {1, "scheme://user@host:12345/path/to/resource?k1=p1#anchor"}, - {1, "scheme://user@host:12345/path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "scheme://user@host:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host:12345/path?k1=p1#anchor"}, + {1, "scheme://user@host:12345/path?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host:12345/path?k1=p1&k2=p2&k3=p3#anchor"}, - // This is treated by the parser as . -#if 0 - {1, "scheme:path"}, - {1, "scheme:path#anchor"}, + {1, "scheme://user@host:12345/path/to"}, + {1, "scheme://user@host:12345/path/to#anchor"}, - {1, "scheme:path?k1=p1"}, - {1, "scheme:path?k1=p1&k2=p2"}, - {1, "scheme:path?k1=p1&k2=p2&k3=p3"}, + {1, "scheme://user@host:12345/path/to?k1=p1#anchor"}, + {1, "scheme://user@host:12345/path/to?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host:12345/path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme:path?k1=p1#anchor"}, - {1, "scheme:path?k1=p1&k2=p2#anchor"}, - {1, "scheme:path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme://user@host:12345/path/to/resource"}, + {1, "scheme://user@host:12345/path/to/resource#anchor"}, - {1, "scheme:path/to"}, - {1, "scheme:path/to#anchor"}, + {1, "scheme://user@host:12345/path/to/resource?k1=p1#anchor"}, + {1, "scheme://user@host:12345/path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "scheme://user@host:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme:path/to?k1=p1"}, - {1, "scheme:path/to?k1=p1&k2=p2"}, - {1, "scheme:path/to?k1=p1&k2=p2&k3=p3"}, + // This is treated by the parser as . + #if 0 + {1, "scheme:path"}, + {1, "scheme:path#anchor"}, - {1, "scheme:path/to?k1=p1#anchor"}, - {1, "scheme:path/to?k1=p1&k2=p2#anchor"}, - {1, "scheme:path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme:path?k1=p1"}, + {1, "scheme:path?k1=p1&k2=p2"}, + {1, "scheme:path?k1=p1&k2=p2&k3=p3"}, - {1, "scheme:path/to/resource"}, - {1, "scheme:path/to/resource#anchor"}, + {1, "scheme:path?k1=p1#anchor"}, + {1, "scheme:path?k1=p1&k2=p2#anchor"}, + {1, "scheme:path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme:path/to/resource?k1=p1"}, - {1, "scheme:path/to/resource?k1=p1&k2=p2"}, - {1, "scheme:path/to/resource?k1=p1&k2=p2&k3=p3"}, + {1, "scheme:path/to"}, + {1, "scheme:path/to#anchor"}, - {1, "scheme:path/to/resource?k1=p1#anchor"}, - {1, "scheme:path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "scheme:path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, -#endif + {1, "scheme:path/to?k1=p1"}, + {1, "scheme:path/to?k1=p1&k2=p2"}, + {1, "scheme:path/to?k1=p1&k2=p2&k3=p3"}, - {1, "scheme:///path"}, - {1, "scheme:///path#anchor"}, + {1, "scheme:path/to?k1=p1#anchor"}, + {1, "scheme:path/to?k1=p1&k2=p2#anchor"}, + {1, "scheme:path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme:///path?k1=p1"}, - {1, "scheme:///path?k1=p1&k2=p2"}, - {1, "scheme:///path?k1=p1&k2=p2&k3=p3"}, + {1, "scheme:path/to/resource"}, + {1, "scheme:path/to/resource#anchor"}, - {1, "scheme:///path?k1=p1#anchor"}, - {1, "scheme:///path?k1=p1&k2=p2#anchor"}, - {1, "scheme:///path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme:path/to/resource?k1=p1"}, + {1, "scheme:path/to/resource?k1=p1&k2=p2"}, + {1, "scheme:path/to/resource?k1=p1&k2=p2&k3=p3"}, - {1, "scheme:///path/to"}, - {1, "scheme:///path/to#anchor"}, + {1, "scheme:path/to/resource?k1=p1#anchor"}, + {1, "scheme:path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "scheme:path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + #endif - {1, "scheme:///path/to?k1=p1"}, - {1, "scheme:///path/to?k1=p1&k2=p2"}, - {1, "scheme:///path/to?k1=p1&k2=p2&k3=p3"}, + {1, "scheme:///path"}, + {1, "scheme:///path#anchor"}, - {1, "scheme:///path/to?k1=p1#anchor"}, - {1, "scheme:///path/to?k1=p1&k2=p2#anchor"}, - {1, "scheme:///path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme:///path?k1=p1"}, + {1, "scheme:///path?k1=p1&k2=p2"}, + {1, "scheme:///path?k1=p1&k2=p2&k3=p3"}, - {1, "scheme:///path/to/resource"}, - {1, "scheme:///path/to/resource#anchor"}, + {1, "scheme:///path?k1=p1#anchor"}, + {1, "scheme:///path?k1=p1&k2=p2#anchor"}, + {1, "scheme:///path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "scheme:///path/to/resource?k1=p1"}, - {1, "scheme:///path/to/resource?k1=p1&k2=p2"}, - {1, "scheme:///path/to/resource?k1=p1&k2=p2&k3=p3"}, + {1, "scheme:///path/to"}, + {1, "scheme:///path/to#anchor"}, - {1, "scheme:///path/to/resource?k1=p1#anchor"}, - {1, "scheme:///path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "scheme:///path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme:///path/to?k1=p1"}, + {1, "scheme:///path/to?k1=p1&k2=p2"}, + {1, "scheme:///path/to?k1=p1&k2=p2&k3=p3"}, - {1, "path"}, - {1, "path#anchor"}, + {1, "scheme:///path/to?k1=p1#anchor"}, + {1, "scheme:///path/to?k1=p1&k2=p2#anchor"}, + {1, "scheme:///path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "path?k1=p1"}, - {1, "path?k1=p1&k2=p2"}, - {1, "path?k1=p1&k2=p2&k3=p3"}, + {1, "scheme:///path/to/resource"}, + {1, "scheme:///path/to/resource#anchor"}, - {1, "path?k1=p1#anchor"}, - {1, "path?k1=p1&k2=p2#anchor"}, - {1, "path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "scheme:///path/to/resource?k1=p1"}, + {1, "scheme:///path/to/resource?k1=p1&k2=p2"}, + {1, "scheme:///path/to/resource?k1=p1&k2=p2&k3=p3"}, - {1, "path/to"}, - {1, "path/to#anchor"}, + {1, "scheme:///path/to/resource?k1=p1#anchor"}, + {1, "scheme:///path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "scheme:///path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "path/to?k1=p1"}, - {1, "path/to?k1=p1&k2=p2"}, - {1, "path/to?k1=p1&k2=p2&k3=p3"}, + {1, "path"}, + {1, "path#anchor"}, - {1, "path/to?k1=p1#anchor"}, - {1, "path/to?k1=p1&k2=p2#anchor"}, - {1, "path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "path?k1=p1"}, + {1, "path?k1=p1&k2=p2"}, + {1, "path?k1=p1&k2=p2&k3=p3"}, - {1, "path/to/resource"}, - {1, "path/to/resource#anchor"}, + {1, "path?k1=p1#anchor"}, + {1, "path?k1=p1&k2=p2#anchor"}, + {1, "path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "path/to/resource?k1=p1"}, - {1, "path/to/resource?k1=p1&k2=p2"}, - {1, "path/to/resource?k1=p1&k2=p2&k3=p3"}, + {1, "path/to"}, + {1, "path/to#anchor"}, - {1, "path/to/resource?k1=p1#anchor"}, - {1, "path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "path/to?k1=p1"}, + {1, "path/to?k1=p1&k2=p2"}, + {1, "path/to?k1=p1&k2=p2&k3=p3"}, - {1, "/path"}, - {1, "/path#anchor"}, + {1, "path/to?k1=p1#anchor"}, + {1, "path/to?k1=p1&k2=p2#anchor"}, + {1, "path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "/path?k1=p1"}, - {1, "/path?k1=p1&k2=p2"}, - {1, "/path?k1=p1&k2=p2&k3=p3"}, + {1, "path/to/resource"}, + {1, "path/to/resource#anchor"}, - {1, "/path?k1=p1#anchor"}, - {1, "/path?k1=p1&k2=p2#anchor"}, - {1, "/path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "path/to/resource?k1=p1"}, + {1, "path/to/resource?k1=p1&k2=p2"}, + {1, "path/to/resource?k1=p1&k2=p2&k3=p3"}, - {1, "/path/to"}, - {1, "/path/to#anchor"}, + {1, "path/to/resource?k1=p1#anchor"}, + {1, "path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "/path/to?k1=p1"}, - {1, "/path/to?k1=p1&k2=p2"}, - {1, "/path/to?k1=p1&k2=p2&k3=p3"}, + {1, "/path"}, + {1, "/path#anchor"}, - {1, "/path/to?k1=p1#anchor"}, - {1, "/path/to?k1=p1&k2=p2#anchor"}, - {1, "/path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "/path?k1=p1"}, + {1, "/path?k1=p1&k2=p2"}, + {1, "/path?k1=p1&k2=p2&k3=p3"}, - {1, "/path/to/resource"}, - {1, "/path/to/resource#anchor"}, + {1, "/path?k1=p1#anchor"}, + {1, "/path?k1=p1&k2=p2#anchor"}, + {1, "/path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "/path/to/resource?k1=p1"}, - {1, "/path/to/resource?k1=p1&k2=p2"}, - {1, "/path/to/resource?k1=p1&k2=p2&k3=p3"}, + {1, "/path/to"}, + {1, "/path/to#anchor"}, - {1, "/path/to/resource?k1=p1#anchor"}, - {1, "/path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "/path/to?k1=p1"}, + {1, "/path/to?k1=p1&k2=p2"}, + {1, "/path/to?k1=p1&k2=p2&k3=p3"}, - {1, "host.domain/path"}, - {1, "host.domain/path#anchor"}, + {1, "/path/to?k1=p1#anchor"}, + {1, "/path/to?k1=p1&k2=p2#anchor"}, + {1, "/path/to?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "host.domain/path?k1=p1"}, - {1, "host.domain/path?k1=p1&k2=p2"}, - {1, "host.domain/path?k1=p1&k2=p2&k3=p3"}, + {1, "/path/to/resource"}, + {1, "/path/to/resource#anchor"}, - {1, "host.domain/path?k1=p1#anchor"}, - {1, "host.domain/path?k1=p1&k2=p2#anchor"}, - {1, "host.domain/path?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "/path/to/resource?k1=p1"}, + {1, "/path/to/resource?k1=p1&k2=p2"}, + {1, "/path/to/resource?k1=p1&k2=p2&k3=p3"}, - {1, "host.domain/path/to"}, - {1, "host.domain/path/to#anchor"}, + {1, "/path/to/resource?k1=p1#anchor"}, + {1, "/path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "host.domain/path/to?k1=p1"}, - {1, "host.domain/path/to?k1=p1&k2=p2"}, - {1, "host.domain/path/to?k1=p1&k2=p2&k3=p3"}, + {1, "host.domain/path"}, + {1, "host.domain/path#anchor"}, - {1, "host.domain/path/to?k1=p1#anchor"}, - {1, "host.domain/path/to?k1=p1&k2=p2#anchor"}, - {1, "host.domain/path/to?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "host.domain/path?k1=p1"}, + {1, "host.domain/path?k1=p1&k2=p2"}, + {1, "host.domain/path?k1=p1&k2=p2&k3=p3"}, - {1, "host.domain/path/to/resource"}, - {1, "host.domain/path/to/resource#anchor"}, + {1, "host.domain/path?k1=p1#anchor"}, + {1, "host.domain/path?k1=p1&k2=p2#anchor"}, + {1, "host.domain/path?k1=p1&k2=p2&k3=p3#anchor"}, - {1, "host.domain/path/to/resource?k1=p1"}, - {1, "host.domain/path/to/resource?k1=p1&k2=p2"}, - {1, "host.domain/path/to/resource?k1=p1&k2=p2&k3=p3"}, + {1, "host.domain/path/to"}, + {1, "host.domain/path/to#anchor"}, - {1, "host.domain/path/to/resource?k1=p1#anchor"}, - {1, "host.domain/path/to/resource?k1=p1&k2=p2#anchor"}, - {1, "host.domain/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, + {1, "host.domain/path/to?k1=p1"}, + {1, "host.domain/path/to?k1=p1&k2=p2"}, + {1, "host.domain/path/to?k1=p1&k2=p2&k3=p3"}, - { 1, "host.domain:12345/path" }, - { 1, "host.domain:12345/path#anchor" }, + {1, "host.domain/path/to?k1=p1#anchor"}, + {1, "host.domain/path/to?k1=p1&k2=p2#anchor"}, + {1, "host.domain/path/to?k1=p1&k2=p2&k3=p3#anchor"}, - { 1, "host.domain:12345/path?k1=p1" }, - { 1, "host.domain:12345/path?k1=p1&k2=p2" }, - { 1, "host.domain:12345/path?k1=p1&k2=p2&k3=p3" }, + {1, "host.domain/path/to/resource"}, + {1, "host.domain/path/to/resource#anchor"}, - { 1, "host.domain:12345/path?k1=p1#anchor" }, - { 1, "host.domain:12345/path?k1=p1&k2=p2#anchor" }, - { 1, "host.domain:12345/path?k1=p1&k2=p2&k3=p3#anchor" }, + {1, "host.domain/path/to/resource?k1=p1"}, + {1, "host.domain/path/to/resource?k1=p1&k2=p2"}, + {1, "host.domain/path/to/resource?k1=p1&k2=p2&k3=p3"}, - { 1, "host.domain:12345/path/to" }, - { 1, "host.domain:12345/path/to#anchor" }, + {1, "host.domain/path/to/resource?k1=p1#anchor"}, + {1, "host.domain/path/to/resource?k1=p1&k2=p2#anchor"}, + {1, "host.domain/path/to/resource?k1=p1&k2=p2&k3=p3#anchor"}, - { 1, "host.domain:12345/path/to?k1=p1" }, - { 1, "host.domain:12345/path/to?k1=p1&k2=p2" }, - { 1, "host.domain:12345/path/to?k1=p1&k2=p2&k3=p3" }, + { 1, "host.domain:12345/path" }, + { 1, "host.domain:12345/path#anchor" }, - { 1, "host.domain:12345/path/to?k1=p1#anchor" }, - { 1, "host.domain:12345/path/to?k1=p1&k2=p2#anchor" }, - { 1, "host.domain:12345/path/to?k1=p1&k2=p2&k3=p3#anchor" }, + { 1, "host.domain:12345/path?k1=p1" }, + { 1, "host.domain:12345/path?k1=p1&k2=p2" }, + { 1, "host.domain:12345/path?k1=p1&k2=p2&k3=p3" }, - { 1, "host.domain:12345/path/to/resource" }, - { 1, "host.domain:12345/path/to/resource#anchor" }, + { 1, "host.domain:12345/path?k1=p1#anchor" }, + { 1, "host.domain:12345/path?k1=p1&k2=p2#anchor" }, + { 1, "host.domain:12345/path?k1=p1&k2=p2&k3=p3#anchor" }, - { 1, "host.domain:12345/path/to/resource?k1=p1" }, - { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2" }, - { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2&k3=p3" }, + { 1, "host.domain:12345/path/to" }, + { 1, "host.domain:12345/path/to#anchor" }, - { 1, "host.domain:12345/path/to/resource?k1=p1#anchor" }, - { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2#anchor" }, - { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor" } -}; -// clang-format on + { 1, "host.domain:12345/path/to?k1=p1" }, + { 1, "host.domain:12345/path/to?k1=p1&k2=p2" }, + { 1, "host.domain:12345/path/to?k1=p1&k2=p2&k3=p3" }, -enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; + { 1, "host.domain:12345/path/to?k1=p1#anchor" }, + { 1, "host.domain:12345/path/to?k1=p1&k2=p2#anchor" }, + { 1, "host.domain:12345/path/to?k1=p1&k2=p2&k3=p3#anchor" }, -NTSCFG_TEST_CASE(1) -{ - // Concern: - // Plan: + { 1, "host.domain:12345/path/to/resource" }, + { 1, "host.domain:12345/path/to/resource#anchor" }, - ntscfg::TestAllocator ta; - { - ntsa::Error error; + { 1, "host.domain:12345/path/to/resource?k1=p1" }, + { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2" }, + { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2&k3=p3" }, - for (int i = 0; i < NUM_DATA; ++i) { - ntsa::Uri uri(&ta); + { 1, "host.domain:12345/path/to/resource?k1=p1#anchor" }, + { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2#anchor" }, + { 1, "host.domain:12345/path/to/resource?k1=p1&k2=p2&k3=p3#anchor" } + }; + // clang-format on - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "--" << bsl::endl; - bsl::cout << "URI: " << DATA[i].d_output << bsl::endl; - } + enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; - bool isValid = uri.parse(DATA[i].d_output); - if (!DATA[i].d_success) { - NTSCFG_TEST_FALSE(isValid); + ntsa::Error error; - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " - << "INVALID" << bsl::endl; - } - } - else { - NTSCFG_TEST_TRUE(isValid); + for (int i = 0; i < NUM_DATA; ++i) { + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); + + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "--" << bsl::endl; + bsl::cout << "URI: " << DATA[i].d_output << bsl::endl; + } + + bool isValid = uri.parse(DATA[i].d_output); + if (!DATA[i].d_success) { + NTSCFG_TEST_FALSE(isValid); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " + << "INVALID" << bsl::endl; + } + } + else { + NTSCFG_TEST_TRUE(isValid); - bsl::string uri_string = uri.text(); + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri << bsl::endl; + } - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri_string << bsl::endl; - } + bsl::string uri_string = uri.text(); - NTSCFG_TEST_EQ(uri_string, bsl::string(DATA[i].d_output)); + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri_string << bsl::endl; } + + NTSCFG_TEST_EQ(uri_string, bsl::string(DATA[i].d_output)); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsa::UriTest::verifyCase2) { - // Concern: - // Plan: + ntsa::Error error; - ntscfg::TestAllocator ta; { - ntsa::Error error; - - { - const bsl::string text = "localhost"; + const bsl::string text = "localhost"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_TRUE(uri.scheme().isNull()); + NTSCFG_TEST_TRUE(uri.scheme().isNull()); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); - } + NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); + } - { - const bsl::string text = "localhost:80"; + { + const bsl::string text = "localhost:80"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_TRUE(uri.scheme().isNull()); + NTSCFG_TEST_TRUE(uri.scheme().isNull()); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); - NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); - } + NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); + NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); + } - { - const bsl::string text = "tcp://localhost"; + { + const bsl::string text = "tcp://localhost"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "tcp"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "tcp"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); - } + NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); + } - { - const bsl::string text = "tcp://localhost:80"; + { + const bsl::string text = "tcp://localhost:80"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "tcp"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "tcp"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); - NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); - } + NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); + NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); + } - { - const bsl::string text = "udp://localhost"; + { + const bsl::string text = "udp://localhost"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "udp"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "udp"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); - } + NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); + } - { - const bsl::string text = "udp://localhost:80"; + { + const bsl::string text = "udp://localhost:80"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "udp"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "udp"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); - NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); - } + NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); + NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); + } - { - const bsl::string text = "unix://localhost"; + { + const bsl::string text = "unix://localhost"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); - } + NTSCFG_TEST_TRUE(uri.authority().value().port().isNull()); + } - { - const bsl::string text = "unix://localhost:80"; + { + const bsl::string text = "unix://localhost:80"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); - NTSCFG_TEST_FALSE(uri.authority().isNull()); + NTSCFG_TEST_FALSE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); + NTSCFG_TEST_FALSE(uri.authority().value().host().isNull()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().isDomainName()); - NTSCFG_TEST_TRUE( - uri.authority().value().host().value().domainName().equals( - "localhost")); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().isDomainName()); + NTSCFG_TEST_TRUE( + uri.authority().value().host().value().domainName().equals( + "localhost")); - NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); - NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); - } + NTSCFG_TEST_FALSE(uri.authority().value().port().isNull()); + NTSCFG_TEST_EQ(uri.authority().value().port().value(), 80); + } - { - const bsl::string text = "/path"; + { + const bsl::string text = "/path"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_TRUE(uri.scheme().isNull()); + NTSCFG_TEST_TRUE(uri.scheme().isNull()); - NTSCFG_TEST_TRUE(uri.authority().isNull()); + NTSCFG_TEST_TRUE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.path().isNull()); - NTSCFG_TEST_EQ(uri.path().value(), "/path"); - } + NTSCFG_TEST_FALSE(uri.path().isNull()); + NTSCFG_TEST_EQ(uri.path().value(), "/path"); + } - { - const bsl::string text = "/path/to/resource"; + { + const bsl::string text = "/path/to/resource"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_TRUE(uri.scheme().isNull()); + NTSCFG_TEST_TRUE(uri.scheme().isNull()); - NTSCFG_TEST_TRUE(uri.authority().isNull()); + NTSCFG_TEST_TRUE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.path().isNull()); - NTSCFG_TEST_EQ(uri.path().value(), "/path/to/resource"); - } + NTSCFG_TEST_FALSE(uri.path().isNull()); + NTSCFG_TEST_EQ(uri.path().value(), "/path/to/resource"); + } - { - const bsl::string text = "unix:///path"; + { + const bsl::string text = "unix:///path"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); - NTSCFG_TEST_TRUE(uri.authority().isNull()); + NTSCFG_TEST_TRUE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.path().isNull()); - NTSCFG_TEST_EQ(uri.path().value(), "/path"); - } + NTSCFG_TEST_FALSE(uri.path().isNull()); + NTSCFG_TEST_EQ(uri.path().value(), "/path"); + } - { - const bsl::string text = "unix:///path/to/resource"; + { + const bsl::string text = "unix:///path/to/resource"; - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - bool parseResult = uri.parse(text); - NTSCFG_TEST_TRUE(parseResult); + bool parseResult = uri.parse(text); + NTSCFG_TEST_TRUE(parseResult); - NTSCFG_TEST_FALSE(uri.scheme().isNull()); - NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); + NTSCFG_TEST_FALSE(uri.scheme().isNull()); + NTSCFG_TEST_EQ(uri.scheme().value(), "unix"); - NTSCFG_TEST_TRUE(uri.authority().isNull()); + NTSCFG_TEST_TRUE(uri.authority().isNull()); - NTSCFG_TEST_FALSE(uri.path().isNull()); - NTSCFG_TEST_EQ(uri.path().value(), "/path/to/resource"); - } + NTSCFG_TEST_FALSE(uri.path().isNull()); + NTSCFG_TEST_EQ(uri.path().value(), "/path/to/resource"); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsa::UriTest::verifyCase3) { - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - { - ntsa::Endpoint endpoint( - ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), 80)); + { + ntsa::Endpoint endpoint( + ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), 80)); - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } + } - { - ntsa::Endpoint endpoint( - ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), 80)); + { + ntsa::Endpoint endpoint( + ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), 80)); - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setScheme("http"); - NTSCFG_TEST_OK(error); + error = uri.setScheme("http"); + NTSCFG_TEST_OK(error); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } + } - { - ntsa::Endpoint endpoint( - ntsa::IpEndpoint(ntsa::Ipv6Address::loopback(), 80)); + { + ntsa::Endpoint endpoint( + ntsa::IpEndpoint(ntsa::Ipv6Address::loopback(), 80)); - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } + } - { - ntsa::Endpoint endpoint( - ntsa::IpEndpoint(ntsa::Ipv6Address::loopback(), 80)); + { + ntsa::Endpoint endpoint( + ntsa::IpEndpoint(ntsa::Ipv6Address::loopback(), 80)); - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setScheme("http"); - NTSCFG_TEST_OK(error); + error = uri.setScheme("http"); + NTSCFG_TEST_OK(error); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } + } - { - ntsa::LocalName localName; - localName.setValue("/tmp/ntf/socket"); + { + ntsa::LocalName localName; + localName.setValue("/tmp/ntf/socket"); - ntsa::Endpoint endpoint(localName); + ntsa::Endpoint endpoint(localName); - ntsa::Uri uri(&ta); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } + } - { - ntsa::LocalName localName; - localName.setValue("/tmp/ntf/socket"); - - ntsa::Endpoint endpoint(localName); + { + ntsa::LocalName localName; + localName.setValue("/tmp/ntf/socket"); - ntsa::Uri uri(&ta); + ntsa::Endpoint endpoint(localName); - error = uri.setScheme("http"); - NTSCFG_TEST_OK(error); + ntsa::Uri uri(NTSCFG_TEST_ALLOCATOR); - error = uri.setEndpoint(endpoint); - NTSCFG_TEST_OK(error); + error = uri.setScheme("http"); + NTSCFG_TEST_OK(error); - error = uri.setPath("path/to/resource"); - NTSCFG_TEST_OK(error); + error = uri.setEndpoint(endpoint); + NTSCFG_TEST_OK(error); - if (NTSCFG_TEST_VERBOSITY) { - bsl::cout << "URI: " << uri.text() - << " (endpoint: " << endpoint << ")" << bsl::endl; - } + error = uri.setPath("path/to/resource"); + NTSCFG_TEST_OK(error); + + if (NTSCFG_TEST_VERBOSITY) { + bsl::cout << "URI: " << uri.text() << " (endpoint: " << endpoint + << ")" << bsl::endl; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsa::UriTest::verifyCase4) { int rc; - ntscfg::TestAllocator ta; - { - ntsa::Uri e1; - ntsa::Uri e2; + ntsa::Uri e1; + ntsa::Uri e2; - bool valid = - e1.parse("http://10.26.55.100:12345/path/to/resource?foo=bar#baz"); - NTSCFG_TEST_TRUE(valid); + bool valid = + e1.parse("http://10.26.55.100:12345/path/to/resource?foo=bar#baz"); + NTSCFG_TEST_TRUE(valid); - bdlsb::MemOutStreamBuf osb(&ta); + bdlsb::MemOutStreamBuf osb(NTSCFG_TEST_ALLOCATOR); - balber::BerEncoder encoder(0, &ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; - - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerEncoder encoder(0, NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" - << bdlb::PrintStringHexDumper( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded:\n" + << bdlb::PrintStringHexDumper( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - balber::BerDecoder decoder(0, &ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + balber::BerDecoder decoder(0, NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2, e1); + NTSCFG_TEST_EQ(rc, 0); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); + + NTSCFG_TEST_EQ(e2, e1); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsa::UriTest::verifyCase5) { int rc; - ntscfg::TestAllocator ta; - { - bsl::vector e1(&ta); - bsl::vector e2(&ta); + bsl::vector e1(NTSCFG_TEST_ALLOCATOR); + bsl::vector e2(NTSCFG_TEST_ALLOCATOR); - { - ntsa::Uri element; + { + ntsa::Uri element; - bool valid = element.parse( - "http://ntf.example.com:12345/path/to/resource?foo=bar#baz"); - NTSCFG_TEST_TRUE(valid); + bool valid = element.parse( + "http://ntf.example.com:12345/path/to/resource?foo=bar#baz"); + NTSCFG_TEST_TRUE(valid); - e1.push_back(element); - } + e1.push_back(element); + } - { - ntsa::Uri element; - - bool valid = element.parse( - "http://10.26.55.100:12345/path/to/resource?foo=bar#baz"); - NTSCFG_TEST_TRUE(valid); + { + ntsa::Uri element; - e1.push_back(element); - } + bool valid = element.parse( + "http://10.26.55.100:12345/path/to/resource?foo=bar#baz"); + NTSCFG_TEST_TRUE(valid); - { - ntsa::Uri element; + e1.push_back(element); + } - ntsa::LocalName localName; - localName.setValue("/tmp/ntf/socket"); + { + ntsa::Uri element; - element.setEndpoint(ntsa::Endpoint(localName)); + ntsa::LocalName localName; + localName.setValue("/tmp/ntf/socket"); - e1.push_back(element); - } + element.setEndpoint(ntsa::Endpoint(localName)); - bdlsb::MemOutStreamBuf osb; + e1.push_back(element); + } - baljsn::Encoder encoder(&ta); - rc = encoder.encode(&osb, e1); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::MemOutStreamBuf osb; - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Encoder encoder(NTSCFG_TEST_ALLOCATOR); + rc = encoder.encode(&osb, e1); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - rc = osb.pubsync(); NTSCFG_TEST_EQ(rc, 0); + } - NTSCFG_TEST_GT(osb.length(), 0); - NTSCFG_TEST_NE(osb.data(), 0); + rc = osb.pubsync(); + NTSCFG_TEST_EQ(rc, 0); - NTSCFG_TEST_LOG_DEBUG << "Encoded: " - << bsl::string_view( - osb.data(), - static_cast(osb.length())) - << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_GT(osb.length(), 0); + NTSCFG_TEST_NE(osb.data(), 0); - bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); + NTSCFG_TEST_LOG_DEBUG << "Encoded: " + << bsl::string_view( + osb.data(), + static_cast(osb.length())) + << NTSCFG_TEST_LOG_END; - baljsn::Decoder decoder(&ta); - rc = decoder.decode(&isb, &e2); - if (rc != 0) { - NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() - << NTSCFG_TEST_LOG_END; + bdlsb::FixedMemInStreamBuf isb(osb.data(), osb.length()); - NTSCFG_TEST_EQ(rc, 0); - } + baljsn::Decoder decoder(NTSCFG_TEST_ALLOCATOR); + rc = decoder.decode(&isb, &e2); + if (rc != 0) { + NTSCFG_TEST_LOG_DEBUG << encoder.loggedMessages() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_EQ(e2.size(), e1.size()); + NTSCFG_TEST_EQ(rc, 0); + } - for (bsl::size_t i = 0; i < e1.size(); ++i) { - NTSCFG_TEST_EQ(e2[i], e1[i]); - } + NTSCFG_TEST_EQ(e2.size(), e1.size()); + + for (bsl::size_t i = 0; i < e1.size(); ++i) { + NTSCFG_TEST_EQ(e2[i], e1[i]); } - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsa/ntsa_zerocopy.t.cpp b/groups/nts/ntsa/ntsa_zerocopy.t.cpp index 5db35756..2d59e823 100644 --- a/groups/nts/ntsa/ntsa_zerocopy.t.cpp +++ b/groups/nts/ntsa/ntsa_zerocopy.t.cpp @@ -13,14 +13,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include +#include +BSLS_IDENT_RCSID(ntsa_zerocopy_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -using namespace ntsa; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsa { + +// Provide tests for 'ntsa::ZeroCopy'. +class ZeroCopyTest +{ + public: + // TODO + static void verify(); +}; + +NTSCFG_TEST_FUNCTION(ntsa::ZeroCopyTest::verify) { { ZeroCopy zc; @@ -28,6 +41,7 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(zc.thru(), 0); NTSCFG_TEST_EQ(zc.type(), ntsa::ZeroCopyType::e_AVOIDED); } + { const bsl::uint32_t from = 5; const bsl::uint32_t thru = 15; @@ -38,6 +52,7 @@ NTSCFG_TEST_CASE(1) NTSCFG_TEST_EQ(zc.thru(), thru); NTSCFG_TEST_EQ(zc.type(), type); } + { const bsl::uint32_t from = 10; const bsl::uint32_t thru = 22; @@ -56,8 +71,5 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsa +} // close namespace BloombergLP diff --git a/groups/nts/ntsb/ntsb_controller.t.cpp b/groups/nts/ntsb/ntsb_controller.t.cpp index b85d7a10..372effc4 100644 --- a/groups/nts/ntsb/ntsb_controller.t.cpp +++ b/groups/nts/ntsb/ntsb_controller.t.cpp @@ -13,39 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -using namespace BloombergLP; +#include +BSLS_IDENT_RCSID(ntsb_controller_t_cpp, "$Id$ $CSID$") -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +#include -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +using namespace BloombergLP; -NTSCFG_TEST_CASE(1) -{ - // Concern: - // Plan: +namespace BloombergLP { +namespace ntsb { - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} +// Provide tests for 'ntsb::Controller'. +class ControllerTest +{ + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsb::ControllerTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsb +} // close namespace BloombergLP diff --git a/groups/nts/ntsb/ntsb_datagramsocket.cpp b/groups/nts/ntsb/ntsb_datagramsocket.cpp index 9dace287..44b20121 100644 --- a/groups/nts/ntsb/ntsb_datagramsocket.cpp +++ b/groups/nts/ntsb/ntsb_datagramsocket.cpp @@ -109,7 +109,7 @@ ntsa::Error DatagramSocket::send(ntsa::SendContext* context, } ntsa::Error DatagramSocket::send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) { @@ -197,21 +197,25 @@ ntsa::Error DatagramSocket::joinMulticastGroup( } ntsa::Error DatagramSocket::joinMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { - return ntsu::SocketOptionUtil::joinMulticastGroupSource( - d_handle, interface, group, source); + return ntsu::SocketOptionUtil::joinMulticastGroupSource(d_handle, + interface, + group, + source); } ntsa::Error DatagramSocket::leaveMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { - return ntsu::SocketOptionUtil::leaveMulticastGroupSource( - d_handle, interface, group, source); + return ntsu::SocketOptionUtil::leaveMulticastGroupSource(d_handle, + interface, + group, + source); } ntsa::Error DatagramSocket::leaveMulticastGroup( diff --git a/groups/nts/ntsb/ntsb_datagramsocket.h b/groups/nts/ntsb/ntsb_datagramsocket.h index a5b900ed..6d920a31 100644 --- a/groups/nts/ntsb/ntsb_datagramsocket.h +++ b/groups/nts/ntsb/ntsb_datagramsocket.h @@ -112,7 +112,7 @@ class DatagramSocket : public ntsi::DatagramSocket /// the specified 'context' the result of the operation. Return the /// error. ntsa::Error send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) BSLS_KEYWORD_OVERRIDE; @@ -198,10 +198,10 @@ class DatagramSocket : public ntsi::DatagramSocket /// only from the specified 'source'. Return the error. Note that this /// function may be called multiple times to allow receiving multicast /// datagrams only from a particular set of source addresses. - ntsa::Error joinMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) BSLS_KEYWORD_OVERRIDE; + ntsa::Error joinMulticastGroupSource(const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) + BSLS_KEYWORD_OVERRIDE; /// Leave the specified source-specific multicast 'group' on the adapter /// identified by the specified 'interface', disallowing datagrams sent by @@ -209,10 +209,10 @@ class DatagramSocket : public ntsi::DatagramSocket /// subscribed to multiple sources within the same group, data from the /// remaining sources will still be delivered. To stop receiving data from /// all sources at once, use 'leaveMulticastGroup'. - ntsa::Error leaveMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) BSLS_KEYWORD_OVERRIDE; + ntsa::Error leaveMulticastGroupSource(const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) + BSLS_KEYWORD_OVERRIDE; // *** Socket Options *** diff --git a/groups/nts/ntsb/ntsb_datagramsocket.t.cpp b/groups/nts/ntsb/ntsb_datagramsocket.t.cpp index 3bf8a697..ed8a8a4b 100644 --- a/groups/nts/ntsb/ntsb_datagramsocket.t.cpp +++ b/groups/nts/ntsb/ntsb_datagramsocket.t.cpp @@ -13,130 +13,53 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntsb_datagramsocket_t_cpp, "$Id$ $CSID$") + #include -#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include using namespace BloombergLP; -// On Linux, at least, sendto on a local datagram socket created and connected -// by ::socketpair returns EINVAL even when the peer address matches the source -// address of the peer. -#define NTSB_DATAGRAMSOCKETTESTER_SENDTO_RECEIVEFROM 0 - -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- - -namespace test { - -namespace { - -/// Provide a suite of utilities for generating test data. -/// This struct is completely thread safe. -struct DataUtil { - /// Return the byte at the specified 'position' in the specified - /// 'dataset'. - static char generateByte(int position, int dataset); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bsl::string* result, - int size, - int offset = 0, - int dataset = 0); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bdlbb::Blob* result, - int size, - int offset = 0, - int dataset = 0); -}; - -char DataUtil::generateByte(int position, int dataset) -{ - struct { - const char* source; - int length; - } DATA[] = { - {"abcdefghijklmnopqrstuvwxyz", 26}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26} - }; - - enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; - - dataset = dataset % NUM_DATA; - return DATA[dataset].source[position % DATA[dataset].length]; -} - -void DataUtil::generateData(bsl::string* result, - int size, - int offset, - int dataset) -{ - result->clear(); - result->resize(size); - - for (int i = offset; i < offset + size; ++i) { - (*result)[i] = generateByte(offset + i, dataset); - } -} +namespace BloombergLP { +namespace ntsb { -void DataUtil::generateData(bdlbb::Blob* result, - int size, - int offset, - int dataset) +// Provide tests for 'ntsb::DatagramSocket'. +class DatagramSocketTest { - result->removeAll(); - result->setLength(size); - - int k = 0; + public: + // TODO + static void verifyCase1(); - for (int i = 0; i < result->numDataBuffers(); ++i) { - const bdlbb::BlobBuffer& buffer = result->buffer(i); + // TODO + static void verifyCase2(); - int numBytesToWrite = i == result->numDataBuffers() - 1 - ? result->lastDataBufferLength() - : buffer.size(); + private: + /// Test the implementations of the specified 'client' and 'server' + /// send and receive data correctly using basic, contiguous buffers. + /// Optionally specify a 'basicAllocator' used to supply memory. If + /// 'basicAllocator' is 0, the currently installed default allocator + /// is used. + static void testBufferIO( + const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator = 0); - for (int j = 0; j < numBytesToWrite; ++j) { - buffer.data()[j] = generateByte(offset + k, dataset); - ++k; - } - } -} + /// Test the implementations of the specified 'client' and 'server' + /// send and receive data correctly using vectored I/O and the + /// scatter/gather paradigm. Optionally specify a 'basicAllocator' used + /// to supply memory. If 'basicAllocator' is 0, the currently installed + /// default allocator is used. + static void testVectorIO( + const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator = 0); -/// Provide utilities for sending and receiving data. -struct AsyncUtil { /// Send from the specified 'client' all the specified 'clientData' /// to the peer of the 'client'. static void sendString(const bsl::shared_ptr& client, @@ -175,11 +98,263 @@ struct AsyncUtil { bslma::Allocator* allocator); }; -void AsyncUtil::sendString(const bsl::shared_ptr& client, - const ntsa::Endpoint& serverEndpoint, - const bsl::string* clientData, - bsl::size_t numMessages, - bslma::Allocator* allocator) +// On Linux, at least, sendto on a local datagram socket created and connected +// by ::socketpair returns EINVAL even when the peer address matches the source +// address of the peer. +#define NTSB_DATAGRAMSOCKETTESTER_SENDTO_RECEIVEFROM 0 + +NTSCFG_TEST_FUNCTION(ntsb::DatagramSocketTest::verifyCase1) +{ + // Concern: Datagram socket buffer I/O + // Plan: + + bsl::vector socketTypes; + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_UDP_IPV4_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + } + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_UDP_IPV6_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + } + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_LOCAL_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_LOCAL_DATAGRAM); + } + + for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { + ntsa::Transport::Value transport = socketTypes[i]; + + ntscfg::TestAllocator ta; + { + ntsa::Error error; + + bsl::shared_ptr client; + bsl::shared_ptr server; + + error = + ntsb::DatagramSocket::pair(&client, &server, transport, &ta); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + DatagramSocketTest::testBufferIO(client, server, &ta); + + error = client->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + error = server->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + } + NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + } +} + +NTSCFG_TEST_FUNCTION(ntsb::DatagramSocketTest::verifyCase2) +{ + // Concern: Datagram socket vector I/O + // Plan: + + bsl::vector socketTypes; + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_UDP_IPV4_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + } + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_UDP_IPV6_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + } + + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_LOCAL_DATAGRAM)) + { + socketTypes.push_back(ntsa::Transport::e_LOCAL_DATAGRAM); + } + + for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { + ntsa::Transport::Value transport = socketTypes[i]; + + ntscfg::TestAllocator ta; + { + ntsa::Error error; + + bsl::shared_ptr client; + bsl::shared_ptr server; + + error = + ntsb::DatagramSocket::pair(&client, &server, transport, &ta); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + DatagramSocketTest::testVectorIO(client, server, &ta); + + error = client->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + error = server->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + } + NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + } +} + +void DatagramSocketTest::testBufferIO( + const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator) +{ + bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); + + ntsa::Error error; + + const bsl::size_t NUM_MESSAGES = 100000; // was: 100 + const bsl::size_t MESSAGE_SIZE = 1024 * 32; // was: 256 + + ntsa::Endpoint clientSourceEndpoint; + error = client->sourceEndpoint(&clientSourceEndpoint); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + ntsa::Endpoint serverSourceEndpoint; + error = server->sourceEndpoint(&serverSourceEndpoint); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + bsl::string clientData(allocator); + ntscfg::TestDataUtil::generateData(&clientData, MESSAGE_SIZE); + + bsls::AtomicInt numMessagesReceived; + + bslmt::ThreadGroup threadGroup(allocator); + threadGroup.addThread(bdlf::BindUtil::bind(&DatagramSocketTest::sendString, + client, + serverSourceEndpoint, + &clientData, + NUM_MESSAGES, + allocator)); + + threadGroup.addThread( + bdlf::BindUtil::bind(&DatagramSocketTest::receiveString, + server, + clientSourceEndpoint, + &clientData, + NUM_MESSAGES, + &numMessagesReceived, + allocator)); + + threadGroup.joinAll(); + + { + bsl::string clientSourceEndpointDescription; + { + bsl::stringstream ss; + ss << clientSourceEndpoint; + clientSourceEndpointDescription = ss.str(); + } + + bsl::string serverSourceEndpointDescription; + { + bsl::stringstream ss; + ss << serverSourceEndpoint; + serverSourceEndpointDescription = ss.str(); + } + + BSLS_LOG_INFO( + "Test buffer I/O %d/%d (%d%%) complete " + "using datagram socket pair %s / %s", + numMessagesReceived.load(), + NUM_MESSAGES, + int(((double(numMessagesReceived.load()) / NUM_MESSAGES) * 100)), + clientSourceEndpointDescription.c_str(), + serverSourceEndpointDescription.c_str()); + } +} + +void DatagramSocketTest::testVectorIO( + const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator) +{ + bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); + + ntsa::Error error; + + const bsl::size_t NUM_MESSAGES = 100000; // was: 100 + const bsl::size_t MESSAGE_SIZE = 1024 * 32; // was: 256 + + ntsa::Endpoint clientSourceEndpoint; + error = client->sourceEndpoint(&clientSourceEndpoint); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + ntsa::Endpoint serverSourceEndpoint; + error = server->sourceEndpoint(&serverSourceEndpoint); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + + bdlbb::PooledBlobBufferFactory blobBufferFactory(MESSAGE_SIZE / 8, + allocator); + + bdlbb::Blob clientData(&blobBufferFactory, allocator); + ntscfg::TestDataUtil::generateData(&clientData, MESSAGE_SIZE); + + bsls::AtomicInt numMessagesReceived; + + bslmt::ThreadGroup threadGroup(allocator); + threadGroup.addThread(bdlf::BindUtil::bind(&DatagramSocketTest::sendBlob, + client, + serverSourceEndpoint, + &clientData, + NUM_MESSAGES, + allocator)); + + threadGroup.addThread( + bdlf::BindUtil::bind(&DatagramSocketTest::receiveBlob, + server, + clientSourceEndpoint, + &clientData, + NUM_MESSAGES, + &numMessagesReceived, + &blobBufferFactory, + allocator)); + + threadGroup.joinAll(); + + { + bsl::string clientSourceEndpointDescription; + { + bsl::stringstream ss; + ss << clientSourceEndpoint; + clientSourceEndpointDescription = ss.str(); + } + + bsl::string serverSourceEndpointDescription; + { + bsl::stringstream ss; + ss << serverSourceEndpoint; + serverSourceEndpointDescription = ss.str(); + } + + BSLS_LOG_INFO( + "Test buffer I/O %d/%d (%d%%) complete " + "using datagram socket pair %s / %s", + numMessagesReceived.load(), + NUM_MESSAGES, + int(((double(numMessagesReceived.load()) / NUM_MESSAGES) * 100)), + clientSourceEndpointDescription.c_str(), + serverSourceEndpointDescription.c_str()); + } +} + +void DatagramSocketTest::sendString( + const bsl::shared_ptr& client, + const ntsa::Endpoint& serverEndpoint, + const bsl::string* clientData, + bsl::size_t numMessages, + bslma::Allocator* allocator) { NTSCFG_WARNING_UNUSED(allocator); @@ -240,7 +415,7 @@ void AsyncUtil::sendString(const bsl::shared_ptr& client, } } -void AsyncUtil::receiveString( +void DatagramSocketTest::receiveString( const bsl::shared_ptr& server, const ntsa::Endpoint& clientEndpoint, const bsl::string* clientData, @@ -300,11 +475,12 @@ void AsyncUtil::receiveString( } } -void AsyncUtil::sendBlob(const bsl::shared_ptr& client, - const ntsa::Endpoint& serverEndpoint, - const bdlbb::Blob* clientData, - bsl::size_t numMessages, - bslma::Allocator* allocator) +void DatagramSocketTest::sendBlob( + const bsl::shared_ptr& client, + const ntsa::Endpoint& serverEndpoint, + const bdlbb::Blob* clientData, + bsl::size_t numMessages, + bslma::Allocator* allocator) { NTSCFG_WARNING_UNUSED(allocator); @@ -361,7 +537,7 @@ void AsyncUtil::sendBlob(const bsl::shared_ptr& client, } } -void AsyncUtil::receiveBlob( +void DatagramSocketTest::receiveBlob( const bsl::shared_ptr& server, const ntsa::Endpoint& clientEndpoint, const bdlbb::Blob* clientData, @@ -420,281 +596,5 @@ void AsyncUtil::receiveBlob( } } -} // close unnamed namespace - -/// Provide facilities to test different datagram sockets -/// conveniently in one place. -struct DatagramSocketTester { - /// Test the implementations of the specified 'client' and 'server' - /// send and receive data correctly using basic, contiguous buffers. - /// Optionally specify a 'basicAllocator' used to supply memory. If - /// 'basicAllocator' is 0, the currently installed default allocator - /// is used. - static void testBufferIO( - const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator = 0); - - /// Test the implementations of the specified 'client' and 'server' - /// send and receive data correctly using vectored I/O and the - /// scatter/gather paradigm. Optionally specify a 'basicAllocator' used - /// to supply memory. If 'basicAllocator' is 0, the currently installed - /// default allocator is used. - static void testVectorIO( - const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator = 0); -}; - -void DatagramSocketTester::testBufferIO( - const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator) -{ - bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); - - ntsa::Error error; - - const bsl::size_t NUM_MESSAGES = 100000; // was: 100 - const bsl::size_t MESSAGE_SIZE = 1024 * 32; // was: 256 - - ntsa::Endpoint clientSourceEndpoint; - error = client->sourceEndpoint(&clientSourceEndpoint); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - ntsa::Endpoint serverSourceEndpoint; - error = server->sourceEndpoint(&serverSourceEndpoint); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - bsl::string clientData(allocator); - DataUtil::generateData(&clientData, MESSAGE_SIZE); - - bsls::AtomicInt numMessagesReceived; - - bslmt::ThreadGroup threadGroup(allocator); - threadGroup.addThread(bdlf::BindUtil::bind(&AsyncUtil::sendString, - client, - serverSourceEndpoint, - &clientData, - NUM_MESSAGES, - allocator)); - - threadGroup.addThread(bdlf::BindUtil::bind(&AsyncUtil::receiveString, - server, - clientSourceEndpoint, - &clientData, - NUM_MESSAGES, - &numMessagesReceived, - allocator)); - - threadGroup.joinAll(); - - { - bsl::string clientSourceEndpointDescription; - { - bsl::stringstream ss; - ss << clientSourceEndpoint; - clientSourceEndpointDescription = ss.str(); - } - - bsl::string serverSourceEndpointDescription; - { - bsl::stringstream ss; - ss << serverSourceEndpoint; - serverSourceEndpointDescription = ss.str(); - } - - BSLS_LOG_INFO( - "Test buffer I/O %d/%d (%d%%) complete " - "using datagram socket pair %s / %s", - numMessagesReceived.load(), - NUM_MESSAGES, - int(((double(numMessagesReceived.load()) / NUM_MESSAGES) * 100)), - clientSourceEndpointDescription.c_str(), - serverSourceEndpointDescription.c_str()); - } -} - -void DatagramSocketTester::testVectorIO( - const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator) -{ - bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); - - ntsa::Error error; - - const bsl::size_t NUM_MESSAGES = 100000; // was: 100 - const bsl::size_t MESSAGE_SIZE = 1024 * 32; // was: 256 - - ntsa::Endpoint clientSourceEndpoint; - error = client->sourceEndpoint(&clientSourceEndpoint); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - ntsa::Endpoint serverSourceEndpoint; - error = server->sourceEndpoint(&serverSourceEndpoint); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - bdlbb::PooledBlobBufferFactory blobBufferFactory(MESSAGE_SIZE / 8, - allocator); - - bdlbb::Blob clientData(&blobBufferFactory, allocator); - DataUtil::generateData(&clientData, MESSAGE_SIZE); - - bsls::AtomicInt numMessagesReceived; - - bslmt::ThreadGroup threadGroup(allocator); - threadGroup.addThread(bdlf::BindUtil::bind(&AsyncUtil::sendBlob, - client, - serverSourceEndpoint, - &clientData, - NUM_MESSAGES, - allocator)); - - threadGroup.addThread(bdlf::BindUtil::bind(&AsyncUtil::receiveBlob, - server, - clientSourceEndpoint, - &clientData, - NUM_MESSAGES, - &numMessagesReceived, - &blobBufferFactory, - allocator)); - - threadGroup.joinAll(); - - { - bsl::string clientSourceEndpointDescription; - { - bsl::stringstream ss; - ss << clientSourceEndpoint; - clientSourceEndpointDescription = ss.str(); - } - - bsl::string serverSourceEndpointDescription; - { - bsl::stringstream ss; - ss << serverSourceEndpoint; - serverSourceEndpointDescription = ss.str(); - } - - BSLS_LOG_INFO( - "Test buffer I/O %d/%d (%d%%) complete " - "using datagram socket pair %s / %s", - numMessagesReceived.load(), - NUM_MESSAGES, - int(((double(numMessagesReceived.load()) / NUM_MESSAGES) * 100)), - clientSourceEndpointDescription.c_str(), - serverSourceEndpointDescription.c_str()); - } -} - -} // close namespace test - -NTSCFG_TEST_CASE(1) -{ - // Concern: Datagram socket buffer I/O - // Plan: - - bsl::vector socketTypes; - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_UDP_IPV4_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - } - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_UDP_IPV6_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - } - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_LOCAL_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_LOCAL_DATAGRAM); - } - - for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { - ntsa::Transport::Value transport = socketTypes[i]; - - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::shared_ptr client; - bsl::shared_ptr server; - - error = - ntsb::DatagramSocket::pair(&client, &server, transport, &ta); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - test::DatagramSocketTester::testBufferIO(client, server, &ta); - - error = client->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - error = server->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); - } -} - -NTSCFG_TEST_CASE(2) -{ - // Concern: Datagram socket vector I/O - // Plan: - - bsl::vector socketTypes; - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_UDP_IPV4_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - } - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_UDP_IPV6_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - } - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_LOCAL_DATAGRAM)) - { - socketTypes.push_back(ntsa::Transport::e_LOCAL_DATAGRAM); - } - - for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { - ntsa::Transport::Value transport = socketTypes[i]; - - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::shared_ptr client; - bsl::shared_ptr server; - - error = - ntsb::DatagramSocket::pair(&client, &server, transport, &ta); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - test::DatagramSocketTester::testVectorIO(client, server, &ta); - - error = client->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - - error = server->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); - } -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsb +} // close namespace BloombergLP diff --git a/groups/nts/ntsb/ntsb_resolver.t.cpp b/groups/nts/ntsb/ntsb_resolver.t.cpp index 5f42f4b5..1719f755 100644 --- a/groups/nts/ntsb/ntsb_resolver.t.cpp +++ b/groups/nts/ntsb/ntsb_resolver.t.cpp @@ -13,3325 +13,3362 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsb_resolver_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsb { -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +// Provide tests for 'ntsb::Resolver'. +class ResolverTest +{ + public: + // TODO + static void verifyCase1(); -// Uncomment or set to 0 to disable tests for invalid domain names, which -// tend to take multiple seconds for each test case variation, since the -// calls block until the name servers time out. -#define NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID 0 + // TODO + static void verifyCase2(); -// Uncomment or set to 0 to disable tests for invalid service names, which -// tend to take multiple seconds for each test case variation, since the -// calls block until the name servers time out. -#define NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID 0 + // TODO + static void verifyCase3(); -namespace test { + // TODO + static void verifyCase4(); -bsl::string makeEndpointSpecifier(ntsa::Port port) -{ - bsl::stringstream ss; - ss << port; + // TODO + static void verifyCase5(); - return ss.str(); -} + // TODO + static void verifyCase6(); -bsl::string makeEndpointSpecifier(const bsl::string& host) -{ - bsl::stringstream ss; - ss << host; + // TODO + static void verifyCase7(); - return ss.str(); -} + // TODO + static void verifyCase8(); -bsl::string makeEndpointSpecifier(const bsl::string& host, - const bsl::string& port) -{ - bsl::stringstream ss; - ss << host << ':' << port; + // TODO + static void verifyCase9(); - return ss.str(); -} + // TODO + static void verifyCase10(); -bsl::string makeEndpointSpecifier(const bsl::string& host, ntsa::Port port) -{ - bsl::stringstream ss; - ss << host << ':' << port; + // TODO + static void verifyCase11(); - return ss.str(); -} + private: + static bsl::string makeEndpointSpecifier(ntsa::Port port); -bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host) -{ - bsl::stringstream ss; - ss << host; + static bsl::string makeEndpointSpecifier(const bsl::string& host); - return ss.str(); -} + static bsl::string makeEndpointSpecifier(const bsl::string& host, + const bsl::string& port); -bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host, - const bsl::string& port) -{ - bsl::stringstream ss; - ss << host << ':' << port; + static bsl::string makeEndpointSpecifier(const bsl::string& host, + ntsa::Port port); - return ss.str(); -} + static bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host); -bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host, - ntsa::Port port) -{ - bsl::stringstream ss; - ss << host << ':' << port; + static bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host, + const bsl::string& port); - return ss.str(); -} + static bsl::string makeEndpointSpecifier(const ntsa::Ipv4Address& host, + ntsa::Port port); -bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host) -{ - bsl::stringstream ss; - ss << host; + static bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host); - return ss.str(); -} + static bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host, + const bsl::string& port); -bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host, - const bsl::string& port) -{ - bsl::stringstream ss; - ss << '[' << host << ']' << ':' << port; + static bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host, + ntsa::Port port); - return ss.str(); -} + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + ntsa::Port port); -bsl::string makeEndpointSpecifier(const ntsa::Ipv6Address& host, - ntsa::Port port) -{ - bsl::stringstream ss; - ss << '[' << host << ']' << ':' << port; + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host); - return ss.str(); -} + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host, + const bsl::string& port); -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - ntsa::Port port) -{ - ntsa::Error error; + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host, + ntsa::Port port); - bsl::string text = test::makeEndpointSpecifier(port); + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host, + const bsl::string& port); - error = resolver->getEndpoint(endpoint, text, options); + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host, + ntsa::Port port); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host); - return error; -} + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host, + const bsl::string& port); -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const bsl::string& host) -{ - ntsa::Error error; + static ntsa::Error getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host, + ntsa::Port port); +}; - bsl::string text = test::makeEndpointSpecifier(host); +// Uncomment or set to 0 to disable tests for invalid domain names, which +// tend to take multiple seconds for each test case variation, since the +// calls block until the name servers time out. +#define NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID 0 - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; +// Uncomment or set to 0 to disable tests for invalid service names, which +// tend to take multiple seconds for each test case variation, since the +// calls block until the name servers time out. +#define NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID 0 - error = resolver->getEndpoint(endpoint, text, options); +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase1) +{ + // Concern: Test 'getHostname' from the system. - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - return error; + bsl::string hostname; + ntsa::Error error = resolver.getHostname(&hostname); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const bsl::string& host, - const bsl::string& port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase2) { - ntsa::Error error; - - bsl::string text = test::makeEndpointSpecifier(host, port); - - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + // Concern: Test 'getHostnameFullyQualified' from the system. - error = resolver->getEndpoint(endpoint, text, options); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } + bsl::string hostname; + ntsa::Error error = resolver.getHostnameFullyQualified(&hostname); + NTSCFG_TEST_FALSE(error); - return error; + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const bsl::string& host, - ntsa::Port port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase3) { + // Concern: Test resolution of domain names to IP addresses from the + // system. + // + // Plan: Ensure 'dns.google.com' resolves to at least two of the known + // IP addresses at which it has been assigned, as of 2020. + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host, port); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + bsl::set ipAddressSet; + ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); + ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); - error = resolver->getEndpoint(endpoint, text, options); + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + bsl::vector ipAddressList; + ntsa::IpAddressOptions ipAddressOptions; + + error = resolver.getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); + + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() << NTSCFG_TEST_LOG_END; + + ipAddressSet.erase(*it); } - return error; + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv4Address& host) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase4) { - ntsa::Error error; + // Concern: Test resolution of IP addresses to domain names from the + // system. + // + // Plan: Resolve the well-known IP address of Google's public DNS server + // to "dns.google". - bsl::string text = test::makeEndpointSpecifier(host); + ntsa::Error error; - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - error = resolver->getEndpoint(endpoint, text, options); + bsl::string domainName; + error = resolver.getDomainName(&domainName, ntsa::IpAddress("8.8.8.8")); if (error) { NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; } else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName << NTSCFG_TEST_LOG_END; } - return error; + NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_EQ(domainName, "dns.google"); } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv4Address& host, - const bsl::string& port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase5) { + // Concern: Test 'getHostname' from the cache. + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host, port); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + resolver.setHostname("test"); - error = resolver->getEndpoint(endpoint, text, options); + bsl::string hostname; + error = resolver.getHostname(&hostname); + NTSCFG_TEST_FALSE(error); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_EQ(hostname, bsl::string("test")); - return error; + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv4Address& host, - ntsa::Port port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase6) { + // Concern: Test 'getHostnameFullyQualified' from the cache. + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host, port); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + resolver.setHostnameFullyQualified("test.home"); - error = resolver->getEndpoint(endpoint, text, options); + bsl::string hostname; + error = resolver.getHostnameFullyQualified(&hostname); + NTSCFG_TEST_FALSE(error); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } + NTSCFG_TEST_EQ(hostname, bsl::string("test.home")); - return error; + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv6Address& host) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase7) { + // Concern: Test resolution of domain names to IP addresses from the + // overrides. + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + bsl::vector ipAddressListOverride; + ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); + ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); - error = resolver->getEndpoint(endpoint, text, options); + resolver.setIpAddress("example.com", ipAddressListOverride); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + bsl::set ipAddressSet(ipAddressListOverride.begin(), + ipAddressListOverride.end()); + + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + + bsl::vector ipAddressList; + ntsa::IpAddressOptions ipAddressOptions; + + error = + resolver.getIpAddress(&ipAddressList, "example.com", ipAddressOptions); + NTSCFG_TEST_FALSE(error); + + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() << NTSCFG_TEST_LOG_END; + + bsl::size_t n = ipAddressSet.erase(*it); + NTSCFG_TEST_EQ(n, 1); } - return error; + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv6Address& host, - const bsl::string& port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase8) { + // Concern: Test resolution of IP addresses to domain names from the + // overrides. + // + // Plan: Resolve the well-known IP address of Google's public DNS server + // to "dns.google". + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host, port); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; + bsl::vector ipAddressListOverride; + ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); + ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); - error = resolver->getEndpoint(endpoint, text, options); + resolver.setIpAddress("example.com", ipAddressListOverride); + + bsl::string domainName; + error = resolver.getDomainName(&domainName, ntsa::IpAddress("8.8.8.8")); if (error) { NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; } else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName << NTSCFG_TEST_LOG_END; } - return error; + NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_EQ(domainName, "example.com"); } -ntsa::Error getEndpoint(ntsb::Resolver* resolver, - ntsa::Endpoint* endpoint, - const ntsa::EndpointOptions& options, - const ntsa::Ipv6Address& host, - ntsa::Port port) +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase9) { + // Concern: Test resolution of endpoints. + ntsa::Error error; - bsl::string text = test::makeEndpointSpecifier(host, port); + const bsl::string DOMAIN_NAME = "test.example.com"; - NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " - << options << NTSCFG_TEST_LOG_END; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + const bsl::string DOMAIN_NAME_INVALID = "invalid.example.com"; +#endif - error = resolver->getEndpoint(endpoint, text, options); + bsl::vector ipv4AddressList; + ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.101")); + ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.102")); + ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.103")); + ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.104")); + ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.105")); + + bsl::vector ipv6AddressList; + ipv6AddressList.push_back( + ntsa::Ipv6Address("2606:2800:220:1:248:1893:25c8:1946")); + ipv6AddressList.push_back( + ntsa::Ipv6Address("2001:41c0::645:a65e:60ff:feda:589d")); + ipv6AddressList.push_back(ntsa::Ipv6Address("2001:0db8::1:0:0:1")); + ipv6AddressList.push_back(ntsa::Ipv6Address("::")); + ipv6AddressList.push_back(ntsa::Ipv6Address("::1")); + + bsl::vector ipAddressList; + ipAddressList.insert(ipAddressList.end(), + ipv4AddressList.begin(), + ipv4AddressList.end()); + ipAddressList.insert(ipAddressList.end(), + ipv6AddressList.begin(), + ipv6AddressList.end()); + + ntsa::Ipv4Address ipv4AddressFallback("10.10.1.20"); + ntsa::Ipv6Address ipv6AddressFallback( + "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); + + const bsl::string SERVICE_NAME = "ntsp"; - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint - << NTSCFG_TEST_LOG_END; - } +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + const bsl::string SERVICE_NAME_INVALID = "invalid-ntsp"; +#endif - return error; -} + bsl::vector tcpPortList; + tcpPortList.push_back(5801); + tcpPortList.push_back(5802); + tcpPortList.push_back(5803); -} // close namespace test + bsl::vector udpPortList; + udpPortList.push_back(9801); + udpPortList.push_back(9802); + udpPortList.push_back(9803); -NTSCFG_TEST_CASE(1) -{ - // Concern: Test 'getHostname' from the system. - // Plan: + bsl::vector portList; + portList.insert(portList.end(), tcpPortList.begin(), tcpPortList.end()); + portList.insert(portList.end(), udpPortList.begin(), udpPortList.end()); - ntscfg::TestAllocator ta; - { - ntsb::Resolver resolver(&ta); + ntsa::Port portFallback = 6484; - bsl::string hostname; - ntsa::Error error = resolver.getHostname(&hostname); - NTSCFG_TEST_FALSE(error); + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + error = resolver.setIpAddress(DOMAIN_NAME, ipAddressList); + NTSCFG_TEST_FALSE(error); -NTSCFG_TEST_CASE(2) -{ - // Concern: Test 'getHostnameFullyQualified' from the system. - // Plan: + error = resolver.setPort(SERVICE_NAME, + tcpPortList, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_FALSE(error); - ntscfg::TestAllocator ta; - { - ntsb::Resolver resolver(&ta); + error = resolver.setPort(SERVICE_NAME, + udpPortList, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_FALSE(error); - bsl::string hostname; - ntsa::Error error = resolver.getHostnameFullyQualified(&hostname); - NTSCFG_TEST_FALSE(error); + // + // Case: (empty) + // - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Test: (empty) -NTSCFG_TEST_CASE(3) -{ - // Concern: Test resolution of domain names to IP addresses from the - // system. - // - // Plan: Ensure 'dns.google.com' resolves to at least two of the known - // IP addresses at which it has been assigned, as of 2020. + // Test: (empty) [TCP/IPv4] - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Test: (empty) [TCP/IPv6] - ntsb::Resolver resolver(&ta); + // Test: (empty) [UDP/IPv4] - bsl::set ipAddressSet; - ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); - ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); + // Test: (empty) [UDP/IPv6] - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + // Test: (empty) with default IPv4 address - bsl::vector ipAddressList; - ntsa::IpAddressOptions ipAddressOptions; + // Test: (empty) with default IPv4 address [TCP/IPv4] - error = resolver.getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + // Test: (empty) with default IPv4 address [TCP/IPv6] - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + // Test: (empty) with default IPv4 address [UDP/IPv4] - ipAddressSet.erase(*it); - } + // Test: (empty) with default IPv4 address [UDP/IPv6] - NTSCFG_TEST_TRUE(ipAddressSet.empty()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Test: (empty) with default IPv6 address -NTSCFG_TEST_CASE(4) -{ - // Concern: Test resolution of IP addresses to domain names from the - // system. - // - // Plan: Resolve the well-known IP address of Google's public DNS server - // to "dns.google". + // Test: (empty) with default IPv6 address [TCP/IPv4] - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Test: (empty) with default IPv6 address [TCP/IPv6] - ntsb::Resolver resolver(&ta); + // Test: (empty) with default IPv6 address [UDP/IPv4] - bsl::string domainName; - error = - resolver.getDomainName(&domainName, ntsa::IpAddress("8.8.8.8")); + // Test: (empty) with default IPv6 address [UDP/IPv6] - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName - << NTSCFG_TEST_LOG_END; - } + // Test: (empty) with default port - NTSCFG_TEST_FALSE(error); - NTSCFG_TEST_EQ(domainName, "dns.google"); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Test: (empty) with default port [TCP/IPv4] -NTSCFG_TEST_CASE(5) -{ - // Concern: Test 'getHostname' from the cache. - // Plan: + // Test: (empty) with default port [TCP/IPv6] - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Test: (empty) with default port [UDP/IPv4] - ntsb::Resolver resolver(&ta); + // Test: (empty) with default port [UDP/IPv6] - resolver.setHostname("test"); + // Test: (empty) with default IPv4 address and port - bsl::string hostname; - error = resolver.getHostname(&hostname); - NTSCFG_TEST_FALSE(error); + // Test: (empty) with default IPv4 address and port [TCP/IPv4] - NTSCFG_TEST_EQ(hostname, bsl::string("test")); + // Test: (empty) with default IPv4 address and port [TCP/IPv6] - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Test: (empty) with default IPv4 address and port [UDP/IPv4] -NTSCFG_TEST_CASE(6) -{ - // Concern: Test 'getHostnameFullyQualified' from the cache. - // Plan: + // Test: (empty) with default IPv4 address and port [UDP/IPv6] - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Test: (empty) with default IPv6 address and port - ntsb::Resolver resolver(&ta); + // Test: (empty) with default IPv6 address and port [TCP/IPv4] - resolver.setHostnameFullyQualified("test.home"); + // Test: (empty) with default IPv6 address and port [TCP/IPv6] - bsl::string hostname; - error = resolver.getHostnameFullyQualified(&hostname); - NTSCFG_TEST_FALSE(error); + // Test: (empty) with default IPv6 address and port [UDP/IPv4] - NTSCFG_TEST_EQ(hostname, bsl::string("test.home")); + // Test: (empty) with default IPv6 address and port [UDP/IPv6] - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // + // Case: + // -NTSCFG_TEST_CASE(7) -{ - // Concern: Test resolution of domain names to IP addresses from the - // overrides. + // Test: - ntscfg::TestAllocator ta; { - ntsa::Error error; - - ntsb::Resolver resolver(&ta); - - bsl::vector ipAddressListOverride; - ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); - ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - resolver.setIpAddress("example.com", ipAddressListOverride); - - bsl::set ipAddressSet(ipAddressListOverride.begin(), - ipAddressListOverride.end()); - - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - - bsl::vector ipAddressList; - ntsa::IpAddressOptions ipAddressOptions; + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + portList[0]); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); + } - error = resolver.getIpAddress(&ipAddressList, - "example.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + // Test: [TCP/IPv4] - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + // Test: [TCP/IPv6] - bsl::size_t n = ipAddressSet.erase(*it); - NTSCFG_TEST_EQ(n, 1); - } + // Test: [UDP/IPv4] - NTSCFG_TEST_TRUE(ipAddressSet.empty()); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Test: [UDP/IPv6] -NTSCFG_TEST_CASE(8) -{ - // Concern: Test resolution of IP addresses to domain names from the - // overrides. - // - // Plan: Resolve the well-known IP address of Google's public DNS server - // to "dns.google". + // Test: with default IPv4 address - ntscfg::TestAllocator ta; { - ntsa::Error error; - - ntsb::Resolver resolver(&ta); - - bsl::vector ipAddressListOverride; - ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); - ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); - - resolver.setIpAddress("example.com", ipAddressListOverride); + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - bsl::string domainName; - error = - resolver.getDomainName(&domainName, ntsa::IpAddress("8.8.8.8")); + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName - << NTSCFG_TEST_LOG_END; - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + portList[0]); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_FALSE(error); - NTSCFG_TEST_EQ(domainName, "example.com"); + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressFallback); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(9) -{ - // Concern: Test resolution of endpoints. - // - // Plan: + // Test: with default IPv4 address [TCP/IPv4] - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Test: with default IPv4 address [TCP/IPv6] - const bsl::string DOMAIN_NAME = "test.example.com"; + // Test: with default IPv4 address [UDP/IPv4] -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - const bsl::string DOMAIN_NAME_INVALID = "invalid.example.com"; -#endif + // Test: with default IPv4 address [UDP/IPv6] - bsl::vector ipv4AddressList; - ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.101")); - ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.102")); - ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.103")); - ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.104")); - ipv4AddressList.push_back(ntsa::Ipv4Address("192.168.1.105")); - - bsl::vector ipv6AddressList; - ipv6AddressList.push_back( - ntsa::Ipv6Address("2606:2800:220:1:248:1893:25c8:1946")); - ipv6AddressList.push_back( - ntsa::Ipv6Address("2001:41c0::645:a65e:60ff:feda:589d")); - ipv6AddressList.push_back(ntsa::Ipv6Address("2001:0db8::1:0:0:1")); - ipv6AddressList.push_back(ntsa::Ipv6Address("::")); - ipv6AddressList.push_back(ntsa::Ipv6Address("::1")); - - bsl::vector ipAddressList; - ipAddressList.insert(ipAddressList.end(), - ipv4AddressList.begin(), - ipv4AddressList.end()); - ipAddressList.insert(ipAddressList.end(), - ipv6AddressList.begin(), - ipv6AddressList.end()); - - ntsa::Ipv4Address ipv4AddressFallback("10.10.1.20"); - ntsa::Ipv6Address ipv6AddressFallback( - "2001:0db8:85a3:0000:0000:8a2e:0370:7334"); - - const bsl::string SERVICE_NAME = "ntsp"; + // Test: with default IPv6 address -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - const bsl::string SERVICE_NAME_INVALID = "invalid-ntsp"; -#endif + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - bsl::vector tcpPortList; - tcpPortList.push_back(5801); - tcpPortList.push_back(5802); - tcpPortList.push_back(5803); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - bsl::vector udpPortList; - udpPortList.push_back(9801); - udpPortList.push_back(9802); - udpPortList.push_back(9803); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + portList[0]); + NTSCFG_TEST_OK(error); - bsl::vector portList; - portList.insert(portList.end(), - tcpPortList.begin(), - tcpPortList.end()); - portList.insert(portList.end(), - udpPortList.begin(), - udpPortList.end()); + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressFallback); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - ntsa::Port portFallback = 6484; + // Test: with default IPv6 address [TCP/IPv4] - ntsb::Resolver resolver(&ta); + // Test: with default IPv6 address [TCP/IPv6] - error = resolver.setIpAddress(DOMAIN_NAME, ipAddressList); - NTSCFG_TEST_FALSE(error); + // Test: with default IPv6 address [UDP/IPv4] - error = resolver.setPort(SERVICE_NAME, - tcpPortList, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_FALSE(error); + // Test: with default IPv6 address [UDP/IPv6] - error = resolver.setPort(SERVICE_NAME, - udpPortList, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); - NTSCFG_TEST_FALSE(error); + // Test: with default port - // - // Case: (empty) - // + // Test: with default port [TCP/IPv4] - // Test: (empty) + // Test: with default port [TCP/IPv6] - // Test: (empty) [TCP/IPv4] + // Test: with default port [UDP/IPv4] - // Test: (empty) [TCP/IPv6] + // Test: with default port [UDP/IPv6] - // Test: (empty) [UDP/IPv4] + // Test: with default IPv4 address and port - // Test: (empty) [UDP/IPv6] + // Test: with default IPv4 address and port [TCP/IPv4] - // Test: (empty) with default IPv4 address + // Test: with default IPv4 address and port [TCP/IPv6] - // Test: (empty) with default IPv4 address [TCP/IPv4] + // Test: with default IPv4 address and port [UDP/IPv4] - // Test: (empty) with default IPv4 address [TCP/IPv6] + // Test: with default IPv4 address and port [UDP/IPv6] - // Test: (empty) with default IPv4 address [UDP/IPv4] + // Test: with default IPv6 address and port - // Test: (empty) with default IPv4 address [UDP/IPv6] + // Test: with default IPv6 address and port [TCP/IPv4] - // Test: (empty) with default IPv6 address + // Test: with default IPv6 address and port [TCP/IPv6] - // Test: (empty) with default IPv6 address [TCP/IPv4] + // Test: with default IPv6 address and port [UDP/IPv4] - // Test: (empty) with default IPv6 address [TCP/IPv6] + // Test: with default IPv6 address and port [UDP/IPv6] - // Test: (empty) with default IPv6 address [UDP/IPv4] + // + // Case: + // - // Test: (empty) with default IPv6 address [UDP/IPv6] + // Test: - // Test: (empty) with default port + // Test: [TCP/IPv4] - // Test: (empty) with default port [TCP/IPv4] + // Test: [TCP/IPv6] - // Test: (empty) with default port [TCP/IPv6] + // Test: [UDP/IPv4] - // Test: (empty) with default port [UDP/IPv4] + // Test: [UDP/IPv6] - // Test: (empty) with default port [UDP/IPv6] + // Test: with default IPv4 address - // Test: (empty) with default IPv4 address and port + // Test: with default IPv4 address [TCP/IPv4] - // Test: (empty) with default IPv4 address and port [TCP/IPv4] + // Test: with default IPv4 address [TCP/IPv6] - // Test: (empty) with default IPv4 address and port [TCP/IPv6] + // Test: with default IPv4 address [UDP/IPv4] - // Test: (empty) with default IPv4 address and port [UDP/IPv4] + // Test: with default IPv4 address [UDP/IPv6] - // Test: (empty) with default IPv4 address and port [UDP/IPv6] + // Test: with default IPv6 address - // Test: (empty) with default IPv6 address and port + // Test: with default IPv6 address [TCP/IPv4] - // Test: (empty) with default IPv6 address and port [TCP/IPv4] + // Test: with default IPv6 address [TCP/IPv6] - // Test: (empty) with default IPv6 address and port [TCP/IPv6] + // Test: with default IPv6 address [UDP/IPv4] - // Test: (empty) with default IPv6 address and port [UDP/IPv4] + // Test: with default IPv6 address [UDP/IPv6] - // Test: (empty) with default IPv6 address and port [UDP/IPv6] + // Test: with default port - // - // Case: - // + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: + options.setPortFallback(portFallback); - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0]); + NTSCFG_TEST_OK(error); - error = - test::getEndpoint(&resolver, &endpoint, options, portList[0]); - NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); - } + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); + } - // Test: [TCP/IPv4] + // Test: with default port [TCP/IPv4] - // Test: [TCP/IPv6] + // Test: with default port [TCP/IPv6] - // Test: [UDP/IPv4] + // Test: with default port [UDP/IPv4] - // Test: [UDP/IPv6] + // Test: with default port [UDP/IPv6] - // Test: with default IPv4 address + // Test: with default IPv4 address and port - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: with default IPv4 address and port [TCP/IPv4] - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + // Test: with default IPv4 address and port [TCP/IPv6] - error = - test::getEndpoint(&resolver, &endpoint, options, portList[0]); - NTSCFG_TEST_OK(error); + // Test: with default IPv4 address and port [UDP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressFallback); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } + // Test: with default IPv4 address and port [UDP/IPv6] - // Test: with default IPv4 address [TCP/IPv4] + // Test: with default IPv6 address and port - // Test: with default IPv4 address [TCP/IPv6] + // Test: with default IPv6 address and port [TCP/IPv4] - // Test: with default IPv4 address [UDP/IPv4] + // Test: with default IPv6 address and port [TCP/IPv6] - // Test: with default IPv4 address [UDP/IPv6] + // Test: with default IPv6 address and port [UDP/IPv4] - // Test: with default IPv6 address + // Test: with default IPv6 address and port [UDP/IPv6] - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // + // Case: : + // - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + // Test: : - error = - test::getEndpoint(&resolver, &endpoint, options, portList[0]); - NTSCFG_TEST_OK(error); + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressFallback); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + portList[0]); + NTSCFG_TEST_OK(error); - // Test: with default IPv6 address [TCP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: with default IPv6 address [TCP/IPv6] + // Test: : with default IPv4 address - // Test: with default IPv6 address [UDP/IPv4] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: with default IPv6 address [UDP/IPv6] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: with default port + // Test: : with default IPv4 address [UDP/IPv4] - // Test: with default port [TCP/IPv4] + // Test: : with default IPv4 address [UDP/IPv6] - // Test: with default port [TCP/IPv6] + // Test: : with default IPv6 address - // Test: with default port [UDP/IPv4] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: with default port [UDP/IPv6] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: with default IPv4 address and port + // Test: : with default IPv6 address [UDP/IPv4] - // Test: with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: with default IPv4 address and port [TCP/IPv6] + // Test: : with default port - // Test: with default IPv4 address and port [UDP/IPv4] + // Test: : with default port [TCP/IPv4] - // Test: with default IPv4 address and port [UDP/IPv6] + // Test: : with default port [TCP/IPv6] - // Test: with default IPv6 address and port + // Test: : with default port [UDP/IPv4] - // Test: with default IPv6 address and port [TCP/IPv4] + // Test: : with default port [UDP/IPv6] - // Test: with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv4 address and port - // Test: with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv6] - // - // Case: - // + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: [TCP/IPv4] + // Test: : with default IPv6 address and port - // Test: [TCP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: [UDP/IPv4] + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: [UDP/IPv6] + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: with default IPv4 address + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: with default IPv4 address [TCP/IPv4] + // + // Case: : + // - // Test: with default IPv4 address [TCP/IPv6] + // Test: : - // Test: with default IPv4 address [UDP/IPv4] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv6 address + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: with default IPv6 address [TCP/IPv4] + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address [TCP/IPv6] + options.setPortSelector(j); - // Test: with default IPv6 address [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv6 address [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + portList[j % portList.size()]); + } + } - // Test: with default port + // Test: : [TCP/IPv4] + { { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setPortFallback(portFallback); + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0]); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); NTSCFG_TEST_OK(error); NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); } - // Test: with default port [TCP/IPv4] - - // Test: with default port [TCP/IPv6] - - // Test: with default port [UDP/IPv4] - - // Test: with default port [UDP/IPv6] + for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address and port + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setPortSelector(j); - // Test: with default IPv4 address and port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv4 address and port [TCP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); + } + } - // Test: with default IPv4 address and port [UDP/IPv4] + // Test: : [TCP/IPv6] - // Test: with default IPv4 address and port [UDP/IPv6] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address and port + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - // Test: with default IPv6 address and port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); + } - // Test: with default IPv6 address and port [TCP/IPv6] + // Test: : [UDP/IPv4] - // Test: with default IPv6 address and port [UDP/IPv4] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address and port [UDP/IPv6] + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - // - // Case: : - // + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); + } - { + for (bsl::size_t j = 0; j < 2 * udpPortList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - portList[0]); + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + options.setPortSelector(j); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); NTSCFG_TEST_OK(error); NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + udpPortList[j % udpPortList.size()]); } + } - // Test: : with default IPv4 address + // Test: : [UDP/IPv6] - // Test: : with default IPv4 address [TCP/IPv4] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address [TCP/IPv6] + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - // Test: : with default IPv4 address [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv4AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); + } - // Test: : with default IPv4 address [UDP/IPv6] + // Test: : with default IPv4 address - // Test: : with default IPv6 address + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default IPv4 address [UDP/IPv6] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default IPv6 address - // Test: : with default port + // Test: : with default IPv6 address [TCP/IPv4] - // Test: : with default port [TCP/IPv4] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default port [TCP/IPv6] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default port [UDP/IPv4] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default port [UDP/IPv6] + // Test: : with default port - // Test: : with default IPv4 address and port + // Test: : with default port [TCP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: : with default port [TCP/IPv6] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: : with default port [UDP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: : with default IPv4 address and port - // Test: : with default IPv6 address and port + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv6 address and port - // - // Case: : - // + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: : + // Test: : with default IPv6 address and port [TCP/IPv6] - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address and port [UDP/IPv4] + + // Test: : with default IPv6 address and port [UDP/IPv6] + + // Test: : + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } + // Test: : [TCP/IPv4] - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : [TCP/IPv6] - options.setPortSelector(j); + // Test: : [UDP/IPv4] + + // Test: : [UDP/IPv6] - error = test::getEndpoint(&resolver, + // Test: : with default IPv4 address + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; + + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - portList[j % portList.size()]); - } - } + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv6] - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address [UDP/IPv4] - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + // Test: : with default IPv4 address [UDP/IPv6] + + // Test: : with default IPv6 address + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; + + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + // Test: : with default IPv6 address [TCP/IPv4] - for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address [TCP/IPv6] - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - options.setPortSelector(j); + // Test: : with default IPv6 address [UDP/IPv4] + + // Test: : with default IPv6 address [UDP/IPv6] - error = test::getEndpoint(&resolver, + // Test: : with default port + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; + + options.setPortFallback(portFallback); + + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } - } + // Test: : with default port [TCP/IPv4] - // Test: : [TCP/IPv6] + // Test: : with default port [TCP/IPv6] - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default port [UDP/IPv4] - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + // Test: : with default port [UDP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); - } + // Test: : with default IPv4 address and port - // Test: : [UDP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv4] - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [TCP/IPv6] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + // Test: : with default IPv4 address and port [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv4 address and port [UDP/IPv6] - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv6 address and port - for (bsl::size_t j = 0; j < 2 * udpPortList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address and port [TCP/IPv4] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - options.setPortSelector(j); + // Test: : with default IPv6 address and port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } - } - - // Test: : [UDP/IPv6] - - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; - - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); - } - - // Test: : with default IPv4 address + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv4 address [TCP/IPv6] - - // Test: : with default IPv4 address [UDP/IPv4] - - // Test: : with default IPv4 address [UDP/IPv6] + // + // Case: + // - // Test: : with default IPv6 address + // Test: - // Test: : with default IPv6 address [TCP/IPv4] + // Test: [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: [UDP/IPv6] - // Test: : with default port + // Test: with default IPv4 address - // Test: : with default port [TCP/IPv4] + // Test: with default IPv4 address [TCP/IPv4] - // Test: : with default port [TCP/IPv6] + // Test: with default IPv4 address [TCP/IPv6] - // Test: : with default port [UDP/IPv4] + // Test: with default IPv4 address [UDP/IPv4] - // Test: : with default port [UDP/IPv6] + // Test: with default IPv4 address [UDP/IPv6] - // Test: : with default IPv4 address and port + // Test: with default IPv6 address - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: with default IPv6 address [TCP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: with default IPv6 address [TCP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: with default IPv6 address [UDP/IPv4] - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: with default IPv6 address [UDP/IPv6] - // Test: : with default IPv6 address and port + // Test: with default port - // Test: : with default IPv6 address and port [TCP/IPv4] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address and port [TCP/IPv6] + options.setPortFallback(portFallback); - // Test: : with default IPv6 address and port [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0]); + NTSCFG_TEST_OK(error); - // Test: : with default IPv6 address and port [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); + } - // Test: : + // Test: with default port [TCP/IPv4] -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: with default port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: with default port [UDP/IPv4] - // Test: : [TCP/IPv4] + // Test: with default port [UDP/IPv6] - // Test: : [TCP/IPv6] + // Test: with default IPv4 address and port - // Test: : [UDP/IPv4] + // Test: with default IPv4 address and port [TCP/IPv4] - // Test: : [UDP/IPv6] + // Test: with default IPv4 address and port [TCP/IPv6] - // Test: : with default IPv4 address + // Test: with default IPv4 address and port [UDP/IPv4] -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: with default IPv4 address and port [UDP/IPv6] - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + // Test: with default IPv6 address and port - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: with default IPv6 address and port [TCP/IPv4] - // Test: : with default IPv4 address [TCP/IPv4] + // Test: with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv4 address [UDP/IPv6] + // + // Case: : + // - // Test: : with default IPv6 address + // Test: : -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + portList[0]); + NTSCFG_TEST_OK(error); - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default IPv4 address - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: : with default port + // Test: : with default IPv4 address [UDP/IPv6] -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address - options.setPortFallback(portFallback); + // Test: : with default IPv6 address [TCP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv4AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default port [TCP/IPv4] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default port [TCP/IPv6] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default port [UDP/IPv4] + // Test: : with default port - // Test: : with default port [UDP/IPv6] + // Test: : with default port [TCP/IPv4] - // Test: : with default IPv4 address and port + // Test: : with default port [TCP/IPv6] - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: : with default IPv4 address and port - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: : with default IPv6 address and port + // Test: : with default IPv4 address and port [TCP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv6 address and port - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv4] - // - // Case: - // + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: [TCP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: [TCP/IPv6] + // + // Case: : + // - // Test: [UDP/IPv4] + // Test: : - // Test: [UDP/IPv6] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv4 address [TCP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: with default IPv4 address [TCP/IPv6] + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address [UDP/IPv4] + options.setPortSelector(j); - // Test: with default IPv4 address [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv6 address + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + portList[j % portList.size()]); + } + } - // Test: with default IPv6 address [TCP/IPv4] + // Test: : [TCP/IPv4] - // Test: with default IPv6 address [TCP/IPv6] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address [UDP/IPv4] + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - // Test: with default IPv6 address [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); + } - // Test: with default port + // Test: : [TCP/IPv6] + { { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setPortFallback(portFallback); + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0]); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); NTSCFG_TEST_OK(error); NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); } - // Test: with default port [TCP/IPv4] - - // Test: with default port [TCP/IPv6] - - // Test: with default port [UDP/IPv4] - - // Test: with default port [UDP/IPv6] + for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address and port + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + options.setPortSelector(j); - // Test: with default IPv4 address and port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: with default IPv4 address and port [TCP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); + } + } - // Test: with default IPv4 address and port [UDP/IPv4] + // Test: : [UDP/IPv4] - // Test: with default IPv4 address and port [UDP/IPv6] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address and port + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - // Test: with default IPv6 address and port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); + } - // Test: with default IPv6 address and port [TCP/IPv6] + // Test: : [UDP/IPv6] - // Test: with default IPv6 address and port [UDP/IPv4] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address and port [UDP/IPv6] + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - // - // Case: : - // + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); + } - { + for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - portList[0]); + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + options.setPortSelector(j); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + ipv6AddressList[0], + SERVICE_NAME); NTSCFG_TEST_OK(error); NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + udpPortList[j % udpPortList.size()]); } + } - // Test: : with default IPv4 address - - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv4 address - // Test: : with default IPv4 address [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: : with default IPv4 address [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: : with default IPv6 address + // Test: : with default IPv4 address [UDP/IPv6] - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default IPv6 address - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default port + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default port [TCP/IPv4] + // Test: : with default port - // Test: : with default port [TCP/IPv6] + // Test: : with default port [TCP/IPv4] - // Test: : with default port [UDP/IPv4] + // Test: : with default port [TCP/IPv6] - // Test: : with default port [UDP/IPv6] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv4 address and port + // Test: : with default port [UDP/IPv6] - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv4 address and port - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default IPv6 address and port + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: : with default IPv6 address and port - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv6 address and port [UDP/IPv4] - // - // Case: : - // + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : + // Test: : - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } + // Test: : [TCP/IPv4] - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : [TCP/IPv6] - options.setPortSelector(j); + // Test: : [UDP/IPv4] + + // Test: : [UDP/IPv6] + + // Test: : with default IPv4 address + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; + + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - portList[j % portList.size()]); - } - } + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: : [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv4] - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address [TCP/IPv6] - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + // Test: : with default IPv4 address [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); - } + // Test: : with default IPv4 address [UDP/IPv6] - // Test: : [TCP/IPv6] + // Test: : with default IPv6 address - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + // Test: : with default IPv6 address [TCP/IPv4] - for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address [TCP/IPv6] - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - options.setPortSelector(j); + // Test: : with default IPv6 address [UDP/IPv4] + + // Test: : with default IPv6 address [UDP/IPv6] + + // Test: : with default port + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, + options.setPortFallback(portFallback); + + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } - } - - // Test: : [UDP/IPv4] + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default port [TCP/IPv4] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + // Test: : with default port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_ERROR(error, ntsa::Error::e_INVALID); - } + // Test: : with default port [UDP/IPv4] - // Test: : [UDP/IPv6] + // Test: : with default port [UDP/IPv6] - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + // Test: : with default IPv4 address and port [TCP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv4 address and port [TCP/IPv6] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv4 address and port [UDP/IPv4] - for (bsl::size_t j = 0; j < 2 * tcpPortList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [UDP/IPv6] - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - options.setPortSelector(j); + // Test: : with default IPv6 address and port - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv6 address and port [TCP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } - } + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv4 address + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv4 address [TCP/IPv6] + // + // Case: + // - // Test: : with default IPv4 address [UDP/IPv4] + // Test: - // Test: : with default IPv4 address [UDP/IPv6] + // Test: [TCP/IPv4] - // Test: : with default IPv6 address + // Test: [TCP/IPv6] - // Test: : with default IPv6 address [TCP/IPv4] + // Test: [UDP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: [UDP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: with default IPv4 address - // Test: : with default IPv6 address [UDP/IPv6] + // Test: with default IPv4 address [TCP/IPv4] - // Test: : with default port + // Test: with default IPv4 address [TCP/IPv6] - // Test: : with default port [TCP/IPv4] + // Test: with default IPv4 address [UDP/IPv4] - // Test: : with default port [TCP/IPv6] + // Test: with default IPv4 address [UDP/IPv6] - // Test: : with default port [UDP/IPv4] + // Test: with default IPv6 address - // Test: : with default port [UDP/IPv6] + // Test: with default IPv6 address [TCP/IPv4] - // Test: : with default IPv4 address and port + // Test: with default IPv6 address [TCP/IPv6] - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: with default IPv6 address [UDP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: with default IPv6 address [UDP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: with default port - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: with default port [TCP/IPv4] - // Test: : with default IPv6 address and port + // Test: with default port [TCP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: with default port [UDP/IPv4] - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: with default port [UDP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: with default IPv4 address and port - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: with default IPv4 address and port [TCP/IPv4] - // Test: : + // Test: with default IPv4 address and port [TCP/IPv6] -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: with default IPv4 address and port [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: with default IPv4 address and port [UDP/IPv6] - // Test: : [TCP/IPv4] + // Test: with default IPv6 address and port - // Test: : [TCP/IPv6] + // Test: with default IPv6 address and port [TCP/IPv4] - // Test: : [UDP/IPv4] + // Test: with default IPv6 address and port [TCP/IPv6] - // Test: : [UDP/IPv6] + // Test: with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address + // Test: with default IPv6 address and port [UDP/IPv6] -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv4 address [TCP/IPv4] + // Test: [TCP/IPv4] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: [TCP/IPv6] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: [UDP/IPv4] - // Test: : with default IPv4 address [UDP/IPv6] + // Test: [UDP/IPv6] - // Test: : with default IPv6 address + // Test: with default IPv4 address -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv6 address [TCP/IPv4] + // Test: with default IPv4 address [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: with default IPv4 address [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: with default IPv4 address [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: with default IPv4 address [UDP/IPv6] - // Test: : with default port + // Test: with default IPv6 address -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setPortFallback(portFallback); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - ipv6AddressList[0], - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default port [TCP/IPv4] + // Test: with default IPv6 address [TCP/IPv4] - // Test: : with default port [TCP/IPv6] + // Test: with default IPv6 address [TCP/IPv6] - // Test: : with default port [UDP/IPv4] + // Test: with default IPv6 address [UDP/IPv4] - // Test: : with default port [UDP/IPv6] + // Test: with default IPv6 address [UDP/IPv6] - // Test: : with default IPv4 address and port + // Test: with default port - // Test: : with default IPv4 address and port [TCP/IPv4] +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port [TCP/IPv6] + options.setPortFallback(portFallback); - // Test: : with default IPv4 address and port [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: with default port [TCP/IPv4] - // Test: : with default IPv6 address and port + // Test: with default port [TCP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: with default port [UDP/IPv4] - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: with default port [UDP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: with default IPv4 address and port - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: with default IPv4 address and port [TCP/IPv4] - // - // Case: - // + // Test: with default IPv4 address and port [TCP/IPv6] - // Test: + // Test: with default IPv4 address and port [UDP/IPv4] - // Test: [TCP/IPv4] + // Test: with default IPv4 address and port [UDP/IPv6] - // Test: [TCP/IPv6] + // Test: with default IPv6 address and port - // Test: [UDP/IPv4] + // Test: with default IPv6 address and port [TCP/IPv4] - // Test: [UDP/IPv6] + // Test: with default IPv6 address and port [TCP/IPv6] - // Test: with default IPv4 address + // Test: with default IPv6 address and port [UDP/IPv4] - // Test: with default IPv4 address [TCP/IPv4] + // Test: with default IPv6 address and port [UDP/IPv6] - // Test: with default IPv4 address [TCP/IPv6] + // + // Case: : + // - // Test: with default IPv4 address [UDP/IPv4] + // Test: : - // Test: with default IPv4 address [UDP/IPv6] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + portList[0]); + NTSCFG_TEST_OK(error); - // Test: with default IPv6 address [TCP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: with default IPv6 address [TCP/IPv6] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv6 address [UDP/IPv4] + options.setIpAddressSelector(i); - // Test: with default IPv6 address [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + portList[0]); + NTSCFG_TEST_OK(error); - // Test: with default port + NTSCFG_TEST_EQ(endpoint.ip().host(), + ipAddressList[i % ipAddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } + } - // Test: with default port [TCP/IPv4] + // Test: : [TCP/IPv4] - // Test: with default port [TCP/IPv6] + // Test: : [TCP/IPv6] - // Test: with default port [UDP/IPv4] + // Test: : [UDP/IPv4] - // Test: with default port [UDP/IPv6] + // Test: : [UDP/IPv6] - // Test: with default IPv4 address and port + // Test: : with default IPv4 address - // Test: with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: with default IPv4 address and port [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: with default IPv4 address and port [UDP/IPv4] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: with default IPv4 address and port [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv6] - // Test: with default IPv6 address and port + // Test: : with default IPv6 address - // Test: with default IPv6 address and port [TCP/IPv4] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: + // Test: : with default port -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default port [TCP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: : with default port [TCP/IPv6] - // Test: [TCP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: [TCP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: [UDP/IPv4] + // Test: : with default IPv4 address and port - // Test: [UDP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: with default IPv4 address + // Test: : with default IPv4 address and port [TCP/IPv6] -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [UDP/IPv4] - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + // Test: : with default IPv4 address and port [UDP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: : with default IPv6 address and port - // Test: with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: with default IPv4 address [TCP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: with default IPv4 address [UDP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: with default IPv4 address [UDP/IPv6] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: with default IPv6 address + // Test: : #if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; - - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + portList[0]); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: with default IPv6 address [TCP/IPv4] + // Test: : [TCP/IPv4] - // Test: with default IPv6 address [TCP/IPv6] + // Test: : [TCP/IPv6] - // Test: with default IPv6 address [UDP/IPv4] + // Test: : [UDP/IPv4] - // Test: with default IPv6 address [UDP/IPv6] + // Test: : [UDP/IPv6] - // Test: with default port + // Test: : with default IPv4 address #if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setPortFallback(portFallback); + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + portList[0]); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: with default port [TCP/IPv4] - - // Test: with default port [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: with default port [UDP/IPv4] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: with default port [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: with default IPv4 address and port + // Test: : with default IPv4 address [UDP/IPv6] - // Test: with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv6 address - // Test: with default IPv4 address and port [TCP/IPv6] - - // Test: with default IPv4 address and port [UDP/IPv4] +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: with default IPv4 address and port [UDP/IPv6] + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - // Test: with default IPv6 address and port + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + portList[0]); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: with default IPv6 address and port [TCP/IPv4] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: with default IPv6 address and port [TCP/IPv6] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: with default IPv6 address and port [UDP/IPv4] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv6 address [UDP/IPv6] - // - // Case: : - // + // Test: : with default port - // Test: : +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + options.setPortFallback(portFallback); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, - DOMAIN_NAME, + DOMAIN_NAME_INVALID, portList[0]); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } - - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; - - options.setIpAddressSelector(i); + NTSCFG_TEST_TRUE(error); + } +#endif - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - portList[0]); - NTSCFG_TEST_OK(error); + // Test: : with default port [TCP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host(), - ipAddressList[i % ipAddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } - } + // Test: : with default port [TCP/IPv6] - // Test: : [TCP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: : [TCP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: : [UDP/IPv4] + // Test: : with default IPv4 address and port - // Test: : [UDP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: : with default IPv4 address + // Test: : with default IPv4 address and port [TCP/IPv6] - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: : with default IPv6 address and port - // Test: : with default IPv4 address [UDP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: : with default IPv6 address + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // + // Case: : + // - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : - // Test: : with default port + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default port [TCP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: : with default port [UDP/IPv4] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default port [UDP/IPv6] + options.setIpAddressSelector(i); - // Test: : with default IPv4 address and port + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv4 address and port [TCP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host(), + ipAddressList[i % ipAddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); + } - // Test: : with default IPv4 address and port [TCP/IPv6] + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port [UDP/IPv4] + options.setPortSelector(j); - // Test: : with default IPv4 address and port [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv6 address and port + NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + portList[j % portList.size()]); + } - // Test: : with default IPv6 address and port [TCP/IPv4] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address and port [TCP/IPv6] + options.setIpAddressSelector(i); + options.setPortSelector(j); - // Test: : with default IPv6 address and port [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv6 address and port [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host(), + ipAddressList[i % ipAddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + portList[j % portList.size()]); + } + } + } - // Test: : + // Test: : [TCP/IPv4] -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - portList[0]); - NTSCFG_TEST_TRUE(error); - } -#endif + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : [TCP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); + } - // Test: : [TCP/IPv6] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : [UDP/IPv4] + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setIpAddressSelector(i); - // Test: : [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv4 address + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), + ipv4AddressList[i % ipv4AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); + } -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setPortSelector(j); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - portList[0]); - NTSCFG_TEST_TRUE(error); + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); } -#endif - // Test: : with default IPv4 address [TCP/IPv4] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address [TCP/IPv6] + options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setIpAddressSelector(i); + options.setPortSelector(j); - // Test: : with default IPv4 address [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv4 address [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), + ipv4AddressList[i % ipv4AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); + } + } + } - // Test: : with default IPv6 address + // Test: : [TCP/IPv6] -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - portList[0]); - NTSCFG_TEST_TRUE(error); + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); } -#endif - // Test: : with default IPv6 address [TCP/IPv4] - - // Test: : with default IPv6 address [TCP/IPv6] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address [UDP/IPv4] + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + options.setIpAddressSelector(i); - // Test: : with default IPv6 address [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default port + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), + ipv6AddressList[i % ipv6AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); + } -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setPortFallback(portFallback); + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + options.setPortSelector(j); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - portList[0]); - NTSCFG_TEST_TRUE(error); + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); } -#endif - // Test: : with default port [TCP/IPv4] + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default port [TCP/IPv6] + options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + options.setIpAddressSelector(i); + options.setPortSelector(j); - // Test: : with default port [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default port [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), + ipv6AddressList[i % ipv6AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + tcpPortList[j % tcpPortList.size()]); + } + } + } - // Test: : with default IPv4 address and port + // Test: : [UDP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv4] + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port [TCP/IPv6] + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - // Test: : with default IPv4 address and port [UDP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv4 address and port [UDP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); + } - // Test: : with default IPv6 address and port + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address and port [TCP/IPv4] + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + options.setIpAddressSelector(i); - // Test: : with default IPv6 address and port [TCP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - // Test: : with default IPv6 address and port [UDP/IPv4] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), + ipv4AddressList[i % ipv4AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); + } - // Test: : with default IPv6 address and port [UDP/IPv6] - - // - // Case: : - // - - // Test: : - - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; - - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } - - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressSelector(i); + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + options.setPortSelector(j); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host(), - ipAddressList[i % ipAddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), portList[0]); - } + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + udpPortList[j % udpPortList.size()]); + } + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; + options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + options.setIpAddressSelector(i); options.setPortSelector(j); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host(), ipAddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), + ipv4AddressList[i % ipv4AddressList.size()]); NTSCFG_TEST_EQ(endpoint.ip().port(), - portList[j % portList.size()]); + udpPortList[j % udpPortList.size()]); } + } + } - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : [UDP/IPv6] - options.setIpAddressSelector(i); - options.setPortSelector(j); + { + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, DOMAIN_NAME, SERVICE_NAME); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host(), - ipAddressList[i % ipAddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - portList[j % portList.size()]); - } - } + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); } - // Test: : [TCP/IPv4] - - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + options.setIpAddressSelector(i); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), + ipv6AddressList[i % ipv6AddressList.size()]); + NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); + } - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - options.setIpAddressSelector(i); + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + options.setPortSelector(j); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), - ipv4AddressList[i % ipv4AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().port(), + udpPortList[j % udpPortList.size()]); + } + for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { ntsa::Endpoint endpoint; ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + options.setIpAddressSelector(i); options.setPortSelector(j); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME); NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); + NTSCFG_TEST_EQ(endpoint.ip().host().v6(), + ipv6AddressList[i % ipv6AddressList.size()]); NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } - - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; - - options.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - options.setIpAddressSelector(i); - options.setPortSelector(j); - - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ( - endpoint.ip().host().v4(), - ipv4AddressList[i % ipv4AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } + udpPortList[j % udpPortList.size()]); } } + } - // Test: : [TCP/IPv6] + // Test: : with default IPv4 address - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address [TCP/IPv4] - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + // Test: : with default IPv4 address [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv4 address [UDP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + // Test: : with default IPv4 address [UDP/IPv6] - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - options.setIpAddressSelector(i); + // Test: : with default IPv6 address [TCP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv6 address [TCP/IPv6] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), - ipv6AddressList[i % ipv6AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), tcpPortList[0]); - } + // Test: : with default IPv6 address [UDP/IPv4] - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address [UDP/IPv6] - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - options.setPortSelector(j); + // Test: : with default port - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default port [TCP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } + // Test: : with default port [TCP/IPv6] - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default port [UDP/IPv4] - options.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - options.setIpAddressSelector(i); - options.setPortSelector(j); + // Test: : with default port [UDP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ( - endpoint.ip().host().v6(), - ipv6AddressList[i % ipv6AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - tcpPortList[j % tcpPortList.size()]); - } - } - } + // Test: : with default IPv4 address and port - // Test: : [UDP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv4] - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [TCP/IPv6] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + // Test: : with default IPv4 address and port [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv4 address and port [UDP/IPv6] - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv6 address and port - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv6 address and port [TCP/IPv4] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - options.setIpAddressSelector(i); + // Test: : with default IPv6 address and port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv6 address and port [UDP/IPv4] - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), - ipv4AddressList[i % ipv4AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv6 address and port [UDP/IPv6] - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - options.setPortSelector(j); +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, - DOMAIN_NAME, + DOMAIN_NAME_INVALID, SERVICE_NAME); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } + // Test: : [TCP/IPv4] - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : [TCP/IPv6] - options.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - options.setIpAddressSelector(i); - options.setPortSelector(j); + // Test: : [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ( - endpoint.ip().host().v4(), - ipv4AddressList[i % ipv4AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } - } - } + // Test: : [UDP/IPv6] - // Test: : [UDP/IPv6] + // Test: : with default IPv4 address - { - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, - DOMAIN_NAME, + DOMAIN_NAME_INVALID, SERVICE_NAME); - NTSCFG_TEST_OK(error); + NTSCFG_TEST_TRUE(error); + } +#endif - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv4 address [TCP/IPv4] - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address [TCP/IPv6] - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - options.setIpAddressSelector(i); + // Test: : with default IPv4 address [UDP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); + // Test: : with default IPv4 address [UDP/IPv6] - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), - ipv6AddressList[i % ipv6AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), udpPortList[0]); - } + // Test: : with default IPv6 address - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - options.setPortSelector(j); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, + error = ResolverTest::getEndpoint(&resolver, &endpoint, options, - DOMAIN_NAME, + DOMAIN_NAME_INVALID, SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(endpoint.ip().host().v6(), ipv6AddressList[0]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } - - for (bsl::size_t i = 0; i < 2 * ipAddressList.size(); ++i) { - for (bsl::size_t j = 0; j < 2 * portList.size(); ++j) { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + NTSCFG_TEST_TRUE(error); + } +#endif - options.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - options.setIpAddressSelector(i); - options.setPortSelector(j); + // Test: : with default IPv6 address [TCP/IPv4] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ( - endpoint.ip().host().v6(), - ipv6AddressList[i % ipv6AddressList.size()]); - NTSCFG_TEST_EQ(endpoint.ip().port(), - udpPortList[j % udpPortList.size()]); - } - } - } + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default IPv4 address + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: : with default port - // Test: : with default IPv4 address [UDP/IPv4] +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address [UDP/IPv6] + options.setPortFallback(portFallback); - // Test: : with default IPv6 address + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + SERVICE_NAME); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default port [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default port [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: : with default port + // Test: : with default IPv4 address and port - // Test: : with default port [TCP/IPv4] + // Test: : with default IPv4 address and port [TCP/IPv4] - // Test: : with default port [TCP/IPv6] + // Test: : with default IPv4 address and port [TCP/IPv6] - // Test: : with default port [UDP/IPv4] + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default port [UDP/IPv6] + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default IPv4 address and port + // Test: : with default IPv6 address and port - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv4 address and port [UDP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address and port [UDP/IPv6] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv6 address and port + // Test: : - // Test: : with default IPv6 address and port [TCP/IPv4] +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address and port [TCP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: : [TCP/IPv4] - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: : [TCP/IPv6] - // Test: : + // Test: : [UDP/IPv4] -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : [UDP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME); - NTSCFG_TEST_TRUE(error); - } + // Test: : with default IPv4 address + +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; + + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: : [UDP/IPv4] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: : [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv6] - // Test: : with default IPv4 address + // Test: : with default IPv6 address -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default IPv4 address [UDP/IPv6] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default IPv6 address + // Test: : with default port -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + options.setPortFallback(portFallback); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default port [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default port [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: : with default port + // Test: : with default IPv4 address and port -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [TCP/IPv4] - options.setPortFallback(portFallback); + // Test: : with default IPv4 address and port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: : with default IPv4 address and port [UDP/IPv4] - // Test: : with default port [TCP/IPv4] + // Test: : with default IPv4 address and port [UDP/IPv6] - // Test: : with default port [TCP/IPv6] + // Test: : with default IPv6 address and port - // Test: : with default port [UDP/IPv4] + // Test: : with default IPv6 address and port [TCP/IPv4] - // Test: : with default port [UDP/IPv6] + // Test: : with default IPv6 address and port [TCP/IPv6] - // Test: : with default IPv4 address and port + // Test: : with default IPv6 address and port [UDP/IPv4] - // Test: : with default IPv4 address and port [TCP/IPv4] + // Test: : with default IPv6 address and port [UDP/IPv6] - // Test: : with default IPv4 address and port [TCP/IPv6] + // Test: : - // Test: : with default IPv4 address and port [UDP/IPv4] +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } +#endif - // Test: : with default IPv6 address and port + // Test: : [TCP/IPv4] - // Test: : with default IPv6 address and port [TCP/IPv4] + // Test: : [TCP/IPv6] - // Test: : with default IPv6 address and port [TCP/IPv6] + // Test: : [UDP/IPv4] - // Test: : with default IPv6 address and port [UDP/IPv4] + // Test: : [UDP/IPv6] - // Test: : with default IPv6 address and port [UDP/IPv6] + // Test: : with default IPv4 address - // Test: : +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : [TCP/IPv4] + // Test: : with default IPv4 address [TCP/IPv4] - // Test: : [TCP/IPv6] + // Test: : with default IPv4 address [TCP/IPv6] - // Test: : [UDP/IPv4] + // Test: : with default IPv4 address [UDP/IPv4] - // Test: : [UDP/IPv6] + // Test: : with default IPv4 address [UDP/IPv6] - // Test: : with default IPv4 address + // Test: : with default IPv6 address -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv4 address [TCP/IPv4] + // Test: : with default IPv6 address [TCP/IPv4] - // Test: : with default IPv4 address [TCP/IPv6] + // Test: : with default IPv6 address [TCP/IPv6] - // Test: : with default IPv4 address [UDP/IPv4] + // Test: : with default IPv6 address [UDP/IPv4] - // Test: : with default IPv4 address [UDP/IPv6] + // Test: : with default IPv6 address [UDP/IPv6] - // Test: : with default IPv6 address + // Test: : with default port -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; +#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); + options.setPortFallback(portFallback); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + DOMAIN_NAME_INVALID, + SERVICE_NAME_INVALID); + NTSCFG_TEST_TRUE(error); + } #endif - // Test: : with default IPv6 address [TCP/IPv4] + // Test: : with default port [TCP/IPv4] - // Test: : with default IPv6 address [TCP/IPv6] + // Test: : with default port [TCP/IPv6] - // Test: : with default IPv6 address [UDP/IPv4] + // Test: : with default port [UDP/IPv4] - // Test: : with default IPv6 address [UDP/IPv6] + // Test: : with default port [UDP/IPv6] - // Test: : with default port + // Test: : with default IPv4 address and port -#if NTSB_RESOLVER_TEST_SERVICE_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + // Test: : with default IPv4 address and port [TCP/IPv4] - options.setPortFallback(portFallback); + // Test: : with default IPv4 address and port [TCP/IPv6] - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + // Test: : with default IPv4 address and port [UDP/IPv4] + + // Test: : with default IPv4 address and port [UDP/IPv6] + + // Test: : with default IPv6 address and port + + // Test: : with default IPv6 address and port [TCP/IPv4] + + // Test: : with default IPv6 address and port [TCP/IPv6] + + // Test: : with default IPv6 address and port [UDP/IPv4] + + // Test: : with default IPv6 address and port [UDP/IPv6] +} + +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase10) +{ + // Concern: Test resolution of endpoints with empty inputs but both an + // IP address fallback and port fallback specified. - // Test: : with default port [TCP/IPv4] + ntsa::Error error; - // Test: : with default port [TCP/IPv6] + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); - // Test: : with default port [UDP/IPv4] + const ntsa::Ipv4Address ipv4AddressFallback("192.168.0.100"); + const ntsa::Port portFallback = 12345; - // Test: : with default port [UDP/IPv6] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port + bsl::string emptyString; - // Test: : with default IPv4 address and port [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + emptyString); + NTSCFG_TEST_TRUE(error); + } - // Test: : with default IPv4 address and port [TCP/IPv6] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv4 address and port [UDP/IPv4] + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - // Test: : with default IPv4 address and port [UDP/IPv6] + bsl::string emptyString; - // Test: : with default IPv6 address and port + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + emptyString); + NTSCFG_TEST_TRUE(error); + } - // Test: : with default IPv6 address and port [TCP/IPv4] + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; - // Test: : with default IPv6 address and port [TCP/IPv6] + options.setPortFallback(portFallback); - // Test: : with default IPv6 address and port [UDP/IPv4] + bsl::string emptyString; - // Test: : with default IPv6 address and port [UDP/IPv6] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + emptyString); + NTSCFG_TEST_TRUE(error); + } - // Test: : + { + ntsa::Endpoint endpoint; + ntsa::EndpointOptions options; -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + options.setPortFallback(portFallback); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + bsl::string emptyString; - // Test: : [TCP/IPv4] + error = ResolverTest::getEndpoint(&resolver, + &endpoint, + options, + emptyString); + NTSCFG_TEST_OK(error); - // Test: : [TCP/IPv6] + NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressFallback); + NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); + } +} - // Test: : [UDP/IPv4] +NTSCFG_TEST_FUNCTION(ntsb::ResolverTest::verifyCase11) +{ + // Concern: Test resolution of a service name expressed as a port number. - // Test: : [UDP/IPv6] + ntsa::Error error; - // Test: : with default IPv4 address + ntsb::Resolver resolver(NTSCFG_TEST_ALLOCATOR); + ntsa::PortOptions portOptions; + + // clang-format off + struct Data { + const char* d_serviceName; + bsl::size_t d_port; + bool d_success; + } DATA[] = { + { "", 0, false }, + + { "0", 0, true }, + { " 0", 0, true }, + { "0 ", 0, true }, + { " 0 ", 0, true }, + + { "+0", 0, true }, + { " +0", 0, true }, + { "+0 ", 0, true }, + { " +0 ", 0, true }, + + { "-0", 0, false }, + { " -0", 0, false }, + { "-0 ", 0, false }, + { " -0 ", 0, false }, + + { "1", 1, true }, + { " 1", 1, true }, + { "1 ", 1, true }, + { " 1 ", 1, true }, + + { "+1", 1, true }, + { " +1", 1, true }, + { "+1 ", 1, true }, + { " +1 ", 1, true }, + + { "-1", 0, false }, + { " -1", 0, false }, + { "-1 ", 0, false }, + { " -1 ", 0, false }, + + { "8080", 8080, true }, + { " 8080", 8080, true }, + { "8080 ", 8080, true }, + { " 8080 ", 8080, true }, + + { "+8080", 8080, true }, + { " +8080", 8080, true }, + { "+8080 ", 8080, true }, + { " +8080 ", 8080, true }, + + { "-8080", 0, false }, + { " -8080", 0, false }, + { "-8080 ", 0, false }, + { " -8080 ", 0, false }, + + { "65535", 65535, true }, + { " 65535", 65535, true }, + { "65535 ", 65535, true }, + { " 65535 ", 65535, true }, + + { "+65535", 65535, true }, + { " +65535", 65535, true }, + { "+65535 ", 65535, true }, + { " +65535 ", 65535, true }, + + { "-65535", 0, false }, + { " -65535", 0, false }, + { "-65535 ", 0, false }, + { " -65535 ", 0, false }, + + { "4294967296", 0, false }, + { " 4294967296", 0, false }, + { "4294967296 ", 0, false }, + { " 4294967296 ", 0, false }, + + { "+4294967296", 0, false }, + { " +4294967296", 0, false }, + { "+4294967296 ", 0, false }, + { " +4294967296 ", 0, false }, + + { "-4294967296", 0, false }, + { " -4294967296", 0, false }, + { "-4294967296 ", 0, false }, + { " -4294967296 ", 0, false }, + + { "18446744073709551615", 0, false }, + { " 18446744073709551615", 0, false }, + { "18446744073709551615 ", 0, false }, + { " 18446744073709551615 ", 0, false }, + + { "+18446744073709551615", 0, false }, + { " +18446744073709551615", 0, false }, + { "+18446744073709551615 ", 0, false }, + { " +18446744073709551615 ", 0, false }, + + { "-18446744073709551615", 0, false }, + { " -18446744073709551615", 0, false }, + { "-18446744073709551615 ", 0, false }, + { " -18446744073709551615 ", 0, false }, + + { "99999999999999999999", 0, false }, + { " 99999999999999999999", 0, false }, + { "99999999999999999999 ", 0, false }, + { " 99999999999999999999 ", 0, false }, + + { "+99999999999999999999", 0, false }, + { " +99999999999999999999", 0, false }, + { "+99999999999999999999 ", 0, false }, + { " +99999999999999999999 ", 0, false }, + + { "-99999999999999999999", 0, false }, + { " -99999999999999999999", 0, false }, + { "-99999999999999999999 ", 0, false }, + { " -99999999999999999999 ", 0, false } + }; + // clang-format on + + for (bsl::size_t i = 0; i < sizeof(DATA) / sizeof(DATA[0]); ++i) { + bsl::vector portList; + error = resolver.getPort(&portList, + bslstl::StringRef(DATA[i].d_serviceName), + portOptions); -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + bsl::size_t portNumber = 0; + if (!portList.empty()) { + portNumber = static_cast(portList[0]); + } - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + BSLS_LOG_DEBUG("Service name '%s' => port %zu: error = %s", + DATA[i].d_serviceName, + portNumber, + error.text().c_str()); - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); + if (DATA[i].d_success) { + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(portList.size(), 1); + NTSCFG_TEST_EQ(portNumber, DATA[i].d_port); } -#endif + else { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); + NTSCFG_TEST_TRUE(portList.empty()); + } + } +} + +bsl::string ResolverTest::makeEndpointSpecifier(ntsa::Port port) +{ + bsl::stringstream ss; + ss << port; + + return ss.str(); +} - // Test: : with default IPv4 address [TCP/IPv4] +bsl::string ResolverTest::makeEndpointSpecifier(const bsl::string& host) +{ + bsl::stringstream ss; + ss << host; - // Test: : with default IPv4 address [TCP/IPv6] + return ss.str(); +} - // Test: : with default IPv4 address [UDP/IPv4] +bsl::string ResolverTest::makeEndpointSpecifier(const bsl::string& host, + const bsl::string& port) +{ + bsl::stringstream ss; + ss << host << ':' << port; - // Test: : with default IPv4 address [UDP/IPv6] + return ss.str(); +} - // Test: : with default IPv6 address +bsl::string ResolverTest::makeEndpointSpecifier(const bsl::string& host, + ntsa::Port port) +{ + bsl::stringstream ss; + ss << host << ':' << port; -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + return ss.str(); +} - options.setIpAddressFallback(ntsa::IpAddress(ipv6AddressFallback)); +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv4Address& host) +{ + bsl::stringstream ss; + ss << host; - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + return ss.str(); +} - // Test: : with default IPv6 address [TCP/IPv4] +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv4Address& host, + const bsl::string& port) +{ + bsl::stringstream ss; + ss << host << ':' << port; - // Test: : with default IPv6 address [TCP/IPv6] + return ss.str(); +} - // Test: : with default IPv6 address [UDP/IPv4] +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv4Address& host, + ntsa::Port port) +{ + bsl::stringstream ss; + ss << host << ':' << port; - // Test: : with default IPv6 address [UDP/IPv6] + return ss.str(); +} - // Test: : with default port +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv6Address& host) +{ + bsl::stringstream ss; + ss << host; -#if NTSB_RESOLVER_TEST_DOMAIN_NAME_INVALID - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + return ss.str(); +} - options.setPortFallback(portFallback); +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv6Address& host, + const bsl::string& port) +{ + bsl::stringstream ss; + ss << '[' << host << ']' << ':' << port; - error = test::getEndpoint(&resolver, - &endpoint, - options, - DOMAIN_NAME_INVALID, - SERVICE_NAME_INVALID); - NTSCFG_TEST_TRUE(error); - } -#endif + return ss.str(); +} - // Test: : with default port [TCP/IPv4] +bsl::string ResolverTest::makeEndpointSpecifier(const ntsa::Ipv6Address& host, + ntsa::Port port) +{ + bsl::stringstream ss; + ss << '[' << host << ']' << ':' << port; - // Test: : with default port [TCP/IPv6] + return ss.str(); +} - // Test: : with default port [UDP/IPv4] +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + ntsa::Port port) +{ + ntsa::Error error; - // Test: : with default port [UDP/IPv6] + bsl::string text = ResolverTest::makeEndpointSpecifier(port); - // Test: : with default IPv4 address and port + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - // Test: : with default IPv4 address and port [TCP/IPv4] + error = resolver->getEndpoint(endpoint, text, options); - // Test: : with default IPv4 address and port [TCP/IPv6] + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } - // Test: : with default IPv4 address and port [UDP/IPv4] + return error; +} - // Test: : with default IPv4 address and port [UDP/IPv6] +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host) +{ + ntsa::Error error; - // Test: : with default IPv6 address and port + bsl::string text = ResolverTest::makeEndpointSpecifier(host); - // Test: : with default IPv6 address and port [TCP/IPv4] + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; + + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } - // Test: : with default IPv6 address and port [TCP/IPv6] + return error; +} + +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host, + const bsl::string& port) +{ + ntsa::Error error; + + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); - // Test: : with default IPv6 address and port [UDP/IPv4] + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - // Test: : with default IPv6 address and port [UDP/IPv6] + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } + + return error; } -NTSCFG_TEST_CASE(10) +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const bsl::string& host, + ntsa::Port port) { - // Concern: Test resolution of endpoints with empty inputs but both an - // IP address fallback and port fallback specified. - // - // Plan: + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); - ntsb::Resolver resolver(&ta); + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - const ntsa::Ipv4Address ipv4AddressFallback("192.168.0.100"); - const ntsa::Port portFallback = 12345; + error = resolver->getEndpoint(endpoint, text, options); - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } - bsl::string emptyString; + return error; +} - error = - test::getEndpoint(&resolver, &endpoint, options, emptyString); - NTSCFG_TEST_TRUE(error); - } +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host) +{ + ntsa::Error error; - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + bsl::string text = ResolverTest::makeEndpointSpecifier(host); - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - bsl::string emptyString; + error = resolver->getEndpoint(endpoint, text, options); - error = - test::getEndpoint(&resolver, &endpoint, options, emptyString); - NTSCFG_TEST_TRUE(error); - } + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + return error; +} - options.setPortFallback(portFallback); +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host, + const bsl::string& port) +{ + ntsa::Error error; - bsl::string emptyString; + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); - error = - test::getEndpoint(&resolver, &endpoint, options, emptyString); - NTSCFG_TEST_TRUE(error); - } + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - { - ntsa::Endpoint endpoint; - ntsa::EndpointOptions options; + error = resolver->getEndpoint(endpoint, text, options); - options.setIpAddressFallback(ntsa::IpAddress(ipv4AddressFallback)); - options.setPortFallback(portFallback); + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } - bsl::string emptyString; + return error; +} - error = - test::getEndpoint(&resolver, &endpoint, options, emptyString); - NTSCFG_TEST_OK(error); +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv4Address& host, + ntsa::Port port) +{ + ntsa::Error error; - NTSCFG_TEST_EQ(endpoint.ip().host().v4(), ipv4AddressFallback); - NTSCFG_TEST_EQ(endpoint.ip().port(), portFallback); - } + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); + + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; + + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + return error; } -NTSCFG_TEST_CASE(11) +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host) { - // Concern: Test resolution of a service name expressed as a port number. + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - ntsb::Resolver resolver(&ta); - ntsa::PortOptions portOptions; - - // clang-format off - struct Data { - const char* d_serviceName; - bsl::size_t d_port; - bool d_success; - } DATA[] = { - { "", 0, false }, - - { "0", 0, true }, - { " 0", 0, true }, - { "0 ", 0, true }, - { " 0 ", 0, true }, - - { "+0", 0, true }, - { " +0", 0, true }, - { "+0 ", 0, true }, - { " +0 ", 0, true }, - - { "-0", 0, false }, - { " -0", 0, false }, - { "-0 ", 0, false }, - { " -0 ", 0, false }, - - { "1", 1, true }, - { " 1", 1, true }, - { "1 ", 1, true }, - { " 1 ", 1, true }, - - { "+1", 1, true }, - { " +1", 1, true }, - { "+1 ", 1, true }, - { " +1 ", 1, true }, - - { "-1", 0, false }, - { " -1", 0, false }, - { "-1 ", 0, false }, - { " -1 ", 0, false }, - - { "8080", 8080, true }, - { " 8080", 8080, true }, - { "8080 ", 8080, true }, - { " 8080 ", 8080, true }, - - { "+8080", 8080, true }, - { " +8080", 8080, true }, - { "+8080 ", 8080, true }, - { " +8080 ", 8080, true }, - - { "-8080", 0, false }, - { " -8080", 0, false }, - { "-8080 ", 0, false }, - { " -8080 ", 0, false }, - - { "65535", 65535, true }, - { " 65535", 65535, true }, - { "65535 ", 65535, true }, - { " 65535 ", 65535, true }, - - { "+65535", 65535, true }, - { " +65535", 65535, true }, - { "+65535 ", 65535, true }, - { " +65535 ", 65535, true }, - - { "-65535", 0, false }, - { " -65535", 0, false }, - { "-65535 ", 0, false }, - { " -65535 ", 0, false }, - - { "4294967296", 0, false }, - { " 4294967296", 0, false }, - { "4294967296 ", 0, false }, - { " 4294967296 ", 0, false }, - - { "+4294967296", 0, false }, - { " +4294967296", 0, false }, - { "+4294967296 ", 0, false }, - { " +4294967296 ", 0, false }, - - { "-4294967296", 0, false }, - { " -4294967296", 0, false }, - { "-4294967296 ", 0, false }, - { " -4294967296 ", 0, false }, - - { "18446744073709551615", 0, false }, - { " 18446744073709551615", 0, false }, - { "18446744073709551615 ", 0, false }, - { " 18446744073709551615 ", 0, false }, - - { "+18446744073709551615", 0, false }, - { " +18446744073709551615", 0, false }, - { "+18446744073709551615 ", 0, false }, - { " +18446744073709551615 ", 0, false }, - - { "-18446744073709551615", 0, false }, - { " -18446744073709551615", 0, false }, - { "-18446744073709551615 ", 0, false }, - { " -18446744073709551615 ", 0, false }, - - { "99999999999999999999", 0, false }, - { " 99999999999999999999", 0, false }, - { "99999999999999999999 ", 0, false }, - { " 99999999999999999999 ", 0, false }, - - { "+99999999999999999999", 0, false }, - { " +99999999999999999999", 0, false }, - { "+99999999999999999999 ", 0, false }, - { " +99999999999999999999 ", 0, false }, - - { "-99999999999999999999", 0, false }, - { " -99999999999999999999", 0, false }, - { "-99999999999999999999 ", 0, false }, - { " -99999999999999999999 ", 0, false } - }; - // clang-format on - - for (bsl::size_t i = 0; i < sizeof(DATA) / sizeof(DATA[0]); ++i) { - bsl::vector portList; - error = resolver.getPort(&portList, - bslstl::StringRef(DATA[i].d_serviceName), - portOptions); - - bsl::size_t portNumber = 0; - if (!portList.empty()) { - portNumber = static_cast(portList[0]); - } + bsl::string text = ResolverTest::makeEndpointSpecifier(host); - BSLS_LOG_DEBUG("Service name '%s' => port %zu: error = %s", - DATA[i].d_serviceName, - portNumber, - error.text().c_str()); + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - if (DATA[i].d_success) { - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(portList.size(), 1); - NTSCFG_TEST_EQ(portNumber, DATA[i].d_port); - } - else { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - NTSCFG_TEST_TRUE(portList.empty()); - } - } + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } + + return error; } -NTSCFG_TEST_DRIVER +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host, + const bsl::string& port) { - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); - NTSCFG_TEST_REGISTER(8); + ntsa::Error error; - NTSCFG_TEST_REGISTER(9); + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); - NTSCFG_TEST_REGISTER(10); + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_REGISTER(11); + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } + + return error; +} + +ntsa::Error ResolverTest::getEndpoint(ntsb::Resolver* resolver, + ntsa::Endpoint* endpoint, + const ntsa::EndpointOptions& options, + const ntsa::Ipv6Address& host, + ntsa::Port port) +{ + ntsa::Error error; + + bsl::string text = ResolverTest::makeEndpointSpecifier(host, port); + + NTSCFG_TEST_LOG_DEBUG << "--" << NTSCFG_TEST_LOG_END; + NTSCFG_TEST_LOG_DEBUG << "Parsing: '" << text << "' using options " + << options << NTSCFG_TEST_LOG_END; + + error = resolver->getEndpoint(endpoint, text, options); + + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + NTSCFG_TEST_LOG_DEBUG << "Endpoint = " << *endpoint + << NTSCFG_TEST_LOG_END; + } + + return error; } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsb +} // close namespace BloombergLP diff --git a/groups/nts/ntsb/ntsb_streamsocket.cpp b/groups/nts/ntsb/ntsb_streamsocket.cpp index 15d6756b..119bbc34 100644 --- a/groups/nts/ntsb/ntsb_streamsocket.cpp +++ b/groups/nts/ntsb/ntsb_streamsocket.cpp @@ -109,7 +109,7 @@ ntsa::Error StreamSocket::send(ntsa::SendContext* context, } ntsa::Error StreamSocket::send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) { diff --git a/groups/nts/ntsb/ntsb_streamsocket.h b/groups/nts/ntsb/ntsb_streamsocket.h index 86ad9a07..d40c17b1 100644 --- a/groups/nts/ntsb/ntsb_streamsocket.h +++ b/groups/nts/ntsb/ntsb_streamsocket.h @@ -106,7 +106,7 @@ class StreamSocket : public ntsi::StreamSocket /// the specified 'context' the result of the operation. Return the /// error. ntsa::Error send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) BSLS_KEYWORD_OVERRIDE; diff --git a/groups/nts/ntsb/ntsb_streamsocket.t.cpp b/groups/nts/ntsb/ntsb_streamsocket.t.cpp index ca4ac692..af47f989 100644 --- a/groups/nts/ntsb/ntsb_streamsocket.t.cpp +++ b/groups/nts/ntsb/ntsb_streamsocket.t.cpp @@ -13,124 +13,50 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntsb_streamsocket_t_cpp, "$Id$ $CSID$") + #include -#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- - -namespace test { - -namespace { - -/// Provide a suite of utilities for generating test data. -/// This struct is completely thread safe. -struct DataUtil { - /// Return the byte at the specified 'position' in the specified - /// 'dataset'. - static char generateByte(int position, int dataset); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bsl::string* result, - int size, - int offset = 0, - int dataset = 0); - - /// Load into the specified 'result' the specified 'size' sequence of - /// bytes from the specified 'dataset' starting at the specified - /// 'offset'. - static void generateData(bdlbb::Blob* result, - int size, - int offset = 0, - int dataset = 0); -}; - -char DataUtil::generateByte(int position, int dataset) -{ - struct { - const char* source; - int length; - } DATA[] = { - {"abcdefghijklmnopqrstuvwxyz", 26}, - {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26} - }; - - enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; - - dataset = dataset % NUM_DATA; - return DATA[dataset].source[position % DATA[dataset].length]; -} - -void DataUtil::generateData(bsl::string* result, - int size, - int offset, - int dataset) -{ - result->clear(); - result->resize(size); - - for (int i = offset; i < offset + size; ++i) { - (*result)[i] = generateByte(offset + i, dataset); - } -} +namespace BloombergLP { +namespace ntsb { -void DataUtil::generateData(bdlbb::Blob* result, - int size, - int offset, - int dataset) +// Provide tests for 'ntsb::StreamSocket'. +class StreamSocketTest { - result->removeAll(); - result->setLength(size); + public: + // TODO + static void verifyCase1(); - int k = 0; + // TODO + static void verifyCase2(); - for (int i = 0; i < result->numDataBuffers(); ++i) { - const bdlbb::BlobBuffer& buffer = result->buffer(i); - - int numBytesToWrite = i == result->numDataBuffers() - 1 - ? result->lastDataBufferLength() - : buffer.size(); + private: + /// Test the implementations of the specified 'client' and 'server' + /// send and receive data correctly using basic, contiguous buffers. + /// Optionally specify a 'basicAllocator' used to supply memory. If + /// 'basicAllocator' is 0, the currently installed default allocator + /// is used. + static void testBufferIO(const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator = 0); - for (int j = 0; j < numBytesToWrite; ++j) { - buffer.data()[j] = generateByte(offset + k, dataset); - ++k; - } - } -} + /// Test the implementations of the specified 'client' and 'server' + /// send and receive data correctly using vectored I/O and the + /// scatter/gather paradigm. Optionally specify a 'basicAllocator' used + /// to supply memory. If 'basicAllocator' is 0, the currently installed + /// default allocator is used. + static void testVectorIO(const bsl::shared_ptr& client, + const bsl::shared_ptr& server, + bslma::Allocator* basicAllocator = 0); -/// Provide utilities for testing stream sockets. -struct StreamSocketUtil { /// Send all the specified 'data' having the specified 'size' through /// the specified 'socket', using as many system calls as necessary. /// Return the error. @@ -153,238 +79,134 @@ struct StreamSocketUtil { /// 'data' from the specified 'socket', using as many system calls as /// necessary. Return the error. static ntsa::Error receiveAll(bdlbb::Blob* data, ntsa::Handle socket); -}; - -ntsa::Error StreamSocketUtil::sendAll(const void* data, - bsl::size_t size, - ntsa::Handle socket) -{ - if (size == 0) { - return ntsa::Error(); - } - - NTSCFG_TEST_TRUE(data); - bsl::size_t numBytesRemaining = size; - const char* position = static_cast(data); - - while (numBytesRemaining > 0) { - ntsa::SendContext context; - ntsa::SendOptions options; + /// Send from the specified 'client' all the specified 'clientData' + /// to the peer of the 'client'. + static void sendString(const bsl::shared_ptr& client, + const bsl::string* clientData); - ntsa::Data data(ntsa::ConstBuffer(position, numBytesRemaining)); + /// Receive from the specified 'server' into the pre-ressized + /// 'serverData' all the data sent by the peer of the 'server'. + static void receiveString( + const bsl::shared_ptr& server, + bsl::string* serverData); - ntsa::Error error = - ntsu::SocketUtil::send(&context, data, options, socket); - if (error) { - if (error == ntsa::Error::e_INTERRUPTED) { - continue; - } - return error; - } + /// Send from the specified 'client' all the specified 'clientData' + /// to the peer of the 'client'. + static void sendBlob(const bsl::shared_ptr& client, + const bdlbb::Blob* clientData); - BSLS_LOG_DEBUG("[+]" - "\nnumBytesSendable: %d" - "\nnumBytesSent: %d", - context.bytesSendable(), - context.bytesSent()); + /// Receive from the specified 'server' into the pre-ressized + /// 'serverData' all the data sent by the peer of the 'server'. + static void receiveBlob(const bsl::shared_ptr& server, + bdlbb::Blob* serverData); +}; - NTSCFG_TEST_LE(context.bytesSent(), numBytesRemaining); +NTSCFG_TEST_FUNCTION(ntsb::StreamSocketTest::verifyCase1) +{ + bsl::vector socketTypes; - position += context.bytesSent(); - numBytesRemaining -= context.bytesSent(); + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV4_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); } - NTSCFG_TEST_EQ(numBytesRemaining, 0); - NTSCFG_TEST_EQ(position, static_cast(data) + size); - - return ntsa::Error(); -} - -ntsa::Error StreamSocketUtil::receiveAll(void* data, - bsl::size_t size, - ntsa::Handle socket) -{ - if (size == 0) { - return ntsa::Error(); + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV6_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); } - NTSCFG_TEST_TRUE(data); - - bsl::size_t numBytesRemaining = size; - char* position = static_cast(data); - - while (numBytesRemaining > 0) { - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(position, numBytesRemaining)); + if (ntsu::AdapterUtil::supportsTransport(ntsa::Transport::e_LOCAL_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); + } - ntsa::Error error = - ntsu::SocketUtil::receive(&context, &data, options, socket); - if (error) { - if (error == ntsa::Error::e_INTERRUPTED) { - continue; - } - return error; - } + for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { + ntsa::Transport::Value transport = socketTypes[i]; - BSLS_LOG_DEBUG("[-]" - "\nnumBytesReceivable: %d" - "\nnumBytesReceived: %d", - context.bytesReceivable(), - context.bytesReceived()); + ntscfg::TestAllocator ta; + { + ntsa::Error error; - NTSCFG_TEST_LE(context.bytesReceived(), numBytesRemaining); + bsl::shared_ptr client; + bsl::shared_ptr server; - position += context.bytesReceived(); - numBytesRemaining -= context.bytesReceived(); - } + error = ntsb::StreamSocket::pair(&client, &server, transport, &ta); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - NTSCFG_TEST_EQ(numBytesRemaining, 0); - NTSCFG_TEST_EQ(position, static_cast(data) + size); + StreamSocketTest::testBufferIO(client, server, &ta); - return ntsa::Error(); -} + error = client->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -ntsa::Error StreamSocketUtil::sendAll(const bdlbb::Blob& data, - ntsa::Handle socket) -{ - bdlbb::Blob dataRemaining = data; + error = server->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - while (dataRemaining.length() > 0) { - ntsa::SendContext context; - ntsa::SendOptions options; + error = client->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - ntsa::Error error = - ntsu::SocketUtil::send(&context, dataRemaining, options, socket); - if (error) { - if (error == ntsa::Error::e_INTERRUPTED) { - continue; - } - return error; + error = server->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); } - - BSLS_LOG_DEBUG("[+]" - "\nnumBytesSendable: %d" - "\nnumBytesSent: %d", - context.bytesSendable(), - context.bytesSent()); - - bdlbb::BlobUtil::erase(&dataRemaining, 0, context.bytesSent()); + NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } - - return ntsa::Error(); } -ntsa::Error StreamSocketUtil::receiveAll(bdlbb::Blob* data, - ntsa::Handle socket) +NTSCFG_TEST_FUNCTION(ntsb::StreamSocketTest::verifyCase2) { - do { - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Error error = - ntsu::SocketUtil::receive(&context, data, options, socket); - if (error) { - if (error == ntsa::Error::e_INTERRUPTED) { - continue; - } - return error; - } + bsl::vector socketTypes; - BSLS_LOG_DEBUG("[-]" - "\nnumBytesReceivable: %d" - "\nnumBytesReceived: %d", - context.bytesReceivable(), - context.bytesReceived()); - } while (data->length() < data->totalSize()); + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV4_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); + } - return ntsa::Error(); -} + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV6_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); + } -/// Provide utilities for sending and receiving data. -struct AsyncUtil { - /// Send from the specified 'client' all the specified 'clientData' - /// to the peer of the 'client'. - static void sendString(const bsl::shared_ptr& client, - const bsl::string* clientData); + if (ntsu::AdapterUtil::supportsTransport(ntsa::Transport::e_LOCAL_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); + } - /// Receive from the specified 'server' into the pre-ressized - /// 'serverData' all the data sent by the peer of the 'server'. - static void receiveString( - const bsl::shared_ptr& server, - bsl::string* serverData); + for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { + ntsa::Transport::Value transport = socketTypes[i]; - /// Send from the specified 'client' all the specified 'clientData' - /// to the peer of the 'client'. - static void sendBlob(const bsl::shared_ptr& client, - const bdlbb::Blob* clientData); + ntscfg::TestAllocator ta; + { + ntsa::Error error; - /// Receive from the specified 'server' into the pre-ressized - /// 'serverData' all the data sent by the peer of the 'server'. - static void receiveBlob(const bsl::shared_ptr& server, - bdlbb::Blob* serverData); -}; + bsl::shared_ptr client; + bsl::shared_ptr server; -void AsyncUtil::sendString(const bsl::shared_ptr& client, - const bsl::string* clientData) -{ - ntsa::Error error = StreamSocketUtil::sendAll(&(*clientData)[0], - clientData->size(), - client->handle()); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -} + error = ntsb::StreamSocket::pair(&client, &server, transport, &ta); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -void AsyncUtil::receiveString( - const bsl::shared_ptr& server, - bsl::string* serverData) -{ - ntsa::Error error = StreamSocketUtil::receiveAll(&(*serverData)[0], - serverData->size(), - server->handle()); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -} + StreamSocketTest::testVectorIO(client, server, &ta); -void AsyncUtil::sendBlob(const bsl::shared_ptr& client, - const bdlbb::Blob* clientData) -{ - ntsa::Error error = - StreamSocketUtil::sendAll(*clientData, client->handle()); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -} + error = client->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -void AsyncUtil::receiveBlob(const bsl::shared_ptr& server, - bdlbb::Blob* serverData) -{ - ntsa::Error error = - StreamSocketUtil::receiveAll(serverData, server->handle()); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -} + error = server->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); -/// Provide facilities to test different stream sockets -/// conveniently in one place. -struct StreamSocketTester { - /// Test the implementations of the specified 'client' and 'server' - /// send and receive data correctly using basic, contiguous buffers. - /// Optionally specify a 'basicAllocator' used to supply memory. If - /// 'basicAllocator' is 0, the currently installed default allocator - /// is used. - static void testBufferIO(const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator = 0); + error = client->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - /// Test the implementations of the specified 'client' and 'server' - /// send and receive data correctly using vectored I/O and the - /// scatter/gather paradigm. Optionally specify a 'basicAllocator' used - /// to supply memory. If 'basicAllocator' is 0, the currently installed - /// default allocator is used. - static void testVectorIO(const bsl::shared_ptr& client, - const bsl::shared_ptr& server, - bslma::Allocator* basicAllocator = 0); -}; + error = server->close(); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + } + NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + } +} -void StreamSocketTester::testBufferIO( +void StreamSocketTest::testBufferIO( const bsl::shared_ptr& client, const bsl::shared_ptr& server, bslma::Allocator* basicAllocator) @@ -396,16 +218,19 @@ void StreamSocketTester::testBufferIO( const bsl::size_t SIZE = 1024 * 1024 * 64; bsl::string clientData(allocator); - DataUtil::generateData(&clientData, SIZE); + ntscfg::TestDataUtil::generateData(&clientData, SIZE); bsl::string serverData(allocator); serverData.resize(SIZE); bslmt::ThreadGroup threadGroup(allocator); + threadGroup.addThread(bdlf::BindUtil::bind(&StreamSocketTest::sendString, + client, + &clientData)); threadGroup.addThread( - bdlf::BindUtil::bind(&AsyncUtil::sendString, client, &clientData)); - threadGroup.addThread( - bdlf::BindUtil::bind(&AsyncUtil::receiveString, server, &serverData)); + bdlf::BindUtil::bind(&StreamSocketTest::receiveString, + server, + &serverData)); threadGroup.joinAll(); @@ -441,7 +266,7 @@ void StreamSocketTester::testBufferIO( } } -void StreamSocketTester::testVectorIO( +void StreamSocketTest::testVectorIO( const bsl::shared_ptr& client, const bsl::shared_ptr& server, bslma::Allocator* basicAllocator) @@ -455,7 +280,7 @@ void StreamSocketTester::testVectorIO( const bsl::size_t SIZE = 1024 * 1024 * 64; bdlbb::Blob clientData(&blobBufferFactory, allocator); - DataUtil::generateData(&clientData, SIZE); + ntscfg::TestDataUtil::generateData(&clientData, SIZE); bdlbb::Blob serverData(&blobBufferFactory, allocator); serverData.setLength(SIZE); @@ -464,10 +289,12 @@ void StreamSocketTester::testVectorIO( NTSCFG_TEST_EQ(serverData.totalSize(), SIZE); bslmt::ThreadGroup threadGroup(allocator); - threadGroup.addThread( - bdlf::BindUtil::bind(&AsyncUtil::sendBlob, client, &clientData)); - threadGroup.addThread( - bdlf::BindUtil::bind(&AsyncUtil::receiveBlob, server, &serverData)); + threadGroup.addThread(bdlf::BindUtil::bind(&StreamSocketTest::sendBlob, + client, + &clientData)); + threadGroup.addThread(bdlf::BindUtil::bind(&StreamSocketTest::receiveBlob, + server, + &serverData)); threadGroup.joinAll(); @@ -503,123 +330,191 @@ void StreamSocketTester::testVectorIO( } } -} // close unnamed namespace +ntsa::Error StreamSocketTest::sendAll(const void* data, + bsl::size_t size, + ntsa::Handle socket) +{ + if (size == 0) { + return ntsa::Error(); + } -} // close namespace test + NTSCFG_TEST_TRUE(data); -NTSCFG_TEST_CASE(1) -{ - // Concern: - // Plan: + bsl::size_t numBytesRemaining = size; + const char* position = static_cast(data); - bsl::vector socketTypes; + while (numBytesRemaining > 0) { + ntsa::SendContext context; + ntsa::SendOptions options; - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV4_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); - } + ntsa::Data data(ntsa::ConstBuffer(position, numBytesRemaining)); - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV6_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); - } + ntsa::Error error = + ntsu::SocketUtil::send(&context, data, options, socket); + if (error) { + if (error == ntsa::Error::e_INTERRUPTED) { + continue; + } + return error; + } - if (ntsu::AdapterUtil::supportsTransport(ntsa::Transport::e_LOCAL_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); - } + BSLS_LOG_DEBUG("[+]" + "\nnumBytesSendable: %d" + "\nnumBytesSent: %d", + context.bytesSendable(), + context.bytesSent()); - for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { - ntsa::Transport::Value transport = socketTypes[i]; + NTSCFG_TEST_LE(context.bytesSent(), numBytesRemaining); - ntscfg::TestAllocator ta; - { - ntsa::Error error; + position += context.bytesSent(); + numBytesRemaining -= context.bytesSent(); + } - bsl::shared_ptr client; - bsl::shared_ptr server; + NTSCFG_TEST_EQ(numBytesRemaining, 0); + NTSCFG_TEST_EQ(position, static_cast(data) + size); - error = ntsb::StreamSocket::pair(&client, &server, transport, &ta); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + return ntsa::Error(); +} - test::StreamSocketTester::testBufferIO(client, server, &ta); +ntsa::Error StreamSocketTest::receiveAll(void* data, + bsl::size_t size, + ntsa::Handle socket) +{ + if (size == 0) { + return ntsa::Error(); + } - error = client->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + NTSCFG_TEST_TRUE(data); - error = server->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + bsl::size_t numBytesRemaining = size; + char* position = static_cast(data); - error = client->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + while (numBytesRemaining > 0) { + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - error = server->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + ntsa::Data data(ntsa::MutableBuffer(position, numBytesRemaining)); + + ntsa::Error error = + ntsu::SocketUtil::receive(&context, &data, options, socket); + if (error) { + if (error == ntsa::Error::e_INTERRUPTED) { + continue; + } + return error; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + BSLS_LOG_DEBUG("[-]" + "\nnumBytesReceivable: %d" + "\nnumBytesReceived: %d", + context.bytesReceivable(), + context.bytesReceived()); + + NTSCFG_TEST_LE(context.bytesReceived(), numBytesRemaining); + + position += context.bytesReceived(); + numBytesRemaining -= context.bytesReceived(); } + + NTSCFG_TEST_EQ(numBytesRemaining, 0); + NTSCFG_TEST_EQ(position, static_cast(data) + size); + + return ntsa::Error(); } -NTSCFG_TEST_CASE(2) +ntsa::Error StreamSocketTest::sendAll(const bdlbb::Blob& data, + ntsa::Handle socket) { - // Concern: - // Plan: + bdlbb::Blob dataRemaining = data; - bsl::vector socketTypes; + while (dataRemaining.length() > 0) { + ntsa::SendContext context; + ntsa::SendOptions options; - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV4_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); - } + ntsa::Error error = + ntsu::SocketUtil::send(&context, dataRemaining, options, socket); + if (error) { + if (error == ntsa::Error::e_INTERRUPTED) { + continue; + } + return error; + } - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV6_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); - } + BSLS_LOG_DEBUG("[+]" + "\nnumBytesSendable: %d" + "\nnumBytesSent: %d", + context.bytesSendable(), + context.bytesSent()); - if (ntsu::AdapterUtil::supportsTransport(ntsa::Transport::e_LOCAL_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); + bdlbb::BlobUtil::erase(&dataRemaining, 0, context.bytesSent()); } - for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { - ntsa::Transport::Value transport = socketTypes[i]; - - ntscfg::TestAllocator ta; - { - ntsa::Error error; + return ntsa::Error(); +} - bsl::shared_ptr client; - bsl::shared_ptr server; +ntsa::Error StreamSocketTest::receiveAll(bdlbb::Blob* data, + ntsa::Handle socket) +{ + do { + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - error = ntsb::StreamSocket::pair(&client, &server, transport, &ta); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + ntsa::Error error = + ntsu::SocketUtil::receive(&context, data, options, socket); + if (error) { + if (error == ntsa::Error::e_INTERRUPTED) { + continue; + } + return error; + } - test::StreamSocketTester::testVectorIO(client, server, &ta); + BSLS_LOG_DEBUG("[-]" + "\nnumBytesReceivable: %d" + "\nnumBytesReceived: %d", + context.bytesReceivable(), + context.bytesReceived()); + } while (data->length() < data->totalSize()); - error = client->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); + return ntsa::Error(); +} - error = server->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); +void StreamSocketTest::sendString( + const bsl::shared_ptr& client, + const bsl::string* clientData) +{ + ntsa::Error error = StreamSocketTest::sendAll(&(*clientData)[0], + clientData->size(), + client->handle()); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); +} - error = client->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); +void StreamSocketTest::receiveString( + const bsl::shared_ptr& server, + bsl::string* serverData) +{ + ntsa::Error error = StreamSocketTest::receiveAll(&(*serverData)[0], + serverData->size(), + server->handle()); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); +} - error = server->close(); - NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); - } +void StreamSocketTest::sendBlob( + const bsl::shared_ptr& client, + const bdlbb::Blob* clientData) +{ + ntsa::Error error = + StreamSocketTest::sendAll(*clientData, client->handle()); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); } -NTSCFG_TEST_DRIVER +void StreamSocketTest::receiveBlob( + const bsl::shared_ptr& server, + bdlbb::Blob* serverData) { - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); + ntsa::Error error = + StreamSocketTest::receiveAll(serverData, server->handle()); + NTSCFG_TEST_EQ(error, ntsa::Error::e_OK); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsb +} // close namespace BloombergLP diff --git a/groups/nts/ntscfg/ntscfg_limits.t.cpp b/groups/nts/ntscfg/ntscfg_limits.t.cpp new file mode 100644 index 00000000..0e66b4e5 --- /dev/null +++ b/groups/nts/ntscfg/ntscfg_limits.t.cpp @@ -0,0 +1,41 @@ +// Copyright 2020-2023 Bloomberg Finance L.P. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +BSLS_IDENT_RCSID(ntscfg_limits_t_cpp, "$Id$ $CSID$") + +#include + +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntscfg { + +// Provide tests for 'ntscfg::Limit'. +class LimitTest +{ + public: + // TODO + static void verify(); +}; + +NTSCFG_TEST_FUNCTION(ntscfg::LimitTest::verify) +{ +} + +} // close namespace ntscfg +} // close namespace BloombergLP diff --git a/groups/nts/ntscfg/ntscfg_platform.cpp b/groups/nts/ntscfg/ntscfg_platform.cpp index 9e3b9205..ca844466 100644 --- a/groups/nts/ntscfg/ntscfg_platform.cpp +++ b/groups/nts/ntscfg/ntscfg_platform.cpp @@ -28,9 +28,9 @@ BSLS_IDENT_RCSID(ntscfg_platform_cpp, "$Id$ $CSID$") #if defined(BSLS_PLATFORM_OS_UNIX) #include +#include #include #include -#include #if defined(BSLS_PLATFORM_OS_LINUX) #include @@ -39,9 +39,9 @@ BSLS_IDENT_RCSID(ntscfg_platform_cpp, "$Id$ $CSID$") #endif #if defined(BSLS_PLATFORM_OS_WINDOWS) +#include #include #include -#include #pragma comment(lib, "ws2_32.lib") #endif @@ -165,12 +165,11 @@ int Platform::exit() #endif } - bsl::size_t Platform::numCores() { #if defined(BSLS_PLATFORM_OS_UNIX) - errno = 0; + errno = 0; const int cpuCount = sysconf(_SC_NPROCESSORS_ONLN); if (cpuCount < 0) { return 1; @@ -257,10 +256,7 @@ bsl::string Platform::buildBranch() bsl::string result = NTS_BUILD_BRANCH; if (result.empty()) { bsl::stringstream ss; - ss << NTS_VERSION_MAJOR - << '.' - << NTS_VERSION_MINOR - << '.' + ss << NTS_VERSION_MAJOR << '.' << NTS_VERSION_MINOR << '.' << NTS_VERSION_PATCH; result = ss.str(); } diff --git a/groups/nts/ntscfg/ntscfg_platform.h b/groups/nts/ntscfg/ntscfg_platform.h index e13fc641..c5c10a12 100644 --- a/groups/nts/ntscfg/ntscfg_platform.h +++ b/groups/nts/ntscfg/ntscfg_platform.h @@ -23,20 +23,20 @@ BSLS_IDENT("$Id: $") #include #include #include -#include #include #include -#include #include +#include #include +#include #include #include -#include #include +#include #include #include -#include #include +#include #include #include #include @@ -183,7 +183,7 @@ namespace ntscfg { /// Return a movable reference to 'object.member'. /// /// @ingroup module_ntscfg -#define NTSCFG_MOVE_FROM(object, member) \ +#define NTSCFG_MOVE_FROM(object, member) \ NTSCFG_MOVE(NTSCFG_MOVE_ACCESS(object).member) #if defined(BDE_BUILD_TARGET_OPT) @@ -210,9 +210,7 @@ namespace ntscfg { /// /// @ingroup module_ntscfg #define NTSCFG_DECLARE_NESTED_BITWISE_MOVABLE_TRAITS(TYPE) \ - BSLALG_DECLARE_NESTED_TRAITS( \ - TYPE, \ - bslalg::TypeTraitBitwiseMoveable) + BSLALG_DECLARE_NESTED_TRAITS(TYPE, bslalg::TypeTraitBitwiseMoveable) /// Declare the specified 'TYPE' uses an allocator to supply memory. /// @@ -227,9 +225,9 @@ namespace ntscfg { /// this type. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_TRAIT_BITWISE_INITIALIZABLE(Type) \ - BSLMF_NESTED_TRAIT_DECLARATION( \ - Type, bsl::is_trivially_default_constructible) +#define NTSCFG_TYPE_TRAIT_BITWISE_INITIALIZABLE(Type) \ + BSLMF_NESTED_TRAIT_DECLARATION(Type, \ + bsl::is_trivially_default_constructible) /// Declare a type trait for the specified 'type' to indicate its /// copy-constructor and copy-assignment operator is equivalent to copying each @@ -240,7 +238,7 @@ namespace ntscfg { /// object of this type has a trivial destructor. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_TRAIT_BITWISE_COPYABLE(Type) \ +#define NTSCFG_TYPE_TRAIT_BITWISE_COPYABLE(Type) \ BSLMF_NESTED_TRAIT_DECLARATION(Type, bslmf::IsBitwiseCopyable) /// Declare a type trait for the specified 'type' to indicate its @@ -251,7 +249,7 @@ namespace ntscfg { /// type. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_TRAIT_BITWISE_MOVABLE(Type) \ +#define NTSCFG_TYPE_TRAIT_BITWISE_MOVABLE(Type) \ BSLMF_NESTED_TRAIT_DECLARATION(Type, bslmf::IsBitwiseMoveable) /// Declare a type trait for the specified 'type' to indicate its @@ -263,7 +261,7 @@ namespace ntscfg { /// has no padding bytes between data members. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_TRAIT_BITWISE_COMPARABLE(Type) \ +#define NTSCFG_TYPE_TRAIT_BITWISE_COMPARABLE(Type) \ BSLMF_NESTED_TRAIT_DECLARATION(Type, bslmf::IsBitwiseEqualityComparable) /// Declare a type trait for the specified 'type' to indicate it accepts an @@ -273,43 +271,43 @@ namespace ntscfg { /// objects of this type. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_TRAIT_ALLOCATOR_AWARE(Type) \ +#define NTSCFG_TYPE_TRAIT_ALLOCATOR_AWARE(Type) \ BSLALG_DECLARE_NESTED_TRAITS(Type, bslalg::TypeTraitUsesBslmaAllocator) /// Return true if the specified 'type' is bitwise-initializable, otherwise /// return false. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_CHECK_BITWISE_INITIALIZABLE(Type) \ +#define NTSCFG_TYPE_CHECK_BITWISE_INITIALIZABLE(Type) \ bsl::is_trivially_default_constructible::value /// Return true if the specified 'type' is bitwise-movable, otherwise return /// false. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_CHECK_BITWISE_MOVABLE(Type) \ - ((bslmf::IsBitwiseMoveable::value) && \ +#define NTSCFG_TYPE_CHECK_BITWISE_MOVABLE(Type) \ + ((bslmf::IsBitwiseMoveable::value) && \ (bsl::is_nothrow_move_constructible::value)) /// Return true if the specified 'type' is bitwise-copyable, otherwise return /// false. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_CHECK_BITWISE_COPYABLE(Type) \ +#define NTSCFG_TYPE_CHECK_BITWISE_COPYABLE(Type) \ bslmf::IsBitwiseCopyable::value /// Return true if the specified 'type' is bitwise-comparable, otherwise return /// false. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_CHECK_BITWISE_COMPARABLE(Type) \ +#define NTSCFG_TYPE_CHECK_BITWISE_COMPARABLE(Type) \ bslmf::IsBitwiseEqualityComparable::value /// Return true if the specified 'type' accepts an allocator argument to its /// constructors, otherwise return false. /// /// @ingroup module_ntscfg -#define NTSCFG_TYPE_CHECK_ALLOCATOR_AWARE(Type) \ +#define NTSCFG_TYPE_CHECK_ALLOCATOR_AWARE(Type) \ bslalg::HasTrait::VALUE /// @internal @brief @@ -414,7 +412,7 @@ struct Platform { /// error otherwise. static int exit(); - /// Return the number of CPU cores on the current machine. + /// Return the number of CPU cores on the current machine. static bsl::size_t numCores(); /// Return true if the version of the operating system running the current diff --git a/groups/nts/ntscfg/ntscfg_platform.t.cpp b/groups/nts/ntscfg/ntscfg_platform.t.cpp index 50de59f0..240fd7bc 100644 --- a/groups/nts/ntscfg/ntscfg_platform.t.cpp +++ b/groups/nts/ntscfg/ntscfg_platform.t.cpp @@ -13,28 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntscfg_limits_t_cpp, "$Id$ $CSID$") + #include -#include +using namespace BloombergLP; + +namespace BloombergLP { +namespace ntscfg { -int testCase1() +// Provide tests for 'ntscfg::Platform'. +class PlatformTest { - return 0; -} + public: + // TODO + static void verify(); +}; -int main(int argc, char** argv) +NTSCFG_TEST_FUNCTION(ntscfg::PlatformTest::verify) { - int testCase = 0; - if (argc > 1) { - testCase = bsl::atoi(argv[1]); - } - - if (testCase == 0 || testCase == 1) { - return testCase1(); - } - else { - return -1; - } - - return 0; } + +} // close namespace ntscfg +} // close namespace BloombergLP diff --git a/groups/nts/ntscfg/ntscfg_test.cpp b/groups/nts/ntscfg/ntscfg_test.cpp index 176691ce..0de7363e 100644 --- a/groups/nts/ntscfg/ntscfg_test.cpp +++ b/groups/nts/ntscfg/ntscfg_test.cpp @@ -1,80 +1,2 @@ -// Copyright 2020-2023 Bloomberg Finance L.P. -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include - #include BSLS_IDENT_RCSID(ntscfg_test_cpp, "$Id$ $CSID$") - -namespace BloombergLP { -namespace ntscfg { - -#if NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR - -TestAllocator::TestAllocator() -: d_base(64) -{ -} - -TestAllocator::~TestAllocator() -{ -} - -void* TestAllocator::allocate(size_type size) -{ - return d_base.allocate(size); -} - -void TestAllocator::deallocate(void* address) -{ - d_base.deallocate(address); -} - -bsl::int64_t TestAllocator::numBlocksInUse() const -{ - // Intentionally report 0 blocks in use and assert in the destructor. - return 0; -} - -#else - -TestAllocator::TestAllocator() -: d_base() -{ -} - -TestAllocator::~TestAllocator() -{ -} - -void* TestAllocator::allocate(size_type size) -{ - return d_base.allocate(size); -} - -void TestAllocator::deallocate(void* address) -{ - d_base.deallocate(address); -} - -bsl::int64_t TestAllocator::numBlocksInUse() const -{ - return d_base.numBlocksInUse(); -} - -#endif - -} // close package namespace -} // close enterprise namespace diff --git a/groups/nts/ntscfg/ntscfg_test.h b/groups/nts/ntscfg/ntscfg_test.h index b1703bdc..7cd6c62b 100644 --- a/groups/nts/ntscfg/ntscfg_test.h +++ b/groups/nts/ntscfg/ntscfg_test.h @@ -1,27 +1,27 @@ -// Copyright 2020-2023 Bloomberg Finance L.P. -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - #ifndef INCLUDED_NTSCFG_TEST #define INCLUDED_NTSCFG_TEST #include BSLS_IDENT("$Id: $") -#include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -29,25 +29,49 @@ BSLS_IDENT("$Id: $") #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include +#include #include #include #include +#include #include +#include +#include #include #include #include +#include #include -#include -#include #include +#include +#include +#include #include +#include #include #include #include +#include +#include #include #include +#include +#include +#include +#include + +#ifndef NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR +#define NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR 1 +#endif #if NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR #include @@ -60,26 +84,26 @@ namespace ntscfg { /// Describe a test case context. /// /// @ingroup module_ntscfg -class TestCaseContext +class TestCaseContext { int d_number; bsl::string d_name; bsl::function d_function; -private: + private: TestCaseContext(const TestCaseContext&) BSLS_KEYWORD_DELETED; TestCaseContext& operator=(const TestCaseContext&) BSLS_KEYWORD_DELETED; -public: + public: /// Create a new test case context. Optionally specify a 'basicAllocator' - /// used to supply memory. If 'basicAllocator' is 0, the currently + /// used to supply memory. If 'basicAllocator' is 0, the currently /// installed global allocator is used. explicit TestCaseContext(bslma::Allocator* basicAllocator = 0); /// Create a new test case context. Optionally specify a 'basicAllocator' - /// used to supply memory. If 'basicAllocator' is 0, the currently + /// used to supply memory. If 'basicAllocator' is 0, the currently /// installed global allocator is used. - TestCaseContext(const TestCaseContext& original, + TestCaseContext(const TestCaseContext& original, bslma::Allocator* basicAllocator = 0); /// Destroy this object. @@ -108,76 +132,67 @@ class TestCaseContext /// This type accepts an allocator argument to its constructors and may /// dynamically allocate memory during its operation. - NTSCFG_TYPE_TRAIT_ALLOCATOR_AWARE(TestCaseContext); + BSLALG_DECLARE_NESTED_TRAITS(TestCaseContext, + bslalg::TypeTraitUsesBslmaAllocator); }; -NTSCFG_INLINE -TestCaseContext::TestCaseContext(bslma::Allocator* basicAllocator) +inline TestCaseContext::TestCaseContext(bslma::Allocator* basicAllocator) : d_number(0) , d_name(basicAllocator ? basicAllocator : bslma::Default::globalAllocator()) -, d_function(bsl::allocator_arg, - basicAllocator ? basicAllocator : - bslma::Default::globalAllocator()) +, d_function( + bsl::allocator_arg, + basicAllocator ? basicAllocator : bslma::Default::globalAllocator()) { } -NTSCFG_INLINE -TestCaseContext::TestCaseContext(const TestCaseContext& original, - bslma::Allocator* basicAllocator) +inline TestCaseContext::TestCaseContext(const TestCaseContext& original, + bslma::Allocator* basicAllocator) : d_number(original.d_number) -, d_name(original.d_name, +, d_name(original.d_name, basicAllocator ? basicAllocator : bslma::Default::globalAllocator()) -, d_function(bsl::allocator_arg, - basicAllocator ? basicAllocator : - bslma::Default::globalAllocator(), - original.d_function) +, d_function( + bsl::allocator_arg, + basicAllocator ? basicAllocator : bslma::Default::globalAllocator(), + original.d_function) { } -NTSCFG_INLINE -TestCaseContext::~TestCaseContext() +inline TestCaseContext::~TestCaseContext() { } -NTSCFG_INLINE -void TestCaseContext::setNumber(int value) +inline void TestCaseContext::setNumber(int value) { d_number = value; } -NTSCFG_INLINE -void TestCaseContext::setName(const bsl::string& value) +inline void TestCaseContext::setName(const bsl::string& value) { d_name = value; } -NTSCFG_INLINE -void TestCaseContext::setFunction(const bsl::function& value) +inline void TestCaseContext::setFunction(const bsl::function& value) { d_function = value; } -NTSCFG_INLINE -void TestCaseContext::execute() +inline void TestCaseContext::execute() { BSLS_LOG_INFO("Testing: %s", d_name.c_str()); d_function(); } -NTSCFG_INLINE -int TestCaseContext::number() const +inline int TestCaseContext::number() const { return d_number; } -NTSCFG_INLINE -const bsl::string& TestCaseContext::name() const +inline const bsl::string& TestCaseContext::name() const { return d_name; } -NTSCFG_INLINE -bool TestCaseContext::isDefined() const +inline bool TestCaseContext::isDefined() const { if (d_function) { return true; @@ -187,106 +202,6 @@ bool TestCaseContext::isDefined() const } } -/// @internal @brief -/// The test case number. -/// -/// @ingroup module_ntscfg -extern int testCase; - -/// @internal @brief -/// The test verbosity level. -/// -/// @ingroup module_ntscfg -extern int testVerbosity; - -/// @internal @brief -/// The number of arguments specified when the test driver was executed. -/// -/// @ingroup module_ntscfg -extern int testArgc; - -/// @internal @brief -/// The argument vector specified when the test driver was executed. -/// -/// @ingroup module_ntscfg -extern char** testArgv; - -/// @internal @brief -/// The test allocator. -/// -/// @ingroup module_ntscfg -extern bslma::Allocator* testAllocator; - -/// @internal @brief -/// Defines a type alias for a function invoked to initialize any global state -/// used by the test driver. -/// -/// @ingroup module_ntscfg -typedef void (*TestInitCallback)(); - -/// @internal @brief -/// Defines a type alias for a function invoked to clean up any global state -/// used by the test driver. -/// -/// @ingroup module_ntscfg -typedef void (*TestExitCallback)(); - -/// @internal @brief -/// Defines a type alias for a function invoked to execute a test case. -/// -/// @ingroup module_ntscfg -typedef bsl::function TestCaseFunction; - -/// @internal @brief -/// Defines a type alias for a map of test case numbers to the associated -/// function to invoke to execute that test case. -/// -/// @ingroup module_ntscfg -typedef bsl::map TestCaseContextMap; - -/// @internal @brief -/// Defines a type alias for a map of test case numbers to the associated -/// function to invoke to execute that test case. -/// -/// @ingroup module_ntscfg -typedef bsl::vector TestCaseContextVector; - -/// The function invoked to initialize any global state used by the test -/// driver. -/// -/// @ingroup module_ntscfg -extern TestInitCallback testInit; - -/// The function invoked to clean up any global state used by the test driver. -/// -/// @ingroup module_ntscfg -extern TestExitCallback testExit; - -/// @internal @brief -/// Provide a guard to automatically call any registered initialization or -/// exit functions in the context of a test driver. -/// -/// @ingroup module_ntscfg -struct TestGuard { - /// Construct the guard and automatically call any registered - /// initialization function. - TestGuard() - { - if (testInit) { - testInit(); - } - } - - /// Construct the guard and automatically call any registered exit - /// function. - ~TestGuard() - { - if (testExit) { - testExit(); - } - } -}; - #if NTS_BUILD_WITH_STACK_TRACE_TEST_ALLOCATOR /// @internal @brief @@ -332,6 +247,31 @@ class TestAllocator : public bslma::Allocator bsl::int64_t numBlocksInUse() const; }; +inline TestAllocator::TestAllocator() +: d_base(64) +{ +} + +inline TestAllocator::~TestAllocator() +{ +} + +inline void* TestAllocator::allocate(size_type size) +{ + return d_base.allocate(size); +} + +inline void TestAllocator::deallocate(void* address) +{ + d_base.deallocate(address); +} + +inline bsl::int64_t TestAllocator::numBlocksInUse() const +{ + // Intentionally report 0 blocks in use and assert in the destructor. + return 0; +} + #else /// @internal @brief @@ -382,13 +322,672 @@ class TestAllocator : public bslma::Allocator bsl::int64_t numBlocksInUse() const; }; +inline TestAllocator::TestAllocator() +: d_base() +{ +} + +inline TestAllocator::~TestAllocator() +{ +} + +inline void* TestAllocator::allocate(size_type size) +{ + return d_base.allocate(size); +} + +inline void TestAllocator::deallocate(void* address) +{ + d_base.deallocate(address); +} + +inline bsl::int64_t TestAllocator::numBlocksInUse() const +{ + return d_base.numBlocksInUse(); +} + #endif -} // close package namespace -} // close enterprise namespace +/// @internal @brief +/// Provide a logger for a test driver. +/// +/// @par Thread Safety +/// This class is thread safe. +/// +/// @ingroup module_ntscfg +class TestLog +{ + bslma::Allocator* d_allocator_p; + ball::LoggerManager* d_manager_p; + ball::LoggerManagerConfiguration d_config; + ball::Severity::Level d_severityLevel; + + private: + TestLog(const TestLog&) BSLS_KEYWORD_DELETED; + TestLog& operator=(const TestLog&) BSLS_KEYWORD_DELETED; + + public: + /// Create a new logger with the specified 'verbosity'. Optionally specify + /// a 'basicAllocator' used to supply memory. If 'basicAllocator' is 0, the + /// global allocator is used. + explicit TestLog(int verbosity, bslma::Allocator* basicAllocator = 0); + + /// Destroy this object. + ~TestLog(); + + /// Log the specified 'message' from the specified 'file' at the specified + /// 'line' under the specified 'severity' level. + static void printLogMessage(bsls::LogSeverity::Enum severity, + const char* file, + int line, + const char* message); +}; + +inline TestLog::TestLog(int verbosity, bslma::Allocator* basicAllocator) +: d_allocator_p(basicAllocator ? basicAllocator + : bslma::Default::globalAllocator()) +, d_manager_p(0) +, d_config(d_allocator_p) +, d_severityLevel(ball::Severity::e_OFF) +{ + int rc; + + switch (verbosity) { + case 0: + d_severityLevel = BloombergLP::ball::Severity::e_OFF; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_FATAL); + break; + case 1: + d_severityLevel = BloombergLP::ball::Severity::e_ERROR; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_ERROR); + break; + case 2: + d_severityLevel = BloombergLP::ball::Severity::e_WARN; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_WARN); + break; + case 3: + d_severityLevel = BloombergLP::ball::Severity::e_INFO; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_INFO); + break; + case 4: + d_severityLevel = BloombergLP::ball::Severity::e_DEBUG; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_DEBUG); + break; + default: + d_severityLevel = BloombergLP::ball::Severity::e_TRACE; + bsls::Log::setSeverityThreshold(bsls::LogSeverity::e_TRACE); + break; + } + + rc = d_config.setDefaultThresholdLevelsIfValid(d_severityLevel); + BSLS_ASSERT_OPT(rc == 0); + + d_manager_p = &ball::LoggerManager::initSingleton(d_config, d_allocator_p); + + bsl::shared_ptr observer; + observer.createInplace(d_allocator_p, &bsl::cout, d_allocator_p); + + rc = d_manager_p->registerObserver(observer, "default"); + BSLS_ASSERT_OPT(rc == 0); +} + +inline TestLog::~TestLog() +{ + // Do not explicitly shut down the logger singleton becuase it must + // remain alive during the execution of static destructors. + // + // ball::LoggerManager::shutDownSingleton(); +} + +void TestLog::printLogMessage(bsls::LogSeverity::Enum severity, + const char* file, + int line, + const char* message) +{ + bdlt::Datetime now = bdlt::CurrentTime::utc(); + + char nowBuffer[256]; + now.printToBuffer(nowBuffer, sizeof nowBuffer, 3); + + bsl::uint64_t thread = bslmt::ThreadUtil::selfIdAsUint64(); + + bsl::string threadName; + bslmt::ThreadUtil::getThreadName(&threadName); + + bsl::string fileString = file; + bsl::string::size_type n = fileString.find_last_of("/\\"); + if (n != bsl::string::npos) { + fileString = fileString.substr(n + 1); + } + bsl::stringstream fileStream; + fileStream << fileString; + fileStream << ':' << line; + fileStream.flush(); + + char severityCode; + switch (severity) { + case bsls::LogSeverity::e_FATAL: + severityCode = 'F'; + break; + case bsls::LogSeverity::e_ERROR: + severityCode = 'E'; + break; + case bsls::LogSeverity::e_WARN: + severityCode = 'W'; + break; + case bsls::LogSeverity::e_INFO: + severityCode = 'I'; + break; + case bsls::LogSeverity::e_DEBUG: + severityCode = 'D'; + break; + case bsls::LogSeverity::e_TRACE: + severityCode = 'T'; + break; + default: + severityCode = 'X'; + } + if (threadName.empty()) { + bsl::fprintf(stdout, + "[ %c ][ %s ][ %012llu ][ %40s ]: %s\n", + severityCode, + nowBuffer, + static_cast(thread), + fileStream.str().c_str(), + message); + } + else { + bsl::fprintf(stdout, + "[ %c ][ %s ][ %16s ][ %40s ]: %s\n", + severityCode, + nowBuffer, + threadName.c_str(), + fileStream.str().c_str(), + message); + } + + bsl::fflush(stdout); +} + +/// @internal @brief +/// Provide a suite of utilities for generating test data. +/// +/// @par Thread Safety +/// This class is thread safe. +class TestDataUtil +{ + public: + /// Return the byte at the specified 'position' in the specified + /// 'dataset'. + static char generateByte(bsl::size_t position, bsl::size_t dataset); + + /// Load into the specified 'result' the specified 'size' sequence of + /// bytes from the specified 'dataset' starting at the specified + /// 'offset'. + static void generateData(bsl::string* result, + bsl::size_t size, + bsl::size_t offset = 0, + bsl::size_t dataset = 0); + + /// Load into the specified 'result' the specified 'size' sequence of + /// bytes from the specified 'dataset' starting at the specified + /// 'offset'. + static void generateData(bdlbb::Blob* result, + bsl::size_t size, + bsl::size_t offset = 0, + bsl::size_t dataset = 0); +}; + +inline char TestDataUtil::generateByte(bsl::size_t position, + bsl::size_t dataset) +{ + struct { + const char* source; + bsl::size_t length; + } DATA[] = { + {"abcdefghijklmnopqrstuvwxyz", 26}, + {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", 26} + }; + + enum { NUM_DATA = sizeof(DATA) / sizeof(*DATA) }; + + dataset = dataset % NUM_DATA; + return DATA[dataset].source[position % DATA[dataset].length]; +} + +inline void TestDataUtil::generateData(bsl::string* result, + bsl::size_t size, + bsl::size_t offset, + bsl::size_t dataset) +{ + result->clear(); + result->resize(size); + + for (bsl::size_t i = offset; i < offset + size; ++i) { + (*result)[i] = generateByte(offset + i, dataset); + } +} + +inline void TestDataUtil::generateData(bdlbb::Blob* result, + bsl::size_t size, + bsl::size_t offset, + bsl::size_t dataset) +{ + result->removeAll(); + result->setLength(static_cast(size)); + + bsl::size_t k = 0; + + for (int i = 0; i < result->numDataBuffers(); ++i) { + const bdlbb::BlobBuffer& buffer = result->buffer(i); + + bsl::size_t numBytesToWrite = i == result->numDataBuffers() - 1 + ? result->lastDataBufferLength() + : buffer.size(); + + for (bsl::size_t j = 0; j < numBytesToWrite; ++j) { + buffer.data()[j] = generateByte(offset + k, dataset); + ++k; + } + } +} + +/// @internal @brief +/// Defines a type alias for a function invoked to execute a test case. +/// +/// @ingroup module_ntscfg +typedef bsl::function TestCaseFunction; + +/// @internal @brief +/// Defines a type alias for a map of test case numbers to the associated +/// function to invoke to execute that test case. +/// +/// @ingroup module_ntscfg +typedef bsl::map TestCaseContextMap; + +/// @internal @brief +/// Defines a type alias for a vector of iterators to test case contexts, +/// indexed by test case number. +/// +/// @ingroup module_ntscfg +typedef bsl::vector TestCaseContextVector; + +/// @internal @brief +/// The test case number. +/// +/// @ingroup module_ntscfg +static int testCase = 0; + +/// @internal @brief +/// The test verbosity level. +/// +/// @ingroup module_ntscfg +static int testVerbosity = 0; + +/// @internal @brief +/// The number of arguments specified when the test driver was executed. +/// +/// @ingroup module_ntscfg +static int testArgc = 0; + +/// @internal @brief +/// The argument vector specified when the test driver was executed. +/// +/// @ingroup module_ntscfg +static char** testArgv = 0; + +/// @internal @brief +/// The test allocator. +/// +/// @ingroup module_ntscfg +static bslma::Allocator* testAllocator = + &bslma::NewDeleteAllocator::singleton(); + +/// @internal @brief +/// The map of test case numbers to the associated function to invoke to +/// execute that test case. +/// +/// @ingroup module_ntscfg +static ntscfg::TestCaseContextMap testCaseMap( + &bslma::NewDeleteAllocator::singleton()); + +/// @internal @brief +/// The vector of iterators to test case contexts, indexed by test case number. +/// +/// @ingroup module_ntscfg +static ntscfg::TestCaseContextVector testCaseVector( + &bslma::NewDeleteAllocator::singleton()); + +/// @internal @brief +/// Provide utilities for a test driver. +/// +/// @par Thread Safety +/// This class is thread safe. +/// +/// @ingroup module_ntscfg +class TestUtil +{ + public: + static void registerTestCase(const char* name, + const TestCaseFunction& function); + + static bool parseInt(int* result, const char* text); + + static void list(); + + static void help(); +}; + +void TestUtil::registerTestCase(const char* name, + const TestCaseFunction& function) +{ + const int testCaseNumber = + static_cast(BloombergLP::ntscfg::testCaseVector.size() + 1); + + BloombergLP::ntscfg::TestCaseContext& testCaseContext = + BloombergLP::ntscfg::testCaseMap[testCaseNumber]; + + testCaseContext.setNumber(testCaseNumber); + testCaseContext.setName(name); + testCaseContext.setFunction(function); + + BloombergLP::ntscfg::testCaseVector.push_back( + BloombergLP::ntscfg::testCaseMap.find(testCaseNumber)); +} + +bool TestUtil::parseInt(int* result, const char* text) +{ + char* end = 0; + int temp = static_cast(strtol(text, &end, 10)); + if (end == 0 || *end != 0) { + return false; + } + + *result = static_cast(temp); + return true; +} + +void TestUtil::list() +{ + bsl::size_t maxDigits = 0; + { + bsl::size_t numTests = ntscfg::testCaseVector.size(); + do { + numTests /= 10; + ++maxDigits; + } while (numTests != 0); + } + + for (ntscfg::TestCaseContextMap::const_iterator it = + ntscfg::testCaseMap.begin(); + it != ntscfg::testCaseMap.end(); + ++it) + { + const ntscfg::TestCaseContext& testCaseContext = it->second; + + bsl::cout << bsl::setw(maxDigits); + bsl::cout << bsl::right; + bsl::cout << testCaseContext.number(); + bsl::cout << ") "; + bsl::cout << testCaseContext.name(); + bsl::cout << bsl::endl; + } +} + +void TestUtil::help() +{ + bsl::printf("%s\n", + "usage: .exe " + "[ ] [ ]"); +} + +/// @internal @brief +/// Provide an automatic test function registrar. +/// +/// @par Thread Safety +/// This class is thread safe. +/// +/// @ingroup module_ntscfg +class TestRegistration +{ + public: + /// Create a new automatic test registrar for the test case having the + /// specified 'name' implemented by the specified 'function'. + TestRegistration(const char* name, const TestCaseFunction& function); + + /// Destroy this object. + ~TestRegistration(); + + private: + TestRegistration(const TestRegistration&) BSLS_KEYWORD_DELETED; + TestRegistration& operator=(const TestRegistration&) BSLS_KEYWORD_DELETED; +}; + +TestRegistration::TestRegistration(const char* name, + const TestCaseFunction& function) +{ + BloombergLP::ntscfg::TestUtil::registerTestCase(name, function); +} + +TestRegistration::~TestRegistration() +{ +} + +} // close namespace ntscfg +} // close namespace BloombergLP + +int main(int argc, char** argv) +{ + BloombergLP::ntscfg::Platform::initialize(); + BloombergLP::ntscfg::Platform::ignore(BloombergLP::ntscfg::Signal::e_PIPE); + + BloombergLP::bslmt::ThreadUtil::setThreadName("main"); + + BloombergLP::bsls::Log::setLogMessageHandler( + &BloombergLP::ntscfg::TestLog::printLogMessage); + + BloombergLP::ntscfg::testCase = 0; + BloombergLP::ntscfg::testVerbosity = 0; + BloombergLP::ntscfg::testArgc = argc; + BloombergLP::ntscfg::testArgv = argv; + + try { + BloombergLP::bdlb::NullableValue concern; + + int i = 1; + while (i < argc) { + const char* arg = argv[i]; + + if ((0 == bsl::strcmp(arg, "-?")) || + (0 == bsl::strcmp(arg, "--help"))) + { + BloombergLP::ntscfg::TestUtil::help(); + return 1; + } + + if ((0 == bsl::strcmp(arg, "-l")) || + (0 == bsl::strcmp(arg, "--list"))) + { + BloombergLP::ntscfg::TestUtil::list(); + return 0; + } + + if ((0 == bsl::strcmp(arg, "-v")) || + (0 == bsl::strcmp(arg, "--verbosity"))) + { + ++i; + if (i >= argc) { + BloombergLP::ntscfg::TestUtil::help(); + return 1; + } + + int level; + if (BloombergLP::ntscfg::TestUtil::parseInt(&level, arg)) { + BloombergLP::ntscfg::testVerbosity = level; + } + else { + bsl::cerr << "The log verbosity " << level << " is invalid" + << bsl::endl; + return 1; + } + + ++i; + continue; + } + + if (0 == bsl::strcmp(arg, "--concern")) { + ++i; + if (i >= argc) { + BloombergLP::ntscfg::TestUtil::help(); + return 1; + } + concern.makeValue(bsl::string(arg)); + ++i; + continue; + } + + if (concern.isNull()) { + concern.makeValue(bsl::string(arg)); + } + else { + BloombergLP::ntscfg::testVerbosity++; + } + + ++i; + } + + if (concern.has_value() && concern.value() == "0") { + concern.reset(); + } + + if (concern.has_value()) { + int number = 0; + if (BloombergLP::ntscfg::TestUtil::parseInt( + &number, + concern.value().c_str())) + { + if (BloombergLP::ntscfg::testCaseMap.contains(number)) { + BloombergLP::ntscfg::testCase = number; + } + else { + if (BloombergLP::ntscfg::testVerbosity >= 3) { + bsl::cerr << "The test case number " << number + << " is not found" << bsl::endl; + } + return 1; + } + } + else { + bool found = false; + for (BloombergLP::ntscfg::TestCaseContextMap::const_iterator + it = BloombergLP::ntscfg::testCaseMap.begin(); + it != BloombergLP::ntscfg::testCaseMap.end(); + ++it) + { + const BloombergLP::ntscfg::TestCaseContext& + testCaseContext = it->second; + + if (concern.value() == testCaseContext.name()) { + BloombergLP::ntscfg::testCase = + testCaseContext.number(); + found = true; + break; + } + } + + if (!found) { + if (BloombergLP::ntscfg::testVerbosity >= 3) { + bsl::cerr << "The test case number " << number + << " is not found" << bsl::endl; + } + return -1; + } + } + } + + BloombergLP::ntscfg::TestLog testLog( + BloombergLP::ntscfg::testVerbosity); + + if (BloombergLP::ntscfg::testCase == 0) { + BloombergLP::ntscfg::testCase = 1; + while (true) { + BloombergLP::ntscfg::TestCaseContext& testCaseContext = + BloombergLP::ntscfg::testCaseMap + [BloombergLP::ntscfg::testCase]; + + if (testCaseContext.isDefined()) { + BloombergLP::ntscfg::TestAllocator ta; + BloombergLP::ntscfg::testAllocator = &ta; + testCaseContext.execute(); + if (ta.numBlocksInUse() != 0) { + bsl::cerr << "Leaked " << ta.numBlocksInUse() + << " memory blocks" << bsl::endl; + bsl::abort(); + } + ++BloombergLP::ntscfg::testCase; + } + else { + break; + } + } + } + else { + BloombergLP::ntscfg::TestCaseContext& testCaseContext = + BloombergLP::ntscfg::testCaseMap + [BloombergLP::ntscfg::testCase]; + + if (testCaseContext.isDefined()) { + BloombergLP::ntscfg::TestAllocator ta; + BloombergLP::ntscfg::testAllocator = &ta; + testCaseContext.execute(); + if (ta.numBlocksInUse() != 0) { + bsl::cerr << "Leaked " << ta.numBlocksInUse() + << " memory blocks" << bsl::endl; + bsl::abort(); + } + } + else { + return -1; + } + } + } + catch (const bsl::exception& e) { + bsl::printf("Test %d failed: %s\n", + BloombergLP::ntscfg::testCase, + e.what()); + return 1; + } + catch (...) { + bsl::printf("Test %d failed: %s\n", + BloombergLP::ntscfg::testCase, + "Unknown exception"); + return 1; + } + + return 0; +} + +// Concatenate two compile-type identifier into a single identifier. Note that +// this macro is private to the implementation and should not be used. +#define NTSCFG_TEST_FUNCTION_NAME_JOIN(a, b) a##b + +// The identifier of a lock scope, formed from the specified 'prefix' +// concatenated with the specified 'disambiguator'. Note that this macro is +// private to the implementation and should not be used. +#define NTSCFG_TEST_FUNCTION_NAME(prefix, disambiguator) \ + NTSCFG_TEST_FUNCTION_NAME_JOIN(prefix, disambiguator) + +// Implement the declaration of a test function for the specified +// 'concernStringLiteral'. Note that this macro is private to the +// implementation and should not be used. +#define NTSCFG_TEST_FUNCTION(function) \ + BloombergLP::ntscfg::TestRegistration NTSCFG_TEST_FUNCTION_NAME( \ + test_, \ + __COUNTER__)(#function, &(function)); \ + void function() /// @internal @brief /// Assert the 'expression' is true. @@ -609,528 +1208,6 @@ class TestAllocator : public bslma::Allocator /// @ingroup module_ntscfg #define NTSCFG_TEST_ALLOCATOR BloombergLP::ntscfg::testAllocator -/// @internal @brief -/// Begin a functional test case identified by the specified 'number'. -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_CASE(number) void runTestCase##number() - -/// @internal @brief -/// Define the beginning of a callback function to be run after all the common -/// test mechanisms are initialized but before any of the test cases are run. -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_INIT() \ - void runTestInit(); \ - struct runTestInitBinder { \ - runTestInitBinder() \ - { \ - BloombergLP::ntscfg::testInit = &runTestInit; \ - } \ - } s_runTestInitBinder; \ - void runTestInit() - -/// @internal @brief -/// Define the beginning of a callback function to be run after all the test -/// cases are run but before the the common test mechanisms are destroyed. -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_EXIT() \ - void runTestExit(); \ - struct runTestExitBinder { \ - runTestExitBinder() \ - { \ - BloombergLP::ntscfg::testExit = &runTestExit; \ - } \ - } s_runTestExitBinder; \ - void runTestExit() - -/// @internal @brief -/// Begin the definition of the dispatcher for a component test driver. -/// -/// @par Usage Example: The skeleton of a test driver -/// This example shows the basic skeleton of a test driver. -/// -/// #include -/// -/// NTSCFG_TEST_CASE(1) -/// { -/// NTSCFG_TEST_TRUE(true); -/// NTSCFG_TEST_FALSE(false); -/// } -/// -/// NTSCFG_TEST_CASE(2) -/// { -/// NTSCFG_TEST_EQ(1, 1); -/// NTSCFG_TEST_NE(1, 2); -/// } -/// -/// NTSCFG_TEST_DRIVER -/// { -/// NTSCFG_TEST_REGISTER(1); -/// NTSCFG_TEST_REGISTER(2); -/// } -/// NTSCFG_TEST_DRIVER_END; -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_DRIVER \ - namespace BloombergLP { \ - namespace ntscfg { \ - \ - int testCase; \ - int testVerbosity; \ - int testArgc; \ - char** testArgv; \ - TestInitCallback testInit; \ - TestExitCallback testExit; \ - \ - void printLogMessage(bsls::LogSeverity::Enum severity, \ - const char* file, \ - int line, \ - const char* message) \ - { \ - bdlt::Datetime now = bdlt::CurrentTime::utc(); \ - \ - char nowBuffer[256]; \ - now.printToBuffer(nowBuffer, sizeof nowBuffer, 3); \ - \ - bsl::uint64_t thread = bslmt::ThreadUtil::selfIdAsUint64(); \ - \ - bsl::string threadName; \ - bslmt::ThreadUtil::getThreadName(&threadName); \ - \ - bsl::string fileString = file; \ - \ - bsl::string::size_type n = fileString.find_last_of("/\\"); \ - if (n != bsl::string::npos) { \ - fileString = fileString.substr(n + 1); \ - } \ - \ - bsl::stringstream fileStream; \ - fileStream << fileString; \ - fileStream << ':' << line; \ - fileStream.flush(); \ - \ - char severityCode; \ - switch (severity) { \ - case bsls::LogSeverity::e_FATAL: \ - severityCode = 'F'; \ - break; \ - case bsls::LogSeverity::e_ERROR: \ - severityCode = 'E'; \ - break; \ - case bsls::LogSeverity::e_WARN: \ - severityCode = 'W'; \ - break; \ - case bsls::LogSeverity::e_INFO: \ - severityCode = 'I'; \ - break; \ - case bsls::LogSeverity::e_DEBUG: \ - severityCode = 'D'; \ - break; \ - case bsls::LogSeverity::e_TRACE: \ - severityCode = 'T'; \ - break; \ - default: \ - severityCode = 'X'; \ - } \ - \ - if (threadName.empty()) { \ - bsl::fprintf(stdout, \ - "[ %c ][ %s ][ %012llu ][ %40s ]: %s\n", \ - severityCode, \ - nowBuffer, \ - static_cast(thread), \ - fileStream.str().c_str(), \ - message); \ - } \ - else { \ - bsl::fprintf(stdout, \ - "[ %c ][ %s ][ %16s ][ %40s ]: %s\n", \ - severityCode, \ - nowBuffer, \ - threadName.c_str(), \ - fileStream.str().c_str(), \ - message); \ - } \ - \ - bsl::fflush(stdout); \ - } \ - } \ - } \ - \ - int runTest(int testCase, int); \ - int main(int argc, char** argv); \ - \ - int runTest(int testCase, int verbosity) \ - { \ - (void)verbosity; \ - switch (testCase) - -/// @internal @brief -/// End the definition of the dispatcher for a component test driver. -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_DRIVER_END \ - return -1; \ - } \ - \ - int main(int argc, char** argv) \ - { \ - BloombergLP::ntscfg::Platform::initialize(); \ - BloombergLP::ntscfg::Platform::ignore( \ - BloombergLP::ntscfg::Signal::e_PIPE); \ - \ - BloombergLP::bslmt::ThreadUtil::setThreadName("main"); \ - \ - BloombergLP::bsls::Log::setLogMessageHandler( \ - &BloombergLP::ntscfg::printLogMessage); \ - \ - BloombergLP::ntscfg::testCase = 0; \ - BloombergLP::ntscfg::testVerbosity = 0; \ - BloombergLP::ntscfg::testArgc = argc; \ - BloombergLP::ntscfg::testArgv = argv; \ - \ - try { \ - if (argc > 6) { \ - bsl::printf("%s\n", \ - "usage: .exe " \ - "[ ] [ ]"); \ - return 1; \ - } \ - \ - if (argc >= 2) { \ - BloombergLP::ntscfg::testCase = bsl::atoi(argv[1]); \ - } \ - \ - if (argc == 2) { \ - BloombergLP::ntscfg::testVerbosity = 0; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_FATAL); \ - } \ - \ - if (argc >= 3) { \ - BloombergLP::ntscfg::testVerbosity = 2; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_WARN); \ - } \ - \ - if (argc >= 4) { \ - BloombergLP::ntscfg::testVerbosity = 3; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_INFO); \ - } \ - \ - if (argc >= 5) { \ - BloombergLP::ntscfg::testVerbosity = 4; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_DEBUG); \ - } \ - \ - if (argc == 6) { \ - BloombergLP::ntscfg::testVerbosity = 5; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_TRACE); \ - } \ - \ - BloombergLP::ntscfg::TestGuard testGuard; \ - \ - if (BloombergLP::ntscfg::testCase == 0) { \ - BloombergLP::ntscfg::testCase = 1; \ - while (0 == runTest(BloombergLP::ntscfg::testCase, \ - BloombergLP::ntscfg::testVerbosity)) \ - { \ - ++BloombergLP::ntscfg::testCase; \ - } \ - } \ - else { \ - if (0 != runTest(BloombergLP::ntscfg::testCase, \ - BloombergLP::ntscfg::testVerbosity)) \ - { \ - return -1; \ - } \ - } \ - } \ - catch (const bsl::exception& e) { \ - bsl::printf("Test %d failed: %s\n", \ - BloombergLP::ntscfg::testCase, \ - e.what()); \ - return 1; \ - } \ - catch (...) { \ - bsl::printf("Test %d failed: %s\n", \ - BloombergLP::ntscfg::testCase, \ - "Unknown exception"); \ - return 1; \ - } \ - \ - return 0; \ - } - -/// @internal @brief -/// Register a functional test case inside a dispatcher for a component test -/// driver. -/// -/// @ingroup module_ntscfg -#define NTSCFG_TEST_REGISTER(number) \ - case number: \ - bsl::printf("Running test case %d\n", number); \ - runTestCase##number(); \ - return 0; - -#endif - - - - - - - - - - - - - - - -/// Begin the definition of the dispatcher for a component test driver. -#define NTSCFG_TEST_SUITE \ - namespace BloombergLP { \ - namespace ntscfg { \ - \ - int testCase; \ - int testVerbosity; \ - int testArgc; \ - char** testArgv; \ - bslma::Allocator* testAllocator; \ - TestInitCallback testInit; \ - TestExitCallback testExit; \ - \ - void printLogMessage(bsls::LogSeverity::Enum severity, \ - const char* file, \ - int line, \ - const char* message) \ - { \ - bdlt::Datetime now = bdlt::CurrentTime::utc(); \ - \ - char nowBuffer[256]; \ - now.printToBuffer(nowBuffer, sizeof nowBuffer, 3); \ - \ - bsl::uint64_t thread = bslmt::ThreadUtil::selfIdAsUint64(); \ - \ - bsl::string threadName; \ - bslmt::ThreadUtil::getThreadName(&threadName); \ - \ - bsl::string fileString = file; \ - \ - bsl::string::size_type n = fileString.find_last_of("/\\"); \ - if (n != bsl::string::npos) { \ - fileString = fileString.substr(n + 1); \ - } \ - \ - bsl::stringstream fileStream; \ - fileStream << fileString; \ - fileStream << ':' << line; \ - fileStream.flush(); \ - \ - char severityCode; \ - switch (severity) { \ - case bsls::LogSeverity::e_FATAL: \ - severityCode = 'F'; \ - break; \ - case bsls::LogSeverity::e_ERROR: \ - severityCode = 'E'; \ - break; \ - case bsls::LogSeverity::e_WARN: \ - severityCode = 'W'; \ - break; \ - case bsls::LogSeverity::e_INFO: \ - severityCode = 'I'; \ - break; \ - case bsls::LogSeverity::e_DEBUG: \ - severityCode = 'D'; \ - break; \ - case bsls::LogSeverity::e_TRACE: \ - severityCode = 'T'; \ - break; \ - default: \ - severityCode = 'X'; \ - } \ - \ - if (threadName.empty()) { \ - bsl::fprintf(stdout, \ - "[ %c ][ %s ][ %012llu ][ %40s ]: %s\n", \ - severityCode, \ - nowBuffer, \ - static_cast(thread), \ - fileStream.str().c_str(), \ - message); \ - } \ - else { \ - bsl::fprintf(stdout, \ - "[ %c ][ %s ][ %16s ][ %40s ]: %s\n", \ - severityCode, \ - nowBuffer, \ - threadName.c_str(), \ - fileStream.str().c_str(), \ - message); \ - } \ - \ - bsl::fflush(stdout); \ - } \ - } \ - } \ - \ - int main(int argc, char** argv) \ - { \ - BloombergLP::ntscfg::Platform::initialize(); \ - BloombergLP::ntscfg::Platform::ignore( \ - BloombergLP::ntscfg::Signal::e_PIPE); \ - \ - BloombergLP::bslmt::ThreadUtil::setThreadName("main"); \ - \ - BloombergLP::bsls::Log::setLogMessageHandler( \ - &BloombergLP::ntscfg::printLogMessage); \ - \ - BloombergLP::ntscfg::testCase = 0; \ - BloombergLP::ntscfg::testVerbosity = 0; \ - BloombergLP::ntscfg::testArgc = argc; \ - BloombergLP::ntscfg::testArgv = argv; \ - BloombergLP::ntscfg::testAllocator = 0; \ - \ - try { \ - if (argc > 6) { \ - bsl::printf("%s\n", \ - "usage: .exe " \ - "[ ] [ ]"); \ - return 1; \ - } \ - \ - if (argc >= 2) { \ - BloombergLP::ntscfg::testCase = bsl::atoi(argv[1]); \ - } \ - \ - if (argc == 2) { \ - BloombergLP::ntscfg::testVerbosity = 0; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_FATAL); \ - } \ - \ - if (argc >= 3) { \ - BloombergLP::ntscfg::testVerbosity = 2; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_WARN); \ - } \ - \ - if (argc >= 4) { \ - BloombergLP::ntscfg::testVerbosity = 3; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_INFO); \ - } \ - \ - if (argc >= 5) { \ - BloombergLP::ntscfg::testVerbosity = 4; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_DEBUG); \ - } \ - \ - if (argc == 6) { \ - BloombergLP::ntscfg::testVerbosity = 5; \ - BloombergLP::bsls::Log::setSeverityThreshold( \ - BloombergLP::bsls::LogSeverity::e_TRACE); \ - } \ - \ - BloombergLP::ntscfg::TestGuard testGuard; \ - \ - BloombergLP::ntscfg::TestCaseContextMap testCaseMap; \ - BloombergLP::ntscfg::TestCaseContextVector testCaseVector; \ - -/// Register a functional test case inside a dispatcher for a component test -/// driver. -#define NTSCFG_TEST_FUNCTION_INDEX(number, function) \ - testCaseMap[number] = function - -/// Register a functional test case inside a dispatcher for a component test -/// driver. -#define NTSCFG_TEST_FUNCTION(function) \ - { \ - const int testCaseNumber = \ - static_cast(testCaseVector.size() + 1); \ - \ - ntscfg::TestCaseContext& testCaseContext = \ - testCaseMap[testCaseNumber]; \ - \ - testCaseContext.setNumber(testCaseNumber); \ - testCaseContext.setName(#function); \ - testCaseContext.setFunction(function); \ - \ - testCaseVector.push_back(testCaseMap.find(testCaseNumber)); \ - } - -/// End the definition of the dispatcher for a component test driver. -#define NTSCFG_TEST_SUITE_END \ - if (BloombergLP::ntscfg::testCase == 0) { \ - BloombergLP::ntscfg::testCase = 1; \ - while (true) { \ - BloombergLP::ntscfg::TestCaseContext& testCaseContext = \ - testCaseMap[BloombergLP::ntscfg::testCase]; \ - \ - if (testCaseContext.isDefined()) { \ - BloombergLP::ntscfg::TestAllocator ta; \ - BloombergLP::ntscfg::testAllocator = &ta; \ - testCaseContext.execute(); \ - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); \ - ++BloombergLP::ntscfg::testCase; \ - } \ - else { \ - break; \ - } \ - } \ - } \ - else { \ - BloombergLP::ntscfg::TestCaseContext& testCaseContext = \ - testCaseMap[BloombergLP::ntscfg::testCase]; \ - \ - if (testCaseContext.isDefined()) { \ - BloombergLP::ntscfg::TestAllocator ta; \ - BloombergLP::ntscfg::testAllocator = &ta; \ - testCaseContext.execute(); \ - NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); \ - } \ - else { \ - return -1; \ - } \ - } \ - } \ - catch (const bsl::exception& e) { \ - bsl::printf("Test %d failed: %s\n", \ - BloombergLP::ntscfg::testCase, \ - e.what()); \ - return 1; \ - } \ - catch (...) { \ - bsl::printf("Test %d failed: %s\n", \ - BloombergLP::ntscfg::testCase, \ - "Unknown exception"); \ - return 1; \ - } \ - \ - BloombergLP::ntscfg::Platform::exit(); \ - \ - return 0; \ - } - - - - - - - - - - - /// @internal @brief /// Log at the fatal severity level. /// @@ -1254,3 +1331,5 @@ class TestAllocator : public bslma::Allocator #else #error Not implemented #endif + +#endif diff --git a/groups/nts/ntscfg/ntscfg_test.t.cpp b/groups/nts/ntscfg/ntscfg_test.t.cpp index e72a6829..3847864f 100644 --- a/groups/nts/ntscfg/ntscfg_test.t.cpp +++ b/groups/nts/ntscfg/ntscfg_test.t.cpp @@ -1,77 +1,4 @@ -// Copyright 2020-2023 Bloomberg Finance L.P. -// SPDX-License-Identifier: Apache-2.0 -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - #include -#include - -using namespace BloombergLP; - -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- - -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- - -NTSCFG_TEST_INIT() -{ - BSLS_LOG_DEBUG("%s", "Test init"); -} - -NTSCFG_TEST_CASE(1) -{ - ntscfg::TestAllocator ta; - { - BSLS_LOG_DEBUG("%s", "Test case 1"); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(2) -{ - ntscfg::TestAllocator ta; - { - BSLS_LOG_DEBUG("%s", "Test case 2"); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(3) -{ - ntscfg::TestAllocator ta; - { - BSLS_LOG_DEBUG("%s", "Test case 3"); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_EXIT() -{ - BSLS_LOG_DEBUG("%s", "Test exit"); -} -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; +#include +BSLS_IDENT_RCSID(ntscfg_test_t_cpp, "$Id$ $CSID$") diff --git a/groups/nts/ntsd/ntsd_datautil.t.cpp b/groups/nts/ntsd/ntsd_datautil.t.cpp index 10c7e0e1..6ac5a2bc 100644 --- a/groups/nts/ntsd/ntsd_datautil.t.cpp +++ b/groups/nts/ntsd/ntsd_datautil.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsd_datautil_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsd { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsd::DataUtil'. +class DataUtilTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsd::DataUtilTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsd +} // close namespace BloombergLP diff --git a/groups/nts/ntsd/ntsd_message.t.cpp b/groups/nts/ntsd/ntsd_message.t.cpp index 372f77fd..a4a219b5 100644 --- a/groups/nts/ntsd/ntsd_message.t.cpp +++ b/groups/nts/ntsd/ntsd_message.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsd_message_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsd { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsd::Message'. +class MessageTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsd::MessageTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsd +} // close namespace BloombergLP diff --git a/groups/nts/ntsd/ntsd_messageheader.t.cpp b/groups/nts/ntsd/ntsd_messageheader.t.cpp index dff7763c..33c17924 100644 --- a/groups/nts/ntsd/ntsd_messageheader.t.cpp +++ b/groups/nts/ntsd/ntsd_messageheader.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsd_messageheader_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsd { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsd::MessageHeader'. +class MessageHeaderTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsd::MessageHeaderTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsd +} // close namespace BloombergLP diff --git a/groups/nts/ntsd/ntsd_messageparser.t.cpp b/groups/nts/ntsd/ntsd_messageparser.t.cpp index 093b53ce..b42a8ec6 100644 --- a/groups/nts/ntsd/ntsd_messageparser.t.cpp +++ b/groups/nts/ntsd/ntsd_messageparser.t.cpp @@ -13,45 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - -#include -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsd_messageparser_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsd { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsd::MessageParser'. +class MessageParserTest { - // Concern: - // Plan: + public: + // TODO + static void verify(); +}; - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsd::MessageParserTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsd +} // close namespace BloombergLP diff --git a/groups/nts/ntsd/ntsd_messagetype.t.cpp b/groups/nts/ntsd/ntsd_messagetype.t.cpp index ff82e058..8ca43140 100644 --- a/groups/nts/ntsd/ntsd_messagetype.t.cpp +++ b/groups/nts/ntsd/ntsd_messagetype.t.cpp @@ -13,42 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsd_messagetype_t_cpp, "$Id$ $CSID$") -using namespace BloombergLP; +#include -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +using namespace BloombergLP; -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsd { -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntsd::MessageType'. +class MessageTypeTest { - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsd::MessageTypeTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsd +} // close namespace BloombergLP diff --git a/groups/nts/ntsf/ntsf_system.cpp b/groups/nts/ntsf/ntsf_system.cpp index c7b0ace5..624a72b3 100644 --- a/groups/nts/ntsf/ntsf_system.cpp +++ b/groups/nts/ntsf/ntsf_system.cpp @@ -829,24 +829,26 @@ ntsa::Error System::leaveMulticastGroup(ntsa::Handle socket, group); } -ntsa::Error System::joinMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) -{ - return ntsu::SocketOptionUtil::joinMulticastGroupSource( - socket, interface, group, source); -} - -ntsa::Error System::leaveMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) -{ - return ntsu::SocketOptionUtil::leaveMulticastGroupSource( - socket, interface, group, source); +ntsa::Error System::joinMulticastGroupSource(ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) +{ + return ntsu::SocketOptionUtil::joinMulticastGroupSource(socket, + interface, + group, + source); +} + +ntsa::Error System::leaveMulticastGroupSource(ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) +{ + return ntsu::SocketOptionUtil::leaveMulticastGroupSource(socket, + interface, + group, + source); } ntsa::Error System::setBlocking(ntsa::Handle socket, bool blocking) diff --git a/groups/nts/ntsf/ntsf_system.h b/groups/nts/ntsf/ntsf_system.h index ba867fb5..1c08a237 100644 --- a/groups/nts/ntsf/ntsf_system.h +++ b/groups/nts/ntsf/ntsf_system.h @@ -1623,7 +1623,7 @@ struct System { class SystemGuard { private: - SystemGuard(const SystemGuard&) BSLS_KEYWORD_DELETED; + SystemGuard(const SystemGuard&) BSLS_KEYWORD_DELETED; SystemGuard& operator=(const SystemGuard&) BSLS_KEYWORD_DELETED; public: @@ -1653,7 +1653,7 @@ class HandleGuard ntsa::Handle d_handle; private: - HandleGuard(const HandleGuard&) BSLS_KEYWORD_DELETED; + HandleGuard(const HandleGuard&) BSLS_KEYWORD_DELETED; HandleGuard& operator=(const HandleGuard&) BSLS_KEYWORD_DELETED; public: diff --git a/groups/nts/ntsf/ntsf_system.t.cpp b/groups/nts/ntsf/ntsf_system.t.cpp index 5d6d0ab6..3c9a9057 100644 --- a/groups/nts/ntsf/ntsf_system.t.cpp +++ b/groups/nts/ntsf/ntsf_system.t.cpp @@ -13,30 +13,45 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsf_system_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsf { + +// Provide tests for 'ntsf::System'. +class SystemTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase6(); -NTSCFG_TEST_CASE(1) + // TODO + static void verifyCase7(); +}; + +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase1) { // Concern: A TCP/IPv4 socket may bind to the same port number assigned to // another TCP/IPv4 socket as long as the first socket binds to INADDR_ANY @@ -51,164 +66,160 @@ NTSCFG_TEST_CASE(1) // and verifies the assumption that the binding only succeeds on certain // operating systems but fails on others. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - const bool k_REUSE_ADDRESS = true; + const bool k_REUSE_ADDRESS = true; - // Create an "outer" TCP/IPv4 listener socket. + // Create an "outer" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketOne = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketOne = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "outer" listener socket to INADDR_ANY:0. + // Bind the "outer" listener socket to INADDR_ANY:0. - error = listenerSocketOne->bind( - ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), - k_REUSE_ADDRESS); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->bind( + ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), + k_REUSE_ADDRESS); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "outer" socket. + // Learn the port assigned to the "outer" socket. - ntsa::Endpoint listenerSocketOneSourceEndpoint; - error = listenerSocketOne->sourceEndpoint( - &listenerSocketOneSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketOneSourceEndpoint; + error = + listenerSocketOne->sourceEndpoint(&listenerSocketOneSourceEndpoint); + NTSCFG_TEST_OK(error); - // Create an "inner" TCP/IPv4 listener socket. + // Create an "inner" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketTwo = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketTwo = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "inner" listener socket to INADDR_ANY and the port of the - // "outer" listener socket. + // Bind the "inner" listener socket to INADDR_ANY and the port of the + // "outer" listener socket. - error = listenerSocketTwo->bind( - ntsa::Endpoint( - ntsa::IpEndpoint(ntsa::Ipv4Address::any(), - listenerSocketOneSourceEndpoint.ip().port())), - k_REUSE_ADDRESS); + error = listenerSocketTwo->bind( + ntsa::Endpoint( + ntsa::IpEndpoint(ntsa::Ipv4Address::any(), + listenerSocketOneSourceEndpoint.ip().port())), + k_REUSE_ADDRESS); - // Assert the binding succeeds on Linux and AIX, and fails on all - // other operating systems. + // Assert the binding succeeds on Linux and AIX, and fails on all + // other operating systems. #if defined(BSLS_PLATFORM_OS_AIX) || defined(BSLS_PLATFORM_OS_LINUX) - NTSCFG_TEST_OK(error); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "inner" socket. + // Learn the port assigned to the "inner" socket. - ntsa::Endpoint listenerSocketTwoSourceEndpoint; - error = listenerSocketTwo->sourceEndpoint( - &listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketTwoSourceEndpoint; + error = + listenerSocketTwo->sourceEndpoint(&listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Assert the endpoints to which the two sockets are bound are the - // same. + // Assert the endpoints to which the two sockets are bound are the + // same. - NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), - listenerSocketTwoSourceEndpoint.ip().port()); + NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), + listenerSocketTwoSourceEndpoint.ip().port()); - // Begin listening on the "inner" listener socket. + // Begin listening on the "inner" listener socket. - error = listenerSocketTwo->listen(1); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->listen(1); + NTSCFG_TEST_OK(error); - // Create a "client" TCP/IPv4 stream socket. + // Create a "client" TCP/IPv4 stream socket. - bsl::shared_ptr clientSocket = - ntsf::System::createStreamSocket(&ta); + bsl::shared_ptr clientSocket = + ntsf::System::createStreamSocket(NTSCFG_TEST_ALLOCATOR); - error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Connect the "client" stream socket to the "inner" listening socket. + // Connect the "client" stream socket to the "inner" listening socket. - error = clientSocket->connect(listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + error = clientSocket->connect(listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Accept a "server" stream socket from the "inner" listening socket. + // Accept a "server" stream socket from the "inner" listening socket. - bsl::shared_ptr serverSocket; - error = listenerSocketTwo->accept(&serverSocket, &ta); - NTSCFG_TEST_OK(error); + bsl::shared_ptr serverSocket; + error = listenerSocketTwo->accept(&serverSocket, NTSCFG_TEST_ALLOCATOR); + NTSCFG_TEST_OK(error); - // Send data from the "client" socket to the "server" socket. + // Send data from the "client" socket to the "server" socket. - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - char sendData[13]; - bsl::memcpy(sendData, "Hello, world!", 13); + char sendData[13]; + bsl::memcpy(sendData, "Hello, world!", 13); - error = clientSocket->send(&sendContext, sendData, 13, sendOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); + error = clientSocket->send(&sendContext, sendData, 13, sendOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); - // Receive data at the "server" socket send by the "client" socket. + // Receive data at the "server" socket send by the "client" socket. - ntsa::ReceiveContext receiveContext; - ntsa::ReceiveOptions receiveOptions; + ntsa::ReceiveContext receiveContext; + ntsa::ReceiveOptions receiveOptions; - char receiveData[13]; + char receiveData[13]; - error = serverSocket->receive(&receiveContext, - receiveData, - sizeof receiveData, - receiveOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); + error = serverSocket->receive(&receiveContext, + receiveData, + sizeof receiveData, + receiveOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); - // Assert the data received by the "server" socket matches the data - // send by the "client" socket. + // Assert the data received by the "server" socket matches the data + // send by the "client" socket. - NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); + NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); - // Close the "client" socket. + // Close the "client" socket. - error = clientSocket->close(); - NTSCFG_TEST_OK(error); + error = clientSocket->close(); + NTSCFG_TEST_OK(error); - // Close the "server" socket. + // Close the "server" socket. - error = serverSocket->close(); - NTSCFG_TEST_OK(error); + error = serverSocket->close(); + NTSCFG_TEST_OK(error); #elif defined(BSLS_PLATFORM_OS_SOLARIS) - // Assert that Solaris refuses to allow two sockets to bind to the - // same port, despite both sockets having SO_REUSEADDR set, unless - // the second sockets binds to an IPv4 address that is different - // than the IPv4 address to which the first socket is bound. Note that - // other operating systems may also exhibit the same behavior, but - // this test case is simply verifying that this combination of - // parameters is not portable. + // Assert that Solaris refuses to allow two sockets to bind to the + // same port, despite both sockets having SO_REUSEADDR set, unless + // the second sockets binds to an IPv4 address that is different + // than the IPv4 address to which the first socket is bound. Note that + // other operating systems may also exhibit the same behavior, but + // this test case is simply verifying that this combination of + // parameters is not portable. - NTSCFG_TEST_ERROR(error, ntsa::Error::e_ADDRESS_IN_USE); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_ADDRESS_IN_USE); #endif - // Close the "inner" listener socket. + // Close the "inner" listener socket. - error = listenerSocketTwo->close(); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->close(); + NTSCFG_TEST_OK(error); - // Close the "outer" listener socket. + // Close the "outer" listener socket. - error = listenerSocketOne->close(); - NTSCFG_TEST_OK(error); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + error = listenerSocketOne->close(); + NTSCFG_TEST_OK(error); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase2) { // Concern: A TCP/IPv4 socket may bind to the same port number assigned to // another TCP/IPv4 socket as long as the first socket binds to INADDR_ANY @@ -222,144 +233,140 @@ NTSCFG_TEST_CASE(2) // This case specifically tests binding the second socket to the loopback // address. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - const bool k_REUSE_ADDRESS = true; + const bool k_REUSE_ADDRESS = true; - // Create an "outer" TCP/IPv4 listener socket. + // Create an "outer" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketOne = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketOne = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "outer" listener socket to INADDRY_ANY:0. + // Bind the "outer" listener socket to INADDRY_ANY:0. - error = listenerSocketOne->bind( - ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), - k_REUSE_ADDRESS); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->bind( + ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), + k_REUSE_ADDRESS); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "outer" socket. + // Learn the port assigned to the "outer" socket. - ntsa::Endpoint listenerSocketOneSourceEndpoint; - error = listenerSocketOne->sourceEndpoint( - &listenerSocketOneSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketOneSourceEndpoint; + error = + listenerSocketOne->sourceEndpoint(&listenerSocketOneSourceEndpoint); + NTSCFG_TEST_OK(error); - // Create an "inner" TCP/IPv4 listener socket. + // Create an "inner" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketTwo = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketTwo = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "inner" listener socket to 127.0.0.1 and the port of the - // "outer" listener socket. + // Bind the "inner" listener socket to 127.0.0.1 and the port of the + // "outer" listener socket. - error = listenerSocketTwo->bind( - ntsa::Endpoint( - ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), - listenerSocketOneSourceEndpoint.ip().port())), - k_REUSE_ADDRESS); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->bind( + ntsa::Endpoint( + ntsa::IpEndpoint(ntsa::Ipv4Address::loopback(), + listenerSocketOneSourceEndpoint.ip().port())), + k_REUSE_ADDRESS); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "inner" socket. + // Learn the port assigned to the "inner" socket. - ntsa::Endpoint listenerSocketTwoSourceEndpoint; - error = listenerSocketTwo->sourceEndpoint( - &listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketTwoSourceEndpoint; + error = + listenerSocketTwo->sourceEndpoint(&listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Assert the endpoints to which the two sockets are bound are the - // same. + // Assert the endpoints to which the two sockets are bound are the + // same. - NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), - listenerSocketTwoSourceEndpoint.ip().port()); + NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), + listenerSocketTwoSourceEndpoint.ip().port()); - // Begin listening on the "inner" listener socket. + // Begin listening on the "inner" listener socket. - error = listenerSocketTwo->listen(1); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->listen(1); + NTSCFG_TEST_OK(error); - // Create a "client" TCP/IPv4 stream socket. + // Create a "client" TCP/IPv4 stream socket. - bsl::shared_ptr clientSocket = - ntsf::System::createStreamSocket(&ta); + bsl::shared_ptr clientSocket = + ntsf::System::createStreamSocket(NTSCFG_TEST_ALLOCATOR); - error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Connect the "client" stream socket to the "inner" listening socket. + // Connect the "client" stream socket to the "inner" listening socket. - error = clientSocket->connect(listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + error = clientSocket->connect(listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Accept a "server" stream socket from the "inner" listening socket. + // Accept a "server" stream socket from the "inner" listening socket. - bsl::shared_ptr serverSocket; - error = listenerSocketTwo->accept(&serverSocket, &ta); - NTSCFG_TEST_OK(error); + bsl::shared_ptr serverSocket; + error = listenerSocketTwo->accept(&serverSocket, NTSCFG_TEST_ALLOCATOR); + NTSCFG_TEST_OK(error); - // Send data from the "client" socket to the "server" socket. + // Send data from the "client" socket to the "server" socket. - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - char sendData[13]; - bsl::memcpy(sendData, "Hello, world!", 13); + char sendData[13]; + bsl::memcpy(sendData, "Hello, world!", 13); - error = clientSocket->send(&sendContext, sendData, 13, sendOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); + error = clientSocket->send(&sendContext, sendData, 13, sendOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); - // Receive data at the "server" socket send by the "client" socket. + // Receive data at the "server" socket send by the "client" socket. - ntsa::ReceiveContext receiveContext; - ntsa::ReceiveOptions receiveOptions; + ntsa::ReceiveContext receiveContext; + ntsa::ReceiveOptions receiveOptions; - char receiveData[13]; + char receiveData[13]; - error = serverSocket->receive(&receiveContext, - receiveData, - sizeof receiveData, - receiveOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); + error = serverSocket->receive(&receiveContext, + receiveData, + sizeof receiveData, + receiveOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); - // Assert the data received by the "server" socket matches the data - // send by the "client" socket. + // Assert the data received by the "server" socket matches the data + // send by the "client" socket. - NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); + NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); - // Close the "client" socket. + // Close the "client" socket. - error = clientSocket->close(); - NTSCFG_TEST_OK(error); + error = clientSocket->close(); + NTSCFG_TEST_OK(error); - // Close the "server" socket. + // Close the "server" socket. - error = serverSocket->close(); - NTSCFG_TEST_OK(error); + error = serverSocket->close(); + NTSCFG_TEST_OK(error); - // Close the "inner" listener socket. + // Close the "inner" listener socket. - error = listenerSocketTwo->close(); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->close(); + NTSCFG_TEST_OK(error); - // Close the "outer" listener socket. + // Close the "outer" listener socket. - error = listenerSocketOne->close(); - NTSCFG_TEST_OK(error); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + error = listenerSocketOne->close(); + NTSCFG_TEST_OK(error); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase3) { // Concern: A TCP/IPv4 socket may bind to the same port number assigned to // another TCP/IPv4 socket as long as the first socket binds to INADDR_ANY @@ -373,350 +380,327 @@ NTSCFG_TEST_CASE(3) // This case specifically tests binding the second socket to the IPv4 // address assigned to a network interface. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - const bool k_REUSE_ADDRESS = true; + const bool k_REUSE_ADDRESS = true; - // Discover the principle network interface assigned an IPv4 address. + // Discover the principle network interface assigned an IPv4 address. - ntsa::Adapter adapter; - bool adapterFound = - ntsf::System::discoverAdapter(&adapter, - ntsa::IpAddressType::e_V4, - false); - NTSCFG_TEST_TRUE(adapterFound); + ntsa::Adapter adapter; + bool adapterFound = + ntsf::System::discoverAdapter(&adapter, + ntsa::IpAddressType::e_V4, + false); + NTSCFG_TEST_TRUE(adapterFound); - NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); + NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - ntsa::Ipv4Address adapterAddress = adapter.ipv4Address().value(); + ntsa::Ipv4Address adapterAddress = adapter.ipv4Address().value(); - // Create an "outer" TCP/IPv4 listener socket. + // Create an "outer" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketOne = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketOne = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "outer" listener socket to the adapter address. + // Bind the "outer" listener socket to the adapter address. - error = listenerSocketOne->bind( - ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), - k_REUSE_ADDRESS); - NTSCFG_TEST_OK(error); + error = listenerSocketOne->bind( + ntsa::Endpoint(ntsa::IpEndpoint(ntsa::Ipv4Address::any(), 0)), + k_REUSE_ADDRESS); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "outer" socket. + // Learn the port assigned to the "outer" socket. - ntsa::Endpoint listenerSocketOneSourceEndpoint; - error = listenerSocketOne->sourceEndpoint( - &listenerSocketOneSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketOneSourceEndpoint; + error = + listenerSocketOne->sourceEndpoint(&listenerSocketOneSourceEndpoint); + NTSCFG_TEST_OK(error); - // Create an "inner" TCP/IPv4 listener socket. + // Create an "inner" TCP/IPv4 listener socket. - bsl::shared_ptr listenerSocketTwo = - ntsf::System::createListenerSocket(&ta); + bsl::shared_ptr listenerSocketTwo = + ntsf::System::createListenerSocket(NTSCFG_TEST_ALLOCATOR); - error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Bind the "inner" listener socket to the adapter address and the port - // of the "outer" listener socket. + // Bind the "inner" listener socket to the adapter address and the port + // of the "outer" listener socket. - error = listenerSocketTwo->bind( - ntsa::Endpoint( - ntsa::IpEndpoint(adapterAddress, - listenerSocketOneSourceEndpoint.ip().port())), - k_REUSE_ADDRESS); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->bind( + ntsa::Endpoint( + ntsa::IpEndpoint(adapterAddress, + listenerSocketOneSourceEndpoint.ip().port())), + k_REUSE_ADDRESS); + NTSCFG_TEST_OK(error); - // Learn the port assigned to the "inner" socket. + // Learn the port assigned to the "inner" socket. - ntsa::Endpoint listenerSocketTwoSourceEndpoint; - error = listenerSocketTwo->sourceEndpoint( - &listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + ntsa::Endpoint listenerSocketTwoSourceEndpoint; + error = + listenerSocketTwo->sourceEndpoint(&listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Assert the endpoints to which the two sockets are bound are the - // same. + // Assert the endpoints to which the two sockets are bound are the + // same. - NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), - listenerSocketTwoSourceEndpoint.ip().port()); + NTSCFG_TEST_EQ(listenerSocketOneSourceEndpoint.ip().port(), + listenerSocketTwoSourceEndpoint.ip().port()); - // Begin listening on the "inner" listener socket. + // Begin listening on the "inner" listener socket. - error = listenerSocketTwo->listen(1); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->listen(1); + NTSCFG_TEST_OK(error); - // Create a "client" TCP/IPv4 stream socket. + // Create a "client" TCP/IPv4 stream socket. - bsl::shared_ptr clientSocket = - ntsf::System::createStreamSocket(&ta); + bsl::shared_ptr clientSocket = + ntsf::System::createStreamSocket(NTSCFG_TEST_ALLOCATOR); - error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_OK(error); + error = clientSocket->open(ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_OK(error); - // Connect the "client" stream socket to the "inner" listening socket. + // Connect the "client" stream socket to the "inner" listening socket. - error = clientSocket->connect(listenerSocketTwoSourceEndpoint); - NTSCFG_TEST_OK(error); + error = clientSocket->connect(listenerSocketTwoSourceEndpoint); + NTSCFG_TEST_OK(error); - // Accept a "server" stream socket from the "inner" listening socket. + // Accept a "server" stream socket from the "inner" listening socket. - bsl::shared_ptr serverSocket; - error = listenerSocketTwo->accept(&serverSocket, &ta); - NTSCFG_TEST_OK(error); + bsl::shared_ptr serverSocket; + error = listenerSocketTwo->accept(&serverSocket, NTSCFG_TEST_ALLOCATOR); + NTSCFG_TEST_OK(error); - // Send data from the "client" socket to the "server" socket. + // Send data from the "client" socket to the "server" socket. - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - char sendData[13]; - bsl::memcpy(sendData, "Hello, world!", 13); + char sendData[13]; + bsl::memcpy(sendData, "Hello, world!", 13); - error = clientSocket->send(&sendContext, sendData, 13, sendOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); + error = clientSocket->send(&sendContext, sendData, 13, sendOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(sendContext.bytesSent(), 13); - // Receive data at the "server" socket send by the "client" socket. + // Receive data at the "server" socket send by the "client" socket. - ntsa::ReceiveContext receiveContext; - ntsa::ReceiveOptions receiveOptions; + ntsa::ReceiveContext receiveContext; + ntsa::ReceiveOptions receiveOptions; - char receiveData[13]; + char receiveData[13]; - error = serverSocket->receive(&receiveContext, - receiveData, - sizeof receiveData, - receiveOptions); - NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); + error = serverSocket->receive(&receiveContext, + receiveData, + sizeof receiveData, + receiveOptions); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_EQ(receiveContext.bytesReceived(), 13); - // Assert the data received by the "server" socket matches the data - // send by the "client" socket. + // Assert the data received by the "server" socket matches the data + // send by the "client" socket. - NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); + NTSCFG_TEST_EQ(bsl::memcmp(receiveData, sendData, 13), 0); - // Close the "client" socket. + // Close the "client" socket. - error = clientSocket->close(); - NTSCFG_TEST_OK(error); + error = clientSocket->close(); + NTSCFG_TEST_OK(error); - // Close the "server" socket. + // Close the "server" socket. - error = serverSocket->close(); - NTSCFG_TEST_OK(error); + error = serverSocket->close(); + NTSCFG_TEST_OK(error); - // Close the "inner" listener socket. + // Close the "inner" listener socket. - error = listenerSocketTwo->close(); - NTSCFG_TEST_OK(error); + error = listenerSocketTwo->close(); + NTSCFG_TEST_OK(error); - // Close the "outer" listener socket. + // Close the "outer" listener socket. - error = listenerSocketOne->close(); - NTSCFG_TEST_OK(error); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + error = listenerSocketOne->close(); + NTSCFG_TEST_OK(error); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase4) { // Concern: Resolution from default resolver automatically initialized - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::vector ipAddressListOverride; - ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); - ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); + ntsa::Error error; - error = - ntsf::System::setIpAddress("example.com", ipAddressListOverride); - NTSCFG_TEST_OK(error); + bsl::vector ipAddressListOverride; + ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); + ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); - bsl::set ipAddressSet(ipAddressListOverride.begin(), - ipAddressListOverride.end()); + error = ntsf::System::setIpAddress("example.com", ipAddressListOverride); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(ipAddressListOverride.begin(), + ipAddressListOverride.end()); - bsl::vector ipAddressList; - ntsa::IpAddressOptions ipAddressOptions; + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - error = ntsf::System::getIpAddress(&ipAddressList, - "example.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + bsl::vector ipAddressList; + ntsa::IpAddressOptions ipAddressOptions; - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsf::System::getIpAddress(&ipAddressList, + "example.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - bsl::size_t n = ipAddressSet.erase(*it); - NTSCFG_TEST_EQ(n, 1); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + bsl::size_t n = ipAddressSet.erase(*it); + NTSCFG_TEST_EQ(n, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase5) { // Concern: Resolution from default resolver explicitly installed - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - { - ntsa::ResolverConfig resolverConfig; - resolverConfig.setOverridesEnabled(true); - resolverConfig.setSystemEnabled(false); + ntsa::Error error; - bsl::shared_ptr resolver = - ntsf::System::createResolver( - resolverConfig, - bslma::Default::globalAllocator()); + { + ntsa::ResolverConfig resolverConfig; + resolverConfig.setOverridesEnabled(true); + resolverConfig.setSystemEnabled(false); - NTSCFG_TEST_EQ(resolver.use_count(), 1); + bsl::shared_ptr resolver = + ntsf::System::createResolver(resolverConfig, + bslma::Default::globalAllocator()); - ntsf::System::setDefault(resolver); + NTSCFG_TEST_EQ(resolver.use_count(), 1); - NTSCFG_TEST_EQ(resolver.use_count(), 2); + ntsf::System::setDefault(resolver); - bsl::shared_ptr resolverDefault; - ntsf::System::getDefault(&resolverDefault); + NTSCFG_TEST_EQ(resolver.use_count(), 2); - NTSCFG_TEST_EQ(resolver.use_count(), 3); + bsl::shared_ptr resolverDefault; + ntsf::System::getDefault(&resolverDefault); - NTSCFG_TEST_EQ(resolverDefault, resolver); - } + NTSCFG_TEST_EQ(resolver.use_count(), 3); - bsl::vector ipAddressListOverride; - ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); - ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); + NTSCFG_TEST_EQ(resolverDefault, resolver); + } - error = - ntsf::System::setIpAddress("example.com", ipAddressListOverride); - NTSCFG_TEST_OK(error); + bsl::vector ipAddressListOverride; + ipAddressListOverride.push_back(ntsa::IpAddress("4.4.4.4")); + ipAddressListOverride.push_back(ntsa::IpAddress("8.8.8.8")); - bsl::set ipAddressSet(ipAddressListOverride.begin(), - ipAddressListOverride.end()); + error = ntsf::System::setIpAddress("example.com", ipAddressListOverride); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(ipAddressListOverride.begin(), + ipAddressListOverride.end()); - bsl::vector ipAddressList; - ntsa::IpAddressOptions ipAddressOptions; + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - error = ntsf::System::getIpAddress(&ipAddressList, - "example.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + bsl::vector ipAddressList; + ntsa::IpAddressOptions ipAddressOptions; - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsf::System::getIpAddress(&ipAddressList, + "example.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - bsl::size_t n = ipAddressSet.erase(*it); - NTSCFG_TEST_EQ(n, 1); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + bsl::size_t n = ipAddressSet.erase(*it); + NTSCFG_TEST_EQ(n, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase6) { // Concern: test that loadTcpCongestionControlAlgorithmSupport does not - // contradict with testTcpCongestionControlAlgorithmSupport + // contradict with testTcpCongestionControlAlgorithmSupport. - ntscfg::TestAllocator ta; - { - bsl::vector supportedAlgorithms(&ta); + ntsa::Error error; - const ntsa::Error error = - ntsf::System::loadTcpCongestionControlAlgorithmSupport( - &supportedAlgorithms); + bsl::vector supportedAlgorithms(NTSCFG_TEST_ALLOCATOR); + error = ntsf::System::loadTcpCongestionControlAlgorithmSupport( + &supportedAlgorithms); #if defined(BSLS_PLATFORM_OS_LINUX) - NTSCFG_TEST_OK(error); - - for (bsl::vector::const_iterator it = - supportedAlgorithms.cbegin(); - it != supportedAlgorithms.cend(); - ++it) - { - NTSCFG_TEST_TRUE( - ntsf::System::testTcpCongestionControlAlgorithmSupport(*it)); - } + NTSCFG_TEST_OK(error); + + for (bsl::vector::const_iterator it = + supportedAlgorithms.cbegin(); + it != supportedAlgorithms.cend(); + ++it) + { + NTSCFG_TEST_TRUE( + ntsf::System::testTcpCongestionControlAlgorithmSupport(*it)); + } #else - NTSCFG_TEST_ERROR(error, ntsa::Error::e_NOT_IMPLEMENTED); + NTSCFG_TEST_ERROR(error, ntsa::Error::e_NOT_IMPLEMENTED); #endif - // test some random unsupported name: - NTSCFG_TEST_FALSE( - ntsf::System::testTcpCongestionControlAlgorithmSupport( - "random_name")); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + NTSCFG_TEST_FALSE( + ntsf::System::testTcpCongestionControlAlgorithmSupport("random_name")); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsf::SystemTest::verifyCase7) { - ntscfg::TestAllocator ta; - { - bsl::shared_ptr socket = - ntsf::System::createDatagramSocket(&ta); + // Concern: setBlocking/getBlocking. + + ntsa::Error error; + + bsl::shared_ptr socket = + ntsf::System::createDatagramSocket(NTSCFG_TEST_ALLOCATOR); + + error = socket->open(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_OK(error); - ntsa::Error error = socket->open(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - NTSCFG_TEST_OK(error); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_OK(ntsf::System::setBlocking(socket->handle(), true)); + error = ntsf::System::setBlocking(socket->handle(), true); + NTSCFG_TEST_OK(error); + + bool blocking = false; + error = ntsf::System::getBlocking(socket->handle(), &blocking); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_TRUE(blocking); - bool blocking = false; - NTSCFG_TEST_OK(ntsf::System::getBlocking(socket->handle(), &blocking)); - NTSCFG_TEST_TRUE(blocking); + error = ntsf::System::setBlocking(socket->handle(), false); + NTSCFG_TEST_OK(error); - NTSCFG_TEST_OK(ntsf::System::setBlocking(socket->handle(), false)); + blocking = true; + error = ntsf::System::getBlocking(socket->handle(), &blocking); + NTSCFG_TEST_OK(error); + NTSCFG_TEST_FALSE(blocking); - blocking = true; - NTSCFG_TEST_OK(ntsf::System::getBlocking(socket->handle(), &blocking)); - NTSCFG_TEST_FALSE(blocking); #else - bool blocking = false; - NTSCFG_TEST_TRUE( - ntsf::System::getBlocking(socket->handle(), &blocking)); + + bool blocking = false; + error = ntsf::System::getBlocking(socket->handle(), &blocking); + NTSCFG_TEST_TRUE(error); #endif - error = socket->close(); - NTSCFG_TEST_OK(error); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + error = socket->close(); + NTSCFG_TEST_OK(error); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsf +} // close namespace BloombergLP diff --git a/groups/nts/ntsi/ntsi_datagramsocket.cpp b/groups/nts/ntsi/ntsi_datagramsocket.cpp index f1e93ce6..92482f07 100644 --- a/groups/nts/ntsi/ntsi_datagramsocket.cpp +++ b/groups/nts/ntsi/ntsi_datagramsocket.cpp @@ -73,7 +73,7 @@ ntsa::Error DatagramSocket::send(ntsa::SendContext* context, } ntsa::Error DatagramSocket::send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) { @@ -187,9 +187,9 @@ ntsa::Error DatagramSocket::leaveMulticastGroup( } ntsa::Error DatagramSocket::joinMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { NTSCFG_WARNING_UNUSED(interface); NTSCFG_WARNING_UNUSED(group); @@ -199,9 +199,9 @@ ntsa::Error DatagramSocket::joinMulticastGroupSource( } ntsa::Error DatagramSocket::leaveMulticastGroupSource( - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { NTSCFG_WARNING_UNUSED(interface); NTSCFG_WARNING_UNUSED(group); diff --git a/groups/nts/ntsi/ntsi_datagramsocket.h b/groups/nts/ntsi/ntsi_datagramsocket.h index 75ce2420..63a18f0c 100644 --- a/groups/nts/ntsi/ntsi_datagramsocket.h +++ b/groups/nts/ntsi/ntsi_datagramsocket.h @@ -474,7 +474,7 @@ class DatagramSocket : public ntsi::Channel /// the specified 'context' the result of the operation. Return the /// error. virtual ntsa::Error send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options); diff --git a/groups/nts/ntsi/ntsi_streamsocket.cpp b/groups/nts/ntsi/ntsi_streamsocket.cpp index 059828a2..8b7db084 100644 --- a/groups/nts/ntsi/ntsi_streamsocket.cpp +++ b/groups/nts/ntsi/ntsi_streamsocket.cpp @@ -73,7 +73,7 @@ ntsa::Error StreamSocket::send(ntsa::SendContext* context, } ntsa::Error StreamSocket::send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options) { diff --git a/groups/nts/ntsi/ntsi_streamsocket.h b/groups/nts/ntsi/ntsi_streamsocket.h index 6eaadd8e..00dc24c8 100644 --- a/groups/nts/ntsi/ntsi_streamsocket.h +++ b/groups/nts/ntsi/ntsi_streamsocket.h @@ -269,7 +269,7 @@ class StreamSocket : public ntsi::Channel /// the specified 'context' the result of the operation. Return the /// error. virtual ntsa::Error send(ntsa::SendContext* context, - const ntsa::ConstBuffer *data, + const ntsa::ConstBuffer* data, bsl::size_t size, const ntsa::SendOptions& options); diff --git a/groups/nts/ntso/ntso_devpoll.t.cpp b/groups/nts/ntso/ntso_devpoll.t.cpp index ee87cd3a..4f47975f 100644 --- a/groups/nts/ntso/ntso_devpoll.t.cpp +++ b/groups/nts/ntso/ntso_devpoll.t.cpp @@ -13,94 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_DEVPOLL_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::Devpoll'. +class DevpollTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::DevpollTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("devpoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("devpoll"); - bsl::shared_ptr reactor = - ntso::DevpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::DevpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::DevpollTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("devpoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("devpoll"); - bsl::shared_ptr reactor = - ntso::DevpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::DevpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::DevpollTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("devpoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("devpoll"); - bsl::shared_ptr reactor = - ntso::DevpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::DevpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_epoll.t.cpp b/groups/nts/ntso/ntso_epoll.t.cpp index 5fe05152..6faa36a8 100644 --- a/groups/nts/ntso/ntso_epoll.t.cpp +++ b/groups/nts/ntso/ntso_epoll.t.cpp @@ -13,94 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_EPOLL_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::Epoll'. +class EpollTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::EpollTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("epoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("epoll"); - bsl::shared_ptr reactor = - ntso::EpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::EpollTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("epoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("epoll"); - bsl::shared_ptr reactor = - ntso::EpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::EpollTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("epoll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("epoll"); - bsl::shared_ptr reactor = - ntso::EpollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EpollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_eventport.t.cpp b/groups/nts/ntso/ntso_eventport.t.cpp index 259698fb..f4445705 100644 --- a/groups/nts/ntso/ntso_eventport.t.cpp +++ b/groups/nts/ntso/ntso_eventport.t.cpp @@ -13,94 +13,91 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_EVENTPORT_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::EventPort'. +class EventPortTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::EventPortTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("eventport"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("eventport"); - bsl::shared_ptr reactor = - ntso::EventPortUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EventPortUtil::createReactor(reactorConfig, + NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::EventPortTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("eventport"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("eventport"); - bsl::shared_ptr reactor = - ntso::EventPortUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EventPortUtil::createReactor(reactorConfig, + NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::EventPortTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("eventport"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("eventport"); - bsl::shared_ptr reactor = - ntso::EventPortUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::EventPortUtil::createReactor(reactorConfig, + NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_kqueue.t.cpp b/groups/nts/ntso/ntso_kqueue.t.cpp index 6e69c681..20e341d6 100644 --- a/groups/nts/ntso/ntso_kqueue.t.cpp +++ b/groups/nts/ntso/ntso_kqueue.t.cpp @@ -13,98 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_KQUEUE_ENABLED -namespace test { +// Provide tests for 'ntso::Kqueue'. +class KqueueTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); -} // close namespace test + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntso::KqueueTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("kqueue"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("kqueue"); - bsl::shared_ptr reactor = - ntso::KqueueUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::KqueueUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::KqueueTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("kqueue"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("kqueue"); - bsl::shared_ptr reactor = - ntso::KqueueUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::KqueueUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::KqueueTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("kqueue"); - - bsl::shared_ptr reactor = - ntso::KqueueUtil::createReactor(reactorConfig, &ta); - - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); - - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("kqueue"); -#else + bsl::shared_ptr reactor = + ntso::KqueueUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); -NTSCFG_TEST_CASE(1) -{ -} + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER_END; #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_poll.t.cpp b/groups/nts/ntso/ntso_poll.t.cpp index 68b4526e..fa78c324 100644 --- a/groups/nts/ntso/ntso_poll.t.cpp +++ b/groups/nts/ntso/ntso_poll.t.cpp @@ -13,94 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_POLL_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::Poll'. +class PollTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::PollTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("poll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("poll"); - bsl::shared_ptr reactor = - ntso::PollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::PollTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("poll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("poll"); - bsl::shared_ptr reactor = - ntso::PollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::PollTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("poll"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("poll"); - bsl::shared_ptr reactor = - ntso::PollUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_pollset.t.cpp b/groups/nts/ntso/ntso_pollset.t.cpp index 369cd84c..17d6c513 100644 --- a/groups/nts/ntso/ntso_pollset.t.cpp +++ b/groups/nts/ntso/ntso_pollset.t.cpp @@ -13,94 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_POLLSET_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::Pollset'. +class PollsetTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::PollsetTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("pollset"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("pollset"); - bsl::shared_ptr reactor = - ntso::PollsetUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollsetUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::PollsetTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("pollset"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("pollset"); - bsl::shared_ptr reactor = - ntso::PollsetUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollsetUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::PollsetTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("pollset"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("pollset"); - bsl::shared_ptr reactor = - ntso::PollsetUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::PollsetUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_select.t.cpp b/groups/nts/ntso/ntso_select.t.cpp index e7fb128a..3b6dfa3c 100644 --- a/groups/nts/ntso/ntso_select.t.cpp +++ b/groups/nts/ntso/ntso_select.t.cpp @@ -13,94 +13,88 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - +#include #include +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; +namespace BloombergLP { +namespace ntso { + #if NTSO_SELECT_ENABLED -NTSCFG_TEST_CASE(1) +// Provide tests for 'ntso::Select'. +class SelectTest +{ + public: + // Concern: Test the usage example. + static void verifyCase1(); + + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + static void verifyCase2(); + + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + static void verifyCase3(); +}; + +NTSCFG_TEST_FUNCTION(ntso::SelectTest::verifyCase1) { // Concern: Test the usage example. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("select"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("select"); - bsl::shared_ptr reactor = - ntso::SelectUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::SelectUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::usage(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::usage(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntso::SelectTest::verifyCase2) { // Concern: Polling after a socket has been shutdown for both reading and // writing after both sides have shutdown writing does not block. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("select"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("select"); - bsl::shared_ptr reactor = - ntso::SelectUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::SelectUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterFullShutdown(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterFullShutdown(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntso::SelectTest::verifyCase3) { // Concern: Close socket while it still remains added to the reactor. // Polling the reactor times out. - ntscfg::TestAllocator ta; - { - ntsa::ReactorConfig reactorConfig(&ta); - reactorConfig.setDriverName("select"); + ntsa::ReactorConfig reactorConfig(NTSCFG_TEST_ALLOCATOR); + reactorConfig.setDriverName("select"); - bsl::shared_ptr reactor = - ntso::SelectUtil::createReactor(reactorConfig, &ta); + bsl::shared_ptr reactor = + ntso::SelectUtil::createReactor(reactorConfig, NTSCFG_TEST_ALLOCATOR); - ntso::Test::ReactorVector reactorVector(&ta); - reactorVector.push_back(reactor); + ntso::Test::ReactorVector reactorVector(NTSCFG_TEST_ALLOCATOR); + reactorVector.push_back(reactor); - ntso::Test::pollingAfterClose(reactorVector, &ta); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + ntso::Test::pollingAfterClose(reactorVector, NTSCFG_TEST_ALLOCATOR); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); -} -NTSCFG_TEST_DRIVER_END; - -#else - -NTSCFG_TEST_CASE(1) -{ -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; - #endif + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/ntso_test.cpp b/groups/nts/ntso/ntso_test.cpp index ef0dbb62..863d2ce7 100644 --- a/groups/nts/ntso/ntso_test.cpp +++ b/groups/nts/ntso/ntso_test.cpp @@ -13,1022 +13,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include BSLS_IDENT_RCSID(ntso_test_cpp, "$Id$ $CSID$") - -namespace BloombergLP { -namespace ntso { - -void Test::usage(const ReactorVector& reactors, bslma::Allocator* allocator) -{ - // Concern: - // Plan: - - ntsa::Error error; - - for (ReactorVector::const_iterator reactorIterator = reactors.begin(); - reactorIterator != reactors.end(); - ++reactorIterator) - { - const bsl::shared_ptr& reactor = *reactorIterator; - - ntsa::EventSet eventSet(allocator); - - bdlb::NullableValue deadline; - - // Create a socket pair. - - bsl::shared_ptr client; - bsl::shared_ptr server; - - error = Test::pair(&client, - &server, - ntsa::Transport::e_TCP_IPV4_STREAM, - allocator); - NTSCFG_TEST_OK(error); - - error = client->setBlocking(false); - NTSCFG_TEST_OK(error); - - error = server->setBlocking(false); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); - - // Send a single byte to the server. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = client->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the client. - - error = reactor->hideWritable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); - - // Receive a single byte at the server. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = server->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); - - // Send a single byte to the client. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = server->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the server. - - error = reactor->hideWritable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); - - // Receive a single byte at the client. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = client->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Shutdown writing by the client. - - BSLS_LOG_DEBUG("Descriptor %d shutting down writing", - (int)(client->handle())); - - error = client->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || - eventSet.isHangup(server->handle())); - - // Receive a single byte at the server. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = server->receive(&context, &data, options); - if (error) { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); - } - else { - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 0); - } - } - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Shutdown writing by the server. - - BSLS_LOG_DEBUG("Descriptor %d shutting down writing", - (int)(server->handle())); - - error = server->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || - eventSet.isHangup(client->handle())); - - // Receive a single byte at the client. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = client->receive(&context, &data, options); - if (error) { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); - } - else { - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 0); - } - } - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Close the sockets. - - client->close(); - server->close(); - } -} - -void Test::pollingAfterFullShutdown(const ReactorVector& reactors, - bslma::Allocator* allocator) -{ - // Concern: Polling after a socket has been shutdown for both reading and - // writing after both sides have shutdown writing does not block. - - ntsa::Error error; - - for (ReactorVector::const_iterator reactorIterator = reactors.begin(); - reactorIterator != reactors.end(); - ++reactorIterator) - { - const bsl::shared_ptr& reactor = *reactorIterator; - - ntsa::EventSet eventSet(allocator); - - bdlb::NullableValue deadline; - - // Create a socket pair. - - bsl::shared_ptr client; - bsl::shared_ptr server; - - error = Test::pair(&client, - &server, - ntsa::Transport::e_TCP_IPV4_STREAM, - allocator); - NTSCFG_TEST_OK(error); - - error = client->setBlocking(false); - NTSCFG_TEST_OK(error); - - error = server->setBlocking(false); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); - - // Send a single byte to the server. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = client->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the client. - - error = reactor->hideWritable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); - - // Receive a single byte at the server. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = server->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); - - // Send a single byte to the client. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = server->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the server. - - error = reactor->hideWritable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); - - // Receive a single byte at the client. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = client->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Shutdown writing by the client. - - BSLS_LOG_DEBUG("Descriptor %d shutting down writing", - (int)(client->handle())); - - error = client->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || - eventSet.isHangup(server->handle())); - - // Receive a single byte at the server. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = server->receive(&context, &data, options); - if (error) { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); - } - else { - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 0); - } - } - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Shutdown writing by the server. - - BSLS_LOG_DEBUG("Descriptor %d shutting down writing", - (int)(server->handle())); - - error = server->shutdown(ntsa::ShutdownType::e_SEND); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || - eventSet.isHangup(client->handle())); - - // Receive a single byte at the client. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = client->receive(&context, &data, options); - if (error) { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); - } - else { - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 0); - } - } - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - BSLS_LOG_INFO("Polling server after shutdown complete"); - - // Shutdown reading by the server. - - server->shutdown(ntsa::ShutdownType::e_RECEIVE); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable or has an error. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || - eventSet.isHangup(server->handle()) || - eventSet.isError(server->handle())); - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - BSLS_LOG_INFO("Polling client after shutdown complete"); - - // Shutdown reading by the client. - - client->shutdown(ntsa::ShutdownType::e_RECEIVE); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable or has an error. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || - eventSet.isHangup(client->handle()) || - eventSet.isError(client->handle())); - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Close the sockets. - - client->close(); - server->close(); - } -} - -void Test::pollingAfterClose(const ReactorVector& reactors, - bslma::Allocator* allocator) -{ - // Concern: Close socket while it still remains added to the reactor. - // Polling the reactor times out. - - ntsa::Error error; - - for (ReactorVector::const_iterator reactorIterator = reactors.begin(); - reactorIterator != reactors.end(); - ++reactorIterator) - { - const bsl::shared_ptr& reactor = *reactorIterator; - - ntsa::EventSet eventSet(allocator); - - bdlb::NullableValue deadline; - - // Create a socket pair. - - bsl::shared_ptr client; - bsl::shared_ptr server; - - error = Test::pair(&client, - &server, - ntsa::Transport::e_TCP_IPV4_STREAM, - allocator); - NTSCFG_TEST_OK(error); - - error = client->setBlocking(false); - NTSCFG_TEST_OK(error); - - error = server->setBlocking(false); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); - - // Send a single byte to the server. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = client->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the client. - - error = reactor->hideWritable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); - - // Receive a single byte at the server. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = server->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the server. - - error = reactor->hideReadable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the writability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showWritable(server); - NTSCFG_TEST_OK(error); - - // Wait until the server is writable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); - - // Send a single byte to the client. - - { - char buffer = 'X'; - - ntsa::SendContext context; - ntsa::SendOptions options; - - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - - error = server->send(&context, data, options); - NTSCFG_TEST_OK(error); - - NTSCFG_TEST_EQ(context.bytesSendable(), 1); - NTSCFG_TEST_EQ(context.bytesSent(), 1); - } - - // Lose interest in the writability of the server. - - error = reactor->hideWritable(server); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(server); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the client. - - error = reactor->attachSocket(client); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(client); - NTSCFG_TEST_OK(error); - - // Wait until the client is readable. - - error = reactor->wait(&eventSet, deadline); - NTSCFG_TEST_OK(error); - ntso::Test::log(eventSet); - - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); - - // Receive a single byte at the client. - - { - char buffer; - - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; - - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - - error = client->receive(&context, &data, options); - NTSCFG_TEST_FALSE(error); - - NTSCFG_TEST_EQ(context.bytesReceivable(), 1); - NTSCFG_TEST_EQ(context.bytesReceived(), 1); - NTSCFG_TEST_EQ(buffer, 'X'); - } - - // Lose interest in the readability of the client. - - error = reactor->hideReadable(client); - NTSCFG_TEST_OK(error); - - error = reactor->detachSocket(client); - NTSCFG_TEST_OK(error); - - // Gain interest in the readability of the server. - - error = reactor->attachSocket(server); - NTSCFG_TEST_OK(error); - - error = reactor->showReadable(server); - NTSCFG_TEST_OK(error); - - BSLS_LOG_DEBUG("Descriptor %d closing", (int)(server->handle())); - ntsa::Handle serverHandle = server->handle(); - server->close(); - - // Wait until the server is readable. - - error = - reactor->wait(&eventSet, - bdlt::CurrentTime::now() + bsls::TimeInterval(1)); - if (error) { - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_WOULD_BLOCK)); - ntso::Test::log(eventSet); - NTSCFG_TEST_EQ(eventSet.size(), 0); - } - else { - ntso::Test::log(eventSet); - NTSCFG_TEST_EQ(eventSet.size(), 1); - NTSCFG_TEST_TRUE(eventSet.isError(serverHandle)); - - ntsa::Event event; - const bool found = eventSet.find(&event, serverHandle); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_TRUE( - event.error() == ntsa::Error(ntsa::Error::e_NOT_OPEN) || - event.error() == ntsa::Error(ntsa::Error::e_NOT_SOCKET)); - } - } -} - -void Test::log(const bsl::vector& eventSet) -{ - for (bsl::size_t i = 0; i < eventSet.size(); ++i) { - bsl::stringstream ss; - ss << eventSet[i]; - - BSLS_LOG_DEBUG("Polled event %s", ss.str().c_str()); - } -} - -ntsa::Error Test::pair(bsl::shared_ptr* client, - bsl::shared_ptr* server, - ntsa::Transport::Value type, - bslma::Allocator* basicAllocator) -{ - ntsa::Error error; - - bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); - - client->reset(); - server->reset(); - - bsl::shared_ptr concreteClient; - bsl::shared_ptr concreteServer; - - error = ntsb::StreamSocket::pair(&concreteClient, - &concreteServer, - ntsa::Transport::e_TCP_IPV4_STREAM, - allocator); - if (error) { - return error; - } - - *client = concreteClient; - *server = concreteServer; - - return ntsa::Error(); -} - -void Test::log(const ntsa::EventSet& eventSet) -{ - for (ntsa::EventSet::const_iterator it = eventSet.cbegin(); - it != eventSet.cend(); - ++it) - { - const ntsa::Event& event = *it; - - bsl::stringstream ss; - ss << event; - - BSLS_LOG_DEBUG("Polled event %s", ss.str().c_str()); - } -} - -} // close package namespace -} // close enterprise namespace diff --git a/groups/nts/ntso/ntso_test.h b/groups/nts/ntso/ntso_test.h index 4feb4a07..a086c1d5 100644 --- a/groups/nts/ntso/ntso_test.h +++ b/groups/nts/ntso/ntso_test.h @@ -26,15 +26,6 @@ BSLS_IDENT("$Id: $") #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include namespace BloombergLP { namespace ntso { @@ -97,6 +88,1016 @@ struct Test { static void log(const ntsa::EventSet& eventSet); }; +inline void Test::usage(const ReactorVector& reactors, + bslma::Allocator* allocator) +{ + // Concern: + // Plan: + + ntsa::Error error; + + for (ReactorVector::const_iterator reactorIterator = reactors.begin(); + reactorIterator != reactors.end(); + ++reactorIterator) + { + const bsl::shared_ptr& reactor = *reactorIterator; + + ntsa::EventSet eventSet(allocator); + + bdlb::NullableValue deadline; + + // Create a socket pair. + + bsl::shared_ptr client; + bsl::shared_ptr server; + + error = Test::pair(&client, + &server, + ntsa::Transport::e_TCP_IPV4_STREAM, + allocator); + NTSCFG_TEST_OK(error); + + error = client->setBlocking(false); + NTSCFG_TEST_OK(error); + + error = server->setBlocking(false); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); + + // Send a single byte to the server. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = client->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the client. + + error = reactor->hideWritable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); + + // Receive a single byte at the server. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = server->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); + + // Send a single byte to the client. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = server->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the server. + + error = reactor->hideWritable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); + + // Receive a single byte at the client. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = client->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Shutdown writing by the client. + + BSLS_LOG_DEBUG("Descriptor %d shutting down writing", + (int)(client->handle())); + + error = client->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || + eventSet.isHangup(server->handle())); + + // Receive a single byte at the server. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = server->receive(&context, &data, options); + if (error) { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); + } + else { + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 0); + } + } + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Shutdown writing by the server. + + BSLS_LOG_DEBUG("Descriptor %d shutting down writing", + (int)(server->handle())); + + error = server->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || + eventSet.isHangup(client->handle())); + + // Receive a single byte at the client. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = client->receive(&context, &data, options); + if (error) { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); + } + else { + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 0); + } + } + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Close the sockets. + + client->close(); + server->close(); + } +} + +inline void Test::pollingAfterFullShutdown(const ReactorVector& reactors, + bslma::Allocator* allocator) +{ + // Concern: Polling after a socket has been shutdown for both reading and + // writing after both sides have shutdown writing does not block. + + ntsa::Error error; + + for (ReactorVector::const_iterator reactorIterator = reactors.begin(); + reactorIterator != reactors.end(); + ++reactorIterator) + { + const bsl::shared_ptr& reactor = *reactorIterator; + + ntsa::EventSet eventSet(allocator); + + bdlb::NullableValue deadline; + + // Create a socket pair. + + bsl::shared_ptr client; + bsl::shared_ptr server; + + error = Test::pair(&client, + &server, + ntsa::Transport::e_TCP_IPV4_STREAM, + allocator); + NTSCFG_TEST_OK(error); + + error = client->setBlocking(false); + NTSCFG_TEST_OK(error); + + error = server->setBlocking(false); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); + + // Send a single byte to the server. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = client->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the client. + + error = reactor->hideWritable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); + + // Receive a single byte at the server. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = server->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); + + // Send a single byte to the client. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = server->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the server. + + error = reactor->hideWritable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); + + // Receive a single byte at the client. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = client->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Shutdown writing by the client. + + BSLS_LOG_DEBUG("Descriptor %d shutting down writing", + (int)(client->handle())); + + error = client->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || + eventSet.isHangup(server->handle())); + + // Receive a single byte at the server. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = server->receive(&context, &data, options); + if (error) { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); + } + else { + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 0); + } + } + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Shutdown writing by the server. + + BSLS_LOG_DEBUG("Descriptor %d shutting down writing", + (int)(server->handle())); + + error = server->shutdown(ntsa::ShutdownType::e_SEND); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || + eventSet.isHangup(client->handle())); + + // Receive a single byte at the client. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = client->receive(&context, &data, options); + if (error) { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_EOF)); + } + else { + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 0); + } + } + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + BSLS_LOG_INFO("Polling server after shutdown complete"); + + // Shutdown reading by the server. + + server->shutdown(ntsa::ShutdownType::e_RECEIVE); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable or has an error. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle()) || + eventSet.isHangup(server->handle()) || + eventSet.isError(server->handle())); + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + BSLS_LOG_INFO("Polling client after shutdown complete"); + + // Shutdown reading by the client. + + client->shutdown(ntsa::ShutdownType::e_RECEIVE); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable or has an error. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle()) || + eventSet.isHangup(client->handle()) || + eventSet.isError(client->handle())); + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Close the sockets. + + client->close(); + server->close(); + } +} + +inline void Test::pollingAfterClose(const ReactorVector& reactors, + bslma::Allocator* allocator) +{ + // Concern: Close socket while it still remains added to the reactor. + // Polling the reactor times out. + + ntsa::Error error; + + for (ReactorVector::const_iterator reactorIterator = reactors.begin(); + reactorIterator != reactors.end(); + ++reactorIterator) + { + const bsl::shared_ptr& reactor = *reactorIterator; + + ntsa::EventSet eventSet(allocator); + + bdlb::NullableValue deadline; + + // Create a socket pair. + + bsl::shared_ptr client; + bsl::shared_ptr server; + + error = Test::pair(&client, + &server, + ntsa::Transport::e_TCP_IPV4_STREAM, + allocator); + NTSCFG_TEST_OK(error); + + error = client->setBlocking(false); + NTSCFG_TEST_OK(error); + + error = server->setBlocking(false); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(client->handle())); + + // Send a single byte to the server. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = client->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the client. + + error = reactor->hideWritable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(server->handle())); + + // Receive a single byte at the server. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = server->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the server. + + error = reactor->hideReadable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the writability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showWritable(server); + NTSCFG_TEST_OK(error); + + // Wait until the server is writable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isWritable(server->handle())); + + // Send a single byte to the client. + + { + char buffer = 'X'; + + ntsa::SendContext context; + ntsa::SendOptions options; + + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + + error = server->send(&context, data, options); + NTSCFG_TEST_OK(error); + + NTSCFG_TEST_EQ(context.bytesSendable(), 1); + NTSCFG_TEST_EQ(context.bytesSent(), 1); + } + + // Lose interest in the writability of the server. + + error = reactor->hideWritable(server); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(server); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the client. + + error = reactor->attachSocket(client); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(client); + NTSCFG_TEST_OK(error); + + // Wait until the client is readable. + + error = reactor->wait(&eventSet, deadline); + NTSCFG_TEST_OK(error); + ntso::Test::log(eventSet); + + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isReadable(client->handle())); + + // Receive a single byte at the client. + + { + char buffer; + + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; + + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + + error = client->receive(&context, &data, options); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_EQ(context.bytesReceivable(), 1); + NTSCFG_TEST_EQ(context.bytesReceived(), 1); + NTSCFG_TEST_EQ(buffer, 'X'); + } + + // Lose interest in the readability of the client. + + error = reactor->hideReadable(client); + NTSCFG_TEST_OK(error); + + error = reactor->detachSocket(client); + NTSCFG_TEST_OK(error); + + // Gain interest in the readability of the server. + + error = reactor->attachSocket(server); + NTSCFG_TEST_OK(error); + + error = reactor->showReadable(server); + NTSCFG_TEST_OK(error); + + BSLS_LOG_DEBUG("Descriptor %d closing", (int)(server->handle())); + ntsa::Handle serverHandle = server->handle(); + server->close(); + + // Wait until the server is readable. + + error = + reactor->wait(&eventSet, + bdlt::CurrentTime::now() + bsls::TimeInterval(1)); + if (error) { + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_WOULD_BLOCK)); + ntso::Test::log(eventSet); + NTSCFG_TEST_EQ(eventSet.size(), 0); + } + else { + ntso::Test::log(eventSet); + NTSCFG_TEST_EQ(eventSet.size(), 1); + NTSCFG_TEST_TRUE(eventSet.isError(serverHandle)); + + ntsa::Event event; + const bool found = eventSet.find(&event, serverHandle); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_TRUE( + event.error() == ntsa::Error(ntsa::Error::e_NOT_OPEN) || + event.error() == ntsa::Error(ntsa::Error::e_NOT_SOCKET)); + } + } +} + +inline void Test::log(const bsl::vector& eventSet) +{ + for (bsl::size_t i = 0; i < eventSet.size(); ++i) { + bsl::stringstream ss; + ss << eventSet[i]; + + BSLS_LOG_DEBUG("Polled event %s", ss.str().c_str()); + } +} + +inline ntsa::Error Test::pair(bsl::shared_ptr* client, + bsl::shared_ptr* server, + ntsa::Transport::Value type, + bslma::Allocator* basicAllocator) +{ + ntsa::Error error; + + bslma::Allocator* allocator = bslma::Default::allocator(basicAllocator); + + client->reset(); + server->reset(); + + bsl::shared_ptr concreteClient; + bsl::shared_ptr concreteServer; + + error = ntsb::StreamSocket::pair(&concreteClient, + &concreteServer, + ntsa::Transport::e_TCP_IPV4_STREAM, + allocator); + if (error) { + return error; + } + + *client = concreteClient; + *server = concreteServer; + + return ntsa::Error(); +} + +inline void Test::log(const ntsa::EventSet& eventSet) +{ + for (ntsa::EventSet::const_iterator it = eventSet.cbegin(); + it != eventSet.cend(); + ++it) + { + const ntsa::Event& event = *it; + + bsl::stringstream ss; + ss << event; + + BSLS_LOG_DEBUG("Polled event %s", ss.str().c_str()); + } +} + } // close package namespace } // close enterprise namespace diff --git a/groups/nts/ntso/ntso_test.t.cpp b/groups/nts/ntso/ntso_test.t.cpp index 1a996dec..a35f23a8 100644 --- a/groups/nts/ntso/ntso_test.t.cpp +++ b/groups/nts/ntso/ntso_test.t.cpp @@ -13,16 +13,29 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + +#include +BSLS_IDENT_RCSID(ntso_test_t_cpp, "$Id$ $CSID$") + #include -#include +using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntso { + +// Provide tests for 'ntso::Test'. +class TestTest { -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntso::TestTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntso +} // close namespace BloombergLP diff --git a/groups/nts/ntso/package/ntso.mem b/groups/nts/ntso/package/ntso.mem index e8b1092b..6dbd86cc 100644 --- a/groups/nts/ntso/package/ntso.mem +++ b/groups/nts/ntso/package/ntso.mem @@ -5,4 +5,3 @@ ntso_kqueue ntso_poll ntso_pollset ntso_select -ntso_test diff --git a/groups/nts/ntsu/ntsu_adapterutil.t.cpp b/groups/nts/ntsu/ntsu_adapterutil.t.cpp index 5258157c..d2306829 100644 --- a/groups/nts/ntsu/ntsu_adapterutil.t.cpp +++ b/groups/nts/ntsu/ntsu_adapterutil.t.cpp @@ -14,32 +14,83 @@ // limitations under the License. #include -#include -#include -#include -#include -#include +#include +BSLS_IDENT_RCSID(ntsu_adapterutil_t_cpp, "$Id$ $CSID$") + +#include using namespace BloombergLP; -using namespace ntsu; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsu { + +// Provide tests for 'ntsu::AdapterUtil'. +class AdapterUtilTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + private: + // Print the specified 'adapterList' to the log. + static void log(const bsl::vector& adapterList); +}; + +NTSCFG_TEST_FUNCTION(ntsu::AdapterUtilTest::verifyCase1) +{ + bsl::vector adapterList(NTSCFG_TEST_ALLOCATOR); + ntsu::AdapterUtil::discoverAdapterList(&adapterList); + ntsu::AdapterUtilTest::log(adapterList); +} + +NTSCFG_TEST_FUNCTION(ntsu::AdapterUtilTest::verifyCase2) +{ + const bool supportsIpv4 = ntsu::AdapterUtil::supportsIpv4(); + NTSCFG_TEST_TRUE(supportsIpv4); + +#if defined(BSLS_PLATFORM_OS_UNIX) + + const bool supportsLocalStream = ntsu::AdapterUtil::supportsLocalStream(); + +#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL + NTSCFG_TEST_TRUE(supportsLocalStream); +#else + NTSCFG_TEST_FALSE(supportsLocalStream); +#endif -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + const bool supportsLocalDatagram = + ntsu::AdapterUtil::supportsLocalDatagram(); -namespace test { +#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL + NTSCFG_TEST_TRUE(supportsLocalDatagram); +#else + NTSCFG_TEST_FALSE(supportsLocalDatagram); +#endif + +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + + const bool supportsLocalStream = ntsu::AdapterUtil::supportsLocalStream(); + +#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL + NTSCFG_TEST_TRUE(supportsLocalStream); +#else + NTSCFG_TEST_FALSE(supportsLocalStream); +#endif + + const bool supportsLocalDatagram = + ntsu::AdapterUtil::supportsLocalDatagram(); + NTSCFG_TEST_FALSE(supportsLocalDatagram); + +#else +#error Unsupported platform +#endif +} -void logAdapterList(const bsl::vector& adapterList) +void AdapterUtilTest::log(const bsl::vector& adapterList) { const bsl::size_t WN = 40; const bsl::size_t WI = 6; @@ -102,68 +153,5 @@ void logAdapterList(const bsl::vector& adapterList) BSLS_LOG_DEBUG("\nAdapter list:\n%s", adapterListReport.c_str()); } -} // close namespace test - -NTSCFG_TEST_CASE(1) -{ - // Concern: - // Plan: - - ntscfg::TestAllocator ta; - { - bsl::vector adapterList; - ntsu::AdapterUtil::discoverAdapterList(&adapterList); - test::logAdapterList(adapterList); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} - -NTSCFG_TEST_CASE(2) -{ - const bool supportsIpv4 = ntsu::AdapterUtil::supportsIpv4(); - NTSCFG_TEST_TRUE(supportsIpv4); - -#if defined(BSLS_PLATFORM_OS_UNIX) - - const bool supportsLocalStream = ntsu::AdapterUtil::supportsLocalStream(); - -#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL - NTSCFG_TEST_TRUE(supportsLocalStream); -#else - NTSCFG_TEST_FALSE(supportsLocalStream); -#endif - - const bool supportsLocalDatagram = - ntsu::AdapterUtil::supportsLocalDatagram(); - -#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL - NTSCFG_TEST_TRUE(supportsLocalDatagram); -#else - NTSCFG_TEST_FALSE(supportsLocalDatagram); -#endif - -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - - const bool supportsLocalStream = ntsu::AdapterUtil::supportsLocalStream(); - -#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL - NTSCFG_TEST_TRUE(supportsLocalStream); -#else - NTSCFG_TEST_FALSE(supportsLocalStream); -#endif - - const bool supportsLocalDatagram = - ntsu::AdapterUtil::supportsLocalDatagram(); - NTSCFG_TEST_FALSE(supportsLocalDatagram); - -#else -#error Unsupported platform -#endif -} - -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/groups/nts/ntsu/ntsu_resolverutil.t.cpp b/groups/nts/ntsu/ntsu_resolverutil.t.cpp index 35bad8c3..099efa93 100644 --- a/groups/nts/ntsu/ntsu_resolverutil.t.cpp +++ b/groups/nts/ntsu/ntsu_resolverutil.t.cpp @@ -14,77 +14,118 @@ // limitations under the License. #include -#include -#include +#include +BSLS_IDENT_RCSID(ntsu_resolverutil_t_cpp, "$Id$ $CSID$") -#include -#include -#include -#include +#include using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsu { -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- +// Provide tests for 'ntsu::ResolverUtil'. +class ResolverUtilTest +{ + public: + // Verify concern: getHostname. + static void verifyGetHostname(); -namespace test { + // Verify concern: getHostnameFullyQualified. + static void verifyGetHostnameFullyQualified(); -const char IANA_SERVICE_NAME[] = "discard"; -const ntsa::Port IANA_SERVICE_TCP_PORT = 9; -const ntsa::Port IANA_SERVICE_UDP_PORT = 9; + // Verify concern: getIpAddress. + static void verifyGetIpAddress(); -} // close namespace test + // Verify concern: getIpAddress(V4). + static void verifyGetIpAddressV4(); -NTSCFG_TEST_CASE(1) -{ - // Concern: 'getHostname'. - // Plan: + // Verify concern: getIpAddress(V6). + static void verifyGetIpAddressV6(); - ntscfg::TestAllocator ta; - { - ntsa::Error error; + // Verify concern: getIpAddress(TCP_V4). + static void verifyGetIpAddressTcpV4(); - bsl::string hostname(&ta); - error = ntsu::ResolverUtil::getHostname(&hostname); - NTSCFG_TEST_FALSE(error); + // Verify concern: getIpAddress(UDP_V4). + static void verifyGetIpAddressUdpV4(); - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} + // Verify concern: getIpAddress(TCP_V6). + static void verifyGetIpAddressTcpV6(); + + // Verify concern: getIpAddress(UDP_V6). + static void verifyGetIpAddressUdpV6(); + + // Verify concern: getDomainName. + static void verifyGetDomainName(); + + // Verify concern: getPort. + static void verifyGetPort(); + + // Verify concern: getPort(TCP). + static void verifyGetPortTcp(); -NTSCFG_TEST_CASE(2) + // Verify concern: getPort(UDP). + static void verifyGetPortUdp(); + + // Verify concern: getServiceName. + static void verifyGetServiceName(); + + // Verify concern: getLocalIpAddress. + static void verifyGetLocalIpAddress(); + + // Verify concern: getLocalIpAddress(V4). + static void verifyGetLocalIpAddressV4(); + + // Verify concern: getLocalIpAddress(V6). + static void verifyGetLocalIpAddressV6(); + + // Verify concern: getLocalIpAddress(TCP_V4). + static void verifyGetLocalIpAddressTcpV4(); + + // Verify concern: getLocalIpAddress(UDP_V4). + static void verifyGetLocalIpAddressUdpV4(); + + // Verify concern: getLocalIpAddress(TCP_V6). + static void verifyGetLocalIpAddressTcpV6(); + + // Verify concern: getLocalIpAddress(UDP_V6). + static void verifyGetLocalIpAddressUdpV6(); + + private: + // The expected well-known service name. + static const char k_IANA_SERVICE_NAME[8]; + + // The expected well-known service TCP port. + static const ntsa::Port k_IANA_SERVICE_TCP_PORT; + + // The expected well-known service UDP port. + static const ntsa::Port k_IANA_SERVICE_UDP_PORT; +}; + +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetHostname) { - // Concern: 'getHostnameFullyQualified'. - // Plan: + ntsa::Error error; - ntscfg::TestAllocator ta; - { - ntsa::Error error; + bsl::string hostname(NTSCFG_TEST_ALLOCATOR); + error = ntsu::ResolverUtil::getHostname(&hostname); + NTSCFG_TEST_FALSE(error); - bsl::string hostname(&ta); - error = ntsu::ResolverUtil::getHostnameFullyQualified(&hostname); - NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; +} - NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname - << NTSCFG_TEST_LOG_END; - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetHostnameFullyQualified) +{ + ntsa::Error error; + + bsl::string hostname(NTSCFG_TEST_ALLOCATOR); + error = ntsu::ResolverUtil::getHostnameFullyQualified(&hostname); + NTSCFG_TEST_FALSE(error); + + NTSCFG_TEST_LOG_DEBUG << "Hostname: " << hostname << NTSCFG_TEST_LOG_END; } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddress) { // Concern: Test resolution of domain names to IP addresses for use by // an unspecified transport. @@ -92,128 +133,116 @@ NTSCFG_TEST_CASE(3) // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); - ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); + ntsa::Error error; - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); + ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - ipAddressSet.erase(*it); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + ipAddressSet.erase(*it); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressV4) { // Concern: Test resolution of domain names to IPv4 addresses. // // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::set ipAddressSet(&ta); - ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); - ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); + ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V4); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V4); - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); - - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - ipAddressSet.erase(*it); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + ipAddressSet.erase(*it); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressV6) { // Concern: Test resolution of domain names to IPv6 addresses. // // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + ntsa::Error error; - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V6); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: NTSCFG_TEST_FALSE(error); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V6); - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + // TODO: NTSCFG_TEST_FALSE(error); - // TODO: bsl::size_t n = ipAddressSet.erase(*it); - // TODO: NTSCFG_TEST_EQ(n, 1); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + // TODO: bsl::size_t n = ipAddressSet.erase(*it); + // TODO: NTSCFG_TEST_EQ(n, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressTcpV4) { // Concern: Test resolution of domain names to IP addresses for use by // a specific TCP/IPv4-based transport. @@ -221,43 +250,39 @@ NTSCFG_TEST_CASE(6) // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); - ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); + ntsa::Error error; - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); + ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - ipAddressSet.erase(*it); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + ipAddressSet.erase(*it); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressUdpV4) { // Concern: Test resolution of domain names to IP addresses for use by // a specific UDP/IPv4-based transport. @@ -265,43 +290,39 @@ NTSCFG_TEST_CASE(7) // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); - ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); + ntsa::Error error; - NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + ipAddressSet.insert(ntsa::IpAddress("8.8.8.8")); + ipAddressSet.insert(ntsa::IpAddress("8.8.4.4")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + NTSCFG_TEST_FALSE(error); - ipAddressSet.erase(*it); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + ipAddressSet.erase(*it); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(8) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressTcpV6) { // Concern: Test resolution of domain names to IP addresses for use by // a specific TCP/IPv6-based transport. @@ -309,44 +330,40 @@ NTSCFG_TEST_CASE(8) // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + ntsa::Error error; - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: NTSCFG_TEST_FALSE(error); + ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + // TODO: NTSCFG_TEST_FALSE(error); - // TODO: bsl::size_t n = ipAddressSet.erase(*it); - // TODO: NTSCFG_TEST_EQ(n, 1); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + // TODO: bsl::size_t n = ipAddressSet.erase(*it); + // TODO: NTSCFG_TEST_EQ(n, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(9) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetIpAddressUdpV6) { // Concern: Test resolution of domain names to IP addresses for use by // a specific UDP/IPv6-based transport. @@ -354,72 +371,64 @@ NTSCFG_TEST_CASE(9) // Plan: Ensure 'dns.google.com' resolves to at least two of the known // IP addresses at which it has been assigned, as of 2020. - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + ntsa::Error error; - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: NTSCFG_TEST_FALSE(error); + ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() - << NTSCFG_TEST_LOG_END; + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + // TODO: NTSCFG_TEST_FALSE(error); - // TODO: bsl::size_t n = ipAddressSet.erase(*it); - // TODO: NTSCFG_TEST_EQ(n, 1); - } + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << it->text() + << NTSCFG_TEST_LOG_END; - NTSCFG_TEST_TRUE(ipAddressSet.empty()); + // TODO: bsl::size_t n = ipAddressSet.erase(*it); + // TODO: NTSCFG_TEST_EQ(n, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_TRUE(ipAddressSet.empty()); } -NTSCFG_TEST_CASE(10) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetDomainName) { // Concern: Test resolution of IP addresses to domain names. // Plan: Resolve the well-known IP address of Google's public DNS server // to "dns.google". - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::string domainName(&ta); - error = ntsu::ResolverUtil::getDomainName(&domainName, - ntsa::IpAddress("8.8.8.8")); + bsl::string domainName(NTSCFG_TEST_ALLOCATOR); + error = ntsu::ResolverUtil::getDomainName(&domainName, + ntsa::IpAddress("8.8.8.8")); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName - << NTSCFG_TEST_LOG_END; - } - - NTSCFG_TEST_FALSE(error); - NTSCFG_TEST_EQ(domainName, "dns.google"); + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + else { + NTSCFG_TEST_LOG_DEBUG << "Domain name: " << domainName + << NTSCFG_TEST_LOG_END; + } + + NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_EQ(domainName, "dns.google"); } -NTSCFG_TEST_CASE(11) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetPort) { // Concern: Test resolution of service names to port numbers for use by // an unspecified transport. @@ -428,50 +437,45 @@ NTSCFG_TEST_CASE(11) return; } - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector portList(&ta); - ntsa::PortOptions portOptions; + bsl::vector portList(NTSCFG_TEST_ALLOCATOR); + ntsa::PortOptions portOptions; - error = ntsu::ResolverUtil::getPort(&portList, - test::IANA_SERVICE_NAME, - portOptions); + error = ntsu::ResolverUtil::getPort(&portList, + k_IANA_SERVICE_NAME, + portOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = portList.begin(); - it != portList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Port: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = portList.begin(); + it != portList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Port: " << *it << NTSCFG_TEST_LOG_END; } + } - NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_FALSE(error); - { - bsl::size_t count = bsl::count(portList.begin(), - portList.end(), - test::IANA_SERVICE_TCP_PORT); - NTSCFG_TEST_GE(count, 1); - } + { + bsl::size_t count = bsl::count(portList.begin(), + portList.end(), + k_IANA_SERVICE_TCP_PORT); + NTSCFG_TEST_GE(count, 1); + } - { - bsl::size_t count = bsl::count(portList.begin(), - portList.end(), - test::IANA_SERVICE_UDP_PORT); - NTSCFG_TEST_GE(count, 1); - } + { + bsl::size_t count = bsl::count(portList.begin(), + portList.end(), + k_IANA_SERVICE_UDP_PORT); + NTSCFG_TEST_GE(count, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(12) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetPortTcp) { // Concern: Test resolution of service names to port numbers for use by // a specific TCP-based transport. @@ -480,43 +484,37 @@ NTSCFG_TEST_CASE(12) return; } - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector portList(&ta); - ntsa::PortOptions portOptions; + bsl::vector portList(NTSCFG_TEST_ALLOCATOR); + ntsa::PortOptions portOptions; - portOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + portOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - error = ntsu::ResolverUtil::getPort(&portList, - test::IANA_SERVICE_NAME, - portOptions); + error = ntsu::ResolverUtil::getPort(&portList, + k_IANA_SERVICE_NAME, + portOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = portList.begin(); - it != portList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Port: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = portList.begin(); + it != portList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Port: " << *it << NTSCFG_TEST_LOG_END; } + } - NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_FALSE(error); - bsl::size_t count = bsl::count(portList.begin(), - portList.end(), - test::IANA_SERVICE_TCP_PORT); - NTSCFG_TEST_GE(count, 1); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + bsl::size_t count = + bsl::count(portList.begin(), portList.end(), k_IANA_SERVICE_TCP_PORT); + NTSCFG_TEST_GE(count, 1); } -NTSCFG_TEST_CASE(13) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetPortUdp) { // Concern: Test resolution of service names to port numbers for use by // a specific UDP-based transport. @@ -525,42 +523,36 @@ NTSCFG_TEST_CASE(13) return; } - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector portList(&ta); - ntsa::PortOptions portOptions; + bsl::vector portList(NTSCFG_TEST_ALLOCATOR); + ntsa::PortOptions portOptions; - portOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + portOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - error = ntsu::ResolverUtil::getPort(&portList, - test::IANA_SERVICE_NAME, - portOptions); + error = ntsu::ResolverUtil::getPort(&portList, + k_IANA_SERVICE_NAME, + portOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = portList.begin(); - it != portList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Port: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = portList.begin(); + it != portList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Port: " << *it << NTSCFG_TEST_LOG_END; } - - NTSCFG_TEST_FALSE(error); - bsl::size_t count = bsl::count(portList.begin(), - portList.end(), - test::IANA_SERVICE_UDP_PORT); - NTSCFG_TEST_GE(count, 1); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + NTSCFG_TEST_FALSE(error); + bsl::size_t count = + bsl::count(portList.begin(), portList.end(), k_IANA_SERVICE_UDP_PORT); + NTSCFG_TEST_GE(count, 1); } -NTSCFG_TEST_CASE(14) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetServiceName) { // Concern: Test resolution of port numbers to service names. // Plan: @@ -569,285 +561,227 @@ NTSCFG_TEST_CASE(14) return; } - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::string serviceName(&ta); - error = ntsu::ResolverUtil::getServiceName( - &serviceName, - test::IANA_SERVICE_TCP_PORT, - ntsa::Transport::e_TCP_IPV4_STREAM); - - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - NTSCFG_TEST_LOG_DEBUG << "Service name: " << serviceName - << NTSCFG_TEST_LOG_END; - } + bsl::string serviceName(NTSCFG_TEST_ALLOCATOR); + error = + ntsu::ResolverUtil::getServiceName(&serviceName, + k_IANA_SERVICE_TCP_PORT, + ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_FALSE(error); - NTSCFG_TEST_EQ(serviceName, test::IANA_SERVICE_NAME); + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + else { + NTSCFG_TEST_LOG_DEBUG << "Service name: " << serviceName + << NTSCFG_TEST_LOG_END; + } + + NTSCFG_TEST_FALSE(error); + NTSCFG_TEST_EQ(serviceName, k_IANA_SERVICE_NAME); } -NTSCFG_TEST_CASE(15) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddress) { // Concern: Test getting the IP addresses assigned to the local machine. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressV4) { // Concern: Test getting the IPv4 addresses assigned to the local machine. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V4); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V4); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(17) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressV6) { // Concern: Test getting the IPv6 addresses assigned to the local machine. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V6); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V6); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(18) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressTcpV4) { // Concern: Test getting the IP addresses assigned to the local machine // for use by a TCP/IPv4 transport. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(19) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressUdpV4) { // Concern: Test getting the IP addresses assigned to the local machine // for use by a UDP/IPv4 transport. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_ERROR << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(20) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressTcpV6) { // Concern: Test getting the IP addresses assigned to the local machine // for use by a TCP/IPv6 transport. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); + ipAddressOptions.setTransport(ntsa::Transport::e_TCP_IPV6_STREAM); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(21) +NTSCFG_TEST_FUNCTION(ntsu::ResolverUtilTest::verifyGetLocalIpAddressUdpV6) { // Concern: Test getting the IP addresses assigned to the local machine // for use by a UDP/IPv6 transport. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - bsl::vector ipAddressList(&ta); - ntsa::IpAddressOptions ipAddressOptions; + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); + ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV6_DATAGRAM); - error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, - ipAddressOptions); + error = ntsu::ResolverUtil::getLocalIpAddress(&ipAddressList, + ipAddressOptions); - if (error) { - NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; - } - else { - for (bsl::vector::const_iterator it = - ipAddressList.begin(); - it != ipAddressList.end(); - ++it) - { - NTSCFG_TEST_LOG_DEBUG << "Address: " << *it - << NTSCFG_TEST_LOG_END; - } + if (error) { + NTSCFG_TEST_LOG_DEBUG << "Error: " << error << NTSCFG_TEST_LOG_END; + } + else { + for (bsl::vector::const_iterator it = + ipAddressList.begin(); + it != ipAddressList.end(); + ++it) + { + NTSCFG_TEST_LOG_DEBUG << "Address: " << *it << NTSCFG_TEST_LOG_END; } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); // getHostname - NTSCFG_TEST_REGISTER(2); // getHostnameFullyQualified - NTSCFG_TEST_REGISTER(3); // getIpAddress - NTSCFG_TEST_REGISTER(4); // getIpAddress(V4) - NTSCFG_TEST_REGISTER(5); // getIpAddress(V6) - NTSCFG_TEST_REGISTER(6); // getIpAddress(TCP_V4) - NTSCFG_TEST_REGISTER(7); // getIpAddress(UDP_V4) - NTSCFG_TEST_REGISTER(8); // getIpAddress(TCP_V6) - NTSCFG_TEST_REGISTER(9); // getIpAddress(UDP_V6) - NTSCFG_TEST_REGISTER(10); // getDomainName - NTSCFG_TEST_REGISTER(11); // getPort - NTSCFG_TEST_REGISTER(12); // getPort(TCP) - NTSCFG_TEST_REGISTER(13); // getPort(UDP) - NTSCFG_TEST_REGISTER(14); // getServiceName - NTSCFG_TEST_REGISTER(15); // getLocalIpAddress - NTSCFG_TEST_REGISTER(16); // getLocalIpAddress(V4) - NTSCFG_TEST_REGISTER(17); // getLocalIpAddress(V6) - NTSCFG_TEST_REGISTER(18); // getLocalIpAddress(TCP_V4) - NTSCFG_TEST_REGISTER(19); // getLocalIpAddress(UDP_V4) - NTSCFG_TEST_REGISTER(20); // getLocalIpAddress(TCP_V6) - NTSCFG_TEST_REGISTER(21); // getLocalIpAddress(UDP_V6) -} -NTSCFG_TEST_DRIVER_END; +const char ResolverUtilTest::k_IANA_SERVICE_NAME[8] = "discard"; +const ntsa::Port ResolverUtilTest::k_IANA_SERVICE_TCP_PORT = 9; +const ntsa::Port ResolverUtilTest::k_IANA_SERVICE_UDP_PORT = 9; + +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/groups/nts/ntsu/ntsu_socketoptionutil.cpp b/groups/nts/ntsu/ntsu_socketoptionutil.cpp index 46e25908..c407aa47 100644 --- a/groups/nts/ntsu/ntsu_socketoptionutil.cpp +++ b/groups/nts/ntsu/ntsu_socketoptionutil.cpp @@ -102,10 +102,9 @@ struct SocketStorageUtil { const ntsa::IpAddress& ipAddress); }; -ntsa::Error SocketStorageUtil::convert( - sockaddr_storage* socketAddress, - socklen_t* socketAddressSize, - const ntsa::IpAddress& ipAddress) +ntsa::Error SocketStorageUtil::convert(sockaddr_storage* socketAddress, + socklen_t* socketAddressSize, + const ntsa::IpAddress& ipAddress) { bsl::memset(socketAddress, 0, sizeof(sockaddr_storage)); *socketAddressSize = 0; @@ -119,9 +118,8 @@ ntsa::Error SocketStorageUtil::convert( socketAddressIpv4->sin_family = AF_INET; socketAddressIpv4->sin_port = 0; - ipAddress.v4().copyTo( - &socketAddressIpv4->sin_addr, - sizeof socketAddressIpv4->sin_addr); + ipAddress.v4().copyTo(&socketAddressIpv4->sin_addr, + sizeof socketAddressIpv4->sin_addr); } else if (ipAddress.isV6()) { sockaddr_in6* socketAddressIpv6 = @@ -132,12 +130,10 @@ ntsa::Error SocketStorageUtil::convert( socketAddressIpv6->sin6_family = AF_INET6; socketAddressIpv6->sin6_port = 0; - ipAddress.v6().copyTo( - &socketAddressIpv6->sin6_addr, - sizeof socketAddressIpv6->sin6_addr); + ipAddress.v6().copyTo(&socketAddressIpv6->sin6_addr, + sizeof socketAddressIpv6->sin6_addr); - socketAddressIpv6->sin6_scope_id = - ipAddress.v6().scopeId(); + socketAddressIpv6->sin6_scope_id = ipAddress.v6().scopeId(); } else { return ntsa::Error(ntsa::Error::e_INVALID); @@ -146,7 +142,7 @@ ntsa::Error SocketStorageUtil::convert( return ntsa::Error(); } -} // close unnamed namespace +} // close unnamed namespace ntsa::Error SocketOptionUtil::setOption(ntsa::Handle socket, const ntsa::SocketOption& option) @@ -1808,10 +1804,10 @@ ntsa::Error SocketOptionUtil::leaveMulticastGroup( } ntsa::Error SocketOptionUtil::joinMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { #if defined(BSLS_PLATFORM_OS_LINUX) || defined(BSLS_PLATFORM_OS_DARWIN) @@ -1830,13 +1826,13 @@ ntsa::Error SocketOptionUtil::joinMulticastGroupSource( return ntsa::Error(errno); } - if (socketAddress.ss_family != AF_INET && - socketAddress.ss_family != AF_INET6) + if (socketAddress.ss_family != AF_INET && + socketAddress.ss_family != AF_INET6) { return ntsa::Error(ntsa::Error::e_INVALID); } - const bsl::uint32_t interfaceIndex = + const bsl::uint32_t interfaceIndex = ntsu::AdapterUtil::discoverInterfaceIndex(interface); if (interfaceIndex == 0) { @@ -1848,15 +1844,16 @@ ntsa::Error SocketOptionUtil::joinMulticastGroupSource( req.gsr_interface = interfaceIndex; socklen_t groupAddressSize = 0; - error = SocketStorageUtil::convert( - &req.gsr_group, &groupAddressSize, group); + error = + SocketStorageUtil::convert(&req.gsr_group, &groupAddressSize, group); if (error) { return error; } socklen_t sourceAddressSize = 0; - error = SocketStorageUtil::convert( - &req.gsr_source, &sourceAddressSize, source); + error = SocketStorageUtil::convert(&req.gsr_source, + &sourceAddressSize, + source); if (error) { return error; } @@ -1900,7 +1897,7 @@ ntsa::Error SocketOptionUtil::joinMulticastGroupSource( sizeof mreq.imr_sourceaddr.s_addr); errno = 0; - rc = ::setsockopt(socket, + rc = ::setsockopt(socket, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, reinterpret_cast(&mreq), @@ -1927,10 +1924,10 @@ ntsa::Error SocketOptionUtil::joinMulticastGroupSource( } ntsa::Error SocketOptionUtil::leaveMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { #if defined(BSLS_PLATFORM_OS_LINUX) || defined(BSLS_PLATFORM_OS_DARWIN) @@ -1949,13 +1946,13 @@ ntsa::Error SocketOptionUtil::leaveMulticastGroupSource( return ntsa::Error(errno); } - if (socketAddress.ss_family != AF_INET && - socketAddress.ss_family != AF_INET6) + if (socketAddress.ss_family != AF_INET && + socketAddress.ss_family != AF_INET6) { return ntsa::Error(ntsa::Error::e_INVALID); } - const bsl::uint32_t interfaceIndex = + const bsl::uint32_t interfaceIndex = ntsu::AdapterUtil::discoverInterfaceIndex(interface); if (interfaceIndex == 0) { @@ -1967,15 +1964,16 @@ ntsa::Error SocketOptionUtil::leaveMulticastGroupSource( req.gsr_interface = interfaceIndex; socklen_t groupAddressSize = 0; - error = SocketStorageUtil::convert( - &req.gsr_group, &groupAddressSize, group); + error = + SocketStorageUtil::convert(&req.gsr_group, &groupAddressSize, group); if (error) { return error; } socklen_t sourceAddressSize = 0; - error = SocketStorageUtil::convert( - &req.gsr_source, &sourceAddressSize, source); + error = SocketStorageUtil::convert(&req.gsr_source, + &sourceAddressSize, + source); if (error) { return error; } @@ -3307,10 +3305,10 @@ ntsa::Error SocketOptionUtil::leaveMulticastGroup( } ntsa::Error SocketOptionUtil::joinMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { NTSCFG_WARNING_UNUSED(socket); NTSCFG_WARNING_UNUSED(interface); @@ -3321,10 +3319,10 @@ ntsa::Error SocketOptionUtil::joinMulticastGroupSource( } ntsa::Error SocketOptionUtil::leaveMulticastGroupSource( - ntsa::Handle socket, - const ntsa::IpAddress& interface, - const ntsa::IpAddress& group, - const ntsa::IpAddress& source) + ntsa::Handle socket, + const ntsa::IpAddress& interface, + const ntsa::IpAddress& group, + const ntsa::IpAddress& source) { NTSCFG_WARNING_UNUSED(socket); NTSCFG_WARNING_UNUSED(interface); diff --git a/groups/nts/ntsu/ntsu_socketoptionutil.h b/groups/nts/ntsu/ntsu_socketoptionutil.h index d821592f..d3a1389d 100644 --- a/groups/nts/ntsu/ntsu_socketoptionutil.h +++ b/groups/nts/ntsu/ntsu_socketoptionutil.h @@ -323,7 +323,7 @@ struct SocketOptionUtil { ntsa::Handle socket, const ntsa::IpAddress& interface, const ntsa::IpAddress& group, - const ntsa::IpAddress& source); + const ntsa::IpAddress& source); /// Load into the specified 'result' the flag that indicates if the /// socket type is a stream socket. Return the error. diff --git a/groups/nts/ntsu/ntsu_socketoptionutil.t.cpp b/groups/nts/ntsu/ntsu_socketoptionutil.t.cpp index 7ed7eb87..77a5dd10 100644 --- a/groups/nts/ntsu/ntsu_socketoptionutil.t.cpp +++ b/groups/nts/ntsu/ntsu_socketoptionutil.t.cpp @@ -13,17 +13,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include + +#include +BSLS_IDENT_RCSID(ntsu_socketoptionutil_t_cpp, "$Id$ $CSID$") + #include + +#include +#include #include #include -#include -#include -#include -#include -#include #if defined(BSLS_PLATFORM_OS_LINUX) #include @@ -38,24 +38,46 @@ using namespace BloombergLP; -// Undefine to test all socket types. -// #define NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE -// ntsa::Transport::e_TCP_IPV4_STREAM +namespace BloombergLP { +namespace ntsu { -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +// Provide tests for 'ntsu::SocketOptionUtil'. +class SocketOptionUtilTest +{ + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase3(); -NTSCFG_TEST_CASE(1) + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); + + // TODO + static void verifyCase6(); + + // TODO + static void verifyCase7(); + + // TODO + static void verifyCase8(); + + // TODO + static void verifyCase9(); +}; + +// Undefine to test all socket types. +// #define NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE +// ntsa::Transport::e_TCP_IPV4_STREAM + +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase1) { // Concern: Socket options on TCP/IPv4 sockets, using the raw API. // Plan: @@ -79,8 +101,8 @@ NTSCFG_TEST_CASE(1) { ntsa::Transport::Value transport = SOCKET_TYPES[socketTypeIndex]; -#if defined(NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) - if (transport != NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) { +#if defined(NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) + if (transport != NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) { continue; } #endif @@ -582,7 +604,7 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase2) { // Concern: Socket options on TCP/IPv4 sockets, using the union API. // Plan: @@ -606,8 +628,8 @@ NTSCFG_TEST_CASE(2) { ntsa::Transport::Value transport = SOCKET_TYPES[socketTypeIndex]; -#if defined(NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) - if (transport != NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) { +#if defined(NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) + if (transport != NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) { continue; } #endif @@ -1176,7 +1198,7 @@ NTSCFG_TEST_CASE(2) } } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase3) { // Concern: Multicast options // Plan: @@ -1205,8 +1227,8 @@ NTSCFG_TEST_CASE(3) { ntsa::Transport::Value transport = SOCKET_TYPES[socketTypeIndex]; -#if defined(NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) - if (transport != NTSU_SOCKETOPTUTIL_TEST_SOCKET_TYPE) { +#if defined(NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) + if (transport != NTSU_SOCKETOPTIONUTIL_TEST_SOCKET_TYPE) { continue; } #endif @@ -1470,7 +1492,7 @@ NTSCFG_TEST_CASE(3) } } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase4) { // Concern: Default Socket options on TCP/IPv4 sockets. // Plan: @@ -1497,7 +1519,7 @@ NTSCFG_TEST_CASE(4) ntsu::SocketUtil::close(socket); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase5) { // Concern: Timestamping support and platform assumptions. @@ -1826,7 +1848,7 @@ NTSCFG_TEST_CASE(5) } } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase6) { // Concern: Zero-copy support and platform assumptions. @@ -1922,7 +1944,7 @@ NTSCFG_TEST_CASE(6) } } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase7) { // Concern: test isLocal @@ -1987,7 +2009,7 @@ NTSCFG_TEST_CASE(7) } } -NTSCFG_TEST_CASE(8) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase8) { // Concern: test setBlocking/getBlocking @@ -2088,7 +2110,7 @@ NTSCFG_TEST_CASE(8) } } -NTSCFG_TEST_CASE(9) +NTSCFG_TEST_FUNCTION(ntsu::SocketOptionUtilTest::verifyCase9) { // Concern: getTcpCongestionControl and setTcpCongestionControl @@ -2187,16 +2209,5 @@ NTSCFG_TEST_CASE(9) NTSCFG_TEST_EQ(ta.numBlocksInUse(), 0); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); - NTSCFG_TEST_REGISTER(8); - NTSCFG_TEST_REGISTER(9); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/groups/nts/ntsu/ntsu_socketutil.cpp b/groups/nts/ntsu/ntsu_socketutil.cpp index 8ad0daa1..a504effe 100644 --- a/groups/nts/ntsu/ntsu_socketutil.cpp +++ b/groups/nts/ntsu/ntsu_socketutil.cpp @@ -5391,7 +5391,7 @@ ntsa::Error SocketUtil::bind(const ntsa::Endpoint& endpoint, ntsa::Error error; #if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL - const bool isLocal = endpoint.isLocal(); + const bool isLocal = endpoint.isLocal(); #else const bool isLocal = false; #endif diff --git a/groups/nts/ntsu/ntsu_socketutil.t.cpp b/groups/nts/ntsu/ntsu_socketutil.t.cpp index eaf5b9f8..54cc24c1 100644 --- a/groups/nts/ntsu/ntsu_socketutil.t.cpp +++ b/groups/nts/ntsu/ntsu_socketutil.t.cpp @@ -14,24 +14,16 @@ // limitations under the License. #include + +#include +BSLS_IDENT_RCSID(ntsu_socketutil_t_cpp, "$Id$ $CSID$") + +#include + #include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #if defined(BSLS_PLATFORM_OS_WINDOWS) #define WIN32_LEAN_AND_MEAN @@ -39,34 +31,350 @@ #endif #if defined(BSLS_PLATFORM_OS_LINUX) -#include - #include #include +#include #include #include #endif using namespace BloombergLP; -//============================================================================= -// TEST PLAN -//----------------------------------------------------------------------------- -// Overview -// -------- -// -//----------------------------------------------------------------------------- +namespace BloombergLP { +namespace ntsu { + +// Provide tests for 'ntsu::SocketUtil'. +class SocketUtilTest +{ + /// This typedef defines a callback function invoked to test a particular + /// portion of the component using the specified connected 'server' and + /// 'client' having the specified stream socket 'transport', supplying + /// memory using the specified 'allocator'. + typedef bsl::function + StreamSocketTestCallback; + + /// This typedef defines a callback function invoked to test a particular + /// portion of the component using using the specified 'server' bound to the + /// specified 'serverEndpoint' and 'client' bound to the specified + /// 'clientEndpoint', each 'client' and 'server' socket having the + /// specified 'transport', supplying + /// memory using the specified 'allocator'. + typedef bsl::function + DatagramSocketTestCallback; + + // Provide a in-core storage of bytes. + template + class Storage; + +#if defined(BSLS_PLATFORM_OS_LINUX) + + // Return the native flags indicating timestamping support for the + // specified 'socket'. + static bsl::uint32_t timestampingSupport(ntsa::Handle socket); + +#endif + + // Return true if the specified 'socket' supports RX timestamps. + static bool supportsRxTimestamps(ntsa::Handle socket); + + // Return true if the specified 'socket' supports TX timestamps. + static bool supportsTxTimestamps(ntsa::Handle socket); + + // Load into the specified 'result' the zero-copy notifications for the + // specified 'handle'. + static void extractZeroCopyNotifications(bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator); + + // Load into the specified 'result' the timestamp notifications for the + // specified 'handle'. + static void extractTimestampNotifications( + bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator); + + // Load into the specified 'result' the notifications for the specified + // 'handle'. + static void extractNotifications(bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator); + + // Execute the specified 'test'. + static void executeStreamSocketTest(const StreamSocketTestCallback& test, + bslma::Allocator* basicAllocator = 0); + + // Execute the specified 'test'. + static void executeDatagramSocketTest( + const DatagramSocketTestCallback& test, + bslma::Allocator* basicAllocator = 0); + + static void testStreamSocketTransmissionSingleBuffer( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionSingleBufferWithControlMsg( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionMultipleBuffers( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionBlob( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionBlobWithControlMsg( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionWithControlMsgDropped( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketTransmissionFile( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionSingleBuffer( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionSingleBufferWithControlMsg( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionMultipleBuffers( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionBlob( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionBlobWithControlMsg( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionWithControlMsgDropped( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionSingleMessage( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testDatagramSocketTransmissionMultipleMessages( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testDatagramSocketTxTimestamps( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testDatagramSocketTxTimestampsAndZeroCopy( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + static void testStreamSocketTxTimestampsAndZeroCopy( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testStreamSocketReceiveNotifications( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator); + + static void testDatagramSocketReceiveNotifications( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator); + + public: + // TODO + static void verifyCase1(); + + // TODO + static void verifyCase2(); + + // TODO + static void verifyCase3(); + + // TODO + static void verifyCase4(); + + // TODO + static void verifyCase5(); + + // TODO + static void verifyCase6(); + + // TODO + static void verifyCase7(); + + // TODO + static void verifyCase8(); + + // TODO + static void verifyCase9(); + + // TODO + static void verifyCase10(); + + // TODO + static void verifyCase11(); + + // TODO + static void verifyCase12(); + + // TODO + static void verifyCase13(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase14(); -namespace test { + // TODO + static void verifyCase15(); + + // TODO + static void verifyCase16(); + + // TODO + static void verifyCase17(); + + // TODO + static void verifyCase18(); + + // TODO + static void verifyCase19(); + + // TODO + static void verifyCase20(); + + // TODO + static void verifyCase21(); + + // TODO + static void verifyCase22(); + + // TODO + static void verifyCase23(); + + // TODO + static void verifyCase24(); + + // TODO + static void verifyCase25(); + + // TODO + static void verifyCase26(); + + // TODO + static void verifyCase27(); + + // TODO + static void verifyCase28(); + + // TODO + static void verifyCase29(); + + // TODO + static void verifyCase30(); + + // TODO + static void verifyCase31(); + + // TODO + static void verifyCase32(); + + // TODO + static void verifyCase33(); + + // TODO + static void verifyCase34(); +}; /// Provide a in-core storage of bytes. template -class Storage +class SocketUtilTest::Storage { char d_buffer[N]; @@ -84,7 +392,7 @@ class Storage #if defined(BSLS_PLATFORM_OS_LINUX) -bsl::uint32_t timestampingSupport(ntsa::Handle socket) +bsl::uint32_t SocketUtilTest::timestampingSupport(ntsa::Handle socket) { ntsa::Error error; int rc; @@ -111,13 +419,13 @@ bsl::uint32_t timestampingSupport(ntsa::Handle socket) return static_cast(info.so_timestamping); } -bool supportsRxTimestamps(ntsa::Handle socket) +bool SocketUtilTest::supportsRxTimestamps(ntsa::Handle socket) { const bsl::uint32_t flags = timestampingSupport(socket); return (flags & ntsu::TimestampUtil::e_SOF_TIMESTAMPING_RX_SOFTWARE) != 0; } -bool supportsTxTimestamps(ntsa::Handle socket) +bool SocketUtilTest::supportsTxTimestamps(ntsa::Handle socket) { const bsl::uint32_t flags = timestampingSupport(socket); return (flags & ntsu::TimestampUtil::e_SOF_TIMESTAMPING_TX_SOFTWARE) != 0; @@ -125,13 +433,13 @@ bool supportsTxTimestamps(ntsa::Handle socket) #else -bool supportsRxTimestamps(ntsa::Handle socket) +bool SocketUtilTest::supportsRxTimestamps(ntsa::Handle socket) { NTSCFG_WARNING_UNUSED(socket); return false; } -bool supportsTxTimestamps(ntsa::Handle socket) +bool SocketUtilTest::supportsTxTimestamps(ntsa::Handle socket) { NTSCFG_WARNING_UNUSED(socket); return false; @@ -139,9 +447,10 @@ bool supportsTxTimestamps(ntsa::Handle socket) #endif -void extractZeroCopyNotifications(bsl::list* zerocopy, - ntsa::Handle handle, - bslma::Allocator* allocator) +void SocketUtilTest::extractZeroCopyNotifications( + bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator) { ntsa::NotificationQueue notifications(allocator); notifications.setHandle(handle); @@ -158,13 +467,14 @@ void extractZeroCopyNotifications(bsl::list* zerocopy, ++it) { NTSCFG_TEST_TRUE(it->isZeroCopy()); - zerocopy->push_back(it->zeroCopy()); + result->push_back(it->zeroCopy()); } } -void extractTimestampNotifications(bsl::list* ts, - ntsa::Handle handle, - bslma::Allocator* allocator) +void SocketUtilTest::extractTimestampNotifications( + bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator) { ntsa::NotificationQueue notifications(allocator); notifications.setHandle(handle); @@ -181,13 +491,14 @@ void extractTimestampNotifications(bsl::list* ts, ++it) { NTSCFG_TEST_TRUE(it->isTimestamp()); - ts->push_back(it->timestamp()); + result->push_back(it->timestamp()); } } -void extractNotifications(bsl::list* nt, - ntsa::Handle handle, - bslma::Allocator* allocator) +void SocketUtilTest::extractNotifications( + bsl::list* result, + ntsa::Handle handle, + bslma::Allocator* allocator) { ntsa::NotificationQueue notifications(allocator); notifications.setHandle(handle); @@ -203,36 +514,13 @@ void extractNotifications(bsl::list* nt, it != notifications.notifications().cend(); ++it) { - nt->push_back(*it); + result->push_back(*it); } } -/// This typedef defines a callback function invoked to test a particular -/// portion of the component using the specified connected 'server' and -/// 'client' having the specified stream socket 'transport', supplying -/// memory using the specified 'allocator'. -typedef bsl::function - StreamSocketTestCallback; - -/// This typedef defines a callback function invoked to test a particular -/// portion of the component using using the specified 'server' bound to the -/// specified 'serverEndpoint' and 'client' bound to the specified -/// 'clientEndpoint', each 'client' and 'server' socket having the -/// specified 'transport', supplying -/// memory using the specified 'allocator'. -typedef bsl::function - DatagramSocketTestCallback; - -void executeStreamSocketTest(const StreamSocketTestCallback& test, - bslma::Allocator* basicAllocator = 0) +void SocketUtilTest::executeStreamSocketTest( + const StreamSocketTestCallback& test, + bslma::Allocator* basicAllocator) { // Execute the specified stream socket 'test'. @@ -386,8 +674,9 @@ void executeStreamSocketTest(const StreamSocketTestCallback& test, } } -void executeDatagramSocketTest(const DatagramSocketTestCallback& test, - bslma::Allocator* basicAllocator = 0) +void SocketUtilTest::executeDatagramSocketTest( + const DatagramSocketTestCallback& test, + bslma::Allocator* basicAllocator) { // Execute the specified datagram socket 'test'. @@ -515,10 +804,11 @@ void executeDatagramSocketTest(const DatagramSocketTestCallback& test, } } -void testStreamSocketTransmissionSingleBuffer(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketTransmissionSingleBuffer( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { NTSCFG_TEST_LOG_DEBUG << "Testing " << transport << ": send/recv" << NTSCFG_TEST_LOG_END; @@ -567,7 +857,7 @@ void testStreamSocketTransmissionSingleBuffer(ntsa::Transport::Value transport, } } -void testStreamSocketTransmissionSingleBufferWithControlMsg( +void SocketUtilTest::testStreamSocketTransmissionSingleBufferWithControlMsg( ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, @@ -659,7 +949,7 @@ void testStreamSocketTransmissionSingleBufferWithControlMsg( } } -void testStreamSocketTransmissionMultipleBuffers( +void SocketUtilTest::testStreamSocketTransmissionMultipleBuffers( ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, @@ -735,10 +1025,11 @@ void testStreamSocketTransmissionMultipleBuffers( } } -void testStreamSocketTransmissionBlob(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketTransmissionBlob( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { NTSCFG_TEST_LOG_DEBUG << "Testing " << transport << ": writev/readv (blob)" << NTSCFG_TEST_LOG_END; @@ -788,7 +1079,7 @@ void testStreamSocketTransmissionBlob(ntsa::Transport::Value transport, } } -void testStreamSocketTransmissionBlobWithControlMsg( +void SocketUtilTest::testStreamSocketTransmissionBlobWithControlMsg( ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, @@ -882,7 +1173,7 @@ void testStreamSocketTransmissionBlobWithControlMsg( } } -void testStreamSocketTransmissionWithControlMsgDropped( +void SocketUtilTest::testStreamSocketTransmissionWithControlMsgDropped( ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, @@ -987,10 +1278,11 @@ void testStreamSocketTransmissionWithControlMsgDropped( } } -void testStreamSocketTransmissionFile(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketTransmissionFile( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { // This test succeeds when run locally but fails when run on build machines // during continuous integration, probably because the temporary files @@ -1138,7 +1430,7 @@ void testStreamSocketTransmissionFile(ntsa::Transport::Value transport, #endif } -void testDatagramSocketTransmissionSingleBuffer( +void SocketUtilTest::testDatagramSocketTransmissionSingleBuffer( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1198,7 +1490,7 @@ void testDatagramSocketTransmissionSingleBuffer( } } -void testDatagramSocketTransmissionSingleBufferWithControlMsg( +void SocketUtilTest::testDatagramSocketTransmissionSingleBufferWithControlMsg( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1296,7 +1588,7 @@ void testDatagramSocketTransmissionSingleBufferWithControlMsg( } } -void testDatagramSocketTransmissionMultipleBuffers( +void SocketUtilTest::testDatagramSocketTransmissionMultipleBuffers( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1380,12 +1672,13 @@ void testDatagramSocketTransmissionMultipleBuffers( } } -void testDatagramSocketTransmissionBlob(ntsa::Transport::Value transport, - ntsa::Handle server, - const ntsa::Endpoint& serverEndpoint, - ntsa::Handle client, - const ntsa::Endpoint& clientEndpoint, - bslma::Allocator* allocator) +void SocketUtilTest::testDatagramSocketTransmissionBlob( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator) { NTSCFG_TEST_LOG_DEBUG << "Testing " << transport << ": sendmsg/recvmsg (blob)" << NTSCFG_TEST_LOG_END; @@ -1440,7 +1733,7 @@ void testDatagramSocketTransmissionBlob(ntsa::Transport::Value transport, } } -void testDatagramSocketTransmissionBlobWithControlMsg( +void SocketUtilTest::testDatagramSocketTransmissionBlobWithControlMsg( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1540,7 +1833,7 @@ void testDatagramSocketTransmissionBlobWithControlMsg( } } -void testDatagramSocketTransmissionWithControlMsgDropped( +void SocketUtilTest::testDatagramSocketTransmissionWithControlMsgDropped( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1652,7 +1945,7 @@ void testDatagramSocketTransmissionWithControlMsgDropped( } } -void testDatagramSocketTransmissionSingleMessage( +void SocketUtilTest::testDatagramSocketTransmissionSingleMessage( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1742,7 +2035,7 @@ void testDatagramSocketTransmissionSingleMessage( #endif } -void testDatagramSocketTransmissionMultipleMessages( +void SocketUtilTest::testDatagramSocketTransmissionMultipleMessages( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1759,7 +2052,7 @@ void testDatagramSocketTransmissionMultipleMessages( char DATA[] = "123456789"; - typedef test::Storage StorageBuffer; + typedef SocketUtilTest::Storage StorageBuffer; StorageBuffer clientBuffer0[NUM_MESSAGES]; StorageBuffer clientBuffer1[NUM_MESSAGES]; @@ -1903,10 +2196,11 @@ void testDatagramSocketTransmissionMultipleMessages( } } -void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketMsgZeroCopy( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { if (transport == ntsa::Transport::e_LOCAL_STREAM) { return; @@ -1953,7 +2247,9 @@ void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); - test::extractZeroCopyNotifications(&feedback, client, allocator); + SocketUtilTest::extractZeroCopyNotifications(&feedback, + client, + allocator); } // receive data @@ -1977,7 +2273,9 @@ void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, // retrieve data from the socket error queue until all send system // calls are acknowledged by the OS while (!sendIDs.empty()) { - test::extractZeroCopyNotifications(&feedback, client, allocator); + SocketUtilTest::extractZeroCopyNotifications(&feedback, + client, + allocator); while (!feedback.empty()) { const ntsa::ZeroCopy& zc = feedback.front(); @@ -1997,12 +2295,13 @@ void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, } } -void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, - ntsa::Handle server, - const ntsa::Endpoint& serverEndpoint, - ntsa::Handle client, - const ntsa::Endpoint& clientEndpoint, - bslma::Allocator* allocator) +void SocketUtilTest::testDatagramSocketTxTimestamps( + ntsa::Transport::Value transport, + ntsa::Handle server, + const ntsa::Endpoint& serverEndpoint, + ntsa::Handle client, + const ntsa::Endpoint& clientEndpoint, + bslma::Allocator* allocator) { if (transport == ntsa::Transport::e_LOCAL_DATAGRAM) { return; @@ -2064,7 +2363,9 @@ void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); - test::extractTimestampNotifications(&feedback, client, allocator); + SocketUtilTest::extractTimestampNotifications(&feedback, + client, + allocator); } // receive data @@ -2088,7 +2389,9 @@ void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, // retrieve data from the socket error queue until all send system // calls related timestamps received while (!timestampsToValidate.empty()) { - test::extractTimestampNotifications(&feedback, client, allocator); + SocketUtilTest::extractTimestampNotifications(&feedback, + client, + allocator); while (!feedback.empty()) { const ntsa::Timestamp& ts = feedback.front(); @@ -2105,10 +2408,11 @@ void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, } } -void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketTxTimestamps( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { if (transport == ntsa::Transport::e_LOCAL_STREAM) { return; @@ -2175,7 +2479,9 @@ void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, [ntsa::TimestampType::e_ACKNOWLEDGED] = sysTimeBeforeSending; - test::extractTimestampNotifications(&feedback, client, allocator); + SocketUtilTest::extractTimestampNotifications(&feedback, + client, + allocator); } // receive data @@ -2199,7 +2505,9 @@ void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, // retrieve data from the socket error queue until all send system // calls related timestamps received while (!timestampsToValidate.empty()) { - test::extractTimestampNotifications(&feedback, client, allocator); + SocketUtilTest::extractTimestampNotifications(&feedback, + client, + allocator); while (!feedback.empty()) { const ntsa::Timestamp& ts = feedback.front(); @@ -2216,7 +2524,7 @@ void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, } } -void testDatagramSocketTxTimestampsAndZeroCopy( +void SocketUtilTest::testDatagramSocketTxTimestampsAndZeroCopy( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -2299,7 +2607,7 @@ void testDatagramSocketTxTimestampsAndZeroCopy( NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); - test::extractNotifications(&feedback, client, allocator); + SocketUtilTest::extractNotifications(&feedback, client, allocator); } // receive data @@ -2323,7 +2631,7 @@ void testDatagramSocketTxTimestampsAndZeroCopy( // retrieve data from the socket error queue until all send system // calls related timestamps received while (!timestampsToValidate.empty() || !zeroCopyToValidate.empty()) { - test::extractNotifications(&feedback, client, allocator); + SocketUtilTest::extractNotifications(&feedback, client, allocator); while (!feedback.empty()) { const ntsa::Notification& nt = feedback.front(); @@ -2361,10 +2669,11 @@ void testDatagramSocketTxTimestampsAndZeroCopy( } } -void testStreamSocketTxTimestampsAndZeroCopy(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketTxTimestampsAndZeroCopy( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { if (transport == ntsa::Transport::e_LOCAL_STREAM) { return; @@ -2443,7 +2752,7 @@ void testStreamSocketTxTimestampsAndZeroCopy(ntsa::Transport::Value transport, NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); - test::extractNotifications(&feedback, client, allocator); + SocketUtilTest::extractNotifications(&feedback, client, allocator); } // receive data @@ -2467,7 +2776,7 @@ void testStreamSocketTxTimestampsAndZeroCopy(ntsa::Transport::Value transport, // retrieve data from the socket error queue until all send system // calls related timestamps received while (!timestampsToValidate.empty() || !zeroCopyToValidate.empty()) { - test::extractNotifications(&feedback, client, allocator); + SocketUtilTest::extractNotifications(&feedback, client, allocator); while (!feedback.empty()) { const ntsa::Notification& nt = feedback.front(); @@ -2505,10 +2814,11 @@ void testStreamSocketTxTimestampsAndZeroCopy(ntsa::Transport::Value transport, } } -void testStreamSocketReceiveNotifications(ntsa::Transport::Value transport, - ntsa::Handle server, - ntsa::Handle client, - bslma::Allocator* allocator) +void SocketUtilTest::testStreamSocketReceiveNotifications( + ntsa::Transport::Value transport, + ntsa::Handle server, + ntsa::Handle client, + bslma::Allocator* allocator) { NTSCFG_TEST_LOG_DEBUG << "Testing " << transport << NTSCFG_TEST_LOG_END; @@ -2562,7 +2872,7 @@ void testStreamSocketReceiveNotifications(ntsa::Transport::Value transport, } } -void testDatagramSocketReceiveNotifications( +void SocketUtilTest::testDatagramSocketReceiveNotifications( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -2623,9 +2933,7 @@ void testDatagramSocketReceiveNotifications( } } -} // close namespace 'test' - -NTSCFG_TEST_CASE(1) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase1) { // Concern: Stream socket breathing test, which also serves as the // usage example. @@ -2878,7 +3186,7 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_CASE(2) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase2) { // Concern: Datagram socket breathing test, which also serves as the // usage example. @@ -3076,433 +3384,384 @@ NTSCFG_TEST_CASE(2) } } -NTSCFG_TEST_CASE(3) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase3) { // Concern: Stream socket transmission: single buffer. // Plan: - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTransmissionSingleBuffer); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionSingleBuffer); } -NTSCFG_TEST_CASE(4) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase4) { // Concern: Stream socket transmission: multiple buffers. // Plan: - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTransmissionMultipleBuffers); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionMultipleBuffers); } -NTSCFG_TEST_CASE(5) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase5) { // Concern: Stream socket transmission: blob. // Plan: - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest(&test::testStreamSocketTransmissionBlob); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionBlob); } -NTSCFG_TEST_CASE(6) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase6) { // Concern: Stream socket transmission: file. // Plan: - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest(&test::testStreamSocketTransmissionFile); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionFile); } -NTSCFG_TEST_CASE(7) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase7) { // Concern: Stream socket transmission: single buffer. // Plan: - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionSingleBuffer); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionSingleBuffer); } -NTSCFG_TEST_CASE(8) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase8) { // Concern: Stream socket transmission: multiple buffers. // Plan: - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionMultipleBuffers); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionMultipleBuffers); } -NTSCFG_TEST_CASE(9) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase9) { // Concern: Stream socket transmission: blob. // Plan: - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionBlob); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionBlob); } -NTSCFG_TEST_CASE(10) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase10) { // Concern: Stream socket transmission: single message. // Plan: - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionSingleMessage); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionSingleMessage); } -NTSCFG_TEST_CASE(11) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase11) { // Concern: Stream socket transmission: multiple messages. // Plan: - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionMultipleMessages); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionMultipleMessages); } -NTSCFG_TEST_CASE(12) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase12) { // Concern: Listener socket maximum backlog // Plan: - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::vector socketTypes; - - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV4_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); - } + ntsa::Error error; - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_TCP_IPV6_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); - } + bsl::vector socketTypes; - if (ntsu::AdapterUtil::supportsTransport( - ntsa::Transport::e_LOCAL_STREAM)) - { - socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); - } + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV4_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV4_STREAM); + } - const bsl::size_t systemSoMaxConn = ntsu::SocketUtil::maxBacklog(); + if (ntsu::AdapterUtil::supportsTransport( + ntsa::Transport::e_TCP_IPV6_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_TCP_IPV6_STREAM); + } - if (NTSCFG_TEST_VERBOSITY > 0) { - bsl::cout << "SOMAXCONN = " << systemSoMaxConn << bsl::endl; - } + if (ntsu::AdapterUtil::supportsTransport(ntsa::Transport::e_LOCAL_STREAM)) + { + socketTypes.push_back(ntsa::Transport::e_LOCAL_STREAM); + } - for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { - ntsa::Transport::Value transport = socketTypes[i]; + const bsl::size_t systemSoMaxConn = ntsu::SocketUtil::maxBacklog(); - bsl::size_t BACKLOG[7]; - BACKLOG[0] = 0; - BACKLOG[1] = 1; - BACKLOG[2] = systemSoMaxConn - 1; - BACKLOG[3] = systemSoMaxConn; - BACKLOG[4] = systemSoMaxConn + 1; - BACKLOG[5] = 4096; - BACKLOG[6] = 8192; + if (NTSCFG_TEST_VERBOSITY > 0) { + bsl::cout << "SOMAXCONN = " << systemSoMaxConn << bsl::endl; + } - for (bsl::size_t backlogIndex = 0; backlogIndex < 7; - ++backlogIndex) - { - bsl::size_t backlog = BACKLOG[backlogIndex]; + for (bsl::size_t i = 0; i < socketTypes.size(); ++i) { + ntsa::Transport::Value transport = socketTypes[i]; - // Create a blocking socket, bind it to any port on the loopback - // address, then begin listening for connections. + bsl::size_t BACKLOG[7]; + BACKLOG[0] = 0; + BACKLOG[1] = 1; + BACKLOG[2] = systemSoMaxConn - 1; + BACKLOG[3] = systemSoMaxConn; + BACKLOG[4] = systemSoMaxConn + 1; + BACKLOG[5] = 4096; + BACKLOG[6] = 8192; - ntsa::Handle listener; - error = ntsu::SocketUtil::create(&listener, transport); - NTSCFG_TEST_ASSERT(!error); + for (bsl::size_t backlogIndex = 0; backlogIndex < 7; ++backlogIndex) { + bsl::size_t backlog = BACKLOG[backlogIndex]; - if (transport == ntsa::Transport::e_TCP_IPV4_STREAM) { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - false, - listener); - NTSCFG_TEST_ASSERT(!error); - } - else if (transport == ntsa::Transport::e_TCP_IPV6_STREAM) { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - false, - listener); - NTSCFG_TEST_ASSERT(!error); - } - else if (transport == ntsa::Transport::e_LOCAL_STREAM) { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); + // Create a blocking socket, bind it to any port on the loopback + // address, then begin listening for connections. - error = ntsu::SocketUtil::bind(ntsa::Endpoint(localName), - false, - listener); - NTSCFG_TEST_ASSERT(!error); - } - else { - NTSCFG_TEST_TRUE(false); - } + ntsa::Handle listener; + error = ntsu::SocketUtil::create(&listener, transport); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint listenerEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, - listener); + if (transport == ntsa::Transport::e_TCP_IPV4_STREAM) { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + false, + listener); NTSCFG_TEST_ASSERT(!error); - - if (NTSCFG_TEST_VERBOSITY > 0) { - bsl::cout << "Testing backlog = " << backlog << bsl::endl; - } - - error = ntsu::SocketUtil::listen(backlog, listener); + } + else if (transport == ntsa::Transport::e_TCP_IPV6_STREAM) { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + false, + listener); + NTSCFG_TEST_ASSERT(!error); + } + else if (transport == ntsa::Transport::e_LOCAL_STREAM) { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(listener); + error = ntsu::SocketUtil::bind(ntsa::Endpoint(localName), + false, + listener); NTSCFG_TEST_ASSERT(!error); } + else { + NTSCFG_TEST_TRUE(false); + } + + ntsa::Endpoint listenerEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, listener); + NTSCFG_TEST_ASSERT(!error); + + if (NTSCFG_TEST_VERBOSITY > 0) { + bsl::cout << "Testing backlog = " << backlog << bsl::endl; + } + + error = ntsu::SocketUtil::listen(backlog, listener); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(listener); + NTSCFG_TEST_ASSERT(!error); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(13) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase13) { // Concern: Duplicating sockets // Plan: - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - // Create a blocking socket, bind it to any port on the loopback - // address, then begin listening for connections. + // Create a blocking socket, bind it to any port on the loopback + // address, then begin listening for connections. - ntsa::Handle listener; - error = ntsu::SocketUtil::create(&listener, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_ASSERT(!error); + ntsa::Handle listener; + error = ntsu::SocketUtil::create(&listener, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - false, - listener); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + false, + listener); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::listen(1, listener); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::listen(1, listener); + NTSCFG_TEST_ASSERT(!error); - // Create a blocking socket for the client, then connect that socket to - // the listener socket's local endpoint. + // Create a blocking socket for the client, then connect that socket to + // the listener socket's local endpoint. - ntsa::Handle client; - error = ntsu::SocketUtil::create(&client, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_ASSERT(!error); + ntsa::Handle client; + error = + ntsu::SocketUtil::create(&client, ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint listenerEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, listener); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint listenerEndpoint; + error = ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, listener); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::connect(listenerEndpoint, client); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::connect(listenerEndpoint, client); + NTSCFG_TEST_ASSERT(!error); - // Create a blocking socket for the server by accepting the connection - // made to the listener socket. + // Create a blocking socket for the server by accepting the connection + // made to the listener socket. - ntsa::Handle server; - error = ntsu::SocketUtil::accept(&server, listener); - NTSCFG_TEST_ASSERT(!error); + ntsa::Handle server; + error = ntsu::SocketUtil::accept(&server, listener); + NTSCFG_TEST_ASSERT(!error); - // Duplicate the client socket handle the close it. The subseequent - // test ensures that operations on the socket still succeed, because - // the original handle is not yet closed. + // Duplicate the client socket handle the close it. The subseequent + // test ensures that operations on the socket still succeed, because + // the original handle is not yet closed. - { - ntsa::Handle clientDuplicate = ntsa::k_INVALID_HANDLE; - error = ntsu::SocketUtil::duplicate(&clientDuplicate, client); - NTSCFG_TEST_NE(clientDuplicate, ntsa::k_INVALID_HANDLE); + { + ntsa::Handle clientDuplicate = ntsa::k_INVALID_HANDLE; + error = ntsu::SocketUtil::duplicate(&clientDuplicate, client); + NTSCFG_TEST_NE(clientDuplicate, ntsa::k_INVALID_HANDLE); - error = ntsu::SocketUtil::close(clientDuplicate); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(clientDuplicate); + NTSCFG_TEST_ASSERT(!error); + } - // Duplicate the server socket handle the close it. The subseequent - // test ensures that operations on the socket still succeed, because - // the original handle is not yet closed. + // Duplicate the server socket handle the close it. The subseequent + // test ensures that operations on the socket still succeed, because + // the original handle is not yet closed. - { - ntsa::Handle serverDuplicate = ntsa::k_INVALID_HANDLE; - error = ntsu::SocketUtil::duplicate(&serverDuplicate, server); - NTSCFG_TEST_NE(serverDuplicate, ntsa::k_INVALID_HANDLE); + { + ntsa::Handle serverDuplicate = ntsa::k_INVALID_HANDLE; + error = ntsu::SocketUtil::duplicate(&serverDuplicate, server); + NTSCFG_TEST_NE(serverDuplicate, ntsa::k_INVALID_HANDLE); - error = ntsu::SocketUtil::close(serverDuplicate); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(serverDuplicate); + NTSCFG_TEST_ASSERT(!error); + } - // Enqueue outgoing data to transmit by the client socket. + // Enqueue outgoing data to transmit by the client socket. - { - char buffer = 'C'; - ntsa::SendContext context; - ntsa::SendOptions options; + { + char buffer = 'C'; + ntsa::SendContext context; + ntsa::SendOptions options; - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - error = ntsu::SocketUtil::send(&context, data, options, client); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::send(&context, data, options, client); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_ASSERT(context.bytesSendable() == 1); - NTSCFG_TEST_ASSERT(context.bytesSent() == 1); - } + NTSCFG_TEST_ASSERT(context.bytesSendable() == 1); + NTSCFG_TEST_ASSERT(context.bytesSent() == 1); + } - // Dequeue incoming data received by the server socket. + // Dequeue incoming data received by the server socket. - { - char buffer; - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; + { + char buffer; + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - error = - ntsu::SocketUtil::receive(&context, &data, options, server); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); - NTSCFG_TEST_ASSERT(context.bytesReceived() == 1); - NTSCFG_TEST_ASSERT(buffer == 'C'); - } - - // Enqueue outgoing data to transmit by the server socket. - - { - char buffer = 'S'; - ntsa::SendContext context; - ntsa::SendOptions options; + error = ntsu::SocketUtil::receive(&context, &data, options, server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); + NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); + NTSCFG_TEST_ASSERT(context.bytesReceived() == 1); + NTSCFG_TEST_ASSERT(buffer == 'C'); + } - error = ntsu::SocketUtil::send(&context, data, options, server); - NTSCFG_TEST_ASSERT(!error); + // Enqueue outgoing data to transmit by the server socket. - NTSCFG_TEST_ASSERT(context.bytesSendable() == 1); - NTSCFG_TEST_ASSERT(context.bytesSent() == 1); - } + { + char buffer = 'S'; + ntsa::SendContext context; + ntsa::SendOptions options; - // Dequeue incoming data received by the client socket. + ntsa::Data data(ntsa::ConstBuffer(&buffer, 1)); - { - char buffer; - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; + error = ntsu::SocketUtil::send(&context, data, options, server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + NTSCFG_TEST_ASSERT(context.bytesSendable() == 1); + NTSCFG_TEST_ASSERT(context.bytesSent() == 1); + } - error = - ntsu::SocketUtil::receive(&context, &data, options, client); - NTSCFG_TEST_ASSERT(!error); + // Dequeue incoming data received by the client socket. - NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); - NTSCFG_TEST_ASSERT(context.bytesReceived() == 1); - NTSCFG_TEST_ASSERT(buffer == 'S'); - } + { + char buffer; + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - // Shutdown writing by the client socket. + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - error = ntsu::SocketUtil::shutdown(ntsa::ShutdownType::e_SEND, client); + error = ntsu::SocketUtil::receive(&context, &data, options, client); NTSCFG_TEST_ASSERT(!error); - // Dequeue incoming data received by the server socket, and observe - // that zero bytes are successfully dequeued, indicating the client - // socket has shut down writing from its side of the connection. + NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); + NTSCFG_TEST_ASSERT(context.bytesReceived() == 1); + NTSCFG_TEST_ASSERT(buffer == 'S'); + } - { - char buffer; - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; + // Shutdown writing by the client socket. - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + error = ntsu::SocketUtil::shutdown(ntsa::ShutdownType::e_SEND, client); + NTSCFG_TEST_ASSERT(!error); - error = - ntsu::SocketUtil::receive(&context, &data, options, server); - NTSCFG_TEST_ASSERT(!error); + // Dequeue incoming data received by the server socket, and observe + // that zero bytes are successfully dequeued, indicating the client + // socket has shut down writing from its side of the connection. - NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); - NTSCFG_TEST_ASSERT(context.bytesReceived() == 0); - } + { + char buffer; + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - // Shutdown writing by the server socket. + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - error = ntsu::SocketUtil::shutdown(ntsa::ShutdownType::e_SEND, server); + error = ntsu::SocketUtil::receive(&context, &data, options, server); NTSCFG_TEST_ASSERT(!error); - // Dequeue incoming data received by the client socket, and observe - // that zero bytes are successfully dequeued, indicating the server - // socket has shut down writing from its side of the connection. - - { - char buffer; - ntsa::ReceiveContext context; - ntsa::ReceiveOptions options; + NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); + NTSCFG_TEST_ASSERT(context.bytesReceived() == 0); + } - ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); + // Shutdown writing by the server socket. - error = - ntsu::SocketUtil::receive(&context, &data, options, client); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::shutdown(ntsa::ShutdownType::e_SEND, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); - NTSCFG_TEST_ASSERT(context.bytesReceived() == 0); - } + // Dequeue incoming data received by the client socket, and observe + // that zero bytes are successfully dequeued, indicating the server + // socket has shut down writing from its side of the connection. - // Close each socket. + { + char buffer; + ntsa::ReceiveContext context; + ntsa::ReceiveOptions options; - error = ntsu::SocketUtil::close(listener); - NTSCFG_TEST_ASSERT(!error); + ntsa::Data data(ntsa::MutableBuffer(&buffer, 1)); - error = ntsu::SocketUtil::close(client); + error = ntsu::SocketUtil::receive(&context, &data, options, client); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(context.bytesReceivable() == 1); + NTSCFG_TEST_ASSERT(context.bytesReceived() == 0); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + // Close each socket. + + error = ntsu::SocketUtil::close(listener); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(client); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); } -NTSCFG_TEST_CASE(14) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase14) { // Concern: Binding datagram sockets. // @@ -3577,592 +3836,733 @@ NTSCFG_TEST_CASE(14) // sendto(:) 0.0.0.0: // connect(:) : - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; + + const bool k_REUSE_ADDRESS = false; - const bool k_REUSE_ADDRESS = false; + // Test IPv4. - // Test IPv4. + { + // Concern 1: The source endpoint of a socket initially after + // creation is "0.0.0.0:0". [On Windows 'getsockname' returns an + // error. { - // Concern 1: The source endpoint of a socket initially after - // creation is "0.0.0.0:0". [On Windows 'getsockname' returns an - // error. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); - - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); } - // Concern 2: The socket may be bound after creation to - // "0.0.0.0:0", and the socket's resulting source endpoint is the - // host "0.0.0.0" with a non-zero port. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } + + // Concern 2: The socket may be bound after creation to + // "0.0.0.0:0", and the socket's resulting source endpoint is the + // host "0.0.0.0" with a non-zero port. + + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + // Concern 3: After the socket is bound to "0.0.0.0:0", the + // socket's resulting source endpoint is the host "0.0.0.0" with + // a non-zero port. The socket may *not* be subsequently bound to + // an IPv4 address that matches one of IPv4 addresses assigned to + // one of the network interfaces even if the port matches the + // existing port to which the socket is bound. - // Concern 3: After the socket is bound to "0.0.0.0:0", the - // socket's resulting source endpoint is the host "0.0.0.0" with - // a non-zero port. The socket may *not* be subsequently bound to - // an IPv4 address that matches one of IPv4 addresses assigned to - // one of the network interfaces even if the port matches the - // existing port to which the socket is bound. + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + { + ntsa::Endpoint sourceEndpoint1; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + ntsa::Endpoint sourceEndpoint2; { - ntsa::Endpoint sourceEndpoint1; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V4, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); + + sourceEndpoint2 = + ntsa::Endpoint(adapter.ipv4Address().value(), + sourceEndpoint1.ip().port()); + } + + error = ntsu::SocketUtil::bind(sourceEndpoint2, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV4()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + // Concern 4: The socket may be bound after creation to an IPv4 + // address that matches one of IPv4 addresses assigned to one of + // the network interfaces and port zero, and the resulting socket's + // source endpoint is that IPv4 address with a port chosen by the + // operating system. - ntsa::Endpoint sourceEndpoint2; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V4, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - - sourceEndpoint2 = - ntsa::Endpoint(adapter.ipv4Address().value(), - sourceEndpoint1.ip().port()); - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint explicitSourceEndpoint; + { + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V4, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - error = ntsu::SocketUtil::bind(sourceEndpoint2, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); + explicitSourceEndpoint = + ntsa::Endpoint(adapter.ipv4Address().value(), 0); } - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), + explicitSourceEndpoint.ip().host()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); } - // Concern 4: The socket may be bound after creation to an IPv4 - // address that matches one of IPv4 addresses assigned to one of - // the network interfaces and port zero, and the resulting socket's - // source endpoint is that IPv4 address with a port chosen by the - // operating system. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } + + // Concern 5: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'connect', and may not + // explicitly rebind afterwards. + + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint serverEndpoint; { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint explicitSourceEndpoint; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V4, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - - explicitSourceEndpoint = - ntsa::Endpoint(adapter.ipv4Address().value(), 0); - } - - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } - NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), - explicitSourceEndpoint.ip().host()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - } - // Concern 5: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'connect', and may not - // explicitly rebind afterwards. + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 5a: A datagram socket may be explicitly bound to "any" + // address and "any" port, which results in the source endpoint + // being the "any" address and a non-zero port. The socket may then + // be implicitly rebound by the operating system as a result of + // calling 'connect', so that the resulting source endpoint is now + // an explicit IP address but still having the same port (i.e., the + // address changes from "any" to a specific IP address assigned to + // a network interface, but the port does not change), but the + // datagram socket may not explicitly rebound afterwards. - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + ntsa::Endpoint serverEndpoint; - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif } - // Concern 5a: A datagram socket may be explicitly bound to "any" - // address and "any" port, which results in the source endpoint - // being the "any" address and a non-zero port. The socket may then - // be implicitly rebound by the operating system as a result of - // calling 'connect', so that the resulting source endpoint is now - // an explicit IP address but still having the same port (i.e., the - // address changes from "any" to a specific IP address assigned to - // a network interface, but the port does not change), but the - // datagram socket may not explicitly rebound afterwards. + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 6: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'sendto', and may not + // explicitly rebind afterwards. - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + ntsa::Endpoint serverEndpoint; - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + { + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; + + sendOptions.setEndpoint(serverEndpoint); - error = ntsu::SocketUtil::close(socket); + char storage = 'X'; + + error = ntsu::SocketUtil::send( + &sendContext, + ntsa::Data(ntsa::ConstBuffer(&storage, 1)), + sendOptions, + socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - } - // Concern 6: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'sendto', and may not - // explicitly rebind afterwards. + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + } { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + // Concern 7: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'sendto', *will* be + // implicitly rebound as a result of calling 'connect', and may not + // explicitly rebind afterwards. - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint serverEndpoint; - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } + + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } + } - { - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + { + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - sendOptions.setEndpoint(serverEndpoint); + sendOptions.setEndpoint(serverEndpoint); - char storage = 'X'; + char storage = 'X'; - error = ntsu::SocketUtil::send( - &sendContext, - ntsa::Data(ntsa::ConstBuffer(&storage, 1)), - sendOptions, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::send( + &sendContext, + ntsa::Data(ntsa::ConstBuffer(&storage, 1)), + sendOptions, + socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - } + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 7: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'sendto', *will* be - // implicitly rebound as a result of calling 'connect', and may not - // explicitly rebind afterwards. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } + + // Concern 8: A datagram socket may connect and reconnect to the + // same remote endpoint successfully, and may, while already + // connected, connect and reconnect to a different remote endpoint + // successfully. + + { + ntsa::Handle serverOne; + error = + ntsu::SocketUtil::create(&serverOne, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint serverOneEndpoint; { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + serverOne); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + error = ntsu::SocketUtil::sourceEndpoint(&serverOneEndpoint, + serverOne); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverOneEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverOneEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(serverOneEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverOneEndpoint.ip().port() == 0); + } - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + ntsa::Handle serverTwo; + error = + ntsu::SocketUtil::create(&serverTwo, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + ntsa::Endpoint serverTwoEndpoint; - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + serverTwo); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + error = ntsu::SocketUtil::sourceEndpoint(&serverTwoEndpoint, + serverTwo); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverTwoEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverTwoEndpoint.ip().host().isV4()); + + NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().port() == 0); + } + + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - { - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; - - sendOptions.setEndpoint(serverEndpoint); + } - char storage = 'X'; + for (bsl::size_t i = 0; i < 2; ++i) { + // Connect to server one then reconnect to server one. - error = ntsu::SocketUtil::send( - &sendContext, - ntsa::Data(ntsa::ConstBuffer(&storage, 1)), - sendOptions, - socket); + for (bsl::size_t j = 0; j < 2; ++j) { + error = + ntsu::SocketUtil::connect(serverOneEndpoint, socket); NTSCFG_TEST_ASSERT(!error); ntsa::Endpoint sourceEndpoint; @@ -4173,12 +4573,22 @@ NTSCFG_TEST_CASE(14) NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + + ntsa::Endpoint remoteEndpoint; + error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, + socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_EQ(remoteEndpoint, serverOneEndpoint); } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); + // Connect to server two then reconnect to server two. + + for (bsl::size_t j = 0; j < 2; ++j) { + error = + ntsu::SocketUtil::connect(serverTwoEndpoint, socket); NTSCFG_TEST_ASSERT(!error); ntsa::Endpoint sourceEndpoint; @@ -4197,800 +4607,784 @@ NTSCFG_TEST_CASE(14) socket); NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + NTSCFG_TEST_EQ(remoteEndpoint, serverTwoEndpoint); } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + // Note: attempting to "disconnect" from the remote + // endpoint, by connecting to something like AF_UNSPEC, + // fails on Linux and Darwin. We assume "disconnecting" + // a connected datagram socket is either entirely not + // supported or at least very unportable. + } - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 8: A datagram socket may connect and reconnect to the - // same remote endpoint successfully, and may, while already - // connected, connect and reconnect to a different remote endpoint - // successfully. - - { - ntsa::Handle serverOne; - error = ntsu::SocketUtil::create( - &serverOne, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverOneEndpoint; + error = ntsu::SocketUtil::close(serverTwo); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - serverOne); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(serverOne); + NTSCFG_TEST_ASSERT(!error); + } + } - error = - ntsu::SocketUtil::sourceEndpoint(&serverOneEndpoint, - serverOne); - NTSCFG_TEST_ASSERT(!error); + // Test IPv6. - NTSCFG_TEST_TRUE(serverOneEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverOneEndpoint.ip().host().isV4()); + if (ntsu::AdapterUtil::supportsIpv6()) { + // Concern 1: The source endpoint of a socket initially after + // creation is "[:0]:0". - NTSCFG_TEST_FALSE( - serverOneEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverOneEndpoint.ip().port() == 0); - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Handle serverTwo; - error = ntsu::SocketUtil::create( - &serverTwo, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverTwoEndpoint; + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - serverTwo); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } - error = - ntsu::SocketUtil::sourceEndpoint(&serverTwoEndpoint, - serverTwo); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(serverTwoEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverTwoEndpoint.ip().host().isV4()); + // Concern 2: The socket may be bound after creation to + // "[:0]:0", and the socket's resulting source endpoint is the + // host ":0" with a non-zero port. - NTSCFG_TEST_FALSE( - serverTwoEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().port() == 0); - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - for (bsl::size_t i = 0; i < 2; ++i) { - // Connect to server one then reconnect to server one. + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - for (bsl::size_t j = 0; j < 2; ++j) { - error = ntsu::SocketUtil::connect(serverOneEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - ntsa::Endpoint sourceEndpoint; - error = - ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 3: After the socket is bound to "[:0]:0", the + // socket's resulting source endpoint is the host ":0" with + // a non-zero port. The socket may *not* be subsequently bound to + // an IPv6 address that matches one of IPv6 addresses assigned to + // one of the network interfaces even if the port matches the + // existing port to which the socket is bound. - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE( - sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = - ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverOneEndpoint); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - // Connect to server two then reconnect to server two. + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - for (bsl::size_t j = 0; j < 2; ++j) { - error = ntsu::SocketUtil::connect(serverTwoEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Endpoint sourceEndpoint1; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = - ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); - NTSCFG_TEST_FALSE( - sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + ntsa::Endpoint sourceEndpoint2; + { + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V6, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); + + sourceEndpoint2 = + ntsa::Endpoint(adapter.ipv6Address().value(), + sourceEndpoint1.ip().port()); + } + + error = ntsu::SocketUtil::bind(sourceEndpoint2, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - ntsa::Endpoint remoteEndpoint; - error = - ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_EQ(remoteEndpoint, serverTwoEndpoint); - } + // Concern 4: The socket may be bound after creation to an IPv6 + // address that matches one of IPv6 addresses assigned to one of + // the network interfaces and port zero, and the resulting socket's + // source endpoint is that IPv6 address with a port chosen by the + // operating system. - // Note: attempting to "disconnect" from the remote - // endpoint, by connecting to something like AF_UNSPEC, - // fails on Linux and Darwin. We assume "disconnecting" - // a connected datagram socket is either entirely not - // supported or at least very unportable. - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + { + ntsa::Endpoint explicitSourceEndpoint; { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V6, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); + explicitSourceEndpoint = + ntsa::Endpoint(adapter.ipv6Address().value(), 0); } - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(serverTwo); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(serverOne); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + + NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), + explicitSourceEndpoint.ip().host()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); } + + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); } - // Test IPv6. + // Concern 5: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'connect', and may not + // explicitly rebind afterwards. + + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - if (ntsu::AdapterUtil::supportsIpv6()) { - // Concern 1: The source endpoint of a socket initially after - // creation is "[:0]:0". + ntsa::Endpoint serverEndpoint; { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } + + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); } - // Concern 2: The socket may be bound after creation to - // "[:0]:0", and the socket's resulting source endpoint is the - // host ":0" with a non-zero port. - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverEndpoint.ip().port()); } - // Concern 3: After the socket is bound to "[:0]:0", the - // socket's resulting source endpoint is the host ":0" with - // a non-zero port. The socket may *not* be subsequently bound to - // an IPv6 address that matches one of IPv6 addresses assigned to - // one of the network interfaces even if the port matches the - // existing port to which the socket is bound. - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + // Concern 5a: A datagram socket may be explicitly bound to "any" + // address and "any" port, which results in the source endpoint + // being the "any" address and a non-zero port. The socket may then + // be implicitly rebound by the operating system as a result of + // calling 'connect', so that the resulting source endpoint is now + // an explicit IP address but still having the same port (i.e., the + // address changes from "any" to a specific IP address assigned to + // a network interface, but the port does not change), but the + // datagram socket may not explicitly rebound afterwards. - { - ntsa::Endpoint sourceEndpoint1; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV6()); + ntsa::Endpoint serverEndpoint; - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint2; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V6, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - - sourceEndpoint2 = - ntsa::Endpoint(adapter.ipv6Address().value(), - sourceEndpoint1.ip().port()); - } + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint2, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); } - // Concern 4: The socket may be bound after creation to an IPv6 - // address that matches one of IPv6 addresses assigned to one of - // the network interfaces and port zero, and the resulting socket's - // source endpoint is that IPv6 address with a port chosen by the - // operating system. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint explicitSourceEndpoint; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V6, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - - explicitSourceEndpoint = - ntsa::Endpoint(adapter.ipv6Address().value(), 0); - } - - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - - NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), - explicitSourceEndpoint.ip().host()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif } - // Concern 5: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'connect', and may not - // explicitly rebind afterwards. - { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverEndpoint.ip().port()); + } - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverEndpoint.ip().port()); - } + // Concern 6: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'sendto', and may not + // explicitly rebind afterwards. - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Endpoint serverEndpoint; - error = ntsu::SocketUtil::close(socket); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); } - // Concern 5a: A datagram socket may be explicitly bound to "any" - // address and "any" port, which results in the source endpoint - // being the "any" address and a non-zero port. The socket may then - // be implicitly rebound by the operating system as a result of - // calling 'connect', so that the resulting source endpoint is now - // an explicit IP address but still having the same port (i.e., the - // address changes from "any" to a specific IP address assigned to - // a network interface, but the port does not change), but the - // datagram socket may not explicitly rebound afterwards. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + sendOptions.setEndpoint(serverEndpoint); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + char storage = 'X'; - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::send( + &sendContext, + ntsa::Data(ntsa::ConstBuffer(&storage, 1)), + sendOptions, + socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + // Concern 7: A datagram socket is implicitly bound to an explicit + // source endpoint as a result of calling 'sendto', *will* be + // implicitly rebound as a result of calling 'connect', and may not + // explicitly rebind afterwards. - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint serverEndpoint; - NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverEndpoint.ip().port()); - } + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + } - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - // Concern 6: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'sendto', and may not - // explicitly rebind afterwards. + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - ntsa::Endpoint serverEndpoint; + sendOptions.setEndpoint(serverEndpoint); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + char storage = 'X'; - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::send( + &sendContext, + ntsa::Data(ntsa::ConstBuffer(&storage, 1)), + sendOptions, + socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + } + + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - { - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - sendOptions.setEndpoint(serverEndpoint); + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverEndpoint.ip().port()); + } - char storage = 'X'; + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::send( - &sendContext, - ntsa::Data(ntsa::ConstBuffer(&storage, 1)), - sendOptions, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - } + // Concern 8: A datagram socket may connect and reconnect to the + // same remote endpoint successfully, and may, while already + // connected, connect and reconnect to a different remote endpoint + // successfully. - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle serverOne; + error = + ntsu::SocketUtil::create(&serverOne, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Endpoint serverOneEndpoint; - error = ntsu::SocketUtil::close(socket); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + serverOne); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); + error = ntsu::SocketUtil::sourceEndpoint(&serverOneEndpoint, + serverOne); NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverOneEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverOneEndpoint.ip().host().isV6()); + + NTSCFG_TEST_FALSE(serverOneEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverOneEndpoint.ip().port() == 0); } - // Concern 7: A datagram socket is implicitly bound to an explicit - // source endpoint as a result of calling 'sendto', *will* be - // implicitly rebound as a result of calling 'connect', and may not - // explicitly rebind afterwards. + ntsa::Handle serverTwo; + error = + ntsu::SocketUtil::create(&serverTwo, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint serverTwoEndpoint; { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + serverTwo); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::sourceEndpoint(&serverTwoEndpoint, + serverTwo); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(serverTwoEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverTwoEndpoint.ip().host().isV6()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - } + NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().port() == 0); + } - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - { - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; - - sendOptions.setEndpoint(serverEndpoint); + } - char storage = 'X'; + for (bsl::size_t i = 0; i < 2; ++i) { + // Connect to server one then reconnect to server one. - error = ntsu::SocketUtil::send( - &sendContext, - ntsa::Data(ntsa::ConstBuffer(&storage, 1)), - sendOptions, - socket); + for (bsl::size_t j = 0; j < 2; ++j) { + error = + ntsu::SocketUtil::connect(serverOneEndpoint, socket); NTSCFG_TEST_ASSERT(!error); ntsa::Endpoint sourceEndpoint; @@ -5001,12 +5395,26 @@ NTSCFG_TEST_CASE(14) NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + + ntsa::Endpoint remoteEndpoint; + error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, + socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverOneEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverOneEndpoint.ip().port()); } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); + // Connect to server two then reconnect to server two. + + for (bsl::size_t j = 0; j < 2; ++j) { + error = + ntsu::SocketUtil::connect(serverTwoEndpoint, socket); NTSCFG_TEST_ASSERT(!error); ntsa::Endpoint sourceEndpoint; @@ -5027,1887 +5435,1698 @@ NTSCFG_TEST_CASE(14) NTSCFG_TEST_TRUE( remoteEndpoint.ip().host().v6().equalsScopeless( - serverEndpoint.ip().host().v6())); + serverTwoEndpoint.ip().host().v6())); NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverEndpoint.ip().port()); + serverTwoEndpoint.ip().port()); } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + // Note: attempting to "disconnect" from the remote + // endpoint, by connecting to something like AF_UNSPEC, + // fails on Linux and Darwin. We assume "disconnecting" + // a connected datagram socket is either entirely not + // supported or at least very unportable. + } - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 8: A datagram socket may connect and reconnect to the - // same remote endpoint successfully, and may, while already - // connected, connect and reconnect to a different remote endpoint - // successfully. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Handle serverOne; - error = ntsu::SocketUtil::create( - &serverOne, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(serverTwo); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverOneEndpoint; + error = ntsu::SocketUtil::close(serverOne); + NTSCFG_TEST_ASSERT(!error); + } + } - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - serverOne); - NTSCFG_TEST_ASSERT(!error); + // Test Unix domain. - error = - ntsu::SocketUtil::sourceEndpoint(&serverOneEndpoint, - serverOne); - NTSCFG_TEST_ASSERT(!error); +#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL && \ + !defined(BSLS_PLATFORM_OS_WINDOWS) + { + // Concern 1: The source endpoint of a socket initially after + // creation is the unnamed local name. - NTSCFG_TEST_TRUE(serverOneEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverOneEndpoint.ip().host().isV6()); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE( - serverOneEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverOneEndpoint.ip().port() == 0); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + if (error) { + BSLS_LOG_ERROR("Failed to get source endpoint: %s", + error.text().c_str()); } - - ntsa::Handle serverTwo; - error = ntsu::SocketUtil::create( - &serverTwo, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverTwoEndpoint; + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + } + + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - serverTwo); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - error = - ntsu::SocketUtil::sourceEndpoint(&serverTwoEndpoint, - serverTwo); - NTSCFG_TEST_ASSERT(!error); + // Concern 2: The socket may be bound after creation to an unnamed + // name, and the socket's resulting source endpoint is *not* the + // unnamed name, but an explicit name chosen by the operating + // system (on Linux, in the abstract namespace.) [This + // functionality is only true on Linux]. - NTSCFG_TEST_TRUE(serverTwoEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverTwoEndpoint.ip().host().isV6()); +#if defined(BSLS_PLATFORM_OS_LINUX) + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE( - serverTwoEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverTwoEndpoint.ip().port() == 0); - } + { + ntsa::Endpoint unnamedSourceEndpoint = + ntsa::Endpoint(ntsa::LocalName()); + NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.isLocal()); + NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.local().isUnnamed()); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::bind(unnamedSourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_NE(sourceEndpoint, unnamedSourceEndpoint); + NTSCFG_TEST_GT(sourceEndpoint.local().value().size(), 0); +#if defined(BSLS_PLATFORM_OS_LINUX) + NTSCFG_TEST_TRUE(sourceEndpoint.local().isAbstract()); #endif - } - - for (bsl::size_t i = 0; i < 2; ++i) { - // Connect to server one then reconnect to server one. + } - for (bsl::size_t j = 0; j < 2; ++j) { - error = ntsu::SocketUtil::connect(serverOneEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = - ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } +#endif - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + // Concern 3: The socket may be bound after creation to an explicit + // name, and the socket's resulting source endpoint is the explicit + // name. - NTSCFG_TEST_FALSE( - sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = - ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverOneEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverOneEndpoint.ip().port()); - } + ntsa::Endpoint explicitSourceEndpoint = + ntsa::Endpoint(localName); - // Connect to server two then reconnect to server two. + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - for (bsl::size_t j = 0; j < 2; ++j) { - error = ntsu::SocketUtil::connect(serverTwoEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = - ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_EQ(sourceEndpoint, explicitSourceEndpoint); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE( - sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - ntsa::Endpoint remoteEndpoint; - error = - ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 4: A datagram socket is implicitly bound to an unnamed + // source endpoint as a result of calling 'connect', and *may*, + // on Linux, explicitly rebind afterwards. - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverTwoEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverTwoEndpoint.ip().port()); - } + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - // Note: attempting to "disconnect" from the remote - // endpoint, by connecting to something like AF_UNSPEC, - // fails on Linux and Darwin. We assume "disconnecting" - // a connected datagram socket is either entirely not - // supported or at least very unportable. - } + ntsa::Endpoint serverEndpoint; - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + ntsa::Endpoint explicitServerEndpoint = + ntsa::Endpoint(localName); - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::bind(explicitServerEndpoint, + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(serverTwo); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(serverOne); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); + NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); } - } - // Test Unix domain. - -#if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL && \ - !defined(BSLS_PLATFORM_OS_WINDOWS) - { - // Concern 1: The source endpoint of a socket initially after - // creation is the unnamed local name. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_LOCAL_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - if (error) { - BSLS_LOG_ERROR("Failed to get source endpoint: %s", - error.text().c_str()); - } - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + } - error = ntsu::SocketUtil::unlink(socket); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - } - // Concern 2: The socket may be bound after creation to an unnamed - // name, and the socket's resulting source endpoint is *not* the - // unnamed name, but an explicit name chosen by the operating - // system (on Linux, in the abstract namespace.) [This - // functionality is only true on Linux]. + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); -#if defined(BSLS_PLATFORM_OS_LINUX) - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_LOCAL_DATAGRAM); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint unnamedSourceEndpoint = - ntsa::Endpoint(ntsa::LocalName()); - NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.isLocal()); - NTSCFG_TEST_ASSERT( - unnamedSourceEndpoint.local().isUnnamed()); - - error = ntsu::SocketUtil::bind(unnamedSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_NE(sourceEndpoint, unnamedSourceEndpoint); - NTSCFG_TEST_GT(sourceEndpoint.local().value().size(), 0); #if defined(BSLS_PLATFORM_OS_LINUX) - NTSCFG_TEST_TRUE(sourceEndpoint.local().isAbstract()); -#endif - } - - error = ntsu::SocketUtil::unlink(socket); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - } #endif + } - // Concern 3: The socket may be bound after creation to an explicit - // name, and the socket's resulting source endpoint is the explicit - // name. + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_LOCAL_DATAGRAM); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint explicitSourceEndpoint = - ntsa::Endpoint(localName); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 5: A datagram socket is implicitly bound to an + // *implicit* source endpoint as a result of calling 'sendto' + // (i.e., the operating system does not generate a name), and + // *may*, on Linux, explicitly rebind afterwards. - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_EQ(sourceEndpoint, explicitSourceEndpoint); - } + ntsa::Endpoint serverEndpoint; + + { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::unlink(socket); + ntsa::Endpoint explicitServerEndpoint = + ntsa::Endpoint(localName); + + error = ntsu::SocketUtil::bind(explicitServerEndpoint, + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); + NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); } - // Concern 4: A datagram socket is implicitly bound to an unnamed - // source endpoint as a result of calling 'connect', and *may*, - // on Linux, explicitly rebind afterwards. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_LOCAL_DATAGRAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + } - { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::SendContext sendContext; + ntsa::SendOptions sendOptions; - ntsa::Endpoint explicitServerEndpoint = - ntsa::Endpoint(localName); + sendOptions.setEndpoint(serverEndpoint); - error = ntsu::SocketUtil::bind(explicitServerEndpoint, - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + char storage = 'X'; - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::send( + &sendContext, + ntsa::Data(ntsa::ConstBuffer(&storage, 1)), + sendOptions, + socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); - NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); - } + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + } - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_LOCAL_DATAGRAM); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); +#if defined(BSLS_PLATFORM_OS_LINUX) + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); - } + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); +#endif + } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + error = ntsu::SocketUtil::unlink(server); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } + } +#endif +} - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase15) +{ + // Concern: Binding stream sockets. + // Plan: - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Error error; -#if defined(BSLS_PLATFORM_OS_LINUX) - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + const bool k_REUSE_ADDRESS = false; - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); -#endif - } + // Test IPv4. - error = ntsu::SocketUtil::unlink(socket); - NTSCFG_TEST_ASSERT(!error); + { + // Concern 1: The source endpoint of a socket initially after + // creation is "0.0.0.0:0". - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::unlink(server); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif } - // Concern 5: A datagram socket is implicitly bound to an - // *implicit* source endpoint as a result of calling 'sendto' - // (i.e., the operating system does not generate a name), and - // *may*, on Linux, explicitly rebind afterwards. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } + + // Concern 2: The socket may be bound after creation to + // "0.0.0.0:0", and the socket's resulting source endpoint is the + // host "0.0.0.0" with a non-zero port. + + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_LOCAL_DATAGRAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - ntsa::Endpoint explicitServerEndpoint = - ntsa::Endpoint(localName); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - error = ntsu::SocketUtil::bind(explicitServerEndpoint, - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); - NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); - } + // Concern 3: After the socket is bound to "0.0.0.0:0", the + // socket's resulting source endpoint is the host "0.0.0.0" with + // a non-zero port. The socket may *not* be subsequently bound to + // an IPv4 address that matches one of IPv4 addresses assigned to + // one of the network interfaces even if the port matches the + // existing port to which the socket is bound. + + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_LOCAL_DATAGRAM); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - { - ntsa::SendContext sendContext; - ntsa::SendOptions sendOptions; + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - sendOptions.setEndpoint(serverEndpoint); + { + ntsa::Endpoint sourceEndpoint1; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, socket); + NTSCFG_TEST_ASSERT(!error); - char storage = 'X'; + NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV4()); - error = ntsu::SocketUtil::send( - &sendContext, - ntsa::Data(ntsa::ConstBuffer(&storage, 1)), - sendOptions, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint2; + { + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V4, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); + + sourceEndpoint2 = + ntsa::Endpoint(adapter.ipv4Address().value(), + sourceEndpoint1.ip().port()); + } + + error = ntsu::SocketUtil::bind(sourceEndpoint2, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); - } + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 4: The socket may be bound after creation to an IPv4 + // address that matches one of IPv4 addresses assigned to one of + // the network interfaces and port zero, and the resulting socket's + // source endpoint is that IPv4 address with a port chosen by the + // operating system. -#if defined(BSLS_PLATFORM_OS_LINUX) - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); -#endif + { + ntsa::Endpoint explicitSourceEndpoint; + { + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V4, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); + + explicitSourceEndpoint = + ntsa::Endpoint(adapter.ipv4Address().value(), 0); } - error = ntsu::SocketUtil::unlink(socket); + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::unlink(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), + explicitSourceEndpoint.ip().host()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); } - } -#endif - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); -} -NTSCFG_TEST_CASE(15) -{ - // Concern: Binding stream sockets. - // Plan: - - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - const bool k_REUSE_ADDRESS = false; + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - // Test IPv4. + // Concern 5: A stream socket is implicitly bound to an explicit + // source endpoint as a result of calling 'connect', and may not + // explicitly rebind afterwards. { - // Concern 1: The source endpoint of a socket initially after - // creation is "0.0.0.0:0". + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); + + ntsa::Endpoint serverEndpoint; { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::listen(100, server); NTSCFG_TEST_ASSERT(!error); } - // Concern 2: The socket may be bound after creation to - // "0.0.0.0:0", and the socket's resulting source endpoint is the - // host "0.0.0.0" with a non-zero port. + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV4_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } - - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif } - // Concern 3: After the socket is bound to "0.0.0.0:0", the - // socket's resulting source endpoint is the host "0.0.0.0" with - // a non-zero port. The socket may *not* be subsequently bound to - // an IPv4 address that matches one of IPv4 addresses assigned to - // one of the network interfaces even if the port matches the - // existing port to which the socket is bound. - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); + error = ntsu::SocketUtil::connect(serverEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } - - { - ntsa::Endpoint sourceEndpoint1; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV4()); - - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint2; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V4, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - - sourceEndpoint2 = - ntsa::Endpoint(adapter.ipv4Address().value(), - sourceEndpoint1.ip().port()); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::bind(sourceEndpoint2, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - error = ntsu::SocketUtil::close(socket); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - } - // Concern 4: The socket may be bound after creation to an IPv4 - // address that matches one of IPv4 addresses assigned to one of - // the network interfaces and port zero, and the resulting socket's - // source endpoint is that IPv4 address with a port chosen by the - // operating system. + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint explicitSourceEndpoint; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V4, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv4Address().isNull()); - - explicitSourceEndpoint = - ntsa::Endpoint(adapter.ipv4Address().value(), 0); - } - - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), - explicitSourceEndpoint.ip().host()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + // Concern 5a: A stream socket may be explicitly bound to "any" + // address and "any" port, which results in the source endpoint + // being the "any" address and a non-zero port. The socket may then + // be implicitly rebound by the operating system as a result of + // calling 'connect', so that the resulting source endpoint is now + // an explicit IP address but still having the same port (i.e., the + // address changes from "any" to a specific IP address assigned to + // a network interface, but the port does not change), but the + // stream socket may not explicitly rebound afterwards. - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - // Concern 5: A stream socket is implicitly bound to an explicit - // source endpoint as a result of calling 'connect', and may not - // explicitly rebind afterwards. + ntsa::Endpoint serverEndpoint; { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_TCP_IPV4_STREAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - error = ntsu::SocketUtil::listen(100, server); - NTSCFG_TEST_ASSERT(!error); - } - - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV4_DATAGRAM); + error = ntsu::SocketUtil::listen(100, server); NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } + } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - error = ntsu::SocketUtil::close(socket); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); } - // Concern 5a: A stream socket may be explicitly bound to "any" - // address and "any" port, which results in the source endpoint - // being the "any" address and a non-zero port. The socket may then - // be implicitly rebound by the operating system as a result of - // calling 'connect', so that the resulting source endpoint is now - // an explicit IP address but still having the same port (i.e., the - // address changes from "any" to a specific IP address assigned to - // a network interface, but the port does not change), but the - // stream socket may not explicitly rebound afterwards. - { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_TCP_IPV4_STREAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV4()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - error = ntsu::SocketUtil::listen(100, server); - NTSCFG_TEST_ASSERT(!error); - } + // Concern 6: A stream socket is implicitly bound to an explicit + // source endpoint as a result of calling 'listen', and may not + // explicitly rebind afterwards. [On Windows this is an error.] - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } - - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } - - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + } - error = ntsu::SocketUtil::close(socket); + { + error = ntsu::SocketUtil::listen(100, socket); +#if defined(BSLS_PLATFORM_OS_UNIX) NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - } - // Concern 6: A stream socket is implicitly bound to an explicit - // source endpoint as a result of calling 'listen', and may not - // explicitly rebind afterwards. [On Windows this is an error.] + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); +#elif defined(BSLS_PLATFORM_OS_WINDOWS) + NTSCFG_TEST_ASSERT(error); +#endif + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } + } - { - error = ntsu::SocketUtil::listen(100, socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } + } - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + // Test IPv6. - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV4()); + if (ntsu::AdapterUtil::supportsIpv6()) { + // Concern 1: The source endpoint of a socket initially after + // creation is "[:0]:0". - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v4().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); } + + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); } - // Test IPv6. + // Concern 2: The socket may be bound after creation to + // "[:0]:0", and the socket's resulting source endpoint is the + // host ":0" with a non-zero port. - if (ntsu::AdapterUtil::supportsIpv6()) { - // Concern 1: The source endpoint of a socket initially after - // creation is "[:0]:0". + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); -#if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); -#elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); -#endif - } + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 2: The socket may be bound after creation to - // "[:0]:0", and the socket's resulting source endpoint is the - // host ":0" with a non-zero port. - - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + // Concern 3: After the socket is bound to "[:0]:0", the + // socket's resulting source endpoint is the host ":0" with + // a non-zero port. The socket may *not* be subsequently bound to + // an IPv6 address that matches one of IPv6 addresses assigned to + // one of the network interfaces even if the port matches the + // existing port to which the socket is bound. - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); } - // Concern 3: After the socket is bound to "[:0]:0", the - // socket's resulting source endpoint is the host ":0" with - // a non-zero port. The socket may *not* be subsequently bound to - // an IPv6 address that matches one of IPv6 addresses assigned to - // one of the network interfaces even if the port matches the - // existing port to which the socket is bound. - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); + ntsa::Endpoint sourceEndpoint1; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, socket); NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + ntsa::Endpoint sourceEndpoint2; { - ntsa::Endpoint sourceEndpoint1; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint1, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V6, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); + + sourceEndpoint2 = + ntsa::Endpoint(adapter.ipv6Address().value(), + sourceEndpoint1.ip().port()); + } + + error = ntsu::SocketUtil::bind(sourceEndpoint2, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); + } - NTSCFG_TEST_TRUE(sourceEndpoint1.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().isV6()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint1.ip().port() != 0); + // Concern 4: The socket may be bound after creation to an IPv6 + // address that matches one of IPv6 addresses assigned to one of + // the network interfaces and port zero, and the resulting socket's + // source endpoint is that IPv6 address with a port chosen by the + // operating system. - ntsa::Endpoint sourceEndpoint2; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V6, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - - sourceEndpoint2 = - ntsa::Endpoint(adapter.ipv6Address().value(), - sourceEndpoint1.ip().port()); - } + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint explicitSourceEndpoint; + { + ntsa::Adapter adapter; + bool found = ntsu::AdapterUtil::discoverAdapter( + &adapter, + ntsa::IpAddressType::e_V6, + false); + NTSCFG_TEST_TRUE(found); + NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - error = ntsu::SocketUtil::bind(sourceEndpoint2, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); + explicitSourceEndpoint = + ntsa::Endpoint(adapter.ipv6Address().value(), 0); } - error = ntsu::SocketUtil::close(socket); + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - } - // Concern 4: The socket may be bound after creation to an IPv6 - // address that matches one of IPv6 addresses assigned to one of - // the network interfaces and port zero, and the resulting socket's - // source endpoint is that IPv6 address with a port chosen by the - // operating system. - - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint explicitSourceEndpoint; - { - ntsa::Adapter adapter; - bool found = ntsu::AdapterUtil::discoverAdapter( - &adapter, - ntsa::IpAddressType::e_V6, - false); - NTSCFG_TEST_TRUE(found); - NTSCFG_TEST_FALSE(adapter.ipv6Address().isNull()); - - explicitSourceEndpoint = - ntsa::Endpoint(adapter.ipv6Address().value(), 0); - } - - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), + explicitSourceEndpoint.ip().host()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_EQ(sourceEndpoint.ip().host(), - explicitSourceEndpoint.ip().host()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + // Concern 5: A stream socket is implicitly bound to an explicit + // source endpoint as a result of calling 'connect', and may not + // explicitly rebind afterwards. - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); - // Concern 5: A stream socket is implicitly bound to an explicit - // source endpoint as a result of calling 'connect', and may not - // explicitly rebind afterwards. + ntsa::Endpoint serverEndpoint; { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_TCP_IPV6_STREAM); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); - - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::listen(100, server); - NTSCFG_TEST_ASSERT(!error); - } + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_UDP_IPV6_DATAGRAM); + error = ntsu::SocketUtil::listen(100, server); NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_UDP_IPV6_DATAGRAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverEndpoint.ip().port()); - } + NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverEndpoint.ip().port()); + } - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 5a: A stream socket may be explicitly bound to "any" - // address and "any" port, which results in the source endpoint - // being the "any" address and a non-zero port. The socket may then - // be implicitly rebound by the operating system as a result of - // calling 'connect', so that the resulting source endpoint is now - // an explicit IP address but still having the same port (i.e., the - // address changes from "any" to a specific IP address assigned to - // a network interface, but the port does not change), but the - // stream socket may not explicitly rebound afterwards. + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Handle server; - error = ntsu::SocketUtil::create( - &server, - ntsa::Transport::e_TCP_IPV6_STREAM); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - ntsa::Endpoint serverEndpoint; + // Concern 5a: A stream socket may be explicitly bound to "any" + // address and "any" port, which results in the source endpoint + // being the "any" address and a non-zero port. The socket may then + // be implicitly rebound by the operating system as a result of + // calling 'connect', so that the resulting source endpoint is now + // an explicit IP address but still having the same port (i.e., the + // address changes from "any" to a specific IP address assigned to + // a network interface, but the port does not change), but the + // stream socket may not explicitly rebound afterwards. - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Handle server; + error = + ntsu::SocketUtil::create(&server, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint serverEndpoint; - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::loopback(), 0), + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); + + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::listen(100, server); - NTSCFG_TEST_ASSERT(!error); - } + NTSCFG_TEST_FALSE(serverEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(serverEndpoint.ip().port() == 0); - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); + error = ntsu::SocketUtil::listen(100, server); NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - { - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv6Address::any(), 0), + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); - } + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() != 0); + } - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); - NTSCFG_TEST_TRUE(serverEndpoint.isIp()); - NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE( - remoteEndpoint.ip().host().v6().equalsScopeless( - serverEndpoint.ip().host().v6())); - NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == - serverEndpoint.ip().port()); - } + NTSCFG_TEST_TRUE(remoteEndpoint.isIp()); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().host().isV6()); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(serverEndpoint.isIp()); + NTSCFG_TEST_TRUE(serverEndpoint.ip().host().isV6()); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); - } + NTSCFG_TEST_TRUE( + remoteEndpoint.ip().host().v6().equalsScopeless( + serverEndpoint.ip().host().v6())); + NTSCFG_TEST_TRUE(remoteEndpoint.ip().port() == + serverEndpoint.ip().port()); + } - error = ntsu::SocketUtil::close(socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); } - // Concern 6: A stream socket is implicitly bound to an explicit - // source endpoint as a result of calling 'listen', and may not - // explicitly rebind afterwards. [On Windows this is an error.] + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Handle socket; - error = ntsu::SocketUtil::create( - &socket, - ntsa::Transport::e_TCP_IPV6_STREAM); - NTSCFG_TEST_ASSERT(!error); + // Concern 6: A stream socket is implicitly bound to an explicit + // source endpoint as a result of calling 'listen', and may not + // explicitly rebind afterwards. [On Windows this is an error.] - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Handle socket; + error = + ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_TCP_IPV6_STREAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } + } - { - error = ntsu::SocketUtil::listen(100, socket); + { + error = ntsu::SocketUtil::listen(100, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); + NTSCFG_TEST_TRUE(sourceEndpoint.isIp()); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().isV6()); - NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); - NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); + NTSCFG_TEST_TRUE(sourceEndpoint.ip().host().v6().isAny()); + NTSCFG_TEST_FALSE(sourceEndpoint.ip().port() == 0); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(error); #elif defined(BSLS_PLATFORM_OS_WINDOWS) - NTSCFG_TEST_ASSERT(error); + NTSCFG_TEST_ASSERT(error); #endif - } - - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); } + + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); } + } - // Test Unix domain. + // Test Unix domain. #if NTSCFG_BUILD_WITH_TRANSPORT_PROTOCOL_LOCAL + { + // Concern 1: The source endpoint of a socket initially after + // creation is the unnamed local name, except on Windows, which + // specifically describes its non-standard behavior where a + // Unix domain socket is not implicitly assigned the unnamed + // address. + { - // Concern 1: The source endpoint of a socket initially after - // creation is the unnamed local name, except on Windows, which - // specifically describes its non-standard behavior where a - // Unix domain socket is not implicitly assigned the unnamed - // address. + ntsa::Handle socket; + error = ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_STREAM); + NTSCFG_TEST_ASSERT(!error); { - ntsa::Handle socket; + ntsa::Endpoint sourceEndpoint; error = - ntsu::SocketUtil::create(&socket, - ntsa::Transport::e_LOCAL_STREAM); - NTSCFG_TEST_ASSERT(!error); - - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); #else - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); + NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); #endif - } + } - error = ntsu::SocketUtil::unlink(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } + + // Concern 2: The socket may be bound after creation to an unnamed + // name, and the socket's resulting source endpoint is *not* the + // unnamed name, but an explicit name chosen by the operating + // system (on Linux, in the abstract namespace.) [This + // functionality is only available on Linux.] - // Concern 2: The socket may be bound after creation to an unnamed - // name, and the socket's resulting source endpoint is *not* the - // unnamed name, but an explicit name chosen by the operating - // system (on Linux, in the abstract namespace.) [This - // functionality is only available on Linux.] +#if defined(BSLS_PLATFORM_OS_LINUX) + { + ntsa::Handle socket; + error = ntsu::SocketUtil::create(&socket, + ntsa::Transport::e_LOCAL_STREAM); + NTSCFG_TEST_ASSERT(!error); + + { + ntsa::Endpoint unnamedSourceEndpoint = + ntsa::Endpoint(ntsa::LocalName()); + NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.isLocal()); + NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.local().isUnnamed()); + + error = ntsu::SocketUtil::bind(unnamedSourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); -#if defined(BSLS_PLATFORM_OS_LINUX) - { - ntsa::Handle socket; + ntsa::Endpoint sourceEndpoint; error = - ntsu::SocketUtil::create(&socket, - ntsa::Transport::e_LOCAL_STREAM); + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint unnamedSourceEndpoint = - ntsa::Endpoint(ntsa::LocalName()); - NTSCFG_TEST_ASSERT(unnamedSourceEndpoint.isLocal()); - NTSCFG_TEST_ASSERT( - unnamedSourceEndpoint.local().isUnnamed()); - - error = ntsu::SocketUtil::bind(unnamedSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); - - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_NE(sourceEndpoint, unnamedSourceEndpoint); - NTSCFG_TEST_GT(sourceEndpoint.local().value().size(), 0); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_NE(sourceEndpoint, unnamedSourceEndpoint); + NTSCFG_TEST_GT(sourceEndpoint.local().value().size(), 0); #if defined(BSLS_PLATFORM_OS_LINUX) - NTSCFG_TEST_TRUE(sourceEndpoint.local().isAbstract()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isAbstract()); #endif - } + } - error = ntsu::SocketUtil::unlink(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } #endif - // Concern 3: The socket may be bound after creation to an explicit - // name, and the socket's resulting source endpoint is the explicit - // name. + // Concern 3: The socket may be bound after creation to an explicit + // name, and the socket's resulting source endpoint is the explicit + // name. - { - ntsa::Handle socket; - error = - ntsu::SocketUtil::create(&socket, + { + ntsa::Handle socket; + error = ntsu::SocketUtil::create(&socket, ntsa::Transport::e_LOCAL_STREAM); - NTSCFG_TEST_ASSERT(!error); - - { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); - - ntsa::Endpoint explicitSourceEndpoint = - ntsa::Endpoint(localName); - - error = ntsu::SocketUtil::bind(explicitSourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_EQ(sourceEndpoint, explicitSourceEndpoint); - } + ntsa::Endpoint explicitSourceEndpoint = + ntsa::Endpoint(localName); - error = ntsu::SocketUtil::unlink(socket); + error = ntsu::SocketUtil::bind(explicitSourceEndpoint, + k_REUSE_ADDRESS, + socket); NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); NTSCFG_TEST_ASSERT(!error); + + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_EQ(sourceEndpoint, explicitSourceEndpoint); } - // Concern 4: A stream socket is implicitly bound to an unnamed - // source endpoint as a result of calling 'connect', and *may*, on - // Linux, explicitly rebind afterwards. + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); + + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); + } - { - ntsa::Handle server; - error = - ntsu::SocketUtil::create(&server, + // Concern 4: A stream socket is implicitly bound to an unnamed + // source endpoint as a result of calling 'connect', and *may*, on + // Linux, explicitly rebind afterwards. + + { + ntsa::Handle server; + error = ntsu::SocketUtil::create(&server, ntsa::Transport::e_LOCAL_STREAM); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint serverEndpoint; + ntsa::Endpoint serverEndpoint; - { - ntsa::LocalName localName; - error = ntsa::LocalName::generateUnique(&localName); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::LocalName localName; + error = ntsa::LocalName::generateUnique(&localName); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint explicitServerEndpoint = - ntsa::Endpoint(localName); + ntsa::Endpoint explicitServerEndpoint = + ntsa::Endpoint(localName); - error = ntsu::SocketUtil::bind(explicitServerEndpoint, - k_REUSE_ADDRESS, - server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(explicitServerEndpoint, + k_REUSE_ADDRESS, + server); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, - server); - NTSCFG_TEST_ASSERT(!error); + error = + ntsu::SocketUtil::sourceEndpoint(&serverEndpoint, server); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); - NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); + NTSCFG_TEST_TRUE(serverEndpoint.isLocal()); + NTSCFG_TEST_EQ(serverEndpoint, explicitServerEndpoint); - error = ntsu::SocketUtil::listen(100, server); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::listen(100, server); + NTSCFG_TEST_ASSERT(!error); + } - ntsa::Handle socket; - error = - ntsu::SocketUtil::create(&socket, + ntsa::Handle socket; + error = ntsu::SocketUtil::create(&socket, ntsa::Transport::e_LOCAL_STREAM); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); #else - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); + NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); #endif - } + } - { - error = ntsu::SocketUtil::connect(serverEndpoint, socket); - NTSCFG_TEST_ASSERT(!error); + { + error = ntsu::SocketUtil::connect(serverEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); - ntsa::Endpoint remoteEndpoint; - error = ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint remoteEndpoint; + error = + ntsu::SocketUtil::remoteEndpoint(&remoteEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); - } + NTSCFG_TEST_EQ(remoteEndpoint, serverEndpoint); + } - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); - NTSCFG_TEST_ASSERT(!error); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); + NTSCFG_TEST_ASSERT(!error); #if defined(BSLS_PLATFORM_OS_LINUX) - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind(sourceEndpoint, - k_REUSE_ADDRESS, - socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind(sourceEndpoint, + k_REUSE_ADDRESS, + socket); + NTSCFG_TEST_ASSERT(!error); #endif - } + } - error = ntsu::SocketUtil::unlink(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::unlink(server); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(server); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(server); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(server); + NTSCFG_TEST_ASSERT(!error); + } - // Concern 5: A stream socket is implicitly bound to an unnamed - // source endpoint as a result of calling 'listen', and *may* - // explicitly rebind afterwards. [This functionality is only - // available on Linux, on all other platforms a stream socket - // must be explicitly bound before calling 'listen'.) + // Concern 5: A stream socket is implicitly bound to an unnamed + // source endpoint as a result of calling 'listen', and *may* + // explicitly rebind afterwards. [This functionality is only + // available on Linux, on all other platforms a stream socket + // must be explicitly bound before calling 'listen'.) - { - ntsa::Handle socket; - error = - ntsu::SocketUtil::create(&socket, + { + ntsa::Handle socket; + error = ntsu::SocketUtil::create(&socket, ntsa::Transport::e_LOCAL_STREAM); - NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::Endpoint sourceEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, - socket); + { + ntsa::Endpoint sourceEndpoint; + error = + ntsu::SocketUtil::sourceEndpoint(&sourceEndpoint, socket); #if defined(BSLS_PLATFORM_OS_UNIX) - NTSCFG_TEST_ASSERT(!error); - NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); - NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); + NTSCFG_TEST_ASSERT(!error); + NTSCFG_TEST_TRUE(sourceEndpoint.isLocal()); + NTSCFG_TEST_TRUE(sourceEndpoint.local().isUnnamed()); #else - NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); - NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); + NTSCFG_TEST_EQ(error, ntsa::Error(ntsa::Error::e_INVALID)); + NTSCFG_TEST_TRUE(sourceEndpoint.isUndefined()); #endif - } + } - { - error = ntsu::SocketUtil::listen(100, socket); - NTSCFG_TEST_ASSERT(error); - } + { + error = ntsu::SocketUtil::listen(100, socket); + NTSCFG_TEST_ASSERT(error); + } - error = ntsu::SocketUtil::unlink(socket); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::unlink(socket); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::close(socket); - NTSCFG_TEST_ASSERT(!error); - } + error = ntsu::SocketUtil::close(socket); + NTSCFG_TEST_ASSERT(!error); } -#endif } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); +#endif } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase16) { // Concern: Listing system sockets. - ntscfg::TestAllocator ta; - { - ntsa::Error error; + ntsa::Error error; - ntsa::Handle listener; - error = ntsu::SocketUtil::create(&listener, - ntsa::Transport::e_TCP_IPV4_STREAM); - NTSCFG_TEST_ASSERT(!error); + ntsa::Handle listener; + error = ntsu::SocketUtil::create(&listener, + ntsa::Transport::e_TCP_IPV4_STREAM); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::bind( - ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), - true, - listener); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::bind( + ntsa::Endpoint(ntsa::Ipv4Address::loopback(), 0), + true, + listener); + NTSCFG_TEST_ASSERT(!error); - ntsa::Endpoint listenerEndpoint; - error = ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, listener); - NTSCFG_TEST_ASSERT(!error); + ntsa::Endpoint listenerEndpoint; + error = ntsu::SocketUtil::sourceEndpoint(&listenerEndpoint, listener); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketUtil::listen(1, listener); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::listen(1, listener); + NTSCFG_TEST_ASSERT(!error); - BSLS_LOG_INFO("Listening at %s", listenerEndpoint.text().c_str()); + BSLS_LOG_INFO("Listening at %s", listenerEndpoint.text().c_str()); - { - ntsa::SocketInfoFilter filter; - filter.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - filter.setAll(false); + { + ntsa::SocketInfoFilter filter; + filter.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + filter.setAll(false); - bsl::stringstream ss; - ntsu::SocketUtil::reportInfo(ss, filter); + bsl::stringstream ss; + ntsu::SocketUtil::reportInfo(ss, filter); - BSLS_LOG_INFO("Dump status:\n%s", ss.str().c_str()); - } + BSLS_LOG_INFO("Dump status:\n%s", ss.str().c_str()); + } - error = ntsu::SocketUtil::close(listener); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::close(listener); + NTSCFG_TEST_ASSERT(!error); - { - ntsa::SocketInfoFilter filter; - filter.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); - filter.setAll(false); + { + ntsa::SocketInfoFilter filter; + filter.setTransport(ntsa::Transport::e_TCP_IPV4_STREAM); + filter.setAll(false); - bsl::stringstream ss; - ntsu::SocketUtil::reportInfo(ss, filter); + bsl::stringstream ss; + ntsu::SocketUtil::reportInfo(ss, filter); - BSLS_LOG_INFO("Dump status:\n%s", ss.str().c_str()); - } + BSLS_LOG_INFO("Dump status:\n%s", ss.str().c_str()); } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(17) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase17) { // Concern: Create stream socket pairs. // @@ -7255,7 +7474,7 @@ NTSCFG_TEST_CASE(17) } } -NTSCFG_TEST_CASE(18) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase18) { // Concern: Create datagram socket pairs. // @@ -7598,97 +7817,87 @@ NTSCFG_TEST_CASE(18) } } -NTSCFG_TEST_CASE(19) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase19) { // Concern: Datagram socket transmission with control data: single buffer. // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionSingleBufferWithControlMsg); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest:: + testDatagramSocketTransmissionSingleBufferWithControlMsg); + #endif } -NTSCFG_TEST_CASE(20) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase20) { // Concern: Datagram socket transmission with control data: blob. // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionBlobWithControlMsg); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionBlobWithControlMsg); + #endif } -NTSCFG_TEST_CASE(21) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase21) { // Concern: Datagram socket transmission with control data: dropped. // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTransmissionWithControlMsgDropped); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTransmissionWithControlMsgDropped); + #endif } -NTSCFG_TEST_CASE(22) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase22) { // Concern: Stream socket transmission with control data: single buffer. // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTransmissionSingleBufferWithControlMsg); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest:: + testStreamSocketTransmissionSingleBufferWithControlMsg); + #endif } -NTSCFG_TEST_CASE(23) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase23) { // Concern: Stream socket transmission with control data: blob. // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTransmissionBlobWithControlMsg); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionBlobWithControlMsg); + #endif } -NTSCFG_TEST_CASE(24) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase24) { // Concern: Stream socket transmission with control data: dropped // Plan: #if defined(BSLS_PLATFORM_UNIX) - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTransmissionWithControlMsgDropped); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTransmissionWithControlMsgDropped); + #endif } -NTSCFG_TEST_CASE(25) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase25) { // Concern: validate that an incoming software timestamp and a file handle // can be simultaneously retrieved from one control message @@ -7800,7 +8009,7 @@ NTSCFG_TEST_CASE(25) NTSCFG_TEST_ASSERT(!error); } -NTSCFG_TEST_CASE(26) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase26) { // Concern: ntsu::SocketUtil::isSocket correctly indicates true if a // file descriptor is an alias for a socket, and false, after the file @@ -7835,7 +8044,7 @@ NTSCFG_TEST_CASE(26) } } -NTSCFG_TEST_CASE(27) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase27) { // Concern: Test that Linux MSG_ZEROCOPY mechanism is applied for DATAGRAM // sockets @@ -7884,95 +8093,94 @@ NTSCFG_TEST_CASE(27) NTSCFG_TEST_LOG_DEBUG << "Testing " << *transport << NTSCFG_TEST_LOG_END; - ntscfg::TestAllocator ta; - { - // Observation: if system MTU is 1500 bytes then maximum payload - // size of UDP IPV4 packet for which MSG_ZEROCOPY functionality can - // really work is 1472 bytes (because UDP header is 8 bytes and - // IPV4 header is 20 bytes). + // Observation: if system MTU is 1500 bytes then maximum payload + // size of UDP IPV4 packet for which MSG_ZEROCOPY functionality can + // really work is 1472 bytes (because UDP header is 8 bytes and + // IPV4 header is 20 bytes). - const int msgSize = 1472; - const int numMessagesToSend = 200; + const int msgSize = 1472; + const int numMessagesToSend = 200; - ntsa::Error error; - ntsa::Handle handle = ntsa::k_INVALID_HANDLE; + ntsa::Error error; + ntsa::Handle handle = ntsa::k_INVALID_HANDLE; - error = ntsu::SocketUtil::create(&handle, *transport); - NTSCFG_TEST_ASSERT(!error); + error = ntsu::SocketUtil::create(&handle, *transport); + NTSCFG_TEST_ASSERT(!error); - error = ntsu::SocketOptionUtil::setZeroCopy(handle, true); - NTSCFG_TEST_OK(error); + error = ntsu::SocketOptionUtil::setZeroCopy(handle, true); + NTSCFG_TEST_OK(error); - bsl::vector message(msgSize, &ta); - for (int i = 0; i < msgSize; ++i) { - message[i] = bsl::rand() % 100; - } - const ntsa::Data data( - ntsa::ConstBuffer(message.data(), message.size())); + bsl::vector message(msgSize, &ta); + for (int i = 0; i < msgSize; ++i) { + message[i] = bsl::rand() % 100; + } + const ntsa::Data data( + ntsa::ConstBuffer(message.data(), message.size())); - ntsa::Endpoint endpoint; - if (*transport == ntsa::Transport::e_UDP_IPV4_DATAGRAM) { - NTSCFG_TEST_TRUE(endpoint.parse("127.0.0.1:5555")); - // NTSCFG_TEST_TRUE(endpoint.parse("108.22.44.23:5555")); - } - else if (*transport == ntsa::Transport::e_UDP_IPV6_DATAGRAM) { - NTSCFG_TEST_TRUE(endpoint.parse("[::1]:5555")); - // NTSCFG_TEST_TRUE(endpoint.parse("[fe80::215:5dff:fe8d:6bd1]:5555")); - } + ntsa::Endpoint endpoint; + if (*transport == ntsa::Transport::e_UDP_IPV4_DATAGRAM) { + NTSCFG_TEST_TRUE(endpoint.parse("127.0.0.1:5555")); + // NTSCFG_TEST_TRUE(endpoint.parse("108.22.44.23:5555")); + } + else if (*transport == ntsa::Transport::e_UDP_IPV6_DATAGRAM) { + NTSCFG_TEST_TRUE(endpoint.parse("[::1]:5555")); + // NTSCFG_TEST_TRUE(endpoint.parse("[fe80::215:5dff:fe8d:6bd1]:5555")); + } - bsl::list feedback(&ta); - bsl::unordered_set sendIDs(&ta); + bsl::list feedback(&ta); + bsl::unordered_set sendIDs(&ta); - for (int i = 0; i < numMessagesToSend; ++i) { - ntsa::SendContext context; - ntsa::SendOptions options; - options.setEndpoint(endpoint); - options.setZeroCopy(true); + for (int i = 0; i < numMessagesToSend; ++i) { + ntsa::SendContext context; + ntsa::SendOptions options; + options.setEndpoint(endpoint); + options.setZeroCopy(true); - error = - ntsu::SocketUtil::send(&context, data, options, handle); - if (error == ntsa::Error(ntsa::Error::e_WOULD_BLOCK) || - error == ntsa::Error(ntsa::Error::e_LIMIT)) - { - --i; - continue; - } - NTSCFG_TEST_OK(error); - sendIDs.insert(i); + error = ntsu::SocketUtil::send(&context, data, options, handle); + if (error == ntsa::Error(ntsa::Error::e_WOULD_BLOCK) || + error == ntsa::Error(ntsa::Error::e_LIMIT)) + { + --i; + continue; + } + NTSCFG_TEST_OK(error); + sendIDs.insert(i); - NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); - NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); + NTSCFG_TEST_ASSERT(context.bytesSendable() == msgSize); + NTSCFG_TEST_ASSERT(context.bytesSent() == msgSize); - test::extractZeroCopyNotifications(&feedback, handle, &ta); - } + SocketUtilTest::extractZeroCopyNotifications(&feedback, + handle, + &ta); + } - // retrieve data from the socket error queue until all send system - // calls are acknowledged by the OS - while (!sendIDs.empty()) { - test::extractZeroCopyNotifications(&feedback, handle, &ta); + // retrieve data from the socket error queue until all send system + // calls are acknowledged by the OS + while (!sendIDs.empty()) { + SocketUtilTest::extractZeroCopyNotifications(&feedback, + handle, + &ta); - while (!feedback.empty()) { - const ntsa::ZeroCopy& zc = feedback.front(); - if (zc.from() == zc.thru()) { - NTSCFG_TEST_EQ(sendIDs.erase(zc.from()), 1); - } - else { - for (bsl::uint32_t i = zc.from(); i != (zc.thru() + 1); - ++i) - { - NTSCFG_TEST_EQ(sendIDs.erase(i), 1); - } + while (!feedback.empty()) { + const ntsa::ZeroCopy& zc = feedback.front(); + if (zc.from() == zc.thru()) { + NTSCFG_TEST_EQ(sendIDs.erase(zc.from()), 1); + } + else { + for (bsl::uint32_t i = zc.from(); i != (zc.thru() + 1); + ++i) + { + NTSCFG_TEST_EQ(sendIDs.erase(i), 1); } - feedback.pop_front(); } + feedback.pop_front(); } } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } #endif } -NTSCFG_TEST_CASE(28) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase28) { // Concern: Test that Linux MSG_ZEROCOPY mechanism is applied for STREAM // sockets @@ -7995,15 +8203,14 @@ NTSCFG_TEST_CASE(28) return; } } - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest(&test::testStreamSocketMsgZeroCopy); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketMsgZeroCopy); + #endif } -NTSCFG_TEST_CASE(29) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase29) { // Concern: Test TX timestamping functionality for DATAGRAM sockets #if defined(BSLS_PLATFORM_OS_LINUX) @@ -8019,15 +8226,14 @@ NTSCFG_TEST_CASE(29) return; } } - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest(&test::testDatagramSocketTxTimestamps); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTxTimestamps); + #endif } -NTSCFG_TEST_CASE(30) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase30) { // Concern: Test TX timestamping functionality for STREAM sockets #if defined(BSLS_PLATFORM_OS_LINUX) @@ -8043,15 +8249,14 @@ NTSCFG_TEST_CASE(30) return; } } - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest(&test::testStreamSocketTxTimestamps); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTxTimestamps); + #endif } -NTSCFG_TEST_CASE(31) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase31) { // Concern: Test TX timestamping an MSG_ZEROCOPY functionality for // DATAGRAM sockets @@ -8070,16 +8275,13 @@ NTSCFG_TEST_CASE(31) } } - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketTxTimestampsAndZeroCopy); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketTxTimestampsAndZeroCopy); + #endif } -NTSCFG_TEST_CASE(32) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase32) { // Concern: Test TX timestamping an MSG_ZEROCOPY functionality for // STREAM sockets @@ -8096,16 +8298,14 @@ NTSCFG_TEST_CASE(32) return; } } - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketTxTimestampsAndZeroCopy); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketTxTimestampsAndZeroCopy); + #endif } -NTSCFG_TEST_CASE(33) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase33) { // Concern: test that for stream sockets configured in a blocking mode // attempt to read data from the socket error queue does not lead to a @@ -8113,15 +8313,11 @@ NTSCFG_TEST_CASE(33) // in its receive buffer and call to ::recvmsg can return 0, // receiveNotifications does not hang in an endless loop. - ntscfg::TestAllocator ta; - { - test::executeStreamSocketTest( - &test::testStreamSocketReceiveNotifications); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeStreamSocketTest( + &SocketUtilTest::testStreamSocketReceiveNotifications); } -NTSCFG_TEST_CASE(34) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase34) { // Concern: test that for datagram sockets configured in a blocking mode // attempt to read data from the socket error queue does not lead to a @@ -8129,49 +8325,9 @@ NTSCFG_TEST_CASE(34) // in its receive buffer and call to ::recvmsg can return 0, // receiveNotifications does not hang in an endless loop. - ntscfg::TestAllocator ta; - { - test::executeDatagramSocketTest( - &test::testDatagramSocketReceiveNotifications); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); + SocketUtilTest::executeDatagramSocketTest( + &SocketUtilTest::testDatagramSocketReceiveNotifications); } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); - NTSCFG_TEST_REGISTER(2); - NTSCFG_TEST_REGISTER(3); - NTSCFG_TEST_REGISTER(4); - NTSCFG_TEST_REGISTER(5); - NTSCFG_TEST_REGISTER(6); - NTSCFG_TEST_REGISTER(7); - NTSCFG_TEST_REGISTER(8); - NTSCFG_TEST_REGISTER(9); - NTSCFG_TEST_REGISTER(10); - NTSCFG_TEST_REGISTER(11); - NTSCFG_TEST_REGISTER(12); - NTSCFG_TEST_REGISTER(13); - NTSCFG_TEST_REGISTER(14); - NTSCFG_TEST_REGISTER(15); - NTSCFG_TEST_REGISTER(16); - NTSCFG_TEST_REGISTER(17); - NTSCFG_TEST_REGISTER(18); - NTSCFG_TEST_REGISTER(19); - NTSCFG_TEST_REGISTER(20); - NTSCFG_TEST_REGISTER(21); - NTSCFG_TEST_REGISTER(22); - NTSCFG_TEST_REGISTER(23); - NTSCFG_TEST_REGISTER(24); - NTSCFG_TEST_REGISTER(25); - NTSCFG_TEST_REGISTER(26); - NTSCFG_TEST_REGISTER(27); - NTSCFG_TEST_REGISTER(28); - NTSCFG_TEST_REGISTER(29); - NTSCFG_TEST_REGISTER(30); - NTSCFG_TEST_REGISTER(31); - NTSCFG_TEST_REGISTER(32); - NTSCFG_TEST_REGISTER(33); - NTSCFG_TEST_REGISTER(34); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/groups/nts/ntsu/ntsu_timestamputil.t.cpp b/groups/nts/ntsu/ntsu_timestamputil.t.cpp index 07567e32..51b527cb 100644 --- a/groups/nts/ntsu/ntsu_timestamputil.t.cpp +++ b/groups/nts/ntsu/ntsu_timestamputil.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,13 +13,27 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include - #include +#include +BSLS_IDENT_RCSID(ntsu_timestamputil_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsu { + +// Provide tests for 'ntsu::TimestampUtil'. +class TimestampUtilTest +{ + public: + // TODO + static void verify(); +}; + +NTSCFG_TEST_FUNCTION(ntsu::TimestampUtilTest::verify) { bsl::string result; @@ -94,8 +108,5 @@ NTSCFG_TEST_CASE(1) } } -NTSCFG_TEST_DRIVER -{ - NTSCFG_TEST_REGISTER(1); -} -NTSCFG_TEST_DRIVER_END; +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/groups/nts/ntsu/ntsu_zerocopyutil.t.cpp b/groups/nts/ntsu/ntsu_zerocopyutil.t.cpp index d1bd4c3c..40dfff1c 100644 --- a/groups/nts/ntsu/ntsu_zerocopyutil.t.cpp +++ b/groups/nts/ntsu/ntsu_zerocopyutil.t.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Bloomberg Finance L.P. +// Copyright 2020-2023 Bloomberg Finance L.P. // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,14 +15,27 @@ #include +#include +BSLS_IDENT_RCSID(ntsu_zerocopyutil_t_cpp, "$Id$ $CSID$") + +#include + using namespace BloombergLP; -NTSCFG_TEST_CASE(1) +namespace BloombergLP { +namespace ntsu { + +// Provide tests for 'ntsu::ZeroCopyUtil'. +class ZeroCopyUtilTest { -} + public: + // TODO + static void verify(); +}; -NTSCFG_TEST_DRIVER +NTSCFG_TEST_FUNCTION(ntsu::ZeroCopyUtilTest::verify) { - NTSCFG_TEST_REGISTER(1); } -NTSCFG_TEST_DRIVER_END; + +} // close namespace ntsu +} // close namespace BloombergLP diff --git a/targets.cmake b/targets.cmake index e5a7a9a6..11dff1fa 100644 --- a/targets.cmake +++ b/targets.cmake @@ -272,7 +272,7 @@ if (${NTF_BUILD_WITH_NTS}) ntf_component(NAME ntso_poll) ntf_component(NAME ntso_pollset) ntf_component(NAME ntso_select) - ntf_component(NAME ntso_test) + ntf_component(NAME ntso_test PRIVATE) ntf_package_end(NAME ntso)