Skip to content

Commit

Permalink
Refs #20972. Add UDP 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 9, 2024
1 parent 68e1b51 commit f61bafd
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/unittest/transport/UDPv4Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

#include <asio.hpp>
#include <gtest/gtest.h>

#include <fastdds/dds/log/Log.hpp>
#include <fastrtps/transport/UDPv4TransportDescriptor.h>
#include <fastrtps/utils/IPFinder.h>
#include <fastrtps/utils/IPLocator.h>
Expand Down Expand Up @@ -75,6 +77,68 @@ class UDPv4Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(UDPv4Tests, wrong_configuration)
{
// Too big sendBufferSize
{
UDPv4TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

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

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

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

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

// Buffer sizes automatically decrease
{
UDPv4TransportDescriptor wrong_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;
UDPv4Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

}

TEST_F(UDPv4Tests, locators_with_kind_1_supported)
{
// Given
Expand Down
63 changes: 63 additions & 0 deletions test/unittest/transport/UDPv6Tests.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,68 @@ class UDPv6Tests : public ::testing::Test
std::unique_ptr<std::thread> receiverThread;
};

TEST_F(UDPv6Tests, wrong_configuration)
{
// Too big sendBufferSize
{
UDPv6TransportDescriptor wrong_descriptor;
wrong_descriptor.sendBufferSize = std::numeric_limits<uint32_t>::max();
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_FALSE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

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

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

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

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

// Buffer sizes automatically decrease
{
UDPv6TransportDescriptor wrong_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;
UDPv6Transport transportUnderTest(wrong_descriptor);
ASSERT_TRUE(transportUnderTest.init());
eprosima::fastdds::dds::Log::Flush();
}

}

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

0 comments on commit f61bafd

Please sign in to comment.