2121
2222#include < fastdds/dds/domain/DomainParticipantFactory.hpp>
2323#include < fastdds/dds/xtypes/common.hpp>
24+ #include < fastdds/dds/xtypes/dynamic_types/DynamicTypeBuilderFactory.hpp>
2425#include < fastdds/dds/xtypes/type_representation/TypeObject.hpp>
2526#include < fastdds/dds/xtypes/type_representation/TypeObjectUtils.hpp>
2627
28+ #include < fastdds/xtypes/type_representation/TypeObjectRegistry.hpp>
29+
2730namespace eprosima {
2831namespace fastdds {
2932namespace dds {
3033namespace xtypes {
3134
35+ class TestTypeObjectRegistry : public TypeObjectRegistry
36+ {
37+
38+ public:
39+
40+ using TypeObjectRegistry::set_annotation_parameter_value;
41+ };
42+
3243// Test TypeObjectRegistry::register_type_object
3344TEST (TypeObjectRegistryTests, register_type_object)
3445{
@@ -330,6 +341,42 @@ TEST(TypeObjectRegistryTests, get_type_information)
330341 EXPECT_EQ (RETCODE_OK , registry.get_type_information (type_ids, type_info, false ));
331342}
332343
344+ // (MacOS) Regression test for clang/libc++ builds: empty char8 annotation
345+ // parameters must not route through the string overload
346+ // and must produce a null character default value instead
347+ TEST (TypeObjectRegistryTests, set_annotation_parameter_value_empty_char8)
348+ {
349+ TestTypeObjectRegistry registry;
350+ AnnotationParameterValue param_value;
351+ // Build the primitive char8 type explicitly so the conversion logic is exercised on the
352+ // single-character annotation path instead of the string one
353+ auto char8_type = DynamicTypeBuilderFactory::get_instance ()->get_primitive_type (TK_CHAR8 );
354+
355+ ASSERT_NE (nullptr , char8_type);
356+ // An empty value for a char8 annotation must still succeed and yield the default
357+ // null character rather than being treated as a string payload
358+ EXPECT_EQ (RETCODE_OK , registry.set_annotation_parameter_value (char8_type, " " , param_value));
359+ EXPECT_EQ (TK_CHAR8 , param_value._d ());
360+ EXPECT_EQ (' \0 ' , param_value.char_value ());
361+ }
362+
363+ // (MacOS) Regression test for clang/libc++ builds: non empty char8 annotation
364+ TEST (TypeObjectRegistryTests, set_annotation_parameter_value_non_empty_char8_uses_first_character)
365+ {
366+ TestTypeObjectRegistry registry;
367+ AnnotationParameterValue param_value;
368+ // Use the same primitive char8 path to verify how
369+ // text input is narrowed into a single annotation character
370+ auto char8_type = DynamicTypeBuilderFactory::get_instance ()->get_primitive_type (TK_CHAR8 );
371+
372+ ASSERT_NE (nullptr , char8_type);
373+ // For char8 annotations only the first character is significant,
374+ // even if the provided text contains more bytes
375+ EXPECT_EQ (RETCODE_OK , registry.set_annotation_parameter_value (char8_type, " FastDDS" , param_value));
376+ EXPECT_EQ (TK_CHAR8 , param_value._d ());
377+ EXPECT_EQ (' F' , param_value.char_value ());
378+ }
379+
333380} // xtypes
334381} // dds
335382} // fastdds
@@ -342,3 +389,4 @@ int main(
342389 testing::InitGoogleTest (&argc, argv);
343390 return RUN_ALL_TESTS ();
344391}
392+
0 commit comments