moveit2
The MoveIt Motion Planning Framework for ROS 2.
Loading...
Searching...
No Matches
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{
49using ::testing::AtLeast;
50using ::testing::Return;
51using ::testing::ReturnRef;
52
54{
55public:
56 MOCK_CONST_METHOD0(getTipFrames, const std::vector<std::string>&());
57};
58
60{
61public:
62 MOCK_CONST_METHOD0(getSolverInstance, const SolverMock*());
63 MOCK_CONST_METHOD0(getName, const std::string&());
64};
65
69class GetSolverTipFrameTest : public testing::Test
70{
71protected:
72 void SetUp() override;
73
74protected:
77 const std::string group_name_{ "fake_group" };
78};
79
81{
82 EXPECT_CALL(jmg_mock_, getName()).WillRepeatedly(ReturnRef(group_name_));
83}
84
89TEST_F(GetSolverTipFrameTest, TestExceptionErrorCodeMapping)
90{
91 {
92 auto nse_ex = std::make_shared<NoSolverException>("");
93 EXPECT_EQ(nse_ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::FAILURE);
94 }
95
96 {
97 auto ex = std::make_shared<MoreThanOneTipFrameException>("");
98 EXPECT_EQ(ex->getErrorCode(), moveit_msgs::msg::MoveItErrorCodes::FAILURE);
99 }
100}
101
106TEST_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
121TEST_F(GetSolverTipFrameTest, TestExceptionNoSolver)
122{
123 EXPECT_CALL(jmg_mock_, getSolverInstance()).WillOnce(Return(nullptr));
124
125 EXPECT_THROW(getSolverTipFrame(&jmg_mock_), NoSolverException);
126}
127
132TEST_F(GetSolverTipFrameTest, NullptrJointGroup)
133{
134 moveit::core::JointModelGroup* group = nullptr;
135 EXPECT_THROW(hasSolver(group), std::invalid_argument);
136}
137
138} // namespace pilz_industrial_motion_planner
139
140int main(int argc, char** argv)
141{
142 testing::InitGoogleTest(&argc, argv);
143
144 return RUN_ALL_TESTS();
145}
MOCK_CONST_METHOD0(getName, const std::string &())
MOCK_CONST_METHOD0(getSolverInstance, const SolverMock *())
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)