Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rclcpp/src/rclcpp/init_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ InitOptions::InitOptions(rcl_allocator_t allocator)
*init_options_ = rcl_get_zero_initialized_init_options();
rcl_ret_t ret = rcl_init_options_init(init_options_.get(), allocator);
if (RCL_RET_OK != ret) {
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to initialized rcl init options");
rclcpp::exceptions::throw_from_rcl_error(ret, "failed to initialize rcl init options");
}
}

Expand Down
2 changes: 1 addition & 1 deletion rclcpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ 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})
target_link_libraries(test_init_options ${PROJECT_NAME} mimick)
endif()
ament_add_gtest(test_parameter_client rclcpp/test_parameter_client.cpp)
if(TARGET test_parameter_client)
Expand Down
63 changes: 63 additions & 0 deletions rclcpp/test/rclcpp/test_init_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <gtest/gtest.h>

#include <stdexcept>
#include <string>
#include <vector>

Expand All @@ -22,6 +23,8 @@

#include "rclcpp/init_options.hpp"

#include "../mocking_utils/patch.hpp"
#include "../utils/rclcpp_gtest_macros.hpp"

TEST(TestInitOptions, test_construction) {
rcl_allocator_t allocator = rcl_get_default_allocator();
Expand Down Expand Up @@ -75,3 +78,63 @@ TEST(TestInitOptions, test_domain_id) {
options.use_default_domain_id();
EXPECT_EQ(domain_id, options.get_domain_id());
}

// Required for mocking_utils below
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, ==)
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, !=)
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, <)
MOCKING_UTILS_BOOL_OPERATOR_RETURNS_FALSE(rcutils_allocator_t, >)

TEST(TestInitOptions, constructor_rcl_init_options_init_failed) {
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_init_options_init, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
rclcpp::InitOptions(),
std::runtime_error("failed to initialize rcl init options: error not set"));
}

TEST(TestInitOptions, constructor_rcl_init_options_copy_failed) {
rcl_init_options_t rcl_opts;
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_init_options_copy, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
new rclcpp::InitOptions(rcl_opts),
std::runtime_error("failed to copy rcl init options: error not set"));
}

TEST(TestInitOptions, copy_constructor_rcl_init_options_copy_failed) {
rclcpp::InitOptions options;
rclcpp::InitOptions options2;
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_init_options_copy, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
options2.operator=(options),
std::runtime_error("failed to copy rcl init options: error not set"));
}

TEST(TestInitOptions, use_default_domain_id_rcl_get_default_domain_id_failed) {
rclcpp::InitOptions options;
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_get_default_domain_id, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
options.use_default_domain_id(),
std::runtime_error("failed to get default domain id: error not set"));
}

TEST(TestInitOptions, set_domain_id_rcl_init_options_set_domain_id_failed) {
rclcpp::InitOptions options;
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_init_options_set_domain_id, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
options.set_domain_id(0),
std::runtime_error("failed to set domain id to rcl init options: error not set"));
}

TEST(TestInitOptions, get_domain_id_rcl_init_options_get_domain_id_failed) {
rclcpp::InitOptions options;
auto mock = mocking_utils::patch_and_return(
"lib:rclcpp", rcl_init_options_get_domain_id, RCL_RET_ERROR);
RCLCPP_EXPECT_THROW_EQ(
options.get_domain_id(),
std::runtime_error("failed to get domain id from rcl init options: error not set"));
}