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 8964634 commit 3a90ced
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
62 changes: 62 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,67 @@ class TCPv4Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(TCPv4Tests, wrong_configuration_values)
{
// Too big sendBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big receiveBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.receiveBufferSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big maxMessageSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = std::numeric_limits<uint32_t>::max();
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than receiveBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.receiveBufferSize = 5;
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than sendBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.sendBufferSize = 5;
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Buffer sizes automatically decrease
{
auto wrong_descriptor = descriptor;
wrong_descriptor.sendBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.maxMessageSize = 1470;
TCPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}
}

TEST_F(TCPv4Tests, locators_with_kind_1_supported)
{
// Given
Expand Down
62 changes: 62 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,67 @@ class TCPv6Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(TCPv6Tests, wrong_configuration_values)
{
// Too big sendBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big receiveBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.receiveBufferSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Too big maxMessageSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = std::numeric_limits<uint32_t>::max();
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than receiveBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.receiveBufferSize = 5;
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// maxMessageSize bigger than sendBufferSize
{
auto wrong_descriptor = descriptor;
wrong_descriptor.maxMessageSize = 10;
wrong_descriptor.sendBufferSize = 5;
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

// Buffer sizes automatically decrease
{
auto wrong_descriptor = descriptor;
wrong_descriptor.sendBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.receiveBufferSize = static_cast<uint32_t>(std::numeric_limits<int32_t>::max());
wrong_descriptor.maxMessageSize = 1470;
TCPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}
}

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

0 comments on commit 3a90ced

Please sign in to comment.