Add in more tests for init_options coverage. (#1353)
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
This commit is contained in:
parent
6238b4263b
commit
8cc331f38c
3 changed files with 38 additions and 2 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -282,7 +282,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)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -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();
|
||||
|
@ -61,3 +64,36 @@ TEST(TestInitOptions, test_initialize_logging) {
|
|||
EXPECT_FALSE(options.auto_initialize_logging());
|
||||
}
|
||||
}
|
||||
|
||||
// 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"));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue