18 #ifndef ROS_IGN_BRIDGE__TEST_UTILS_H_
19 #define ROS_IGN_BRIDGE__TEST_UTILS_H_
21 #include <gtest/gtest.h>
23 #include <std_msgs/Bool.h>
24 #include <std_msgs/Empty.h>
25 #include <std_msgs/Float32.h>
26 #include <std_msgs/Float64.h>
27 #include <std_msgs/Header.h>
28 #include <std_msgs/Int32.h>
29 #include <std_msgs/String.h>
30 #include <geometry_msgs/Point.h>
31 #include <geometry_msgs/Pose.h>
32 #include <geometry_msgs/PoseArray.h>
33 #include <geometry_msgs/PoseStamped.h>
34 #include <geometry_msgs/Transform.h>
35 #include <geometry_msgs/TransformStamped.h>
36 #include <geometry_msgs/Twist.h>
37 #include <geometry_msgs/Quaternion.h>
38 #include <geometry_msgs/Vector3.h>
40 #include <nav_msgs/OccupancyGrid.h>
41 #include <nav_msgs/Odometry.h>
42 #include <rosgraph_msgs/Clock.h>
43 #include <sensor_msgs/BatteryState.h>
44 #include <sensor_msgs/CameraInfo.h>
45 #include <sensor_msgs/FluidPressure.h>
46 #include <sensor_msgs/Image.h>
47 #include <sensor_msgs/Imu.h>
48 #include <sensor_msgs/JointState.h>
49 #include <sensor_msgs/LaserScan.h>
50 #include <sensor_msgs/MagneticField.h>
51 #include <sensor_msgs/NavSatFix.h>
52 #include <sensor_msgs/PointCloud2.h>
53 #include <sensor_msgs/PointField.h>
54 #include <tf2_msgs/TFMessage.h>
55 #include <visualization_msgs/Marker.h>
56 #include <visualization_msgs/MarkerArray.h>
61 #include <ignition/msgs.hh>
76 template <
class Rep,
class Period>
79 const std::chrono::duration<Rep, Period> &_sleepEach,
83 while (!_boolVar && i < _retries)
86 std::this_thread::sleep_for(_sleepEach);
99 template <
class Rep,
class Period>
102 const std::chrono::duration<Rep, Period> &_sleepEach,
106 while (!_boolVar && i < _retries)
109 std::this_thread::sleep_for(_sleepEach);
129 std_msgs::Bool expected_msg;
132 EXPECT_EQ(expected_msg.data, _msg.data);
149 std_msgs::ColorRGBA expected_msg;
152 EXPECT_EQ(expected_msg.r, _msg.r);
153 EXPECT_EQ(expected_msg.g, _msg.g);
154 EXPECT_EQ(expected_msg.b, _msg.b);
155 EXPECT_EQ(expected_msg.a, _msg.a);
189 std_msgs::Int32 expected_msg;
192 EXPECT_EQ(expected_msg.data, _msg.data);
199 std_msgs::Float32 expected_msg;
202 EXPECT_FLOAT_EQ(expected_msg.data, _msg.data);
209 std_msgs::Float64 expected_msg;
212 EXPECT_DOUBLE_EQ(expected_msg.data, _msg.data);
222 _msg.frame_id =
"frame_id_value";
229 std_msgs::Header expected_msg;
232 EXPECT_GE(expected_msg.seq, 0u);
233 EXPECT_EQ(expected_msg.stamp.sec, _msg.stamp.sec);
234 EXPECT_EQ(expected_msg.stamp.nsec, _msg.stamp.nsec);
235 EXPECT_EQ(expected_msg.frame_id, _msg.frame_id);
242 _msg.data =
"string";
249 std_msgs::String expected_msg;
252 EXPECT_EQ(expected_msg.data, _msg.data);
269 geometry_msgs::Quaternion expected_msg;
272 EXPECT_EQ(expected_msg.x, _msg.x);
273 EXPECT_EQ(expected_msg.y, _msg.y);
274 EXPECT_EQ(expected_msg.z, _msg.z);
275 EXPECT_EQ(expected_msg.w, _msg.w);
291 geometry_msgs::Vector3 expected_msg;
294 EXPECT_EQ(expected_msg.x, _msg.x);
295 EXPECT_EQ(expected_msg.y, _msg.y);
296 EXPECT_EQ(expected_msg.z, _msg.z);
320 rosgraph_msgs::Clock expected_msg;
323 EXPECT_EQ(expected_msg.clock.sec, _msg.clock.sec);
324 EXPECT_EQ(expected_msg.clock.nsec, _msg.clock.nsec);
331 geometry_msgs::Point expected_msg;
334 EXPECT_EQ(expected_msg.x, _msg.x);
335 EXPECT_EQ(expected_msg.y, _msg.y);
336 EXPECT_EQ(expected_msg.z, _msg.z);
359 geometry_msgs::Pose pose;
361 _msg.poses.push_back(pose);
412 _msg.child_frame_id =
"child_frame_id_value";
419 geometry_msgs::TransformStamped expected_msg;
424 EXPECT_EQ(expected_msg.child_frame_id, _msg.child_frame_id);
431 geometry_msgs::TransformStamped tf;
433 _msg.transforms.push_back(tf);
440 tf2_msgs::TFMessage expected_msg;
503 _msg.info.map_load_time.sec = 100;
504 _msg.info.map_load_time.nsec = 200;
505 _msg.info.resolution = 0.05;
506 _msg.info.width = 10;
507 _msg.info.height = 20;
509 _msg.data.resize(_msg.info.width * _msg.info.height, 1);
516 nav_msgs::OccupancyGrid expected_msg;
520 EXPECT_EQ(expected_msg.info.map_load_time.sec,
521 _msg.info.map_load_time.sec);
522 EXPECT_EQ(expected_msg.info.map_load_time.nsec,
523 _msg.info.map_load_time.nsec);
524 EXPECT_FLOAT_EQ(expected_msg.info.resolution, _msg.info.resolution);
525 EXPECT_EQ(expected_msg.info.width, _msg.info.width);
526 EXPECT_EQ(expected_msg.info.height, _msg.info.height);
530 EXPECT_EQ(expected_msg.data.size(), _msg.data.size());
531 EXPECT_EQ(expected_msg.data[0], _msg.data[0]);
556 std_msgs::Header header_msg;
559 _msg.header = header_msg;
562 _msg.encoding =
"rgb8";
563 _msg.is_bigendian =
false;
564 _msg.step = _msg.width * 3;
565 _msg.data.resize(_msg.height * _msg.step,
'1');
572 sensor_msgs::Image expected_msg;
576 EXPECT_EQ(expected_msg.width, _msg.width);
577 EXPECT_EQ(expected_msg.height, _msg.height);
578 EXPECT_EQ(expected_msg.encoding, _msg.encoding);
579 EXPECT_EQ(expected_msg.is_bigendian, _msg.is_bigendian);
580 EXPECT_EQ(expected_msg.step, _msg.step);
587 std_msgs::Header header_msg;
590 _msg.header = header_msg;
593 _msg.distortion_model =
"plumb_bob";
639 sensor_msgs::CameraInfo expected_msg;
643 EXPECT_EQ(expected_msg.width, _msg.width);
644 EXPECT_EQ(expected_msg.height, _msg.height);
645 EXPECT_EQ(expected_msg.distortion_model, _msg.distortion_model);
647 for (
auto i = 0; i < 12; ++i)
649 EXPECT_EQ(expected_msg.P[i], _msg.P[i]);
654 EXPECT_EQ(expected_msg.K[i], _msg.K[i]);
655 EXPECT_EQ(expected_msg.R[i], _msg.R[i]);
660 EXPECT_EQ(expected_msg.D[i], _msg.D[i]);
668 std_msgs::Header header_msg;
671 _msg.header = header_msg;
672 _msg.fluid_pressure = 0.123;
673 _msg.variance = 0.456;
680 sensor_msgs::FluidPressure expected_msg;
684 EXPECT_FLOAT_EQ(expected_msg.fluid_pressure, _msg.fluid_pressure);
685 EXPECT_FLOAT_EQ(expected_msg.variance, _msg.variance);
692 std_msgs::Header header_msg;
693 geometry_msgs::Quaternion quaternion_msg;
694 geometry_msgs::Vector3 vector3_msg;
700 _msg.header = header_msg;
701 _msg.orientation = quaternion_msg;
702 _msg.orientation_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
703 _msg.angular_velocity = vector3_msg;
704 _msg.angular_velocity_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
705 _msg.linear_acceleration = vector3_msg;
706 _msg.linear_acceleration_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
718 for (
auto i = 0; i < 9; ++i)
720 EXPECT_FLOAT_EQ(0, _msg.orientation_covariance[i]);
721 EXPECT_FLOAT_EQ(0, _msg.angular_velocity_covariance[i]);
722 EXPECT_FLOAT_EQ(0, _msg.linear_acceleration_covariance[i]);
730 std_msgs::Header header_msg;
733 _msg.header = header_msg;
734 _msg.name = {
"joint_0",
"joint_1",
"joint_2"};
735 _msg.position = {1, 1, 1};
736 _msg.velocity = {2, 2, 2};
737 _msg.effort = {3, 3, 3};
744 sensor_msgs::JointState expected_msg;
749 ASSERT_EQ(expected_msg.name.size(), _msg.name.size());
750 ASSERT_EQ(expected_msg.position.size(), _msg.position.size());
751 ASSERT_EQ(expected_msg.velocity.size(), _msg.velocity.size());
752 ASSERT_EQ(expected_msg.effort.size(), _msg.effort.size());
754 for (
auto i = 0u; i < _msg.position.size(); ++i)
756 EXPECT_EQ(expected_msg.name[i], _msg.name[i]);
757 EXPECT_FLOAT_EQ(expected_msg.position[i], _msg.position[i]);
758 EXPECT_FLOAT_EQ(expected_msg.velocity[i], _msg.velocity[i]);
759 EXPECT_FLOAT_EQ(expected_msg.effort[i], _msg.effort[i]);
767 const unsigned int num_readings = 100u;
768 const double laser_frequency = 40;
770 std_msgs::Header header_msg;
773 _msg.header = header_msg;
774 _msg.angle_min = -1.57;
775 _msg.angle_max = 1.57;
776 _msg.angle_increment = 3.14 / num_readings;
777 _msg.time_increment = (1 / laser_frequency) / (num_readings);
781 _msg.ranges.resize(num_readings, 0);
782 _msg.intensities.resize(num_readings, 1);
789 sensor_msgs::LaserScan expected_msg;
793 EXPECT_FLOAT_EQ(expected_msg.angle_min, _msg.angle_min);
794 EXPECT_FLOAT_EQ(expected_msg.angle_max, _msg.angle_max);
795 EXPECT_FLOAT_EQ(expected_msg.angle_increment, _msg.angle_increment);
796 EXPECT_FLOAT_EQ(0, _msg.time_increment);
797 EXPECT_FLOAT_EQ(0, _msg.scan_time);
798 EXPECT_FLOAT_EQ(expected_msg.range_min, _msg.range_min);
799 EXPECT_FLOAT_EQ(expected_msg.range_max, _msg.range_max);
801 const unsigned int num_readings =
802 (_msg.angle_max - _msg.angle_min) / _msg.angle_increment;
803 for (
auto i = 0u; i < num_readings; ++i)
805 EXPECT_FLOAT_EQ(expected_msg.ranges[i], _msg.ranges[i]);
806 EXPECT_FLOAT_EQ(expected_msg.intensities[i], _msg.intensities[i]);
814 std_msgs::Header header_msg;
815 geometry_msgs::Vector3 vector3_msg;
820 _msg.header = header_msg;
821 _msg.magnetic_field = vector3_msg;
822 _msg.magnetic_field_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
832 for (
auto i = 0u; i < 9; ++i)
833 EXPECT_FLOAT_EQ(0, _msg.magnetic_field_covariance[i]);
840 std_msgs::Header header_msg;
843 _msg.header = header_msg;
844 _msg.status.status = sensor_msgs::NavSatStatus::STATUS_FIX;
845 _msg.latitude = 0.00;
846 _msg.longitude = 0.00;
847 _msg.altitude = 0.00;
848 _msg.position_covariance = {1, 2, 3, 4, 5, 6, 7, 8, 9};
849 _msg.position_covariance_type =
850 sensor_msgs::NavSatFix::COVARIANCE_TYPE_UNKNOWN;
857 sensor_msgs::NavSatFix expected_msg;
861 EXPECT_EQ(expected_msg.status, _msg.status);
862 EXPECT_FLOAT_EQ(expected_msg.latitude, _msg.latitude);
863 EXPECT_FLOAT_EQ(expected_msg.longitude, _msg.longitude);
864 EXPECT_FLOAT_EQ(expected_msg.altitude, _msg.altitude);
865 EXPECT_EQ(expected_msg.position_covariance_type,
866 _msg.position_covariance_type);
868 for (
auto i = 0u; i < 9; ++i)
869 EXPECT_FLOAT_EQ(0, _msg.position_covariance[i]);
878 sensor_msgs::PointField field;
881 field.datatype = sensor_msgs::PointField::FLOAT32;
883 _msg.fields.push_back(field);
888 _msg.height = height;
890 _msg.is_bigendian =
false;
892 _msg.row_step = 4 * width;
893 _msg.is_dense =
true;
895 _msg.data.resize(_msg.row_step * _msg.height);
896 uint8_t *msgBufferIndex = _msg.data.data();
898 for (uint32_t j = 0; j < height; ++j)
900 for (uint32_t i = 0; i < width; ++i)
902 *
reinterpret_cast<float*
>(msgBufferIndex + _msg.fields[0].offset) =
904 msgBufferIndex += _msg.point_step;
918 EXPECT_EQ(height, _msg.height);
919 EXPECT_EQ(width, _msg.width);
920 EXPECT_FALSE(_msg.is_bigendian);
921 EXPECT_EQ(4u, _msg.point_step);
922 EXPECT_EQ(4U * width, _msg.row_step);
923 EXPECT_TRUE(_msg.is_dense);
925 unsigned char *msgBufferIndex =
926 const_cast<unsigned char*
>(_msg.data.data());
928 for (uint32_t j = 0; j < height; ++j)
930 for (uint32_t i = 0; i < width; ++i)
933 reinterpret_cast<float*
>(msgBufferIndex + _msg.fields[0].offset);
935 EXPECT_FLOAT_EQ(
static_cast<float>(j * width + i), *value);
936 msgBufferIndex += _msg.point_step;
945 std_msgs::Header header_msg;
948 _msg.header = header_msg;
953 _msg.percentage = 654;
954 _msg.power_supply_status = sensor_msgs::BatteryState::POWER_SUPPLY_STATUS_DISCHARGING;
961 sensor_msgs::BatteryState expected_msg;
965 EXPECT_EQ(expected_msg.voltage, _msg.voltage);
966 EXPECT_EQ(expected_msg.current, _msg.current);
967 EXPECT_EQ(expected_msg.charge, _msg.charge);
968 EXPECT_EQ(expected_msg.capacity, _msg.capacity);
969 EXPECT_EQ(expected_msg.percentage, _msg.percentage);
970 EXPECT_EQ(expected_msg.power_supply_status, _msg.power_supply_status);
981 _msg.type = visualization_msgs::Marker::CUBE;
982 _msg.action = visualization_msgs::Marker::ADD;
988 _msg.lifetime.sec = 100;
989 _msg.lifetime.nsec = 200;
991 geometry_msgs::Point pt;
993 _msg.points.push_back(pt);
1001 visualization_msgs::Marker expected_msg;
1006 EXPECT_EQ(expected_msg.ns, _msg.ns);
1007 EXPECT_EQ(expected_msg.id, _msg.id);
1008 EXPECT_EQ(expected_msg.type, _msg.type);
1009 EXPECT_EQ(expected_msg.action, _msg.action);
1015 EXPECT_EQ(expected_msg.lifetime.sec, _msg.lifetime.sec);
1016 EXPECT_EQ(expected_msg.lifetime.nsec, _msg.lifetime.nsec);
1020 EXPECT_EQ(expected_msg.text, _msg.text);
1027 _msg.markers.clear();
1028 visualization_msgs::Marker marker;
1030 _msg.markers.push_back(marker);
1037 visualization_msgs::MarkerArray expected_msg;
1040 EXPECT_EQ(1u, _msg.markers.size());
1052 _msg.set_data(
true);
1059 ignition::msgs::Boolean expected_msg;
1062 EXPECT_EQ(expected_msg.data(), _msg.data());
1079 ignition::msgs::Color expected_msg;
1082 EXPECT_EQ(expected_msg.r(), _msg.r());
1083 EXPECT_EQ(expected_msg.g(), _msg.g());
1084 EXPECT_EQ(expected_msg.b(), _msg.b());
1085 EXPECT_EQ(expected_msg.a(), _msg.a());
1105 ignition::msgs::Int32 expected_msg;
1108 EXPECT_EQ(expected_msg.data(), _msg.data());
1122 ignition::msgs::Float expected_msg;
1125 EXPECT_FLOAT_EQ(expected_msg.data(), _msg.data());
1139 ignition::msgs::Double expected_msg;
1142 EXPECT_DOUBLE_EQ(expected_msg.data(), _msg.data());
1149 auto seq_entry = _msg.add_data();
1150 seq_entry->set_key(
"seq");
1151 seq_entry->add_value(
"1");
1152 _msg.mutable_stamp()->set_sec(2);
1153 _msg.mutable_stamp()->set_nsec(3);
1154 auto frame_id_entry = _msg.add_data();
1155 frame_id_entry->set_key(
"frame_id");
1156 frame_id_entry->add_value(
"frame_id_value");
1163 ignition::msgs::Header expected_msg;
1166 EXPECT_EQ(expected_msg.stamp().sec(), _msg.stamp().sec());
1167 EXPECT_EQ(expected_msg.stamp().nsec(), _msg.stamp().nsec());
1168 EXPECT_GE(_msg.data_size(), 2);
1169 EXPECT_EQ(expected_msg.data(0).key(), _msg.data(0).key());
1170 EXPECT_EQ(1, _msg.data(0).value_size());
1171 std::string value = _msg.data(0).value(0);
1174 uint32_t ul = std::stoul(value,
nullptr);
1177 catch (std::exception & e)
1181 EXPECT_EQ(expected_msg.data(1).key(), _msg.data(1).key());
1182 EXPECT_EQ(1, _msg.data(1).value_size());
1183 EXPECT_EQ(expected_msg.data(1).value(0), _msg.data(1).value(0));
1190 _msg.mutable_sim()->set_sec(1);
1191 _msg.mutable_sim()->set_nsec(2);
1198 ignition::msgs::Clock expected_msg;
1201 EXPECT_EQ(expected_msg.sim().sec(), _msg.sim().sec());
1202 EXPECT_EQ(expected_msg.sim().nsec(), _msg.sim().nsec());
1209 _msg.set_data(
"string");
1216 ignition::msgs::StringMsg expected_msg;
1219 EXPECT_EQ(expected_msg.data(), _msg.data());
1236 ignition::msgs::Quaternion expected_msg;
1239 EXPECT_EQ(expected_msg.x(), _msg.x());
1240 EXPECT_EQ(expected_msg.y(), _msg.y());
1241 EXPECT_EQ(expected_msg.z(), _msg.z());
1242 EXPECT_EQ(expected_msg.w(), _msg.w());
1258 ignition::msgs::Vector3d expected_msg;
1261 EXPECT_EQ(expected_msg.x(), _msg.x());
1262 EXPECT_EQ(expected_msg.y(), _msg.y());
1263 EXPECT_EQ(expected_msg.z(), _msg.z());
1271 auto child_frame_id_entry = _msg.mutable_header()->add_data();
1272 child_frame_id_entry->set_key(
"child_frame_id");
1273 child_frame_id_entry->add_value(
"child_frame_id_value");
1283 if (_msg.header().data_size() > 0)
1287 ignition::msgs::Pose expected_msg;
1290 if (_msg.header().data_size() > 2)
1293 ASSERT_EQ(3, expected_msg.header().data_size());
1294 ASSERT_EQ(3, _msg.header().data_size());
1295 EXPECT_EQ(expected_msg.header().data(2).key(),
1296 _msg.header().data(2).key());
1297 EXPECT_EQ(1, _msg.header().data(2).value_size());
1298 EXPECT_EQ(expected_msg.header().data(2).value(0),
1299 _msg.header().data(2).value(0));
1319 ignition::msgs::Pose_V expected_msg;
1330 ignition::msgs::Header header_msg;
1331 ignition::msgs::Vector3d linear_msg;
1332 ignition::msgs::Vector3d angular_msg;
1338 _msg.mutable_header()->CopyFrom(header_msg);
1339 _msg.mutable_linear()->CopyFrom(linear_msg);
1340 _msg.mutable_angular()->CopyFrom(angular_msg);
1355 ignition::msgs::Header header_msg;
1358 _msg.mutable_header()->CopyFrom(header_msg);
1359 _msg.set_width(320);
1360 _msg.set_height(240);
1361 _msg.set_pixel_format_type(ignition::msgs::PixelFormatType::RGB_INT8);
1362 _msg.set_step(_msg.width() * 3);
1363 _msg.set_data(std::string(_msg.height() * _msg.step(),
'1'));
1370 ignition::msgs::Image expected_msg;
1374 EXPECT_EQ(expected_msg.width(), _msg.width());
1375 EXPECT_EQ(expected_msg.height(), _msg.height());
1376 EXPECT_EQ(expected_msg.pixel_format_type(), _msg.pixel_format_type());
1377 EXPECT_EQ(expected_msg.step(), _msg.step());
1378 EXPECT_EQ(expected_msg.data(), _msg.data());
1385 ignition::msgs::Header header_msg;
1388 _msg.mutable_header()->CopyFrom(header_msg);
1389 _msg.set_width(320);
1390 _msg.set_height(240);
1392 auto distortion = _msg.mutable_distortion();
1393 distortion->set_model(ignition::msgs::CameraInfo::Distortion::PLUMB_BOB);
1394 distortion->add_k(1);
1395 distortion->add_k(2);
1396 distortion->add_k(3);
1397 distortion->add_k(4);
1398 distortion->add_k(5);
1400 auto intrinsics = _msg.mutable_intrinsics();
1401 intrinsics->add_k(1);
1402 intrinsics->add_k(0);
1403 intrinsics->add_k(0);
1404 intrinsics->add_k(0);
1405 intrinsics->add_k(1);
1406 intrinsics->add_k(0);
1407 intrinsics->add_k(0);
1408 intrinsics->add_k(0);
1409 intrinsics->add_k(1);
1411 auto projection = _msg.mutable_projection();
1412 projection->add_p(1);
1413 projection->add_p(0);
1414 projection->add_p(0);
1415 projection->add_p(0);
1416 projection->add_p(0);
1417 projection->add_p(1);
1418 projection->add_p(0);
1419 projection->add_p(0);
1420 projection->add_p(0);
1421 projection->add_p(0);
1422 projection->add_p(1);
1423 projection->add_p(0);
1425 _msg.add_rectification_matrix(1);
1426 _msg.add_rectification_matrix(0);
1427 _msg.add_rectification_matrix(0);
1428 _msg.add_rectification_matrix(0);
1429 _msg.add_rectification_matrix(1);
1430 _msg.add_rectification_matrix(0);
1431 _msg.add_rectification_matrix(0);
1432 _msg.add_rectification_matrix(0);
1433 _msg.add_rectification_matrix(1);
1440 ignition::msgs::CameraInfo expected_msg;
1443 ASSERT_TRUE(expected_msg.has_header());
1444 ASSERT_TRUE(_msg.has_header());
1447 EXPECT_EQ(expected_msg.width(), _msg.width());
1448 EXPECT_EQ(expected_msg.height(), _msg.height());
1450 ASSERT_TRUE(expected_msg.has_distortion());
1451 ASSERT_TRUE(_msg.has_distortion());
1453 auto distortion = _msg.distortion();
1454 auto expected_distortion = expected_msg.distortion();
1455 EXPECT_EQ(expected_distortion.model(), distortion.model());
1456 ASSERT_EQ(expected_distortion.k_size(), distortion.k_size());
1457 for (
auto i = 0; i < expected_distortion.k_size(); ++i)
1458 EXPECT_EQ(expected_distortion.k(i), distortion.k(i));
1460 ASSERT_TRUE(expected_msg.has_intrinsics());
1461 ASSERT_TRUE(_msg.has_intrinsics());
1463 auto intrinsics = _msg.intrinsics();
1464 auto expected_intrinsics = expected_msg.intrinsics();
1465 ASSERT_EQ(expected_intrinsics.k_size(), intrinsics.k_size());
1466 for (
auto i = 0; i < expected_intrinsics.k_size(); ++i)
1467 EXPECT_EQ(expected_intrinsics.k(i), intrinsics.k(i));
1469 ASSERT_TRUE(expected_msg.has_projection());
1470 ASSERT_TRUE(_msg.has_projection());
1472 auto projection = _msg.projection();
1473 auto expected_projection = expected_msg.projection();
1474 ASSERT_EQ(expected_projection.p_size(), projection.p_size());
1475 for (
auto i = 0; i < expected_projection.p_size(); ++i)
1476 EXPECT_EQ(expected_projection.p(i), projection.p(i));
1478 ASSERT_EQ(expected_msg.rectification_matrix_size(), _msg.rectification_matrix_size());
1479 for (
auto i = 0; i < expected_msg.rectification_matrix_size(); ++i)
1480 EXPECT_EQ(expected_msg.rectification_matrix(i), _msg.rectification_matrix(i));
1487 ignition::msgs::Header header_msg;
1490 _msg.mutable_header()->CopyFrom(header_msg);
1491 _msg.set_pressure(0.123);
1492 _msg.set_variance(0.456);
1499 ignition::msgs::FluidPressure expected_msg;
1503 EXPECT_FLOAT_EQ(expected_msg.pressure(), _msg.pressure());
1504 EXPECT_FLOAT_EQ(expected_msg.variance(), _msg.variance());
1511 ignition::msgs::Header header_msg;
1512 ignition::msgs::Quaternion quaternion_msg;
1513 ignition::msgs::Vector3d vector3_msg;
1519 _msg.mutable_header()->CopyFrom(header_msg);
1520 _msg.mutable_orientation()->CopyFrom(quaternion_msg);
1521 _msg.mutable_angular_velocity()->CopyFrom(vector3_msg);
1522 _msg.mutable_linear_acceleration()->CopyFrom(vector3_msg);
1539 _msg.set_position(1.0);
1540 _msg.set_velocity(2.0);
1541 _msg.set_force(3.0);
1548 ignition::msgs::Axis expected_msg;
1551 EXPECT_DOUBLE_EQ(expected_msg.position(), _msg.position());
1552 EXPECT_DOUBLE_EQ(expected_msg.velocity(), _msg.velocity());
1553 EXPECT_DOUBLE_EQ(expected_msg.force(), _msg.force());
1560 ignition::msgs::Header header_msg;
1562 _msg.mutable_header()->CopyFrom(header_msg);
1564 for (
auto i = 0; i < 3; ++i)
1566 auto newJoint = _msg.add_joint();
1567 newJoint->set_name(
"joint_" + std::to_string(i));
1569 ignition::msgs::Axis axis_msg;
1571 newJoint->mutable_axis1()->CopyFrom(axis_msg);
1579 ignition::msgs::Model expected_msg;
1584 ASSERT_EQ(expected_msg.joint_size(), _msg.joint_size());
1585 for (
auto i = 0; i < _msg.joint_size(); ++i)
1587 EXPECT_EQ(expected_msg.joint(i).name(), _msg.joint(i).name());
1596 ignition::msgs::Header header_msg;
1599 const unsigned int num_readings = 100u;
1600 _msg.mutable_header()->CopyFrom(header_msg);
1601 _msg.set_frame(
"frame_id_value");
1602 _msg.set_angle_min(-1.57);
1603 _msg.set_angle_max(1.57);
1604 _msg.set_angle_step(3.14 / num_readings);
1605 _msg.set_range_min(1);
1606 _msg.set_range_max(2);
1607 _msg.set_count(num_readings);
1608 _msg.set_vertical_angle_min(0);
1609 _msg.set_vertical_angle_max(0);
1610 _msg.set_vertical_angle_step(0);
1611 _msg.set_vertical_count(0);
1613 for (
auto i = 0u; i < _msg.count(); ++i)
1616 _msg.add_intensities(1);
1624 ignition::msgs::LaserScan expected_msg;
1628 EXPECT_FLOAT_EQ(expected_msg.angle_min(), _msg.angle_min());
1629 EXPECT_FLOAT_EQ(expected_msg.angle_max(), _msg.angle_max());
1630 EXPECT_FLOAT_EQ(expected_msg.angle_step(), _msg.angle_step());
1631 EXPECT_DOUBLE_EQ(expected_msg.range_min(), _msg.range_min());
1632 EXPECT_DOUBLE_EQ(expected_msg.range_max(), _msg.range_max());
1633 EXPECT_EQ(expected_msg.count(), _msg.count());
1634 EXPECT_DOUBLE_EQ(expected_msg.vertical_angle_min(),
1635 _msg.vertical_angle_min());
1636 EXPECT_DOUBLE_EQ(expected_msg.vertical_angle_max(),
1637 _msg.vertical_angle_max());
1638 EXPECT_DOUBLE_EQ(expected_msg.vertical_angle_step(),
1639 _msg.vertical_angle_step());
1640 EXPECT_EQ(expected_msg.vertical_count(), _msg.vertical_count());
1641 EXPECT_EQ(expected_msg.ranges_size(), _msg.ranges_size());
1642 EXPECT_EQ(expected_msg.intensities_size(), _msg.intensities_size());
1644 for (
auto i = 0u; i < _msg.count(); ++i)
1646 EXPECT_DOUBLE_EQ(expected_msg.ranges(i), _msg.ranges(i));
1647 EXPECT_DOUBLE_EQ(expected_msg.intensities(i), _msg.intensities(i));
1655 ignition::msgs::Header header_msg;
1656 ignition::msgs::Vector3d vector3_msg;
1661 _msg.mutable_header()->CopyFrom(header_msg);
1662 _msg.mutable_field_tesla()->CopyFrom(vector3_msg);
1677 ignition::msgs::Header header_msg;
1680 _msg.mutable_header()->CopyFrom(header_msg);
1681 _msg.set_frame_id(
"frame_id_value");
1682 _msg.set_latitude_deg(0.00);
1683 _msg.set_longitude_deg(0.00);
1684 _msg.set_altitude(0.00);
1685 _msg.set_velocity_east(0.00);
1686 _msg.set_velocity_north(0.00);
1687 _msg.set_velocity_up(0.00);
1694 ignition::msgs::NavSat expected_msg;
1698 EXPECT_FLOAT_EQ(expected_msg.latitude_deg(), _msg.latitude_deg());
1699 EXPECT_FLOAT_EQ(expected_msg.longitude_deg(), _msg.longitude_deg());
1700 EXPECT_FLOAT_EQ(expected_msg.altitude(), _msg.altitude());
1701 EXPECT_FLOAT_EQ(expected_msg.velocity_east(), _msg.velocity_east());
1702 EXPECT_FLOAT_EQ(expected_msg.velocity_north(), _msg.velocity_north());
1703 EXPECT_FLOAT_EQ(expected_msg.velocity_up(), _msg.velocity_up());
1710 ignition::msgs::Header header_msg;
1713 _msg.mutable_header()->CopyFrom(header_msg);
1715 for (
int i = 0u; i < 5; ++i)
1717 _msg.add_position(i);
1718 _msg.add_velocity(i);
1719 _msg.add_normalized(i);
1727 ignition::msgs::Actuators expected_msg;
1732 for (
int i = 0; i < expected_msg.position_size(); ++i)
1734 EXPECT_EQ(expected_msg.position(i), _msg.position(i));
1735 EXPECT_EQ(expected_msg.velocity(i), _msg.velocity(i));
1736 EXPECT_EQ(expected_msg.normalized(i), _msg.normalized(i));
1744 ignition::msgs::Header header_msg;
1745 ignition::msgs::Pose pose_msg;
1750 _msg.mutable_header()->CopyFrom(header_msg);
1752 _msg.mutable_info()->mutable_map_load_time()->set_sec(100);
1753 _msg.mutable_info()->mutable_map_load_time()->set_nsec(200);
1754 _msg.mutable_info()->set_resolution(0.05);
1755 _msg.mutable_info()->set_width(10);
1756 _msg.mutable_info()->set_height(20);
1758 _msg.mutable_info()->mutable_origin()->CopyFrom(pose_msg);
1760 std::vector<int8_t> data(_msg.info().height() * _msg.info().width(), 1);
1761 _msg.set_data(&data[0], data.size());
1770 EXPECT_EQ(100, _msg.info().map_load_time().sec());
1771 EXPECT_EQ(200, _msg.info().map_load_time().nsec());
1772 EXPECT_FLOAT_EQ(0.05, _msg.info().resolution());
1773 EXPECT_EQ(10u, _msg.info().width());
1774 EXPECT_EQ(20u, _msg.info().height());
1777 EXPECT_EQ(20u * 10u, _msg.data().size());
1778 EXPECT_EQ(
'\1', _msg.data()[0]);
1785 ignition::msgs::Header header_msg;
1786 ignition::msgs::Pose pose_msg;
1787 ignition::msgs::Twist twist_msg;
1793 _msg.mutable_header()->CopyFrom(header_msg);
1794 _msg.mutable_pose()->CopyFrom(pose_msg);
1795 _msg.mutable_twist()->CopyFrom(twist_msg);
1811 ignition::msgs::Header header_msg;
1815 _msg.mutable_header()->CopyFrom(header_msg);
1816 ignition::msgs::PointCloudPacked::Field *field = _msg.add_field();
1817 field->set_name(
"x");
1818 field->set_offset(0);
1819 field->set_datatype(ignition::msgs::PointCloudPacked::Field::FLOAT32);
1820 field->set_count(1);
1822 uint32_t height = 4;
1825 _msg.set_height(height);
1826 _msg.set_width(width);
1827 _msg.set_is_bigendian(
false);
1828 _msg.set_point_step(4);
1829 _msg.set_row_step(4 * width);
1830 _msg.set_is_dense(
true);
1832 std::string *msgBuffer = _msg.mutable_data();
1833 msgBuffer->resize(_msg.row_step() * _msg.height());
1834 char *msgBufferIndex = msgBuffer->data();
1836 for (uint32_t j = 0; j < height; ++j)
1838 for (uint32_t i = 0; i < width; ++i)
1840 *
reinterpret_cast<float*
>(msgBufferIndex + _msg.field(0).offset()) =
1842 msgBufferIndex += _msg.point_step();
1853 uint32_t height = 4;
1856 EXPECT_EQ(height, _msg.height());
1857 EXPECT_EQ(width, _msg.width());
1858 EXPECT_FALSE(_msg.is_bigendian());
1859 EXPECT_EQ(4u, _msg.point_step());
1860 EXPECT_EQ(4U * width, _msg.row_step());
1861 EXPECT_TRUE(_msg.is_dense());
1863 char *msgBufferIndex =
const_cast<char*
>(_msg.data().data());
1865 for (uint32_t j = 0; j < height; ++j)
1867 for (uint32_t i = 0; i < width; ++i)
1870 reinterpret_cast<float*
>(msgBufferIndex + _msg.field(0).offset());
1872 EXPECT_FLOAT_EQ(
static_cast<float>(j * width + i), *value);
1873 msgBufferIndex += _msg.point_step();
1882 ignition::msgs::Header header_msg;
1885 _msg.mutable_header()->CopyFrom(header_msg);
1886 _msg.set_voltage(123);
1887 _msg.set_current(456);
1888 _msg.set_charge(789);
1889 _msg.set_capacity(321);
1890 _msg.set_percentage(654);
1891 _msg.set_power_supply_status(ignition::msgs::BatteryState::DISCHARGING);
1898 ignition::msgs::BatteryState expected_msg;
1901 ASSERT_TRUE(expected_msg.has_header());
1902 ASSERT_TRUE(_msg.has_header());
1905 EXPECT_EQ(expected_msg.voltage(), _msg.voltage());
1906 EXPECT_EQ(expected_msg.current(), _msg.current());
1907 EXPECT_EQ(expected_msg.charge(), _msg.charge());
1908 EXPECT_EQ(expected_msg.capacity(), _msg.capacity());
1909 EXPECT_EQ(expected_msg.percentage(), _msg.percentage());
1910 EXPECT_EQ(expected_msg.power_supply_status(), _msg.power_supply_status());
1917 ignition::msgs::Header header_msg;
1920 _msg.mutable_header()->CopyFrom(header_msg);
1922 _msg.set_action(ignition::msgs::Marker::ADD_MODIFY);
1925 _msg.set_type(ignition::msgs::Marker::BOX);
1926 _msg.mutable_lifetime()->set_sec(100);
1927 _msg.mutable_lifetime()->set_nsec(200);
1934 createTestMsg(*_msg.mutable_material()->mutable_specular());
1938 _msg.set_text(
"bar");
1946 ignition::msgs::Marker expected_msg;
1949 ASSERT_TRUE(expected_msg.has_header());
1950 ASSERT_TRUE(_msg.has_header());
1954 EXPECT_EQ(expected_msg.action(), _msg.action());
1955 EXPECT_EQ(expected_msg.ns(), _msg.ns());
1956 EXPECT_EQ(expected_msg.id(), _msg.id());
1957 EXPECT_EQ(expected_msg.type(), _msg.type());
1958 EXPECT_EQ(expected_msg.lifetime().sec(), _msg.lifetime().sec());
1959 EXPECT_EQ(expected_msg.lifetime().nsec(), _msg.lifetime().nsec());
1969 EXPECT_EQ(expected_msg.text(), _msg.text());
1984 ignition::msgs::Marker_V expected_msg;
1992 #endif // ROS_IGN_BRIDGE__TEST_UTILS_H_