From f12e676b3e86a4a85bc9b8409267a2eecfef48c5 Mon Sep 17 00:00:00 2001 From: Karsten Knese Date: Tue, 23 Apr 2019 16:29:13 -0700 Subject: [PATCH] compile tests Signed-off-by: Karsten Knese --- rosbag2_bag_v2_plugins/CMakeLists.txt | 23 ++++- .../resources/test_bag_end_to_end.bag | Bin 0 -> 8522 bytes ...test_rosbag2_info_rosbag_v2_end_to_end.cpp | 72 ++++++++++++++ ...test_rosbag2_play_rosbag_v2_end_to_end.cpp | 92 ++++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 rosbag2_bag_v2_plugins/resources/test_bag_end_to_end.bag create mode 100644 rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_info_rosbag_v2_end_to_end.cpp create mode 100644 rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_play_rosbag_v2_end_to_end.cpp diff --git a/rosbag2_bag_v2_plugins/CMakeLists.txt b/rosbag2_bag_v2_plugins/CMakeLists.txt index 94f3fe4..93e21ad 100644 --- a/rosbag2_bag_v2_plugins/CMakeLists.txt +++ b/rosbag2_bag_v2_plugins/CMakeLists.txt @@ -125,7 +125,6 @@ ament_export_libraries(${PROJECT_NAME}) ament_export_dependencies(rosbag2_storage) ament_export_dependencies(rosbag2 ros1_rosbag_storage rosbag2_storage) - if(BUILD_TESTING) find_package(ament_cmake_gmock REQUIRED) find_package(ament_lint_auto REQUIRED) @@ -158,6 +157,28 @@ if(BUILD_TESTING) ament_target_dependencies(test_rosbag_output_stream rosbag2_test_common) endif() + + ament_add_gmock(test_rosbag2_play_rosbag_v2_end_to_end + test/rosbag2_bag_v2_plugins/test_rosbag2_play_rosbag_v2_end_to_end.cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + if(TARGET test_rosbag2_play_rosbag_v2_end_to_end) + ament_target_dependencies(test_rosbag2_play_rosbag_v2_end_to_end + rosbag2_storage + rclcpp + rosbag2_test_common + std_msgs) + endif() + + ament_add_gmock(test_rosbag2_info_rosbag_v2_end_to_end + test/rosbag2_bag_v2_plugins/test_rosbag2_info_rosbag_v2_end_to_end.cpp + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + if(TARGET test_rosbag2_info_rosbag_v2_end_to_end) + ament_target_dependencies(test_rosbag2_info_rosbag_v2_end_to_end + rosbag2_storage + rclcpp + rosbag2_test_common + std_msgs) + endif() endif() ament_package() diff --git a/rosbag2_bag_v2_plugins/resources/test_bag_end_to_end.bag b/rosbag2_bag_v2_plugins/resources/test_bag_end_to_end.bag new file mode 100644 index 0000000000000000000000000000000000000000..91c05cd2e39d71879fb19d625db7a2c0f514aa26 GIT binary patch literal 8522 zcmeHN&2Jk;6i+_`t0KM;MG=hTmL@@I<2WC7#2!+$DM6(vP6`K#tl6Dedtg0lc4m_r z2_dc=I3PH1rvCsZgb?bVzyWdPhPc6nGw^%+;drSfQURh!yYgy2-<$V-@4cDlv1{$^ zor@b+*lSDY7oE#fQ&W%N^?QkayW>ZRw(b$MAEv%Y>%8k2nvdaCTF6_SL1f&|ox&hW z^j+=;foLrHV%1v}vauM{mlj)%re9z4S6Yq0`w-Ln5P)}ON60{FWl5G=&8gMcj@*;6 zvO^Z45;Cl9EZ5dx%<+a+vP+jQ-nin{SxrbU>1NZik*#Z++wKx$wXW1M=Hd9*>l^KB z?lQ*qd90N#(Oqu0x7%)$)npt;@i^7y#_q;dx4z110k=H7;6pOyk2q%%Zz>szRKAxa z7cyqOw8&&iwQ!7$X-&=hlGU;z3YhIlrXwMX;lAl&G)IONy@3jeC@qMh825=;5J&yd z#63mMD~d`TbG!V+X4hmZFfIffN5kGPBdCPgBilgTWQ!r zPHxt*#yk*#a_5co0ggnZ2*YO6z7CpZj$sjqAP14(W3!O_`q1{^A7tx29xLv_v%nY* z9fIpQB04uW##yJVHP=zWKI3?>#$nhJmy9pzw9tdi;BsANk}d$m`hz&yQvwor!&Eju zR8m{`r5E#f=nz$=s#Dt}j4=sRsYOw8Vj}u3~9wU?XzoQQk38Zp=`(*m&(pRU~7tnFnL;I?Q z1Kl-%ju-HbSkq-}z6np$4Q#fxX0g{v8v%O9HrQ5c$(K!DUu~}W(r@}rPc)ki>8~|> zzFZge=P-T32Al6f1f25(twUOmqG~7Iqe?oD33j0K@6dTqUz?c*2f8y3qG%SyNSmW* z6xz@gbEXa4I#WfUYfKfvS6Yj$z>|%&CYL;DuE>?;HQB`R;nzKH?O9Bpph~uZrJ6iW zYm_wEqTQ{e$e2uJMLzg)dxnIa$6KO6yU?Ocar^Z3nR_;OiSZtdk^OeU^fZ?V(s9~erbVDg(Dp&Xpr5czrMVPda->>VG@NE`PMHdF#tKp zN?#zx3Uw`r3;Di9y|g5`)WMPzm3ah~mOO+0B6@!%xv&iR+{^hgWW7^=W=)QFc-9n8 z-{cyQXTG1aCKF!->$Bii0xFlYN-6WSvq~wel(I@G|0+}c-=>uJZQeIKzA=v_8`J+` z3MU{F<-^$@7w8`ePtyGbp7Me8D0-w8oirsc&dB^=IZ5duzOTecKgTn6oJFIf_-WMX Pp(Bw_QaV2g0xJIinW@D6 literal 0 HcmV?d00001 diff --git a/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_info_rosbag_v2_end_to_end.cpp b/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_info_rosbag_v2_end_to_end.cpp new file mode 100644 index 0000000..a4fdf2d --- /dev/null +++ b/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_info_rosbag_v2_end_to_end.cpp @@ -0,0 +1,72 @@ +// Copyright 2018, Bosch Software Innovations GmbH. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include +#include + +#include "rosbag2_test_common/process_execution_helpers.hpp" + +using namespace ::testing; // NOLINT + +class InfoV2EndToEndTestFixture : public Test +{ +public: + InfoV2EndToEndTestFixture() + { + database_path_ = _SRC_RESOURCES_DIR_PATH; // variable defined in CMakeLists.txt + } + + std::string database_path_; +}; + +TEST_F(InfoV2EndToEndTestFixture, info_end_to_end_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info test_bag_end_to_end.bag -s rosbag_v2", database_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); +// The bag size depends on the os and is not asserted, the time is asserted time zone independent + EXPECT_THAT(output, ContainsRegex( + "\nFiles: test_bag_end_to_end\\.bag" + "\nBag size: .*B" + "\nStorage id: rosbag_v2" + "\nDuration: 3\\.0s" + "\nStart: Dec .+ 2018 .+:.+:06\\.974 \\(1544000766\\.974\\)" + "\nEnd Dec .+ 2018 .+:.+:09\\.975 \\(1544000769\\.975\\)" + "\nMessages: 11" + "\nTopic information: ")); + + EXPECT_THAT(output, HasSubstr( + "Topic: rosout | Type: rosgraph_msgs/Log | Count: 5 | Serialization Format: rosbag_v2\n")); + EXPECT_THAT(output, HasSubstr("Topic: string_topic | Type: std_msgs/String | Count: 3 | " + "Serialization Format: rosbag_v2\n")); + EXPECT_THAT(output, HasSubstr( + "Topic: int_topic | Type: std_msgs/Int32 | Count: 3 | Serialization Format: rosbag_v2" + )); +} + + +TEST_F(InfoV2EndToEndTestFixture, info_fails_gracefully_if_storage_format_is_not_specified) { + internal::CaptureStderr(); + auto exit_code = + execute_and_wait_until_completion("ros2 bag info test_bag.bag", database_path_); + auto error_output = internal::GetCapturedStderr(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT(error_output, HasSubstr("Could not read metadata for test_bag.bag")); +} diff --git a/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_play_rosbag_v2_end_to_end.cpp b/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_play_rosbag_v2_end_to_end.cpp new file mode 100644 index 0000000..4e79d39 --- /dev/null +++ b/rosbag2_bag_v2_plugins/test/rosbag2_bag_v2_plugins/test_rosbag2_play_rosbag_v2_end_to_end.cpp @@ -0,0 +1,92 @@ +// Copyright 2018, Bosch Software Innovations GmbH. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include +#include +#include +#include +#include +#include +#include + +// rclcpp must be included before process_execution_helpers.hpp +#include "rclcpp/rclcpp.hpp" +#include "rosbag2_test_common/process_execution_helpers.hpp" + +#include "std_msgs/msg/string.hpp" +#include "std_msgs/msg/int32.hpp" +#include "std_msgs/msg/int32_multi_array.hpp" +#include "rosbag2_test_common/subscription_manager.hpp" + +using namespace ::testing; // NOLINT +using namespace rosbag2_test_common; // NOLINT + +class PlayEndToEndTestFixture : public Test +{ +public: + PlayEndToEndTestFixture() + { + database_path_ = _SRC_RESOURCES_DIR_PATH; // variable defined in CMakeLists.txt + sub_ = std::make_unique(); + } + + static void SetUpTestCase() + { + rclcpp::init(0, nullptr); + } + + static void TearDownTestCase() + { + rclcpp::shutdown(); + } + + std::string database_path_; + std::unique_ptr sub_; +}; + +TEST_F(PlayEndToEndTestFixture, play_end_to_end_test_does_not_try_to_publish_ros1_topics) { + sub_->add_subscription("/string_topic", 2); + sub_->add_subscription("/int_topic", 2); + + auto subscription_future = sub_->spin_subscriptions(); + + auto exit_code = execute_and_wait_until_completion( + "ros2 bag play test_bag_end_to_end.bag -s rosbag_v2", database_path_); + + subscription_future.get(); + + auto string_messages = sub_->get_received_messages("/string_topic"); + auto int_messages = sub_->get_received_messages("/int_topic"); + + EXPECT_THAT(string_messages, SizeIs(Ge(2u))); + EXPECT_THAT(string_messages[0]->data, StrEq("foo")); + + EXPECT_THAT(int_messages, SizeIs(2)); + EXPECT_THAT(int_messages[0]->data, Eq(42)); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); +} + + +TEST_F(PlayEndToEndTestFixture, play_fails_gracefully_if_rosbag_v2_storage_id_is_not_specified) { + internal::CaptureStderr(); + auto exit_code = + execute_and_wait_until_completion("ros2 bag play test_bag.bag", database_path_); + auto error_output = internal::GetCapturedStderr(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT(error_output, HasSubstr("No storage could be initialized")); +}