24 #include <gtest/gtest.h> 25 #include <gmock/gmock.h> 28 #include <canopen_chain_node/GetObject.h> 29 #include <sensor_msgs/JointState.h> 33 #include <pilz_testutils/async_test.h> 40 using canopen_chain_node::GetObject;
56 virtual void SetUp()
override;
57 virtual void TearDown()
override;
59 void publishJointState();
62 MOCK_METHOD2(executeGetObject,
bool(GetObject::Request&, GetObject::Response&));
64 void advertiseGetObjectService();
71 const std::vector<std::string> joint_names_ {
"joint1",
"joint2"};
74 std::atomic_bool terminate_ {
false};
82 &SystemInfoTests::executeGetObject,
92 for(
unsigned int i = 0; i < joint_names_.size(); ++i)
94 driver_nh.setParam(
"nodes/" + joint_names_.at(i) +
"/id",
static_cast<int>(i));
98 advertiseGetObjectService();
103 if (publisher_thread_.joinable())
106 publisher_thread_.join();
113 ros::Publisher joint_state_pub = global_nh.advertise<sensor_msgs::JointState>(
117 while(!terminate_ &&
ros::ok())
119 joint_state_pub.
publish(sensor_msgs::JointState());
129 const std::string exp_msg {
"Test-Msg"};
131 EXPECT_TRUE(std::string(ex->what()) == exp_msg);
141 nh.deleteParam(
"/prbt/driver/nodes");
153 publisher_thread_.join();
156 std::atomic_bool ctor_called {
false};
158 std::thread async_ctor_call_thread = std::thread([
this, &ctor_called] () {
162 this->triggerClearEvent(
"ctor_called");
167 ASSERT_FALSE(ctor_called) <<
"Ctor already finished although \"/joint_states\" topic not published yet";
172 pilz_utils::waitForMessage<sensor_msgs::JointState>(
"/joint_states");
174 BARRIER(
"ctor_called");
176 if (async_ctor_call_thread.joinable())
178 async_ctor_call_thread.join();
189 get_obj_service_.shutdown();
192 std::atomic_bool ctor_called {
false};
194 std::thread async_ctor_call_thread = std::thread([
this, &ctor_called] () {
198 this->triggerClearEvent(
"ctor_called");
203 ASSERT_FALSE(ctor_called) <<
"Ctor already finished although \"get_object\" service not advertised yet";
205 advertiseGetObjectService();
208 BARRIER(
"ctor_called");
210 if (async_ctor_call_thread.joinable())
212 async_ctor_call_thread.join();
222 EXPECT_CALL(*
this, executeGetObject(_,_))
224 .WillRepeatedly(testing::Invoke(
225 [](GetObject::Request&, GetObject::Response& res){
241 EXPECT_CALL(*
this, executeGetObject(_,_))
243 .WillRepeatedly(testing::Invoke(
244 [](GetObject::Request&, GetObject::Response&){
260 ASSERT_EQ(2u, joint_names_.size()) <<
"Number of joints in test set-up have changed => Change expected version container in test accordingly.";
262 const FirmwareCont exp_versions { {joint_names_.at(0),
"100 Build:11158 Date:2018-06-07 16:49:55"},
263 {joint_names_.at(1),
"101 Build:11158 Date:2018-06-07 16:49:55"}};
265 EXPECT_CALL(*
this, executeGetObject(_,_))
267 .WillRepeatedly(testing::Invoke(
268 [exp_versions](GetObject::Request& req, GetObject::Response& res){
269 res.value = exp_versions.at(req.node);
279 for(
const auto& joint : joint_names_)
281 EXPECT_TRUE(actual_version_cont.find(joint) != actual_version_cont.cend()) <<
"No version for joint found";
282 EXPECT_EQ(exp_versions.at(joint), actual_version_cont.at(joint)) <<
"Expected and actual firmware version do not match";
292 ASSERT_EQ(2u, joint_names_.size()) <<
"Number of joints in test set-up have changed => Change expected version container in test accordingly.";
294 const FirmwareCont exp_versions { {joint_names_.at(0),
"100 Build:11158 Date:2018-06-07 16:49:55"},
295 {joint_names_.at(1),
"101 Build:11158 Date:2018-06-07 16:49:55"}};
297 EXPECT_CALL(*
this, executeGetObject(_,_))
299 .WillRepeatedly(testing::Invoke(
300 [exp_versions](GetObject::Request& req, GetObject::Response& res){
301 res.value = exp_versions.at(req.node) +
"AdditionalStuffWhichNeedsToBeRemoved";
311 for(
const auto& joint : joint_names_)
313 EXPECT_TRUE(actual_version_cont.find(joint) != actual_version_cont.cend()) <<
"No version for joint found";
314 EXPECT_EQ(exp_versions.at(joint), actual_version_cont.at(joint)) <<
"Expected and actual firmware version do not match";
322 int main(
int argc,
char *argv[])
324 ros::init(argc, argv,
"system_info_test");
327 testing::InitGoogleTest(&argc, argv);
328 return RUN_ALL_TESTS();
static const std::string JOINT_STATES_TOPIC_NAME
virtual void SetUp() override
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char *argv[])
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
static constexpr unsigned int JOINT_STATES_TOPIC_QUEUE_SIZE
void advertiseGetObjectService()
ros::ServiceServer get_obj_service_
Provides easy access to system information which are of importance when analyzing bugs...
static constexpr double DEFAULT_RETRY_TIMEOUT
Collection of tests checking the functionality of the SystemInfo class.
static void waitForService(const std::string service_name, const double retry_timeout=DEFAULT_RETRY_TIMEOUT, const double msg_output_period=DEFAULT_MSG_OUTPUT_PERIOD)
FirmwareCont getFirmwareVersions()
TEST_F(SystemInfoTests, TestExceptions)
Tests that exception stores and returns correct error message.
virtual void TearDown() override
Exception thrown by the SystemInfo class in case of an error.
static const std::string GET_OBJECT_TOPIC_NAME
std::map< std::string, std::string > FirmwareCont
std::thread publisher_thread_