Description
The extract_type_identifier function extracts the package name and type name from the input string but does not trim leading or trailing whitespace from these extracted components.
Expected Behavior
The function should automatically trim leading and trailing whitespace.
Actual Behavior
When passing " package/ name " as input, the function returns the package name as " package" and the type name as " name ", including the extra spaces.
To Reproduce
Test Case
#include <gmock/gmock.h>
#include <memory>
#include <string>
#include <utility>
#include "ament_index_cpp/get_package_prefix.hpp"
#include "rcpputils/shared_library.hpp"
#include "rosbag2_cpp/typesupport_helpers.hpp"
using namespace ::testing; // NOLINT
TEST(TypesupportHelpersTestV3, ProcessesValidTypeWithWhitespace) {
std::string package, middle, name;
std::tie(package, middle, name) = rosbag2_cpp::extract_type_identifier(" package/ name ");
EXPECT_EQ(package, "package");
EXPECT_TRUE(middle.empty());
EXPECT_EQ(name, "name");
}
Output
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from TypesupportHelpersTestV3
[ RUN ] TypesupportHelpersTestV3.ProcessesValidTypeWithWhitespace
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_cpp/test/rosbag2_cpp/test_typesupport_helpers.cpp:13: Failure
Expected equality of these values:
package
Which is: " package"
"package"
/home/shangzh/rosbag2_ws/rosbag2/rosbag2_cpp/test/rosbag2_cpp/test_typesupport_helpers.cpp:15: Failure
Expected equality of these values:
name
Which is: " name "
"name"
[ FAILED ] TypesupportHelpersTestV3.ProcessesValidTypeWithWhitespace (0 ms)
[----------] 1 test from TypesupportHelpersTestV3 (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] TypesupportHelpersTestV3.ProcessesValidTypeWithWhitespace
1 FAILED TEST
System (please complete the following information)
OS: ubuntu 24.04
ROS 2 Distro: ros 2 jazzy
Install Method: source
Version: ros 2 jazzy
build options: --mixin asan-gcc
Description
The extract_type_identifier function extracts the package name and type name from the input string but does not trim leading or trailing whitespace from these extracted components.
Expected Behavior
The function should automatically trim leading and trailing whitespace.
Actual Behavior
When passing " package/ name " as input, the function returns the package name as " package" and the type name as " name ", including the extra spaces.
To Reproduce
Test Case
Output
System (please complete the following information)
OS: ubuntu 24.04
ROS 2 Distro: ros 2 jazzy
Install Method: source
Version: ros 2 jazzy
build options: --mixin asan-gcc