00001 #include "transform_graph/transform.h"
00002
00003 #include <gtest/gtest.h>
00004
00005 namespace transform_graph {
00006 TEST(TestTransform, TestDefaultIsIdentity) {
00007 Transform t;
00008 Eigen::Matrix4d expected;
00009
00010 expected << 1, 0, 0, 0,
00011 0, 1, 0, 0,
00012 0, 0, 1, 0,
00013 0, 0, 0, 1;
00014
00015 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00016 }
00017
00018 TEST(TestTransform, TestIdentity) {
00019 Transform t = Transform::Identity();
00020 Eigen::Matrix4d expected;
00021
00022 expected << 1, 0, 0, 0,
00023 0, 1, 0, 0,
00024 0, 0, 1, 0,
00025 0, 0, 0, 1;
00026
00027 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00028 }
00029
00030 TEST(TestTransform, TestPosOri) {
00031 transform_graph::Position pos(10, 5, 0);
00032 Eigen::Matrix3d rot;
00033
00034 rot << 0.86603, -0.5, 0,
00035 0.5, 0.86603, 0,
00036 0, 0, 1;
00037
00038 transform_graph::Orientation ori(rot);
00039 Transform t(pos, ori);
00040
00041 Eigen::Matrix4d expected;
00042
00043 expected << 0.86603, -0.5, 0, 10,
00044 0.5, 0.86603, 0, 5,
00045 0, 0, 1, 0,
00046 0, 0, 0, 1;
00047
00048 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.00001));
00049 }
00050
00051 TEST(TestTransform, TestTfTransform) {
00052
00053 tf::Matrix3x3 rot(0.86603, -0.5, 0,
00054 0.5, 0.86603, 0,
00055 0, 0, 1);
00056
00057 tf::Vector3 pos(10, 5, 0);
00058 tf::Transform trans(rot, pos);
00059 Transform t(trans);
00060
00061 Eigen::Matrix4d expected;
00062
00063 expected << 0.86603, -0.5, 0, 10,
00064 0.5, 0.86603, 0, 5,
00065 0, 0, 1, 0,
00066 0, 0, 0, 1;
00067
00068 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00069 }
00070
00071 TEST(TestTransform, TestGeometryMsgsPose) {
00072 geometry_msgs::Pose pose;
00073 pose.orientation.w = 0.96592702;
00074 pose.orientation.x = 0;
00075 pose.orientation.y = 0;
00076 pose.orientation.z = 0.25881873;
00077 pose.position.x = 10;
00078 pose.position.y = 5;
00079 Transform t(pose);
00080
00081 Eigen::Matrix4d expected;
00082
00083 expected << 0.86603, -0.5, 0, 10,
00084 0.5, 0.86603, 0, 5,
00085 0, 0, 1, 0,
00086 0, 0, 0, 1;
00087
00088 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00089 }
00090
00091 TEST(TestTransform, TestEigenAffine) {
00092 Eigen::Matrix4d input;
00093
00094 input << 0.86603, -0.5, 0, 10,
00095 0.5, 0.86603, 0, 5,
00096 0, 0, 1, 0,
00097 0, 0, 0, 1;
00098
00099 Eigen::Affine3d affine(input);
00100 Transform t(affine);
00101 Eigen::Matrix4d expected;
00102
00103 expected << 0.86603, -0.5, 0, 10,
00104 0.5, 0.86603, 0, 5,
00105 0, 0, 1, 0,
00106 0, 0, 0, 1;
00107
00108 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00109 }
00110
00111 TEST(TestTransform, TestEigenMatrix) {
00112 Eigen::Matrix4d input;
00113
00114 input << 0.86603, -0.5, 0, 10,
00115 0.5, 0.86603, 0, 5,
00116 0, 0, 1, 0,
00117 0, 0, 0, 1;
00118
00119 Transform t(input);
00120 Eigen::Matrix4d expected;
00121
00122 expected << 0.86603, -0.5, 0, 10,
00123 0.5, 0.86603, 0, 5,
00124 0, 0, 1, 0,
00125 0, 0, 0, 1;
00126
00127 EXPECT_TRUE(expected.isApprox(t.matrix(), 0.000001));
00128 }
00129
00130 TEST(TestTransform, TestInverse) {
00131 Eigen::Matrix4d input;
00132
00133 input << 0.866, -0.5, 0, 4,
00134 0.5, 0.866, 0, 3,
00135 0, 0, 1, 0,
00136 0, 0, 0, 1;
00137
00138 Transform t(input);
00139 Eigen::Matrix4d expected;
00140
00141 expected << 0.866, 0.5, 0, -4.964,
00142 -0.5, 0.866, 0, -0.598,
00143 0, 0, 1, 0,
00144 0, 0, 0, 1;
00145
00146 EXPECT_TRUE(expected.isApprox(t.inverse().matrix(), 0.0001));
00147 }
00148 }
00149
00150 int main(int argc, char **argv) {
00151 testing::InitGoogleTest(&argc, argv);
00152 return RUN_ALL_TESTS();
00153 }