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,
00031            const descartes_core::TimingConstraint& b)
00032 {
00033   return std::abs(a.upper - b.upper) < 0.001;
00034 }
00035 
00036 // Factory methods for trajectory point construction
00037 template <class T>
00038 TrajectoryPt* CreateTrajectoryPt();
00039 
00040 template <>
00041 TrajectoryPt* CreateTrajectoryPt<CartTrajectoryPt>()
00042 {
00043   return new CartTrajectoryPt();
00044 }
00045 
00046 template <>
00047 TrajectoryPt* CreateTrajectoryPt<JointTrajectoryPt>()
00048 {
00049   return new JointTrajectoryPt();
00050 }
00051 
00052 template <>
00053 TrajectoryPt* CreateTrajectoryPt<AxialSymmetricPt>()
00054 {
00055   return new AxialSymmetricPt();
00056 }
00057 
00058 template <class T>
00059 class TrajectoryPtTest : public testing::Test {
00060  protected:
00061 
00062   TrajectoryPtTest() 
00063     : lhs_(CreateTrajectoryPt<T>()) 
00064     , rhs_(CreateTrajectoryPt<T>())
00065     , lhs_copy_(CreateTrajectoryPt<T>())
00066     , lhs_clone_(CreateTrajectoryPt<T>())
00067   {
00068     lhs_->setTiming(descartes_core::TimingConstraint(10.0));
00069     
00070     lhs_copy_ = lhs_->copy();
00071     lhs_clone_ = lhs_->clone();
00072     lhs_same_ = lhs_;
00073   }
00074 
00075   TrajectoryPtPtr lhs_;
00076   TrajectoryPtPtr rhs_;
00077   TrajectoryPtPtr lhs_copy_;
00078   TrajectoryPtPtr lhs_clone_;
00079   TrajectoryPtPtr lhs_same_;
00080 };
00081 
00082 using testing::Types;
00083 
00084 // Add types of trajectory points here:
00085 typedef Types<CartTrajectoryPt, JointTrajectoryPt, AxialSymmetricPt> Implementations;
00086 
00087 TYPED_TEST_CASE(TrajectoryPtTest, Implementations);
00088 
00089 TYPED_TEST(TrajectoryPtTest, construction) {
00090 
00091   EXPECT_FALSE(this->lhs_->getID().is_nil());
00092   EXPECT_FALSE(this->lhs_copy_->getID().is_nil());
00093   EXPECT_FALSE(this->lhs_clone_->getID().is_nil());
00094   EXPECT_FALSE(this->rhs_->getID().is_nil());
00095 
00096   //Depending on construction method (declaration, copy, clone, same pointer), the
00097   //objects and specifically IDs equality should be defined as follow
00098 
00099   //TODO: Implement equality checks
00100 
00101   //Declared objects should always be different
00102   //EXPECT_NE(*(this->lhs_), *(this->rhs_));
00103   EXPECT_NE(this->lhs_->getID(), this->rhs_->getID());
00104 
00105   //Copied objects should always be the same
00106   //EXPECT_EQ(*(this->lhs_), *(this->lhs_copy_));
00107   EXPECT_EQ(this->lhs_->getID(), this->lhs_copy_->getID());
00108 
00109   //Cloned objects should have the same data (we can't test, but different ids)
00110   //EXPECT_NE(*(this->lhs_), *(this->lhs_clone_));
00111   EXPECT_NE(this->lhs_->getID(), this->lhs_clone_->getID());
00112 
00113   //Pointers to the same objects should be identical (like a copy, but no ambiguity)
00114   //EXPECT_EQ(*(this->lhs_), *(this->lhs_same_));
00115   EXPECT_EQ(this->lhs_->getID(), this->lhs_same_->getID());
00116 
00117   // Copied and cloned points should have the same timing information
00118   EXPECT_TRUE(equal(this->lhs_->getTiming(), this->lhs_copy_->getTiming()));
00119   EXPECT_TRUE(equal(this->lhs_->getTiming(), this->lhs_clone_->getTiming()));
00120   EXPECT_FALSE(equal(this->lhs_->getTiming(), this->rhs_->getTiming()));
00121 }


descartes_trajectory
Author(s): Jorge Nicho
autogenerated on Wed Aug 26 2015 11:21:27