diff --git a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp index 8ed9b46b0..ec8b22b08 100644 --- a/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp +++ b/ddsrouter_core/src/cpp/core/ParticipantFactory.cpp @@ -50,6 +50,9 @@ generic_create_participant( const std::shared_ptr& participant_configuration, Args... args) { + participant_configuration->app_id = "DDS_ROUTER"; + participant_configuration->app_metadata = ""; + std::shared_ptr conf_ = std::dynamic_pointer_cast( participant_configuration); 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/labels/XTSAN.list b/ddsrouter_core/test/labels/XTSAN.list index 6131efbfd..41b0d86a3 100644 --- a/ddsrouter_core/test/labels/XTSAN.list +++ b/ddsrouter_core/test/labels/XTSAN.list @@ -27,3 +27,7 @@ ImplementationsTest.pair_implementation ImplementationsTest.pair_implementation_with_topic ImplementationsTest.all_implementations ImplementationsTest.duplicated_ids_negative +ParticipantFactoryTest.create_simple_participant +ParticipantFactoryTest.create_discovery_server_participant +ParticipantFactoryTest.create_initial_peers_participant +ParticipantFactoryTest.create_xml_participant diff --git a/ddsrouter_core/test/unittest/CMakeLists.txt b/ddsrouter_core/test/unittest/CMakeLists.txt new file mode 100644 index 000000000..f36034880 --- /dev/null +++ b/ddsrouter_core/test/unittest/CMakeLists.txt @@ -0,0 +1,47 @@ +# 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 + 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..0b421c9d5 --- /dev/null +++ b/ddsrouter_core/test/unittest/ParticipantFactoryTest.cpp @@ -0,0 +1,252 @@ +// 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; + +/** + * This class is a subclass of ddspipe::participants::EchoParticipant. + * It provides public access to the protected member 'configuration_' from its base class + * ddspipe::participants::EchoParticipant. + */ +class EchoTestClass : public ddspipe::participants::EchoParticipant +{ +public: + + using ddspipe::participants::EchoParticipant::configuration_; // Make protected member accessible +}; + +/** + * This class is a subclass of ddspipe::participants::SimpleParticipant. + * It provides public access to the protected member 'configuration_' from its base class + * ddspipe::participants::SimpleParticipant. + */ +class SimpleTestClass : public ddspipe::participants::rtps::SimpleParticipant +{ +public: + + using ddspipe::participants::rtps::SimpleParticipant::configuration_; // Make protected member accessible +}; + +/** + * This class is a subclass of ddspipe::participants::DiscoveryServerParticipant. + * It provides public access to the protected member 'configuration_' from its base class + * ddspipe::participants::DiscoveryServerParticipant. + */ +class DiscoveryServerTestClass : public ddspipe::participants::rtps::DiscoveryServerParticipant +{ +public: + + using ddspipe::participants::rtps::DiscoveryServerParticipant::configuration_; // Make protected member accessible +}; + +/** + * This class is a subclass of ddspipe::participants::InitialPeersParticipant. + * It provides public access to the protected member 'configuration_' from its base class + * ddspipe::participants::InitialPeersParticipant. + */ +class InitialPeersTestClass : public ddspipe::participants::rtps::InitialPeersParticipant +{ +public: + + using ddspipe::participants::rtps::InitialPeersParticipant::configuration_; // Make protected member accessible +}; + +/** + * This class is a subclass of ddspipe::participants::XmlParticipant. + * It provides public access to the protected member 'configuration_' from its base class + * ddspipe::participants::XmlParticipant. + */ +class XMLTestClass : public ddspipe::participants::dds::XmlParticipant +{ +public: + + using ddspipe::participants::dds::XmlParticipant::configuration_; // Make protected member accessible +}; + +/** + * This test case is for the ParticipantFactory class, specifically testing the creation + * of an EchoParticipant. The test checks whether the created EchoParticipant has the + * expected configuration values. + */ +TEST(ParticipantFactoryTest, create_echo_participant) +{ + { + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + std::shared_ptr payload_pool(new ddspipe::core::FastPayloadPool()); + std::shared_ptr discovery_database(new ddspipe::core::DiscoveryDatabase()); + + 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::static_pointer_cast(i_participant); + + ASSERT_TRUE(echo_participant) << "Failed to create Echo Participant"; + + ASSERT_EQ(echo_participant->configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(echo_participant->configuration_->app_metadata, ""); + } +} + +/** + * This test case is for the ParticipantFactory class, specifically testing the creation + * of an SimpleParticipant. The test checks whether the created SimpleParticipant has the + * expected configuration values. + */ +TEST(ParticipantFactoryTest, create_simple_participant) +{ + { + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + std::shared_ptr payload_pool(new ddspipe::core::FastPayloadPool()); + std::shared_ptr discovery_database(new ddspipe::core::DiscoveryDatabase()); + + std::shared_ptr i_participant = participant_factory.create_participant( + types::ParticipantKind::simple, configuration, payload_pool, discovery_database); + + std::shared_ptr simple_participant = + std::static_pointer_cast(i_participant); + + ASSERT_TRUE(simple_participant) << "Failed to create Simple Participant"; + + ASSERT_EQ(simple_participant->configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(simple_participant->configuration_->app_metadata, ""); + } +} + +/** + * This test case is for the ParticipantFactory class, specifically testing the creation + * of an DiscoveryServerParticipant. The test checks whether the created DiscoveryServerParticipant has the + * expected configuration values. + */ +TEST(ParticipantFactoryTest, create_discovery_server_participant) +{ + { + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + configuration->listening_addresses.insert(ddspipe::participants::testing::random_address()); + std::shared_ptr payload_pool(new ddspipe::core::FastPayloadPool()); + std::shared_ptr discovery_database(new ddspipe::core::DiscoveryDatabase()); + + 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::static_pointer_cast(i_participant); + + ASSERT_TRUE(discovery_server_participant) << "Failed to create Discovery Server Participant"; + + ASSERT_EQ(discovery_server_participant->configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(discovery_server_participant->configuration_->app_metadata, ""); + } +} + +/** + * This test case is for the ParticipantFactory class, specifically testing the creation + * of an InitialPeersParticipant. The test checks whether the created InitialPeersParticipant has the + * expected configuration values. + */ +TEST(ParticipantFactoryTest, create_initial_peers_participant) +{ + { + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + configuration->listening_addresses.insert(ddspipe::participants::testing::random_address()); + std::shared_ptr payload_pool(new ddspipe::core::FastPayloadPool()); + std::shared_ptr discovery_database(new ddspipe::core::DiscoveryDatabase()); + + 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::static_pointer_cast(i_participant); + + ASSERT_TRUE(initial_peers_participant) << "Failed to create Initial Peers Participant"; + + ASSERT_EQ(initial_peers_participant->configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(initial_peers_participant->configuration_->app_metadata, ""); + } +} + +/** + * This test case is for the ParticipantFactory class, specifically testing the creation + * of an XmlParticipant. The test checks whether the created XmlParticipant has the + * expected configuration values. + */ +TEST(ParticipantFactoryTest, create_xml_participant) +{ + { + ParticipantFactory participant_factory; + + auto configuration = std::make_shared(); + std::shared_ptr payload_pool(new ddspipe::core::FastPayloadPool()); + std::shared_ptr discovery_database(new ddspipe::core::DiscoveryDatabase()); + + std::shared_ptr i_participant = participant_factory.create_participant( + types::ParticipantKind::xml, configuration, payload_pool, discovery_database); + + std::shared_ptr xml_participant = + std::static_pointer_cast(i_participant); + + ASSERT_TRUE(xml_participant) << "Failed to create XML Participant"; + + ASSERT_EQ(xml_participant->configuration_->app_id, "DDS_ROUTER"); + ASSERT_EQ(xml_participant->configuration_->app_metadata, ""); + } +} + +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 bd75e9929..17b4a21f0 100644 --- a/docs/rst/notes/forthcoming_version.rst +++ b/docs/rst/notes/forthcoming_version.rst @@ -16,6 +16,7 @@ The next release will include the following **Features**: * :ref:`Downsampling `. * :ref:`Discovery Trigger `. * 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**: