From f0f8cbc7fbe92f914a7dad87ce902b94df3ce742 Mon Sep 17 00:00:00 2001 From: Irene Bandera Date: Wed, 15 Nov 2023 09:24:06 +0100 Subject: [PATCH] Fix test CI Signed-off-by: Irene Bandera --- .../blackbox/mcap/McapFileCreationTest.cpp | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/ddsrecorder/test/blackbox/mcap/McapFileCreationTest.cpp b/ddsrecorder/test/blackbox/mcap/McapFileCreationTest.cpp index a73f90862..067691118 100644 --- a/ddsrecorder/test/blackbox/mcap/McapFileCreationTest.cpp +++ b/ddsrecorder/test/blackbox/mcap/McapFileCreationTest.cpp @@ -84,11 +84,11 @@ eprosima::fastrtps::types::DynamicType_ptr dynamic_type_; } // test std::unique_ptr create_recorder( - std::string file_name, - int downsampling, + const std::string& file_name, + const int downsampling, DdsRecorderState recorder_state = DdsRecorderState::RUNNING, - unsigned int event_window = 20, - bool ros2_types = false) + const unsigned int event_window = 20, + const bool ros2_types = false) { YAML::Node yml; @@ -110,10 +110,10 @@ std::unique_ptr create_recorder( ); } -void create_publisher( - std::string topic_name, - std::string type_name, - unsigned int domain) +eprosima::fastdds::dds::Publisher* create_publisher( + const std::string& topic_name, + const std::string& type_name, + const unsigned int domain) { eprosima::fastdds::dds::DomainParticipantQos pqos; pqos.name("TypeIntrospectionExample_Participant_Publisher"); @@ -147,11 +147,13 @@ void create_publisher( // Create the DDS DataWriter test::writer_ = publisher_->create_datawriter(topic_, DATAWRITER_QOS_DEFAULT, nullptr); + + return publisher_; } eprosima::fastrtps::types::DynamicData_ptr send_sample( - unsigned int index = 1, - unsigned int time_sleep = 100) + const unsigned int index = 1, + const unsigned int time_sleep = 100) { // Create and initialize new dynamic data eprosima::fastrtps::types::DynamicData_ptr dynamic_data_; @@ -171,10 +173,10 @@ eprosima::fastrtps::types::DynamicData_ptr send_sample( } eprosima::fastrtps::types::DynamicData_ptr record( - std::string file_name, - unsigned int num_msgs = 1, - unsigned int downsampling = 1, - bool ros2_types = false) + const std::string& file_name, + const unsigned int num_msgs = 1, + const unsigned int downsampling = 1, + const bool ros2_types = false) { eprosima::fastrtps::types::DynamicData_ptr send_data; @@ -182,10 +184,15 @@ eprosima::fastrtps::types::DynamicData_ptr record( auto recorder = create_recorder(file_name, downsampling, DdsRecorderState::RUNNING, 20, ros2_types); // Create Publisher - ros2_types ? create_publisher(test::ros2_topic_name, test::ros2_type_name, test::DOMAIN) : create_publisher( - test::dds_topic_name, test::dds_type_name, test::DOMAIN); - - + eprosima::fastdds::dds::Publisher* publisher; + if (ros2_types) + { + publisher = create_publisher(test::ros2_topic_name, test::ros2_type_name, test::DOMAIN); + } + else + { + publisher = create_publisher(test::dds_topic_name, test::dds_type_name, test::DOMAIN); + } // Send data for (unsigned int i = 0; i < num_msgs; i++) @@ -197,7 +204,7 @@ eprosima::fastrtps::types::DynamicData_ptr record( } mcap::LinearMessageView get_msgs_mcap( - std::string file_name, + const std::string& file_name, mcap::McapReader& mcap_reader_) { auto status = mcap_reader_.open(file_name); @@ -208,22 +215,29 @@ mcap::LinearMessageView get_msgs_mcap( } std::tuple record_with_transitions( - std::string file_name, + const std::string& file_name, DdsRecorderState init_state, - unsigned int first_round, - unsigned int secound_round, + const unsigned int first_round, + const unsigned int secound_round, DdsRecorderState current_state, EventKind event = EventKind::NO_EVENT, - unsigned int event_window = 20, + const unsigned int event_window = 20, unsigned int time_sleep = 0, - unsigned int downsampling = 1, - bool ros2_types = false) + const unsigned int downsampling = 1, + const bool ros2_types = false) { uint64_t current_time; { // Create Publisher - ros2_types ? create_publisher(test::ros2_topic_name, test::ros2_type_name, test::DOMAIN) : create_publisher( - test::dds_topic_name, test::dds_type_name, test::DOMAIN); + eprosima::fastdds::dds::Publisher* publisher; + if (ros2_types) + { + publisher = create_publisher(test::ros2_topic_name, test::ros2_type_name, test::DOMAIN); + } + else + { + publisher = create_publisher(test::dds_topic_name, test::dds_type_name, test::DOMAIN); + } // Create Recorder std::unique_ptr recorder = @@ -342,7 +356,7 @@ TEST(McapFileCreationTest, mcap_data_msgs) TEST(McapFileCreationTest, mcap_dds_topic) { - std::string file_name = "output_mcap_data_topic.mcap"; + std::string file_name = "output_mcap_dds_topic.mcap"; record(file_name); @@ -368,7 +382,7 @@ TEST(McapFileCreationTest, mcap_dds_topic) TEST(McapFileCreationTest, mcap_ros2_topic) { - std::string file_name = "output_mcap_data_topic.mcap"; + std::string file_name = "output_mcap_ros2_topic.mcap"; record(file_name, 1, 1, true);