Skip to content

Commit

Permalink
Refs #20972. Add TCP unit tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
  • Loading branch information
MiguelCompany committed May 10, 2024
1 parent f61bafd commit ee59b26
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/unittest/transport/TCPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
#include <memory>
#include <thread>

Expand Down Expand Up @@ -81,6 +82,60 @@ class TCPv4Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(TCPv4Tests, wrong_configuration_values)
{
// Too big sendBufferSize
{
auto desc = descriptor;
desc.sendBufferSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// Too big receiveBufferSize
{
auto desc = descriptor;
desc.receiveBufferSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// Too big maxMessageSize
{
auto desc = descriptor;
desc.maxMessageSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// maxMessageSize bigger than receiveBufferSize
{
auto desc = descriptor;
desc.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::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<uint32_t>(std::numeric_limits<int32_t>::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<uint32_t>(std::numeric_limits<int32_t>::max());
desc.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
TCPv4Transport transportUnderTest(desc);
EXPECT_TRUE(transportUnderTest.init());
}
}

TEST_F(TCPv4Tests, locators_with_kind_1_supported)
{
// Given
Expand Down
55 changes: 55 additions & 0 deletions test/unittest/transport/TCPv6Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
#include <memory>
#include <thread>

Expand Down Expand Up @@ -83,6 +84,60 @@ class TCPv6Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(TCPv6Tests, wrong_configuration_values)
{
// Too big sendBufferSize
{
auto desc = descriptor;
desc.sendBufferSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// Too big receiveBufferSize
{
auto desc = descriptor;
desc.receiveBufferSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// Too big maxMessageSize
{
auto desc = descriptor;
desc.maxMessageSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(desc);
EXPECT_FALSE(transportUnderTest.init());
}

// maxMessageSize bigger than receiveBufferSize
{
auto desc = descriptor;
desc.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::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<uint32_t>(std::numeric_limits<int32_t>::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<uint32_t>(std::numeric_limits<int32_t>::max());
desc.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
TCPv6Transport transportUnderTest(desc);
EXPECT_TRUE(transportUnderTest.init());
}
}

TEST_F(TCPv6Tests, conversion_to_ip6_string)
{
Locator_t locator;
Expand Down

0 comments on commit ee59b26

Please sign in to comment.