diff --git a/test/unittest/transport/TCPv4Tests.cpp b/test/unittest/transport/TCPv4Tests.cpp index 7c6ad31efb0..0f6218d19dd 100644 --- a/test/unittest/transport/TCPv4Tests.cpp +++ b/test/unittest/transport/TCPv4Tests.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -81,6 +82,60 @@ class TCPv4Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(TCPv4Tests, wrong_configuration_values) +{ + // Too big sendBufferSize + { + auto desc = descriptor; + desc.sendBufferSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // Too big receiveBufferSize + { + auto desc = descriptor; + desc.receiveBufferSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // Too big maxMessageSize + { + auto desc = descriptor; + desc.maxMessageSize = std::numeric_limits::max(); + TCPv4Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // maxMessageSize bigger than receiveBufferSize + { + auto desc = descriptor; + desc.receiveBufferSize = static_cast(std::numeric_limits::max()); + desc.maxMessageSize = desc.receiveBufferSize + 1; + TCPv4Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init(nullptr, desc.maxMessageSize)); + } + + // maxMessageSize bigger than sendBufferSize + { + auto desc = descriptor; + desc.sendBufferSize = static_cast(std::numeric_limits::max()); + desc.maxMessageSize = desc.sendBufferSize + 1; + TCPv4Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init(nullptr, desc.maxMessageSize)); + } + + // Buffer sizes automatically decrease + { + auto desc = descriptor; + desc.sendBufferSize = static_cast(std::numeric_limits::max()); + desc.receiveBufferSize = static_cast(std::numeric_limits::max()); + TCPv4Transport transportUnderTest(desc); + EXPECT_TRUE(transportUnderTest.init()); + } +} + TEST_F(TCPv4Tests, locators_with_kind_1_supported) { // Given diff --git a/test/unittest/transport/TCPv6Tests.cpp b/test/unittest/transport/TCPv6Tests.cpp index c88a79ff063..ddb5550238e 100644 --- a/test/unittest/transport/TCPv6Tests.cpp +++ b/test/unittest/transport/TCPv6Tests.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include @@ -83,6 +84,60 @@ class TCPv6Tests : public ::testing::Test std::unique_ptr receiverThread; }; +TEST_F(TCPv6Tests, wrong_configuration_values) +{ + // Too big sendBufferSize + { + auto desc = descriptor; + desc.sendBufferSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // Too big receiveBufferSize + { + auto desc = descriptor; + desc.receiveBufferSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // Too big maxMessageSize + { + auto desc = descriptor; + desc.maxMessageSize = std::numeric_limits::max(); + TCPv6Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init()); + } + + // maxMessageSize bigger than receiveBufferSize + { + auto desc = descriptor; + desc.receiveBufferSize = static_cast(std::numeric_limits::max()); + desc.maxMessageSize = desc.receiveBufferSize + 1; + TCPv6Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init(nullptr, desc.maxMessageSize)); + } + + // maxMessageSize bigger than sendBufferSize + { + auto desc = descriptor; + desc.sendBufferSize = static_cast(std::numeric_limits::max()); + desc.maxMessageSize = desc.sendBufferSize + 1; + TCPv6Transport transportUnderTest(desc); + EXPECT_FALSE(transportUnderTest.init(nullptr, desc.maxMessageSize)); + } + + // Buffer sizes automatically decrease + { + auto desc = descriptor; + desc.sendBufferSize = static_cast(std::numeric_limits::max()); + desc.receiveBufferSize = static_cast(std::numeric_limits::max()); + TCPv6Transport transportUnderTest(desc); + EXPECT_TRUE(transportUnderTest.init()); + } +} + TEST_F(TCPv6Tests, conversion_to_ip6_string) { Locator_t locator;