From 8f3b43fb621d409633c7ff6922e5ef13f862552f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Thu, 11 Apr 2024 12:48:51 +0200 Subject: [PATCH] Refs #20424. Fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- .../xtypes/dynamic_types/DynamicDataImpl.cpp | 12 ++++++-- .../dynamic_types/TypeDescriptorImpl.cpp | 14 +++++++++ .../dynamic_types/TypeDescriptorImpl.hpp | 3 ++ test/feature/dynamic_types/CMakeLists.txt | 4 +++ .../dynamic_types/DynamicTypesTests.cpp | 30 +++++++++---------- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/cpp/fastdds/xtypes/dynamic_types/DynamicDataImpl.cpp b/src/cpp/fastdds/xtypes/dynamic_types/DynamicDataImpl.cpp index 7ceb9651d0c..4c5da3d5773 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/DynamicDataImpl.cpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/DynamicDataImpl.cpp @@ -2030,7 +2030,7 @@ void DynamicDataImpl::apply_bitset_mask( enclosing_type_->get_all_members().at(member_id))}; const auto member_index {member_impl->get_descriptor().index()}; const auto bound {enclosing_type_->get_descriptor().bound().at(member_index)}; - uint64_t mask {0XFFFFFFFFFFFFFFFFllu << bound}; + uint64_t mask {64 == bound ? 0x0llu : 0XFFFFFFFFFFFFFFFFllu << bound}; value &= static_cast>(~mask); } @@ -6677,9 +6677,17 @@ void DynamicDataImpl::serialize( if (it != value_.end()) { int64_t value {0}; + uint64_t uvalue {0}; auto member_data {std::static_pointer_cast(it->second)}; - if (RETCODE_OK == member_data->get_value(value, MEMBER_ID_INVALID)) + ReturnCode_t ret_promotion_value {member_data->get_value(value, MEMBER_ID_INVALID)}; + if (RETCODE_OK != ret_promotion_value) + { + ret_promotion_value = member_data->get_value(uvalue, MEMBER_ID_INVALID); + value = static_cast(uvalue); + } + + if (RETCODE_OK == ret_promotion_value) { auto base {member_id}; auto size {type->get_descriptor().bound().at(index)}; diff --git a/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp b/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp index eaa86e5682e..b5e7ca1f6dc 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp @@ -188,6 +188,20 @@ bool TypeDescriptorImpl::is_consistent() noexcept EPROSIMA_LOG_ERROR(DYN_TYPES, "Descriptor type and the base_type are not of the same kind"); return false; } + + // Check extensibility on structures. + if (TK_STRUCTURE == kind_) + { + if (!is_extensibility_set) + { + extensibility_kind_ = base_type->get_descriptor().extensibility_kind(); + } + else if (extensibility_kind_ != base_type->get_descriptor().extensibility_kind()) + { + EPROSIMA_LOG_ERROR(DYN_TYPES, "ExtensibilityKind is different from that of base type."); + return false; + } + } } // Arrays need one or more bound fields with the lenghts of each dimension. diff --git a/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.hpp b/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.hpp index a4025960470..8a0b75d6012 100644 --- a/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.hpp +++ b/src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.hpp @@ -46,6 +46,8 @@ class TypeDescriptorImpl : public virtual TypeDescriptor ExtensibilityKind extensibility_kind_ {ExtensibilityKind::APPENDABLE}; + bool is_extensibility_set {false}; + bool is_nested_ {false}; public: @@ -202,6 +204,7 @@ class TypeDescriptorImpl : public virtual TypeDescriptor ExtensibilityKind extensibility_kind) noexcept override { extensibility_kind_ = extensibility_kind; + is_extensibility_set = true; } bool is_nested() const noexcept override diff --git a/test/feature/dynamic_types/CMakeLists.txt b/test/feature/dynamic_types/CMakeLists.txt index 5748e6eeb34..9677e962c27 100644 --- a/test/feature/dynamic_types/CMakeLists.txt +++ b/test/feature/dynamic_types/CMakeLists.txt @@ -87,6 +87,10 @@ target_compile_definitions(DynamicTypesTests PRIVATE $<$>,$>:__DEBUG> $<$:__INTERNALDEBUG> # Internal debug activated. ) +target_include_directories(DynamicTypesTests + PRIVATE + ${PROJECT_SOURCE_DIR}/test/utils/ + ) target_link_libraries(DynamicTypesTests GTest::gtest $<$:iphlpapi$Shlwapi> diff --git a/test/feature/dynamic_types/DynamicTypesTests.cpp b/test/feature/dynamic_types/DynamicTypesTests.cpp index c78bc6284d2..dd68776b78e 100644 --- a/test/feature/dynamic_types/DynamicTypesTests.cpp +++ b/test/feature/dynamic_types/DynamicTypesTests.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -232,7 +232,7 @@ TEST_F(DynamicTypesTests, DynamicType_basic) DynamicTypeMember::_ref_type member; { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); // Check members are properly added // • checking invalid id EXPECT_NE(RETCODE_OK, struct_type_builder->get_member(member, 0)); @@ -249,7 +249,6 @@ TEST_F(DynamicTypesTests, DynamicType_basic) ASSERT_EQ(RETCODE_OK, struct_type_builder->get_member(member, 3)); ASSERT_EQ(RETCODE_OK, member->get_descriptor(md)); - EXPECT_TRUE(md->is_consistent()); EXPECT_EQ(md->index(), 0u); EXPECT_EQ(md->name(), md1->name()); EXPECT_EQ(md->type(), md1->type()); @@ -261,7 +260,6 @@ TEST_F(DynamicTypesTests, DynamicType_basic) md2->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT64)); ASSERT_EQ(RETCODE_OK, struct_type_builder->get_member(member, 1)); ASSERT_EQ(RETCODE_OK, member->get_descriptor(md)); - EXPECT_TRUE(md->is_consistent()); EXPECT_EQ(md->index(), 1u); EXPECT_EQ(md->name(), md2->name()); EXPECT_EQ(md->type(), md2->type()); @@ -368,7 +366,7 @@ TEST_F(DynamicTypesTests, DynamicType_basic) // • checking adding duplicates { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); // + duplicate name md = traits::make_shared(); md->id(1); @@ -2502,7 +2500,7 @@ TEST_F(DynamicTypesTests, DynamicType_enum) ASSERT_EQ(builder->add_member(member_descriptor), RETCODE_OK); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); // Try to add a descriptor with the same name. member_descriptor = traits::make_shared(); member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32)); @@ -2717,7 +2715,7 @@ TEST_F(DynamicTypesTests, DynamicType_string) ASSERT_EQ(test1, test2); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); ASSERT_NE(data->set_string_value(MEMBER_ID_INVALID, "TEST_OVER_LENGTH_LIMITS"), RETCODE_OK); } @@ -2876,7 +2874,7 @@ TEST_F(DynamicTypesTests, DynamicType_wstring) { DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; - DynamicTypeBuilder::_ref_type builder {factory->create_wstring_type(0)}; + DynamicTypeBuilder::_ref_type builder {factory->create_wstring_type(static_cast(LENGTH_UNLIMITED))}; ASSERT_TRUE(builder); DynamicType::_ref_type created_type {builder->build()}; ASSERT_TRUE(created_type); @@ -2905,7 +2903,7 @@ TEST_F(DynamicTypesTests, DynamicType_wstring) ASSERT_EQ(test1, test2); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); ASSERT_NE(data->set_wstring_value(MEMBER_ID_INVALID, L"TEST_OVER_LENGTH_LIMITS"), RETCODE_OK); } @@ -3229,7 +3227,7 @@ TEST_F(DynamicTypesTests, DynamicType_nested_alias) ASSERT_EQ(test1, test2); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); ASSERT_NE(data->set_string_value(MEMBER_ID_INVALID, "TEST_OVER_LENGTH_LIMITS"), RETCODE_OK); } @@ -3719,7 +3717,7 @@ TEST_F(DynamicTypesTests, DynamicType_sequence) // Try to insert more than the limit. { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); ASSERT_NE(data->set_int32_values(0, {0, 1, 2, 3, 4, 5, 6}), RETCODE_OK); } @@ -3875,7 +3873,7 @@ TEST_F(DynamicTypesTests, DynamicType_sequence_of_sequences) // Try to insert more than the limit. { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); seq_data = data->loan_value(2); ASSERT_FALSE(seq_data); } @@ -4055,7 +4053,7 @@ TEST_F(DynamicTypesTests, DynamicType_array) // Try to insert more than the limit. { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); ASSERT_NE(data->set_int32_values(0, {1, 2, 3, 4, 5, 6, 7, 8, 9}), RETCODE_OK); } @@ -4235,7 +4233,7 @@ TEST_F(DynamicTypesTests, DynamicType_array_of_arrays) // Try to insert more than the limit. { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); + eprosima::fastdds::testing::ScopeLogs _("disable"); seq_data = data->loan_value(4); ASSERT_FALSE(seq_data); } @@ -5130,7 +5128,7 @@ TEST_F(DynamicTypesTests, DynamicType_structure_inheritance) member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32)); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); // avoid expected errors logging + eprosima::fastdds::testing::ScopeLogs _("disable"); // avoid expected errors logging member_descriptor->name("child_int32"); member_descriptor->id(1); ASSERT_NE(builder->add_member(member_descriptor), RETCODE_OK); @@ -5653,7 +5651,7 @@ TEST_F(DynamicTypesTests, DynamicType_union) ASSERT_EQ(builder->add_member(member_descriptor), RETCODE_OK); { - eprosima::fastdds::dds::Log::ScopeLogs _("disable"); // avoid expected errors logging + eprosima::fastdds::testing::ScopeLogs _("disable"); // avoid expected errors logging member_descriptor = traits::make_shared(); member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32));