trajectory_pt.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #include "descartes_core/trajectory_pt.h"
00020 #include "descartes_trajectory/cart_trajectory_pt.h"
00021 #include "descartes_trajectory/joint_trajectory_pt.h"
00022 #include "descartes_trajectory/axial_symmetric_pt.h"
00023 #include "ros/console.h"
00024 #include <gtest/gtest.h>
00025 
00026 using namespace descartes_core;
00027 using namespace descartes_trajectory;
00028 
00029 // Helper function for testing timing data
00030 bool equal(const descartes_core::TimingConstraint& a, const descartes_core::TimingConstraint& b)
00031 {
00032   return std::abs(a.upper - b.upper) < 0.001;
00033 }
00034 
00035 // Factory methods for trajectory point construction
00036 template <class T>
00037 TrajectoryPt* CreateTrajectoryPt();
00038 
00039 template <>
00040 TrajectoryPt* CreateTrajectoryPt<CartTrajectoryPt>()
00041 {
00042   return new CartTrajectoryPt();
00043 }
00044 
00045 template <>
00046 TrajectoryPt* CreateTrajectoryPt<JointTrajectoryPt>()
00047 {
00048   return new JointTrajectoryPt();
00049 }
00050 
00051 template <>
00052 TrajectoryPt* CreateTrajectoryPt<AxialSymmetricPt>()
00053 {
00054   return new AxialSymmetricPt();
00055 }
00056 
00057 template <class T>
00058 class TrajectoryPtTest : public testing::Test
00059 {
00060 protected:
00061   TrajectoryPtTest()
00062     : lhs_(CreateTrajectoryPt<T>())
00063     , rhs_(CreateTrajectoryPt<T>())
00064     , lhs_copy_(CreateTrajectoryPt<T>())
00065     , lhs_clone_(CreateTrajectoryPt<T>())
00066   {
00067     lhs_->setTiming(descartes_core::TimingConstraint(10.0));
00068 
00069     lhs_copy_ = lhs_->copy();
00070     lhs_clone_ = lhs_->clone();
00071     lhs_same_ = lhs_;
00072   }
00073 
00074   TrajectoryPtPtr lhs_;
00075   TrajectoryPtPtr rhs_;
00076   TrajectoryPtPtr lhs_copy_;
00077   TrajectoryPtPtr lhs_clone_;
00078   TrajectoryPtPtr lhs_same_;
00079 };
00080 
00081 using testing::Types;
00082 
00083 // Add types of trajectory points here:
00084 typedef Types<CartTrajectoryPt, JointTrajectoryPt, AxialSymmetricPt> Implementations;
00085 
00086 TYPED_TEST_CASE(TrajectoryPtTest, Implementations);
00087 
00088 TYPED_TEST(TrajectoryPtTest, construction)
00089 {
00090   EXPECT_FALSE(this->lhs_->getID().is_nil());
00091   EXPECT_FALSE(this->lhs_copy_->getID().is_nil());
00092   EXPECT_FALSE(this->lhs_clone_->getID().is_nil());
00093   EXPECT_FALSE(this->rhs_->getID().is_nil());
00094 
00095   // Depending on construction method (declaration, copy, clone, same pointer), the
00096   // objects and specifically IDs equality should be defined as follow
00097 
00098   // TODO: Implement equality checks
00099 
00100   // Declared objects should always be different
00101   // EXPECT_NE(*(this->lhs_), *(this->rhs_));
00102   EXPECT_NE(this->lhs_->getID(), this->rhs_->getID());
00103 
00104   // Copied objects should always be the same
00105   // EXPECT_EQ(*(this->lhs_), *(this->lhs_copy_));
00106   EXPECT_EQ(this->lhs_->getID(), this->lhs_copy_->getID());
00107 
00108   // Cloned objects should have the same data (we can't test, but different ids)
00109   // EXPECT_NE(*(this->lhs_), *(this->lhs_clone_));
00110   EXPECT_NE(this->lhs_->getID(), this->lhs_clone_->getID());
00111 
00112   // Pointers to the same objects should be identical (like a copy, but no ambiguity)
00113   // EXPECT_EQ(*(this->lhs_), *(this->lhs_same_));
00114   EXPECT_EQ(this->lhs_->getID(), this->lhs_same_->getID());
00115 
00116   // Copied and cloned points should have the same timing information
00117   EXPECT_TRUE(equal(this->lhs_->getTiming(), this->lhs_copy_->getTiming()));
00118   EXPECT_TRUE(equal(this->lhs_->getTiming(), this->lhs_clone_->getTiming()));
00119   EXPECT_FALSE(equal(this->lhs_->getTiming(), this->rhs_->getTiming()));
00120 }


descartes_trajectory
Author(s): Jorge Nicho
autogenerated on Thu Jun 6 2019 21:36:04