Skip to content

Commit

Permalink
Refs #18763: Applied suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Santiago <javiersantiago@eprosima.com>
  • Loading branch information
jsan-rt committed Jun 14, 2023
1 parent 76bcd82 commit c26670e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/cpp/fastdds/core/policy/ParameterSerializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#define FASTDDS_CORE_POLICY__PARAMETERSERIALIZER_HPP_

#include "ParameterList.hpp"
#include "fastdds/dds/log/Log.hpp"

#include <fastdds/rtps/builtin/data/ContentFilterProperty.hpp>
#include <fastdds/rtps/common/CDRMessage_t.h>
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/fastdds/topic/ContentFilteredTopicImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <fastdds/core/policy/ParameterList.hpp>
#include <fastdds/dds/core/policy/ParameterTypes.hpp>
#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/domain/DomainParticipantImpl.hpp>
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
#include <fastdds/rtps/messages/CDRMessage.h>
#include <fastdds/subscriber/DataReaderImpl.hpp>
#include <fastdds/topic/ContentFilterUtils.hpp>
Expand Down
34 changes: 33 additions & 1 deletion test/unittest/dds/participant/ParticipantTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2169,14 +2169,46 @@ TEST(ParticipantTests, DeleteTopicInUse)
// Check that the constraints on maximum expression parameter size are honored
TEST(ParticipantTests, ExpressionParameterLimits)
{

DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT;
TypeSupport type(new TopicDataTypeMock());

// Testing QoS Default limit
DomainParticipant* participant_default_max_parameters =
DomainParticipantFactory::get_instance()->create_participant(0, pqos);
type.register_type(participant_default_max_parameters, "footype");

Topic* topic_default_max_parameters = participant_default_max_parameters->create_topic("footopic", "footype",
TOPIC_QOS_DEFAULT);

std::vector<std::string> expression_parameters;
for (int i = 0; i < 101; i++)
{
expression_parameters.push_back("Parameter");
}

ContentFilteredTopic* content_filtered_topic_default_max_parameters =
participant_default_max_parameters->create_contentfilteredtopic("contentfilteredtopic",
topic_default_max_parameters, "", expression_parameters);
ASSERT_EQ(content_filtered_topic_default_max_parameters, nullptr);

ContentFilteredTopic* content_filtered_topic_default_valid_parameters =
participant_default_max_parameters->create_contentfilteredtopic("contentfilteredtopic",
topic_default_max_parameters, "", {"Parameter1", "Parameter2"});
ASSERT_NE(content_filtered_topic_default_valid_parameters, nullptr);

ASSERT_EQ(participant_default_max_parameters->delete_contentfilteredtopic(
content_filtered_topic_default_valid_parameters), ReturnCode_t::RETCODE_OK);
ASSERT_EQ(participant_default_max_parameters->delete_topic(topic_default_max_parameters), ReturnCode_t::RETCODE_OK);
ASSERT_EQ(DomainParticipantFactory::get_instance()->delete_participant(
participant_default_max_parameters), ReturnCode_t::RETCODE_OK);

// Test user defined limits
pqos.allocation().content_filter.expression_parameters.maximum = 1;

DomainParticipant* participant =
DomainParticipantFactory::get_instance()->create_participant(0, pqos);

TypeSupport type(new TopicDataTypeMock());
type.register_type(participant, "footype");

Topic* topic = participant->create_topic("footopic", "footype", TOPIC_QOS_DEFAULT);
Expand Down
46 changes: 44 additions & 2 deletions test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "fastdds/dds/log/Log.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>

Expand Down Expand Up @@ -1199,7 +1198,8 @@ TEST(BuiltinDataSerializationTests, contentfilterproperty_interoperability)
}

/*!
* \test Test for deserialization of messages with the maximum size of expression parameters
* \test Test for deserialization of messages with expression parameters list
* with sizes of 100 or greater
*/
TEST(BuiltinDataSerializationTests, contentfilterproperty_max_parameter_check)
{
Expand Down Expand Up @@ -1256,6 +1256,48 @@ TEST(BuiltinDataSerializationTests, contentfilterproperty_max_parameter_check)
EXPECT_TRUE(out.readFromCDRMessage(&msg, network, true));

ASSERT_EQ(100, out.content_filter().expression_parameters.size());

CDRMessage_t msg_fault(5000);
EXPECT_TRUE(fastdds::dds::ParameterList::writeEncapsulationToCDRMsg(&msg_fault));

// Manual serialization of a ContentFilterProperty.
{
uint32_t len = manual_content_filter_cdr_serialized_size(
content_filtered_topic_name,
related_topic_name,
filter_class_name,
filter_expression,
expression_parameters
);
EXPECT_TRUE(fastrtps::rtps::CDRMessage::addUInt16(&msg_fault, fastdds::dds::PID_CONTENT_FILTER_PROPERTY));
EXPECT_TRUE(fastrtps::rtps::CDRMessage::addUInt16(&msg_fault, static_cast<uint16_t>(len - 4)));
// content_filtered_topic_name
EXPECT_TRUE(fastrtps::rtps::CDRMessage::add_string(&msg_fault, content_filtered_topic_name));
// related_topic_name
EXPECT_TRUE(fastrtps::rtps::CDRMessage::add_string(&msg_fault, related_topic_name));
// filter_class_name
EXPECT_TRUE(fastrtps::rtps::CDRMessage::add_string(&msg_fault, filter_class_name));
// filter_expression
EXPECT_TRUE(fastrtps::rtps::CDRMessage::add_string(&msg_fault, filter_expression));
// expression_parameters
// sequence length

// Add the 101st parameter to the list
expression_parameters.push_back("Parameter");
uint32_t num_params = static_cast<uint32_t>(expression_parameters.size());
EXPECT_EQ(num_params, 101u);
EXPECT_TRUE(fastrtps::rtps::CDRMessage::addUInt32(&msg_fault, num_params));
// Add all parameters
for (const std::string& param : expression_parameters)
{
EXPECT_TRUE(fastrtps::rtps::CDRMessage::add_string(&msg_fault, param));
}
}
EXPECT_TRUE(fastdds::dds::ParameterSerializer<Parameter_t>::add_parameter_sentinel(&msg_fault));

msg_fault.pos = 0;
// Deserialization of messages with more than 100 parameters should fail
ASSERT_FALSE(out.readFromCDRMessage(&msg_fault, network, true));
}
}

Expand Down

0 comments on commit c26670e

Please sign in to comment.