diff --git a/rclcpp/src/rclcpp/init_options.cpp b/rclcpp/src/rclcpp/init_options.cpp index ad2a900b5f..f9fd6f5f60 100644 --- a/rclcpp/src/rclcpp/init_options.cpp +++ b/rclcpp/src/rclcpp/init_options.cpp @@ -44,6 +44,7 @@ InitOptions::InitOptions(const InitOptions & other) : InitOptions(*other.get_rcl_init_options()) { shutdown_on_sigint = other.shutdown_on_sigint; + initialize_logging_ = other.initialize_logging_; } bool @@ -69,6 +70,7 @@ InitOptions::operator=(const InitOptions & other) rclcpp::exceptions::throw_from_rcl_error(ret, "failed to copy rcl init options"); } this->shutdown_on_sigint = other.shutdown_on_sigint; + this->initialize_logging_ = other.initialize_logging_; } return *this; } diff --git a/rclcpp/test/CMakeLists.txt b/rclcpp/test/CMakeLists.txt index 840c5de0e3..e9e70f8063 100644 --- a/rclcpp/test/CMakeLists.txt +++ b/rclcpp/test/CMakeLists.txt @@ -253,6 +253,11 @@ if(TARGET test_node_options) ament_target_dependencies(test_node_options "rcl") target_link_libraries(test_node_options ${PROJECT_NAME}) endif() +ament_add_gtest(test_init_options rclcpp/test_init_options.cpp) +if(TARGET test_init_options) + ament_target_dependencies(test_init_options "rcl") + target_link_libraries(test_init_options ${PROJECT_NAME}) +endif() ament_add_gtest(test_parameter_client rclcpp/test_parameter_client.cpp) if(TARGET test_parameter_client) ament_target_dependencies(test_parameter_client diff --git a/rclcpp/test/rclcpp/test_init_options.cpp b/rclcpp/test/rclcpp/test_init_options.cpp new file mode 100644 index 0000000000..3c0cae739a --- /dev/null +++ b/rclcpp/test/rclcpp/test_init_options.cpp @@ -0,0 +1,63 @@ +// Copyright 2020 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 "rcl/allocator.h" +#include "rcl/domain_id.h" + +#include "rclcpp/init_options.hpp" + + +TEST(TestInitOptions, test_construction) { + rcl_allocator_t allocator = rcl_get_default_allocator(); + auto options = rclcpp::InitOptions(allocator); + const rcl_init_options_t * rcl_options = options.get_rcl_init_options(); + ASSERT_TRUE(rcl_options != nullptr); + ASSERT_TRUE(rcl_options->impl != nullptr); + + { + auto options_copy = rclcpp::InitOptions(options); + const rcl_init_options_t * rcl_options_copy = options_copy.get_rcl_init_options(); + ASSERT_TRUE(rcl_options_copy != nullptr); + ASSERT_TRUE(rcl_options_copy->impl != nullptr); + } + + { + auto options_copy = options; + const rcl_init_options_t * rcl_options_copy = options_copy.get_rcl_init_options(); + ASSERT_TRUE(rcl_options_copy != nullptr); + ASSERT_TRUE(rcl_options_copy->impl != nullptr); + } +} + +TEST(TestInitOptions, test_initialize_logging) { + { + auto options = rclcpp::InitOptions(); + EXPECT_TRUE(options.auto_initialize_logging()); + } + + { + auto options = rclcpp::InitOptions().auto_initialize_logging(true); + EXPECT_TRUE(options.auto_initialize_logging()); + } + + { + auto options = rclcpp::InitOptions().auto_initialize_logging(false); + EXPECT_FALSE(options.auto_initialize_logging()); + } +}