Skip to content

Commit

Permalink
Replace allocation with captured rcutils_strdup
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
  • Loading branch information
Blast545 committed Aug 13, 2020
1 parent 4a7573a commit c4c9fb9
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions rcl/test/rcl/test_rmw_impl_id_check_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,14 @@ TEST(TestRmwCheck, test_mock_rmw_impl_check) {
EXPECT_EQ(NULL, get_env_id_matches_name);
EXPECT_TRUE(rcutils_set_env(RCL_ASSERT_RMW_ID_MATCHES_ENV_VAR_NAME, "some_random_name"));

// Return an allocated string as strdup would do for the first case
// calling the function
rcl_allocator_t allocator = rcl_get_default_allocator();
size_t dummy_str_size = 3u;
char * new_string = static_cast<char *>(allocator.zero_allocate(
dummy_str_size, 1u, allocator.state));

auto mock = mocking_utils::patch(
"lib:rcl", rcutils_strdup, [&new_string](auto...) {
"lib:rcl", rcutils_strdup,
[base = rcutils_strdup](const char * str, auto allocator)
{
static int counter = 1;
if (counter == 1) {
counter++;
return new_string;
return base(str, allocator);
} else {
return static_cast<char *>(NULL);
}
Expand Down

0 comments on commit c4c9fb9

Please sign in to comment.