00001
00002
00003
00004
00005
00006
00007
00008
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 #include <gtest/gtest.h>
00036 #include "joint_states_settler/joint_states_deflater.h"
00037
00038 using namespace std;
00039 using namespace joint_states_settler;
00040 using namespace sensor_msgs;
00041
00042 static const double eps = 1e-10;
00043
00044 TEST(JointStatesDeflator, easy1)
00045 {
00046 JointStatesDeflater deflater;
00047
00048 vector<string> joint_names;
00049 joint_names.resize(2);
00050 joint_names[0] = "A";
00051 joint_names[1] = "C";
00052 deflater.setDeflationJointNames(joint_names);
00053
00054 JointStatePtr joint_states;
00055 DeflatedJointStates deflated_msg;
00056 JointState pruned;
00057
00058
00059
00060 joint_states.reset(new JointState);
00061 joint_states->name.resize(3);
00062 joint_states->position.resize(3);
00063 joint_states->velocity.resize(3);
00064 joint_states->effort.resize(3);
00065 joint_states->name[0] = "A";
00066 joint_states->name[1] = "B";
00067 joint_states->name[2] = "C";
00068 joint_states->position[0] = 1.0;
00069 joint_states->position[1] = 2.0;
00070 joint_states->position[2] = 3.0;
00071
00072 deflater.deflate(joint_states, deflated_msg);
00073 deflater.prune(*joint_states, pruned);
00074
00075 ASSERT_EQ(deflated_msg.channels_.size(), (unsigned int) 2);
00076 EXPECT_NEAR(deflated_msg.channels_[0], 1.0, eps);
00077 EXPECT_NEAR(deflated_msg.channels_[1], 3.0, eps);
00078
00079 ASSERT_EQ(pruned.name.size(), (unsigned int) 2);
00080 ASSERT_EQ(pruned.position.size(), (unsigned int) 2);
00081 EXPECT_EQ(pruned.name[0], "A");
00082 EXPECT_EQ(pruned.name[1], "C");
00083 EXPECT_NEAR(pruned.position[0], 1.0, eps);
00084 EXPECT_NEAR(pruned.position[1], 3.0, eps);
00085
00086
00087
00088 joint_states.reset(new JointState);
00089 joint_states->name.resize(3);
00090 joint_states->position.resize(3);
00091 joint_states->velocity.resize(3);
00092 joint_states->effort.resize(3);
00093 joint_states->name[0] = "C";
00094 joint_states->name[1] = "A";
00095 joint_states->name[2] = "B";
00096 joint_states->position[0] = 4.0;
00097 joint_states->position[1] = 5.0;
00098 joint_states->position[2] = 6.0;
00099
00100 deflater.deflate(joint_states, deflated_msg);
00101 deflater.prune(*joint_states, pruned);
00102
00103 EXPECT_EQ(deflated_msg.channels_.size(), (unsigned int) 2);
00104 EXPECT_NEAR(deflated_msg.channels_[0], 5.0, eps);
00105 EXPECT_NEAR(deflated_msg.channels_[1], 4.0, eps);
00106
00107 ASSERT_EQ(pruned.name.size(), (unsigned int) 2);
00108 ASSERT_EQ(pruned.position.size(), (unsigned int) 2);
00109 EXPECT_EQ(pruned.name[0], "A");
00110 EXPECT_EQ(pruned.name[1], "C");
00111 EXPECT_NEAR(pruned.position[0], 5.0, eps);
00112 EXPECT_NEAR(pruned.position[1], 4.0, eps);
00113
00114
00115
00116 joint_states.reset(new JointState);
00117 joint_states->name.resize(4);
00118 joint_states->position.resize(4);
00119 joint_states->velocity.resize(4);
00120 joint_states->effort.resize(4);
00121 joint_states->name[0] = "D";
00122 joint_states->name[1] = "C";
00123 joint_states->name[2] = "B";
00124 joint_states->name[3] = "A";
00125 joint_states->position[0] = 7.0;
00126 joint_states->position[1] = 8.0;
00127 joint_states->position[2] = 9.0;
00128 joint_states->position[3] = 10.0;
00129
00130 deflater.deflate(joint_states, deflated_msg);
00131 deflater.prune(*joint_states, pruned);
00132
00133 EXPECT_EQ(deflated_msg.channels_.size(), (unsigned int) 2);
00134 EXPECT_NEAR(deflated_msg.channels_[0], 10.0, eps);
00135 EXPECT_NEAR(deflated_msg.channels_[1], 8.0, eps);
00136
00137 ASSERT_EQ(pruned.name.size(), (unsigned int) 2);
00138 ASSERT_EQ(pruned.position.size(), (unsigned int) 2);
00139 EXPECT_EQ(pruned.name[0], "A");
00140 EXPECT_EQ(pruned.name[1], "C");
00141 EXPECT_NEAR(pruned.position[0], 10.0, eps);
00142 EXPECT_NEAR(pruned.position[1], 8.0, eps);
00143 }
00144
00145
00146 int main(int argc, char **argv){
00147 testing::InitGoogleTest(&argc, argv);
00148 return RUN_ALL_TESTS();
00149 }