From 043a6bf57afc5ba5cad9f7e54ea802fd7d3ab9bb Mon Sep 17 00:00:00 2001 From: Soenke Prophet Date: Fri, 4 Oct 2024 12:24:24 +0200 Subject: [PATCH] add test-cases for sorted info output Signed-off-by: Soenke Prophet --- .../test_rosbag2_info_end_to_end.cpp | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/rosbag2_tests/test/rosbag2_tests/test_rosbag2_info_end_to_end.cpp b/rosbag2_tests/test/rosbag2_tests/test_rosbag2_info_end_to_end.cpp index 61808d1c9..92e1a59ef 100644 --- a/rosbag2_tests/test/rosbag2_tests/test_rosbag2_info_end_to_end.cpp +++ b/rosbag2_tests/test/rosbag2_tests/test_rosbag2_info_end_to_end.cpp @@ -185,6 +185,102 @@ TEST_P(InfoEndToEndTestFixture, info_basic_types_and_arrays_with_verbose_option_ "Size Contribution: 2.7 KiB | Serialization Format: cdr")); } +TEST_P(InfoEndToEndTestFixture, info_output_default_sorted_by_name_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion("ros2 bag info cdr_test", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "Topic: /array_topic | Type: test_msgs/msg/Arrays | Count: 4 | " + "Serialization Format: cdr\n" + " Topic: /test_topic | Type: test_msgs/msg/BasicTypes | Count: 3 | " + "Serialization Format: cdr")); +} + +TEST_P(InfoEndToEndTestFixture, info_output_sorted_by_name_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info cdr_test --sort name", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "Topic: /array_topic | Type: test_msgs/msg/Arrays | Count: 4 | " + "Serialization Format: cdr\n" + " Topic: /test_topic | Type: test_msgs/msg/BasicTypes | Count: 3 | " + "Serialization Format: cdr")); +} + +TEST_P(InfoEndToEndTestFixture, info_output_sorted_by_type_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info cdr_test --sort type", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "Topic: /array_topic | Type: test_msgs/msg/Arrays | Count: 4 | " + "Serialization Format: cdr\n" + " Topic: /test_topic | Type: test_msgs/msg/BasicTypes | Count: 3 | " + "Serialization Format: cdr")); +} + +TEST_P(InfoEndToEndTestFixture, info_output_sorted_by_count_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info cdr_test --sort count", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "Topic: /test_topic | Type: test_msgs/msg/BasicTypes | Count: 3 | " + "Serialization Format: cdr\n" + " Topic: /array_topic | Type: test_msgs/msg/Arrays | Count: 4 | " + "Serialization Format: cdr")); +} + +TEST_P(InfoEndToEndTestFixture, info_output_topics_only_sorted_by_count_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info -t cdr_test --sort count", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "/test_topic\n" + "/array_topic")); +} + +TEST_P(InfoEndToEndTestFixture, info_output_topics_only_default_sorted_by_name_test) { + internal::CaptureStdout(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info -t cdr_test", bags_path_); + std::string output = internal::GetCapturedStdout(); + + EXPECT_THAT(exit_code, Eq(EXIT_SUCCESS)); + EXPECT_THAT( + output, HasSubstr( + "/array_topic\n" + "/test_topic")); +} + +TEST_P(InfoEndToEndTestFixture, info_fails_gracefully_sort_method_does_not_exist_test) { + internal::CaptureStderr(); + auto exit_code = execute_and_wait_until_completion( + "ros2 bag info cdr_test --sort non_existent", bags_path_); + auto error_output = internal::GetCapturedStderr(); + + EXPECT_THAT(exit_code, Ne(EXIT_SUCCESS)); + EXPECT_THAT( + error_output, HasSubstr("--sort: invalid choice: 'non_existent'")); +} + // TODO(Martin-Idel-SI): Revisit exit code non-zero here, gracefully should be exit code zero TEST_P(InfoEndToEndTestFixture, info_fails_gracefully_if_bag_does_not_exist) { internal::CaptureStderr();