Go to the documentation of this file.00001 #include "config.h"
00002 #include <gtest/gtest.h>
00003
00004 #include <sensor_msgs/JointState.h>
00005 #include "ros_type_introspection/ros_introspection.hpp"
00006
00007 using namespace ros::message_traits;
00008 using namespace RosIntrospection;
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 TEST(Renamer2, DeserializeJointStateAndRename)
00103 {
00104 RosIntrospection::Parser parser;
00105
00106 std::vector<SubstitutionRule> rules;
00107 rules.push_back( SubstitutionRule("position.#", "name.#", "@/pos") );
00108 rules.push_back( SubstitutionRule("velocity.#", "name.#", "@/vel") );
00109 rules.push_back( SubstitutionRule("effort.#", "name.#", "@/eff") );
00110
00111 ROSType main_type( DataType<sensor_msgs::JointState>::value() );
00112
00113 parser.registerMessageDefinition(
00114 "JointState", main_type,
00115 Definition<sensor_msgs::JointState>::value());
00116
00117 parser.registerRenamingRules( main_type, rules);
00118
00119 sensor_msgs::JointState joint_state;
00120
00121 joint_state.header.seq = 2016;
00122 joint_state.header.stamp.sec = 1234;
00123 joint_state.header.stamp.nsec = 567*1000*1000;
00124 joint_state.header.frame_id = "pippo";
00125
00126 joint_state.name.resize( 3 );
00127 joint_state.position.resize( 3 );
00128 joint_state.velocity.resize( 3 );
00129 joint_state.effort.resize( 3 );
00130
00131 std::string names[3];
00132 names[0] = ("hola");
00133 names[1] = ("ciao");
00134 names[2] = ("bye");
00135
00136 for (int i=0; i<3; i++)
00137 {
00138 joint_state.name[i] = names[i];
00139 joint_state.position[i]= 11+i;
00140 joint_state.velocity[i]= 21+i;
00141 joint_state.effort[i]= 31+i;
00142 }
00143
00144 std::vector<uint8_t> buffer( ros::serialization::serializationLength(joint_state) );
00145 ros::serialization::OStream stream(buffer.data(), buffer.size());
00146 ros::serialization::Serializer<sensor_msgs::JointState>::write(stream, joint_state);
00147
00148 FlatMessage flat_container;
00149 RenamedValues renamed_value;
00150
00151 parser.deserializeIntoFlatContainer("JointState", absl::Span<uint8_t>(buffer), &flat_container,100);
00152 parser.applyNameTransform("JointState", flat_container, &renamed_value);
00153
00154 if(VERBOSE_TEST)
00155 {
00156 std::cout << "----------------\n";
00157 for(auto&it: flat_container.value) {
00158 std::cout << it.first.toStdString() << " >> " << it.second.convert<double>() << std::endl;
00159 }
00160 std::cout << "----------------\n";
00161 for(auto&it: renamed_value) {
00162 std::cout << it.first << " >> " << it.second.convert<double>() << std::endl;
00163 }
00164 std::cout << "----------------\n";
00165 }
00166
00167 int i = 0;
00168
00169 EXPECT_EQ( renamed_value[i].first , ("JointState/header/seq"));
00170 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 2016 );
00171
00172 EXPECT_EQ( renamed_value[i].first , ("JointState/header/stamp"));
00173 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 1234.567 );
00174
00175 EXPECT_EQ( renamed_value[i].first , ("JointState/hola/pos"));
00176 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 11 );
00177
00178 EXPECT_EQ( renamed_value[i].first , ("JointState/ciao/pos"));
00179 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 12 );
00180
00181 EXPECT_EQ( renamed_value[i].first , ("JointState/bye/pos"));
00182 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 13 );
00183
00184 EXPECT_EQ( renamed_value[i].first , ("JointState/hola/vel"));
00185 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 21 );
00186
00187 EXPECT_EQ( renamed_value[i].first , ("JointState/ciao/vel"));
00188 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 22 );
00189
00190 EXPECT_EQ( renamed_value[i].first , ("JointState/bye/vel"));
00191 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 23 );
00192
00193 EXPECT_EQ( renamed_value[i].first , ("JointState/hola/eff"));
00194 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 31 );
00195
00196 EXPECT_EQ( renamed_value[i].first , ("JointState/ciao/eff"));
00197 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 32 );
00198
00199 EXPECT_EQ( renamed_value[i].first , ("JointState/bye/eff"));
00200 EXPECT_EQ( renamed_value[i++].second.convert<double>(), 33 );
00201
00202 }
00203