Skip to content

Commit 4f19b7d

Browse files
Allow creation of built-in content filters with different type name (#5867) (#5875)
* Allow creation of built-in content filters with different type name (#5867) * Refs #23265. Add unit test. Signed-off-by: Miguel Company <[email protected]> * Refs #23265. Add blackbox test. Signed-off-by: Miguel Company <[email protected]> * Refs #23265. Use type identifiers when creating DDS filter object. Signed-off-by: Miguel Company <[email protected]> * Refs #23265. Refactor for readability. Signed-off-by: Miguel Company <[email protected]> * Refs #23265. Apply review suggestion. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> * Fix uncrustify Signed-off-by: Miguel Company <[email protected]> * Ensure type object registration in blackbox test. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> Co-authored-by: Miguel Company <[email protected]>
1 parent 1e881c6 commit 4f19b7d

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

src/cpp/fastdds/topic/DDSSQLFilter/DDSFilterFactory.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,20 @@ DDSFilterFactory::~DDSFilterFactory()
449449
pool.clear();
450450
}
451451

452+
static const eprosima::fastrtps::types::TypeIdentifier* get_complete_type_identifier(
453+
const char* type_name,
454+
const TopicDataType* data_type)
455+
{
456+
using eprosima::fastrtps::types::TypeObjectFactory;
457+
auto type_id = TypeObjectFactory::get_instance()->get_type_identifier(type_name, true);
458+
if (!type_id)
459+
{
460+
type_id = TypeObjectFactory::get_instance()->get_type_identifier(data_type->getName(), true);
461+
}
462+
463+
return type_id;
464+
}
465+
452466
IContentFilterFactory::ReturnCode_t DDSFilterFactory::create_content_filter(
453467
const char* filter_class_name,
454468
const char* type_name,
@@ -459,8 +473,6 @@ IContentFilterFactory::ReturnCode_t DDSFilterFactory::create_content_filter(
459473
{
460474
using eprosima::fastrtps::types::TypeObjectFactory;
461475

462-
static_cast<void>(data_type);
463-
464476
ReturnCode_t ret = ReturnCode_t::RETCODE_UNSUPPORTED;
465477

466478
if (nullptr == filter_expression)
@@ -517,18 +529,18 @@ IContentFilterFactory::ReturnCode_t DDSFilterFactory::create_content_filter(
517529
}
518530
else
519531
{
520-
auto type_object = TypeObjectFactory::get_instance()->get_type_object(type_name, true);
521-
if (!type_object)
532+
auto type_id = get_complete_type_identifier(type_name, data_type);
533+
if (!type_id)
522534
{
523535
EPROSIMA_LOG_ERROR(DDSSQLFILTER, "No TypeObject found for type " << type_name);
524536
ret = ReturnCode_t::RETCODE_BAD_PARAMETER;
525537
}
526538
else
527539
{
540+
auto type_object = TypeObjectFactory::get_instance()->get_type_object(type_id);
528541
auto node = parser::parse_filter_expression(filter_expression, type_object);
529542
if (node)
530543
{
531-
auto type_id = TypeObjectFactory::get_instance()->get_type_identifier(type_name, true);
532544
auto dyn_type = TypeObjectFactory::get_instance()->build_dynamic_type(type_name, type_id, type_object);
533545
DDSFilterExpression* expr = get_expression();
534546
expr->set_type(dyn_type);

test/blackbox/common/DDSBlackboxTestsContentFilter.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ class DDSContentFilter : public testing::TestWithParam<communication_type>
288288
{
289289
std::this_thread::sleep_for(std::chrono::milliseconds(100));
290290
reader->get_subscription_matched_status(status);
291-
} while (status.current_count < 1);
291+
}
292+
while (status.current_count < 1);
292293
}
293294

294295
return reader;
@@ -755,6 +756,39 @@ TEST(DDSContentFilter, OnlyFilterAliveChanges)
755756
ASSERT_EQ(reader.get_sample_lost_status().total_count, 0);
756757
}
757758

759+
/*
760+
* Regression test for https://eprosima.easyredmine.com/issues/23265
761+
*
762+
* This test checks that a DDSSQL content filter can be created with a type name that is different from the one
763+
* in the generated type support.
764+
*/
765+
TEST(DDSContentFilter, filter_other_type_name)
766+
{
767+
using namespace eprosima::fastdds;
768+
769+
// Ensure type object registration
770+
registerHelloWorldTypes();
771+
772+
// Create a DomainParticipant
773+
DomainParticipant* participant =
774+
dds::DomainParticipantFactory::get_instance()->create_participant(0, PARTICIPANT_QOS_DEFAULT);
775+
ASSERT_NE(participant, nullptr);
776+
777+
// Create a ContentFilteredTopic with a different type name
778+
dds::TypeSupport type_support(new HelloWorldPubSubType());
779+
ASSERT_EQ(type_support.register_type(participant, "CustomType"), ReturnCode_t::RETCODE_OK);
780+
dds::Topic* topic = participant->create_topic(
781+
"TestTopic", "CustomType", TOPIC_QOS_DEFAULT);
782+
ASSERT_NE(topic, nullptr);
783+
dds::ContentFilteredTopic* filtered_topic = participant->create_contentfilteredtopic(
784+
"FilteredTopic", topic, "index <= %0", { "6" });
785+
ASSERT_NE(filtered_topic, nullptr);
786+
787+
// Delete all entities
788+
ASSERT_EQ(participant->delete_contained_entities(), ReturnCode_t::RETCODE_OK);
789+
ASSERT_EQ(dds::DomainParticipantFactory::get_instance()->delete_participant(participant), ReturnCode_t::RETCODE_OK);
790+
}
791+
758792
#ifdef INSTANTIATE_TEST_SUITE_P
759793
#define GTEST_INSTANTIATE_TEST_MACRO(x, y, z, w) INSTANTIATE_TEST_SUITE_P(x, y, z, w)
760794
#else

test/unittest/dds/topic/DDSSQLFilter/DDSSQLFilterTests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,27 @@ TEST_F(DDSSQLFilterTests, type_compatibility_compare_operand_op_operand)
553553
}
554554
}
555555

556+
/*
557+
* Regression test for https://eprosima.easyredmine.com/issues/23265
558+
*
559+
* This test checks that a DDSSQL content filter can be created with a type name that is different from the one
560+
* used to register the type object representation.
561+
*/
562+
TEST_F(DDSSQLFilterTests, different_type_name)
563+
{
564+
ContentFilterTestTypePubSubType type;
565+
566+
IContentFilter* filter_instance = nullptr;
567+
DDSFilterFactory factory;
568+
StackAllocatedSequence<const char*, 10> params;
569+
570+
EXPECT_EQ(factory.create_content_filter("DDSSQL", "MyCustomType", &type,
571+
"uint16_field = 3", params, filter_instance), ReturnCode_t::RETCODE_OK);
572+
573+
EXPECT_EQ(ReturnCode_t::RETCODE_OK,
574+
factory.delete_content_filter("DDSSQL", filter_instance));
575+
}
576+
556577
/**
557578
* Singleton that holds the serialized payloads to be evaluated
558579
*/

0 commit comments

Comments
 (0)