Add visibility to rcl_timer_get_allocator (#610)
* Add RCL_PUBLIC to be able of using the function externally * Add fixture to setup timers before testing them * Add test for rcl_timer_get_allocator function * Add minor style changes Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
This commit is contained in:
parent
3142616db4
commit
b714f41aca
2 changed files with 49 additions and 0 deletions
|
@ -566,6 +566,8 @@ rcl_timer_reset(rcl_timer_t * timer);
|
||||||
* \param[inout] timer handle to the timer object
|
* \param[inout] timer handle to the timer object
|
||||||
* \return pointer to the allocator, or `NULL` if an error occurred
|
* \return pointer to the allocator, or `NULL` if an error occurred
|
||||||
*/
|
*/
|
||||||
|
RCL_PUBLIC
|
||||||
|
RCL_WARN_UNUSED
|
||||||
const rcl_allocator_t *
|
const rcl_allocator_t *
|
||||||
rcl_timer_get_allocator(const rcl_timer_t * timer);
|
rcl_timer_get_allocator(const rcl_timer_t * timer);
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,46 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static uint8_t times_called = 0;
|
||||||
|
static void callback_function(rcl_timer_t * timer, int64_t last_call)
|
||||||
|
{
|
||||||
|
(void) timer;
|
||||||
|
(void) last_call;
|
||||||
|
times_called++;
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestPreInitTimer : public TestTimerFixture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
rcl_clock_t clock;
|
||||||
|
rcl_allocator_t allocator;
|
||||||
|
rcl_timer_t timer;
|
||||||
|
rcl_timer_callback_t timer_callback_test = &callback_function;
|
||||||
|
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
|
TestTimerFixture::SetUp();
|
||||||
|
rcl_ret_t ret;
|
||||||
|
allocator = rcl_get_default_allocator();
|
||||||
|
timer = rcl_get_zero_initialized_timer();
|
||||||
|
ASSERT_EQ(
|
||||||
|
RCL_RET_OK,
|
||||||
|
rcl_clock_init(RCL_ROS_TIME, &clock, &allocator)) << rcl_get_error_string().str;
|
||||||
|
|
||||||
|
ret = rcl_timer_init(
|
||||||
|
&timer, &clock, this->context_ptr, RCL_S_TO_NS(1), timer_callback_test,
|
||||||
|
rcl_get_default_allocator());
|
||||||
|
ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string().str;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override
|
||||||
|
{
|
||||||
|
EXPECT_EQ(RCL_RET_OK, rcl_timer_fini(&timer)) << rcl_get_error_string().str;
|
||||||
|
EXPECT_EQ(RCL_RET_OK, rcl_clock_fini(&clock)) << rcl_get_error_string().str;
|
||||||
|
TestTimerFixture::TearDown();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TEST_F(TestTimerFixture, test_two_timers) {
|
TEST_F(TestTimerFixture, test_two_timers) {
|
||||||
rcl_ret_t ret;
|
rcl_ret_t ret;
|
||||||
|
|
||||||
|
@ -512,3 +552,10 @@ TEST_F(TestTimerFixture, test_ros_time_wakes_wait) {
|
||||||
EXPECT_TRUE(timer_was_ready);
|
EXPECT_TRUE(timer_was_ready);
|
||||||
EXPECT_LT(finish - start, std::chrono::milliseconds(100));
|
EXPECT_LT(finish - start, std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(TestPreInitTimer, test_timer_get_allocator) {
|
||||||
|
const rcl_allocator_t * allocator_returned = rcl_timer_get_allocator(&timer);
|
||||||
|
EXPECT_TRUE(rcutils_allocator_is_valid(allocator_returned));
|
||||||
|
|
||||||
|
EXPECT_EQ(NULL, rcl_timer_get_allocator(nullptr));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue