From 6bed708fb922f57f9987986a527b73c8976f7ba4 Mon Sep 17 00:00:00 2001 From: Jose Tomas Lorente Date: Thu, 24 Sep 2020 13:01:00 -0300 Subject: [PATCH] Add tests take bad arguments (#125) Signed-off-by: lobotuerk --- .../test/test_subscription.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test_rmw_implementation/test/test_subscription.cpp b/test_rmw_implementation/test/test_subscription.cpp index 277ecd1b..96fcbc0e 100644 --- a/test_rmw_implementation/test/test_subscription.cpp +++ b/test_rmw_implementation/test/test_subscription.cpp @@ -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{};