unittest_fake_speed_override.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <ros/ros.h>
19 
20 #include <gtest/gtest.h>
21 
22 #include <pilz_msgs/GetSpeedOverride.h>
23 #include <dynamic_reconfigure/Reconfigure.h>
24 #include <prbt_hardware_support/FakeSpeedOverrideConfig.h>
25 
26 namespace prbt_hardware_support
27 {
28 
29 static constexpr double EXPECTED_DEFAULT_SPEED_OVERRIDE{1.0};
30 
31 class FakeSpeedOverrideTest : public testing::Test
32 {
33  protected:
34  void SetUp() override;
35 
36  bool setSpeedOverrideParameter(double speed_override);
37 
40  pilz_msgs::GetSpeedOverride srv;
41 
42  FakeSpeedOverrideConfig conf;
43 };
44 
46 {
48  client = n.serviceClient<pilz_msgs::GetSpeedOverride>("/prbt/get_speed_override");
49  dynamic_parameter_client = n.serviceClient<dynamic_reconfigure::Reconfigure>("/fake_speed_override_node/set_parameters");
50 }
51 
53 {
54  dynamic_reconfigure::Reconfigure rec;
55  dynamic_reconfigure::DoubleParameter speed_override_param;
56  speed_override_param.name = "speed_override";
57  speed_override_param.value = speed_override;
58 
59  rec.request.config.doubles.push_back(speed_override_param);
60 
61  return dynamic_parameter_client.call(rec);
62 }
63 
72 TEST_F(FakeSpeedOverrideTest, defaultSpeedOverride)
73 {
74  ASSERT_TRUE(client.call(srv));
75  EXPECT_EQ(srv.response.speed_override, EXPECTED_DEFAULT_SPEED_OVERRIDE);
76 }
77 
78 TEST_F(FakeSpeedOverrideTest, testSettingSpeedOverride)
79 {
80  ASSERT_TRUE(client.call(srv));
81  EXPECT_EQ(srv.response.speed_override, conf.__getDefault__().speed_override);
82 
83  const auto test_value = 0.5;
84  EXPECT_TRUE(setSpeedOverrideParameter(test_value));
85  EXPECT_TRUE(client.call(srv));
86  EXPECT_EQ(srv.response.speed_override, test_value);
87 }
88 
89 TEST_F(FakeSpeedOverrideTest, testSettingSpeedOverrideToLow)
90 {
91  EXPECT_TRUE(setSpeedOverrideParameter(conf.__getMin__().speed_override - 0.1));
92 
93  ASSERT_TRUE(client.call(srv));
94  EXPECT_EQ(srv.response.speed_override, conf.__getMin__().speed_override);
95 }
96 
97 TEST_F(FakeSpeedOverrideTest, testSettingSpeedOverrideToHigh)
98 {
99  EXPECT_TRUE(setSpeedOverrideParameter(conf.__getMax__().speed_override + 0.1));
100 
101  ASSERT_TRUE(client.call(srv));
102  EXPECT_EQ(srv.response.speed_override, conf.__getMax__().speed_override);
103 }
104 
105 } // namespace prbt_hardware_support
106 
107 int main(int argc, char** argv)
108 {
109  ros::init(argc, argv, "unittest_fake_speed_override");
110  ros::NodeHandle nh;
111 
112  testing::InitGoogleTest(&argc, argv);
113  return RUN_ALL_TESTS();
114 }
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
static constexpr double EXPECTED_DEFAULT_SPEED_OVERRIDE
TEST_F(BrakeTestRequiredIntegrationTest, testBrakeTestAnnouncement)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)


prbt_hardware_support
Author(s):
autogenerated on Fri Feb 28 2020 03:16:57