From 8096fd0f3f5d1f86a061f7a60036faed18698b63 Mon Sep 17 00:00:00 2001 From: adriancampo Date: Wed, 3 Apr 2024 14:18:22 +0200 Subject: [PATCH] Refs #20424: Added tests for finals and mutables. Signed-off-by: adriancampo --- test/feature/dynamic_types/CMakeLists.txt | 10 +- .../DynamicTypesFinalDDSTypesTests.cpp | 925 ++++++++++++++++++ .../DynamicTypesMutableDDSTypesTests.cpp | 925 ++++++++++++++++++ 3 files changed, 1856 insertions(+), 4 deletions(-) create mode 100644 test/feature/dynamic_types/dds_types_tests/DynamicTypesFinalDDSTypesTests.cpp create mode 100644 test/feature/dynamic_types/dds_types_tests/DynamicTypesMutableDDSTypesTests.cpp diff --git a/test/feature/dynamic_types/CMakeLists.txt b/test/feature/dynamic_types/CMakeLists.txt index 83ed79383d5..5748e6eeb34 100644 --- a/test/feature/dynamic_types/CMakeLists.txt +++ b/test/feature/dynamic_types/CMakeLists.txt @@ -27,8 +27,10 @@ set(DYNAMIC_TYPES_DDS_TYPES_TEST_SOURCE dds_types_tests/DynamicTypesArraysDDSTypesTests.cpp dds_types_tests/DynamicTypesBitsetsDDSTypesTests.cpp dds_types_tests/DynamicTypesEnumerationsDDSTypesTests.cpp + dds_types_tests/DynamicTypesFinalDDSTypesTests.cpp dds_types_tests/DynamicTypesInheritanceDDSTypesTests.cpp dds_types_tests/DynamicTypesMapsDDSTypesTests.cpp + dds_types_tests/DynamicTypesMutableDDSTypesTests.cpp dds_types_tests/DynamicTypesPrimitivesDDSTypesTests.cpp dds_types_tests/DynamicTypesSequencesDDSTypesTests.cpp dds_types_tests/DynamicTypesStringsDDSTypesTests.cpp @@ -46,12 +48,16 @@ set(DYNAMIC_TYPES_DDS_TYPES_TEST_SOURCE ${PROJECT_SOURCE_DIR}/test/dds-types-test/bitsetsTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/enumerationsPubSubTypes.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/enumerationsTypeObjectSupport.cxx + ${PROJECT_SOURCE_DIR}/test/dds-types-test/finalPubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/dds-types-test/finalTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/helpers/basic_inner_typesPubSubTypes.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/helpers/basic_inner_typesTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/inheritancePubSubTypes.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/inheritanceTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/mapsPubSubTypes.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/mapsTypeObjectSupport.cxx + ${PROJECT_SOURCE_DIR}/test/dds-types-test/mutablePubSubTypes.cxx + ${PROJECT_SOURCE_DIR}/test/dds-types-test/mutableTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/primitivesPubSubTypes.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/primitivesTypeObjectSupport.cxx ${PROJECT_SOURCE_DIR}/test/dds-types-test/sequencesPubSubTypes.cxx @@ -66,14 +72,10 @@ set(DYNAMIC_TYPES_DDS_TYPES_TEST_SOURCE # ${PROJECT_SOURCE_DIR}/test/dds-types-test/constantsTypeObjectSupport.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/declarationsPubSubTypes.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/externalPubSubTypes.cxx - # ${PROJECT_SOURCE_DIR}/test/dds-types-test/finalPubSubTypes.cxx - # ${PROJECT_SOURCE_DIR}/test/dds-types-test/finalTypeObjectSupport.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/keyPubSubTypes.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/keyTypeObjectSupport.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/member_idPubSubTypes.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/member_idTypeObjectSupport.cxx - # ${PROJECT_SOURCE_DIR}/test/dds-types-test/mutablePubSubTypes.cxx - # ${PROJECT_SOURCE_DIR}/test/dds-types-test/mutableTypeObjectSupport.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/optionalPubSubTypes.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/optionalTypeObjectSupport.cxx # ${PROJECT_SOURCE_DIR}/test/dds-types-test/relative_path_includePubSubTypes.cxx diff --git a/test/feature/dynamic_types/dds_types_tests/DynamicTypesFinalDDSTypesTests.cpp b/test/feature/dynamic_types/dds_types_tests/DynamicTypesFinalDDSTypesTests.cpp new file mode 100644 index 00000000000..16260911527 --- /dev/null +++ b/test/feature/dynamic_types/dds_types_tests/DynamicTypesFinalDDSTypesTests.cpp @@ -0,0 +1,925 @@ +// 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/helpers/basic_inner_types.hpp" +#include "../../../dds-types-test/finalPubSubTypes.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +constexpr const char* const final_short_struct_name = "FinalShortStruct"; +constexpr const char* const final_ushort_struct_name = "FinalUShortStruct"; +constexpr const char* const final_long_struct_name = "FinalLongStruct"; +constexpr const char* const final_ulong_struct_name = "FinalULongStruct"; +constexpr const char* const final_longlong_struct_name = "FinalLongLongStruct"; +constexpr const char* const final_ulonglong_struct_name = "FinalULongLongStruct"; +constexpr const char* const final_float_struct_name = "FinalFloatStruct"; +constexpr const char* const final_double_struct_name = "FinalDoubleStruct"; +constexpr const char* const final_longdouble_struct_name = "FinalLongDoubleStruct"; +constexpr const char* const final_bool_struct_name = "FinalBooleanStruct"; +constexpr const char* const final_byte_struct_name = "FinalOctetStruct"; +constexpr const char* const final_char_struct_name = "FinalCharStruct"; +constexpr const char* const final_wchar_struct_name = "FinalWCharStruct"; +constexpr const char* const final_union_struct_name = "FinalUnionStruct"; +constexpr const char* const final_empty_struct_name = "FinalEmptyStruct"; +constexpr const char* const final_emptyinheritance_struct_name = "FinalEmptyInheritanceStruct"; +constexpr const char* const final_inheritance_struct_name = "FinalInheritanceStruct"; +constexpr const char* const final_inheritanceempty_struct_name = "InheritanceEmptyStruct"; +constexpr const char* const final_extensibilityinheritance_struct_name = "FinalExtensibilityInheritance"; + +constexpr const char* var_str_name = "var_str"; + +DynamicType::_ref_type create_final_short_struct() +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_short_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_short_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + type_builder->add_member(member_descriptor); + + return type_builder->build(); +} + +DynamicType::_ref_type create_final_empty_struct() +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_empty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + return type_builder->build(); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalShortStruct) +{ + DynamicType::_ref_type struct_type = create_final_short_struct(); + 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_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); + + // XCDRv1 + { + FinalShortStruct struct_data; + FinalShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + // XCDRv2 + { + FinalShortStruct struct_data; + FinalShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalUShortStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_ushort_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ushort_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalUShortStruct struct_data; + FinalUShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ushort(), test_value); + } + + // XCDRv2 + { + FinalUShortStruct struct_data; + FinalUShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ushort(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_long_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalLongStruct struct_data; + FinalLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_long(), test_value); + } + + // XCDRv2 + { + FinalLongStruct struct_data; + FinalLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_long(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalULongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_ulong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ulong_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalULongStruct struct_data; + FinalULongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulong(), test_value); + } + + // XCDRv2 + { + FinalULongStruct struct_data; + FinalULongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalLongLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_longlong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalLongLongStruct struct_data; + FinalLongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longlong(), test_value); + } + + // XCDRv2 + { + FinalLongLongStruct struct_data; + FinalLongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longlong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalULongLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_ulonglong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ulong_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalULongLongStruct struct_data; + FinalULongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulonglong(), test_value); + } + + // XCDRv2 + { + FinalULongLongStruct struct_data; + FinalULongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulonglong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalFloatStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_float_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_float_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalFloatStruct struct_data; + FinalFloatStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_float(), test_value); + } + + // XCDRv2 + { + FinalFloatStruct struct_data; + FinalFloatStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_float(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalDoubleStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_double_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_double_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalDoubleStruct struct_data; + FinalDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_double(), test_value); + } + + // XCDRv2 + { + FinalDoubleStruct struct_data; + FinalDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_double(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalLongDoubleStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_longdouble_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_double_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + FinalLongDoubleStruct struct_data; + FinalLongDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longdouble(), test_value); + } + + // XCDRv2 + { + FinalLongDoubleStruct struct_data; + FinalLongDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longdouble(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalBooleanStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_bool_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_bool_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + 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_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); + + // XCDRv1 + { + FinalBooleanStruct struct_data; + FinalBooleanStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_boolean(), test_value); + } + + // XCDRv2 + { + FinalBooleanStruct struct_data; + FinalBooleanStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_boolean(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalOctetStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_byte_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_byte_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BYTE)); + 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::fastrtps::rtps::octet value = 255; + eprosima::fastrtps::rtps::octet test_value = 0; + 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); + + // XCDRv1 + { + FinalOctetStruct struct_data; + FinalOctetStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_octet(), test_value); + } + + // XCDRv2 + { + FinalOctetStruct struct_data; + FinalOctetStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_octet(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalCharStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_char_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_char_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + 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_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); + + // XCDRv1 + { + FinalCharStruct struct_data; + FinalCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char8(), test_value); + } + + // XCDRv2 + { + FinalCharStruct struct_data; + FinalCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char8(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalWCharStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_wchar_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_wchar_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + 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_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); + + // XCDRv1 + { + FinalWCharStruct struct_data; + FinalWCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char16(), test_value); + } + + // XCDRv2 + { + FinalWCharStruct struct_data; + FinalWCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char16(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalUnionStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_union_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_union_name); + member_descriptor->type(DynamicTypesDDSTypesTest::create_inner_union_helper()); + 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 float_value = 23.5; + float test_float_value = 0; + int16_t short_value = 55; + int16_t test_short_value = 0; + DynamicData::_ref_type union_data = data->loan_value(data->get_member_id_by_name(var_union_name)); + ASSERT_TRUE(union_data); + + EXPECT_EQ(union_data->set_float32_value(union_data->get_member_id_by_name( + union_float_member_name), float_value), RETCODE_OK); + EXPECT_EQ(union_data->get_float32_value(test_float_value, union_data->get_member_id_by_name( + union_float_member_name)), RETCODE_OK); + EXPECT_EQ(float_value, test_float_value); + EXPECT_EQ(union_data->set_int16_value(union_data->get_member_id_by_name( + union_short_member_name), short_value), RETCODE_OK); + EXPECT_EQ(union_data->get_int16_value(test_short_value, union_data->get_member_id_by_name( + union_short_member_name)), RETCODE_OK); + EXPECT_EQ(short_value, test_short_value); + EXPECT_EQ(data->return_loaned_value(union_data), RETCODE_OK); + + // XCDRv1 + { + FinalUnionStruct struct_data; + FinalUnionStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_union().shortValue(), test_short_value); + } + + // XCDRv2 + { + FinalUnionStruct struct_data; + FinalUnionStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_union().shortValue(), test_short_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalEmptyStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_empty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + DynamicType::_ref_type struct_type = type_builder->build(); + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + // XCDRv1 + { + FinalEmptyStruct struct_data; + FinalEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + } + + // XCDRv2 + { + FinalEmptyStruct struct_data; + FinalEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalEmptyInheritanceStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_emptyinheritance_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + type_descriptor->base_type(create_final_empty_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_str_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(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); + + std::string str_value = "STRING_TEST"; + std::string str_test_value = ""; + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(str_test_value, data->get_member_id_by_name(var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, str_test_value); + + // XCDRv1 + { + FinalEmptyInheritanceStruct struct_data; + FinalEmptyInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + // XCDRv2 + { + FinalEmptyInheritanceStruct struct_data; + FinalEmptyInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalInheritanceStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_emptyinheritance_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + type_descriptor->base_type(create_final_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_str_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(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 short_value = 2; + int16_t short_test_value = 0; + std::string str_value = "STRING_TEST"; + std::string str_test_value = ""; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(str_test_value, data->get_member_id_by_name(var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, str_test_value); + + // XCDRv1 + { + FinalInheritanceStruct struct_data; + FinalInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + // XCDRv2 + { + FinalInheritanceStruct struct_data; + FinalInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalInheritanceEmptyStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_inheritanceempty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::FINAL); + type_descriptor->base_type(create_final_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_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 short_value = 2; + int16_t short_test_value = 0; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + // XCDRv1 + { + InheritanceEmptyStruct struct_data; + InheritanceEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + } + + // XCDRv2 + { + InheritanceEmptyStruct struct_data; + InheritanceEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_FinalExtensibilityInheritance) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(final_extensibilityinheritance_struct_name); + type_descriptor->base_type(create_final_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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); + + int16_t short_value = 2; + int16_t short_test_value = 0; + int32_t long_value = 443; + int32_t long_test_value = 0; + + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_long_name), long_value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(long_test_value, data->get_member_id_by_name(var_long_name)), RETCODE_OK); + EXPECT_EQ(long_value, long_test_value); + + // XCDRv1 + { + FinalExtensibilityInheritance struct_data; + FinalExtensibilityInheritancePubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_long(), long_test_value); + } + + // XCDRv2 + { + FinalExtensibilityInheritance struct_data; + FinalExtensibilityInheritancePubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_long(), long_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +} // namespace dds +} // namespace fastdds +} // namespace eprosima diff --git a/test/feature/dynamic_types/dds_types_tests/DynamicTypesMutableDDSTypesTests.cpp b/test/feature/dynamic_types/dds_types_tests/DynamicTypesMutableDDSTypesTests.cpp new file mode 100644 index 00000000000..1db2727f0dd --- /dev/null +++ b/test/feature/dynamic_types/dds_types_tests/DynamicTypesMutableDDSTypesTests.cpp @@ -0,0 +1,925 @@ +// 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/helpers/basic_inner_types.hpp" +#include "../../../dds-types-test/mutablePubSubTypes.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace eprosima { +namespace fastdds { +namespace dds { + +constexpr const char* const mutable_short_struct_name = "MutableShortStruct"; +constexpr const char* const mutable_ushort_struct_name = "MutableUShortStruct"; +constexpr const char* const mutable_long_struct_name = "MutableLongStruct"; +constexpr const char* const mutable_ulong_struct_name = "MutableULongStruct"; +constexpr const char* const mutable_longlong_struct_name = "MutableLongLongStruct"; +constexpr const char* const mutable_ulonglong_struct_name = "MutableULongLongStruct"; +constexpr const char* const mutable_float_struct_name = "MutableFloatStruct"; +constexpr const char* const mutable_double_struct_name = "MutableDoubleStruct"; +constexpr const char* const mutable_longdouble_struct_name = "MutableLongDoubleStruct"; +constexpr const char* const mutable_bool_struct_name = "MutableBooleanStruct"; +constexpr const char* const mutable_byte_struct_name = "MutableOctetStruct"; +constexpr const char* const mutable_char_struct_name = "MutableCharStruct"; +constexpr const char* const mutable_wchar_struct_name = "MutableWCharStruct"; +constexpr const char* const mutable_union_struct_name = "MutableUnionStruct"; +constexpr const char* const mutable_empty_struct_name = "MutableEmptyStruct"; +constexpr const char* const mutable_emptyinheritance_struct_name = "MutableEmptyInheritanceStruct"; +constexpr const char* const mutable_inheritance_struct_name = "MutableInheritanceStruct"; +constexpr const char* const mutable_inheritanceempty_struct_name = "MutableInheritanceEmptyStruct"; +constexpr const char* const mutable_extensibilityinheritance_struct_name = "MutableExtensibilityInheritance"; + +constexpr const char* var_str_name = "var_str"; + +DynamicType::_ref_type create_mutable_short_struct() +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_short_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_short_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_INT16)); + type_builder->add_member(member_descriptor); + + return type_builder->build(); +} + +DynamicType::_ref_type create_mutable_empty_struct() +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_empty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + return type_builder->build(); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableShortStruct) +{ + DynamicType::_ref_type struct_type = create_mutable_short_struct(); + 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_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); + + // XCDRv1 + { + MutableShortStruct struct_data; + MutableShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + // XCDRv2 + { + MutableShortStruct struct_data; + MutableShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableUShortStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_ushort_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ushort_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableUShortStruct struct_data; + MutableUShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ushort(), test_value); + } + + // XCDRv2 + { + MutableUShortStruct struct_data; + MutableUShortStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ushort(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_long_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableLongStruct struct_data; + MutableLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_long(), test_value); + } + + // XCDRv2 + { + MutableLongStruct struct_data; + MutableLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_long(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableULongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_ulong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ulong_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableULongStruct struct_data; + MutableULongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulong(), test_value); + } + + // XCDRv2 + { + MutableULongStruct struct_data; + MutableULongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableLongLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_longlong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableLongLongStruct struct_data; + MutableLongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longlong(), test_value); + } + + // XCDRv2 + { + MutableLongLongStruct struct_data; + MutableLongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longlong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableULongLongStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_ulonglong_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_ulong_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableULongLongStruct struct_data; + MutableULongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulonglong(), test_value); + } + + // XCDRv2 + { + MutableULongLongStruct struct_data; + MutableULongLongStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_ulonglong(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableFloatStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_float_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_float_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableFloatStruct struct_data; + MutableFloatStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_float(), test_value); + } + + // XCDRv2 + { + MutableFloatStruct struct_data; + MutableFloatStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_float(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableDoubleStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_double_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_double_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableDoubleStruct struct_data; + MutableDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_double(), test_value); + } + + // XCDRv2 + { + MutableDoubleStruct struct_data; + MutableDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_double(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableLongDoubleStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_longdouble_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_double_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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_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); + + // XCDRv1 + { + MutableLongDoubleStruct struct_data; + MutableLongDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longdouble(), test_value); + } + + // XCDRv2 + { + MutableLongDoubleStruct struct_data; + MutableLongDoubleStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_longdouble(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableBooleanStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_bool_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_bool_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BOOLEAN)); + 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_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); + + // XCDRv1 + { + MutableBooleanStruct struct_data; + MutableBooleanStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_boolean(), test_value); + } + + // XCDRv2 + { + MutableBooleanStruct struct_data; + MutableBooleanStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_boolean(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableOctetStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_byte_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_byte_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_BYTE)); + 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::fastrtps::rtps::octet value = 255; + eprosima::fastrtps::rtps::octet test_value = 0; + 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); + + // XCDRv1 + { + MutableOctetStruct struct_data; + MutableOctetStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_octet(), test_value); + } + + // XCDRv2 + { + MutableOctetStruct struct_data; + MutableOctetStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_octet(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableCharStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_char_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_char_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR8)); + 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_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); + + // XCDRv1 + { + MutableCharStruct struct_data; + MutableCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char8(), test_value); + } + + // XCDRv2 + { + MutableCharStruct struct_data; + MutableCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char8(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableWCharStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_wchar_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_wchar_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->get_primitive_type(TK_CHAR16)); + 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_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); + + // XCDRv1 + { + MutableWCharStruct struct_data; + MutableWCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char16(), test_value); + } + + // XCDRv2 + { + MutableWCharStruct struct_data; + MutableWCharStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_char16(), test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableUnionStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_union_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_union_name); + member_descriptor->type(DynamicTypesDDSTypesTest::create_inner_union_helper()); + 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 float_value = 23.5; + float test_float_value = 0; + int16_t short_value = 55; + int16_t test_short_value = 0; + DynamicData::_ref_type union_data = data->loan_value(data->get_member_id_by_name(var_union_name)); + ASSERT_TRUE(union_data); + + EXPECT_EQ(union_data->set_float32_value(union_data->get_member_id_by_name( + union_float_member_name), float_value), RETCODE_OK); + EXPECT_EQ(union_data->get_float32_value(test_float_value, union_data->get_member_id_by_name( + union_float_member_name)), RETCODE_OK); + EXPECT_EQ(float_value, test_float_value); + EXPECT_EQ(union_data->set_int16_value(union_data->get_member_id_by_name( + union_short_member_name), short_value), RETCODE_OK); + EXPECT_EQ(union_data->get_int16_value(test_short_value, union_data->get_member_id_by_name( + union_short_member_name)), RETCODE_OK); + EXPECT_EQ(short_value, test_short_value); + EXPECT_EQ(data->return_loaned_value(union_data), RETCODE_OK); + + // XCDRv1 + { + MutableUnionStruct struct_data; + MutableUnionStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_union().shortValue(), test_short_value); + } + + // XCDRv2 + { + MutableUnionStruct struct_data; + MutableUnionStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_union().shortValue(), test_short_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableEmptyStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_empty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + DynamicType::_ref_type struct_type = type_builder->build(); + DynamicData::_ref_type data {DynamicDataFactory::get_instance()->create_data(struct_type)}; + ASSERT_TRUE(data); + + // XCDRv1 + { + MutableEmptyStruct struct_data; + MutableEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + } + + // XCDRv2 + { + MutableEmptyStruct struct_data; + MutableEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableEmptyInheritanceStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_emptyinheritance_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + type_descriptor->base_type(create_mutable_empty_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_str_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(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); + + std::string str_value = "STRING_TEST"; + std::string str_test_value = ""; + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(str_test_value, data->get_member_id_by_name(var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, str_test_value); + + // XCDRv1 + { + MutableEmptyInheritanceStruct struct_data; + MutableEmptyInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + // XCDRv2 + { + MutableEmptyInheritanceStruct struct_data; + MutableEmptyInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableInheritanceStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_inheritance_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + type_descriptor->base_type(create_mutable_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_str_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->create_string_type(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 short_value = 2; + int16_t short_test_value = 0; + std::string str_value = "STRING_TEST"; + std::string str_test_value = ""; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + EXPECT_EQ(data->set_string_value(data->get_member_id_by_name(var_str_name), str_value), RETCODE_OK); + EXPECT_EQ(data->get_string_value(str_test_value, data->get_member_id_by_name(var_str_name)), RETCODE_OK); + EXPECT_EQ(str_value, str_test_value); + + // XCDRv1 + { + MutableInheritanceStruct struct_data; + MutableInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + // XCDRv2 + { + MutableInheritanceStruct struct_data; + MutableInheritanceStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_str(), str_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableInheritanceEmptyStruct) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_inheritanceempty_struct_name); + type_descriptor->extensibility_kind(ExtensibilityKind::MUTABLE); + type_descriptor->base_type(create_mutable_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_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 short_value = 2; + int16_t short_test_value = 0; + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + // XCDRv1 + { + MutableInheritanceEmptyStruct struct_data; + MutableInheritanceEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + } + + // XCDRv2 + { + MutableInheritanceEmptyStruct struct_data; + MutableInheritanceEmptyStructPubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +TEST_F(DynamicTypesDDSTypesTest, DDSTypesTest_MutableExtensibilityInheritance) +{ + TypeDescriptor::_ref_type type_descriptor {traits::make_shared()}; + type_descriptor->kind(TK_STRUCTURE); + type_descriptor->name(mutable_extensibilityinheritance_struct_name); + type_descriptor->base_type(create_mutable_short_struct()); + DynamicTypeBuilder::_ref_type type_builder {DynamicTypeBuilderFactory::get_instance()->create_type(type_descriptor)}; + + MemberDescriptor::_ref_type member_descriptor {traits::make_shared()}; + member_descriptor->name(var_long_name); + member_descriptor->type(DynamicTypeBuilderFactory::get_instance()->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); + + int16_t short_value = 2; + int16_t short_test_value = 0; + int32_t long_value = 443; + int32_t long_test_value = 0; + + EXPECT_EQ(data->set_int16_value(data->get_member_id_by_name(var_short_name), short_value), RETCODE_OK); + EXPECT_EQ(data->get_int16_value(short_test_value, data->get_member_id_by_name(var_short_name)), RETCODE_OK); + EXPECT_EQ(short_value, short_test_value); + + EXPECT_EQ(data->set_int32_value(data->get_member_id_by_name(var_long_name), long_value), RETCODE_OK); + EXPECT_EQ(data->get_int32_value(long_test_value, data->get_member_id_by_name(var_long_name)), RETCODE_OK); + EXPECT_EQ(long_value, long_test_value); + + // XCDRv1 + { + MutableExtensibilityInheritance struct_data; + MutableExtensibilityInheritancePubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_long(), long_test_value); + } + + // XCDRv2 + { + MutableExtensibilityInheritance struct_data; + MutableExtensibilityInheritancePubSubType static_pubsubType; + check_serialization_deserialization(struct_type, data, XCDR2_DATA_REPRESENTATION, struct_data, + static_pubsubType); + EXPECT_EQ(struct_data.var_short(), short_test_value); + EXPECT_EQ(struct_data.var_long(), long_test_value); + } + + EXPECT_EQ(DynamicDataFactory::get_instance()->delete_data(data), RETCODE_OK); +} + +} // namespace dds +} // namespace fastdds +} // namespace eprosima