moveit2
The MoveIt Motion Planning Framework for ROS 2.
unittest_get_solver_tip_frame.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019 Pilz GmbH & Co. KG
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Pilz GmbH & Co. KG nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include <memory>
36 #include <stdexcept>
37 #include <string>
38 #include <vector>
39 
40 #include <gmock/gmock.h>
41 #include <gtest/gtest.h>
42 
44 
46 
48 {
49 using ::testing::AtLeast;
50 using ::testing::Return;
51 using ::testing::ReturnRef;
52 
54 {
55 public:
56  MOCK_CONST_METHOD0(getTipFrames, const std::vector<std::string>&());
57 };
58 
60 {
61 public:
62  MOCK_CONST_METHOD0(getSolverInstance, SolverMock const*());
63  MOCK_CONST_METHOD0(getName, const std::string&());
64 };
65 
69 class GetSolverTipFrameTest : public testing::Test
70 {
71 protected:
72  void SetUp() override;
73 
74 protected:
77  const std::string group_name_{ "fake_group" };
78 };
79 
81 {
82  EXPECT_CALL(jmg_mock_, getName()).WillRepeatedly(ReturnRef(group_name_));
83 }
84 
89 TEST_F(GetSolverTipFrameTest, TestExceptionErrorCodeMapping)
90 {
91  {
92  std::shared_ptr<NoSolverException> nse_ex{ new NoSolverException("") };
93  EXPECT_EQ(nse_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::FAILURE);
94  }
95 
96  {
97  std::shared_ptr<MoreThanOneTipFrameException> ex{ new MoreThanOneTipFrameException("") };
98  EXPECT_EQ(ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::FAILURE);
99  }
100 }
101 
106 TEST_F(GetSolverTipFrameTest, TestExceptionMoreThanOneTipFrame)
107 {
108  std::vector<std::string> tip_frames{ "fake_tip_frame1", "fake_tip_frame2" };
109 
110  EXPECT_CALL(jmg_mock_, getSolverInstance()).Times(AtLeast(1)).WillRepeatedly(Return(&solver_mock_));
111 
112  EXPECT_CALL(solver_mock_, getTipFrames()).Times(AtLeast(1)).WillRepeatedly(ReturnRef(tip_frames));
113 
114  EXPECT_THROW(getSolverTipFrame(&jmg_mock_), MoreThanOneTipFrameException);
115 }
116 
121 TEST_F(GetSolverTipFrameTest, TestExceptionNoSolver)
122 {
123  EXPECT_CALL(jmg_mock_, getSolverInstance()).WillOnce(Return(nullptr));
124 
125  EXPECT_THROW(getSolverTipFrame(&jmg_mock_), NoSolverException);
126 }
127 
132 TEST_F(GetSolverTipFrameTest, NullptrJointGroup)
133 {
135  EXPECT_THROW(hasSolver(group), std::invalid_argument);
136 }
137 
138 } // namespace pilz_industrial_motion_planner
139 
140 int main(int argc, char** argv)
141 {
142  testing::InitGoogleTest(&argc, argv);
143 
144  return RUN_ALL_TESTS();
145 }
MOCK_CONST_METHOD0(getSolverInstance, SolverMock const *())
MOCK_CONST_METHOD0(getName, const std::string &())
MOCK_CONST_METHOD0(getTipFrames, const std::vector< std::string > &())
TEST_F(GetSolverTipFrameIntegrationTest, TestHasSolverManipulator)
Check if hasSolver() can be called successfully for the manipulator group.
int main(int argc, char **argv)