Skip to content

Commit 16fc3e0

Browse files
committed
Refs 14006: Add test for default constructed physical properties
Signed-off-by: Eduardo Ponz <[email protected]>
1 parent f449036 commit 16fc3e0

File tree

2 files changed

+107
-13
lines changed

2 files changed

+107
-13
lines changed

src/cpp/fastdds/domain/DomainParticipantFactory.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,22 @@ namespace eprosima {
4848
namespace fastdds {
4949
namespace dds {
5050

51+
/**
52+
* @brief Fill DomainParticipantQos from a given attributes RTPSParticipantAttributes object
53+
*
54+
* @param[in, out] qos The DomainParticipantQos to set
55+
* @param[in] attr The RTPSParticipantAttributes from which the @c qos is set.
56+
* @param[out] merge_properties Whether the non-binary properties should be merged or overriden.
57+
* If set to false @c qos will contain the properties from @c attr. If set to true, the non-binary properties
58+
* are combined by adding to @c qos those from @c attr that are not present (by name) in @c qos.
59+
*/
5160
static void set_qos_from_attributes(
5261
DomainParticipantQos& qos,
53-
const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr)
62+
const eprosima::fastrtps::rtps::RTPSParticipantAttributes& attr,
63+
bool merge_properties)
5464
{
5565
qos.user_data().setValue(attr.userData);
5666
qos.allocation() = attr.allocation;
57-
qos.properties() = attr.properties;
5867
qos.wire_protocol().prefix = attr.prefix;
5968
qos.wire_protocol().participant_id = attr.participantID;
6069
qos.wire_protocol().builtin = attr.builtin;
@@ -68,6 +77,22 @@ static void set_qos_from_attributes(
6877
qos.transport().listen_socket_buffer_size = attr.listenSocketBufferSize;
6978
qos.name() = attr.getName();
7079
qos.flow_controllers() = attr.flow_controllers;
80+
81+
if (merge_properties)
82+
{
83+
for (auto property : attr.properties.properties())
84+
{
85+
if (nullptr == fastrtps::rtps::PropertyPolicyHelper::find_property(qos.properties(), property.name()))
86+
{
87+
qos.properties().properties().emplace_back(property);
88+
}
89+
}
90+
qos.properties().binary_properties() = attr.properties.binary_properties();
91+
}
92+
else
93+
{
94+
qos.properties() = attr.properties;
95+
}
7196
}
7297

7398
DomainParticipantFactory::DomainParticipantFactory()
@@ -240,7 +265,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
240265
if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr))
241266
{
242267
DomainParticipantQos qos = default_participant_qos_;
243-
set_qos_from_attributes(qos, attr.rtps);
268+
set_qos_from_attributes(qos, attr.rtps, true);
244269
return create_participant(did, qos, listen, mask);
245270
}
246271

@@ -259,7 +284,7 @@ DomainParticipant* DomainParticipantFactory::create_participant_with_profile(
259284
if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr))
260285
{
261286
DomainParticipantQos qos = default_participant_qos_;
262-
set_qos_from_attributes(qos, attr.rtps);
287+
set_qos_from_attributes(qos, attr.rtps, true);
263288
return create_participant(attr.domainId, qos, listen, mask);
264289
}
265290

@@ -337,7 +362,7 @@ ReturnCode_t DomainParticipantFactory::get_participant_qos_from_profile(
337362
if (XMLP_ret::XML_OK == XMLProfileManager::fillParticipantAttributes(profile_name, attr))
338363
{
339364
qos = default_participant_qos_;
340-
set_qos_from_attributes(qos, attr.rtps);
365+
set_qos_from_attributes(qos, attr.rtps, true);
341366
return ReturnCode_t::RETCODE_OK;
342367
}
343368

@@ -417,7 +442,7 @@ void DomainParticipantFactory::reset_default_participant_qos()
417442
{
418443
eprosima::fastrtps::ParticipantAttributes attr;
419444
XMLProfileManager::getDefaultParticipantAttributes(attr);
420-
set_qos_from_attributes(default_participant_qos_, attr.rtps);
445+
set_qos_from_attributes(default_participant_qos_, attr.rtps, true);
421446
}
422447
}
423448

