@@ -201,3 +201,60 @@ TEST_F(SchemaExtractorTest, RemoveCommentsOnlyComments) {
201201 }
202202 EXPECT_TRUE (is_empty_or_whitespace) << " Result should be empty or whitespace-only, got: '" << result << " '" ;
203203}
204+
205+ // ---------------------------------------------------------------------------
206+ // Regression: Builtin types with array brackets (e.g., float64[9]) must be
207+ // recognised as builtins, not treated as nested message types.
208+ // ---------------------------------------------------------------------------
209+ TEST_F (SchemaExtractorTest, BuiltinArrayTypeNotMistakenForNestedType) {
210+ // sensor_msgs/msg/Imu contains "float64[9] orientation_covariance".
211+ // Before the fix, float64[9] was not recognized as builtin because
212+ // brackets were stripped after the builtin check, causing the schema
213+ // extraction to try to find "sensor_msgs/msg/float64.msg" which fails.
214+ std::string schema = extractor_->get_message_definition (" sensor_msgs/msg/Imu" );
215+ ASSERT_FALSE (schema.empty ()) << " Imu schema should not be empty (float64[9] must be recognised as builtin)" ;
216+
217+ // Verify the covariance fields are present in the output
218+ EXPECT_NE (schema.find (" orientation_covariance" ), std::string::npos);
219+ EXPECT_NE (schema.find (" angular_velocity_covariance" ), std::string::npos);
220+ EXPECT_NE (schema.find (" linear_acceleration_covariance" ), std::string::npos);
221+ }
222+
223+ // ---------------------------------------------------------------------------
224+ // Non-existent nested type should cause the whole schema to fail
225+ // (not silently omit the nested type).
226+ // ---------------------------------------------------------------------------
227+ TEST_F (SchemaExtractorTest, NonExistentNestedTypeReturnsEmpty) {
228+ // We can't easily create a message type with a fake nested type,
229+ // but we can verify that a completely fabricated package returns empty.
230+ std::string schema = extractor_->get_message_definition (" fake_nonexistent_pkg/msg/FakeType" );
231+ EXPECT_TRUE (schema.empty ()) << " Fabricated nested type should produce empty schema" ;
232+ }
233+
234+ // ---------------------------------------------------------------------------
235+ // Verify ImuSchemaContainsExpectedFields - specifically tests that the
236+ // schema correctly handles builtin types with fixed-size arrays.
237+ // ---------------------------------------------------------------------------
238+ TEST_F (SchemaExtractorTest, ImuSchemaContainsExpectedFields) {
239+ std::string actual = extractor_->get_message_definition (" sensor_msgs/msg/Imu" );
240+ ASSERT_FALSE (actual.empty ()) << " Failed to extract schema for sensor_msgs/msg/Imu" ;
241+
242+ std::string actual_no_comments = remove_comments_from_schema (actual);
243+
244+ // Core fields
245+ EXPECT_NE (actual_no_comments.find (" std_msgs/Header header" ), std::string::npos);
246+ EXPECT_NE (actual_no_comments.find (" geometry_msgs/Quaternion orientation" ), std::string::npos);
247+ EXPECT_NE (actual_no_comments.find (" geometry_msgs/Vector3 angular_velocity" ), std::string::npos);
248+ EXPECT_NE (actual_no_comments.find (" geometry_msgs/Vector3 linear_acceleration" ), std::string::npos);
249+
250+ // Fixed-size array builtins (the regression case)
251+ EXPECT_NE (actual_no_comments.find (" float64[9] orientation_covariance" ), std::string::npos);
252+ EXPECT_NE (actual_no_comments.find (" float64[9] angular_velocity_covariance" ), std::string::npos);
253+ EXPECT_NE (actual_no_comments.find (" float64[9] linear_acceleration_covariance" ), std::string::npos);
254+
255+ // Nested types should be present
256+ EXPECT_NE (actual_no_comments.find (" MSG: geometry_msgs/Quaternion" ), std::string::npos);
257+ EXPECT_NE (actual_no_comments.find (" MSG: geometry_msgs/Vector3" ), std::string::npos);
258+ EXPECT_NE (actual_no_comments.find (" MSG: std_msgs/Header" ), std::string::npos);
259+ EXPECT_NE (actual_no_comments.find (" MSG: builtin_interfaces/Time" ), std::string::npos);
260+ }
0 commit comments