Skip to content

Commit

Permalink
Refs #20849: Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <62831776+elianalf@users.noreply.github.com>
  • Loading branch information
elianalf committed May 14, 2024
1 parent 14c17fb commit 05b6154
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions test/blackbox/common/RTPSBlackboxTestsBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.h>
#include <fastdds/rtps/RTPSDomain.h>
#include <fastdds/rtps/transport/shared_mem/SharedMemTransportDescriptor.h>
#include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -1184,26 +1183,27 @@ TEST(RTPS, participant_ignore_local_endpoints_two_participants)
}

/* Maximum number of bytes allowed for an RTPS datagram generated by this participant. */
TEST(RTPS, Check_max_output_message_size_participant)
TEST(RTPS, max_output_message_size_participant)
{
/* Set up */
// Create the RTPSParticipants with the appropriate value for the property
auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
std::string segment_size_str = "1470";
const uint32_t segment_size = std::stoul(segment_size_str);
const uint32_t segment_size = 1470;
std::string segment_size_str = std::to_string(segment_size);
testTransport->messages_filter_ = [segment_size](eprosima::fastrtps::rtps::CDRMessage_t& datagram)
{
bool result = datagram.length > segment_size;
EXPECT_FALSE(result);
return result;
EXPECT_LE(datagram.length, segment_size);
return false;
};

// Create the RTPSReader
RTPSWithRegistrationReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
reader.init();
EXPECT_TRUE(reader.isInitialized());

eprosima::fastrtps::rtps::RTPSParticipantAttributes patt;
eprosima::fastrtps::rtps::RTPSParticipant* participant_reader =
eprosima::fastrtps::rtps::RTPSDomain::createParticipant(static_cast<uint32_t>(GET_PID()) % 230, patt);
ASSERT_NE(participant_reader, nullptr);
patt.useBuiltinTransports = false;
patt.userTransports.push_back(testTransport);
patt.useBuiltinTransports = false;
patt.userTransports.push_back(testTransport);
patt.properties.properties().emplace_back("fastdds.max_message_size", segment_size_str);
eprosima::fastrtps::rtps::RTPSParticipant* participant_writer =
eprosima::fastrtps::rtps::RTPSDomain::createParticipant(static_cast<uint32_t>(GET_PID()) % 230, patt);
Expand All @@ -1214,11 +1214,6 @@ TEST(RTPS, Check_max_output_message_size_participant)
writer.init();
EXPECT_TRUE(writer.isInitialized());

// Create the RTPSReader
RTPSWithRegistrationReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME, participant_reader);
reader.init();
EXPECT_TRUE(reader.isInitialized());

// Wait for discovery
writer.wait_discovery(1, std::chrono::seconds(2));
reader.wait_discovery(1, std::chrono::seconds(2));
Expand All @@ -1238,46 +1233,44 @@ TEST(RTPS, Check_max_output_message_size_participant)

/* Tear-down */
eprosima::fastrtps::rtps::RTPSDomain::removeRTPSParticipant(participant_writer);
eprosima::fastrtps::rtps::RTPSDomain::removeRTPSParticipant(participant_reader);
}

/* Maximum number of bytes allowed for an RTPS datagram generated by this writer. */
TEST(RTPS, Check_max_output_message_size_writer)
TEST(RTPS, max_output_message_size_writer)
{
std::string segment_size_str = "1470";
const uint32_t segment_size = std::stoul(segment_size_str);
const uint32_t segment_size = 1470;
std::string segment_size_str = std::to_string(segment_size);

auto testTransport = std::make_shared<eprosima::fastdds::rtps::test_UDPv4TransportDescriptor>();
testTransport->messages_filter_ = [segment_size](eprosima::fastrtps::rtps::CDRMessage_t& datagram)
{
bool result = datagram.length > segment_size;
EXPECT_FALSE(result);
return result;
EXPECT_LE(datagram.length, segment_size);
return false;
};
RTPSWithRegistrationWriter<HelloWorldPubSubType> writer_(TEST_TOPIC_NAME);
writer_.add_property("fastdds.max_message_size", segment_size_str).disable_builtin_transport().add_user_transport_to_pparams(testTransport).init();
ASSERT_TRUE(writer_.isInitialized());
RTPSWithRegistrationWriter<HelloWorldPubSubType> writer(TEST_TOPIC_NAME);
writer.add_property("fastdds.max_message_size", segment_size_str).disable_builtin_transport().add_user_transport_to_pparams(testTransport).init();
ASSERT_TRUE(writer.isInitialized());

RTPSWithRegistrationReader<HelloWorldPubSubType> reader_(TEST_TOPIC_NAME);
reader_.init();
EXPECT_TRUE(reader_.isInitialized());
RTPSWithRegistrationReader<HelloWorldPubSubType> reader(TEST_TOPIC_NAME);
reader.init();
EXPECT_TRUE(reader.isInitialized());

writer_.wait_discovery();
reader_.wait_discovery();
writer.wait_discovery();
reader.wait_discovery();

EXPECT_EQ(writer_.get_matched(), 1u);
EXPECT_EQ(reader_.get_matched(), 1u);
EXPECT_EQ(writer.get_matched(), 1u);
EXPECT_EQ(reader.get_matched(), 1u);

// Send samples
auto samples = default_large_helloworld_data_generator(1);
reader_.expected_data(samples);
reader_.startReception();
writer_.send(samples);
reader.expected_data(samples);
reader.startReception();
writer.send(samples);
EXPECT_TRUE(samples.empty());

// Wait for reception
reader_.block_for_all(std::chrono::seconds(1));
EXPECT_EQ(reader_.getReceivedCount(), 1u);
reader.block_for_all(std::chrono::seconds(1));
EXPECT_EQ(reader.getReceivedCount(), 1u);

}

Expand Down

0 comments on commit 05b6154

Please sign in to comment.