Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
22 changes: 22 additions & 0 deletions rcl/test/rcl/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,26 @@ TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), nominal) {
TEST_F(CLASSNAME(TestContextFixture, RMW_IMPLEMENTATION), bad_fini) {
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_context_fini(nullptr));
rcl_reset_error();

rcl_init_options_t init_options = rcl_get_zero_initialized_init_options();
rcl_ret_t ret = rcl_init_options_init(&init_options, rcl_get_default_allocator());
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
OSRF_TESTING_TOOLS_CPP_SCOPE_EXIT(
{
EXPECT_EQ(RCL_RET_OK, rcl_init_options_fini(&init_options)) << rcl_get_error_string().str;
});

rcl_context_t context = rcl_get_zero_initialized_context();
ret = rcl_init(0, nullptr, &init_options, &context);
EXPECT_EQ(RCL_RET_OK, ret);

ret = rcl_context_fini(&context);
EXPECT_EQ(ret, RCL_RET_INVALID_ARGUMENT);
rcl_reset_error();

ret = rcl_shutdown(&context);
EXPECT_EQ(ret, RCL_RET_OK);

ret = rcl_context_fini(&context);
EXPECT_EQ(ret, RCL_RET_OK);
}
34 changes: 34 additions & 0 deletions rcl/test/rcl/test_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,40 @@ TEST_P(TestEventFixture, test_pubsub_incompatible_qos)
tear_down_publisher_subscriber();
}

/*
* Passing bad param subscriber/publisher event ini
*/
TEST_P(TestEventFixture, test_bad_event_ini)
{
setup_publisher_subscriber(default_qos_profile, default_qos_profile);
const rcl_subscription_event_type_t unknown_sub_type = (rcl_subscription_event_type_t) 5432;
const rcl_publisher_event_type_t unknown_pub_type = (rcl_publisher_event_type_t) 5432;

publisher_event = rcl_get_zero_initialized_event();
rcl_ret_t ret = rcl_publisher_event_init(
&publisher_event,
&publisher,
unknown_pub_type);
EXPECT_EQ(ret, RCL_RET_INVALID_ARGUMENT);

subscription_event = rcl_get_zero_initialized_event();
ret = rcl_subscription_event_init(
&subscription_event,
&subscription,
unknown_sub_type);
EXPECT_EQ(ret, RCL_RET_INVALID_ARGUMENT);

tear_down_publisher_subscriber();
}

/*
* Passing bad argument to get_rmw_handle
*/
TEST_P(TestEventFixture, test_bad_get_handle)
{
EXPECT_EQ(NULL, rcl_event_get_rmw_handle(nullptr));
}

static
std::array<TestIncompatibleQosEventParams, 5>
get_test_pubsub_incompatible_qos_inputs()
Expand Down
11 changes: 11 additions & 0 deletions rcl/test/rcl/test_guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,14 @@ TEST_F(
EXPECT_EQ(RCL_RET_OK, ret);
rcl_reset_error();
}

/* Tests trigger_guard_condition with bad arguments
*/
TEST_F(
CLASSNAME(TestGuardConditionFixture, RMW_IMPLEMENTATION), test_rcl_guard_condition_bad_arg) {
rcl_guard_condition_t zero_guard_condition = rcl_get_zero_initialized_guard_condition();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_trigger_guard_condition(nullptr));
rcl_reset_error();
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, rcl_trigger_guard_condition(&zero_guard_condition));
rcl_reset_error();
}
41 changes: 41 additions & 0 deletions rcl/test/rcl/test_lexer_lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_accept)
EXPECT_EQ(RCL_LEXEME_EOF, lexeme);
}

TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_accept_bad_arg)
{
rcl_lexer_lookahead2_t buffer;
rcl_lexer_lookahead2_t buffer_not_ini = rcl_get_zero_initialized_lexer_lookahead2();
SCOPE_LOOKAHEAD2(buffer, "foobar/");

rcl_lexeme_t lexeme = RCL_LEXEME_NONE;
const char * lexeme_text;
size_t lexeme_text_length = 0;

// Can't accept without peek first
rcl_ret_t ret = rcl_lexer_lookahead2_accept(&buffer, &lexeme_text, &lexeme_text_length);
EXPECT_EQ(RCL_RET_ERROR, ret) << rcl_get_error_string().str;
rcl_reset_error();

// Expected usage
ret = rcl_lexer_lookahead2_peek(&buffer, &lexeme);
EXPECT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
EXPECT_EQ(RCL_LEXEME_TOKEN, lexeme);

// Invalid nullptr parameter
ret = rcl_lexer_lookahead2_accept(nullptr, &lexeme_text, &lexeme_text_length);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
rcl_reset_error();

// Invalid not ini parameter
ret = rcl_lexer_lookahead2_accept(&buffer_not_ini, &lexeme_text, &lexeme_text_length);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
rcl_reset_error();

// Invalid nullptr as lexeme_text_length
ret = rcl_lexer_lookahead2_accept(&buffer, &lexeme_text, nullptr);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
rcl_reset_error();

// Invalid nullptr as lexeme_text
ret = rcl_lexer_lookahead2_accept(&buffer, nullptr, &lexeme_text_length);
EXPECT_EQ(RCL_RET_INVALID_ARGUMENT, ret) << rcl_get_error_string().str;
rcl_reset_error();
}

TEST_F(CLASSNAME(TestLexerLookaheadFixture, RMW_IMPLEMENTATION), test_expect)
{
rcl_ret_t ret;
Expand Down
18 changes: 18 additions & 0 deletions rcl/test/rcl/test_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,21 @@ TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_bad_arguments) {
&service, this->node_ptr, ts,
topic, &service_options_bad_alloc)) << rcl_get_error_string().str;
}

/* Name failed tests
*/
TEST_F(CLASSNAME(TestServiceFixture, RMW_IMPLEMENTATION), test_service_fail_name) {
const rosidl_service_type_support_t * ts = ROSIDL_GET_SRV_TYPE_SUPPORT(
test_msgs, srv, BasicTypes);
const char * topic = "white space";
rcl_service_t service = rcl_get_zero_initialized_service();
rcl_service_options_t service_options = rcl_service_get_default_options();
rcl_ret_t ret = rcl_service_init(&service, this->node_ptr, ts, topic, &service_options);
EXPECT_EQ(RCL_RET_SERVICE_NAME_INVALID, ret) << rcl_get_error_string().str;
rcl_reset_error();

const char * topic2 = "{invalidbecausecurlybraces}";
ret = rcl_service_init(&service, this->node_ptr, ts, topic2, &service_options);
EXPECT_EQ(RCL_RET_SERVICE_NAME_INVALID, ret) << rcl_get_error_string().str;
rcl_reset_error();
}
5 changes: 5 additions & 0 deletions rcl/test/rcl/test_validate_topic_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ TEST(test_validate_topic_name, various_valid_topics) {
EXPECT_EQ(42u, invalid_index);
EXPECT_STREQ(nullptr, rcl_topic_name_validation_result_string(validation_result));
}

int not_valid_validation_result = 5600;
EXPECT_STREQ(
"unknown result code for rcl topic name validation",
rcl_topic_name_validation_result_string(not_valid_validation_result));
}

TEST(test_validate_topic_name, various_invalid_topics) {
Expand Down