@@ -181,7 +181,7 @@ TYPED_TEST(TrafficLightsInternalTest, compareTrafficLightsState)
181
181
182
182
TYPED_TEST (TrafficLightsInternalTest, startUpdate_publishMarkers)
183
183
{
184
- const auto marker_id = this ->id ;
184
+ const auto base_marker_id = this ->id ;
185
185
constexpr const char * color_name = " red" ;
186
186
this ->lights ->setTrafficLightsState (this ->id , stateFromColor (color_name));
187
187
@@ -205,25 +205,56 @@ TYPED_TEST(TrafficLightsInternalTest, startUpdate_publishMarkers)
205
205
EXPECT_EQ (marker.action , visualization_msgs::msg::Marker::DELETEALL) << info;
206
206
};
207
207
208
- const auto verify_add_marker = [&color_name, &marker_id](
209
- const visualization_msgs::msg::Marker & marker,
208
+ const auto verify_add_marker = [&base_marker_id](
209
+ const visualization_msgs::msg::Marker marker,
210
+ const geometry_msgs::msg::Point position,
211
+ const std::string color_name, const bool is_on,
210
212
const auto info = " " ) {
211
213
EXPECT_EQ (marker.ns , " bulb" ) << info;
212
- EXPECT_EQ (marker.id , marker_id ) << info;
214
+ EXPECT_EQ (marker.id >> 2 , base_marker_id ) << info;
213
215
EXPECT_EQ (marker.type , visualization_msgs::msg::Marker::SPHERE) << info;
214
216
EXPECT_EQ (marker.action , visualization_msgs::msg::Marker::ADD) << info;
215
217
216
- EXPECT_POINT_NEAR_STREAM (
217
- marker.pose .position ,
218
- geometry_msgs::build<geometry_msgs::msg::Point>().x (3770.02 ).y (73738.34 ).z (5.80 ),
219
- position_eps, info);
218
+ EXPECT_POINT_NEAR_STREAM (marker.pose .position , position, position_eps, info);
220
219
221
220
EXPECT_QUATERNION_EQ_STREAM (marker.pose .orientation , geometry_msgs::msg::Quaternion (), info);
222
221
223
222
EXPECT_POINT_EQ_STREAM (
224
223
marker.scale , geometry_msgs::build<geometry_msgs::msg::Vector3>().x (0.3 ).y (0.3 ).z (0.3 ), info);
225
224
226
- EXPECT_COLOR_RGBA_NEAR_STREAM (marker.color , color_names::makeColorMsg (color_name), eps, info);
225
+ auto expected_color = color_names::makeColorMsg (color_name);
226
+ expected_color.a = is_on ? 1.0 : 0.3 ;
227
+ EXPECT_COLOR_RGBA_NEAR_STREAM (marker.color , expected_color, eps, info);
228
+ };
229
+
230
+ const auto verify_add_markers = [&base_marker_id, &color_name, &verify_add_marker](
231
+ const std::vector<visualization_msgs::msg::Marker> & markers) {
232
+ EXPECT_EQ (markers.size (), static_cast <std::size_t >(3 ));
233
+ for (auto & marker : markers) {
234
+ using Color = traffic_simulator::TrafficLight::Color;
235
+
236
+ const auto color_value = static_cast <Color::Value>(marker.id & 0b11 );
237
+ const auto color = static_cast <Color>(color_value);
238
+
239
+ if (color.is (Color::red)) {
240
+ const auto red_position =
241
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3769.15 ).y (73737.92 ).z (5.81 );
242
+ verify_add_marker (
243
+ marker, red_position, " red" , true , " red marker " + std::to_string (marker.id ));
244
+ } else if (color.is (Color::yellow)) {
245
+ const auto yellow_position =
246
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3769.60 ).y (73738.12 ).z (5.81 );
247
+ verify_add_marker (
248
+ marker, yellow_position, " yellow" , false , " yellow marker " + std::to_string (marker.id ));
249
+ } else if (color.is (Color::green)) {
250
+ const auto green_position =
251
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3770.02 ).y (73738.34 ).z (5.80 );
252
+ verify_add_marker (
253
+ marker, green_position, " green" , false , " green marker " + std::to_string (marker.id ));
254
+ } else {
255
+ FAIL () << " Unknown color for marker id: " << marker.id ;
256
+ }
257
+ }
227
258
};
228
259
229
260
// verify contents of messages
@@ -237,8 +268,7 @@ TYPED_TEST(TrafficLightsInternalTest, startUpdate_publishMarkers)
237
268
}
238
269
{
239
270
const auto & one_marker = markers[i + 1 ].markers ;
240
- EXPECT_EQ (one_marker.size (), static_cast <std::size_t >(1 ));
241
- verify_add_marker (one_marker[0 ], " marker " + std::to_string (i + 1 ));
271
+ verify_add_markers (one_marker);
242
272
243
273
headers.push_back (one_marker[0 ].header );
244
274
}
@@ -254,7 +284,7 @@ TYPED_TEST(TrafficLightsInternalTest, startUpdate_publishMarkers)
254
284
255
285
TYPED_TEST (TrafficLightsInternalTest, resetUpdate_publishMarkers)
256
286
{
257
- const auto marker_id = this ->id ;
287
+ const auto base_marker_id = this ->id ;
258
288
constexpr const char * color_name = " green" ;
259
289
this ->lights ->setTrafficLightsState (this ->id , stateFromColor (color_name));
260
290
@@ -297,27 +327,57 @@ TYPED_TEST(TrafficLightsInternalTest, resetUpdate_publishMarkers)
297
327
EXPECT_EQ (marker.action , visualization_msgs::msg::Marker::DELETEALL) << info;
298
328
};
299
329
300
- const auto verify_add_marker = [&color_name, &marker_id](
301
- const visualization_msgs::msg::Marker & marker,
330
+ const auto verify_add_marker = [&base_marker_id](
331
+ const visualization_msgs::msg::Marker marker,
332
+ const geometry_msgs::msg::Point position,
333
+ const std::string color_name, const bool is_on,
302
334
const auto info = " " ) {
303
335
EXPECT_EQ (marker.ns , " bulb" ) << info;
304
- EXPECT_EQ (marker.id , marker_id ) << info;
336
+ EXPECT_EQ (marker.id >> 2 , base_marker_id ) << info;
305
337
EXPECT_EQ (marker.type , visualization_msgs::msg::Marker::SPHERE) << info;
306
338
EXPECT_EQ (marker.action , visualization_msgs::msg::Marker::ADD) << info;
307
339
308
- EXPECT_POINT_NEAR_STREAM (
309
- marker.pose .position ,
310
- geometry_msgs::build<geometry_msgs::msg::Point>().x (3770.02 ).y (73738.34 ).z (5.80 ),
311
- position_eps, info);
340
+ EXPECT_POINT_NEAR_STREAM (marker.pose .position , position, position_eps, info);
312
341
313
342
EXPECT_QUATERNION_EQ_STREAM (marker.pose .orientation , geometry_msgs::msg::Quaternion (), info);
314
343
315
344
EXPECT_POINT_EQ_STREAM (
316
345
marker.scale , geometry_msgs::build<geometry_msgs::msg::Vector3>().x (0.3 ).y (0.3 ).z (0.3 ), info);
317
346
318
- EXPECT_COLOR_RGBA_NEAR_STREAM (marker.color , color_names::makeColorMsg (color_name), eps, info);
347
+ auto expected_color = color_names::makeColorMsg (color_name);
348
+ expected_color.a = is_on ? 1.0 : 0.3 ;
349
+ EXPECT_COLOR_RGBA_NEAR_STREAM (marker.color , expected_color, eps, info);
319
350
};
320
351
352
+ const auto verify_add_markers = [&base_marker_id, &color_name, &verify_add_marker](
353
+ const std::vector<visualization_msgs::msg::Marker> & markers) {
354
+ EXPECT_EQ (markers.size (), static_cast <std::size_t >(3 ));
355
+ for (auto & marker : markers) {
356
+ using Color = traffic_simulator::TrafficLight::Color;
357
+
358
+ const auto color_value = static_cast <Color::Value>(marker.id & 0b11 );
359
+ const auto color = static_cast <Color>(color_value);
360
+
361
+ if (color.is (Color::red)) {
362
+ const auto red_position =
363
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3769.15 ).y (73737.92 ).z (5.81 );
364
+ verify_add_marker (
365
+ marker, red_position, " red" , false , " red marker " + std::to_string (marker.id ));
366
+ } else if (color.is (Color::yellow)) {
367
+ const auto yellow_position =
368
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3769.60 ).y (73738.12 ).z (5.81 );
369
+ verify_add_marker (
370
+ marker, yellow_position, " yellow" , false , " yellow marker " + std::to_string (marker.id ));
371
+ } else if (color.is (Color::green)) {
372
+ const auto green_position =
373
+ geometry_msgs::build<geometry_msgs::msg::Point>().x (3770.02 ).y (73738.34 ).z (5.80 );
374
+ verify_add_marker (
375
+ marker, green_position, " green" , true , " green marker " + std::to_string (marker.id ));
376
+ } else {
377
+ FAIL () << " Unknown color for marker id: " << marker.id ;
378
+ }
379
+ }
380
+ };
321
381
// verify contents of messages - before reset
322
382
std::vector<std_msgs::msg::Header> headers;
323
383
for (std::size_t i = 0 ; i < markers.size (); i += 2 ) {
@@ -329,8 +389,7 @@ TYPED_TEST(TrafficLightsInternalTest, resetUpdate_publishMarkers)
329
389
}
330
390
{
331
391
const auto & one_marker = markers[i + 1 ].markers ;
332
- EXPECT_EQ (one_marker.size (), static_cast <std::size_t >(1 ));
333
- verify_add_marker (one_marker[0 ], " marker " + std::to_string (i + 1 ));
392
+ verify_add_markers (one_marker);
334
393
335
394
headers.push_back (one_marker[0 ].header );
336
395
}
@@ -355,8 +414,7 @@ TYPED_TEST(TrafficLightsInternalTest, resetUpdate_publishMarkers)
355
414
}
356
415
{
357
416
const auto & one_marker = markers_reset[i + 1 ].markers ;
358
- EXPECT_EQ (one_marker.size (), static_cast <std::size_t >(1 ));
359
- verify_add_marker (one_marker[0 ], " marker " + std::to_string (i + 1 ));
417
+ verify_add_markers (one_marker);
360
418
361
419
headers_reset.push_back (one_marker[0 ].header );
362
420
}
0 commit comments