From 01bf69f058c82f210ff0140d74d9558c06db42dd Mon Sep 17 00:00:00 2001 From: Eugenio Collado Date: Mon, 9 Dec 2024 16:24:32 +0100 Subject: [PATCH] Test RTPSParticipant creation fails if SHM MaxMessageSize is lower than minimum Signed-off-by: Eugenio Collado --- test/unittest/CMakeLists.txt | 1 + test/unittest/rtps/participant/CMakeLists.txt | 29 ++++++++ .../rtps/participant/ParticipantTests.cpp | 69 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 test/unittest/rtps/participant/CMakeLists.txt create mode 100644 test/unittest/rtps/participant/ParticipantTests.cpp diff --git a/test/unittest/CMakeLists.txt b/test/unittest/CMakeLists.txt index 743d7d4adce..a5af4a6be02 100644 --- a/test/unittest/CMakeLists.txt +++ b/test/unittest/CMakeLists.txt @@ -39,6 +39,7 @@ if(NOT QNX) endif() add_subdirectory(rtps/history) add_subdirectory(rtps/network) +add_subdirectory(rtps/participant) add_subdirectory(rtps/persistence) add_subdirectory(rtps/reader) add_subdirectory(rtps/resources/timedevent) diff --git a/test/unittest/rtps/participant/CMakeLists.txt b/test/unittest/rtps/participant/CMakeLists.txt new file mode 100644 index 00000000000..75068c6fa27 --- /dev/null +++ b/test/unittest/rtps/participant/CMakeLists.txt @@ -0,0 +1,29 @@ +# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(PARTICIPANTTESTS_SOURCE ParticipantTests.cpp) + +add_executable(RTPSParticipantTests ${PARTICIPANTTESTS_SOURCE}) +target_compile_definitions(RTPSParticipantTests PRIVATE + BOOST_ASIO_STANDALONE + ASIO_STANDALONE + $<$>,$>:__DEBUG> + $<$:__INTERNALDEBUG> # Internal debug activated. + ) +target_include_directories(RTPSParticipantTests PRIVATE + ${Asio_INCLUDE_DIR}) +target_link_libraries(RTPSParticipantTests fastcdr fastdds foonathan_memory + GTest::gmock + ${CMAKE_DL_LIBS}) +gtest_discover_tests(RTPSParticipantTests) diff --git a/test/unittest/rtps/participant/ParticipantTests.cpp b/test/unittest/rtps/participant/ParticipantTests.cpp new file mode 100644 index 00000000000..f37c49392b3 --- /dev/null +++ b/test/unittest/rtps/participant/ParticipantTests.cpp @@ -0,0 +1,69 @@ +// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include +#include +#include +#include +#include + +#include + + +namespace eprosima { +namespace fastdds { +namespace rtps { + +using namespace testing; + +RTPSParticipant* transport_size_participant_init( + uint32_t max_message_size) +{ + uint32_t domain_id = 0; + std::string max_message_size_str = std::to_string(max_message_size); + + RTPSParticipantAttributes p_attr; + BuiltinTransportsOptions options; + options.maxMessageSize = max_message_size; + p_attr.setup_transports(BuiltinTransports::SHM, options); + RTPSParticipant* participant = RTPSDomain::createParticipant( + domain_id, true, p_attr); + + return participant; +} + +/** + * This test checks that the participant is not created when the max message size is smaller than the PDP package size + * but it is properly created when the max message size is bigger than the PDP package size. + */ +TEST(RTPSParticipantTests, participant_creation_message_size) +{ + ASSERT_EQ(transport_size_participant_init(100), nullptr); + ASSERT_NE(transport_size_participant_init(1000), nullptr); +} + +} // namespace rtps +} // namespace fastdds +} // namespace eprosima + +int main( + int argc, + char** argv) +{ + testing::InitGoogleMock(&argc, argv); + return RUN_ALL_TESTS(); +}