From ec72eb433433f0901b53ca21ff02cf820be7216e Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 8 Mar 2024 09:29:48 +0100 Subject: [PATCH 01/12] Refs #20543: Default Domain Id value Signed-off-by: JesusPoderoso --- .../dds/domain/DomainParticipantFactory.hpp | 15 +++++++++++++++ .../fastdds/domain/DomainParticipantFactory.cpp | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index cb13568e001..2a971278696 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -96,6 +96,19 @@ class DomainParticipantFactory DomainParticipantListener* listener = nullptr, const StatusMask& mask = StatusMask::all()); + /** + * Create a Participant. + * + * @param qos DomainParticipantQos Reference. + * @param listener DomainParticipantListener Pointer (default: nullptr) + * @param mask StatusMask Reference (default: all) + * @return DomainParticipant pointer. (nullptr if not created.) + */ + RTPS_DllAPI DomainParticipant* create_participant( + const DomainParticipantQos& qos, + DomainParticipantListener* listener = nullptr, + const StatusMask& mask = StatusMask::all()); + /** * Create a Participant. * @@ -342,6 +355,8 @@ class DomainParticipantFactory mutable bool default_xml_profiles_loaded; + DomainId_t default_domain_id_; + DomainParticipantFactoryQos factory_qos_; DomainParticipantQos default_participant_qos_; diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index de7c65fc57c..a9311e95c31 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -54,6 +54,7 @@ namespace dds { DomainParticipantFactory::DomainParticipantFactory() : default_xml_profiles_loaded(false) + , default_domain_id_(0) , default_participant_qos_(PARTICIPANT_QOS_DEFAULT) , topic_pool_(fastrtps::rtps::TopicPayloadPoolRegistry::instance()) , rtps_domain_(fastrtps::rtps::RTPSDomainImpl::get_instance()) @@ -206,6 +207,14 @@ DomainParticipant* DomainParticipantFactory::create_participant( return dom_part; } +DomainParticipant* DomainParticipantFactory::create_participant( + const DomainParticipantQos& qos, + DomainParticipantListener* listen, + const StatusMask& mask) +{ + return create_participant(default_domain_id_, qos, listen, mask); +} + DomainParticipant* DomainParticipantFactory::create_participant_with_profile( DomainId_t did, const std::string& profile_name, @@ -239,7 +248,8 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( { DomainParticipantQos qos = default_participant_qos_; utils::set_qos_from_attributes(qos, attr.rtps); - return create_participant(attr.domainId, qos, listen, mask); + default_domain_id_ = attr.domainId; + return create_participant(default_domain_id_, qos, listen, mask); } return nullptr; @@ -423,6 +433,7 @@ void DomainParticipantFactory::reset_default_participant_qos() ParticipantAttributes attr; XMLProfileManager::getDefaultParticipantAttributes(attr); utils::set_qos_from_attributes(default_participant_qos_, attr.rtps); + default_domain_id_ = attr.domainId; } } From 71dc91c1e82de8a7a3998e1c7341c5df1a64038f Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 8 Mar 2024 10:58:21 +0100 Subject: [PATCH 02/12] Refs #20543: Rename method Signed-off-by: JesusPoderoso --- include/fastdds/dds/domain/DomainParticipantFactory.hpp | 4 +--- src/cpp/fastdds/domain/DomainParticipantFactory.cpp | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index 2a971278696..6b3c6de4d12 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -99,13 +99,11 @@ class DomainParticipantFactory /** * Create a Participant. * - * @param qos DomainParticipantQos Reference. * @param listener DomainParticipantListener Pointer (default: nullptr) * @param mask StatusMask Reference (default: all) * @return DomainParticipant pointer. (nullptr if not created.) */ - RTPS_DllAPI DomainParticipant* create_participant( - const DomainParticipantQos& qos, + RTPS_DllAPI DomainParticipant* create_participant_with_default_profile( DomainParticipantListener* listener = nullptr, const StatusMask& mask = StatusMask::all()); diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index a9311e95c31..bf2afdd0325 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -207,12 +207,12 @@ DomainParticipant* DomainParticipantFactory::create_participant( return dom_part; } -DomainParticipant* DomainParticipantFactory::create_participant( - const DomainParticipantQos& qos, +DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile( DomainParticipantListener* listen, const StatusMask& mask) { - return create_participant(default_domain_id_, qos, listen, mask); + load_profiles(); + return create_participant(default_domain_id_, default_participant_qos_, listen, mask); } DomainParticipant* DomainParticipantFactory::create_participant_with_profile( From fae60332b2762d18ba33b17d41e437f2309ab6c4 Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 8 Mar 2024 11:26:57 +0100 Subject: [PATCH 03/12] Refs #20543: Apply rev suggestions Signed-off-by: JesusPoderoso --- .../dds/domain/DomainParticipantFactory.hpp | 8 ++----- .../domain/DomainParticipantFactory.cpp | 21 ++++++++----------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index 6b3c6de4d12..ce5e953b751 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -97,15 +97,11 @@ class DomainParticipantFactory const StatusMask& mask = StatusMask::all()); /** - * Create a Participant. + * Create a Participant with default domain id and qos. * - * @param listener DomainParticipantListener Pointer (default: nullptr) - * @param mask StatusMask Reference (default: all) * @return DomainParticipant pointer. (nullptr if not created.) */ - RTPS_DllAPI DomainParticipant* create_participant_with_default_profile( - DomainParticipantListener* listener = nullptr, - const StatusMask& mask = StatusMask::all()); + RTPS_DllAPI DomainParticipant* create_participant_with_default_profile(); /** * Create a Participant. diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index bf2afdd0325..c0222e7c5f9 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -156,7 +156,7 @@ ReturnCode_t DomainParticipantFactory::delete_participant( DomainParticipant* DomainParticipantFactory::create_participant( DomainId_t did, const DomainParticipantQos& qos, - DomainParticipantListener* listen, + DomainParticipantListener* listener, const StatusMask& mask) { load_profiles(); @@ -165,10 +165,10 @@ DomainParticipant* DomainParticipantFactory::create_participant( DomainParticipant* dom_part = new DomainParticipant(mask); #ifndef FASTDDS_STATISTICS - DomainParticipantImpl* dom_part_impl = new DomainParticipantImpl(dom_part, did, pqos, listen); + DomainParticipantImpl* dom_part_impl = new DomainParticipantImpl(dom_part, did, pqos, listener); #else eprosima::fastdds::statistics::dds::DomainParticipantImpl* dom_part_impl = - new eprosima::fastdds::statistics::dds::DomainParticipantImpl(dom_part, did, pqos, listen); + new eprosima::fastdds::statistics::dds::DomainParticipantImpl(dom_part, did, pqos, listener); #endif // FASTDDS_STATISTICS if (fastrtps::rtps::GUID_t::unknown() != dom_part_impl->guid()) @@ -207,18 +207,16 @@ DomainParticipant* DomainParticipantFactory::create_participant( return dom_part; } -DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile( - DomainParticipantListener* listen, - const StatusMask& mask) +DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile() { load_profiles(); - return create_participant(default_domain_id_, default_participant_qos_, listen, mask); + return create_participant(default_domain_id_, default_participant_qos_, nullptr, StatusMask::all()); } DomainParticipant* DomainParticipantFactory::create_participant_with_profile( DomainId_t did, const std::string& profile_name, - DomainParticipantListener* listen, + DomainParticipantListener* listener, const StatusMask& mask) { load_profiles(); @@ -229,7 +227,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( { DomainParticipantQos qos = default_participant_qos_; utils::set_qos_from_attributes(qos, attr.rtps); - return create_participant(did, qos, listen, mask); + return create_participant(did, qos, listener, mask); } return nullptr; @@ -237,7 +235,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( DomainParticipant* DomainParticipantFactory::create_participant_with_profile( const std::string& profile_name, - DomainParticipantListener* listen, + DomainParticipantListener* listener, const StatusMask& mask) { load_profiles(); @@ -248,8 +246,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile( { DomainParticipantQos qos = default_participant_qos_; utils::set_qos_from_attributes(qos, attr.rtps); - default_domain_id_ = attr.domainId; - return create_participant(default_domain_id_, qos, listen, mask); + return create_participant(attr.domainId, qos, listener, mask); } return nullptr; From c8d8a372a8cc4df748fd52996e25c3eaca0223cc Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 8 Mar 2024 11:42:17 +0100 Subject: [PATCH 04/12] Refs #20543: Address missed suggestions Signed-off-by: JesusPoderoso --- .../fastdds/dds/domain/DomainParticipantFactory.hpp | 12 ++++++++++++ src/cpp/fastdds/domain/DomainParticipantFactory.cpp | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index ce5e953b751..bd63f8da40a 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -103,6 +103,18 @@ class DomainParticipantFactory */ RTPS_DllAPI DomainParticipant* create_participant_with_default_profile(); + + /** + * Create a Participant with default domain id and qos. + * + * @return DomainParticipant pointer. (nullptr if not created.) + * @param listener DomainParticipantListener Pointer + * @param mask StatusMask Reference + */ + RTPS_DllAPI DomainParticipant* create_participant_with_default_profile( + DomainParticipantListener* listener, + const StatusMask& mask); + /** * Create a Participant. * diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index c0222e7c5f9..018b40818d8 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -210,7 +210,15 @@ DomainParticipant* DomainParticipantFactory::create_participant( DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile() { load_profiles(); - return create_participant(default_domain_id_, default_participant_qos_, nullptr, StatusMask::all()); + return create_participant(default_domain_id_, default_participant_qos_, nullptr, StatusMask::none()); +} + +DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile( + DomainParticipantListener* listener, + const StatusMask& mask) +{ + load_profiles(); + return create_participant(default_domain_id_, default_participant_qos_, listener, mask); } DomainParticipant* DomainParticipantFactory::create_participant_with_profile( From 820e036030b8d0cfead91e3cf26b63e44e709833 Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Fri, 8 Mar 2024 11:55:15 +0100 Subject: [PATCH 05/12] Refs #20543: Apply last(?) revision suggestion Signed-off-by: JesusPoderoso --- src/cpp/fastdds/domain/DomainParticipantFactory.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index 018b40818d8..7394ec8945e 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -209,8 +209,7 @@ DomainParticipant* DomainParticipantFactory::create_participant( DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile() { - load_profiles(); - return create_participant(default_domain_id_, default_participant_qos_, nullptr, StatusMask::none()); + return create_participant_with_default_profile(nullptr, StatusMask::none()); } DomainParticipant* DomainParticipantFactory::create_participant_with_default_profile( From 61b435943daba6c6b4015e4562c3cccde90b045b Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Thu, 14 Mar 2024 09:04:17 +0100 Subject: [PATCH 06/12] Refs #20543: Apply Edu' suggestion Signed-off-by: JesusPoderoso --- include/fastdds/dds/domain/DomainParticipantFactory.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/fastdds/dds/domain/DomainParticipantFactory.hpp b/include/fastdds/dds/domain/DomainParticipantFactory.hpp index bd63f8da40a..a222cca44b3 100644 --- a/include/fastdds/dds/domain/DomainParticipantFactory.hpp +++ b/include/fastdds/dds/domain/DomainParticipantFactory.hpp @@ -101,7 +101,7 @@ class DomainParticipantFactory * * @return DomainParticipant pointer. (nullptr if not created.) */ - RTPS_DllAPI DomainParticipant* create_participant_with_default_profile(); + FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile(); /** @@ -111,7 +111,7 @@ class DomainParticipantFactory * @param listener DomainParticipantListener Pointer * @param mask StatusMask Reference */ - RTPS_DllAPI DomainParticipant* create_participant_with_default_profile( + FASTDDS_EXPORTED_API DomainParticipant* create_participant_with_default_profile( DomainParticipantListener* listener, const StatusMask& mask); From 9764ca173d0ee4fa37e7d39bb06711b386bab68c Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Mon, 18 Mar 2024 08:31:57 +0100 Subject: [PATCH 07/12] Refs #20543: Apply Edu' suggestion (2) Signed-off-by: JesusPoderoso --- src/cpp/fastdds/domain/DomainParticipantFactory.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp index 7394ec8945e..acc293c092d 100644 --- a/src/cpp/fastdds/domain/DomainParticipantFactory.cpp +++ b/src/cpp/fastdds/domain/DomainParticipantFactory.cpp @@ -363,6 +363,10 @@ ReturnCode_t DomainParticipantFactory::load_profiles() { reset_default_participant_qos(); } + // Take the default domain id from the default participant profile + eprosima::fastrtps::ParticipantAttributes attr; + XMLProfileManager::getDefaultParticipantAttributes(attr); + default_domain_id_ = attr.domainId; RTPSDomain::set_filewatch_thread_config(factory_qos_.file_watch_threads(), factory_qos_.file_watch_threads()); } @@ -437,7 +441,6 @@ void DomainParticipantFactory::reset_default_participant_qos() ParticipantAttributes attr; XMLProfileManager::getDefaultParticipantAttributes(attr); utils::set_qos_from_attributes(default_participant_qos_, attr.rtps); - default_domain_id_ = attr.domainId; } } From a52e452838a68afd2741e06edff25de726e7c29b Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Mon, 18 Mar 2024 09:05:32 +0100 Subject: [PATCH 08/12] Refs #20543: Add missing test Signed-off-by: JesusPoderoso --- .../dds/participant/ParticipantTests.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index f0b495d650c..4ead7275ebf 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -568,6 +569,34 @@ TEST(ParticipantTests, CreateDomainParticipantWithProfile) ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant(participant) == ReturnCode_t::RETCODE_OK); } +TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfile) +{ + // set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml" + setenv("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml", true); + + uint32_t domain_id = 123u; // This is the domain ID set in the default profile above + uint32_t default_domain_id = 0u; // This is the default domain ID + + //participant using the given profile + DomainParticipant* default_env_participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); + ASSERT_NE(default_env_participant, nullptr); + ASSERT_EQ(default_env_participant->get_domain_id(), domain_id); + ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( + default_env_participant) == ReturnCode_t::RETCODE_OK); + + // unset XML profile environment variable + unsetenv("FASTRTPS_DEFAULT_PROFILES_FILE"); + + //participant using default values + DomainParticipant* default_participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); + ASSERT_NE(default_participant, nullptr); + ASSERT_EQ(default_participant->get_domain_id(), default_domain_id); + ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( + default_participant) == ReturnCode_t::RETCODE_OK); +} + TEST(ParticipantTests, GetParticipantProfileQos) { DomainParticipantFactory::get_instance()->load_XML_profiles_file("test_xml_profile.xml"); From 504795b7889183f979fe87c96da4249b466078c3 Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Thu, 21 Mar 2024 10:49:42 +0100 Subject: [PATCH 09/12] Refs #20543: Fix test Signed-off-by: JesusPoderoso --- .../dds/participant/ParticipantTests.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 4ead7275ebf..4f283f0f658 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -66,6 +66,7 @@ #include #include "../../logging/mock/MockConsumer.h" +#include "../../common/env_var_utils.hpp" #if defined(__cplusplus_winrt) #define GET_PID GetCurrentProcessId @@ -571,22 +572,27 @@ TEST(ParticipantTests, CreateDomainParticipantWithProfile) TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfile) { - // set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml" - setenv("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml", true); - uint32_t domain_id = 123u; // This is the domain ID set in the default profile above - uint32_t default_domain_id = 0u; // This is the default domain ID + + // set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml" + eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml"); //participant using the given profile DomainParticipant* default_env_participant = DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); + + // unset XML profile environment variable + eprosima::testing::clear_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE"); + ASSERT_NE(default_env_participant, nullptr); ASSERT_EQ(default_env_participant->get_domain_id(), domain_id); ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( default_env_participant) == ReturnCode_t::RETCODE_OK); +} - // unset XML profile environment variable - unsetenv("FASTRTPS_DEFAULT_PROFILES_FILE"); +TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfile) +{ + uint32_t default_domain_id = 0u; // This is the default domain ID //participant using default values DomainParticipant* default_participant = From 2ffb981c14ba6cc820458b20eaa3bf39addf4f1c Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Tue, 26 Mar 2024 08:20:24 +0100 Subject: [PATCH 10/12] Refs #20543: Apply rev suggestions Signed-off-by: JesusPoderoso --- .../dds/participant/ParticipantTests.cpp | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 4f283f0f658..09b838042e7 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -13,11 +13,11 @@ // limitations under the License. #include +#include #include #include #include #include -#include #include #include @@ -65,8 +65,8 @@ #include #include -#include "../../logging/mock/MockConsumer.h" #include "../../common/env_var_utils.hpp" +#include "../../logging/mock/MockConsumer.h" #if defined(__cplusplus_winrt) #define GET_PID GetCurrentProcessId @@ -586,6 +586,31 @@ TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfile) ASSERT_NE(default_env_participant, nullptr); ASSERT_EQ(default_env_participant->get_domain_id(), domain_id); + ASSERT_EQ(default_env_participant->get_listener(), nullptr); + ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( + default_env_participant) == ReturnCode_t::RETCODE_OK); +} + +TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfileListener) +{ + uint32_t domain_id = 123u; // This is the domain ID set in the default profile above + + // set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml" + eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml"); + + DomainParticipantListener* listener = new DomainParticipantListener(); + + //participant using the given profile + DomainParticipant* default_env_participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(listener, + StatusMask::none()); + + // unset XML profile environment variable + eprosima::testing::clear_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE"); + + ASSERT_NE(default_env_participant, nullptr); + ASSERT_EQ(default_env_participant->get_domain_id(), domain_id); + ASSERT_EQ(default_env_participant->get_listener(), listener); ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( default_env_participant) == ReturnCode_t::RETCODE_OK); } @@ -599,6 +624,24 @@ TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfile) DomainParticipantFactory::get_instance()->create_participant_with_default_profile(); ASSERT_NE(default_participant, nullptr); ASSERT_EQ(default_participant->get_domain_id(), default_domain_id); + ASSERT_EQ(default_participant->get_listener(), nullptr); + ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( + default_participant) == ReturnCode_t::RETCODE_OK); +} + +TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfileListener) +{ + uint32_t default_domain_id = 0u; // This is the default domain ID + + DomainParticipantListener* listener = new DomainParticipantListener(); + + //participant using default values + DomainParticipant* default_participant = + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(listener, + StatusMask::none()); + ASSERT_NE(default_participant, nullptr); + ASSERT_EQ(default_participant->get_domain_id(), default_domain_id); + ASSERT_EQ(default_participant->get_listener(), listener); ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( default_participant) == ReturnCode_t::RETCODE_OK); } From 052dd8140c37aafccebb91e83ab84213893c6d25 Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Wed, 27 Mar 2024 07:20:50 +0100 Subject: [PATCH 11/12] Refs #20543: Instanciate test listener in stack Signed-off-by: JesusPoderoso --- test/unittest/dds/participant/ParticipantTests.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unittest/dds/participant/ParticipantTests.cpp b/test/unittest/dds/participant/ParticipantTests.cpp index 09b838042e7..445b28c491e 100644 --- a/test/unittest/dds/participant/ParticipantTests.cpp +++ b/test/unittest/dds/participant/ParticipantTests.cpp @@ -598,11 +598,11 @@ TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfileListener) // set XML profile as environment variable: "export FASTDDS_DEFAULT_PROFILES_FILE=test_xml_profile.xml" eprosima::testing::set_environment_variable("FASTDDS_DEFAULT_PROFILES_FILE", "test_xml_profile.xml"); - DomainParticipantListener* listener = new DomainParticipantListener(); + DomainParticipantListener listener; //participant using the given profile DomainParticipant* default_env_participant = - DomainParticipantFactory::get_instance()->create_participant_with_default_profile(listener, + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(&listener, StatusMask::none()); // unset XML profile environment variable @@ -610,7 +610,7 @@ TEST(ParticipantTests, CreateDomainParticipantWithDefaultProfileListener) ASSERT_NE(default_env_participant, nullptr); ASSERT_EQ(default_env_participant->get_domain_id(), domain_id); - ASSERT_EQ(default_env_participant->get_listener(), listener); + ASSERT_EQ(default_env_participant->get_listener(), &listener); ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( default_env_participant) == ReturnCode_t::RETCODE_OK); } @@ -633,15 +633,15 @@ TEST(ParticipantTests, CreateDomainParticipantWithoutDefaultProfileListener) { uint32_t default_domain_id = 0u; // This is the default domain ID - DomainParticipantListener* listener = new DomainParticipantListener(); + DomainParticipantListener listener; //participant using default values DomainParticipant* default_participant = - DomainParticipantFactory::get_instance()->create_participant_with_default_profile(listener, + DomainParticipantFactory::get_instance()->create_participant_with_default_profile(&listener, StatusMask::none()); ASSERT_NE(default_participant, nullptr); ASSERT_EQ(default_participant->get_domain_id(), default_domain_id); - ASSERT_EQ(default_participant->get_listener(), listener); + ASSERT_EQ(default_participant->get_listener(), &listener); ASSERT_TRUE(DomainParticipantFactory::get_instance()->delete_participant( default_participant) == ReturnCode_t::RETCODE_OK); } From 1117c4a86302bb036504a2e739eae584182864dd Mon Sep 17 00:00:00 2001 From: JesusPoderoso Date: Wed, 27 Mar 2024 08:52:30 +0100 Subject: [PATCH 12/12] Refs #20543: Include new feature in versions.md Signed-off-by: JesusPoderoso --- versions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/versions.md b/versions.md index 141fe89c3b7..9a2ba577c5f 100644 --- a/versions.md +++ b/versions.md @@ -23,6 +23,7 @@ Forthcoming * StringMatching * TimeConversion * DBQueue +* Added create participant methods that use environment XML profile for participant configuration. Version 2.14.0 --------------