hand_commander_test.cpp
Go to the documentation of this file.
00001 
00002 // We are testing this
00003 #include "sr_hand/hand_commander.hpp"
00004 
00005 // ROS
00006 #include "ros/ros.h"
00007 
00008 // Gtest
00009 #include <gtest/gtest.h>
00010 
00011 using namespace std;
00012 using namespace shadowrobot;
00013 
00014 TEST(HandCommander, constructor)
00015 {
00016     HandCommander handcmd = HandCommander();
00017     EXPECT_TRUE(true);
00018 }
00019 
00020 TEST(HandCommander, topic_state)
00021 {
00022     HandCommander handcmd = HandCommander();
00023 
00024     // get_controller_state_topic returns fully resolved topics
00025     ros::NodeHandle nh;
00026 
00027     std::string topic = handcmd.get_controller_state_topic("ffj3");
00028     EXPECT_EQ(nh.resolveName("sh_ffj3_position_controller/state"), topic);
00029 
00030     topic = handcmd.get_controller_state_topic("ffj0");
00031     EXPECT_EQ(nh.resolveName("sh_ffj0_position_controller/state"), topic);
00032 
00033     topic = handcmd.get_controller_state_topic("unknown joint");
00034     EXPECT_EQ("", topic);
00035 }
00036 
00037 TEST(HandCommander, min_max)
00038 {
00039     HandCommander handcmd = HandCommander();
00040 
00041     std::pair<double, double> min_max = handcmd.get_min_max("FFJ3");
00042     EXPECT_DOUBLE_EQ(min_max.first, 0.0);
00043     EXPECT_DOUBLE_EQ(min_max.second, 1.57079632679);
00044 
00045     //also works for lower case
00046     min_max = handcmd.get_min_max("ffj3");
00047     EXPECT_DOUBLE_EQ(min_max.first, 0.0);
00048     EXPECT_DOUBLE_EQ(min_max.second, 1.57079632679);
00049 
00050     //j0 should be 0, 180
00051     min_max = handcmd.get_min_max("ffj0");
00052     EXPECT_DOUBLE_EQ(min_max.first, 0.0);
00053     EXPECT_DOUBLE_EQ(min_max.second, 3.14159265358);
00054 
00055     //returns 0, 0 if joint not found
00056     min_max = handcmd.get_min_max("unknown joint");
00057     EXPECT_DOUBLE_EQ(min_max.first, 0.0);
00058     EXPECT_DOUBLE_EQ(min_max.second, 0.0);
00059 
00060     //Check that we can get the min and max for each joint
00061     std::vector<std::string> all_joints = handcmd.get_all_joints();
00062     for( size_t i=0; i < all_joints.size(); ++i)
00063     {
00064        min_max = handcmd.get_min_max(all_joints[i]);
00065        EXPECT_TRUE(min_max.first != min_max.second); //min = max if joint not found
00066     }
00067 }
00068 
00069 TEST(HandCommander, all_joints)
00070 {
00071     HandCommander handcmd = HandCommander();
00072 
00073     EXPECT_EQ(handcmd.get_all_joints().size(), 20);
00074 }
00075 
00076 int main(int argc, char **argv)
00077 {
00078     testing::InitGoogleTest(&argc, argv);
00079     ros::init(argc, argv, "hand_commander_test");
00080     ros::NodeHandle nh; // init the node
00081 
00082     //sleep until gazebo is ready
00083     sleep(10.0);
00084 
00085     return RUN_ALL_TESTS();
00086 }


sr_hand
Author(s): Ugo Cupcic
autogenerated on Fri Aug 21 2015 12:24:55