diff --git a/proto-test/CMakeLists.txt b/proto-test/CMakeLists.txt deleted file mode 100644 index 1d8a5e4..0000000 --- a/proto-test/CMakeLists.txt +++ /dev/null @@ -1,147 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -project(proto_test) - -# Default to C++17 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) - set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic) -endif() -if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND MSVC) - # /bigobj is needed to avoid error C1128: - # https://msdn.microsoft.com/en-us/library/8578y171.aspx - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") -endif() - -option(SKIP_SINGLE_RMW_TESTS - "Skip tests involving only a single RMW implementation" OFF) -option(SKIP_MULTI_RMW_TESTS - "Skip tests involving only multiple RMW implementations" OFF) - -find_package(ament_cmake_auto REQUIRED) -ament_auto_find_build_dependencies() - -if(BUILD_TESTING) - find_package(ament_cmake REQUIRED) - find_package(osrf_testing_tools_cpp REQUIRED) - find_package(rcpputils REQUIRED) - find_package(rcl REQUIRED) - find_package(rclcpp REQUIRED) - find_package(test_msgs REQUIRED) - - - include_directories(include) - - ament_index_get_resource(interface_files "rosidl_interfaces" "test_msgs") - string(REPLACE "\n" ";" interface_files "${interface_files}") - - - set(message_files "") - set(service_files "") - set(action_files "") - foreach(interface_file ${interface_files}) - get_filename_component(interface_ns "${interface_file}" DIRECTORY) - get_filename_component(interface_ns "${interface_ns}" NAME) - string_ends_with("${interface_file}" ".msg" is_message) - if(is_message AND interface_ns STREQUAL "msg") - list(APPEND message_files "${interface_file}") - continue() - endif() - string_ends_with("${interface_file}" ".srv" is_service) - if(is_service AND interface_ns STREQUAL "srv") - list(APPEND service_files "${interface_file}") - continue() - endif() - string_ends_with("${interface_file}" ".idl" is_action) - if(is_action AND interface_ns STREQUAL "action") - list(APPEND action_files "${interface_file}") - continue() - endif() - endforeach() - - find_package(ament_lint_auto REQUIRED) - ament_lint_auto_find_test_dependencies() - - # # Provides PYTHON_EXECUTABLE_DEBUG - # find_package(python_cmake_module REQUIRED) - # find_package(PythonExtra REQUIRED) - - # get the rmw implementations ahead of time - find_package(rmw_implementation_cmake REQUIRED) - get_available_rmw_implementations(rmw_implementations2) - foreach(rmw_implementation ${rmw_implementations2}) - find_package("${rmw_implementation}" REQUIRED) - endforeach() - - function(custom_test target with_message_argument) - if(with_message_argument) - # adding test for each message type - foreach(message_file ${message_files}) - get_filename_component(TEST_MESSAGE_TYPE "${message_file}" NAME_WE) - ament_add_test( - "${target}${target_suffix}__${TEST_MESSAGE_TYPE}" - COMMAND "$" "${TEST_MESSAGE_TYPE}" - TIMEOUT 15 - GENERATE_RESULT_FOR_RETURN_CODE_ZERO - APPEND_LIBRARY_DIRS "${append_library_dirs}") - set_tests_properties( - "${target}${target_suffix}__${TEST_MESSAGE_TYPE}" - PROPERTIES REQUIRED_FILES "$" - ) - endforeach() - else() - ament_add_test( - "${target}${target_suffix}" - COMMAND "$" - TIMEOUT 15 - GENERATE_RESULT_FOR_RETURN_CODE_ZERO - APPEND_LIBRARY_DIRS "${append_library_dirs}") - set_tests_properties( - "${target}${target_suffix}" - PROPERTIES REQUIRED_FILES "$" - ) - endif() - endfunction() - - function(custom_executable target) - add_executable(${target} ${ARGN}) - ament_target_dependencies(${target} - "rclcpp" - "rclcpp_action" - "test_msgs" - ) - endfunction() - - add_library(subscribe_types STATIC - "test/subscribe_array_types.cpp" - "test/subscribe_basic_types.cpp" - "test/subscribe_string_types.cpp") - ament_target_dependencies(subscribe_types - "rclcpp" - "test_msgs") - - # publisher combined with a subscriber - custom_executable(test_proto_typeadapt_cpp - "test/test_proto_typeadapt.cpp") - target_link_libraries(test_proto_typeadapt_cpp subscribe_types rcpputils::rcpputils) - - - set(append_library_dirs "${CMAKE_CURRENT_BINARY_DIR}") - if(WIN32) - set(append_library_dirs "${append_library_dirs}/$") - endif() - - # finding gtest once in the highest scope - # prevents finding it repeatedly in each local scope - ament_find_gtest() - - custom_test(test_proto_typeadapt_cpp TRUE) - -endif() # BUILD_TESTING - - - -ament_auto_package() \ No newline at end of file diff --git a/proto-test/include/proto_test/typeadapt_message_fixtures.hpp b/proto-test/include/proto_test/typeadapt_message_fixtures.hpp deleted file mode 100644 index 921038b..0000000 --- a/proto-test/include/proto_test/typeadapt_message_fixtures.hpp +++ /dev/null @@ -1,705 +0,0 @@ -#ifndef TYPEADAPT_MSGS__MESSAGE_FIXTURES_HPP_ -#define TYPEADAPT_MSGS__MESSAGE_FIXTURES_HPP_ - -#include -#include -#include -#include -#include -#include - -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/arrays__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/basic_types__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/bounded_plain_sequences__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/bounded_sequences__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/builtins__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/constants__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/defaults__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/empty__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/multi_nested__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/nested__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/strings__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/unbounded_sequences__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/w_strings__typeadapter_protobuf_cpp.hpp" - -// static inline std::string -// from_u8string(const std::string & s) -// { -// return s; -// } - -// static inline std::string -// from_u8string(std::string && s) -// { -// return std::move(s); -// } - -// #if defined(__cpp_lib_char8_t) -// static inline std::string -// from_u8string(const std::u8string & s) -// { -// return std::string(s.begin(), s.end()); -// } -// #endif - -typedef std::shared_ptr EmptySharedPtr; -typedef std::shared_ptr BasicTypesSharedPtr; -typedef std::shared_ptr ConstantsSharedPtr; -typedef std::shared_ptr DefaultsSharedPtr; -typedef std::shared_ptr StringsSharedPtr; -typedef std::shared_ptr ArraysSharedPtr; -typedef std::shared_ptr UnboundedSequencesSharedPtr; -typedef std::shared_ptr BoundedPlainSequencesSharedPtr; -typedef std::shared_ptr BoundedSequencesSharedPtr; -typedef std::shared_ptr MultiNestedSharedPtr; -typedef std::shared_ptr NestedSharedPtr; -typedef std::shared_ptr BuiltinsSharedPtr; -typedef std::shared_ptr WStringsSharedPtr; - -static inline std::vector -get_proto_messages_empty() -{ - std::vector messages; - auto msg = std::make_shared(); - messages.push_back(msg); - return messages; -} - -static inline std::vector -get_proto_messages_basic_types() -{ - std::vector messages; - // { - // auto msg = std::make_shared(); - // msg->set_bool_value(false); - // msg->set_byte_value(0); - // msg->set_char_value(0); - // msg->set_float32_value(0.0f); - // msg->set_float64_value(0); - // msg->set_int8_value(0); - // msg->set_uint8_value(0); - // msg->set_int16_value(0); - // msg->set_uint16_value(0); - // msg->set_int32_value(0); - // msg->set_uint32_value(0); - // msg->set_int64_value(0); - // msg->set_uint64_value(0); - // messages.push_back(msg); - // } - { - auto msg = std::make_shared(); - msg->set_bool_value(true); - msg->set_byte_value(255); - msg->set_char_value(255); - msg->set_float32_value(1.125f); - msg->set_float64_value(1.125); - msg->set_int8_value(std::numeric_limits::max()); - msg->set_uint8_value(std::numeric_limits::max()); - msg->set_int16_value(std::numeric_limits::max()); - msg->set_uint16_value(std::numeric_limits::max()); - msg->set_int32_value(std::numeric_limits::max()); - msg->set_uint32_value(std::numeric_limits::max()); - msg->set_int64_value(std::numeric_limits::max()); - msg->set_uint64_value(std::numeric_limits::max()); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->set_bool_value(false); - msg->set_byte_value(0); - msg->set_char_value(0); - msg->set_float32_value(-2.125f); - msg->set_float64_value(-2.125); - msg->set_int8_value(std::numeric_limits::min()); - msg->set_uint8_value(0); - msg->set_int16_value(std::numeric_limits::min()); - msg->set_uint16_value(0); - msg->set_int32_value(std::numeric_limits::min()); - msg->set_uint32_value(0); - msg->set_int64_value(std::numeric_limits::min()); - msg->set_uint64_value(0); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->set_bool_value(true); - msg->set_byte_value(1); - msg->set_char_value(1); - msg->set_float32_value(1.0f); - msg->set_float64_value(1); - msg->set_int8_value(1); - msg->set_uint8_value(1); - msg->set_int16_value(1); - msg->set_uint16_value(1); - msg->set_int32_value(1); - msg->set_uint32_value(1); - msg->set_int64_value(1); - msg->set_uint64_value(1); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_constants() -{ - std::vector messages; - { - auto msg = std::make_shared(); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_defaults() -{ - std::vector messages; - { - auto msg = std::make_shared(); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_strings() -{ - std::vector messages; - { - auto msg = std::make_shared(); - msg->set_string_value(""); - msg->set_bounded_string_value(""); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->set_string_value("Hello world!"); - msg->set_bounded_string_value("Hello world!"); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->set_string_value(from_u8string(u8"Hell\u00F6 W\u00F6rld!")); // using umlaut - msg->set_bounded_string_value(from_u8string(u8"Hell\u00F6 W\u00F6rld!")); // using umlaut - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->set_string_value(""); - msg->set_bounded_string_value(""); - for (size_t i = 0; i < 20000; ++i) { - msg->set_string_value( msg->string_value() + std::to_string(i % 10)); - } - for (size_t i = 0; i < 22; ++i) { - msg->set_bounded_string_value(msg->bounded_string_value() + std::to_string(i % 10)); - } - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_arrays() -{ - auto basic_types_msgs = get_proto_messages_basic_types(); - std::vector messages; - { - auto msg = std::make_shared(); - - msg->add_bool_values(false); - msg->add_bool_values(true); - msg->add_bool_values(false); - - std::string values("000"); - values[0] = 0; - values[1] = 255; - values[2] = 0; - msg->set_byte_values(values); - - values[0] = 0; - values[1] = 255; - values[2] = 0; - msg->set_char_values(values); - - msg->add_float32_values(0.0f); - msg->add_float32_values(1.125f); - msg->add_float32_values(-2.125f); - - msg->add_float64_values(0); - msg->add_float64_values(1.125); - msg->add_float64_values(-2.125); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - values[2] = std::numeric_limits::min(); - msg->set_int8_values(values); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - values[2] = 0; - msg->set_uint8_values(values); - - msg->add_int16_values(0); - msg->add_int16_values(std::numeric_limits::max()); - msg->add_int16_values(std::numeric_limits::min()); - - msg->add_uint16_values(0); - msg->add_uint16_values(std::numeric_limits::max()); - msg->add_uint16_values(0); - - msg->add_int32_values(static_cast(0)); - msg->add_int32_values(std::numeric_limits::max()); - msg->add_int32_values(std::numeric_limits::min()); - - msg->add_uint32_values(0); - msg->add_uint32_values(std::numeric_limits::max()); - msg->add_uint32_values(0); - - msg->add_int64_values(0); - msg->add_int64_values(std::numeric_limits::max()); - msg->add_int64_values(std::numeric_limits::min()); - - msg->add_uint64_values(0); - msg->add_uint64_values(std::numeric_limits::max()); - msg->add_uint64_values(0); - - msg->add_string_values(""); - msg->add_string_values("max value"); - msg->add_string_values("min value"); - - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[0]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[1]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[2]); - - - - messages.push_back(msg); - - - } - return messages; -} - -static inline std::vector -get_proto_messages_unbounded_sequences() -{ - auto basic_types_msgs = get_proto_messages_basic_types(); - std::vector messages; - { - auto msg = std::make_shared(); - msg->add_bool_values(true); - msg->set_byte_values(std::string(1, 0xff)); - msg->set_char_values(std::string(1,255)); - msg->add_float32_values(1.125f); - msg->add_float64_values(1.125); - msg->set_int8_values(std::string(1,std::numeric_limits::max())); - msg->set_uint8_values(std::string(1,std::numeric_limits::max())); - msg->add_int16_values(std::numeric_limits::max()); - msg->add_uint16_values(std::numeric_limits::max()); - msg->add_int32_values(std::numeric_limits::max()); - msg->add_uint32_values(std::numeric_limits::max()); - msg->add_int64_values(std::numeric_limits::max()); - msg->add_uint64_values(std::numeric_limits::max()); - msg->add_string_values("max value"); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[0]); - msg->set_alignment_check(1); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - msg->add_bool_values(false); - msg->add_bool_values(true); - - std::string values; - values[0] = 0; - values[1] = 0xff; - msg->set_byte_values(values); - - values[0] = 0; - values[1] = 255; - msg->set_char_values(values); - - msg->add_float32_values(0.0f); - msg->add_float32_values(1.125f); - msg->add_float32_values(-2.125f); - - msg->add_float64_values(0); - msg->add_float64_values(1.125); - msg->add_float64_values(-2.125); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - values[2] = std::numeric_limits::min(); - msg->set_int8_values(values); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - msg->set_uint8_values(values); - - msg->add_int16_values(0); - msg->add_int16_values(std::numeric_limits::max()); - msg->add_int16_values(std::numeric_limits::min()); - - msg->add_uint16_values(0); - msg->add_uint16_values(std::numeric_limits::max()); - - // The narrowing static cast is required to avoid build errors on Windows. - msg->add_int32_values(static_cast(0)); - msg->add_int32_values(std::numeric_limits::max()); - msg->add_int32_values(std::numeric_limits::min()); - - msg->add_uint32_values(0); - msg->add_uint32_values(std::numeric_limits::max()); - - msg->add_int64_values(0); - msg->add_int64_values(std::numeric_limits::max()); - msg->add_int64_values(std::numeric_limits::min()); - - msg->add_uint64_values(0); - msg->add_uint64_values(std::numeric_limits::max()); - - msg->add_string_values(""); - msg->add_string_values("max value"); - msg->add_string_values("optional min value"); - - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[0]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[1]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[2]); - msg->set_alignment_check(2); - messages.push_back(msg); - } - // { - // auto msg = std::make_shared(); - // // check sequences with more then 100 elements - // const size_t size = 1000; - // msg->set_bool_values.resize(size); - // msg->set_byte_values.resize(size); - // msg->set_char_values.resize(size); - // msg->set_float32_values.resize(size); - // msg->add_float64_values.resize(size); - // msg->set_int8_values.resize(size); - // msg->set_uint8_values.resize(size); - // msg->set_int16_values.resize(size); - // msg->set_uint16_values.resize(size); - // msg->set_int32_values.resize(size); - // msg->set_uint32_values.resize(size); - // msg->set_int64_values.resize(size); - // msg->set_uint64_values.resize(size); - // msg->set_string_values.resize(size); - // msg->set_basic_types_values.resize(size); - // for (size_t i = 0; i < size; ++i) { - // msg->set_bool_values[i] = (i % 2 != 0) ? true : false; - // msg->set_byte_values[i] = static_cast(i); - // msg->set_char_values[i] = static_cast(i % (1 << 8)); - // msg->set_float32_values[i] = 1.125f * i; - // msg->add_float64_values[i] = 1.125 * i; - // msg->set_int8_values[i] = static_cast(i); - // msg->set_uint8_values[i] = static_cast(i); - // msg->set_int16_values[i] = static_cast(i); - // msg->set_uint16_values[i] = static_cast(i); - // msg->set_int32_values[i] = static_cast(i); - // msg->set_uint32_values[i] = static_cast(i); - // msg->set_int64_values[i] = i; - // msg->set_uint64_values[i] = i; - // msg->set_string_values[i] = std::to_string(i); - // msg->set_basic_types_values[i] = *basic_types_msgs[i % basic_types_msgs.size()]; - // } - // msg->set_alignment_check = 3; - // messages.push_back(msg); - // } - { - auto msg = std::make_shared(); - // check default sequences - msg->set_alignment_check(4); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_bounded_plain_sequences() -{ - auto basic_types_msgs = get_proto_messages_basic_types(); - auto msg = std::make_shared(); - std::vector messages; - { - auto msg = std::make_shared(); - msg->add_bool_values(false); - msg->add_bool_values(true); - msg->add_bool_values(false); - - std::string values; - values[0] = 0; - values[1] = 1; - values[2] = 0xff; - msg->set_byte_values(values); - - values[0] = 0; - values[1] = 1; - values[2] = 255; - msg->set_char_values(values); - - msg->add_float32_values(0.0f); - msg->add_float32_values(1.125f); - msg->add_float32_values(-2.125f); - - msg->add_float64_values(0); - msg->add_float64_values(1.125); - msg->add_float64_values(-2.125); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - values[2] = std::numeric_limits::min(); - msg->set_int8_values(values); - - values[0] = 0; - values[1] = 1; - values[2] = std::numeric_limits::min(); - msg->set_uint8_values(values); - - msg->add_int16_values(0); - msg->add_int16_values(std::numeric_limits::max()); - msg->add_int16_values(std::numeric_limits::min()); - - msg->add_uint16_values(0); - msg->add_uint16_values(1); - msg->add_uint16_values(std::numeric_limits::max()); - - // The narrowing static cast is required to avoid build errors on Windows. - msg->add_int32_values(static_cast(0)); - msg->add_int32_values(std::numeric_limits::max()); - msg->add_int32_values(std::numeric_limits::min()); - - msg->add_uint32_values(0); - msg->add_uint32_values(1); - msg->add_uint32_values(std::numeric_limits::max()); - - msg->add_int64_values(0); - msg->add_int64_values(std::numeric_limits::max()); - msg->add_int64_values(std::numeric_limits::min()); - - msg->add_uint64_values(0); - msg->add_uint64_values(1); - msg->add_uint64_values(std::numeric_limits::max()); - - msg->add_basic_types_values()->CopyFrom (*basic_types_msgs[0]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[1]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[2]); - msg->set_alignment_check(2); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - // check default sequences - msg->set_alignment_check(4); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_bounded_sequences() -{ - auto basic_types_msgs = get_proto_messages_basic_types(); - auto msg = std::make_shared(); - std::vector messages; - { - auto msg = std::make_shared(); - msg->add_bool_values(false); - msg->add_bool_values(true); - msg->add_bool_values(false); - - std::string values; - values[0] = 0; - values[1] = 1; - values[2] = 0xff; - msg->set_byte_values(values); - - values[0] = 0; - values[1] = 1; - values[2] = 255; - msg->set_char_values(values); - - msg->add_float32_values(0.0f); - msg->add_float32_values(1.125f); - msg->add_float32_values(-2.125f); - - msg->add_float64_values(0); - msg->add_float64_values(1.125); - msg->add_float64_values(-2.125); - - values[0] = 0; - values[1] = std::numeric_limits::max(); - values[2] = std::numeric_limits::min(); - msg->set_int8_values(values); - - values[0] = 0; - values[1] = 1; - values[2] = std::numeric_limits::min(); - msg->set_uint8_values(values); - - msg->add_int16_values(0); - msg->add_int16_values(std::numeric_limits::max()); - msg->add_int16_values(std::numeric_limits::min()); - - msg->add_uint16_values(0); - msg->add_uint16_values(1); - msg->add_uint16_values(std::numeric_limits::max()); - - // The narrowing static cast is required to avoid build errors on Windows. - msg->add_int32_values(static_cast(0)); - msg->add_int32_values(std::numeric_limits::max()); - msg->add_int32_values(std::numeric_limits::min()); - - msg->add_uint32_values(0); - msg->add_uint32_values(1); - msg->add_uint32_values(std::numeric_limits::max()); - - msg->add_int64_values(0); - msg->add_int64_values(std::numeric_limits::max()); - msg->add_int64_values(std::numeric_limits::min()); - - msg->add_uint64_values(0); - msg->add_uint64_values(1); - msg->add_uint64_values(std::numeric_limits::max()); - - msg->add_basic_types_values()->CopyFrom (*basic_types_msgs[0]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[1]); - msg->add_basic_types_values()->CopyFrom(*basic_types_msgs[2]); - msg->set_alignment_check(2); - messages.push_back(msg); - } - { - auto msg = std::make_shared(); - // check default sequences - msg->set_alignment_check(4); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_multi_nested() -{ - auto arrays_msgs = get_proto_messages_arrays(); - auto bounded_sequences_msgs = get_proto_messages_bounded_sequences(); - auto unbounded_sequences_msgs = get_proto_messages_unbounded_sequences(); - const std::size_t num_arrays = arrays_msgs.size(); - const std::size_t num_bounded_sequences = bounded_sequences_msgs.size(); - const std::size_t num_unbounded_sequences = unbounded_sequences_msgs.size(); - std::vector messages; - { - auto msg = std::make_shared(); - for (std::size_t i = 0u; i < msg->array_of_arrays_size(); ++i) { - msg->mutable_array_of_arrays(i)->CopyFrom(*arrays_msgs[i % num_arrays]); - } - for (std::size_t i = 0u; i < msg->array_of_bounded_sequences_size(); ++i) { - msg->mutable_array_of_bounded_sequences(i)->CopyFrom(*bounded_sequences_msgs[i % num_bounded_sequences]); - } - for (std::size_t i = 0u; i < msg->array_of_unbounded_sequences_size(); ++i) { - msg->mutable_array_of_unbounded_sequences(i)->CopyFrom(*unbounded_sequences_msgs[i % num_unbounded_sequences]); - } - const std::size_t sequence_size = 3u; - // msg->set_bounded_sequence_of_arrays.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_bounded_sequence_of_arrays()->CopyFrom(*arrays_msgs[i % num_arrays]); - } - // msg->set_bounded_sequence_of_bounded_sequences.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_bounded_sequence_of_bounded_sequences()->CopyFrom( - *bounded_sequences_msgs[i % num_bounded_sequences]); - } - // msg->set_bounded_sequence_of_unbounded_sequences.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_bounded_sequence_of_unbounded_sequences()->CopyFrom( - *unbounded_sequences_msgs[i % num_unbounded_sequences]); - } - // msg->set_unbounded_sequence_of_arrays.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_unbounded_sequence_of_arrays()->CopyFrom(*arrays_msgs[i % num_arrays]); - } - // msg->set_unbounded_sequence_of_bounded_sequences.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_unbounded_sequence_of_bounded_sequences()->CopyFrom( - *bounded_sequences_msgs[i % num_bounded_sequences]); - } - // msg->set_unbounded_sequence_of_unbounded_sequences.resize(sequence_size); - for (std::size_t i = 0u; i < sequence_size; ++i) { - msg->add_unbounded_sequence_of_unbounded_sequences()->CopyFrom( - *unbounded_sequences_msgs[i % num_unbounded_sequences]); - } - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_nested() -{ - std::vector messages; - auto basic_types_msgs = get_proto_messages_basic_types(); - for (auto basic_types_msg : basic_types_msgs) { - auto msg = std::make_shared(); - msg->mutable_basic_types_value()->CopyFrom(*basic_types_msg); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_builtins() -{ - std::vector messages; - { - auto msg = std::make_shared(); - msg->mutable_duration_value()->set_sec(-1234567890); - msg->mutable_duration_value()->set_nanosec(123456789); - msg->mutable_time_value()->set_sec(-1234567890); - msg->mutable_time_value()->set_nanosec(987654321); - messages.push_back(msg); - } - return messages; -} - -static inline std::vector -get_proto_messages_wstrings() -{ - std::vector messages; - { - auto msg = std::make_shared(); - // msg->set_wstring_value(u""); - // msg->set_array_of_wstrings(0, u"1"); - // msg->set_array_of_wstrings[1] = u"two"; - // msg->set_array_of_wstrings[2] = u"三"; // "One" in Japanese - // msg->set_bounded_sequence_of_wstrings.resize(2); - // msg->set_bounded_sequence_of_wstrings[0] = u"one"; - // msg->set_bounded_sequence_of_wstrings[1] = u"二"; // "Two" in Japanese - // msg->set_unbounded_sequence_of_wstrings.resize(4); - // msg->set_unbounded_sequence_of_wstrings[0] = u"."; - // msg->set_unbounded_sequence_of_wstrings[1] = u".."; - // msg->set_unbounded_sequence_of_wstrings[2] = u"..."; - // msg->set_unbounded_sequence_of_wstrings[3] = u"四"; // "Four" in Japanese - // messages.push_back(msg); - } - // { - // auto msg = std::make_shared(); - // msg->set_wstring_value(u"ascii"; - // messages.push_back(msg); - // } - // { - // auto msg = std::make_shared(); - // msg->set_wstring_value(u"Hell\u00F6 W\u00F6rld!"; // using umlaut - // messages.push_back(msg); - // } - // { - // auto msg = std::make_shared(); - // msg->set_wstring_value(u"ハローワールド"; // "Hello world" in Japanese - // messages.push_back(msg); - // } - return messages; -} - -#endif // TYPEADAPT_MSGS__MESSAGE_FIXTURES_HPP_ diff --git a/proto-test/package.xml b/proto-test/package.xml deleted file mode 100644 index 85ff3dc..0000000 --- a/proto-test/package.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - proto_test - 0.19.1 - Protobuff type adapter test - - Gonzalo de Pedro - - Apache License 2.0 - - Gonzalo de Pedro - - rosidl_default_generators - - ament_cmake_auto - - rosidl_default_runtime - - - ament_cmake - ament_cmake_gtest - ament_lint_auto - ament_lint_common - launch - launch_testing - launch_testing_ament_cmake - osrf_testing_tools_cpp - rcl - rclcpp - rclcpp_action - rclpy - rcpputils - rmw_implementation - rmw_implementation_cmake - ros2cli - test_msgs - - - - ament_cmake - - \ No newline at end of file diff --git a/proto-test/test/subscribe_array_types.cpp b/proto-test/test/subscribe_array_types.cpp deleted file mode 100644 index 2bdfc9a..0000000 --- a/proto-test/test/subscribe_array_types.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "rclcpp/rclcpp.hpp" - -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/arrays__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/bounded_plain_sequences__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/bounded_sequences__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/multi_nested__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/nested__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/unbounded_sequences__typeadapter_protobuf_cpp.hpp" - - -#include "subscribe_array_types.hpp" -#include "subscribe_helper.hpp" - -rclcpp::SubscriptionBase::SharedPtr subscribe_arrays( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_unbounded_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_bounded_plain_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_bounded_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_multi_nested( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_nested( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} diff --git a/proto-test/test/subscribe_array_types.hpp b/proto-test/test/subscribe_array_types.hpp deleted file mode 100644 index e64f0aa..0000000 --- a/proto-test/test/subscribe_array_types.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SUBSCRIBE_ARRAY_TYPES_HPP_ -#define SUBSCRIBE_ARRAY_TYPES_HPP_ - -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/Arrays.pb.h" -#include "test_msgs/msg/UnboundedSequences.pb.h" -#include "test_msgs/msg/BoundedPlainSequences.pb.h" -#include "test_msgs/msg/BoundedSequences.pb.h" -#include "test_msgs/msg/MultiNested.pb.h" -#include "test_msgs/msg/Nested.pb.h" - -rclcpp::SubscriptionBase::SharedPtr subscribe_arrays( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_unbounded_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_bounded_plain_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_bounded_sequences( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_multi_nested( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_nested( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -#endif // SUBSCRIBE_ARRAY_TYPES_HPP_ diff --git a/proto-test/test/subscribe_basic_types.cpp b/proto-test/test/subscribe_basic_types.cpp deleted file mode 100644 index 6bf5cf3..0000000 --- a/proto-test/test/subscribe_basic_types.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "rclcpp/rclcpp.hpp" - -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/basic_types__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/builtins__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/constants__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/defaults__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/empty__typeadapter_protobuf_cpp.hpp" - -#include "subscribe_basic_types.hpp" -#include "subscribe_helper.hpp" - -rclcpp::SubscriptionBase::SharedPtr subscribe_empty( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages) -{ - return subscribe(node, message_type, messages_expected, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_basic_types( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages) -{ - return subscribe( - node, message_type, messages_expected, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_builtins( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages) -{ - return subscribe( - node, message_type, messages_expected, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_constants( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages) -{ - return subscribe( - node, message_type, messages_expected, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_defaults( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages) -{ - return subscribe( - node, message_type, messages_expected, received_messages); -} diff --git a/proto-test/test/subscribe_basic_types.hpp b/proto-test/test/subscribe_basic_types.hpp deleted file mode 100644 index 7f3f916..0000000 --- a/proto-test/test/subscribe_basic_types.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SUBSCRIBE_BASIC_TYPES_HPP_ -#define SUBSCRIBE_BASIC_TYPES_HPP_ - -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/Arrays.pb.h" -#include "test_msgs/msg/BasicTypes.pb.h" -#include "test_msgs/msg/BoundedPlainSequences.pb.h" -#include "test_msgs/msg/BoundedSequences.pb.h" -#include "test_msgs/msg/Builtins.pb.h" -#include "test_msgs/msg/Constants.pb.h" -#include "test_msgs/msg/Defaults.pb.h" -#include "test_msgs/msg/Empty.pb.h" -#include "test_msgs/msg/MultiNested.pb.h" -#include "test_msgs/msg/Nested.pb.h" -#include "test_msgs/msg/Strings.pb.h" -#include "test_msgs/msg/UnboundedSequences.pb.h" -#include "test_msgs/msg/WStrings.pb.h" - - - -rclcpp::SubscriptionBase::SharedPtr subscribe_empty( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_basic_types( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_builtins( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_constants( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_defaults( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & messages_expected, - std::vector & received_messages); - -#endif // SUBSCRIBE_BASIC_TYPES_HPP_ diff --git a/proto-test/test/subscribe_helper.hpp b/proto-test/test/subscribe_helper.hpp deleted file mode 100644 index 2751689..0000000 --- a/proto-test/test/subscribe_helper.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SUBSCRIBE_HELPER_HPP_ -#define SUBSCRIBE_HELPER_HPP_ - -#include -#include -#include -#include - -#include -#include "rclcpp/rclcpp.hpp" - - -template -rclcpp::SubscriptionBase::SharedPtr subscribe( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector::custom_type>> & expected_messages, - std::vector & received_messages) -{ - received_messages.assign(expected_messages.size(), false); - - auto callback = - [&expected_messages, &received_messages]( - const std::shared_ptr::custom_type> received_message - ) -> void - { - google::protobuf::util::MessageDifferencer mdiff; - mdiff.set_message_field_comparison(google::protobuf::util::MessageDifferencer::MessageFieldComparison::EQUAL); - mdiff.set_scope(google::protobuf::util::MessageDifferencer::Scope::PARTIAL); - - // find received message in vector of expected messages - auto received = received_messages.begin(); - bool known_message = false; - size_t index = 0; - for (auto expected_message : expected_messages) { - - std::cout << "RECEIVED MESSAGE: " << received_message->ByteSize() << std::endl; - std::cout << received_message->DebugString() << std::endl; - - std::cout << "EXPECTED MESSAGE:" << expected_message->ByteSize() << std::endl; - std::cout << expected_message->DebugString() << std::endl; - - - if( !expected_message->ByteSize()) { - if( !received_message->ByteSize() ){ - *received = true; - printf("received message #%zu of %zu\n", index + 1, expected_messages.size()); - known_message = true; - break; - } - } else if (mdiff.Compare(*expected_message, *received_message)) { - *received = true; - printf("received message #%zu of %zu\n", index + 1, expected_messages.size()); - known_message = true; - break; - } - ++received; - ++index; - } - if (!known_message) { - throw std::runtime_error("received message does not match any expected message"); - } - - // shutdown node when all expected messages have been received - for (auto received_msg : received_messages) { - if (!received_msg) { - return; - } - } - rclcpp::shutdown(); - }; - - auto qos = rclcpp::QoS(rclcpp::KeepLast(expected_messages.size())); - - return - node->create_subscription(std::string("test/message/") + message_type, qos, callback); -} - -#endif // SUBSCRIBE_HELPER_HPP_ diff --git a/proto-test/test/subscribe_string_types.cpp b/proto-test/test/subscribe_string_types.cpp deleted file mode 100644 index 4911854..0000000 --- a/proto-test/test/subscribe_string_types.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "rclcpp/rclcpp.hpp" - -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/strings__typeadapter_protobuf_cpp.hpp" -#include "test_msgs/msg/w_strings__typeadapter_protobuf_cpp.hpp" - - -#include "subscribe_helper.hpp" -#include "subscribe_string_types.hpp" - -rclcpp::SubscriptionBase::SharedPtr subscribe_strings( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} - -rclcpp::SubscriptionBase::SharedPtr subscribe_wstrings( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages) -{ - return subscribe( - node, message_type, expected_messages, received_messages); -} diff --git a/proto-test/test/subscribe_string_types.hpp b/proto-test/test/subscribe_string_types.hpp deleted file mode 100644 index 66a0709..0000000 --- a/proto-test/test/subscribe_string_types.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2015 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SUBSCRIBE_STRING_TYPES_HPP_ -#define SUBSCRIBE_STRING_TYPES_HPP_ - -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "test_msgs/rosidl_adapter_proto__visibility_control.h" -#include "builtin_interfaces/rosidl_adapter_proto__visibility_control.h" -#include "test_msgs/msg/Strings.pb.h" -#include "test_msgs/msg/WStrings.pb.h" - - - -rclcpp::SubscriptionBase::SharedPtr subscribe_strings( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -rclcpp::SubscriptionBase::SharedPtr subscribe_wstrings( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - const std::vector> & expected_messages, - std::vector & received_messages); - -#endif // SUBSCRIBE_STRING_TYPES_HPP_ diff --git a/proto-test/test/test_proto_typeadapt.cpp b/proto-test/test/test_proto_typeadapt.cpp deleted file mode 100644 index 5390706..0000000 --- a/proto-test/test/test_proto_typeadapt.cpp +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2021 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. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include - -#include "rclcpp/rclcpp.hpp" - -#include "rcpputils/scope_exit.hpp" - -#include "test_msgs/message_fixtures.hpp" -#include "proto_test/typeadapt_message_fixtures.hpp" - -#include "subscribe_array_types.hpp" -#include "subscribe_basic_types.hpp" -#include "subscribe_string_types.hpp" - -template -void publish( - rclcpp::Node::SharedPtr node, - const std::string & message_type, - std::vector::custom_type>> messages, - size_t number_of_cycles = 100) -{ - auto qos = rclcpp::QoS(rclcpp::KeepLast(messages.size())); - - auto publisher = node->create_publisher>(std::string("test/message/") + message_type, qos); - - try { - rclcpp::WallRate cycle_rate(10); - rclcpp::WallRate message_rate(100); - size_t cycle_index = 0; - // publish all messages up to number_of_cycles times, longer sleep between each cycle - while (rclcpp::ok() && cycle_index < number_of_cycles) { - size_t message_index = 0; - // publish all messages one by one, shorter sleep between each message - while (rclcpp::ok() && message_index < messages.size()) { - printf("publishing message #%zu\n", message_index + 1); - publisher->publish(*messages[message_index]); - ++message_index; - message_rate.sleep(); - } - ++cycle_index; - cycle_rate.sleep(); - } - } catch (const std::exception & ex) { - // It is expected to get into invalid context during the sleep, since rclcpp::shutdown() - // might be called earlier (e.g. by subscribe() routine or when running *AfterShutdown case) - if (ex.what() != std::string("context cannot be slept with because it's invalid")) { - printf("ERROR: got unexpected exception: %s\n", ex.what()); - throw ex; - } - } -} - -int main(int argc, char ** argv) -{ - rclcpp::init(argc, argv); - RCPPUTILS_SCOPE_EXIT( - { - rclcpp::shutdown(); - }); - if (argc != 2) { - fprintf(stderr, "Wrong number of arguments, pass one message type\n"); - return 1; - } - - auto start = std::chrono::steady_clock::now(); - - std::string message = argv[1]; - auto node = rclcpp::Node::make_shared(std::string("test_publisher_subscriber_") + message); - - rclcpp::SubscriptionBase::SharedPtr subscriber; - std::vector received_messages; // collect flags about received messages - - auto messages_empty = get_proto_messages_empty(); - auto messages_basic_types = get_proto_messages_basic_types(); - auto messages_arrays = get_proto_messages_arrays(); - auto messages_bounded_plain_sequences = get_proto_messages_bounded_plain_sequences(); - auto messages_bounded_sequences = get_proto_messages_bounded_sequences(); - auto messages_unbounded_sequences = get_proto_messages_unbounded_sequences(); - auto messages_multi_nested = get_proto_messages_multi_nested(); - auto messages_nested = get_proto_messages_nested(); - auto messages_builtins = get_proto_messages_builtins(); - auto messages_constants = get_proto_messages_constants(); - auto messages_defaults = get_proto_messages_defaults(); - auto messages_strings = get_proto_messages_strings(); - auto messages_wstrings = get_proto_messages_wstrings(); - - std::thread spin_thread([node]() { - rclcpp::spin(node); - }); - - - if (message == "Empty") { - subscriber = subscribe_empty(node, message, messages_empty, received_messages); - publish(node, message, messages_empty); - } else if (message == "BasicTypes") { - subscriber = subscribe_basic_types(node, message, messages_basic_types, received_messages); - publish(node, message, messages_basic_types); - } else if (message == "Arrays") { - subscriber = subscribe_arrays(node, message, messages_arrays, received_messages); - publish(node, message, messages_arrays); - } else if (message == "UnboundedSequences") { - subscriber = subscribe_unbounded_sequences( - node, message, messages_unbounded_sequences, received_messages); - publish( - node, message, messages_unbounded_sequences); - } else if (message == "BoundedPlainSequences") { - subscriber = subscribe_bounded_plain_sequences( - node, message, messages_bounded_plain_sequences, received_messages); - publish( - node, message, messages_bounded_plain_sequences); - } else if (message == "BoundedSequences") { - subscriber = subscribe_bounded_sequences( - node, message, messages_bounded_sequences, received_messages); - publish( - node, message, messages_bounded_sequences); - } else if (message == "MultiNested") { - subscriber = subscribe_multi_nested(node, message, messages_multi_nested, received_messages); - publish(node, message, messages_multi_nested); - } else if (message == "Nested") { - subscriber = subscribe_nested(node, message, messages_nested, received_messages); - publish(node, message, messages_nested); - } else if (message == "Builtins") { - subscriber = subscribe_builtins(node, message, messages_builtins, received_messages); - publish(node, message, messages_builtins); - } else if (message == "Constants") { - subscriber = subscribe_constants(node, message, messages_constants, received_messages); - publish(node, message, messages_constants); - } else if (message == "Defaults") { - subscriber = subscribe_defaults(node, message, messages_defaults, received_messages); - publish(node, message, messages_defaults); - } else if (message == "Strings") { - subscriber = subscribe_strings(node, message, messages_strings, received_messages); - publish(node, message, messages_strings); - } else if (message == "WStrings") { - subscriber = subscribe_wstrings(node, message, messages_wstrings, received_messages); - publish(node, message, messages_wstrings); - } else { - fprintf(stderr, "Unknown message argument '%s'\n", message.c_str()); - return 1; - } - - spin_thread.join(); - - auto end = std::chrono::steady_clock::now(); - std::chrono::duration diff = (end - start); - printf("published and subscribed for %f seconds\n", diff.count()); - - for (auto received : received_messages) { - if (!received) { - return 1; - } - } - - return 0; -}