diff --git a/src/cpp/fastdds/xtypes/type_representation/TypeObjectUtils.cpp b/src/cpp/fastdds/xtypes/type_representation/TypeObjectUtils.cpp index bf2636b03df..1da9038def9 100644 --- a/src/cpp/fastdds/xtypes/type_representation/TypeObjectUtils.cpp +++ b/src/cpp/fastdds/xtypes/type_representation/TypeObjectUtils.cpp @@ -829,22 +829,15 @@ void TypeObjectUtils::add_complete_struct_member( { throw InvalidArgumentError("Sequence has another member with same name"); } - } -#endif // !defined(NDEBUG) - auto it = member_seq.begin(); - for (; it != member_seq.end(); ++it) - { - // Ordered by the member_index - if (it->common().member_id() > member.common().member_id()) - { - break; - } - else if (it->common().member_id() == member.common().member_id()) + + if (struct_member.common().member_id() == member.common().member_id()) { throw InvalidArgumentError("Sequence has another member with same ID"); } } - member_seq.emplace(it, member); +#endif // !defined(NDEBUG) + // Ordered by the member_index + member_seq.emplace_back(member); } const AppliedBuiltinTypeAnnotations TypeObjectUtils::build_applied_builtin_type_annotations( @@ -999,6 +992,10 @@ void TypeObjectUtils::add_complete_union_member( { throw InvalidArgumentError("Sequence has another member with same name"); } + if (union_member.common().member_id() == member.common().member_id()) + { + throw InvalidArgumentError("Sequence has another member with same ID"); + } if (member.common().member_flags() & MemberFlagBits::IS_DEFAULT && union_member.common().member_flags() & MemberFlagBits::IS_DEFAULT) { @@ -1013,20 +1010,8 @@ void TypeObjectUtils::add_complete_union_member( } } #endif // !defined(NDEBUG) - auto it = complete_union_member_seq.begin(); - for (; it != complete_union_member_seq.end(); ++it) - { - // Ordered by member_index - if (it->common().member_id() > member.common().member_id()) - { - break; - } - else if (it->common().member_id() == member.common().member_id()) - { - throw InvalidArgumentError("Sequence has another member with same ID"); - } - } - complete_union_member_seq.emplace(it, member); + // Ordered by the member_index + complete_union_member_seq.emplace_back(member); } const CommonDiscriminatorMember TypeObjectUtils::build_common_discriminator_member( diff --git a/test/dds-types-test/appendableCdrAux.ipp b/test/dds-types-test/appendableCdrAux.ipp index 8c503904cd7..0a8f8ad05b3 100644 --- a/test/dds-types-test/appendableCdrAux.ipp +++ b/test/dds-types-test/appendableCdrAux.ipp @@ -1276,11 +1276,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const AppendableEmptyInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const AppendableEmptyStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1363,11 +1362,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const AppendableInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const AppendableShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1442,9 +1440,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const AppendableInheritanceEmptyStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const AppendableShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1527,11 +1526,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const AppendableExtensibilityInheritance& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_long(); - + extern void serialize_key( + Cdr& scdr, + const AppendableShortStruct& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/dds-types-test/finalCdrAux.ipp b/test/dds-types-test/finalCdrAux.ipp index e6d20caef66..3b2bf90cfc0 100644 --- a/test/dds-types-test/finalCdrAux.ipp +++ b/test/dds-types-test/finalCdrAux.ipp @@ -1276,11 +1276,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const FinalEmptyInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const FinalEmptyStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1363,11 +1362,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const FinalInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const FinalShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1442,9 +1440,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InheritanceEmptyStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const FinalShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1527,11 +1526,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const FinalExtensibilityInheritance& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_long(); - + extern void serialize_key( + Cdr& scdr, + const FinalShortStruct& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/dds-types-test/inheritanceCdrAux.ipp b/test/dds-types-test/inheritanceCdrAux.ipp index 68c0d1ab090..82a77fdf4fd 100644 --- a/test/dds-types-test/inheritanceCdrAux.ipp +++ b/test/dds-types-test/inheritanceCdrAux.ipp @@ -129,13 +129,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InnerStructureHelperChild& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_child_longlong(); - - scdr << data.var_child_ulonglong(); - + extern void serialize_key( + Cdr& scdr, + const InnerStructureHelper& data); + serialize_key(scdr, static_cast(data)); } @@ -250,13 +247,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InnerStructureHelperChildChild& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_child_childlonglong2(); - - scdr << data.var_childchild_ulonglong2(); - + extern void serialize_key( + Cdr& scdr, + const InnerStructureHelperChild& data); + serialize_key(scdr, static_cast(data)); } @@ -339,9 +333,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InnerStructureHelperEmptyChild& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const InnerStructureHelper& data); + serialize_key(scdr, static_cast(data)); } @@ -432,11 +427,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InnerStructureHelperEmptyChildChild& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_char(); - + extern void serialize_key( + Cdr& scdr, + const InnerStructureHelperEmptyChild& data); + serialize_key(scdr, static_cast(data)); } @@ -519,13 +513,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InnerEmptyStructureHelperChild& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_child_longlong(); - - scdr << data.var_child_ulonglong(); - + extern void serialize_key( + Cdr& scdr, + const InnerEmptyStructureHelper& data); + serialize_key(scdr, static_cast(data)); } @@ -616,11 +607,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const StructAliasInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.new_member(); - + extern void serialize_key( + Cdr& scdr, + const inner_structure_helper_alias& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/dds-types-test/keyCdrAux.ipp b/test/dds-types-test/keyCdrAux.ipp index e7d9d025abe..d593f5b255d 100644 --- a/test/dds-types-test/keyCdrAux.ipp +++ b/test/dds-types-test/keyCdrAux.ipp @@ -1344,9 +1344,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const KeyedEmptyInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const KeyedEmptyStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1445,9 +1446,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const KeyedInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const KeyedShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1530,9 +1532,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const InheritanceKeyedEmptyStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const KeyedShortStruct& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/dds-types-test/member_idCdrAux.ipp b/test/dds-types-test/member_idCdrAux.ipp index 454919f90ff..cac9a0b808a 100644 --- a/test/dds-types-test/member_idCdrAux.ipp +++ b/test/dds-types-test/member_idCdrAux.ipp @@ -1089,19 +1089,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const DerivedAutoidDefault& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.od(); - - scdr << data.lld(); - - scdr << data.cd(); - - scdr << data.ld(); - - scdr << data.sd(); - + extern void serialize_key( + Cdr& scdr, + const AutoidDefault& data); + serialize_key(scdr, static_cast(data)); } @@ -1208,9 +1199,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const DerivedEmptyAutoidSequential& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const AutoidSequential& data); + serialize_key(scdr, static_cast(data)); } @@ -1357,19 +1349,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const DerivedAutoidSequential& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.od(); - - scdr << data.cd(); - - scdr << data.ld(); - - scdr << data.lld(); - - scdr << data.sd(); - + extern void serialize_key( + Cdr& scdr, + const DerivedEmptyAutoidSequential& data); + serialize_key(scdr, static_cast(data)); } @@ -1516,19 +1499,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const DerivedAutoidHash& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.od(); - - scdr << data.lld(); - - scdr << data.cd(); - - scdr << data.ld(); - - scdr << data.sd(); - + extern void serialize_key( + Cdr& scdr, + const AutoidHash& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/dds-types-test/mutableCdrAux.ipp b/test/dds-types-test/mutableCdrAux.ipp index 712f46eb2f8..df63fd8c6a1 100644 --- a/test/dds-types-test/mutableCdrAux.ipp +++ b/test/dds-types-test/mutableCdrAux.ipp @@ -1276,11 +1276,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const MutableEmptyInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const MutableEmptyStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1363,11 +1362,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const MutableInheritanceStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_str(); - + extern void serialize_key( + Cdr& scdr, + const MutableShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1442,9 +1440,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const MutableInheritanceEmptyStruct& data) { - - static_cast(scdr); - static_cast(data); + extern void serialize_key( + Cdr& scdr, + const MutableShortStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -1527,11 +1526,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const MutableExtensibilityInheritance& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.var_long(); - + extern void serialize_key( + Cdr& scdr, + const MutableShortStruct& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/feature/dynamic_types/DynamicTypesDDSTypesTest.hpp b/test/feature/dynamic_types/DynamicTypesDDSTypesTest.hpp index 619012777c2..7e073e9a7b2 100644 --- a/test/feature/dynamic_types/DynamicTypesDDSTypesTest.hpp +++ b/test/feature/dynamic_types/DynamicTypesDDSTypesTest.hpp @@ -135,6 +135,17 @@ class DynamicTypesDDSTypesTest : public ::testing::Test ASSERT_TRUE(dyn_pubsubType.deserialize(static_payload, &data2)); EXPECT_TRUE(data2->equals(data)); + // Check key hash calculation + if (static_pubsubType.get()->is_compute_key_provided) + { + eprosima::fastdds::rtps::InstanceHandle_t static_ih; + eprosima::fastdds::rtps::InstanceHandle_t dyn_ih; + ASSERT_TRUE(static_pubsubType.compute_key(&data_static, static_ih)); + ASSERT_TRUE(dyn_pubsubType.compute_key(&data, dyn_ih)); + EXPECT_NE(static_ih, eprosima::fastdds::dds::InstanceHandle_t()); + EXPECT_EQ(static_ih, dyn_ih); + } + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data1), RETCODE_OK); EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data2), RETCODE_OK); } diff --git a/test/feature/dynamic_types/dds_types_tests/DynamicTypesKeyDDSTypesTests.cpp b/test/feature/dynamic_types/dds_types_tests/DynamicTypesKeyDDSTypesTests.cpp new file mode 100644 index 00000000000..a5bfebcbacf --- /dev/null +++ b/test/feature/dynamic_types/dds_types_tests/DynamicTypesKeyDDSTypesTests.cpp @@ -0,0 +1,1201 @@ +// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima). +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "../DynamicTypesDDSTypesTest.hpp" +#include "../../../dds-types-test/keyPubSubTypes.hpp" +#include "../../../dds-types-test/keyTypeObjectSupport.hpp" +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +constexpr const char* struct_short_name = "KeyedShortStruct"; +constexpr const char* struct_ushort_name = "KeyedUShortStruct"; +constexpr const char* struct_long_name = "KeyedLongStruct"; +constexpr const char* struct_ulong_name = "KeyedULongStruct"; +constexpr const char* struct_long_long_name = "KeyedLongLongStruct"; +constexpr const char* struct_ulong_long_name = "KeyedULongLongStruct"; +constexpr const char* struct_float_name = "KeyedFloatStruct"; +constexpr const char* struct_double_name = "KeyedDoubleStruct"; +constexpr const char* struct_long_double_name = "KeyedLongDoubleStruct"; +constexpr const char* struct_boolean_name = "KeyedBooleanStruct"; +constexpr const char* struct_byte_name = "KeyedOctetStruct"; +constexpr const char* struct_char_name = "KeyedCharStruct"; +constexpr const char* struct_wchar_name = "KeyedWCharStruct"; +constexpr const char* struct_empty_name = "KeyedEmptyStruct"; +constexpr const char* struct_empty_inheritance_name = "KeyedEmptyInheritanceStruct"; +constexpr const char* struct_inheritance_name = "KeyedInheritanceStruct"; +constexpr const char* struct_inheritance_empty_name = "InheritanceKeyedEmptyStruct"; +constexpr const char* struct_final_name = "KeyedFinal"; +constexpr const char* struct_appendable_name = "KeyedAppendable"; +constexpr const char* struct_mutable_name = "KeyedMutable"; + +constexpr const char* var_key_short_name = "key_short"; +constexpr const char* var_key_ushort_name = "key_ushort"; +constexpr const char* var_key_long_name = "key_long"; +constexpr const char* var_key_ulong_name = "key_ulong"; +constexpr const char* var_key_long_long_name = "key_longlong"; +constexpr const char* var_key_ulong_long_name = "key_ulonglong"; +constexpr const char* var_key_float_name = "key_float"; +constexpr const char* var_key_double_name = "key_double"; +constexpr const char* var_key_long_double_name = "key_longdouble"; +constexpr const char* var_key_boolean_name = "key_boolean"; +constexpr const char* var_key_byte_name = "key_octet"; +constexpr const char* var_key_char_name = "key_char8"; +constexpr const char* var_key_wchar_name = "key_char16"; +constexpr const char* var_key_str_name = "key_str"; +constexpr const char* var_var_str_name = "var_str"; +constexpr const char* var_key_string_name = "key_string"; + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedShortStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_short_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int16_t value {2}; + int16_t test_value {0}; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedShortStruct struct_data; + TypeSupport static_pubsubType {new KeyedShortStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_short(), test_value); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedShortStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedUShortStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_ushort_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_ushort_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_ushort_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT16)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + uint16_t value {2}; + uint16_t test_value {0}; + EXPECT_EQ(data->set_uint16_value(data->get_member_id_by_name(var_key_ushort_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint16_value(test_value, data->get_member_id_by_name(var_key_ushort_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_uint16_value(data->get_member_id_by_name(var_ushort_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint16_value(test_value, data->get_member_id_by_name(var_ushort_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedUShortStruct struct_data; + TypeSupport static_pubsubType {new KeyedUShortStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_ushort(), test_value); + EXPECT_EQ(struct_data.var_ushort(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedUShortStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedLongStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_long_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT32)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT32)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int32_t value {2}; + int32_t test_value {0}; + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_key_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(test_value, data->get_member_id_by_name(var_key_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(test_value, data->get_member_id_by_name(var_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedLongStruct struct_data; + TypeSupport static_pubsubType {new KeyedLongStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_long(), test_value); + EXPECT_EQ(struct_data.var_long(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedLongStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedULongStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_ulong_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_ulong_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT32)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_ulong_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT32)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + uint32_t value {2}; + uint32_t test_value {0}; + EXPECT_EQ(data->set_uint32_value(data->get_member_id_by_name(var_key_ulong_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint32_value(test_value, data->get_member_id_by_name(var_key_ulong_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_uint32_value(data->get_member_id_by_name(var_ulong_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint32_value(test_value, data->get_member_id_by_name(var_ulong_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedULongStruct struct_data; + TypeSupport static_pubsubType {new KeyedULongStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_ulong(), test_value); + EXPECT_EQ(struct_data.var_ulong(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedULongStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedLongLongStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_long_long_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT64)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_long_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT64)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int64_t value {2}; + int64_t test_value {0}; + + EXPECT_EQ(data->set_int64_value(data->get_member_id_by_name(var_key_long_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int64_value(test_value, data->get_member_id_by_name(var_key_long_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_int64_value(data->get_member_id_by_name(var_long_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int64_value(test_value, data->get_member_id_by_name(var_long_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedLongLongStruct struct_data; + TypeSupport static_pubsubType {new KeyedLongLongStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_longlong(), test_value); + EXPECT_EQ(struct_data.var_longlong(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedLongLongStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedULongLongStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_ulong_long_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_ulong_long_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT64)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_ulong_long_name); + member_descriptor->type(factory->get_primitive_type(TK_UINT64)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + uint64_t value {2}; + uint64_t test_value {0}; + EXPECT_EQ(data->set_uint64_value(data->get_member_id_by_name(var_key_ulong_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint64_value(test_value, data->get_member_id_by_name(var_key_ulong_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_uint64_value(data->get_member_id_by_name(var_ulong_long_name), value), RETCODE_OK); + EXPECT_EQ(data->get_uint64_value(test_value, data->get_member_id_by_name(var_ulong_long_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedULongLongStruct struct_data; + TypeSupport static_pubsubType {new KeyedULongLongStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_ulonglong(), test_value); + EXPECT_EQ(struct_data.var_ulonglong(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedULongLongStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedFloatStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_float_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_float_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT32)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_float_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT32)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + float value {2}; + float test_value {0}; + EXPECT_EQ(data->set_float32_value(data->get_member_id_by_name(var_key_float_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float32_value(test_value, data->get_member_id_by_name(var_key_float_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_float32_value(data->get_member_id_by_name(var_float_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float32_value(test_value, data->get_member_id_by_name(var_float_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedFloatStruct struct_data; + TypeSupport static_pubsubType {new KeyedFloatStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_float(), test_value); + EXPECT_EQ(struct_data.var_float(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedFloatStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedDoubleStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_double_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_double_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT64)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_double_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT64)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + double value {2}; + double test_value {0}; + EXPECT_EQ(data->set_float64_value(data->get_member_id_by_name(var_key_double_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float64_value(test_value, data->get_member_id_by_name(var_key_double_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_float64_value(data->get_member_id_by_name(var_double_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float64_value(test_value, data->get_member_id_by_name(var_double_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedDoubleStruct struct_data; + TypeSupport static_pubsubType {new KeyedDoubleStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_double(), test_value); + EXPECT_EQ(struct_data.var_double(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedDoubleStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedLongDoubleStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_long_double_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_double_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT128)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_long_double_name); + member_descriptor->type(factory->get_primitive_type(TK_FLOAT128)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + long double value {2}; + long double test_value {0}; + EXPECT_EQ(data->set_float128_value(data->get_member_id_by_name(var_key_long_double_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float128_value(test_value, data->get_member_id_by_name(var_key_long_double_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_float128_value(data->get_member_id_by_name(var_long_double_name), value), RETCODE_OK); + EXPECT_EQ(data->get_float128_value(test_value, data->get_member_id_by_name(var_long_double_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedLongDoubleStruct struct_data; + TypeSupport static_pubsubType {new KeyedLongDoubleStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_longdouble(), test_value); + EXPECT_EQ(struct_data.var_longdouble(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedLongDoubleStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedBooleanStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_boolean_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_boolean_name); + member_descriptor->type(factory->get_primitive_type(TK_BOOLEAN)); + member_descriptor->is_key(true); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_bool_name); + member_descriptor->type(factory->get_primitive_type(TK_BOOLEAN)); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + bool value = true; + bool test_value = false; + EXPECT_EQ(data->set_boolean_value(data->get_member_id_by_name(var_key_boolean_name), value), RETCODE_OK); + EXPECT_EQ(data->get_boolean_value(test_value, data->get_member_id_by_name(var_key_boolean_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_boolean_value(data->get_member_id_by_name(var_bool_name), value), RETCODE_OK); + EXPECT_EQ(data->get_boolean_value(test_value, data->get_member_id_by_name(var_bool_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedBooleanStruct alias_data; + TypeSupport static_pubsubType {new KeyedBooleanStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, alias_data, static_pubsubType); + EXPECT_EQ(alias_data.key_boolean(), test_value); + EXPECT_EQ(alias_data.var_boolean(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedBooleanStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedOctetStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_byte_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_byte_name); + member_descriptor->type(factory->get_primitive_type(TK_BYTE)); + member_descriptor->is_key(true); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_byte_name); + member_descriptor->type(factory->get_primitive_type(TK_BYTE)); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + eprosima::fastdds::rtps::octet value {2}; + eprosima::fastdds::rtps::octet test_value {0}; + EXPECT_EQ(data->set_byte_value(data->get_member_id_by_name(var_key_byte_name), value), RETCODE_OK); + EXPECT_EQ(data->get_byte_value(test_value, data->get_member_id_by_name(var_key_byte_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_byte_value(data->get_member_id_by_name(var_byte_name), value), RETCODE_OK); + EXPECT_EQ(data->get_byte_value(test_value, data->get_member_id_by_name(var_byte_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedOctetStruct alias_data; + TypeSupport static_pubsubType {new KeyedOctetStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, alias_data, static_pubsubType); + EXPECT_EQ(alias_data.key_octet(), test_value); + EXPECT_EQ(alias_data.var_octet(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedOctetStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedCharStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_char_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_char_name); + member_descriptor->type(factory->get_primitive_type(TK_CHAR8)); + member_descriptor->is_key(true); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_char_name); + member_descriptor->type(factory->get_primitive_type(TK_CHAR8)); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + char value = 'a'; + char test_value = 'b'; + EXPECT_EQ(data->set_char8_value(data->get_member_id_by_name(var_key_char_name), value), RETCODE_OK); + EXPECT_EQ(data->get_char8_value(test_value, data->get_member_id_by_name(var_key_char_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_char8_value(data->get_member_id_by_name(var_char_name), value), RETCODE_OK); + EXPECT_EQ(data->get_char8_value(test_value, data->get_member_id_by_name(var_char_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedCharStruct alias_data; + TypeSupport static_pubsubType {new KeyedCharStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, alias_data, static_pubsubType); + EXPECT_EQ(alias_data.key_char8(), test_value); + EXPECT_EQ(alias_data.var_char8(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedCharStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedWCharStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_wchar_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_wchar_name); + member_descriptor->type(factory->get_primitive_type(TK_CHAR16)); + member_descriptor->is_key(true); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_wchar_name); + member_descriptor->type(factory->get_primitive_type(TK_CHAR16)); + ASSERT_EQ(RETCODE_OK, type_builder->add_member(member_descriptor)); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + wchar_t value = L'a'; + wchar_t test_value = L'b'; + EXPECT_EQ(data->set_char16_value(data->get_member_id_by_name(var_key_wchar_name), value), RETCODE_OK); + EXPECT_EQ(data->get_char16_value(test_value, data->get_member_id_by_name(var_key_wchar_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_char16_value(data->get_member_id_by_name(var_wchar_name), value), RETCODE_OK); + EXPECT_EQ(data->get_char16_value(test_value, data->get_member_id_by_name(var_wchar_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedWCharStruct alias_data; + TypeSupport static_pubsubType {new KeyedWCharStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, alias_data, static_pubsubType); + EXPECT_EQ(alias_data.key_char16(), test_value); + EXPECT_EQ(alias_data.var_char16(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedWCharStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedEmptyStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_empty_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int16_t value {2}; + int16_t test_value {0}; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + KeyedEmptyStruct struct_data; + TypeSupport static_pubsubType {new KeyedEmptyStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_short(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedEmptyStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedEmptyInheritanceStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_empty_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type base_type {type_builder->build()}; + + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_empty_inheritance_name); + type_descriptor->base_type(base_type); + type_builder = factory->create_type(type_descriptor); + ASSERT_TRUE(type_builder); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_str_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_var_str_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int16_t value {2}; + int16_t test_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_key_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_key_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + + for (auto encoding : encodings) + { + KeyedEmptyInheritanceStruct struct_data; + TypeSupport static_pubsubType {new KeyedEmptyInheritanceStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_short(), test_value); + EXPECT_EQ(struct_data.key_str(), test_str_value); + EXPECT_EQ(struct_data.var_str(), test_str_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedEmptyInheritanceStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedInheritanceStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_short_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type base_type {type_builder->build()}; + + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_inheritance_name); + type_descriptor->base_type(base_type); + type_builder = factory->create_type(type_descriptor); + ASSERT_TRUE(type_builder); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_str_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_var_str_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int16_t value {2}; + int16_t test_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_key_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_key_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + + for (auto encoding : encodings) + { + KeyedInheritanceStruct struct_data; + TypeSupport static_pubsubType {new KeyedInheritanceStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_short(), test_value); + EXPECT_EQ(struct_data.var_short(), test_value); + EXPECT_EQ(struct_data.key_str(), test_str_value); + EXPECT_EQ(struct_data.var_str(), test_str_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedInheritanceStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_InheritanceKeyedEmptyStruct) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_short_name); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type base_type {type_builder->build()}; + + type_descriptor = traits::make_shared(); + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_inheritance_empty_name); + type_descriptor->base_type(base_type); + type_builder = factory->create_type(type_descriptor); + ASSERT_TRUE(type_builder); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int16_t value {2}; + int16_t test_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(value, test_value); + + for (auto encoding : encodings) + { + InheritanceKeyedEmptyStruct struct_data; + TypeSupport static_pubsubType {new InheritanceKeyedEmptyStructPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_short(), test_value); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_InheritanceKeyedEmptyStruct_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedFinal) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_final_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT32)); + member_descriptor->is_key(true); + member_descriptor->id(2); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + member_descriptor->id(1); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_string_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + member_descriptor->is_key(true); + member_descriptor->id(0); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int32_t l_value {3}; + int32_t test_l_value {0}; + int16_t s_value {2}; + int16_t test_s_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_key_long_name), l_value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(test_l_value, data->get_member_id_by_name(var_key_long_name)), RETCODE_OK); + EXPECT_EQ(l_value, test_l_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), s_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_s_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(s_value, test_s_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_key_string_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_key_string_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + + for (auto encoding : encodings) + { + KeyedFinal struct_data; + TypeSupport static_pubsubType {new KeyedFinalPubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_long(), test_l_value); + EXPECT_EQ(struct_data.key_short(), test_s_value); + EXPECT_EQ(struct_data.key_string(), test_str_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedFinal_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedAppendable) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_appendable_name); + type_descriptor->extensibility_kind(ExtensibilityKind::APPENDABLE); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT32)); + member_descriptor->is_key(true); + member_descriptor->id(2); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + member_descriptor->id(1); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_string_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + member_descriptor->is_key(true); + member_descriptor->id(0); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int32_t l_value {3}; + int32_t test_l_value {0}; + int16_t s_value {2}; + int16_t test_s_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_key_long_name), l_value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(test_l_value, data->get_member_id_by_name(var_key_long_name)), RETCODE_OK); + EXPECT_EQ(l_value, test_l_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), s_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_s_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(s_value, test_s_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_key_string_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_key_string_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + + for (auto encoding : encodings) + { + KeyedAppendable struct_data; + TypeSupport static_pubsubType {new KeyedAppendablePubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_long(), test_l_value); + EXPECT_EQ(struct_data.key_short(), test_s_value); + EXPECT_EQ(struct_data.key_string(), test_str_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedAppendable_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_KeyedMutable) +{ + DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()}; + + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(struct_mutable_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {factory->create_type(type_descriptor)}; + ASSERT_TRUE(type_builder); + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_key_long_name); + member_descriptor->type(factory->get_primitive_type(TK_INT32)); + member_descriptor->is_key(true); + member_descriptor->id(2); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_short_name); + member_descriptor->type(factory->get_primitive_type(TK_INT16)); + member_descriptor->is_key(true); + member_descriptor->id(1); + type_builder->add_member(member_descriptor); + + member_descriptor = traits::make_shared(); + member_descriptor->name(var_key_string_name); + member_descriptor->type(factory->create_string_type(static_cast(LENGTH_UNLIMITED))->build()); + member_descriptor->is_key(true); + member_descriptor->id(0); + type_builder->add_member(member_descriptor); + + DynamicType::_ref_type struct_type {type_builder->build()}; + + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + int32_t l_value {3}; + int32_t test_l_value {0}; + int16_t s_value {2}; + int16_t test_s_value {0}; + std::string str_value {"my_string"}; + std::string test_str_value; + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_key_long_name), l_value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(test_l_value, data->get_member_id_by_name(var_key_long_name)), RETCODE_OK); + EXPECT_EQ(l_value, test_l_value); + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_key_short_name), s_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(test_s_value, data->get_member_id_by_name(var_key_short_name)), RETCODE_OK); + EXPECT_EQ(s_value, test_s_value); + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_key_string_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(test_str_value, data->get_member_id_by_name(var_key_string_name)), RETCODE_OK); + EXPECT_EQ(str_value, test_str_value); + + for (auto encoding : encodings) + { + KeyedMutable struct_data; + TypeSupport static_pubsubType {new KeyedMutablePubSubType()}; + check_serialization_deserialization(struct_type, data, encoding, struct_data, static_pubsubType); + EXPECT_EQ(struct_data.key_long(), test_l_value); + EXPECT_EQ(struct_data.key_short(), test_s_value); + EXPECT_EQ(struct_data.key_string(), test_str_value); + } + + xtypes::TypeIdentifierPair static_type_ids; + register_KeyedMutable_type_identifier(static_type_ids); + check_typeobject_registry(struct_type, static_type_ids); + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +} // dds +} // fastdds +} // eprosima diff --git a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp index d60c8797ff5..d67363dff20 100644 --- a/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp +++ b/test/unittest/dds/xtypes/serializers/idl/types/struct_struct/gen/struct_structCdrAux.ipp @@ -208,19 +208,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const ParentStruct& data) { - extern void serialize_key( - Cdr& scdr, - const GrandparentStruct& data); - - - static_cast(scdr); - static_cast(data); - scdr << data.my_short(); - - scdr << data.my_string(); - - serialize_key(scdr, data.my_grandparent()); - + extern void serialize_key( + Cdr& scdr, + const GrandparentStruct& data); + serialize_key(scdr, static_cast(data)); } @@ -414,18 +405,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const StructStruct& data) { - extern void serialize_key( - Cdr& scdr, - const NestedStructElement& data); - - - - static_cast(scdr); - static_cast(data); - serialize_key(scdr, data.my_nested_element()); - - scdr << data.my_char(); - + extern void serialize_key( + Cdr& scdr, + const ParentStruct& data); + serialize_key(scdr, static_cast(data)); } diff --git a/test/unittest/dds/xtypes/serializers/json/types/comprehensive_type/gen/ComprehensiveTypeCdrAux.ipp b/test/unittest/dds/xtypes/serializers/json/types/comprehensive_type/gen/ComprehensiveTypeCdrAux.ipp index 544fb01f945..3173240ee07 100644 --- a/test/unittest/dds/xtypes/serializers/json/types/comprehensive_type/gen/ComprehensiveTypeCdrAux.ipp +++ b/test/unittest/dds/xtypes/serializers/json/types/comprehensive_type/gen/ComprehensiveTypeCdrAux.ipp @@ -910,49 +910,10 @@ void serialize_key( eprosima::fastcdr::Cdr& scdr, const AllStruct& data) { - - static_cast(scdr); - static_cast(data); - scdr << data.my_string(); - - scdr << data.my_wstring(); - - scdr << data.my_bounded_string(); - - scdr << data.my_bounded_wstring(); - - scdr << data.my_enum(); - - scdr << data.my_bitmask(); - - scdr << data.my_aliased_struct(); - - scdr << data.my_aliased_enum(); - - scdr << data.my_aliased_bounded_string(); - - scdr << data.my_recursive_alias(); - - scdr << data.bitmask_sequence(); - - scdr << data.enum_sequence(); - - scdr << data.short_sequence(); - - scdr << data.long_array(); - - scdr << data.string_unbounded_map(); - - scdr << data.string_alias_unbounded_map(); - - scdr << data.short_long_map(); - - scdr << data.inner_union(); - - scdr << data.complex_union(); - - scdr << data.my_bitset(); - + extern void serialize_key( + Cdr& scdr, + const PrimitivesStruct& data); + serialize_key(scdr, static_cast(data)); }