Skip to content

Commit

Permalink
Refs #20424. Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo González Moreno <[email protected]>
  • Loading branch information
richiware committed Apr 11, 2024
1 parent 36ed740 commit f693187
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
12 changes: 10 additions & 2 deletions src/cpp/fastdds/xtypes/dynamic_types/DynamicDataImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ void DynamicDataImpl::apply_bitset_mask(
enclosing_type_->get_all_members().at(member_id))};
const auto member_index {member_impl->get_descriptor().index()};
const auto bound {enclosing_type_->get_descriptor().bound().at(member_index)};
uint64_t mask {0XFFFFFFFFFFFFFFFFllu << bound};
uint64_t mask {64 == bound ? 0x0llu : 0XFFFFFFFFFFFFFFFFllu << bound};
value &= static_cast<TypeForKind<TK>>(~mask);
}

Expand Down Expand Up @@ -6677,9 +6677,17 @@ void DynamicDataImpl::serialize(
if (it != value_.end())
{
int64_t value {0};
uint64_t uvalue {0};
auto member_data {std::static_pointer_cast<DynamicDataImpl>(it->second)};

if (RETCODE_OK == member_data->get_value<TK_INT64>(value, MEMBER_ID_INVALID))
ReturnCode_t ret_promotion_value {member_data->get_value<TK_INT64>(value, MEMBER_ID_INVALID)};
if (RETCODE_OK != ret_promotion_value)
{
ret_promotion_value = member_data->get_value<TK_UINT64>(uvalue, MEMBER_ID_INVALID);
value = static_cast<int64_t>(uvalue);
}

if (RETCODE_OK == ret_promotion_value)
{
auto base {member_id};
auto size {type->get_descriptor().bound().at(index)};
Expand Down
14 changes: 14 additions & 0 deletions src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,20 @@ bool TypeDescriptorImpl::is_consistent() noexcept
EPROSIMA_LOG_ERROR(DYN_TYPES, "Descriptor type and the base_type are not of the same kind");
return false;
}

// Check extensibility on structures.
if (TK_STRUCTURE == kind_)
{
if (!is_extensibility_set)
{
extensibility_kind_ = base_type->get_descriptor().extensibility_kind();
}
else if (extensibility_kind_ != base_type->get_descriptor().extensibility_kind())
{
EPROSIMA_LOG_ERROR(DYN_TYPES, "ExtensibilityKind is different from that of base type.");
return false;
}
}
}

// Arrays need one or more bound fields with the lenghts of each dimension.
Expand Down
3 changes: 3 additions & 0 deletions src/cpp/fastdds/xtypes/dynamic_types/TypeDescriptorImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class TypeDescriptorImpl : public virtual TypeDescriptor

ExtensibilityKind extensibility_kind_ {ExtensibilityKind::APPENDABLE};

bool is_extensibility_set {false};

bool is_nested_ {false};

public:
Expand Down Expand Up @@ -202,6 +204,7 @@ class TypeDescriptorImpl : public virtual TypeDescriptor
ExtensibilityKind extensibility_kind) noexcept override
{
extensibility_kind_ = extensibility_kind;
is_extensibility_set = true;
}

bool is_nested() const noexcept override
Expand Down
4 changes: 4 additions & 0 deletions test/feature/dynamic_types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ target_compile_definitions(DynamicTypesTests PRIVATE
$<$<AND:$<NOT:$<BOOL:${WIN32}>>,$<STREQUAL:"${CMAKE_BUILD_TYPE}","Debug">>:__DEBUG>
$<$<BOOL:${INTERNAL_DEBUG}>:__INTERNALDEBUG> # Internal debug activated.
)
target_include_directories(DynamicTypesTests
PRIVATE
${PROJECT_SOURCE_DIR}/test/utils/
)
target_link_libraries(DynamicTypesTests
GTest::gtest
$<$<BOOL:${WIN32}>:iphlpapi$<SEMICOLON>Shlwapi>
Expand Down
30 changes: 14 additions & 16 deletions test/feature/dynamic_types/DynamicTypesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <thread>
#include <tuple>

#include <fastdds/dds/log/Log.hpp>
#include <ScopedLogs.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicData.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicDataFactory.hpp>
#include <fastdds/dds/xtypes/dynamic_types/DynamicPubSubType.hpp>
Expand Down Expand Up @@ -232,7 +232,7 @@ TEST_F(DynamicTypesTests, DynamicType_basic)

DynamicTypeMember::_ref_type member;
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
// Check members are properly added
// • checking invalid id
EXPECT_NE(RETCODE_OK, struct_type_builder->get_member(member, 0));
Expand All @@ -249,7 +249,6 @@ TEST_F(DynamicTypesTests, DynamicType_basic)
ASSERT_EQ(RETCODE_OK, struct_type_builder->get_member(member, 3));
ASSERT_EQ(RETCODE_OK, member->get_descriptor(md));

EXPECT_TRUE(md->is_consistent());
EXPECT_EQ(md->index(), 0u);
EXPECT_EQ(md->name(), md1->name());
EXPECT_EQ(md->type(), md1->type());
Expand All @@ -261,7 +260,6 @@ TEST_F(DynamicTypesTests, DynamicType_basic)
md2->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT64));
ASSERT_EQ(RETCODE_OK, struct_type_builder->get_member(member, 1));
ASSERT_EQ(RETCODE_OK, member->get_descriptor(md));
EXPECT_TRUE(md->is_consistent());
EXPECT_EQ(md->index(), 1u);
EXPECT_EQ(md->name(), md2->name());
EXPECT_EQ(md->type(), md2->type());
Expand Down Expand Up @@ -368,7 +366,7 @@ TEST_F(DynamicTypesTests, DynamicType_basic)

