1 #include <gtest/gtest.h> 12 #include <rosee_msg/NewGenericGraspingActionSrv.h> 23 class testServiceHandler:
public ::testing::Test {
28 testServiceHandler() {
31 virtual ~testServiceHandler() {
34 virtual void SetUp()
override {
36 if (! nh.hasParam(
"robot_name")) {
37 std::cout <<
"[TEST FAIL: robot name not set on server]" << std::endl;
42 nh.getParam(
"robot_name", robot_name);
44 std::string handNameArg =
"hand_name:=" + robot_name;
45 roseeExecutor.reset(
new ROSEE::TestUtils::Process({
"roslaunch",
"end_effector",
"test_rosee_startup.launch", handNameArg}));
49 virtual void TearDown()
override {
52 std::string robot_name;
54 std::unique_ptr<ROSEE::TestUtils::Process> roseeExecutor;
56 template <
class clientType>
73 TEST_F ( testServiceHandler, callNewAction ) {
78 initClient<rosee_msg::NewGenericGraspingActionSrv>(rosee_client,
"/ros_end_effector/new_generic_grasping_action");
80 rosee_msg::NewGenericGraspingActionSrv newActionSrv;
88 EXPECT_TRUE( newActionSrv.response.error_msg.size() > 0 );
91 newActionSrv.request.newAction.action_name =
"newAction";
95 EXPECT_TRUE( newActionSrv.response.error_msg.size() > 0 );
98 newActionSrv.request.newAction.action_motor_position.name.push_back(
"joint_1");
99 newActionSrv.request.newAction.action_motor_position.position.push_back(1);
103 EXPECT_FALSE( newActionSrv.response.error_msg.size() > 0 );
109 EXPECT_TRUE( newActionSrv.response.error_msg.size() > 0 );
113 newActionSrv.request.newAction.action_name =
"newAction_" + std::to_string(
ros::Time::now().toSec());
114 newActionSrv.request.newAction.action_motor_count.name.push_back(
"error_joint_1");
115 newActionSrv.request.newAction.action_motor_count.count.push_back(1);
119 EXPECT_TRUE( newActionSrv.response.error_msg.size() > 0 );
122 newActionSrv.request.newAction.action_motor_count.name.at(0) =
"joint_1";
123 newActionSrv.request.newAction.action_motor_count.count.at(0) = 1;
124 newActionSrv.request.emitYaml =
true;
128 EXPECT_FALSE( newActionSrv.response.error_msg.size() > 0 );
135 TEST_F ( testServiceHandler, callNewActionAndRetrieve ) {
140 initClient<rosee_msg::NewGenericGraspingActionSrv>(rosee_client_new_action,
"/ros_end_effector/new_generic_grasping_action");
141 initClient<rosee_msg::GraspingActionsAvailable>(rosee_client_actions_available,
"/ros_end_effector/grasping_actions_available");
143 rosee_msg::NewGenericGraspingActionSrv newActionSrv;
145 std::string requestActionName =
"newAction_TEST";
146 newActionSrv.request.newAction.action_name = requestActionName;
147 newActionSrv.request.newAction.action_motor_position.name.push_back(
"joint_1");
148 newActionSrv.request.newAction.action_motor_position.position.push_back(1);
149 newActionSrv.request.newAction.elements_involved.push_back(
"an_element");
150 newActionSrv.request.emitYaml =
false;
151 EXPECT_TRUE( rosee_client_new_action.call(newActionSrv) );
154 EXPECT_FALSE( newActionSrv.response.error_msg.size() > 0 );
157 rosee_msg::GraspingActionsAvailable graspActionAvailable;
160 graspActionAvailable.request.action_name =
"newAction_TEST_NOT_EXISTENT";
161 EXPECT_TRUE(rosee_client_actions_available.call(graspActionAvailable));
162 EXPECT_EQ(graspActionAvailable.response.grasping_actions.size(), 0);
165 graspActionAvailable.request.action_name = requestActionName;
167 graspActionAvailable.request.action_type = 1;
168 EXPECT_TRUE(rosee_client_actions_available.call(graspActionAvailable));
169 EXPECT_EQ(1, graspActionAvailable.response.grasping_actions.size());
170 if (graspActionAvailable.response.grasping_actions.size() > 0) {
171 auto receivedAction = graspActionAvailable.response.grasping_actions.at(0);
172 EXPECT_EQ(receivedAction.action_name, requestActionName);
173 EXPECT_EQ(receivedAction.action_motor_positions.at(0).name.size(), newActionSrv.request.newAction.action_motor_position.name.size());
174 EXPECT_EQ(receivedAction.action_motor_positions.at(0).name.at(0), newActionSrv.request.newAction.action_motor_position.name.at(0));
175 EXPECT_EQ(receivedAction.action_motor_positions.at(0).position.at(0), newActionSrv.request.newAction.action_motor_position.position.at(0));
177 EXPECT_EQ(1, receivedAction.action_motor_count.name.size());
178 EXPECT_EQ(receivedAction.action_motor_count.name.at(0), newActionSrv.request.newAction.action_motor_position.name.at(0));
179 EXPECT_EQ(1, receivedAction.action_motor_count.count.at(0));
180 EXPECT_EQ(1, receivedAction.elements_involved.size());
181 if (receivedAction.elements_involved.size() > 0){
182 EXPECT_EQ(receivedAction.elements_involved.at(0), newActionSrv.request.newAction.elements_involved.at(0));
197 int main (
int argc,
char **argv ) {
201 std::cout <<
"[TEST ERROR] Insert hand name as argument" << std::endl;
208 if(setenv(
"ROS_MASTER_URI",
"http://localhost:11322", 1) == -1)
215 std::unique_ptr<ROSEE::TestUtils::Process> roscore;
219 ros::init ( argc, argv,
"testServiceHandler" );
223 ::testing::InitGoogleTest ( &argc, argv );
224 return RUN_ALL_TESTS();
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
#define EXPECT_FALSE(args)
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
#define EXPECT_TRUE(args)
TEST_F(TestRunner, threaded_test)