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 static const std::string RECOVER_SERVICE_NAME{ "recover" };
33 static const std::string HALT_SERVICE_NAME{ "halt" };
34 static const std::string HOLD_SERVICE_NAME{ "hold" };
35 static const std::string UNHOLD_SERVICE_NAME{ "unhold" };
36 
37 static const std::string OMIT_SERVICE_PARAM_NAME{ "omit_service" };
38 static const std::string STOP1_EXECUTOR_NODE_NAME{ "/stop1_executor_node" };
39 
40 static constexpr double WAIT_FOR_NODE_SLEEPTIME_S{ 5.0 };
41 
42 bool triggerCallbackDummy(std_srvs::TriggerRequest& req, std_srvs::TriggerResponse& resp)
43 {
44  return true;
45 }
46 
50 class Stop1ServiceMissingIntegrationTest : public ::testing::Test
51 {
52 public:
56  void SetUp() override;
57 
58 protected:
61 
66 
67  std::function<void()> omit_advertise_func_;
69  std::map<std::string, std::function<void()>> advertise_funcs_;
70 };
71 
73 {
74  ROS_DEBUG("SetUp()");
75 
78  };
81  };
84  };
87  };
88 
89  std::string omit_service;
90  ASSERT_TRUE(nh_priv_.getParam(OMIT_SERVICE_PARAM_NAME, omit_service));
91 
92  const auto& it = advertise_funcs_.find(omit_service);
93  ASSERT_TRUE(it != advertise_funcs_.end()) << "Invalid service name: " << omit_service;
94 
95  omit_advertise_func_ = it->second;
96  advertise_funcs_.erase(it);
97 }
98 
115 {
116  /**********
117  * Step 1 *
118  **********/
119  ROS_DEBUG("Step 1");
120 
121  std::for_each(advertise_funcs_.begin(), advertise_funcs_.end(),
122  [](const std::pair<std::string, std::function<void()>>& el) { el.second(); });
123 
125  EXPECT_FALSE(checkForNode(STOP1_EXECUTOR_NODE_NAME));
126 
127  /**********
128  * Step 2 *
129  **********/
130  ROS_DEBUG("Step 2");
131 
134 }
135 
136 } // namespace prbt_hardware_support
137 
138 int main(int argc, char* argv[])
139 {
140  ros::init(argc, argv, "integrationtest_stop1_service_missing");
141  ros::NodeHandle nh;
142 
144  spinner.start();
145 
146  testing::InitGoogleTest(&argc, argv);
147  return RUN_ALL_TESTS();
148 }
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[])
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
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.
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 Mon Feb 28 2022 23:14:34