Skip to content

Commit

Permalink
Add tests take bad arguments (#125)
Browse files Browse the repository at this point in the history
Signed-off-by: lobotuerk <jtlorente@ekumenlabs.com>
  • Loading branch information
Lobotuerk authored and ahcorde committed Oct 8, 2020
1 parent a61a8ed commit 6bed708
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test_rmw_implementation/test/test_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,41 @@ TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), count_mismatched_subs
EXPECT_EQ(0u, publisher_count);
}

TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), take_with_bad_args) {
bool taken = false;
test_msgs__msg__BasicTypes output_message{};
output_message.bool_value = true;
output_message.char_value = 'a';
output_message.float32_value = 0.42f;
test_msgs__msg__BasicTypes original_message = output_message;
rmw_subscription_allocation_t * null_allocation{nullptr}; // still valid allocation

rmw_ret_t ret = rmw_take(nullptr, &output_message, &taken, null_allocation);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret) << rmw_get_error_string().str;
EXPECT_EQ(taken, false);
EXPECT_EQ(output_message, original_message);
rmw_reset_error();

ret = rmw_take(sub, nullptr, &taken, null_allocation);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret) << rmw_get_error_string().str;
EXPECT_EQ(taken, false);
rmw_reset_error();

ret = rmw_take(sub, &output_message, nullptr, null_allocation);
EXPECT_EQ(RMW_RET_INVALID_ARGUMENT, ret) << rmw_get_error_string().str;
EXPECT_EQ(output_message, original_message);
rmw_reset_error();

const char * implementation_identifier = sub->implementation_identifier;
sub->implementation_identifier = "not-an-rmw-implementation-identifier";
ret = rmw_take(sub, &output_message, &taken, null_allocation);
EXPECT_EQ(RMW_RET_INCORRECT_RMW_IMPLEMENTATION, ret) << rmw_get_error_string().str;
EXPECT_EQ(taken, false);
EXPECT_EQ(output_message, original_message);
rmw_reset_error();
sub->implementation_identifier = implementation_identifier;
}

TEST_F(CLASSNAME(TestSubscriptionUse, RMW_IMPLEMENTATION), take_with_info_with_bad_args) {
bool taken = false;
test_msgs__msg__BasicTypes output_message{};
Expand Down

0 comments on commit 6bed708

Please sign in to comment.