Skip to content

Commit

Permalink
fixup for new type mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelarguedas committed Apr 11, 2017
1 parent eefc615 commit f538258
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions rosidl_generator_c/msg/PrimitiveValues.msg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
44 changes: 35 additions & 9 deletions rosidl_generator_c/test/test_interfaces.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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];
}
Expand Down
26 changes: 13 additions & 13 deletions rosidl_generator_cpp/test/test_interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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, \
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions rosidl_parser/rosidl_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)*$')
Expand Down
4 changes: 2 additions & 2 deletions rosidl_parser/test/test_base_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion rosidl_parser/test/test_constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion rosidl_parser/test/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions rosidl_parser/test/test_parse_primitive_value_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit f538258

Please sign in to comment.