From 4625e588b33297c0031d65f61e78095265e23ff9 Mon Sep 17 00:00:00 2001 From: Matt Millett Date: Tue, 8 Oct 2024 09:15:44 -0400 Subject: [PATCH] Migrate nts test drivers to new design --- groups/nts/ntsa/ntsa_datatype.t.cpp | 2 +- groups/nts/ntsa/ntsa_interest.t.cpp | 90 +- groups/nts/ntscfg/ntscfg_test.h | 26 +- groups/nts/ntsd/ntsd_datautil.t.cpp | 45 +- groups/nts/ntsd/ntsd_message.t.cpp | 45 +- groups/nts/ntsd/ntsd_messageheader.t.cpp | 45 +- groups/nts/ntsd/ntsd_messageparser.t.cpp | 48 +- groups/nts/ntsd/ntsd_messagetype.t.cpp | 45 +- groups/nts/ntsf/ntsf_system.t.cpp | 889 ++++++++-------- groups/nts/ntso/ntso_devpoll.t.cpp | 110 +- groups/nts/ntso/ntso_epoll.t.cpp | 110 +- groups/nts/ntso/ntso_eventport.t.cpp | 110 +- groups/nts/ntso/ntso_kqueue.t.cpp | 110 +- groups/nts/ntso/ntso_poll.t.cpp | 110 +- groups/nts/ntso/ntso_pollset.t.cpp | 110 +- groups/nts/ntso/ntso_select.t.cpp | 110 +- groups/nts/ntso/ntso_test.cpp | 1017 ------------------ groups/nts/ntso/ntso_test.h | 1027 +++++++++++++++++- groups/nts/ntso/ntso_test.t.cpp | 25 +- groups/nts/ntso/package/ntso.mem | 1 - groups/nts/ntsu/ntsu_adapterutil.t.cpp | 156 ++- groups/nts/ntsu/ntsu_resolverutil.t.cpp | 1042 +++++++++---------- groups/nts/ntsu/ntsu_socketoptionutil.t.cpp | 109 +- groups/nts/ntsu/ntsu_socketutil.t.cpp | 843 +++++++++------ groups/nts/ntsu/ntsu_timestamputil.t.cpp | 29 +- groups/nts/ntsu/ntsu_zerocopyutil.t.cpp | 25 +- targets.cmake | 2 +- 27 files changed, 3152 insertions(+), 3129 deletions(-) diff --git a/groups/nts/ntsa/ntsa_datatype.t.cpp b/groups/nts/ntsa/ntsa_datatype.t.cpp index 80f46d16..614caf5e 100644 --- a/groups/nts/ntsa/ntsa_datatype.t.cpp +++ b/groups/nts/ntsa/ntsa_datatype.t.cpp @@ -26,7 +26,7 @@ namespace BloombergLP { namespace ntsa { // Provide tests for 'ntsa::DataType'. -class DataTypeTets +class DataTypeTest { public: // TODO diff --git a/groups/nts/ntsa/ntsa_interest.t.cpp b/groups/nts/ntsa/ntsa_interest.t.cpp index 31f9f68c..8bed6b27 100644 --- a/groups/nts/ntsa/ntsa_interest.t.cpp +++ b/groups/nts/ntsa/ntsa_interest.t.cpp @@ -226,7 +226,7 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) NTSCFG_TEST_TRUE(interestSet.empty()); for (ntsa::Handle i = k_SOCKET_MIN; i <= k_SOCKET_MAX; ++i) { - test::ensureNotFound(interestSet, i); + InterestTest::ensureNotFound(interestSet, i); } // Attach each socket to the interest set. @@ -237,10 +237,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureNotFound(interestSet, j); + InterestTest::ensureNotFound(interestSet, j); } } } @@ -253,10 +253,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -269,10 +269,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } } } @@ -285,10 +285,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -301,10 +301,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } } } @@ -318,10 +318,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -332,10 +332,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } else { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } } } @@ -349,10 +349,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } else { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } } } @@ -363,10 +363,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } } } @@ -380,10 +380,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -394,10 +394,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } else { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } } } @@ -411,10 +411,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } else { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } } } @@ -425,10 +425,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } } } @@ -442,10 +442,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -456,10 +456,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } else { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } } } @@ -473,10 +473,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } else { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } } } @@ -487,10 +487,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantReadable(interestSet, j); + InterestTest::ensureWantReadable(interestSet, j); } } } @@ -504,10 +504,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } @@ -518,10 +518,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } else { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } } } @@ -535,10 +535,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } else { - test::ensureWantBoth(interestSet, j); + InterestTest::ensureWantBoth(interestSet, j); } } } @@ -549,10 +549,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } else { - test::ensureWantWritable(interestSet, j); + InterestTest::ensureWantWritable(interestSet, j); } } } @@ -565,10 +565,10 @@ NTSCFG_TEST_FUNCTION(ntsa::InterestTest::verifyCase2) for (ntsa::Handle j = k_SOCKET_MIN; j <= k_SOCKET_MAX; ++j) { if (j <= i) { - test::ensureNotFound(interestSet, j); + InterestTest::ensureNotFound(interestSet, j); } else { - test::ensureWantNone(interestSet, j); + InterestTest::ensureWantNone(interestSet, j); } } } diff --git a/groups/nts/ntscfg/ntscfg_test.h b/groups/nts/ntscfg/ntscfg_test.h index 3655d4f2..957ab773 100644 --- a/groups/nts/ntscfg/ntscfg_test.h +++ b/groups/nts/ntscfg/ntscfg_test.h @@ -13,6 +13,7 @@ BSLS_IDENT("$Id: $") #include #include #include +#include #include #include #include @@ -43,6 +44,8 @@ BSLS_IDENT("$Id: $") #include #include #include +#include +#include #include #include #include @@ -50,6 +53,7 @@ BSLS_IDENT("$Id: $") #include #include #include +#include #include #include #include @@ -819,24 +823,24 @@ int main(int argc, char** argv) int i = 1; while (i < argc) { - const char* argvValue = argv[i]; + const char* arg = argv[i]; - if ((0 == bsl::strcmp(argv[i], "-?")) || - (0 == bsl::strcmp(argv[i], "--help"))) + if ((0 == bsl::strcmp(arg, "-?")) || + (0 == bsl::strcmp(arg, "--help"))) { BloombergLP::ntscfg::TestUtil::help(); return 1; } - if ((0 == bsl::strcmp(argv[i], "-l")) || - (0 == bsl::strcmp(argv[i], "--list"))) + if ((0 == bsl::strcmp(arg, "-l")) || + (0 == bsl::strcmp(arg, "--list"))) { BloombergLP::ntscfg::TestUtil::list(); return 0; } - if ((0 == bsl::strcmp(argv[i], "-v")) || - (0 == bsl::strcmp(argv[i], "--verbosity"))) + if ((0 == bsl::strcmp(arg, "-v")) || + (0 == bsl::strcmp(arg, "--verbosity"))) { ++i; if (i >= argc) { @@ -845,7 +849,7 @@ int main(int argc, char** argv) } int level; - if (BloombergLP::ntscfg::TestUtil::parseInt(&level, argv[i])) { + if (BloombergLP::ntscfg::TestUtil::parseInt(&level, arg)) { BloombergLP::ntscfg::testVerbosity = level; } else { @@ -858,19 +862,19 @@ int main(int argc, char** argv) continue; } - if (0 == bsl::strcmp(argv[i], "--concern")) { + if (0 == bsl::strcmp(arg, "--concern")) { ++i; if (i >= argc) { BloombergLP::ntscfg::TestUtil::help(); return 1; } - concern.makeValue(bsl::string(argv[i])); + concern.makeValue(bsl::string(arg)); ++i; continue; } if (concern.isNull()) { - concern.makeValue(bsl::string(argv[i])); + concern.makeValue(bsl::string(arg)); } else { BloombergLP::ntscfg::testVerbosity++; 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.t.cpp b/groups/nts/ntsf/ntsf_system.t.cpp index 5d6d0ab6..45c2d4cc 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(); + + // TODO + static void verifyCase6(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase7(); +}; -NTSCFG_TEST_CASE(1) +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,146 +233,142 @@ 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 + // 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 // and both sockets specify SO_REUSEADDR. // @@ -373,350 +380,332 @@ 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/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..40fec3de 100644 --- a/groups/nts/ntso/ntso_eventport.t.cpp +++ b/groups/nts/ntso/ntso_eventport.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_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..2d6238f9 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 { @@ -46,7 +37,8 @@ namespace ntso { // This struct is thread safe. /// /// @ingroup module_ntso -struct Test { +struct Test +{ /// Define a type alias for a vector of reactors. typedef bsl::vector > ReactorVector; @@ -97,6 +89,1021 @@ 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..2c5fdb2f 100644 --- a/groups/nts/ntsu/ntsu_resolverutil.t.cpp +++ b/groups/nts/ntsu/ntsu_resolverutil.t.cpp @@ -14,77 +14,120 @@ // 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(); + + // 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(); -NTSCFG_TEST_CASE(2) + // 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 +135,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; - - 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.setIpAddressType(ntsa::IpAddressType::e_V4); + bsl::vector ipAddressList(NTSCFG_TEST_ALLOCATOR); + ntsa::IpAddressOptions ipAddressOptions; - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V4); - 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; + ntsa::Error error; - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + // TODO: 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_V6); + ipAddressOptions.setIpAddressType(ntsa::IpAddressType::e_V6); - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: NTSCFG_TEST_FALSE(error); + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + // TODO: 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; - - // 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 +252,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 +292,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; + 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.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); + ipAddressOptions.setTransport(ntsa::Transport::e_UDP_IPV4_DATAGRAM); - error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - NTSCFG_TEST_FALSE(error); + 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; - - 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 +332,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; + ntsa::Error error; - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - 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::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: NTSCFG_TEST_FALSE(error); + error = ntsu::ResolverUtil::getIpAddress(&ipAddressList, + "dns.google.com", + ipAddressOptions); + // TODO: 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; - - // 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 +373,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; + ntsa::Error error; - bsl::set ipAddressSet(&ta); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + bsl::set ipAddressSet(NTSCFG_TEST_ALLOCATOR); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); + // TODO: ipAddressSet.insert(ntsa::IpAddress("???")); - // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); + // TODO: NTSCFG_TEST_EQ(ipAddressSet.size(), 2); - 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::getIpAddress(&ipAddressList, - "dns.google.com", - ipAddressOptions); - // TODO: 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); + // 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 +439,46 @@ 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 +487,39 @@ 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 +528,38 @@ 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 +568,234 @@ NTSCFG_TEST_CASE(14) return; } - ntscfg::TestAllocator ta; - { - ntsa::Error error; - - bsl::string serviceName(&ta); - error = ntsu::ResolverUtil::getServiceName( - &serviceName, - test::IANA_SERVICE_TCP_PORT, - ntsa::Transport::e_TCP_IPV4_STREAM); + ntsa::Error error; - 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.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.t.cpp b/groups/nts/ntsu/ntsu_socketutil.t.cpp index eaf5b9f8..ec4848e8 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 @@ -40,7 +32,6 @@ #if defined(BSLS_PLATFORM_OS_LINUX) #include - #include #include #include @@ -49,24 +40,346 @@ 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(); + + // TODO + static void verifyCase14(); + + // 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(); -// [ 1] -//----------------------------------------------------------------------------- -// [ 1] -//----------------------------------------------------------------------------- + // TODO + static void verifyCase23(); -namespace test { + // 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 +397,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 +424,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 +438,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,7 +452,7 @@ bool supportsTxTimestamps(ntsa::Handle socket) #endif -void extractZeroCopyNotifications(bsl::list* zerocopy, +void SocketUtilTest::extractZeroCopyNotifications(bsl::list* result, ntsa::Handle handle, bslma::Allocator* allocator) { @@ -158,11 +471,11 @@ 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, +void SocketUtilTest::extractTimestampNotifications(bsl::list* result, ntsa::Handle handle, bslma::Allocator* allocator) { @@ -181,11 +494,11 @@ 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, +void SocketUtilTest::extractNotifications(bsl::list* result, ntsa::Handle handle, bslma::Allocator* allocator) { @@ -203,36 +516,12 @@ 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 +675,8 @@ 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,7 +1025,8 @@ void testStreamSocketTransmissionMultipleBuffers( } } -void testStreamSocketTransmissionBlob(ntsa::Transport::Value transport, +void SocketUtilTest::testStreamSocketTransmissionBlob( + ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, bslma::Allocator* allocator) @@ -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,7 +1278,7 @@ void testStreamSocketTransmissionWithControlMsgDropped( } } -void testStreamSocketTransmissionFile(ntsa::Transport::Value transport, +void SocketUtilTest::testStreamSocketTransmissionFile(ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, bslma::Allocator* allocator) @@ -1138,7 +1429,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 +1489,7 @@ void testDatagramSocketTransmissionSingleBuffer( } } -void testDatagramSocketTransmissionSingleBufferWithControlMsg( +void SocketUtilTest::testDatagramSocketTransmissionSingleBufferWithControlMsg( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1296,7 +1587,7 @@ void testDatagramSocketTransmissionSingleBufferWithControlMsg( } } -void testDatagramSocketTransmissionMultipleBuffers( +void SocketUtilTest::testDatagramSocketTransmissionMultipleBuffers( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1380,7 +1671,7 @@ void testDatagramSocketTransmissionMultipleBuffers( } } -void testDatagramSocketTransmissionBlob(ntsa::Transport::Value transport, +void SocketUtilTest::testDatagramSocketTransmissionBlob(ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, ntsa::Handle client, @@ -1440,7 +1731,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 +1831,7 @@ void testDatagramSocketTransmissionBlobWithControlMsg( } } -void testDatagramSocketTransmissionWithControlMsgDropped( +void SocketUtilTest::testDatagramSocketTransmissionWithControlMsgDropped( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1652,7 +1943,7 @@ void testDatagramSocketTransmissionWithControlMsgDropped( } } -void testDatagramSocketTransmissionSingleMessage( +void SocketUtilTest::testDatagramSocketTransmissionSingleMessage( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1742,7 +2033,7 @@ void testDatagramSocketTransmissionSingleMessage( #endif } -void testDatagramSocketTransmissionMultipleMessages( +void SocketUtilTest::testDatagramSocketTransmissionMultipleMessages( ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, @@ -1759,7 +2050,7 @@ void testDatagramSocketTransmissionMultipleMessages( char DATA[] = "123456789"; - typedef test::Storage StorageBuffer; + typedef SocketUtilTest::Storage StorageBuffer; StorageBuffer clientBuffer0[NUM_MESSAGES]; StorageBuffer clientBuffer1[NUM_MESSAGES]; @@ -1903,7 +2194,8 @@ void testDatagramSocketTransmissionMultipleMessages( } } -void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, +void SocketUtilTest::testStreamSocketMsgZeroCopy( + ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, bslma::Allocator* allocator) @@ -1953,7 +2245,7 @@ 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 +2269,7 @@ 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,7 +2289,7 @@ void testStreamSocketMsgZeroCopy(ntsa::Transport::Value transport, } } -void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, +void SocketUtilTest::testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, ntsa::Handle server, const ntsa::Endpoint& serverEndpoint, ntsa::Handle client, @@ -2064,7 +2356,7 @@ 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 +2380,7 @@ 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,7 +2397,7 @@ void testDatagramSocketTxTimestamps(ntsa::Transport::Value transport, } } -void testStreamSocketTxTimestamps(ntsa::Transport::Value transport, +void SocketUtilTest::testStreamSocketTxTimestamps(ntsa::Transport::Value transport, ntsa::Handle server, ntsa::Handle client, bslma::Allocator* allocator) @@ -2175,7 +2467,7 @@ 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 +2491,7 @@ 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 +2508,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 +2591,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 +2615,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 +2653,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 +2736,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 +2760,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 +2798,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 +2856,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 +2917,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 +3170,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,128 +3368,94 @@ 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; @@ -3294,17 +3552,13 @@ NTSCFG_TEST_CASE(12) 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; // Create a blocking socket, bind it to any port on the loopback @@ -3498,11 +3752,9 @@ NTSCFG_TEST_CASE(13) error = ntsu::SocketUtil::close(server); NTSCFG_TEST_ASSERT(!error); - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(14) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase14) { // Concern: Binding datagram sockets. // @@ -3577,8 +3829,7 @@ NTSCFG_TEST_CASE(14) // sendto(:) 0.0.0.0: // connect(:) : - ntscfg::TestAllocator ta; - { + ntsa::Error error; const bool k_REUSE_ADDRESS = false; @@ -5566,17 +5817,13 @@ NTSCFG_TEST_CASE(14) } } #endif - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(15) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase15) { // Concern: Binding stream sockets. // Plan: - ntscfg::TestAllocator ta; - { ntsa::Error error; const bool k_REUSE_ADDRESS = false; @@ -6847,16 +7094,12 @@ NTSCFG_TEST_CASE(15) } } #endif - } - NTSCFG_TEST_ASSERT(ta.numBlocksInUse() == 0); } -NTSCFG_TEST_CASE(16) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase16) { // Concern: Listing system sockets. - ntscfg::TestAllocator ta; - { ntsa::Error error; ntsa::Handle listener; @@ -6903,11 +7146,9 @@ NTSCFG_TEST_CASE(16) 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 +7496,7 @@ NTSCFG_TEST_CASE(17) } } -NTSCFG_TEST_CASE(18) +NTSCFG_TEST_FUNCTION(ntsu::SocketUtilTest::verifyCase18) { // Concern: Create datagram socket pairs. // @@ -7598,97 +7839,85 @@ 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 +8029,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 +8064,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,8 +8113,7 @@ 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 @@ -7943,13 +8171,13 @@ NTSCFG_TEST_CASE(27) 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); + SocketUtilTest::extractZeroCopyNotifications(&feedback, handle, &ta); while (!feedback.empty()) { const ntsa::ZeroCopy& zc = feedback.front(); @@ -7966,13 +8194,11 @@ NTSCFG_TEST_CASE(27) 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 +8221,13 @@ 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 +8243,13 @@ 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 +8265,13 @@ 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 +8290,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 +8313,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 +8328,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 +8340,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)