From 9850955b06a5b8aae28a769b6405b657124c31bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez=20Moreno?= Date: Fri, 26 Jul 2024 13:07:51 +0200 Subject: [PATCH] Refs #21379. Add test for new enumeration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González Moreno --- .../xtypes/type_representation/TypeObjectRegistry.cpp | 3 ++- test/dds-types-test/enumerationsTypeObjectSupport.cxx | 6 +++--- .../DynamicTypesEnumerationsDDSTypesTests.cpp | 10 ++++++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp index cd674a3fc70..4b71fba68db 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectRegistry.cpp @@ -2111,7 +2111,8 @@ ReturnCode_t TypeObjectRegistry::register_typeobject_w_enum_dynamic_type( member_descriptor.is_default_label())}; // TODO(richi): Literal value might be automatically assigned or taken from default_value (@value annotation) CommonEnumeratedLiteral common_literal {TypeObjectUtils::build_common_enumerated_literal( - member_descriptor.index(), flags)}; + member_descriptor.default_value().empty() ? member_descriptor.index() : + std::stol(member_descriptor.default_value()), flags)}; CompleteMemberDetail member_detail; complete_member_detail(literal, member_detail); CompleteEnumeratedLiteral literal_member {TypeObjectUtils::build_complete_enumerated_literal( diff --git a/test/dds-types-test/enumerationsTypeObjectSupport.cxx b/test/dds-types-test/enumerationsTypeObjectSupport.cxx index c66e3a2f397..cbcfa203ebb 100644 --- a/test/dds-types-test/enumerationsTypeObjectSupport.cxx +++ b/test/dds-types-test/enumerationsTypeObjectSupport.cxx @@ -119,7 +119,7 @@ void register_EnumWithValues_type_identifier( CompleteEnumeratedLiteralSeq literal_seq_EnumWithValues; { EnumeratedLiteralFlag flags_ENUM_VALUE1 = TypeObjectUtils::build_enumerated_literal_flag(false); - CommonEnumeratedLiteral common_ENUM_VALUE1 = TypeObjectUtils::build_common_enumerated_literal(0, flags_ENUM_VALUE1); + CommonEnumeratedLiteral common_ENUM_VALUE1 = TypeObjectUtils::build_common_enumerated_literal(-3, flags_ENUM_VALUE1); eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE1; ann_custom_EnumWithValues.reset(); AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE1; @@ -134,7 +134,7 @@ void register_EnumWithValues_type_identifier( } { EnumeratedLiteralFlag flags_ENUM_VALUE2 = TypeObjectUtils::build_enumerated_literal_flag(false); - CommonEnumeratedLiteral common_ENUM_VALUE2 = TypeObjectUtils::build_common_enumerated_literal(1, flags_ENUM_VALUE2); + CommonEnumeratedLiteral common_ENUM_VALUE2 = TypeObjectUtils::build_common_enumerated_literal(0, flags_ENUM_VALUE2); eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE2; ann_custom_EnumWithValues.reset(); AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE2; @@ -149,7 +149,7 @@ void register_EnumWithValues_type_identifier( } { EnumeratedLiteralFlag flags_ENUM_VALUE3 = TypeObjectUtils::build_enumerated_literal_flag(false); - CommonEnumeratedLiteral common_ENUM_VALUE3 = TypeObjectUtils::build_common_enumerated_literal(2, flags_ENUM_VALUE3); + CommonEnumeratedLiteral common_ENUM_VALUE3 = TypeObjectUtils::build_common_enumerated_literal(3, flags_ENUM_VALUE3); eprosima::fastcdr::optional member_ann_builtin_ENUM_VALUE3; ann_custom_EnumWithValues.reset(); AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE3; diff --git a/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp b/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp index 5d143dff0f7..406dc7efbcb 100644 --- a/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp +++ b/test/feature/dynamic_types/dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp @@ -253,18 +253,21 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumWithValuesStructure) DynamicTypeBuilderFactory::get_instance()->get_primitive_type( TK_INT32)); enum_literal_descriptor->name("ENUM_VALUE1"); + enum_literal_descriptor->default_value("-3"); enum_builder->add_member(enum_literal_descriptor); enum_literal_descriptor = traits::make_shared(); enum_literal_descriptor->type( DynamicTypeBuilderFactory::get_instance()->get_primitive_type( TK_INT32)); enum_literal_descriptor->name("ENUM_VALUE2"); + enum_literal_descriptor->default_value("0"); enum_builder->add_member(enum_literal_descriptor); enum_literal_descriptor = traits::make_shared(); enum_literal_descriptor->type( DynamicTypeBuilderFactory::get_instance()->get_primitive_type( TK_INT32)); enum_literal_descriptor->name("ENUM_VALUE3"); + enum_literal_descriptor->default_value("3"); enum_builder->add_member(enum_literal_descriptor); MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; @@ -277,12 +280,15 @@ TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_EnumWithValuesStructure) DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; ASSERT_TRUE(data); - int32_t value = 0; + int32_t value = 3; int32_t test_value = 0; EXPECT_EQ( data->set_int32_value( data->get_member_id_by_name( - var_enumwithvalues_name), 1), RETCODE_OK); + var_enumwithvalues_name), value), RETCODE_OK); + EXPECT_EQ( + data->get_int32_value(test_value, + data->get_member_id_by_name(var_enumwithvalues_name)), RETCODE_OK); EXPECT_EQ(value, test_value); for (auto encoding : encodings)