Go to the documentation of this file.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 #include "dx100/utils.h"
00033 #include "dx100/definitions.h"
00034 #include "dx100/trajectory_job.h"
00035 #include "simple_message/joint_traj.h"
00036 #include "simple_message/log_wrapper.h"
00037 
00038 #include <vector>
00039 #include <iostream>
00040 #include <fstream>
00041 #include <gtest/gtest.h>
00042 
00043 using namespace motoman::utils;
00044 using namespace motoman::trajectory_job;
00045 using namespace industrial::joint_traj;
00046 using namespace industrial::joint_traj_pt;
00047 using namespace industrial::joint_data;
00048 
00049 
00050 TEST(Utils, hasSuffix)
00051 {
00052   std::string test = "prefix_root_suffix";
00053   std::string suffix = "suffix";
00054   std::string root = "root";
00055   std::string prefix = "prefix";
00056   std::string empty = "";
00057   EXPECT_TRUE(hasSuffix(test, test));
00058   EXPECT_TRUE(hasSuffix(test, suffix));
00059   EXPECT_FALSE(hasSuffix(test, root));
00060   EXPECT_FALSE(hasSuffix(test, prefix));
00061   EXPECT_TRUE(hasSuffix(test, empty));
00062 
00063 }
00064 
00065 TEST(Utils, checkJointNames)
00066 {
00067         trajectory_msgs::JointTrajectoryPtr base_msg(new trajectory_msgs::JointTrajectory());
00068         trajectory_msgs::JointTrajectoryConstPtr msg(base_msg);
00069   EXPECT_TRUE(checkJointNames(msg));
00070   base_msg->joint_names.push_back("joint_s");
00071   EXPECT_TRUE(checkJointNames(msg));
00072   base_msg->joint_names.push_back("prefix_joint_l");
00073   EXPECT_TRUE(checkJointNames(msg));
00074   base_msg->joint_names.push_back("bad_joint");
00075   EXPECT_FALSE(checkJointNames(msg));
00076   base_msg->joint_names.clear();
00077   base_msg->joint_names.resize(motoman::parameters::Parameters::JOINT_SUFFIXES_SIZE + 1 );
00078   EXPECT_FALSE(checkJointNames(msg));
00079 
00080   base_msg->joint_names.clear();
00081   for (int i = 0; i < motoman::parameters::Parameters::JOINT_SUFFIXES_SIZE; i++)
00082   {
00083         base_msg->joint_names.push_back(motoman::parameters::Parameters::JOINT_SUFFIXES[i]);
00084   }
00085   EXPECT_TRUE(checkJointNames(msg));
00086 }
00087 
00088 TEST(Utils, toMotomanVelocity)
00089 {
00090   std::vector<double> vel;
00091   std::vector<double> lim;
00092 
00093   vel.push_back(1.0);
00094   lim.push_back(2.0);
00095 
00096   EXPECT_FLOAT_EQ(toMotomanVelocity(lim, vel), 1.0/2.0);
00097   EXPECT_FLOAT_EQ(toMotomanVelocity(vel, lim), 1.0);
00098 
00099   vel.push_back(2.0);
00100   lim.push_back(3.0);
00101 
00102   EXPECT_FLOAT_EQ(toMotomanVelocity(lim, vel), 2.0/3.0);
00103 
00104   vel.push_back(3.0);
00105   EXPECT_FLOAT_EQ(toMotomanVelocity(lim, vel), 0.0);
00106 
00107   lim.push_back(4.0);
00108   lim.push_back(5.0);
00109   EXPECT_FLOAT_EQ(toMotomanVelocity(lim, vel), 0.0);
00110 
00111 }
00112 
00113 TEST(DISABLED_TrajectoryJob, init)
00114 {
00115 
00116   using namespace std;
00117 
00118   TrajectoryJob job;
00119   JointTraj traj;
00120   JointTrajPt pt;
00121   JointData init;
00122   string job_name = "JOB_NAME";
00123   string job_ext = ".JBI";
00124 
00125   const int TRAJ_SIZE = 50;
00126   const int BIG_JOB_BUFFER_SIZE = 500000;
00127   char bigJobBuffer[BIG_JOB_BUFFER_SIZE];
00128   const int SMALL_JOB_BUFFER_SIZE = 10;
00129   char smallJobBuffer[SMALL_JOB_BUFFER_SIZE];
00130 
00131   for (int i = 1; i <= TRAJ_SIZE; i++)
00132   {
00133     
00134     for (int j = 0; j < init.getMaxNumJoints(); j++)
00135     {
00136       
00137       ASSERT_TRUE(init.setJoint(j, (i*(j+1))));
00138     }
00139     pt.init(i, init, 11.1111, 0.01);
00140     ASSERT_TRUE(traj.addPoint(pt));
00141   }
00142 
00143   EXPECT_FALSE(job.init("this name is way too long to be the name of a file and this should fail"));
00144   ASSERT_TRUE(job.init((char*)job_name.c_str()));
00145 
00146   EXPECT_FALSE(job.toJobString(traj, &smallJobBuffer[0], SMALL_JOB_BUFFER_SIZE));
00147   
00148   
00149   
00150   EXPECT_TRUE(job.toJobString(traj, &bigJobBuffer[0], BIG_JOB_BUFFER_SIZE));
00151   ofstream file;
00152   job_name.append(job_ext);
00153   file.open(job_name.c_str());
00154   ASSERT_TRUE(file.is_open());
00155   file << bigJobBuffer;
00156   file.close();
00157 
00158 
00159 }
00160 
00161 
00162 
00163 
00164 int main(int argc, char **argv)
00165 {
00166   testing::InitGoogleTest(&argc, argv);
00167   return RUN_ALL_TESTS();
00168 }
00169