2 #include <gtest/gtest.h> 5 #include <sensor_msgs/JointState.h> 6 #include <sensor_msgs/NavSatStatus.h> 7 #include <sensor_msgs/Imu.h> 8 #include <sensor_msgs/Image.h> 9 #include <std_msgs/Int16MultiArray.h> 15 TEST(Deserialize, JointState)
25 sensor_msgs::JointState joint_state;
29 joint_state.header.seq = 2016;
30 joint_state.header.stamp.sec = 1234;
31 joint_state.header.stamp.nsec = 567*1000*1000;
32 joint_state.header.frame_id =
"pippo";
34 joint_state.name.resize( NUM );
35 joint_state.position.resize( NUM );
36 joint_state.velocity.resize( NUM );
37 joint_state.effort.resize( NUM );
39 std::string names[NUM];
44 for (
int i=0;
i<NUM;
i++)
46 joint_state.name[
i] = names[
i%3];
47 joint_state.position[
i]= 10+
i;
48 joint_state.velocity[
i]= 30+
i;
49 joint_state.effort[
i]= 50+
i;
60 for(
auto&it: flat_container.
value) {
61 std::cout << it.first <<
" >> " << it.second.convert<
double>() << std::endl;
64 for(
auto&it: flat_container.
name) {
65 std::cout << it.first <<
" >> " << it.second << std::endl;
69 EXPECT_EQ( flat_container.
value[0].first.toStdString() , (
"JointState/header/seq"));
71 EXPECT_EQ( flat_container.
value[1].first.toStdString() , (
"JointState/header/stamp"));
72 EXPECT_EQ( flat_container.
value[1].second.convert<
double>(),
double(1234.567) );
75 EXPECT_EQ( flat_container.
value[2].first.toStdString() , (
"JointState/position.0"));
77 EXPECT_EQ( flat_container.
value[3].first.toStdString() , (
"JointState/position.1"));
79 EXPECT_EQ( flat_container.
value[4].first.toStdString() , (
"JointState/position.2"));
81 EXPECT_EQ( flat_container.
value[16].first.toStdString() , (
"JointState/position.14"));
84 EXPECT_EQ( flat_container.
value[17].first.toStdString() , (
"JointState/velocity.0"));
86 EXPECT_EQ( flat_container.
value[18].first.toStdString() , (
"JointState/velocity.1"));
88 EXPECT_EQ( flat_container.
value[19].first.toStdString() , (
"JointState/velocity.2"));
90 EXPECT_EQ( flat_container.
value[31].first.toStdString() , (
"JointState/velocity.14"));
93 EXPECT_EQ( flat_container.
value[32].first.toStdString() , (
"JointState/effort.0"));
95 EXPECT_EQ( flat_container.
value[33].first.toStdString() , (
"JointState/effort.1"));
97 EXPECT_EQ( flat_container.
value[34].first.toStdString() , (
"JointState/effort.2"));
99 EXPECT_EQ( flat_container.
value[46].first.toStdString() , (
"JointState/effort.14"));
102 EXPECT_EQ( flat_container.
name[0].first.toStdString() , (
"JointState/header/frame_id"));
105 EXPECT_EQ( flat_container.
name[1].first.toStdString() , (
"JointState/name.0"));
107 EXPECT_EQ( flat_container.
name[2].first.toStdString() , (
"JointState/name.1"));
109 EXPECT_EQ( flat_container.
name[3].first.toStdString() , (
"JointState/name.2"));
113 std::vector<std_msgs::Header> headers;
117 std_msgs::Header
msg;
120 headers.push_back( std::move(msg) );
125 std_msgs::Header
msg;
147 buffer_view, callbackReadAndStore);
150 const std_msgs::Header&
header = headers[0];
151 EXPECT_EQ(header.seq, joint_state.header.seq);
152 EXPECT_EQ(header.stamp.sec, joint_state.header.stamp.sec);
153 EXPECT_EQ(header.stamp.nsec, joint_state.header.stamp.nsec);
154 EXPECT_EQ(header.frame_id, joint_state.header.frame_id);
157 buffer_view, callbackOverwiteInPlace);
160 buffer_view, callbackReadAndStore);
163 const std_msgs::Header& header_mutated = headers[1];
170 TEST( Deserialize, NavSatStatus)
181 sensor_msgs::NavSatStatus nav_stat;
182 nav_stat.status = nav_stat.STATUS_GBAS_FIX;
183 nav_stat.service = nav_stat.SERVICE_COMPASS;
193 if(
VERBOSE_TEST){ std::cout <<
" -------------------- " << std::endl;
195 for(
auto&it: flat_container.
value) {
196 std::cout << it.first <<
" >> " << it.second.convert<
double>() << std::endl;
200 EXPECT_EQ( flat_container.
value[0].first.toStdString() , (
"nav_stat/status"));
201 EXPECT_EQ( flat_container.
value[0].second.convert<
int>(), (
int)nav_stat.STATUS_GBAS_FIX );
202 EXPECT_EQ( flat_container.
value[1].first.toStdString() , (
"nav_stat/service"));
203 EXPECT_EQ( flat_container.
value[1].second.convert<
int>(), (
int)nav_stat.SERVICE_COMPASS );
206 TEST( Deserialize, DeserializeIMU)
219 imu.header.seq = 2016;
220 imu.header.stamp.sec = 1234;
221 imu.header.stamp.nsec = 567*1000*1000;
222 imu.header.frame_id =
"pippo";
224 imu.orientation.x = 11;
225 imu.orientation.y = 12;
226 imu.orientation.z = 13;
227 imu.orientation.w = 14;
229 imu.angular_velocity.x = 21;
230 imu.angular_velocity.y = 22;
231 imu.angular_velocity.z = 23;
233 imu.linear_acceleration.x = 31;
234 imu.linear_acceleration.y = 32;
235 imu.linear_acceleration.z = 33;
237 for (
int i=0;
i<9;
i++)
239 imu.orientation_covariance[
i] = 40+
i;
240 imu.angular_velocity_covariance[
i] = 50+
i;
241 imu.linear_acceleration_covariance[
i] = 60+
i;
254 std::cout <<
" -------------------- " << std::endl;
255 for(
auto&it: flat_container.
value) {
256 std::cout << it.first <<
" >> " << it.second.convert<
double>() << std::endl;
262 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/header/seq"));
263 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 2016 );
265 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/header/stamp"));
266 EXPECT_EQ( flat_container.
value[index].second.convert<
double>(),
double(1234.567) );
269 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/orientation/x"));
270 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 11 );
272 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/orientation/y"));
273 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 12 );
275 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/orientation/z"));
276 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 13 );
278 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/orientation/w"));
279 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 14 );
282 for(
int i=0;
i<9;
i++)
285 sprintf(str,
"imu/orientation_covariance.%d",i);
286 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (str) );
287 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 40+i );
291 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/angular_velocity/x"));
292 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 21 );
294 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/angular_velocity/y"));
295 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 22 );
297 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/angular_velocity/z"));
298 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 23 );
301 for(
int i=0;
i<9;
i++)
304 sprintf(str,
"imu/angular_velocity_covariance.%d",i);
305 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (str) );
306 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 50+i );
310 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/linear_acceleration/x"));
311 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 31 );
313 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/linear_acceleration/y"));
314 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 32 );
316 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (
"imu/linear_acceleration/z"));
317 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 33 );
320 for(
int i=0;
i<9;
i++)
323 sprintf(str,
"imu/linear_acceleration_covariance.%d",i);
324 EXPECT_EQ( flat_container.
value[index].first.toStdString() , (str) );
325 EXPECT_EQ( flat_container.
value[index].second.convert<
int>(), 60+i );
387 TEST( Deserialize, Int16MultiArrayDeserialize)
399 const unsigned N = 6;
400 multi_array.layout.data_offset = 42;
401 multi_array.data.resize(N);
403 for (
unsigned i=0;
i<
N;
i++){
404 multi_array.data[
i] =
i;
420 std::cout <<
" -------------------- " << std::endl;
422 for(
auto&it: flat_container.
value) {
423 std::cout << it.first <<
" >> " << it.second.convert<
double>() << std::endl;
428 TEST( Deserialize, SensorImage)
440 image.step = 3*image.width;
441 image.data.resize( image.height * image.step );
459 int main(
int argc,
char **argv){
460 testing::InitGoogleTest(&argc, argv);
461 return RUN_ALL_TESTS();
std::function< void(const ROSType &, absl::Span< uint8_t > &)> VisitingCallback
TEST(Deserialize, JointState)
EXPECT_EQ(flat_container.value[index].first.toStdString(),("imu/header/seq"))
static void write(Stream &stream, typename boost::call_traits< T >::param_type t)
std::vector< std::pair< StringTreeLeaf, std::string > > name
int main(int argc, char **argv)
RosIntrospection::Parser parser
void applyVisitorToBuffer(const std::string &msg_identifier, const ROSType &monitored_type, absl::Span< uint8_t > &buffer, VisitingCallback callback) const
std_msgs::Header * header(M &m)
std_msgs::Int16MultiArray multi_array
void serialize(Stream &stream, const T &t)
std::vector< std::pair< StringTreeLeaf, Variant > > value
bool deserializeIntoFlatContainer(const std::string &msg_identifier, absl::Span< uint8_t > buffer, FlatMessage *flat_container_output, const uint32_t max_array_size) const
FlatMessage flat_container
uint32_t serializationLength(const T &t)
ros::serialization::OStream stream(buffer.data(), buffer.size())
std::vector< uint8_t > buffer(ros::serialization::serializationLength(imu))
void deserialize(Stream &stream, T &t)
EXPECT_NO_THROW(parser.deserializeIntoFlatContainer("multi_array", absl::Span< uint8_t >(buffer),&flat_container, 100))
void registerMessageDefinition(const std::string &message_identifier, const ROSType &main_type, const std::string &definition)