From 597d11ac7ce06ec7604fe2dcf56aa9a3cea51cf5 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Thu, 23 Nov 2023 09:12:02 +0100 Subject: [PATCH] Add participant factory tests Signed-off-by: Irene Bandera --- ddsrouter_core/test/CMakeLists.txt | 1 + ddsrouter_core/test/unittest/CMakeLists.txt | 48 ++++ .../test/unittest/ParticipantFactoryTest.cpp | 226 ++++++++++++++++++ docs/rst/notes/forthcoming_version.rst | 1 + 4 files changed, 276 insertions(+) create mode 100644 ddsrouter_core/test/unittest/CMakeLists.txt create mode 100644 ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp diff --git a/ddsrouter_core/test/CMakeLists.txt b/ddsrouter_core/test/CMakeLists.txt index ac1eb8010..603238d95 100644 --- a/ddsrouter_core/test/CMakeLists.txt +++ b/ddsrouter_core/test/CMakeLists.txt @@ -17,3 +17,4 @@ add_subdirectory(labels) # Add subdirectory with tests add_subdirectory(blackbox) +add_subdirectory(unittest) diff --git a/ddsrouter_core/test/unittest/CMakeLists.txt b/ddsrouter_core/test/unittest/CMakeLists.txt new file mode 100644 index 000000000..62fa473ff --- /dev/null +++ b/ddsrouter_core/test/unittest/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright 2023 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. + +############################ +# Participant Factory Test # +############################ + +set(TEST_NAME ParticipantFactoryTest) + +set(TEST_SOURCES + ParticipantFactoryTest.cpp + ${PROJECT_SOURCE_DIR}/src/cpp/core/ParticipantFactory.cpp + ) + +set(TEST_LIST + trivial + create_echo_participant + create_simple_participant + create_discovery_server_participant + create_initial_peers_participant + create_xml_participant + ) + +set(TEST_EXTRA_LIBRARIES + fastcdr + fastrtps + cpp_utils + ddspipe_core + ddspipe_participants + ) + +add_unittest_executable( + "${TEST_NAME}" + "${TEST_SOURCES}" + "${TEST_LIST}" + "${TEST_EXTRA_LIBRARIES}" + ) diff --git a/ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp b/ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp new file mode 100644 index 000000000..5938a6244 --- /dev/null +++ b/ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp @@ -0,0 +1,226 @@ +// Copyright 2023 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. + +/** + * @file ParticipantFactoryTest.cpp + * + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +using namespace eprosima; +using namespace eprosima::ddsrouter::core; + +class EchoTestClass : public ddspipe::participants::EchoParticipant +{ +public: + using ddspipe::participants::EchoParticipant::configuration_; // Make protected member accessible + EchoTestClass(std::shared_ptr echo_participant) + : ddspipe::participants::EchoParticipant(*echo_participant) + { + } +}; + +class SimpleTestClass : public ddspipe::participants::rtps::SimpleParticipant +{ +public: + using ddspipe::participants::rtps::SimpleParticipant::configuration_; // Make protected member accessible + SimpleTestClass(std::shared_ptr simple_participant) + : ddspipe::participants::rtps::SimpleParticipant(*simple_participant) + { + } +}; + +class DiscoveryServerTestClass : public ddspipe::participants::rtps::DiscoveryServerParticipant +{ +public: + using ddspipe::participants::rtps::DiscoveryServerParticipant::configuration_; // Make protected member accessible + DiscoveryServerTestClass(std::shared_ptr discovery_server_participant) + : ddspipe::participants::rtps::DiscoveryServerParticipant(*discovery_server_participant) + { + } +}; + +class InitialPeersTestClass : public ddspipe::participants::rtps::InitialPeersParticipant +{ +public: + using ddspipe::participants::rtps::InitialPeersParticipant::configuration_; // Make protected member accessible + InitialPeersTestClass(std::shared_ptr initial_peers_participant) + : ddspipe::participants::rtps::InitialPeersParticipant(*initial_peers_participant) + { + } +}; + +// class XMLTestClass : public ddspipe::participants::dds::XmlParticipant +// { +// public: +// using ddspipe::participants::dds::XmlParticipant::configuration_; // Make protected member accessible +// XMLTestClass(std::shared_ptr xml_participant) +// : ddspipe::participants::dds::XmlParticipant(*xml_participant) +// { +// } +// }; + +/** + * TODO + */ +TEST(ParticipantFactoryTest, trivial) +{ + ParticipantFactory participant_factory; +} + +/** + * TODO + */ +TEST(ParticipantFactoryTest, create_echo_participant) +{ + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + auto payload_pool = std::make_shared(); + auto discovery_database = std::make_shared(); + + std::shared_ptr i_participant = participant_factory.create_participant(types::ParticipantKind::echo, configuration, payload_pool, discovery_database); + + ASSERT_TRUE(i_participant) << "Failed to create I Participant"; + + std::shared_ptr echo_participant = std::dynamic_pointer_cast(i_participant); + + ASSERT_TRUE(echo_participant) << "Failed to create Echo Participant"; + + EchoTestClass participant(echo_participant); + + ASSERT_EQ(participant.configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(participant.configuration_->app_metadata, ""); + +} + +/** + * TODO + */ +TEST(ParticipantFactoryTest, create_simple_participant) +{ + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + auto payload_pool = std::make_shared(); + auto discovery_database = std::make_shared(); + + std::shared_ptr i_participant = participant_factory.create_participant(types::ParticipantKind::simple, configuration, payload_pool, discovery_database); + + std::shared_ptr simple_participant = std::dynamic_pointer_cast(i_participant); + + ASSERT_TRUE(simple_participant) << "Failed to create Simple Participant"; + + SimpleTestClass participant(simple_participant); + + ASSERT_EQ(participant.configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(participant.configuration_->app_metadata, ""); +} + +/** + * TODO + */ +TEST(ParticipantFactoryTest, create_discovery_server_participant) +{ + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + configuration->listening_addresses.insert(ddspipe::participants::testing::random_address()); + auto payload_pool = std::make_shared(); + auto discovery_database = std::make_shared(); + + std::shared_ptr i_participant = participant_factory.create_participant(types::ParticipantKind::discovery_server, configuration, payload_pool, discovery_database); + + std::shared_ptr discovery_server_participant = std::dynamic_pointer_cast(i_participant); + + ASSERT_TRUE(discovery_server_participant) << "Failed to create Discovery Server Participant"; + + DiscoveryServerTestClass participant(discovery_server_participant); + + ASSERT_EQ(participant.configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(participant.configuration_->app_metadata, ""); +} + +/** + * TODO + */ +TEST(ParticipantFactoryTest, create_initial_peers_participant) +{ + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + configuration->listening_addresses.insert(ddspipe::participants::testing::random_address()); + auto payload_pool = std::make_shared(); + auto discovery_database = std::make_shared(); + + std::shared_ptr i_participant = participant_factory.create_participant(types::ParticipantKind::initial_peers, configuration, payload_pool, discovery_database); + + std::shared_ptr initial_peers_participant = std::dynamic_pointer_cast(i_participant); + + ASSERT_TRUE(initial_peers_participant) << "Failed to create Initial Peers Participant"; + + InitialPeersTestClass participant(initial_peers_participant); + + ASSERT_EQ(participant.configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(participant.configuration_->app_metadata, ""); +} + +/** + * TODO + */ +TEST(ParticipantFactoryTest, create_xml_participant) +{ + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + auto payload_pool = std::make_shared(); + auto discovery_database = std::make_shared(); + + std::shared_ptr i_participant = participant_factory.create_participant(types::ParticipantKind::xml, configuration, payload_pool, discovery_database); + + std::shared_ptr xml_participant = std::dynamic_pointer_cast(i_participant); + + ASSERT_TRUE(xml_participant) << "Failed to create XML Participant"; +} + +int main( + int argc, + char** argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/docs/rst/notes/forthcoming_version.rst b/docs/rst/notes/forthcoming_version.rst index fee6ffdcb..c814341b3 100644 --- a/docs/rst/notes/forthcoming_version.rst +++ b/docs/rst/notes/forthcoming_version.rst @@ -15,6 +15,7 @@ The next release will include the following **Features**: * :ref:`Max Reception Rate `. * :ref:`Downsampling `. * Rename the `max-depth` under the `specs` tag to `history-depth`. +* Set `app_id` and `app_metadata` attributes in *eProsima DDS Router* participants. The next release will include the following **Bugfixes**: