Skip to content

Commit

Permalink
Refs #21379. Add test for new enumeration
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware committed Jul 26, 2024
1 parent d2cb6e0 commit 8baf9e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,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(common_literal,
Expand Down
6 changes: 3 additions & 3 deletions test/dds-types-test/enumerationsTypeObjectSupport.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE1;
ann_custom_EnumWithValues.reset();
AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE1;
Expand All @@ -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<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE2;
ann_custom_EnumWithValues.reset();
AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE2;
Expand All @@ -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<AppliedBuiltinMemberAnnotations> member_ann_builtin_ENUM_VALUE3;
ann_custom_EnumWithValues.reset();
AppliedAnnotationSeq tmp_ann_custom_ENUM_VALUE3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemberDescriptor>::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<MemberDescriptor>::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<MemberDescriptor>::make_shared()};
Expand All @@ -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)
Expand Down

0 comments on commit 8baf9e1

Please sign in to comment.