Skip to content

Commit

Permalink
Test RTPSParticipant creation fails if SHM MaxMessageSize is lower th…
Browse files Browse the repository at this point in the history
…an minimum

Signed-off-by: Eugenio Collado <[email protected]>
  • Loading branch information
EugenioCollado committed Dec 16, 2024
1 parent a92ba0f commit 1b90f21
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/unittest/rtps/participant/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_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)
69 changes: 69 additions & 0 deletions test/unittest/rtps/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
@@ -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 <gmock/gmock.h>
#include <gtest/gtest.h>

#include <fastdds/rtps/RTPSDomain.hpp>
#include <fastdds/rtps/participant/RTPSParticipant.hpp>
#include <fastdds/rtps/writer/RTPSWriter.hpp>
#include <fastdds/rtps/history/IPayloadPool.hpp>
#include <fastdds/rtps/history/WriterHistory.hpp>

#include <rtps/writer/BaseWriter.hpp>


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();
}

0 comments on commit 1b90f21

Please sign in to comment.