// • checking adding duplicates
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
// + duplicate name
md = traits<MemberDescriptor>::make_shared();
md->id(1);
Expand Down Expand Up @@ -2502,7 +2500,7 @@ TEST_F(DynamicTypesTests, DynamicType_enum)
ASSERT_EQ(builder->add_member(member_descriptor), RETCODE_OK);

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
// Try to add a descriptor with the same name.
member_descriptor = traits<MemberDescriptor>::make_shared();
member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32));
Expand Down Expand Up @@ -2717,7 +2715,7 @@ TEST_F(DynamicTypesTests, DynamicType_string)
ASSERT_EQ(test1, test2);

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
ASSERT_NE(data->set_string_value(MEMBER_ID_INVALID,
"TEST_OVER_LENGTH_LIMITS"), RETCODE_OK);
}
Expand Down Expand Up @@ -2876,7 +2874,7 @@ TEST_F(DynamicTypesTests, DynamicType_wstring)
{
DynamicTypeBuilderFactory::_ref_type factory {DynamicTypeBuilderFactory::get_instance()};

DynamicTypeBuilder::_ref_type builder {factory->create_wstring_type(0)};
DynamicTypeBuilder::_ref_type builder {factory->create_wstring_type(static_cast<uint32_t>(LENGTH_UNLIMITED))};
ASSERT_TRUE(builder);
DynamicType::_ref_type created_type {builder->build()};
ASSERT_TRUE(created_type);
Expand Down Expand Up @@ -2905,7 +2903,7 @@ TEST_F(DynamicTypesTests, DynamicType_wstring)
ASSERT_EQ(test1, test2);

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
ASSERT_NE(data->set_wstring_value(MEMBER_ID_INVALID,
L"TEST_OVER_LENGTH_LIMITS"), RETCODE_OK);
}
Expand Down Expand Up @@ -3229,7 +3227,7 @@ TEST_F(DynamicTypesTests, DynamicType_nested_alias)
ASSERT_EQ(test1, test2);

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
ASSERT_NE(data->set_string_value(MEMBER_ID_INVALID,
"TEST_OVER_LENGTH_LIMITS"), RETCODE_OK);
}
Expand Down Expand Up @@ -3719,7 +3717,7 @@ TEST_F(DynamicTypesTests, DynamicType_sequence)

// Try to insert more than the limit.
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");

ASSERT_NE(data->set_int32_values(0, {0, 1, 2, 3, 4, 5, 6}), RETCODE_OK);
}
Expand Down Expand Up @@ -3875,7 +3873,7 @@ TEST_F(DynamicTypesTests, DynamicType_sequence_of_sequences)

// Try to insert more than the limit.
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
seq_data = data->loan_value(2);
ASSERT_FALSE(seq_data);
}
Expand Down Expand Up @@ -4055,7 +4053,7 @@ TEST_F(DynamicTypesTests, DynamicType_array)

// Try to insert more than the limit.
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");

ASSERT_NE(data->set_int32_values(0, {1, 2, 3, 4, 5, 6, 7, 8, 9}), RETCODE_OK);
}
Expand Down Expand Up @@ -4235,7 +4233,7 @@ TEST_F(DynamicTypesTests, DynamicType_array_of_arrays)

// Try to insert more than the limit.
{
eprosima::fastdds::dds::Log::ScopeLogs _("disable");
eprosima::fastdds::testing::ScopeLogs _("disable");
seq_data = data->loan_value(4);
ASSERT_FALSE(seq_data);
}
Expand Down Expand Up @@ -5130,7 +5128,7 @@ TEST_F(DynamicTypesTests, DynamicType_structure_inheritance)
member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32));

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable"); // avoid expected errors logging
eprosima::fastdds::testing::ScopeLogs _("disable"); // avoid expected errors logging
member_descriptor->name("child_int32");
member_descriptor->id(1);
ASSERT_NE(builder->add_member(member_descriptor), RETCODE_OK);
Expand Down Expand Up @@ -5653,7 +5651,7 @@ TEST_F(DynamicTypesTests, DynamicType_union)
ASSERT_EQ(builder->add_member(member_descriptor), RETCODE_OK);

{
eprosima::fastdds::dds::Log::ScopeLogs _("disable"); // avoid expected errors logging
eprosima::fastdds::testing::ScopeLogs _("disable"); // avoid expected errors logging

member_descriptor = traits<MemberDescriptor>::make_shared();
member_descriptor->type(factory->get_primitive_type(eprosima::fastdds::dds::TK_INT32));
Expand Down

0 comments on commit f693187

Please sign in to comment.