test/unittest/dds/participant/ParticipantTests.cpp

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,35 @@ TEST(ParticipantTests, CreateDomainParticipant)
311311

312312
}
313313

314+
/**
315+
* @brief Check whether two @ref DomainParticipantQos are equivalent properties wise and equal elsewhere.
316+
*
317+
* @c qos_1 and @c qos_2 have equivalent properties if:
318+
*
319+
* 1. They have equal binary properties
320+
* 2. All the non-binary properties of @c qos_2 are present (by name) in @c qos_1
321+
*
322+
* @param[in] qos_1 LHS @ref DomainParticipantQos
323+
* @param[in] qos_2 RHS @ref DomainParticipantQos
324+
*/
325+
void check_equivalent_qos(
326+
const DomainParticipantQos& qos_1,
327+
const DomainParticipantQos& qos_2)
328+
{
329+
ASSERT_EQ(qos_1.user_data(), qos_2.user_data());
330+
ASSERT_EQ(qos_1.entity_factory(), qos_2.entity_factory());
331+
ASSERT_EQ(qos_1.allocation(), qos_2.allocation());
332+
for (auto property : qos_2.properties().properties())
333+
{
334+
ASSERT_NE(nullptr, fastrtps::rtps::PropertyPolicyHelper::find_property(qos_1.properties(), property.name()));
335+
}
336+
ASSERT_EQ(qos_1.properties().binary_properties(), qos_2.properties().binary_properties());
337+
ASSERT_EQ(qos_1.wire_protocol(), qos_2.wire_protocol());
338+
ASSERT_EQ(qos_1.transport(), qos_2.transport());
339+
ASSERT_EQ(qos_1.name(), qos_2.name());
340+
ASSERT_EQ(qos_1.flow_controllers(), qos_2.flow_controllers());
341+
}
342+
314343
void check_participant_with_profile (
315344
DomainParticipant* participant,
316345
const std::string& profile_name)
@@ -321,9 +350,14 @@ void check_participant_with_profile (
321350
ParticipantAttributes participant_atts;
322351
XMLProfileManager::fillParticipantAttributes(profile_name, participant_atts);
323352

324-
//Values taken from profile
353+
/* Values taken from profile */
325354
ASSERT_TRUE(qos.allocation() == participant_atts.rtps.allocation);
326-
ASSERT_TRUE(qos.properties() == participant_atts.rtps.properties);
355+
// Check that all the non-binary properties in participant_atts are present (by name) in qos
356+
for (auto property : participant_atts.rtps.properties.properties())
357+
{
358+
ASSERT_NE(nullptr, fastrtps::rtps::PropertyPolicyHelper::find_property(qos.properties(), property.name()));
359+
}
360+
ASSERT_TRUE(qos.properties().binary_properties() == participant_atts.rtps.properties.binary_properties());
327361
ASSERT_TRUE(qos.name().to_string() == participant_atts.rtps.getName());
328362
ASSERT_TRUE(qos.wire_protocol().prefix == participant_atts.rtps.prefix);
329363
ASSERT_TRUE(qos.wire_protocol().participant_id == participant_atts.rtps.participantID);
@@ -344,6 +378,41 @@ void check_participant_with_profile (
344378
ASSERT_TRUE(qos.entity_factory() == PARTICIPANT_QOS_DEFAULT.entity_factory());
345379
}
346380

381+
/**
382+
* This test checks that:
383+
*
384+
* 1. In the case of disabled Statistics, none of the physical data related properties are present in a default
385+
* constructed DomainParticipantQos.
386+
* 2. In the case of enabled Statistics, all of the physical data related properties are present in a default
387+
* constructed DomainParticipantQos, and that their default value is empty.
388+
*/
389+
TEST(ParticipantTests, DomainParticipantQosPhysicalProperties)
390+
{
391+
std::vector<std::string> property_names = {
392+
parameter_policy_physical_data_host,
393+
parameter_policy_physical_data_user,
394+
parameter_policy_physical_data_process
395+
};
396+
#ifndef FASTDDS_STATISTICS
397+
/* Check the behaviour when FASTDDS_STATISTICS is NOT defined */
398+
DomainParticipantQos qos_1;
399+
for (std::string property_name : property_names)
400+
{
401+
std::string* property = fastrtps::rtps::PropertyPolicyHelper::find_property(qos_1.properties(), property_name);
402+
ASSERT_EQ(nullptr, property);
403+
}
404+
#else
405+
/* Check the behaviour when FASTDDS_STATISTICS is defined */
406+
DomainParticipantQos qos_2;
407+
for (std::string property_name : property_names)
408+
{
409+
std::string* property = fastrtps::rtps::PropertyPolicyHelper::find_property(qos_2.properties(), property_name);
410+
ASSERT_NE(nullptr, property);
411+
ASSERT_TRUE(property->empty());
412+
}
413+
#endif // ifndef FASTDDS_STATISTICS
414+
}
415+
347416
TEST(ParticipantTests, CreateDomainParticipantWithProfile)
348417
{
349418
DomainParticipantFactory::get_instance()->load_XML_profiles_file("test_xml_profiles.xml");
@@ -494,7 +563,7 @@ TEST(ParticipantTests, ChangeDomainParticipantQos)
494563
DomainParticipantQos qos;
495564
participant->get_qos(qos);
496565

497-
ASSERT_EQ(qos, PARTICIPANT_QOS_DEFAULT);
566+
check_equivalent_qos(qos, PARTICIPANT_QOS_DEFAULT);
498567

499568
qos.entity_factory().autoenable_created_entities = false;
500569
ASSERT_TRUE(participant->set_qos(qos) == ReturnCode_t::RETCODE_OK);
@@ -515,7 +584,7 @@ TEST(ParticipantTests, ChangePSMDomainParticipantQos)
515584
participant = ::dds::domain::DomainParticipant(0, PARTICIPANT_QOS_DEFAULT);
516585
::dds::domain::qos::DomainParticipantQos qos = participant.qos();
517586

518-
ASSERT_EQ(qos, PARTICIPANT_QOS_DEFAULT);
587+
check_equivalent_qos(qos, PARTICIPANT_QOS_DEFAULT);
519588

520589
qos.entity_factory().autoenable_created_entities = false;
521590
ASSERT_NO_THROW(participant.qos(qos));
@@ -1012,7 +1081,7 @@ TEST(ParticipantTests, ChangeWireProtocolQos)
10121081
DomainParticipantQos qos;
10131082
participant->get_qos(qos);
10141083

1015-
ASSERT_EQ(qos, PARTICIPANT_QOS_DEFAULT);
1084+
check_equivalent_qos(qos, PARTICIPANT_QOS_DEFAULT);
10161085

10171086
// Check that just adding two servers is OK
10181087
rtps::RemoteServerAttributes server;
@@ -1985,7 +2054,7 @@ TEST(ParticipantTests, ChangeAllocationDomainParticipantQos)
19852054
DomainParticipantQos qos;
19862055
participant->get_qos(qos);
19872056

1988-
ASSERT_EQ(qos, PARTICIPANT_QOS_DEFAULT);
2057+
check_equivalent_qos(qos, PARTICIPANT_QOS_DEFAULT);
19892058

19902059
qos.allocation().data_limits.max_properties = 10;
19912060
ASSERT_EQ(participant->set_qos(qos), ReturnCode_t::RETCODE_OK);
@@ -2023,7 +2092,7 @@ TEST(ParticipantTests, ChangeDomainParcipantName)
20232092
DomainParticipantQos qos;
20242093
participant->get_qos(qos);
20252094

2026-
ASSERT_EQ(qos, PARTICIPANT_QOS_DEFAULT);
2095+
check_equivalent_qos(qos, PARTICIPANT_QOS_DEFAULT);
20272096

20282097
qos.name() = "part1";
20292098
ASSERT_EQ(participant->set_qos(qos), ReturnCode_t::RETCODE_OK);

0 commit comments

Comments
 (0)