From 4c3cd0c5da49a15da0830cf488acb195b20938e0 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Wed, 31 Jul 2019 07:39:21 -0700 Subject: [PATCH] use latin-1 encoding when reading/writing .idl files, prepend BOM to generated C/C++ files when necessary (#391) * use utf-8 encoding when reading/writing expanded templates Signed-off-by: Dirk Thomas * inject BOM into generated C/C++ code when necessary Signed-off-by: Dirk Thomas * use latin-1 encoding for .idl files Signed-off-by: Dirk Thomas Signed-off-by: Siddharth Kucheria --- .../rosidl_adapter/action/__init__.py | 2 +- rosidl_adapter/rosidl_adapter/msg/__init__.py | 2 +- .../rosidl_adapter/resource/__init__.py | 6 +- rosidl_adapter/rosidl_adapter/srv/__init__.py | 2 +- rosidl_cmake/rosidl_cmake/__init__.py | 17 +- .../rosidl_generator_c/__init__.py | 15 +- rosidl_generator_cpp/CMakeLists.txt | 44 +- .../msg/BoundedArrayBounded.msg | 1 - .../msg/BoundedArrayStatic.msg | 1 - .../msg/BoundedArrayUnbounded.msg | 1 - rosidl_generator_cpp/msg/Empty.msg | 0 .../msg/FieldsWithSameTypeSomeDefaults.msg | 3 - .../msg/PrimitiveStaticArrays.msg | 13 - .../msg/PrimitivesBounded.msg | 14 - .../msg/PrimitivesConstants.msg | 14 - .../msg/PrimitivesDefault.msg | 14 - rosidl_generator_cpp/msg/PrimitivesStatic.msg | 13 - .../msg/PrimitivesUnbounded.msg | 14 - .../msg/StaticArrayBounded.msg | 1 - .../msg/StaticArrayStatic.msg | 1 - .../msg/StaticArrayUnbounded.msg | 1 - rosidl_generator_cpp/msg/String.msg | 1 - .../msg/StringArrayStatic.msg | 1 - rosidl_generator_cpp/msg/StringArrays.msg | 11 - rosidl_generator_cpp/msg/StringBounded.msg | 1 - .../msg/UnboundedArrayBounded.msg | 1 - .../msg/UnboundedArrayStatic.msg | 1 - .../msg/UnboundedArrayUnbounded.msg | 1 - rosidl_generator_cpp/msg/Various.msg | 18 - rosidl_generator_cpp/msg/WString.msg | 1 - rosidl_generator_cpp/package.xml | 1 + .../rosidl_generator_cpp/__init__.py | 15 +- .../srv/ComplexTypeZeroFill.srv | 3 - rosidl_generator_cpp/test/test_interfaces.cpp | 537 +++++++----------- .../test/test_msg_datatype.cpp | 6 +- .../test/test_msg_initialization.cpp | 349 +++--------- .../test/test_srv_initialization.cpp | 54 +- 37 files changed, 376 insertions(+), 804 deletions(-) delete mode 100644 rosidl_generator_cpp/msg/BoundedArrayBounded.msg delete mode 100644 rosidl_generator_cpp/msg/BoundedArrayStatic.msg delete mode 100644 rosidl_generator_cpp/msg/BoundedArrayUnbounded.msg delete mode 100644 rosidl_generator_cpp/msg/Empty.msg delete mode 100644 rosidl_generator_cpp/msg/FieldsWithSameTypeSomeDefaults.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitiveStaticArrays.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitivesBounded.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitivesConstants.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitivesDefault.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitivesStatic.msg delete mode 100644 rosidl_generator_cpp/msg/PrimitivesUnbounded.msg delete mode 100644 rosidl_generator_cpp/msg/StaticArrayBounded.msg delete mode 100644 rosidl_generator_cpp/msg/StaticArrayStatic.msg delete mode 100644 rosidl_generator_cpp/msg/StaticArrayUnbounded.msg delete mode 100644 rosidl_generator_cpp/msg/String.msg delete mode 100644 rosidl_generator_cpp/msg/StringArrayStatic.msg delete mode 100644 rosidl_generator_cpp/msg/StringArrays.msg delete mode 100644 rosidl_generator_cpp/msg/StringBounded.msg delete mode 100644 rosidl_generator_cpp/msg/UnboundedArrayBounded.msg delete mode 100644 rosidl_generator_cpp/msg/UnboundedArrayStatic.msg delete mode 100644 rosidl_generator_cpp/msg/UnboundedArrayUnbounded.msg delete mode 100644 rosidl_generator_cpp/msg/Various.msg delete mode 100644 rosidl_generator_cpp/msg/WString.msg delete mode 100644 rosidl_generator_cpp/srv/ComplexTypeZeroFill.srv diff --git a/rosidl_adapter/rosidl_adapter/action/__init__.py b/rosidl_adapter/rosidl_adapter/action/__init__.py index 64f20026f..97dce92eb 100644 --- a/rosidl_adapter/rosidl_adapter/action/__init__.py +++ b/rosidl_adapter/rosidl_adapter/action/__init__.py @@ -36,5 +36,5 @@ def convert_action_to_idl(package_dir, package_name, input_file, output_dir): 'action': action, } - expand_template('action.idl.em', data, output_file) + expand_template('action.idl.em', data, output_file, encoding='iso-8859-1') return output_file diff --git a/rosidl_adapter/rosidl_adapter/msg/__init__.py b/rosidl_adapter/rosidl_adapter/msg/__init__.py index 4f878f356..68d674793 100644 --- a/rosidl_adapter/rosidl_adapter/msg/__init__.py +++ b/rosidl_adapter/rosidl_adapter/msg/__init__.py @@ -36,7 +36,7 @@ def convert_msg_to_idl(package_dir, package_name, input_file, output_dir): 'msg': msg, } - expand_template('msg.idl.em', data, output_file) + expand_template('msg.idl.em', data, output_file, encoding='iso-8859-1') return output_file diff --git a/rosidl_adapter/rosidl_adapter/resource/__init__.py b/rosidl_adapter/rosidl_adapter/resource/__init__.py index 2b6072979..3c124932d 100644 --- a/rosidl_adapter/rosidl_adapter/resource/__init__.py +++ b/rosidl_adapter/rosidl_adapter/resource/__init__.py @@ -19,17 +19,17 @@ import em -def expand_template(template_name, data, output_file): +def expand_template(template_name, data, output_file, encoding='utf-8'): content = evaluate_template(template_name, data) if output_file.exists(): - existing_content = output_file.read_text(encoding='utf-8') + existing_content = output_file.read_text(encoding=encoding) if existing_content == content: return elif output_file.parent: os.makedirs(str(output_file.parent), exist_ok=True) - output_file.write_text(content, encoding='utf-8') + output_file.write_text(content, encoding=encoding) _interpreter = None diff --git a/rosidl_adapter/rosidl_adapter/srv/__init__.py b/rosidl_adapter/rosidl_adapter/srv/__init__.py index b52ff5830..acfb08645 100644 --- a/rosidl_adapter/rosidl_adapter/srv/__init__.py +++ b/rosidl_adapter/rosidl_adapter/srv/__init__.py @@ -36,5 +36,5 @@ def convert_srv_to_idl(package_dir, package_name, input_file, output_dir): 'srv': srv, } - expand_template('srv.idl.em', data, output_file) + expand_template('srv.idl.em', data, output_file, encoding='iso-8859-1') return output_file diff --git a/rosidl_cmake/rosidl_cmake/__init__.py b/rosidl_cmake/rosidl_cmake/__init__.py index 583bbf9a8..b59675583 100644 --- a/rosidl_cmake/rosidl_cmake/__init__.py +++ b/rosidl_cmake/rosidl_cmake/__init__.py @@ -48,7 +48,10 @@ def get_newest_modification_time(target_dependencies): return newest_timestamp -def generate_files(generator_arguments_file, mapping, additional_context=None, keep_case=False): +def generate_files( + generator_arguments_file, mapping, additional_context=None, + keep_case=False, post_process_callback=None +): args = read_generator_arguments(generator_arguments_file) template_basepath = pathlib.Path(args['template_dir']) @@ -82,7 +85,8 @@ def generate_files(generator_arguments_file, mapping, additional_context=None, k expand_template( os.path.basename(template_file), data, generated_file, minimum_timestamp=latest_target_timestamp, - template_basepath=template_basepath) + template_basepath=template_basepath, + post_process_callback=post_process_callback) except Exception as e: print( 'Error processing idl file: ' + @@ -110,7 +114,7 @@ def get_template_path(template_name): def expand_template( template_name, data, output_file, minimum_timestamp=None, - template_basepath=None + template_basepath=None, post_process_callback=None ): # in the legacy API the first argument was the path to the template if template_basepath is None: @@ -155,12 +159,15 @@ def expand_template( content = output.getvalue() interpreter.shutdown() + if post_process_callback: + content = post_process_callback(content) + # only overwrite file if necessary # which is either when the timestamp is too old or when the content is different if os.path.exists(output_file): timestamp = os.path.getmtime(output_file) if minimum_timestamp is None or timestamp > minimum_timestamp: - with open(output_file, 'r') as h: + with open(output_file, 'r', encoding='utf-8') as h: if h.read() == content: return else: @@ -170,7 +177,7 @@ def expand_template( except FileExistsError: pass - with open(output_file, 'w') as h: + with open(output_file, 'w', encoding='utf-8') as h: h.write(content) diff --git a/rosidl_generator_c/rosidl_generator_c/__init__.py b/rosidl_generator_c/rosidl_generator_c/__init__.py index 7fc4297f2..c6786e264 100644 --- a/rosidl_generator_c/rosidl_generator_c/__init__.py +++ b/rosidl_generator_c/rosidl_generator_c/__init__.py @@ -34,7 +34,20 @@ def generate_c(generator_arguments_file): 'idl__struct.h.em': '%s__struct.h', 'idl__type_support.h.em': '%s__type_support.h', } - generate_files(generator_arguments_file, mapping) + generate_files( + generator_arguments_file, mapping, + post_process_callback=prefix_with_bom_if_necessary) + + +def prefix_with_bom_if_necessary(content): + try: + content.encode('ASCII') + except UnicodeError: + prefix = '\ufeff' + \ + '// NOLINT: This file starts with a BOM ' + \ + 'since it contain non-ASCII characters\n' + content = prefix + content + return content BASIC_IDL_TYPES_TO_C = { diff --git a/rosidl_generator_cpp/CMakeLists.txt b/rosidl_generator_cpp/CMakeLists.txt index 4ee5b2316..bed1a9c89 100644 --- a/rosidl_generator_cpp/CMakeLists.txt +++ b/rosidl_generator_cpp/CMakeLists.txt @@ -17,47 +17,9 @@ ament_python_install_package(${PROJECT_NAME}) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) find_package(rosidl_generator_c REQUIRED) + find_package(test_interface_files REQUIRED) ament_lint_auto_find_test_dependencies() - set(message_files - "msg/BoundedArrayBounded.msg" - "msg/BoundedArrayStatic.msg" - "msg/BoundedArrayUnbounded.msg" - - "msg/Empty.msg" - - "msg/FieldsWithSameTypeSomeDefaults.msg" - - "msg/PrimitiveStaticArrays.msg" - - "msg/PrimitivesBounded.msg" - "msg/PrimitivesConstants.msg" - "msg/PrimitivesDefault.msg" - "msg/PrimitivesStatic.msg" - "msg/PrimitivesUnbounded.msg" - - "msg/StaticArrayBounded.msg" - "msg/StaticArrayStatic.msg" - "msg/StaticArrayUnbounded.msg" - - "msg/String.msg" - "msg/StringBounded.msg" - "msg/StringArrayStatic.msg" - "msg/StringArrays.msg" - - "msg/UnboundedArrayBounded.msg" - "msg/UnboundedArrayStatic.msg" - "msg/UnboundedArrayUnbounded.msg" - - "msg/Various.msg" - - "msg/WString.msg" - ) - - set(srv_files - "srv/ComplexTypeZeroFill.srv" - ) - include(cmake/register_cpp.cmake) set(rosidl_generator_cpp_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -68,8 +30,8 @@ if(BUILD_TESTING) ) rosidl_generate_interfaces(${PROJECT_NAME} - ${message_files} - ${srv_files} + ${test_interface_files_MSG_FILES} + ${test_interface_files_SRV_FILES} ADD_LINTER_TESTS SKIP_INSTALL ) diff --git a/rosidl_generator_cpp/msg/BoundedArrayBounded.msg b/rosidl_generator_cpp/msg/BoundedArrayBounded.msg deleted file mode 100644 index bf6a03c66..000000000 --- a/rosidl_generator_cpp/msg/BoundedArrayBounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesBounded[<=3] primitive_values diff --git a/rosidl_generator_cpp/msg/BoundedArrayStatic.msg b/rosidl_generator_cpp/msg/BoundedArrayStatic.msg deleted file mode 100644 index c373cf65d..000000000 --- a/rosidl_generator_cpp/msg/BoundedArrayStatic.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesStatic[<=3] primitive_values diff --git a/rosidl_generator_cpp/msg/BoundedArrayUnbounded.msg b/rosidl_generator_cpp/msg/BoundedArrayUnbounded.msg deleted file mode 100644 index 2977ee49b..000000000 --- a/rosidl_generator_cpp/msg/BoundedArrayUnbounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesUnbounded[<=3] primitive_values diff --git a/rosidl_generator_cpp/msg/Empty.msg b/rosidl_generator_cpp/msg/Empty.msg deleted file mode 100644 index e69de29bb..000000000 diff --git a/rosidl_generator_cpp/msg/FieldsWithSameTypeSomeDefaults.msg b/rosidl_generator_cpp/msg/FieldsWithSameTypeSomeDefaults.msg deleted file mode 100644 index 89f098e4e..000000000 --- a/rosidl_generator_cpp/msg/FieldsWithSameTypeSomeDefaults.msg +++ /dev/null @@ -1,3 +0,0 @@ -uint32 x -uint32 y 45 -uint32 z diff --git a/rosidl_generator_cpp/msg/PrimitiveStaticArrays.msg b/rosidl_generator_cpp/msg/PrimitiveStaticArrays.msg deleted file mode 100644 index d511e7b5c..000000000 --- a/rosidl_generator_cpp/msg/PrimitiveStaticArrays.msg +++ /dev/null @@ -1,13 +0,0 @@ -bool[10] bool_value -byte[10] byte_value -char[10] char_value -float32[10] float32_value -float64[10] float64_value -int8[10] int8_value -uint8[10] uint8_value -int16[10] int16_value -uint16[10] uint16_value -int32[10] int32_value -uint32[10] uint32_value -int64[10] int64_value -uint64[10] uint64_value diff --git a/rosidl_generator_cpp/msg/PrimitivesBounded.msg b/rosidl_generator_cpp/msg/PrimitivesBounded.msg deleted file mode 100644 index e5ca62cd0..000000000 --- a/rosidl_generator_cpp/msg/PrimitivesBounded.msg +++ /dev/null @@ -1,14 +0,0 @@ -bool[<=10] bool_value -byte[<=10] byte_value -char[<=10] char_value -float32[<=10] float32_value -float64[<=10] float64_value -int8[<=10] int8_value -uint8[<=10] uint8_value -int16[<=10] int16_value -uint16[<=10] uint16_value -int32[<=10] int32_value -uint32[<=10] uint32_value -int64[<=10] int64_value -uint64[<=10] uint64_value -string<=10[<=10] string_values diff --git a/rosidl_generator_cpp/msg/PrimitivesConstants.msg b/rosidl_generator_cpp/msg/PrimitivesConstants.msg deleted file mode 100644 index d392c854a..000000000 --- a/rosidl_generator_cpp/msg/PrimitivesConstants.msg +++ /dev/null @@ -1,14 +0,0 @@ -bool BOOL_CONST=true -byte BYTE_CONST=50 -char CHAR_CONST=100 -float32 FLOAT32_CONST=1.125 -float64 FLOAT64_CONST=1.125 -int8 INT8_CONST=-50 -uint8 UINT8_CONST=200 -int16 INT16_CONST=-1000 -uint16 UINT16_CONST=2000 -int32 INT32_CONST=-30000 -uint32 UINT32_CONST=60000 -int64 INT64_CONST=-40000000 -uint64 UINT64_CONST=50000000 -string STRING_CONST="foo" diff --git a/rosidl_generator_cpp/msg/PrimitivesDefault.msg b/rosidl_generator_cpp/msg/PrimitivesDefault.msg deleted file mode 100644 index 4947eafa8..000000000 --- a/rosidl_generator_cpp/msg/PrimitivesDefault.msg +++ /dev/null @@ -1,14 +0,0 @@ -bool bool_value true -byte byte_value 50 -char char_value 100 -float32 float32_value 1.125 -float64 float64_value 1.125 -int8 int8_value -50 -uint8 uint8_value 200 -int16 int16_value -1000 -uint16 uint16_value 2000 -int32 int32_value -30000 -uint32 uint32_value 60000 -int64 int64_value -40000000 -uint64 uint64_value 50000000 -string string_value "bar" diff --git a/rosidl_generator_cpp/msg/PrimitivesStatic.msg b/rosidl_generator_cpp/msg/PrimitivesStatic.msg deleted file mode 100644 index eaf9b9ef3..000000000 --- a/rosidl_generator_cpp/msg/PrimitivesStatic.msg +++ /dev/null @@ -1,13 +0,0 @@ -bool bool_value -byte byte_value -char char_value -float32 float32_value -float64 float64_value -int8 int8_value -uint8 uint8_value -int16 int16_value -uint16 uint16_value -int32 int32_value -uint32 uint32_value -int64 int64_value -uint64 uint64_value diff --git a/rosidl_generator_cpp/msg/PrimitivesUnbounded.msg b/rosidl_generator_cpp/msg/PrimitivesUnbounded.msg deleted file mode 100644 index 25f1aba07..000000000 --- a/rosidl_generator_cpp/msg/PrimitivesUnbounded.msg +++ /dev/null @@ -1,14 +0,0 @@ -bool[] bool_value -byte[] byte_value -char[] char_value -float32[] float32_value -float64[] float64_value -int8[] int8_value -uint8[] uint8_value -int16[] int16_value -uint16[] uint16_value -int32[] int32_value -uint32[] uint32_value -int64[] int64_value -uint64[] uint64_value -string[] string_value diff --git a/rosidl_generator_cpp/msg/StaticArrayBounded.msg b/rosidl_generator_cpp/msg/StaticArrayBounded.msg deleted file mode 100644 index a9203a4a1..000000000 --- a/rosidl_generator_cpp/msg/StaticArrayBounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesBounded[3] primitive_values diff --git a/rosidl_generator_cpp/msg/StaticArrayStatic.msg b/rosidl_generator_cpp/msg/StaticArrayStatic.msg deleted file mode 100644 index 5a86a51ef..000000000 --- a/rosidl_generator_cpp/msg/StaticArrayStatic.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesStatic[3] primitive_values diff --git a/rosidl_generator_cpp/msg/StaticArrayUnbounded.msg b/rosidl_generator_cpp/msg/StaticArrayUnbounded.msg deleted file mode 100644 index a8c74b87f..000000000 --- a/rosidl_generator_cpp/msg/StaticArrayUnbounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesUnbounded[3] primitive_values diff --git a/rosidl_generator_cpp/msg/String.msg b/rosidl_generator_cpp/msg/String.msg deleted file mode 100644 index 055e799f1..000000000 --- a/rosidl_generator_cpp/msg/String.msg +++ /dev/null @@ -1 +0,0 @@ -string string_value diff --git a/rosidl_generator_cpp/msg/StringArrayStatic.msg b/rosidl_generator_cpp/msg/StringArrayStatic.msg deleted file mode 100644 index dac94a0f7..000000000 --- a/rosidl_generator_cpp/msg/StringArrayStatic.msg +++ /dev/null @@ -1 +0,0 @@ -string[10] string_value diff --git a/rosidl_generator_cpp/msg/StringArrays.msg b/rosidl_generator_cpp/msg/StringArrays.msg deleted file mode 100644 index acc566164..000000000 --- a/rosidl_generator_cpp/msg/StringArrays.msg +++ /dev/null @@ -1,11 +0,0 @@ -#string<=5[3] ub_string_static_array_value -#string<=5[<=10] ub_string_ub_array_value -#string<=5[] ub_string_dynamic_array_value -string[] string_dynamic_array_value -string[3] string_static_array_value -string[<=10] string_bounded_array_value -string[] def_string_dynamic_array_value ["What", "a", "wonderful", "world", "!"] -string[3] def_string_static_array_value ["Hello", "World", "!"] -string[<=10] def_string_bounded_array_value ['Hello', 'World', "!"] -string[] def_various_quotes ["H\"el'lo", 'Wo\'r"ld'] -string[] def_various_commas ["Hel,lo", ',World', abcd, "!,",] diff --git a/rosidl_generator_cpp/msg/StringBounded.msg b/rosidl_generator_cpp/msg/StringBounded.msg deleted file mode 100644 index 81e038a3f..000000000 --- a/rosidl_generator_cpp/msg/StringBounded.msg +++ /dev/null @@ -1 +0,0 @@ -string<=10 string_value diff --git a/rosidl_generator_cpp/msg/UnboundedArrayBounded.msg b/rosidl_generator_cpp/msg/UnboundedArrayBounded.msg deleted file mode 100644 index e898b278d..000000000 --- a/rosidl_generator_cpp/msg/UnboundedArrayBounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesBounded[] primitive_values diff --git a/rosidl_generator_cpp/msg/UnboundedArrayStatic.msg b/rosidl_generator_cpp/msg/UnboundedArrayStatic.msg deleted file mode 100644 index 9d28beeed..000000000 --- a/rosidl_generator_cpp/msg/UnboundedArrayStatic.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesStatic[] primitive_values diff --git a/rosidl_generator_cpp/msg/UnboundedArrayUnbounded.msg b/rosidl_generator_cpp/msg/UnboundedArrayUnbounded.msg deleted file mode 100644 index fdd803e97..000000000 --- a/rosidl_generator_cpp/msg/UnboundedArrayUnbounded.msg +++ /dev/null @@ -1 +0,0 @@ -PrimitivesUnbounded[] primitive_values diff --git a/rosidl_generator_cpp/msg/Various.msg b/rosidl_generator_cpp/msg/Various.msg deleted file mode 100644 index b0d6d5727..000000000 --- a/rosidl_generator_cpp/msg/Various.msg +++ /dev/null @@ -1,18 +0,0 @@ -float32 float32_value 1.125 -float64 float64_value 2.4 -uint64 uint64_value -string string_value "bar" -float32[10] float32_arr -float64[3] float64_arr [8.5, 1.2, 3.4] -float64[2] float64_arr2 [99.0, 2.3] -string[3] string_arr -# TODO(clalancette): default values for strings aren't currently implemented; -# see https://github.com/ros2/rosidl/issues/206 -#string[3] string_def_arr ["hello", "there", "world"] -float32[] unbounded [1, 2] -float32[<=3] bounded_no_def -float32[<=3] bounded_def [3, 4] -FieldsWithSameTypeSomeDefaults vec3 -FieldsWithSameTypeSomeDefaults[2] vec3_fixed -FieldsWithSameTypeSomeDefaults[] vec3_unbounded -FieldsWithSameTypeSomeDefaults[<=2] vec3_bounded diff --git a/rosidl_generator_cpp/msg/WString.msg b/rosidl_generator_cpp/msg/WString.msg deleted file mode 100644 index 83d74e841..000000000 --- a/rosidl_generator_cpp/msg/WString.msg +++ /dev/null @@ -1 +0,0 @@ -wstring wstring_value diff --git a/rosidl_generator_cpp/package.xml b/rosidl_generator_cpp/package.xml index 3b168db3e..89997f351 100644 --- a/rosidl_generator_cpp/package.xml +++ b/rosidl_generator_cpp/package.xml @@ -22,6 +22,7 @@ ament_lint_common rosidl_cmake rosidl_generator_c + test_interface_files rosidl_generator_packages rosidl_runtime_packages diff --git a/rosidl_generator_cpp/rosidl_generator_cpp/__init__.py b/rosidl_generator_cpp/rosidl_generator_cpp/__init__.py index c2cb6c582..a1c0b7e33 100644 --- a/rosidl_generator_cpp/rosidl_generator_cpp/__init__.py +++ b/rosidl_generator_cpp/rosidl_generator_cpp/__init__.py @@ -34,7 +34,20 @@ def generate_cpp(generator_arguments_file): 'idl__struct.hpp.em': '%s__struct.hpp', 'idl__traits.hpp.em': '%s__traits.hpp', } - generate_files(generator_arguments_file, mapping) + generate_files( + generator_arguments_file, mapping, + post_process_callback=prefix_with_bom_if_necessary) + + +def prefix_with_bom_if_necessary(content): + try: + content.encode('ASCII') + except UnicodeError: + prefix = '\ufeff' + \ + '// NOLINT: This file starts with a BOM ' + \ + 'since it contain non-ASCII characters\n' + content = prefix + content + return content MSG_TYPE_TO_CPP = { diff --git a/rosidl_generator_cpp/srv/ComplexTypeZeroFill.srv b/rosidl_generator_cpp/srv/ComplexTypeZeroFill.srv deleted file mode 100644 index becb67bdd..000000000 --- a/rosidl_generator_cpp/srv/ComplexTypeZeroFill.srv +++ /dev/null @@ -1,3 +0,0 @@ -FieldsWithSameTypeSomeDefaults[2] req ---- -FieldsWithSameTypeSomeDefaults[2] reply diff --git a/rosidl_generator_cpp/test/test_interfaces.cpp b/rosidl_generator_cpp/test/test_interfaces.cpp index 1a8819821..a6c7960bf 100644 --- a/rosidl_generator_cpp/test/test_interfaces.cpp +++ b/rosidl_generator_cpp/test/test_interfaces.cpp @@ -22,221 +22,116 @@ #include #include "test_array_generator.hpp" +#include "rosidl_generator_cpp/msg/arrays.hpp" +#include "rosidl_generator_cpp/msg/bounded_sequences.hpp" +#include "rosidl_generator_cpp/msg/basic_types.hpp" +#include "rosidl_generator_cpp/msg/constants.hpp" +#include "rosidl_generator_cpp/msg/defaults.hpp" #include "rosidl_generator_cpp/msg/empty.hpp" - -#include "rosidl_generator_cpp/msg/bounded_array_bounded.hpp" -#include "rosidl_generator_cpp/msg/bounded_array_static.hpp" -#include "rosidl_generator_cpp/msg/bounded_array_unbounded.hpp" - -#include "rosidl_generator_cpp/msg/primitive_static_arrays.hpp" - -#include "rosidl_generator_cpp/msg/primitives_bounded.hpp" -#include "rosidl_generator_cpp/msg/primitives_constants.hpp" -#include "rosidl_generator_cpp/msg/primitives_default.hpp" -#include "rosidl_generator_cpp/msg/primitives_static.hpp" -#include "rosidl_generator_cpp/msg/primitives_unbounded.hpp" - -#include "rosidl_generator_cpp/msg/static_array_bounded.hpp" -#include "rosidl_generator_cpp/msg/static_array_static.hpp" -#include "rosidl_generator_cpp/msg/static_array_unbounded.hpp" - -#include "rosidl_generator_cpp/msg/string.hpp" -#include "rosidl_generator_cpp/msg/string_bounded.hpp" -#include "rosidl_generator_cpp/msg/string_array_static.hpp" -#include "rosidl_generator_cpp/msg/string_arrays.hpp" - -#include "rosidl_generator_cpp/msg/unbounded_array_bounded.hpp" -#include "rosidl_generator_cpp/msg/unbounded_array_static.hpp" -#include "rosidl_generator_cpp/msg/unbounded_array_unbounded.hpp" - -#include "rosidl_generator_cpp/msg/w_string.hpp" - -#define PRIMITIVES_ARRAY_SIZE 10 -#define BOUNDED_STRING_LENGTH 10 +#include "rosidl_generator_cpp/msg/multi_nested.hpp" +#include "rosidl_generator_cpp/msg/nested.hpp" +#include "rosidl_generator_cpp/msg/strings.hpp" +#include "rosidl_generator_cpp/msg/unbounded_sequences.hpp" +#include "rosidl_generator_cpp/msg/w_strings.hpp" + +#define PRIMITIVES_ARRAY_SIZE 3 +#define BOUNDED_STRING_LENGTH 22 #define SUBMESSAGE_ARRAY_SIZE 3 TEST(Test_rosidl_generator_traits, has_fixed_size) { static_assert( - rosidl_generator_traits::has_fixed_size::value, - "Empty::has_fixed_size is false"); - - static_assert( - rosidl_generator_traits::has_fixed_size::value, - "PrimitivesConstants::has_fixed_size is false"); - - static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "PrimitivesDefault::has_fixed_size is true"); - - static_assert( - rosidl_generator_traits::has_fixed_size::value, - "PrimitivesStatic::has_fixed_size is false"); + !rosidl_generator_traits::has_fixed_size::value, + "Arrays::has_fixed_size is true"); static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "PrimitivesBounded::has_fixed_size is true"); + !rosidl_generator_traits::has_fixed_size::value, + "BoundedSequences::has_fixed_size is true"); static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "PrimitivesUnbounded::has_fixed_size is true"); + rosidl_generator_traits::has_fixed_size::value, + "BasicTypes::has_fixed_size is false"); static_assert( - rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::PrimitiveStaticArrays>::value, - "PrimitivesStaticArray::has_fixed_size is false"); + rosidl_generator_traits::has_fixed_size::value, + "Constants::has_fixed_size is false"); static_assert( - rosidl_generator_traits::has_fixed_size::value, - "StaticArrayStatic::has_fixed_size is false"); + rosidl_generator_traits::has_fixed_size::value, + "Defaults::has_fixed_size is false"); static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "StaticArrayBounded::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::StaticArrayUnbounded>::value, - "StaticArrayUnbounded::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "String::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "StringBounded::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::StringArrayStatic>::value, - "StringArrayStatic::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "BoundedArrayStatic::has_fixed_size is true"); - - static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "BoundedArrayBounded::has_fixed_size is true"); + rosidl_generator_traits::has_fixed_size::value, + "Empty::has_fixed_size is false"); static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::BoundedArrayUnbounded>::value, - "BoundedArrayUnbounded::has_fixed_size is true"); + !rosidl_generator_traits::has_fixed_size::value, + "MultiNested::has_fixed_size is true"); static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::UnboundedArrayStatic>::value, - "UnboundedArrayStatic::has_fixed_size is true"); + rosidl_generator_traits::has_fixed_size::value, + "Nested::has_fixed_size is false"); static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::UnboundedArrayBounded>::value, - "UnboundedArrayBounded::has_fixed_size is true"); + !rosidl_generator_traits::has_fixed_size::value, + "Strings::has_fixed_size is true"); static_assert( - !rosidl_generator_traits::has_fixed_size< - rosidl_generator_cpp::msg::UnboundedArrayUnbounded>::value, - "UnboundedArrayUnbounded::has_fixed_size is true"); + !rosidl_generator_traits::has_fixed_size::value, + "UnboundedSequences::has_fixed_size is true"); static_assert( - !rosidl_generator_traits::has_fixed_size::value, - "WString::has_fixed_size is true"); + !rosidl_generator_traits::has_fixed_size::value, + "WStrings::has_fixed_size is true"); } TEST(Test_rosidl_generator_traits, has_bounded_size) { static_assert( - rosidl_generator_traits::has_bounded_size::value, - "Empty::has_bounded_size is false"); - - static_assert( - rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::PrimitivesConstants>::value, - "PrimitivesConstants::has_bounded_size is false"); + !rosidl_generator_traits::has_bounded_size::value, + "Arrays::has_bounded_size is true"); static_assert( - !rosidl_generator_traits::has_bounded_size::value, - "PrimitivesDefault::has_bounded_size is true"); + !rosidl_generator_traits::has_bounded_size::value, + "BoundedSequences::has_bounded_size is true"); static_assert( - rosidl_generator_traits::has_bounded_size::value, - "PrimitivesStatic::has_bounded_size is false"); + rosidl_generator_traits::has_bounded_size::value, + "BasicTypes::has_bounded_size is false"); static_assert( - rosidl_generator_traits::has_bounded_size::value, - "PrimitivesBounded::has_bounded_size is false"); + rosidl_generator_traits::has_bounded_size::value, + "Constants::has_bounded_size is false"); static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::PrimitivesUnbounded>::value, - "PrimitivesUnbounded::has_bounded_size is true"); + rosidl_generator_traits::has_bounded_size::value, + "Defaults::has_bounded_size is false"); static_assert( - rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::PrimitiveStaticArrays>::value, - "PrimitivesStaticArray::has_bounded_size is false"); - - static_assert( - rosidl_generator_traits::has_bounded_size::value, - "StaticArrayStatic::has_bounded_size is false"); - - static_assert( - rosidl_generator_traits::has_bounded_size::value, - "StaticArrayBounded::has_bounded_size is false"); - - static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::StaticArrayUnbounded>::value, - "StaticArrayUnbounded::has_bounded_size is true"); - - static_assert( - !rosidl_generator_traits::has_bounded_size::value, - "String::has_bounded_size is true"); - - static_assert( - rosidl_generator_traits::has_bounded_size::value, - "StringBounded::has_bounded_size is false"); - - static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::StringArrayStatic>::value, - "StringArrayStatic::has_bounded_size is true"); - - static_assert( - rosidl_generator_traits::has_bounded_size::value, - "BoundedArrayStatic::has_bounded_size is false"); - - static_assert( - rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::BoundedArrayBounded>::value, - "BoundedArrayBounded::has_bounded_size is false"); + rosidl_generator_traits::has_bounded_size::value, + "Empty::has_bounded_size is false"); static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::BoundedArrayUnbounded>::value, - "BoundedArrayUnbounded::has_bounded_size is true"); + !rosidl_generator_traits::has_bounded_size::value, + "MultiNested::has_bounded_size is true"); static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::UnboundedArrayStatic>::value, - "UnboundedArrayStatic::has_bounded_size is true"); + rosidl_generator_traits::has_bounded_size::value, + "Nested::has_bounded_size is false"); static_assert( - !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::UnboundedArrayBounded>::value, - "UnboundedArrayBounded::has_bounded_size is true"); + !rosidl_generator_traits::has_bounded_size::value, + "Strings::has_bounded_size is true"); static_assert( !rosidl_generator_traits::has_bounded_size< - rosidl_generator_cpp::msg::UnboundedArrayUnbounded>::value, - "UnboundedArrayUnbounded::has_bounded_size is true"); + rosidl_generator_cpp::msg::UnboundedSequences>::value, + "UnboundedSequences::has_bounded_size is true"); static_assert( - !rosidl_generator_traits::has_bounded_size::value, - "WString::has_bounded_size is true"); + !rosidl_generator_traits::has_bounded_size::value, + "WStrings::has_bounded_size is true"); } -#define TEST_PRIMITIVE_FIELD_ASSIGNMENT(Message, FieldName, InitialValue, FinalValue) \ +#define TEST_BASIC_TYPE_FIELD_ASSIGNMENT(Message, FieldName, InitialValue, FinalValue) \ Message.FieldName = InitialValue; \ ASSERT_EQ(InitialValue, Message.FieldName); \ Message.FieldName = FinalValue; \ @@ -252,34 +147,34 @@ TEST(Test_rosidl_generator_traits, has_bounded_size) { Message.FieldName = InitialValue; \ Message.FieldName = FinalValue; -void test_message_primitives_static(rosidl_generator_cpp::msg::PrimitivesStatic message) +void test_message_primitives_static(rosidl_generator_cpp::msg::BasicTypes message) { // workaround for https://github.com/google/googletest/issues/322 #ifdef __linux__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion-null" #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, bool_value, false, true) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, bool_value, false, true) #ifdef __linux__ #pragma GCC diagnostic pop #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, 0, 255) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, 0, UINT8_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) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint8_value, 0, UINT8_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int16_value, INT16_MIN, INT16_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint16_value, 0, UINT16_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int32_value, INT32_MIN, INT32_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint32_value, 0ul, UINT32_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int64_value, INT64_MIN, INT64_MAX) - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint64_value, 0ull, UINT64_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, byte_value, 0, 255) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, char_value, 0, UINT8_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, float32_value, FLT_MIN, FLT_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, float64_value, DBL_MIN, DBL_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int8_value, INT8_MIN, INT8_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint8_value, 0, UINT8_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int16_value, INT16_MIN, INT16_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint16_value, 0, UINT16_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int32_value, INT32_MIN, INT32_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint32_value, 0ul, UINT32_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int64_value, INT64_MIN, INT64_MAX) + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint64_value, 0ull, UINT64_MAX) } -#define TEST_BOUNDED_ARRAY_PRIMITIVE( \ - Message, FieldName, PrimitiveType, ArraySize, MinVal, MaxVal) \ - rosidl_generator_cpp::BoundedVector pattern_ ## FieldName; \ +#define TEST_BOUNDED_SEQUENCE_TYPES( \ + Message, FieldName, BasicType, ArraySize, MinVal, MaxVal) \ + rosidl_generator_cpp::BoundedVector pattern_ ## FieldName; \ Message.FieldName.resize(ArraySize); \ pattern_ ## FieldName.resize(ArraySize); \ test_vector_fill( \ @@ -287,49 +182,49 @@ void test_message_primitives_static(rosidl_generator_cpp::msg::PrimitivesStatic std::copy_n(pattern_ ## FieldName.begin(), Message.FieldName.size(), Message.FieldName.begin()); \ ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ -#define TEST_BOUNDED_ARRAY_STRING( \ - Message, FieldName, PrimitiveType, ArraySize, MinVal, MaxVal, MinLength, MaxLength) \ - rosidl_generator_cpp::BoundedVector pattern_ ## FieldName; \ +#define TEST_BOUNDED_SEQUENCE_STRING( \ + Message, FieldName, BasicType, ArraySize, MinVal, MaxVal, MinLength, MaxLength) \ + rosidl_generator_cpp::BoundedVector pattern_ ## FieldName; \ Message.FieldName.resize(ArraySize); \ pattern_ ## FieldName.resize(ArraySize); \ test_vector_fill( \ &pattern_ ## FieldName, ArraySize, MinVal, MaxVal, MinLength, MaxLength); \ std::copy_n(pattern_ ## FieldName.begin(), Message.FieldName.size(), Message.FieldName.begin()); \ - ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ + ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); -void test_message_primitives_bounded(rosidl_generator_cpp::msg::PrimitivesBounded message) +void test_message_primitives_bounded(rosidl_generator_cpp::msg::BoundedSequences message) { - TEST_BOUNDED_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, bool_values, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, char_value, unsigned char, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, char_values, unsigned char, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, byte_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, float32_values, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, float64_values, double, PRIMITIVES_ARRAY_SIZE, \ DBL_MIN, DBL_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, int8_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, int8_values, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, uint8_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, uint8_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, int16_value, int16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, int16_values, int16_t, PRIMITIVES_ARRAY_SIZE, \ INT16_MIN, INT16_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, uint16_value, uint16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, uint16_values, uint16_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT16_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, int32_value, int32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, int32_values, int32_t, PRIMITIVES_ARRAY_SIZE, \ INT32_MIN, INT32_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, uint32_value, uint32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, uint32_values, uint32_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, int64_value, int64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, int64_values, int64_t, PRIMITIVES_ARRAY_SIZE, \ INT64_MIN, INT64_MAX) - TEST_BOUNDED_ARRAY_PRIMITIVE(message, uint64_value, uint64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_TYPES(message, uint64_values, uint64_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT64_MAX) - TEST_BOUNDED_ARRAY_STRING(message, string_values, std::string, PRIMITIVES_ARRAY_SIZE, \ + TEST_BOUNDED_SEQUENCE_STRING(message, string_values, std::string, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX, 0, BOUNDED_STRING_LENGTH) } -#define TEST_UNBOUNDED_ARRAY_PRIMITIVE( \ +#define TEST_UNBOUNDED_SEQUENCE_TYPES( \ Message, FieldName, PrimitiveType, ArraySize, MinVal, MaxVal) \ std::vector pattern_ ## FieldName(ArraySize); \ pattern_ ## FieldName.resize(ArraySize); \ @@ -339,7 +234,7 @@ void test_message_primitives_bounded(rosidl_generator_cpp::msg::PrimitivesBounde std::copy_n(pattern_ ## FieldName.begin(), ArraySize, Message.FieldName.begin()); \ ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ -#define TEST_UNBOUNDED_ARRAY_STRING( \ +#define TEST_UNBOUNDED_SEQUENCE_STRING( \ Message, FieldName, PrimitiveType, ArraySize, MinVal, MaxVal, MinLength, MaxLength) \ std::vector pattern_ ## FieldName; \ Message.FieldName.resize(ArraySize); \ @@ -349,39 +244,39 @@ void test_message_primitives_bounded(rosidl_generator_cpp::msg::PrimitivesBounde std::copy_n(pattern_ ## FieldName.begin(), Message.FieldName.size(), Message.FieldName.begin()); \ ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ -void test_message_primitives_unbounded(rosidl_generator_cpp::msg::PrimitivesUnbounded message) +void test_message_primitives_unbounded(rosidl_generator_cpp::msg::UnboundedSequences message) { - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, bool_values, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, char_value, unsigned char, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, char_values, unsigned char, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, byte_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, float32_values, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, float64_values, double, PRIMITIVES_ARRAY_SIZE, \ DBL_MIN, DBL_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, int8_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, int8_values, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, uint8_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, uint8_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, int16_value, int16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, int16_values, int16_t, PRIMITIVES_ARRAY_SIZE, \ INT16_MIN, INT16_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, uint16_value, uint16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, uint16_values, uint16_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT16_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, int32_value, int32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, int32_values, int32_t, PRIMITIVES_ARRAY_SIZE, \ INT32_MIN, INT32_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, uint32_value, uint32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, uint32_values, uint32_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, int64_value, int64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, int64_values, int64_t, PRIMITIVES_ARRAY_SIZE, \ INT64_MIN, INT64_MAX) - TEST_UNBOUNDED_ARRAY_PRIMITIVE(message, uint64_value, uint64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_TYPES(message, uint64_values, uint64_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT64_MAX) - TEST_UNBOUNDED_ARRAY_STRING(message, string_value, std::string, PRIMITIVES_ARRAY_SIZE, \ + TEST_UNBOUNDED_SEQUENCE_STRING(message, string_values, std::string, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX, 0, UINT16_MAX) } -#define TEST_STATIC_ARRAY_PRIMITIVE( \ +#define TEST_ARRAY_TYPES( \ Message, FieldName, PrimitiveType, ArraySize, MinVal, MaxVal) \ std::array pattern_ ## FieldName; \ test_vector_fill( \ @@ -389,141 +284,133 @@ void test_message_primitives_unbounded(rosidl_generator_cpp::msg::PrimitivesUnbo std::copy_n(pattern_ ## FieldName.begin(), ArraySize, Message.FieldName.begin()); \ ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ -void test_message_primitives_static_arrays(rosidl_generator_cpp::msg::PrimitiveStaticArrays message) +void test_message_primitives_static_arrays(rosidl_generator_cpp::msg::Arrays message) { - TEST_STATIC_ARRAY_PRIMITIVE(message, bool_value, bool, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, bool_values, bool, PRIMITIVES_ARRAY_SIZE, \ false, true) - TEST_STATIC_ARRAY_PRIMITIVE(message, char_value, unsigned char, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, char_values, unsigned char, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, byte_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, byte_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, float32_value, float, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, float32_values, float, PRIMITIVES_ARRAY_SIZE, \ FLT_MIN, FLT_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, float64_value, double, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, float64_values, double, PRIMITIVES_ARRAY_SIZE, \ DBL_MIN, DBL_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, int8_value, int8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, int8_values, int8_t, PRIMITIVES_ARRAY_SIZE, \ INT8_MIN, INT8_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, uint8_value, uint8_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, uint8_values, uint8_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT8_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, int16_value, int16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, int16_values, int16_t, PRIMITIVES_ARRAY_SIZE, \ INT16_MIN, INT16_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, uint16_value, uint16_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, uint16_values, uint16_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT16_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, int32_value, int32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, int32_values, int32_t, PRIMITIVES_ARRAY_SIZE, \ INT32_MIN, INT32_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, uint32_value, uint32_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, uint32_values, uint32_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, int64_value, int64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, int64_values, int64_t, PRIMITIVES_ARRAY_SIZE, \ INT64_MIN, INT64_MAX) - TEST_STATIC_ARRAY_PRIMITIVE(message, uint64_value, uint64_t, PRIMITIVES_ARRAY_SIZE, \ + TEST_ARRAY_TYPES(message, uint64_values, uint64_t, PRIMITIVES_ARRAY_SIZE, \ 0, UINT64_MAX) } -// Primitives static -TEST(Test_messages, primitives_static) { - rosidl_generator_cpp::msg::PrimitivesStatic message; +// Basic types +TEST(Test_messages, basic_types) { + rosidl_generator_cpp::msg::BasicTypes message; test_message_primitives_static(message); } -// Primitives static arrays -TEST(Test_messages, primitives_static_arrays) { - rosidl_generator_cpp::msg::PrimitiveStaticArrays message; +// Arrays +TEST(Test_messages, arrays) { + rosidl_generator_cpp::msg::Arrays message; test_message_primitives_static_arrays(message); } -// Primitives bounded arrays -TEST(Test_messages, primitives_bounded) { - rosidl_generator_cpp::msg::PrimitivesBounded message; +// Bounded sequences +TEST(Test_messages, bounded_sequences) { + rosidl_generator_cpp::msg::BoundedSequences message; test_message_primitives_bounded(message); } -// Primitives unbounded arrays -TEST(Test_messages, primitives_unbounded) { - rosidl_generator_cpp::msg::PrimitivesUnbounded message; +// Unbounded sequences +TEST(Test_messages, unbounded_sequences) { + rosidl_generator_cpp::msg::UnboundedSequences message; test_message_primitives_unbounded(message); } -// Static array of a submessage of static primitives -TEST(Test_messages, static_array_static) { - rosidl_generator_cpp::msg::StaticArrayStatic message; - for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_static(message.primitive_values[i]); - } -} - -// Static array of a submessage of bounded array of primitives +// Array of bounded sequences TEST(Test_messages, static_array_bounded) { - rosidl_generator_cpp::msg::StaticArrayBounded message; + rosidl_generator_cpp::msg::MultiNested message; for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_bounded(message.primitive_values[i]); + test_message_primitives_bounded(message.array_of_bounded_sequences[i]); } } -// Static array of a submessage of unbounded array of primitives +// Array of unbounded sequences TEST(Test_messages, static_array_unbounded) { - rosidl_generator_cpp::msg::StaticArrayUnbounded message; + rosidl_generator_cpp::msg::MultiNested message; for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_unbounded(message.primitive_values[i]); + test_message_primitives_unbounded(message.array_of_unbounded_sequences[i]); } } -// Bounded array of a submessage of static primitive +// Bounded sequences of basic types TEST(Test_messages, bounded_array_static) { - rosidl_generator_cpp::msg::BoundedArrayStatic message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::BoundedSequences message; + message.basic_types_values.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_static(message.primitive_values[i]); + test_message_primitives_static(message.basic_types_values[i]); } } -// Bounded array of a submessage of bounded array of primitives +// Bounded sequences of bounded sequences TEST(Test_messages, bounded_array_bounded) { - rosidl_generator_cpp::msg::BoundedArrayBounded message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::MultiNested message; + message.bounded_sequence_of_bounded_sequences.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_bounded(message.primitive_values[i]); + test_message_primitives_bounded(message.bounded_sequence_of_bounded_sequences[i]); } } -// Bounded array of a submessage of unbounded array of primitives +// Bounded sequences of unbounded sequences TEST(Test_messages, bounded_array_unbounded) { - rosidl_generator_cpp::msg::BoundedArrayUnbounded message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::MultiNested message; + message.bounded_sequence_of_unbounded_sequences.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_unbounded(message.primitive_values[i]); + test_message_primitives_unbounded(message.bounded_sequence_of_unbounded_sequences[i]); } } -// Unbounded array of a submessage of static primitives +// Unbounded sequence of basic types TEST(Test_messages, unbounded_array_static) { - rosidl_generator_cpp::msg::UnboundedArrayStatic message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::UnboundedSequences message; + message.basic_types_values.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_static(message.primitive_values[i]); + test_message_primitives_static(message.basic_types_values[i]); } } -// Unbounded array of a submessage of bounded primitive +// Unbounded sequence of bounded sequences TEST(Test_messages, unbounded_array_bounded) { - rosidl_generator_cpp::msg::UnboundedArrayBounded message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::MultiNested message; + message.unbounded_sequence_of_bounded_sequences.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_bounded(message.primitive_values[i]); + test_message_primitives_bounded(message.unbounded_sequence_of_bounded_sequences[i]); } } -// Unbounded array of a submessage of unbounded array of primitives +// Unbounded sequence of unbounded sequences TEST(Test_messages, unbounded_array_unbounded) { - rosidl_generator_cpp::msg::UnboundedArrayUnbounded message; - message.primitive_values.resize(SUBMESSAGE_ARRAY_SIZE); + rosidl_generator_cpp::msg::MultiNested message; + message.unbounded_sequence_of_unbounded_sequences.resize(SUBMESSAGE_ARRAY_SIZE); for (int i = 0; i < SUBMESSAGE_ARRAY_SIZE; i++) { - test_message_primitives_unbounded(message.primitive_values[i]); + test_message_primitives_unbounded(message.unbounded_sequence_of_unbounded_sequences[i]); } } -// Constant Primitives -TEST(Test_messages, primitives_constants) { - rosidl_generator_cpp::msg::PrimitivesConstants message; +// Constants +TEST(Test_messages, constants) { + rosidl_generator_cpp::msg::Constants message; ASSERT_EQ(true, message.BOOL_CONST); ASSERT_EQ(50, message.BYTE_CONST); ASSERT_EQ(100, message.CHAR_CONST); @@ -537,86 +424,60 @@ TEST(Test_messages, primitives_constants) { ASSERT_EQ(60000ul, message.UINT32_CONST); ASSERT_EQ(-40000000, message.INT64_CONST); ASSERT_EQ(50000000ull, message.UINT64_CONST); - ASSERT_STREQ("foo", message.STRING_CONST.c_str()); } -// Primitives with default values -TEST(Test_messages, primitives_default) { - rosidl_generator_cpp::msg::PrimitivesDefault message; - +// Defaults +TEST(Test_messages, defaults) { + rosidl_generator_cpp::msg::Defaults message; // workaround for https://github.com/google/googletest/issues/322 #ifdef __linux__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion-null" #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, bool_value, true, false); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, bool_value, true, false); #ifdef __linux__ #pragma GCC diagnostic pop #endif - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, byte_value, 50, 255); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, char_value, 100, UINT8_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); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint8_value, 200, UINT8_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int16_value, -1000, INT16_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint16_value, 2000, UINT16_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int32_value, -30000, INT32_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint32_value, 60000ul, UINT32_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, int64_value, -40000000, INT64_MAX); - TEST_PRIMITIVE_FIELD_ASSIGNMENT(message, uint64_value, 50000000ull, UINT64_MAX); - TEST_STRING_FIELD_ASSIGNMENT(message, string_value, "bar", "Hello World!") + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, byte_value, 50, 255); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, char_value, 100, UINT8_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, float32_value, 1.125f, FLT_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, float64_value, 1.125, DBL_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int8_value, -50, INT8_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint8_value, 200, UINT8_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int16_value, -1000, INT16_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint16_value, 2000, UINT16_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int32_value, -30000, INT32_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint32_value, 60000ul, UINT32_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, int64_value, -40000000, INT64_MAX); + TEST_BASIC_TYPE_FIELD_ASSIGNMENT(message, uint64_value, 50000000ull, UINT64_MAX); } -// String arrays with default values +// String array with default values TEST(Test_messages, string_arrays_default) { - // rosidl_generator_cpp::msg::StringArrays message; - rosidl_generator_cpp::msg::StringArrays message; - - ASSERT_STREQ("Hello", message.def_string_static_array_value[0].c_str()); - ASSERT_STREQ("World", message.def_string_static_array_value[1].c_str()); - ASSERT_STREQ("!", message.def_string_static_array_value[2].c_str()); - - ASSERT_EQ(3ul, message.def_string_bounded_array_value.size()); - ASSERT_STREQ("Hello", message.def_string_bounded_array_value[0].c_str()); - ASSERT_STREQ("World", message.def_string_bounded_array_value[1].c_str()); - ASSERT_STREQ("!", message.def_string_bounded_array_value[2].c_str()); - - ASSERT_EQ(5ul, message.def_string_dynamic_array_value.size()); - ASSERT_STREQ("What", message.def_string_dynamic_array_value[0].c_str()); - ASSERT_STREQ("a", message.def_string_dynamic_array_value[1].c_str()); - ASSERT_STREQ("wonderful", message.def_string_dynamic_array_value[2].c_str()); - ASSERT_STREQ("world", message.def_string_dynamic_array_value[3].c_str()); - ASSERT_STREQ("!", message.def_string_dynamic_array_value[4].c_str()); - - ASSERT_EQ(4ul, message.def_various_commas.size()); - ASSERT_STREQ("Hel,lo", message.def_various_commas[0].c_str()); - ASSERT_STREQ(",World", message.def_various_commas[1].c_str()); - ASSERT_STREQ("abcd", message.def_various_commas[2].c_str()); - ASSERT_STREQ("!,", message.def_various_commas[3].c_str()); - - ASSERT_EQ(2ul, message.def_various_quotes.size()); - ASSERT_STREQ("H\"el'lo", message.def_various_quotes[0].c_str()); - ASSERT_STREQ("Wo'r\"ld", message.def_various_quotes[1].c_str()); + rosidl_generator_cpp::msg::Arrays message; + ASSERT_STREQ("", message.string_values_default[0].c_str()); + ASSERT_STREQ("max value", message.string_values_default[1].c_str()); + ASSERT_STREQ("min value", message.string_values_default[2].c_str()); + ASSERT_EQ(3ul, message.string_values_default.size()); } // TODO(mikaelarguedas) reenable this test when bounded strings enforce length TEST(Test_messages, DISABLED_Test_bounded_strings) { - rosidl_generator_cpp::msg::StringBounded message; + rosidl_generator_cpp::msg::Strings message; TEST_STRING_FIELD_ASSIGNMENT(message, string_value, "", "Deep into") std::string tooLongString = std::string("Too long string"); - message.string_value = tooLongString; + message.bounded_string_value = tooLongString; tooLongString.resize(BOUNDED_STRING_LENGTH); ASSERT_STREQ(tooLongString.c_str(), message.string_value.c_str()); } TEST(Test_messages, Test_string) { - rosidl_generator_cpp::msg::String message; + rosidl_generator_cpp::msg::Strings message; TEST_STRING_FIELD_ASSIGNMENT(message, string_value, "", "Deep into") } TEST(Test_messages, Test_wstring) { - rosidl_generator_cpp::msg::WString message; + rosidl_generator_cpp::msg::WStrings message; TEST_WSTRING_FIELD_ASSIGNMENT(message, wstring_value, u"", u"wstring_value_\u2122") } @@ -629,7 +490,7 @@ TEST(Test_messages, Test_wstring) { ASSERT_EQ(pattern_ ## FieldName, Message.FieldName); \ TEST(Test_messages, Test_string_array_static) { - rosidl_generator_cpp::msg::StringArrayStatic message; - TEST_STATIC_ARRAY_STRING(message, string_value, std::string, PRIMITIVES_ARRAY_SIZE, \ + rosidl_generator_cpp::msg::Arrays message; + TEST_STATIC_ARRAY_STRING(message, string_values_default, std::string, PRIMITIVES_ARRAY_SIZE, \ 0, UINT32_MAX, 0, UINT16_MAX) } diff --git a/rosidl_generator_cpp/test/test_msg_datatype.cpp b/rosidl_generator_cpp/test/test_msg_datatype.cpp index 9a1d95a11..2782cc428 100644 --- a/rosidl_generator_cpp/test/test_msg_datatype.cpp +++ b/rosidl_generator_cpp/test/test_msg_datatype.cpp @@ -14,13 +14,13 @@ #include #include "rosidl_generator_cpp/msg/empty.hpp" -#include "rosidl_generator_cpp/msg/string.hpp" +#include "rosidl_generator_cpp/msg/strings.hpp" TEST(Test_rosidl_generator_traits, check_data_type) { ASSERT_STREQ( - "rosidl_generator_cpp::msg::String", - rosidl_generator_traits::data_type()); + "rosidl_generator_cpp::msg::Strings", + rosidl_generator_traits::data_type()); ASSERT_STREQ( "rosidl_generator_cpp::msg::Empty", rosidl_generator_traits::data_type()); diff --git a/rosidl_generator_cpp/test/test_msg_initialization.cpp b/rosidl_generator_cpp/test/test_msg_initialization.cpp index 7ad16059a..e5e3ac153 100644 --- a/rosidl_generator_cpp/test/test_msg_initialization.cpp +++ b/rosidl_generator_cpp/test/test_msg_initialization.cpp @@ -18,9 +18,8 @@ #include -#include "rosidl_generator_cpp/msg/primitives_default.hpp" -#include "rosidl_generator_cpp/msg/primitives_static.hpp" -#include "rosidl_generator_cpp/msg/various.hpp" +#include "rosidl_generator_cpp/msg/defaults.hpp" +#include "rosidl_generator_cpp/msg/bounded_sequences.hpp" template struct ScopeExit @@ -46,298 +45,126 @@ make_scope_exit(Callable callable) auto STRING_JOIN(scope_exit_, __LINE__) = make_scope_exit([&]() {code;}) TEST(Test_msg_initialization, no_arg_constructor) { - rosidl_generator_cpp::msg::PrimitivesDefault primitives_def; - ASSERT_TRUE(primitives_def.bool_value); - ASSERT_EQ(50, primitives_def.byte_value); - ASSERT_EQ(100, primitives_def.char_value); - ASSERT_EQ(1.125f, primitives_def.float32_value); - ASSERT_EQ(1.125, primitives_def.float64_value); - ASSERT_EQ(-50, primitives_def.int8_value); - ASSERT_EQ(200, primitives_def.uint8_value); - ASSERT_EQ(-1000, primitives_def.int16_value); - ASSERT_EQ(2000, primitives_def.uint16_value); - ASSERT_EQ(-30000L, primitives_def.int32_value); - ASSERT_EQ(60000UL, primitives_def.uint32_value); - ASSERT_EQ(-40000000LL, primitives_def.int64_value); - ASSERT_EQ(50000000ULL, primitives_def.uint64_value); - ASSERT_EQ("bar", primitives_def.string_value); - - rosidl_generator_cpp::msg::PrimitivesStatic primitives_static; - ASSERT_FALSE(primitives_static.bool_value); - ASSERT_EQ(0, primitives_static.byte_value); - ASSERT_EQ(0, primitives_static.char_value); - ASSERT_EQ(0.0f, primitives_static.float32_value); - ASSERT_EQ(0.0, primitives_static.float64_value); - ASSERT_EQ(0, primitives_static.int8_value); - ASSERT_EQ(0, primitives_static.uint8_value); - ASSERT_EQ(0, primitives_static.int16_value); - ASSERT_EQ(0, primitives_static.uint16_value); - ASSERT_EQ(0L, primitives_static.int32_value); - ASSERT_EQ(0UL, primitives_static.uint32_value); - ASSERT_EQ(0LL, primitives_static.int64_value); - ASSERT_EQ(0ULL, primitives_static.uint64_value); - - rosidl_generator_cpp::msg::Various various_def; - - ASSERT_EQ(1.125f, various_def.float32_value); - ASSERT_EQ(2.4, various_def.float64_value); - ASSERT_EQ(0ULL, various_def.uint64_value); - ASSERT_EQ("bar", various_def.string_value); - ASSERT_TRUE(std::all_of( - various_def.float32_arr.begin(), various_def.float32_arr.end(), [](float i) { - return 0.0f == i; - })); - ASSERT_EQ(8.5, various_def.float64_arr[0]); - ASSERT_EQ(1.2, various_def.float64_arr[1]); - ASSERT_EQ(3.4, various_def.float64_arr[2]); - ASSERT_TRUE(std::all_of( - various_def.string_arr.begin(), various_def.string_arr.end(), [](std::string i) { - return "" == i; - })); - ASSERT_EQ(2UL, various_def.unbounded.size()); - ASSERT_EQ(1.0f, various_def.unbounded[0]); - ASSERT_EQ(2.0f, various_def.unbounded[1]); - ASSERT_EQ(0UL, various_def.bounded_no_def.size()); - ASSERT_EQ(2UL, various_def.bounded_def.size()); - ASSERT_EQ(3.0f, various_def.bounded_def[0]); - ASSERT_EQ(4.0f, various_def.bounded_def[1]); - ASSERT_EQ(0UL, various_def.vec3.x); - ASSERT_EQ(45UL, various_def.vec3.y); - ASSERT_EQ(0UL, various_def.vec3.z); - ASSERT_EQ(2UL, various_def.vec3_fixed.size()); - ASSERT_EQ(0UL, various_def.vec3_fixed[0].x); - ASSERT_EQ(0UL, various_def.vec3_fixed[1].x); - ASSERT_EQ(45UL, various_def.vec3_fixed[0].y); - ASSERT_EQ(45UL, various_def.vec3_fixed[1].y); - ASSERT_EQ(0UL, various_def.vec3_fixed[0].z); - ASSERT_EQ(0UL, various_def.vec3_fixed[1].z); - ASSERT_EQ(0UL, various_def.vec3_unbounded.size()); - ASSERT_EQ(0UL, various_def.vec3_bounded.size()); + rosidl_generator_cpp::msg::Defaults def; + ASSERT_TRUE(def.bool_value); + ASSERT_EQ(50, def.byte_value); + ASSERT_EQ(100, def.char_value); + ASSERT_EQ(1.125f, def.float32_value); + ASSERT_EQ(1.125, def.float64_value); + ASSERT_EQ(-50, def.int8_value); + ASSERT_EQ(200, def.uint8_value); + ASSERT_EQ(-1000, def.int16_value); + ASSERT_EQ(2000, def.uint16_value); + ASSERT_EQ(-30000L, def.int32_value); + ASSERT_EQ(60000UL, def.uint32_value); + ASSERT_EQ(-40000000LL, def.int64_value); + ASSERT_EQ(50000000ULL, def.uint64_value); } TEST(Test_msg_initialization, all_constructor) { - rosidl_generator_cpp::msg::PrimitivesDefault primitives_def( + rosidl_generator_cpp::msg::Defaults def( rosidl_generator_cpp::MessageInitialization::ALL); - ASSERT_TRUE(primitives_def.bool_value); - ASSERT_EQ(50, primitives_def.byte_value); - ASSERT_EQ(100, primitives_def.char_value); - ASSERT_EQ(1.125f, primitives_def.float32_value); - ASSERT_EQ(1.125, primitives_def.float64_value); - ASSERT_EQ(-50, primitives_def.int8_value); - ASSERT_EQ(200, primitives_def.uint8_value); - ASSERT_EQ(-1000, primitives_def.int16_value); - ASSERT_EQ(2000, primitives_def.uint16_value); - ASSERT_EQ(-30000L, primitives_def.int32_value); - ASSERT_EQ(60000UL, primitives_def.uint32_value); - ASSERT_EQ(-40000000LL, primitives_def.int64_value); - ASSERT_EQ(50000000ULL, primitives_def.uint64_value); - ASSERT_EQ("bar", primitives_def.string_value); - - rosidl_generator_cpp::msg::Various def( - rosidl_generator_cpp::MessageInitialization::ALL); - + ASSERT_TRUE(def.bool_value); + ASSERT_EQ(50, def.byte_value); + ASSERT_EQ(100, def.char_value); ASSERT_EQ(1.125f, def.float32_value); - ASSERT_EQ(2.4, def.float64_value); - ASSERT_EQ(0ULL, def.uint64_value); - ASSERT_EQ("bar", def.string_value); - ASSERT_TRUE(std::all_of(def.float32_arr.begin(), def.float32_arr.end(), [](float i) { - return 0.0f == i; - })); - ASSERT_EQ(8.5, def.float64_arr[0]); - ASSERT_EQ(1.2, def.float64_arr[1]); - ASSERT_EQ(3.4, def.float64_arr[2]); - ASSERT_TRUE(std::all_of(def.string_arr.begin(), def.string_arr.end(), [](std::string i) { - return "" == i; - })); - ASSERT_EQ(2UL, def.unbounded.size()); - ASSERT_EQ(1.0f, def.unbounded[0]); - ASSERT_EQ(2.0f, def.unbounded[1]); - ASSERT_EQ(0UL, def.bounded_no_def.size()); - ASSERT_EQ(2UL, def.bounded_def.size()); - ASSERT_EQ(3.0f, def.bounded_def[0]); - ASSERT_EQ(4.0f, def.bounded_def[1]); - ASSERT_EQ(0UL, def.vec3.x); - ASSERT_EQ(45UL, def.vec3.y); - ASSERT_EQ(0UL, def.vec3.z); - ASSERT_EQ(2UL, def.vec3_fixed.size()); - ASSERT_EQ(0UL, def.vec3_fixed[0].x); - ASSERT_EQ(0UL, def.vec3_fixed[1].x); - ASSERT_EQ(45UL, def.vec3_fixed[0].y); - ASSERT_EQ(45UL, def.vec3_fixed[1].y); - ASSERT_EQ(0UL, def.vec3_fixed[0].z); - ASSERT_EQ(0UL, def.vec3_fixed[1].z); - ASSERT_EQ(0UL, def.vec3_unbounded.size()); - ASSERT_EQ(0UL, def.vec3_bounded.size()); + ASSERT_EQ(1.125, def.float64_value); + ASSERT_EQ(-50, def.int8_value); + ASSERT_EQ(200, def.uint8_value); + ASSERT_EQ(-1000, def.int16_value); + ASSERT_EQ(2000, def.uint16_value); + ASSERT_EQ(-30000L, def.int32_value); + ASSERT_EQ(60000UL, def.uint32_value); + ASSERT_EQ(-40000000LL, def.int64_value); + ASSERT_EQ(50000000ULL, def.uint64_value); } TEST(Test_msg_initialization, zero_constructor) { - rosidl_generator_cpp::msg::PrimitivesDefault primitives_def( + rosidl_generator_cpp::msg::Defaults def( rosidl_generator_cpp::MessageInitialization::ZERO); - ASSERT_FALSE(primitives_def.bool_value); - ASSERT_EQ(0, primitives_def.byte_value); - ASSERT_EQ(0, primitives_def.char_value); - ASSERT_EQ(0.0f, primitives_def.float32_value); - ASSERT_EQ(0.0, primitives_def.float64_value); - ASSERT_EQ(0, primitives_def.int8_value); - ASSERT_EQ(0, primitives_def.uint8_value); - ASSERT_EQ(0, primitives_def.int16_value); - ASSERT_EQ(0, primitives_def.uint16_value); - ASSERT_EQ(0L, primitives_def.int32_value); - ASSERT_EQ(0UL, primitives_def.uint32_value); - ASSERT_EQ(0LL, primitives_def.int64_value); - ASSERT_EQ(0ULL, primitives_def.uint64_value); - ASSERT_EQ("", primitives_def.string_value); - - rosidl_generator_cpp::msg::Various def( - rosidl_generator_cpp::MessageInitialization::ZERO); - + ASSERT_FALSE(def.bool_value); + ASSERT_EQ(0, def.byte_value); + ASSERT_EQ(0, def.char_value); ASSERT_EQ(0.0f, def.float32_value); ASSERT_EQ(0.0, def.float64_value); + ASSERT_EQ(0, def.int8_value); + ASSERT_EQ(0, def.uint8_value); + ASSERT_EQ(0, def.int16_value); + ASSERT_EQ(0, def.uint16_value); + ASSERT_EQ(0L, def.int32_value); + ASSERT_EQ(0UL, def.uint32_value); + ASSERT_EQ(0LL, def.int64_value); ASSERT_EQ(0ULL, def.uint64_value); - ASSERT_EQ("", def.string_value); - ASSERT_TRUE(std::all_of(def.float32_arr.begin(), def.float32_arr.end(), [](float i) { - return 0.0f == i; - })); - ASSERT_TRUE(std::all_of(def.float64_arr.begin(), def.float64_arr.end(), [](double i) { - return 0.0 == i; - })); - ASSERT_TRUE(std::all_of(def.string_arr.begin(), def.string_arr.end(), [](std::string i) { - return "" == i; - })); - ASSERT_EQ(0UL, def.unbounded.size()); - ASSERT_EQ(0UL, def.bounded_no_def.size()); - ASSERT_EQ(0UL, def.bounded_def.size()); - ASSERT_EQ(0UL, def.vec3.x); - ASSERT_EQ(0UL, def.vec3.y); - ASSERT_EQ(0UL, def.vec3.z); - ASSERT_EQ(2UL, def.vec3_fixed.size()); - ASSERT_EQ(0UL, def.vec3_fixed[0].x); - ASSERT_EQ(0UL, def.vec3_fixed[1].x); - ASSERT_EQ(0UL, def.vec3_fixed[0].y); - ASSERT_EQ(0UL, def.vec3_fixed[1].y); - ASSERT_EQ(0UL, def.vec3_fixed[0].z); - ASSERT_EQ(0UL, def.vec3_fixed[1].z); - ASSERT_EQ(0UL, def.vec3_unbounded.size()); - ASSERT_EQ(0UL, def.vec3_bounded.size()); } TEST(Test_msg_initialization, defaults_only_constructor) { - rosidl_generator_cpp::msg::PrimitivesDefault primitives_def( + rosidl_generator_cpp::msg::Defaults def( rosidl_generator_cpp::MessageInitialization::DEFAULTS_ONLY); - ASSERT_TRUE(primitives_def.bool_value); - ASSERT_EQ(50, primitives_def.byte_value); - ASSERT_EQ(100, primitives_def.char_value); - ASSERT_EQ(1.125f, primitives_def.float32_value); - ASSERT_EQ(1.125, primitives_def.float64_value); - ASSERT_EQ(-50, primitives_def.int8_value); - ASSERT_EQ(200, primitives_def.uint8_value); - ASSERT_EQ(-1000, primitives_def.int16_value); - ASSERT_EQ(2000, primitives_def.uint16_value); - ASSERT_EQ(-30000L, primitives_def.int32_value); - ASSERT_EQ(60000UL, primitives_def.uint32_value); - ASSERT_EQ(-40000000LL, primitives_def.int64_value); - ASSERT_EQ(50000000ULL, primitives_def.uint64_value); - ASSERT_EQ("bar", primitives_def.string_value); - - char * memory = new char[sizeof(rosidl_generator_cpp::msg::Various)]; - ASSERT_NE(memory, nullptr); - std::memset(memory, 0xfe, sizeof(rosidl_generator_cpp::msg::Various)); - - rosidl_generator_cpp::msg::Various * def = - new(memory) rosidl_generator_cpp::msg::Various( - rosidl_generator_cpp::MessageInitialization::DEFAULTS_ONLY); - - // ensures that the memory gets freed even if an ASSERT is raised - SCOPE_EXIT(def->~Various_(); delete[] memory;); - - ASSERT_EQ(1.125f, def->float32_value); - ASSERT_EQ(2.4, def->float64_value); - ASSERT_EQ(0xfefefefefefefefeULL, def->uint64_value); - ASSERT_EQ("bar", def->string_value); -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - ASSERT_TRUE(std::all_of(def->float32_arr.begin(), def->float32_arr.end(), [](float i) { - uint32_t float32_bit_pattern = *reinterpret_cast(&i); - return 0xfefefefe == float32_bit_pattern; - })); -#ifndef _WIN32 -#pragma GCC diagnostic pop -#endif - - ASSERT_EQ(8.5, def->float64_arr[0]); - ASSERT_EQ(1.2, def->float64_arr[1]); - ASSERT_EQ(3.4, def->float64_arr[2]); - ASSERT_TRUE(std::all_of(def->string_arr.begin(), def->string_arr.end(), [](std::string i) { - return "" == i; - })); - ASSERT_EQ(1.0f, def->unbounded[0]); - ASSERT_EQ(2.0f, def->unbounded[1]); - ASSERT_EQ(0UL, def->bounded_no_def.size()); - ASSERT_EQ(2UL, def->bounded_def.size()); - ASSERT_EQ(3.0f, def->bounded_def[0]); - ASSERT_EQ(4.0f, def->bounded_def[1]); - ASSERT_EQ(0xfefefefe, def->vec3.x); - ASSERT_EQ(45UL, def->vec3.y); - ASSERT_EQ(0xfefefefe, def->vec3.z); - ASSERT_EQ(2UL, def->vec3_fixed.size()); - ASSERT_EQ(45UL, def->vec3_fixed[0].y); - ASSERT_EQ(45UL, def->vec3_fixed[1].y); - ASSERT_EQ(0UL, def->vec3_unbounded.size()); - ASSERT_EQ(0UL, def->vec3_bounded.size()); + ASSERT_TRUE(def.bool_value); + ASSERT_EQ(50, def.byte_value); + ASSERT_EQ(100, def.char_value); + ASSERT_EQ(1.125f, def.float32_value); + ASSERT_EQ(1.125, def.float64_value); + ASSERT_EQ(-50, def.int8_value); + ASSERT_EQ(200, def.uint8_value); + ASSERT_EQ(-1000, def.int16_value); + ASSERT_EQ(2000, def.uint16_value); + ASSERT_EQ(-30000L, def.int32_value); + ASSERT_EQ(60000UL, def.uint32_value); + ASSERT_EQ(-40000000LL, def.int64_value); + ASSERT_EQ(50000000ULL, def.uint64_value); } // This is a test to ensure that when the user passes SKIP to the constructor, // it does no initialization. TEST(Test_msg_initialization, skip_constructor) { - char * memory = new char[sizeof(rosidl_generator_cpp::msg::Various)]; + char * memory = new char[sizeof(rosidl_generator_cpp::msg::BoundedSequences)]; ASSERT_NE(memory, nullptr); - std::memset(memory, 0xfe, sizeof(rosidl_generator_cpp::msg::Various)); + std::memset(memory, 0xfe, sizeof(rosidl_generator_cpp::msg::BoundedSequences)); + rosidl_generator_cpp::msg::BoundedSequences * def = + new(memory) rosidl_generator_cpp::msg::BoundedSequences( + rosidl_generator_cpp::MessageInitialization::SKIP); - rosidl_generator_cpp::msg::Various * def = - new(memory) rosidl_generator_cpp::msg::Various( + char * memory2 = new char[sizeof(rosidl_generator_cpp::msg::Defaults)]; + ASSERT_NE(memory2, nullptr); + std::memset(memory2, 0xfe, sizeof(rosidl_generator_cpp::msg::Defaults)); + rosidl_generator_cpp::msg::Defaults * def2 = + new(memory2) rosidl_generator_cpp::msg::Defaults( rosidl_generator_cpp::MessageInitialization::SKIP); // ensures that the memory gets freed even if an ASSERT is raised - SCOPE_EXIT(def->~Various_(); delete[] memory;); - -#ifndef _WIN32 -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif - uint32_t float32_bit_pattern = *reinterpret_cast(&def->float32_value); + SCOPE_EXIT(def->~BoundedSequences_(); delete[] memory); + SCOPE_EXIT(def2->~Defaults_(); delete[] memory2); + + #ifndef _WIN32 + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" + #endif + uint32_t float32_bit_pattern = + *reinterpret_cast(&def2->float32_value); ASSERT_EQ(0xfefefefe, float32_bit_pattern); - uint64_t float64_bit_pattern = *reinterpret_cast(&def->float64_value); + uint64_t float64_bit_pattern = + *reinterpret_cast(&def2->float64_value); ASSERT_EQ(0xfefefefefefefefeULL, float64_bit_pattern); - ASSERT_TRUE(std::all_of(def->float32_arr.begin(), def->float32_arr.end(), [](float i) { + ASSERT_TRUE(std::all_of(def->float32_values_default.begin(), + def->float32_values_default.end(), [](float i) { uint32_t float32_bit_pattern = *reinterpret_cast(&i); return 0xfefefefe == float32_bit_pattern; })); - ASSERT_TRUE(std::all_of(def->float64_arr.begin(), def->float64_arr.end(), [](double i) { + ASSERT_TRUE(std::all_of(def->float64_values_default.begin(), + def->float64_values_default.end(), [](double i) { uint64_t float64_bit_pattern = *reinterpret_cast(&i); return 0xfefefefefefefefe == float64_bit_pattern; })); -#ifndef _WIN32 -#pragma GCC diagnostic pop -#endif - ASSERT_EQ(0xfefefefefefefefeULL, def->uint64_value); - ASSERT_EQ("", def->string_value); - ASSERT_TRUE(std::all_of(def->string_arr.begin(), def->string_arr.end(), [](std::string i) { + + #ifndef _WIN32 + #pragma GCC diagnostic pop + #endif + ASSERT_EQ(0UL, def->float64_values_default.size()); + ASSERT_EQ(0UL, def->float32_values_default.size()); + ASSERT_EQ(0UL, def->float32_values.size()); + ASSERT_TRUE(std::all_of(def->string_values_default.begin(), + def->string_values_default.end(), [](std::string i) { return "" == i; })); - // std::vector memory doesn't come from the memory we allocated above, but - // instead comes from the allocator. Thus, we don't expect it to be our - // bitpattern for unbounded - ASSERT_EQ(0UL, def->bounded_no_def.size()); - // BoundedVector memory doesn't come from the memory we allocated above, but - // instead comes from the allocator. Thus, we don't expect it to be our - // bitpattern for unbounded - ASSERT_EQ(0UL, def->bounded_def.size()); - ASSERT_EQ(0xfefefefe, def->vec3.x); - ASSERT_EQ(0xfefefefe, def->vec3.y); - ASSERT_EQ(0xfefefefe, def->vec3.z); - ASSERT_EQ(2UL, def->vec3_fixed.size()); - ASSERT_EQ(0UL, def->vec3_unbounded.size()); - ASSERT_EQ(0UL, def->vec3_bounded.size()); } diff --git a/rosidl_generator_cpp/test/test_srv_initialization.cpp b/rosidl_generator_cpp/test/test_srv_initialization.cpp index b3831b0e6..9b160d90b 100644 --- a/rosidl_generator_cpp/test/test_srv_initialization.cpp +++ b/rosidl_generator_cpp/test/test_srv_initialization.cpp @@ -1,4 +1,4 @@ -// Copyright 2017 Open Source Robotics Foundation, Inc. +// Copyright 2019 Open Source Robotics Foundation, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,30 +14,48 @@ #include -#include "rosidl_generator_cpp/srv/complex_type_zero_fill.hpp" +#include "rosidl_generator_cpp/srv/arrays.hpp" +#include "rosidl_generator_cpp/srv/basic_types.hpp" +#include "rosidl_generator_cpp/srv/empty.hpp" TEST(Test_srv_initialization, no_arg_request_constructor) { - rosidl_generator_cpp::srv::ComplexTypeZeroFill::Request def; + rosidl_generator_cpp::srv::Empty::Request empty; - ASSERT_EQ(2UL, def.req.size()); - ASSERT_EQ(0UL, def.req[0].x); - ASSERT_EQ(0UL, def.req[1].x); - ASSERT_EQ(45UL, def.req[0].y); - ASSERT_EQ(45UL, def.req[1].y); - ASSERT_EQ(0UL, def.req[0].z); - ASSERT_EQ(0UL, def.req[1].z); + rosidl_generator_cpp::srv::BasicTypes::Request basic_types; + EXPECT_EQ(false, basic_types.bool_value); + EXPECT_EQ(0, basic_types.byte_value); + EXPECT_EQ(0, basic_types.char_value); + EXPECT_EQ(0.0f, basic_types.float32_value); + EXPECT_EQ(0.0, basic_types.float64_value); + EXPECT_EQ(0, basic_types.int8_value); + EXPECT_EQ(0u, basic_types.uint8_value); + EXPECT_EQ(0, basic_types.int16_value); + EXPECT_EQ(0u, basic_types.uint16_value); + EXPECT_EQ(0, basic_types.int32_value); + EXPECT_EQ(0u, basic_types.uint32_value); + EXPECT_EQ(0, basic_types.int64_value); + EXPECT_EQ(0u, basic_types.uint64_value); + EXPECT_EQ("", basic_types.string_value); } TEST(Test_srv_initialization, no_arg_response_constructor) { - rosidl_generator_cpp::srv::ComplexTypeZeroFill::Response def; + rosidl_generator_cpp::srv::Empty::Request empty; - ASSERT_EQ(2UL, def.reply.size()); - ASSERT_EQ(0UL, def.reply[0].x); - ASSERT_EQ(0UL, def.reply[1].x); - ASSERT_EQ(45UL, def.reply[0].y); - ASSERT_EQ(45UL, def.reply[1].y); - ASSERT_EQ(0UL, def.reply[0].z); - ASSERT_EQ(0UL, def.reply[1].z); + rosidl_generator_cpp::srv::BasicTypes::Response basic_types; + EXPECT_EQ(false, basic_types.bool_value); + EXPECT_EQ(0, basic_types.byte_value); + EXPECT_EQ(0, basic_types.char_value); + EXPECT_EQ(0.0f, basic_types.float32_value); + EXPECT_EQ(0.0, basic_types.float64_value); + EXPECT_EQ(0, basic_types.int8_value); + EXPECT_EQ(0u, basic_types.uint8_value); + EXPECT_EQ(0, basic_types.int16_value); + EXPECT_EQ(0u, basic_types.uint16_value); + EXPECT_EQ(0, basic_types.int32_value); + EXPECT_EQ(0u, basic_types.uint32_value); + EXPECT_EQ(0, basic_types.int64_value); + EXPECT_EQ(0u, basic_types.uint64_value); + EXPECT_EQ("", basic_types.string_value); } // Note that we very specifically don't add tests for some of the other