diff --git a/rosidl_generator_c/include/rosidl_generator_c/primitives_array_functions.h b/rosidl_generator_c/include/rosidl_generator_c/primitives_array_functions.h index ef580c75d..445eb5f59 100644 --- a/rosidl_generator_c/include/rosidl_generator_c/primitives_array_functions.h +++ b/rosidl_generator_c/include/rosidl_generator_c/primitives_array_functions.h @@ -38,7 +38,7 @@ extern "C" // array functions for all primitive types ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(bool, bool) ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(byte, uint8_t) -ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(char, char) +ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(char, int8_t) ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(float32, float) ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(float64, double) ROSIDL_GENERATOR_C__DECLARE_PRIMITIVE_ARRAY_FUNCTIONS(int8, int8_t) diff --git a/rosidl_generator_c/msg/PrimitiveValues.msg b/rosidl_generator_c/msg/PrimitiveValues.msg index 4ca556696..b803e7bef 100644 --- a/rosidl_generator_c/msg/PrimitiveValues.msg +++ b/rosidl_generator_c/msg/PrimitiveValues.msg @@ -1,7 +1,7 @@ bool def_bool_1 true bool def_bool_2 false -byte def_byte -66 -char def_char 66 +byte def_byte 66 +char def_char -66 float32 def_float32 1.125 float64 def_float64 1.125 int8 def_int8 3 diff --git a/rosidl_generator_c/test/test_interfaces.c b/rosidl_generator_c/test/test_interfaces.c index 36bd91301..07872c8fb 100644 --- a/rosidl_generator_c/test/test_interfaces.c +++ b/rosidl_generator_c/test/test_interfaces.c @@ -160,11 +160,11 @@ int test_primitives(void) bool_msg.empty_bool = false; EXPECT_EQ(false, bool_msg.empty_bool); - byte_msg.empty_byte = -128; - EXPECT_EQ(-128, byte_msg.empty_byte); + byte_msg.empty_byte = 0; + EXPECT_EQ(0, byte_msg.empty_byte); - byte_msg.empty_byte = 127; - EXPECT_EQ(127, byte_msg.empty_byte); + byte_msg.empty_byte = 255; + EXPECT_EQ(255, byte_msg.empty_byte); EXPECT_EQ(123, rosidl_generator_c__msg__Constants__X); EXPECT_EQ(-123, rosidl_generator_c__msg__Constants__Y); @@ -254,8 +254,8 @@ int test_primitives_default_value(void) EXPECT_EQ(true, primitive_values->def_bool_1); EXPECT_EQ(false, primitive_values->def_bool_2); - EXPECT_EQ(-66, primitive_values->def_byte); - EXPECT_EQ(66, primitive_values->def_char); + EXPECT_EQ(66, primitive_values->def_byte); + EXPECT_EQ(-66, primitive_values->def_char); EXPECT_EQ(1.125f, primitive_values->def_float32); EXPECT_EQ(1.125, primitive_values->def_float64); EXPECT_EQ(3, primitive_values->def_int8); @@ -332,8 +332,21 @@ int test_primitives_unbounded_arrays(void) } } + // byte_array + res = rosidl_generator_c__byte__Array__init(&arrays->byte_array, ARRAY_SIZE); + EXPECT_EQ(true, res); + uint8_t test_array_byte[7] = {0, 57, 110, 177, 201, 240, 255}; + for (i = 0; i < ARRAY_SIZE; i++) { + arrays->byte_array.data[i] = test_array_byte[i]; + } + // test values + for (i = 0; i < ARRAY_SIZE; i++) { + EXPECT_EQ(test_array_byte[i], arrays->byte_array.data[i]); + } + + // char array - res = rosidl_generator_c__uint8__Array__init(&arrays->char_array, ARRAY_SIZE); + res = rosidl_generator_c__char__Array__init(&arrays->char_array, ARRAY_SIZE); EXPECT_EQ(true, res); char test_array_char[7] = {'a', '5', '#', 'Z', '@', '-', ' '}; for (i = 0; i < ARRAY_SIZE; i++) { @@ -513,8 +526,21 @@ int test_primitives_bounded_arrays(void) } } + // byte_array + res = rosidl_generator_c__byte__Array__init(&arrays->byte_array, ARRAY_SIZE); + EXPECT_EQ(true, res); + uint8_t test_array_byte[8] = {0, 57, 110, 177, 201, 240, 255, 111}; + for (i = 0; i < ARRAY_SIZE; i++) { + arrays->byte_array.data[i] = test_array_byte[i]; + } + // test values + for (i = 0; i < ARRAY_SIZE; i++) { + EXPECT_EQ(test_array_byte[i], arrays->byte_array.data[i]); + } + + // char array - res = rosidl_generator_c__uint8__Array__init(&arrays->char_array, ARRAY_SIZE); + res = rosidl_generator_c__char__Array__init(&arrays->char_array, ARRAY_SIZE); EXPECT_EQ(true, res); char test_array_char[7] = {'a', '5', '#', 'Z', '@', '-', ' '}; for (i = 0; i < ARRAY_SIZE; i++) { @@ -694,7 +720,7 @@ int test_primitives_static_arrays(void) } // byte_array - int8_t test_array_byte[ARRAY_SIZE] = {-127, -55, -30, 0, 58, 100, 127}; + uint8_t test_array_byte[ARRAY_SIZE] = {0, 57, 110, 177, 201, 240, 255}; for (i = 0; i < ARRAY_SIZE; i++) { arrays->byte_array[i] = test_array_byte[i]; } diff --git a/rosidl_generator_cpp/test/test_interfaces.cpp b/rosidl_generator_cpp/test/test_interfaces.cpp index 824cf9833..0a3399f98 100644 --- a/rosidl_generator_cpp/test/test_interfaces.cpp +++ b/rosidl_generator_cpp/test/test_interfaces.cpp @@ -160,8 +160,8 @@ void test_message_primitives_static(rosidl_generator_cpp::msg::PrimitivesStatic #ifdef __linux__ #pragma GCC diagnostic pop #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, INT8_MIN, INT8_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, 0, UINT8_MAX) + TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, 0, UINT8_MAX) + TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, INT8_MIN, INT8_MAX) TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, float32_value, FLT_MIN, FLT_MAX) TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, float64_value, DBL_MIN, DBL_MAX) TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int8_value, INT8_MIN, INT8_MAX) @@ -198,10 +198,10 @@ void test_message_primitives_bounded(rosidl_generator_cpp::msg::PrimitivesBounde { TEST_BOUNDED_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, char_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ - 0, UINT8_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, byte_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_ARRAY_PRIMITIVE(message, char_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) + TEST_BOUNDED_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + 0, UINT8_MAX) TEST_BOUNDED_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) TEST_BOUNDED_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ @@ -250,10 +250,10 @@ void test_message_primitives_unbounded(rosidl_generator_cpp::msg::PrimitivesUnbo { TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, char_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ - 0, UINT8_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, byte_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, char_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) + TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + 0, UINT8_MAX) TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ @@ -290,10 +290,10 @@ void test_message_primitives_static_arrays(rosidl_generator_cpp::msg::PrimitiveS { TEST_STATIC_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_STATIC_ARRAY_PRIMITIVE(message, char_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ - 0, UINT8_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, byte_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_STATIC_ARRAY_PRIMITIVE(message, char_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) + TEST_STATIC_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + 0, UINT8_MAX) TEST_STATIC_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) TEST_STATIC_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ @@ -450,8 +450,8 @@ TEST(Test_messages, primitives_default) { #ifdef __linux__ #pragma GCC diagnostic pop #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, 50, INT8_MIN); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, 100, UINT8_MAX); + TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, 50, UINT8_MAX); + TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, 100, INT8_MAX); TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, float32_value, 1.125f, FLT_MAX); TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, float64_value, 1.125, DBL_MAX); TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int8_value, -50, INT8_MAX); diff --git a/rosidl_parser/rosidl_parser/__init__.py b/rosidl_parser/rosidl_parser/__init__.py index 6fcc0075a..c31a98329 100644 --- a/rosidl_parser/rosidl_parser/__init__.py +++ b/rosidl_parser/rosidl_parser/__init__.py @@ -46,8 +46,8 @@ ] DEPRECATED_TYPES = { - 'byte': 'int8', - 'char': 'uint8' + 'byte': 'uint8', + 'char': 'int8' } VALID_PACKAGE_NAME_PATTERN = re.compile('^[a-z]([a-z0-9_]?[a-z0-9]+)*$') diff --git a/rosidl_parser/test/test_base_type.py b/rosidl_parser/test/test_base_type.py index 1f1b0a1bc..ce3548247 100644 --- a/rosidl_parser/test/test_base_type.py +++ b/rosidl_parser/test/test_base_type.py @@ -34,8 +34,8 @@ def test_base_type_constructor(): 'string'] deprecated_types = { - 'byte': 'int8', - 'char': 'uint8' + 'byte': 'uint8', + 'char': 'int8' } for primitive_type in primitive_types: diff --git a/rosidl_parser/test/test_constant.py b/rosidl_parser/test/test_constant.py index ef7efb2ee..45a748be2 100644 --- a/rosidl_parser/test/test_constant.py +++ b/rosidl_parser/test/test_constant.py @@ -37,7 +37,7 @@ def test_constant_methods(): assert Constant('bool', 'FOO', '1') == Constant('bool', 'FOO', '1') assert Constant('bool', 'FOO', '1') != Constant('bool', 'FOO', '0') assert Constant('bool', 'FOO', '1') != Constant('bool', 'BAR', '1') - assert Constant('bool', 'FOO', '1') != Constant('int8', 'FOO', '1') + assert Constant('bool', 'FOO', '1') != Constant('uint8', 'FOO', '1') assert str(Constant('bool', 'FOO', '1')) == 'bool FOO=True' diff --git a/rosidl_parser/test/test_field.py b/rosidl_parser/test/test_field.py index 5aafd1f9b..a3f89d094 100644 --- a/rosidl_parser/test/test_field.py +++ b/rosidl_parser/test/test_field.py @@ -58,7 +58,7 @@ def test_field_methods(): assert (Field(Type('bool'), 'foo', '1') != Field(Type('bool'), 'bar', '1')) assert (Field(Type('bool'), 'foo', '1') != - Field(Type('int8'), 'foo', '1')) + Field(Type('uint8'), 'foo', '1')) assert str(Field(Type('bool'), 'foo', '1')) == 'bool foo True' diff --git a/rosidl_parser/test/test_parse_primitive_value_string.py b/rosidl_parser/test/test_parse_primitive_value_string.py index c2376de91..51e0fb270 100644 --- a/rosidl_parser/test/test_parse_primitive_value_string.py +++ b/rosidl_parser/test/test_parse_primitive_value_string.py @@ -49,8 +49,8 @@ def test_parse_primitive_value_string_bool(): def test_parse_primitive_value_string_integer(): integer_types = { - 'byte': [8, False], - 'char': [8, True], + 'byte': [8, True], + 'char': [8, False], 'int8': [8, False], 'uint8': [8, True], 'int16': [16, False],