JointTrajectoryManager_Test.cpp
Go to the documentation of this file.
00001 /*
00002  * JointTrajectoryManager_Test.cpp
00003  *
00004  *  Created on: Sept 05, 2012
00005  *      Author: Ross Taylor
00006  */
00007 
00008 #include <iostream>
00009 #include <gtest/gtest.h>
00010 #include "robodyn_controllers/JointTrajectoryManager.h"
00011 #include <tf/tf.h>
00012 
00013 class JointTrajectoryManagerTest : public ::testing::Test
00014 {
00015 protected:
00016     class derivedManager : public JointTrajectoryManager
00017     {
00018     public:
00019         struct GoalIdCompare : public std::binary_function<actionlib_msgs::GoalID, actionlib_msgs::GoalID, bool>
00020         {
00021             bool operator()(const actionlib_msgs::GoalID& left, const actionlib_msgs::GoalID& right) const
00022             {
00023                 return (left.stamp < right.stamp || (left.stamp == right.stamp && left.id < right.id));
00024             }
00025         };
00026 
00027         std::map<actionlib_msgs::GoalID, bool, GoalIdCompare> activeGoals;
00028 
00029     protected:
00030         bool isActive(const actionlib_msgs::GoalID& goalId) const
00031         {
00032             if (activeGoals.find(goalId) == activeGoals.end())
00033             {
00034                 return false;
00035             }
00036             else
00037             {
00038                 return activeGoals.at(goalId);
00039             }
00040         }
00041     };
00042 
00043     virtual void SetUp()
00044     {
00045         manager = new derivedManager();
00046     }
00047 
00048     virtual void TearDown()
00049     {
00050         // delete stuff, etc.
00051         delete manager;
00052     }
00053 
00054     derivedManager* manager; // pointer for easy destruction between tests
00055 };
00056 
00057 // TEST_F uses SetUp/TearDown in Test above
00058 // second argument describes the test (make descriptive)
00059 TEST_F(JointTrajectoryManagerTest, managerTest)
00060 {
00061     // EXPECT_EQ (test equality)
00062     // EXPECT_FLOAT_EQ (test equality, with roundoff allowed)
00063     // EXPECT_TRUE
00064     // EXPECT_FALSE
00065     // EXPECT_THROW
00066     // google google test for more
00067     trajectory_msgs::JointTrajectory trajectory;
00068     trajectory.header.frame_id = "testGoal1";
00069     ros::Time::init();
00070     trajectory.header.stamp = ros::Time::now();
00071     trajectory.joint_names.push_back("joint0");
00072     trajectory.joint_names.push_back("joint1");
00073     trajectory.joint_names.push_back("joint2");
00074 
00075     trajectory_msgs::JointTrajectoryPoint point;
00076     point.positions.push_back(1.0);
00077     point.positions.push_back(2.0);
00078     point.positions.push_back(3.0);
00079     point.time_from_start = ros::Duration(1.1);
00080     trajectory.points.push_back(point);
00081 
00082     actionlib_msgs::GoalID goalId;
00083     goalId.id = trajectory.header.frame_id;
00084     goalId.stamp = trajectory.header.stamp;
00085     manager->addToJointGoalMap(trajectory.joint_names, goalId);
00086     manager->activeGoals[goalId] = true;
00087 
00088     EXPECT_THROW(manager->removeFromJointGoalMap(goalId), std::runtime_error);
00089     manager->activeGoals.erase(goalId);
00090     EXPECT_NO_THROW(manager->removeFromJointGoalMap(goalId));
00091     EXPECT_NO_THROW(manager->addToJointGoalMap(trajectory.joint_names, goalId));
00092     goalId.stamp = ros::Time::now();
00093     EXPECT_NO_THROW(manager->addToJointGoalMap(trajectory.joint_names, goalId));
00094 }
00095 
00096 int main(int argc, char** argv)
00097 {
00098     testing::InitGoogleTest(&argc, argv);
00099     return RUN_ALL_TESTS();
00100 }


robodyn_controllers
Author(s):
autogenerated on Sat Jun 8 2019 20:20:53