integrationtest_stop1_service_missing.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 <gtest/gtest.h>
19 
20 #include <functional>
21 #include <map>
22 #include <string>
23 
24 #include <ros/ros.h>
25 
26 #include <std_srvs/Trigger.h>
27 
29 
30 namespace prbt_hardware_support
31 {
32 
33 static const std::string RECOVER_SERVICE_NAME {"recover"};
34 static const std::string HALT_SERVICE_NAME {"halt"};
35 static const std::string HOLD_SERVICE_NAME {"hold"};
36 static const std::string UNHOLD_SERVICE_NAME {"unhold"};
37 
38 static const std::string OMIT_SERVICE_PARAM_NAME {"omit_service"};
39 static const std::string STOP1_EXECUTOR_NODE_NAME {"/stop1_executor_node"};
40 
41 static constexpr double WAIT_FOR_NODE_SLEEPTIME_S {5.0};
42 
43 bool triggerCallbackDummy(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
44 {
45  return true;
46 }
47 
51 class Stop1ServiceMissingIntegrationTest : public ::testing::Test
52 {
53 public:
57  void SetUp() override;
58 
59 protected:
62 
67 
68  std::function<void()> omit_advertise_func_;
70  std::map<std::string, std::function<void()>> advertise_funcs_;
71 };
72 
74 {
75  ROS_DEBUG("SetUp()");
76 
85 
86  std::string omit_service;
87  ASSERT_TRUE(nh_priv_.getParam(OMIT_SERVICE_PARAM_NAME, omit_service));
88 
89  const auto &it = advertise_funcs_.find(omit_service);
90  ASSERT_TRUE(it != advertise_funcs_.end()) << "Invalid service name: " << omit_service;
91 
92  omit_advertise_func_ = it->second;
93  advertise_funcs_.erase(it);
94 }
95 
112 {
113  /**********
114  * Step 1 *
115  **********/
116  ROS_DEBUG("Step 1");
117 
118  std::for_each(advertise_funcs_.begin(),
119  advertise_funcs_.end(),
120  [](const std::pair<std::string, std::function<void()>> &el){ el.second(); });
121 
123  EXPECT_FALSE(checkForNode(STOP1_EXECUTOR_NODE_NAME));
124 
125  /**********
126  * Step 2 *
127  **********/
128  ROS_DEBUG("Step 2");
129 
132 }
133 
134 } // namespace prbt_hardware_support
135 
136 
137 int main(int argc, char *argv[])
138 {
139  ros::init(argc, argv, "integrationtest_stop1_service_missing");
140  ros::NodeHandle nh;
141 
143  spinner.start();
144 
145  testing::InitGoogleTest(&argc, argv);
146  return RUN_ALL_TESTS();
147 }
void SetUp() override
Gather service-advertising functions for all manipulator services and determine service to omit...
static const std::string HOLD_SERVICE_NAME
TEST_F(BrakeTestRequiredIntegrationTest, testBrakeTestAnnouncement)
int main(int argc, char *argv[])
void waitForNode(std::string node_name, double loop_frequency=10.0)
Blocks until a node defined by node_name comes up.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool triggerCallbackDummy(std_srvs::TriggerRequest &req, std_srvs::TriggerResponse &resp)
static const std::string OMIT_SERVICE_PARAM_NAME
void spinner()
static const std::string UNHOLD_SERVICE_NAME
bool checkForNode(std::string node_name)
Checks if a node is up and running.
static const std::string RECOVER_SERVICE_NAME
static const std::string HALT_SERVICE_NAME
bool getParam(const std::string &key, std::string &s) const
std::map< std::string, std::function< void()> > advertise_funcs_
Map holding all but one service-advertising functions.
static const std::string STOP1_EXECUTOR_NODE_NAME
bool sleep() const
#define ROS_DEBUG(...)


prbt_hardware_support
Author(s):
autogenerated on Thu Feb 13 2020 03:16:51