From b6c35a67b9a90a1808a9b447366e127cb6ebf56f Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 11 Nov 2021 12:31:19 -0300 Subject: [PATCH] Add recorder keyboard control test Signed-off-by: Ivan Santiago Paunovic --- .../include/rosbag2_transport/recorder.hpp | 3 +- .../test_keyboard_controls.cpp | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/rosbag2_transport/include/rosbag2_transport/recorder.hpp b/rosbag2_transport/include/rosbag2_transport/recorder.hpp index f620e610b5..d4c8be5c6f 100644 --- a/rosbag2_transport/include/rosbag2_transport/recorder.hpp +++ b/rosbag2_transport/include/rosbag2_transport/recorder.hpp @@ -107,6 +107,8 @@ class Recorder : public rclcpp::Node ROSBAG2_TRANSPORT_PUBLIC bool is_paused(); + inline constexpr static const auto kPauseResumeToggleKey = KeyboardHandler::KeyCode::SPACE; + private: void topics_discovery(); @@ -157,7 +159,6 @@ class Recorder : public rclcpp::Node // Toogle paused key callback handle KeyboardHandler::callback_handle_t toggle_paused_key_callback_handle_ = KeyboardHandler::invalid_handle; - inline constexpr static const auto kPauseResumeToggleKey = KeyboardHandler::KeyCode::SPACE; }; } // namespace rosbag2_transport diff --git a/rosbag2_transport/test/rosbag2_transport/test_keyboard_controls.cpp b/rosbag2_transport/test/rosbag2_transport/test_keyboard_controls.cpp index d01857b723..e063b20673 100644 --- a/rosbag2_transport/test/rosbag2_transport/test_keyboard_controls.cpp +++ b/rosbag2_transport/test/rosbag2_transport/test_keyboard_controls.cpp @@ -26,11 +26,13 @@ #include "rosbag2_test_common/subscription_manager.hpp" #include "rosbag2_transport/player.hpp" +#include "rosbag2_transport/recorder.hpp" #include "test_msgs/msg/arrays.hpp" #include "test_msgs/msg/basic_types.hpp" #include "test_msgs/message_fixtures.hpp" +#include "record_integration_fixture.hpp" #include "rosbag2_play_test_fixture.hpp" #include "rosbag2_transport_test_fixture.hpp" #include "mock_keyboard_handler.hpp" @@ -177,3 +179,30 @@ TEST_F(RosBag2PlayTestFixture, test_keyboard_controls) EXPECT_THAT(player->num_played_next, 1); EXPECT_THAT(player->num_set_rate, 2); } + +TEST_F(RecordIntegrationTestFixture, test_keyboard_controls) +{ + auto mock_sequential_writer = std::make_unique(); + auto writer = std::make_unique(std::move(mock_sequential_writer)); + auto keyboard_handler = std::make_shared(); + + rosbag2_transport::RecordOptions record_options = {true, false, {}, "rmw_format", 100ms}; + record_options.start_paused = true; + + // play bag in thread + auto recorder = std::make_shared( + std::move(writer), keyboard_handler, storage_options_, + record_options, "test_count_recorder"); + + recorder->record(); + + this->start_async_spin(recorder); + + EXPECT_THAT(recorder->is_paused(), true); + keyboard_handler->simulate_key_press(rosbag2_transport::Recorder::kPauseResumeToggleKey); + EXPECT_THAT(recorder->is_paused(), false); + keyboard_handler->simulate_key_press(rosbag2_transport::Recorder::kPauseResumeToggleKey); + EXPECT_THAT(recorder->is_paused(), true); + + this->stop_spinning(); +}