20 #include <gtest/gtest.h> 21 #include <gmock/gmock.h> 25 #include <std_srvs/SetBool.h> 27 #include <pilz_msgs/GetSpeedOverride.h> 29 #include <pilz_testutils/async_test.h> 31 #include <pilz_msgs/OperationModes.h> 38 "monitor_cartesian_speed" };
50 constexpr
TestData(
const int8_t op_mode_,
const bool expected_request_data_,
const double expected_speed_override_)
72 MOCK_METHOD2(monitor_cartesian_speed_callback_,
bool(std_srvs::SetBoolRequest&, std_srvs::SetBoolResponse&));
81 monitor_cartesian_speed_srv_ =
91 public testing::AsyncTest,
92 public testing::WithParamInterface<TestData>
95 void SetUp()
override;
113 controller_mock_.advertiseService();
123 if (!get_speed_override_client_.isValid())
129 if (!get_speed_override_client_.call(get_speed_override))
131 return testing::AssertionFailure() <<
"Service call failed: " << get_speed_override_client_.getService();
133 if (get_speed_override.response.speed_override != expected_speed_override)
135 return testing::AssertionFailure() <<
"Speed overrides do not match. Expected: " << expected_speed_override
136 <<
", actual: " << get_speed_override.response.speed_override;
138 return testing::AssertionSuccess();
142 using testing::DoAll;
143 using testing::Field;
144 using testing::Return;
145 using testing::SetArgReferee;
152 const auto test_data{ GetParam() };
155 response.success =
true;
156 EXPECT_CALL(controller_mock_, monitor_cartesian_speed_callback_(
157 Field(&std_srvs::SetBoolRequest::data, test_data.expected_request_data), _))
161 msg.value = test_data.op_mode;
163 operation_mode_pub_.publish(msg);
167 EXPECT_TRUE(isSpeedOverrideEqualTo(test_data.expected_speed_override));
175 int main(
int argc,
char* argv[])
177 ros::init(argc, argv,
"integrationtest_operation_mode_setup");
183 testing::InitGoogleTest(&argc, argv);
184 return RUN_ALL_TESTS();
static constexpr TestData OP_MODE_T1_TEST_DATA
pilz_msgs::OperationModes OperationModes
static const std::string MONITOR_CARTESIAN_SPEED_CALLBACK_EVENT
Test the operation_mode_setup_executor_node.
static const std::string OPERATON_MODE_SETUP_EXECUTOR_NODE_NAME
int main(int argc, char *argv[])
ServiceServer advertiseService(ros::NodeHandle n, std::string name, boost::function< bool(const typename ActionSpec::_action_goal_type::_goal_type &, typename ActionSpec::_action_result_type::_result_type &result)> service_cb)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
testing::AssertionResult isSpeedOverrideEqualTo(const double &expected_speed_override)
INSTANTIATE_TEST_CASE_P(TestActivationOfSpeedMonitoring, OperationModeSetupTest, testing::Values(OP_MODE_AUTO_TEST_DATA, OP_MODE_T1_TEST_DATA),)
Provides the monitor_cartesian_speed service.
ros::ServiceClient get_speed_override_client_
static const std::string MONITOR_CARTESIAN_SPEED_SERVICE
const bool expected_request_data
static const std::string GET_SPEED_OVERRIDE_SERVICE
pilz_msgs::GetSpeedOverride GetSpeedOverride
static const std::string OPERATION_MODE_TOPIC
ros::ServiceServer monitor_cartesian_speed_srv_
inline ::testing::AssertionResult waitForNode(const std::string node_name, const double loop_frequency=10.0, const ros::Duration timeout=ros::Duration(10.0))
Blocks until a node defined by node_name comes up.
ControllerMock controller_mock_
ros::Publisher operation_mode_pub_
static constexpr TestData OP_MODE_AUTO_TEST_DATA
static constexpr int DEFAULT_QUEUE_SIZE
static constexpr double EXPECTED_SPEED_OVERRIDE_AUTO
TEST_P(OperationModeSetupTest, testSpeedMonitoringActivation)
Tests that the Cartesian speed monitoring is activated or de-activated depending on the operation mod...
constexpr TestData(const int8_t op_mode_, const bool expected_request_data_, const double expected_speed_override_)
inline ::testing::AssertionResult waitForSubscriber(const ros::Publisher &publisher, const unsigned int subscriber_count=1, const double loop_frequency=10.0, const ros::Duration timeout=ros::Duration(10.0))
Blocks until the specified number of subscribers is registered on a topic.
static constexpr double EXPECTED_SPEED_OVERRIDE_T1
const std::string response
const double expected_speed_override
ROSCPP_DECL bool waitForService(const std::string &service_name, int32_t timeout)