@@ -99,6 +99,202 @@ TEST(TestSmartPoseBuffer, interpolate_pose) // NOLINT
99
99
EXPECT_NEAR (rpy.z * 180 / M_PI, 45.0 , 1e-6 );
100
100
}
101
101
102
+ TEST (TestSmartPoseBuffer, empty_buffer) // NOLINT
103
+ {
104
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
105
+ SmartPoseBuffer smart_pose_buffer (logger, 1.0 , 1.0 );
106
+
107
+ builtin_interfaces::msg::Time target_time;
108
+ target_time.sec = 0 ;
109
+ target_time.nanosec = 0 ;
110
+
111
+ // Test empty buffer
112
+ auto result = smart_pose_buffer.interpolate (target_time);
113
+ EXPECT_FALSE (result.has_value ());
114
+
115
+ // Test buffer with only one element
116
+ auto pose_ptr = std::make_shared<PoseWithCovarianceStamped>();
117
+ pose_ptr->header .stamp = target_time;
118
+ smart_pose_buffer.push_back (pose_ptr);
119
+
120
+ result = smart_pose_buffer.interpolate (target_time);
121
+ EXPECT_FALSE (result.has_value ());
122
+ }
123
+
124
+ TEST (TestSmartPoseBuffer, timeout_validation) // NOLINT
125
+ {
126
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
127
+ const double timeout = 1.0 ; // 1 second timeout
128
+ SmartPoseBuffer smart_pose_buffer (logger, timeout, 100.0 );
129
+
130
+ // Add two poses with 0.5 sec difference
131
+ auto pose1 = std::make_shared<PoseWithCovarianceStamped>();
132
+ pose1->header .stamp .sec = 0 ;
133
+ pose1->header .stamp .nanosec = 0 ;
134
+ smart_pose_buffer.push_back (pose1);
135
+
136
+ auto pose2 = std::make_shared<PoseWithCovarianceStamped>();
137
+ pose2->header .stamp .sec = 0 ;
138
+ pose2->header .stamp .nanosec = 500000000 ; // 0.5 sec
139
+ smart_pose_buffer.push_back (pose2);
140
+
141
+ // Test target time within timeout
142
+ builtin_interfaces::msg::Time target_time1;
143
+ target_time1.sec = 0 ;
144
+ target_time1.nanosec = 250000000 ; // 0.25 sec
145
+ auto result1 = smart_pose_buffer.interpolate (target_time1);
146
+ EXPECT_TRUE (result1.has_value ());
147
+
148
+ // Test target time beyond timeout
149
+ builtin_interfaces::msg::Time target_time2;
150
+ target_time2.sec = 2 ; // 2 sec (beyond 1 sec timeout)
151
+ target_time2.nanosec = 0 ;
152
+ auto result2 = smart_pose_buffer.interpolate (target_time2);
153
+ EXPECT_FALSE (result2.has_value ());
154
+ }
155
+
156
+ TEST (TestSmartPoseBuffer, position_tolerance_validation) // NOLINT
157
+ {
158
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
159
+ const double tolerance = 1.0 ; // 1 meter tolerance
160
+ SmartPoseBuffer smart_pose_buffer (logger, 10.0 , tolerance);
161
+
162
+ // Add two poses within tolerance
163
+ auto pose1 = std::make_shared<PoseWithCovarianceStamped>();
164
+ pose1->header .stamp .sec = 0 ;
165
+ pose1->pose .pose .position .x = 0 ;
166
+ pose1->pose .pose .position .y = 0 ;
167
+ smart_pose_buffer.push_back (pose1);
168
+
169
+ auto pose2 = std::make_shared<PoseWithCovarianceStamped>();
170
+ pose2->header .stamp .sec = 1 ;
171
+ pose2->pose .pose .position .x = 0.5 ; // 0.5m distance
172
+ pose2->pose .pose .position .y = 0 ;
173
+ smart_pose_buffer.push_back (pose2);
174
+
175
+ builtin_interfaces::msg::Time target_time;
176
+ target_time.sec = 0 ;
177
+ target_time.nanosec = 500000000 ; // 0.5 sec
178
+ auto result1 = smart_pose_buffer.interpolate (target_time);
179
+ EXPECT_TRUE (result1.has_value ());
180
+
181
+ // Add a pose beyond tolerance
182
+ auto pose3 = std::make_shared<PoseWithCovarianceStamped>();
183
+ pose3->header .stamp .sec = 2 ;
184
+ pose3->pose .pose .position .x = 2.0 ; // 2m distance (beyond 1m tolerance)
185
+ pose3->pose .pose .position .y = 0 ;
186
+ smart_pose_buffer.push_back (pose3);
187
+
188
+ target_time.sec = 1 ;
189
+ auto result2 = smart_pose_buffer.interpolate (target_time);
190
+ EXPECT_FALSE (result2.has_value ());
191
+ }
192
+
193
+ TEST (TestSmartPoseBuffer, buffer_operations) // NOLINT
194
+ {
195
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
196
+ SmartPoseBuffer smart_pose_buffer (logger, 10.0 , 10.0 );
197
+
198
+ // Test pop_old
199
+ for (int i = 0 ; i < 5 ; ++i) {
200
+ auto pose = std::make_shared<PoseWithCovarianceStamped>();
201
+ pose->header .stamp .sec = i;
202
+ smart_pose_buffer.push_back (pose);
203
+ }
204
+
205
+ builtin_interfaces::msg::Time pop_time;
206
+ pop_time.sec = 2 ;
207
+ smart_pose_buffer.pop_old (pop_time);
208
+
209
+ builtin_interfaces::msg::Time target_time;
210
+ target_time.sec = 1 ;
211
+ auto result1 = smart_pose_buffer.interpolate (target_time);
212
+ EXPECT_FALSE (result1.has_value ()); // Should fail because we popped too much
213
+
214
+ target_time.sec = 3 ;
215
+ auto result2 = smart_pose_buffer.interpolate (target_time);
216
+ EXPECT_TRUE (result2.has_value ());
217
+
218
+ // Test clear
219
+ smart_pose_buffer.clear ();
220
+ auto result3 = smart_pose_buffer.interpolate (target_time);
221
+ EXPECT_FALSE (result3.has_value ());
222
+ }
223
+
224
+ TEST (TestSmartPoseBuffer, non_chronological_timestamps) // NOLINT
225
+ {
226
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
227
+ SmartPoseBuffer smart_pose_buffer (logger, 10.0 , 10.0 );
228
+
229
+ // Add poses in order
230
+ for (int i = 0 ; i < 3 ; ++i) {
231
+ auto pose = std::make_shared<PoseWithCovarianceStamped>();
232
+ pose->header .stamp .sec = i;
233
+ smart_pose_buffer.push_back (pose);
234
+ }
235
+
236
+ // Add pose with older timestamp (should clear buffer)
237
+ auto old_pose = std::make_shared<PoseWithCovarianceStamped>();
238
+ old_pose->header .stamp .sec = 0 ;
239
+ smart_pose_buffer.push_back (old_pose);
240
+
241
+ // Buffer should now only contain the old_pose
242
+ builtin_interfaces::msg::Time target_time;
243
+ target_time.sec = 1 ;
244
+ auto result = smart_pose_buffer.interpolate (target_time);
245
+ EXPECT_FALSE (result.has_value ()); // Not enough poses in buffer
246
+ }
247
+
248
+ TEST (TestSmartPoseBuffer, target_time_before_first_pose) // NOLINT
249
+ {
250
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
251
+ SmartPoseBuffer smart_pose_buffer (logger, 10.0 , 10.0 );
252
+
253
+ // Add two poses
254
+ auto pose1 = std::make_shared<PoseWithCovarianceStamped>();
255
+ pose1->header .stamp .sec = 10 ;
256
+ smart_pose_buffer.push_back (pose1);
257
+
258
+ auto pose2 = std::make_shared<PoseWithCovarianceStamped>();
259
+ pose2->header .stamp .sec = 20 ;
260
+ smart_pose_buffer.push_back (pose2);
261
+
262
+ // Test target time before first pose
263
+ builtin_interfaces::msg::Time target_time;
264
+ target_time.sec = 5 ;
265
+ auto result = smart_pose_buffer.interpolate (target_time);
266
+ EXPECT_FALSE (result.has_value ());
267
+ }
268
+
269
+ TEST (TestSmartPoseBuffer, target_time_after_last_pose) // NOLINT
270
+ {
271
+ rclcpp::Logger logger = rclcpp::get_logger (" test_logger" );
272
+ const double timeout = 1.0 ;
273
+ SmartPoseBuffer smart_pose_buffer (logger, timeout, 10.0 );
274
+
275
+ // Add two poses
276
+ auto pose1 = std::make_shared<PoseWithCovarianceStamped>();
277
+ pose1->header .stamp .sec = 10 ;
278
+ smart_pose_buffer.push_back (pose1);
279
+
280
+ auto pose2 = std::make_shared<PoseWithCovarianceStamped>();
281
+ pose2->header .stamp .sec = 11 ;
282
+ smart_pose_buffer.push_back (pose2);
283
+
284
+ // Test target time slightly after last pose (within timeout)
285
+ builtin_interfaces::msg::Time target_time1;
286
+ target_time1.sec = 11 ;
287
+ target_time1.nanosec = 500000000 ; // 11.5 sec
288
+ auto result1 = smart_pose_buffer.interpolate (target_time1);
289
+ EXPECT_TRUE (result1.has_value ());
290
+
291
+ // Test target time well after last pose (beyond timeout)
292
+ builtin_interfaces::msg::Time target_time2;
293
+ target_time2.sec = 12 ; // 12 sec (beyond 1 sec timeout)
294
+ auto result2 = smart_pose_buffer.interpolate (target_time2);
295
+ EXPECT_FALSE (result2.has_value ());
296
+ }
297
+
102
298
int main (int argc, char ** argv)
103
299
{
104
300
rclcpp::init (argc, argv);
0 commit comments