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> 39 using canopen_chain_node::GetObject;
55 void SetUp()
override;
56 void TearDown()
override;
58 void publishJointState();
61 MOCK_METHOD2(executeGetObject,
bool(GetObject::Request&, GetObject::Response&));
63 void advertiseGetObjectService();
70 const std::vector<std::string> joint_names_{
"joint1",
"joint2" };
73 std::atomic_bool terminate_{
false };
79 get_obj_service_ = driver_nh.advertiseService(
GET_OBJECT_TOPIC_NAME, &SystemInfoTests::executeGetObject,
this);
88 for (
unsigned int i = 0; i < joint_names_.size(); ++i)
90 driver_nh.setParam(
"nodes/" + joint_names_.at(i) +
"/id",
static_cast<int>(i));
94 advertiseGetObjectService();
99 if (publisher_thread_.joinable())
102 publisher_thread_.join();
112 while (!terminate_ &&
ros::ok())
114 joint_state_pub.
publish(sensor_msgs::JointState());
124 const std::string exp_msg{
"Test-Msg" };
136 nh.deleteParam(
"/prbt/driver/nodes");
148 publisher_thread_.join();
151 std::atomic_bool ctor_called{
false };
153 std::thread async_ctor_call_thread = std::thread([
this, &ctor_called]() {
157 this->triggerClearEvent(
"ctor_called");
162 ASSERT_FALSE(ctor_called) <<
"Ctor already finished although \"/joint_states\" topic not published yet";
167 pilz_utils::waitForMessage<sensor_msgs::JointState>(
"/joint_states");
169 BARRIER(
"ctor_called");
171 if (async_ctor_call_thread.joinable())
173 async_ctor_call_thread.join();
184 get_obj_service_.shutdown();
187 std::atomic_bool ctor_called{
false };
189 std::thread async_ctor_call_thread = std::thread([
this, &ctor_called]() {
193 this->triggerClearEvent(
"ctor_called");
198 ASSERT_FALSE(ctor_called) <<
"Ctor already finished although \"get_object\" service not advertised yet";
200 advertiseGetObjectService();
203 BARRIER(
"ctor_called");
205 if (async_ctor_call_thread.joinable())
207 async_ctor_call_thread.join();
217 EXPECT_CALL(*
this, executeGetObject(_, _))
219 .WillRepeatedly(testing::Invoke([](GetObject::Request&, GetObject::Response& res) {
234 EXPECT_CALL(*
this, executeGetObject(_, _))
236 .WillRepeatedly(testing::Invoke([](GetObject::Request&, GetObject::Response&) {
return false; }));
249 ASSERT_EQ(2u, joint_names_.size()) <<
"Number of joints in test set-up have changed => Change expected version " 250 "container in test accordingly.";
252 const FirmwareCont exp_versions{ { joint_names_.at(0),
"100 Build:11158 Date:2018-06-07 16:49:55" },
253 { joint_names_.at(1),
"101 Build:11158 Date:2018-06-07 16:49:55" } };
255 EXPECT_CALL(*
this, executeGetObject(_, _))
257 .WillRepeatedly(testing::Invoke([exp_versions](GetObject::Request& req, GetObject::Response& res) {
258 res.value = exp_versions.at(req.node);
267 for (
const auto& joint : joint_names_)
269 EXPECT_TRUE(actual_version_cont.find(joint) != actual_version_cont.cend()) <<
"No version for joint found";
270 EXPECT_EQ(exp_versions.at(joint), actual_version_cont.at(joint)) <<
"Expected and actual firmware version do not " 281 ASSERT_EQ(2u, joint_names_.size()) <<
"Number of joints in test set-up have changed => Change expected version " 282 "container in test accordingly.";
284 const FirmwareCont exp_versions{ { joint_names_.at(0),
"100 Build:11158 Date:2018-06-07 16:49:55" },
285 { joint_names_.at(1),
"101 Build:11158 Date:2018-06-07 16:49:55" } };
287 EXPECT_CALL(*
this, executeGetObject(_, _))
289 .WillRepeatedly(testing::Invoke([exp_versions](GetObject::Request& req, GetObject::Response& res) {
290 res.value = exp_versions.at(req.node) +
"AdditionalStuffWhichNeedsToBeRemoved";
299 for (
const auto& joint : joint_names_)
301 EXPECT_TRUE(actual_version_cont.find(joint) != actual_version_cont.cend()) <<
"No version for joint found";
302 EXPECT_EQ(exp_versions.at(joint), actual_version_cont.at(joint)) <<
"Expected and actual firmware version do not " 309 int main(
int argc,
char* argv[])
311 ros::init(argc, argv,
"system_info_test");
314 testing::InitGoogleTest(&argc, argv);
315 return RUN_ALL_TESTS();
static const std::string JOINT_STATES_TOPIC_NAME
std::map< std::string, std::string > FirmwareCont
Exception thrown by the SystemInfo class in case of an error.
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_
static constexpr double DEFAULT_RETRY_TIMEOUT
void publish(const boost::shared_ptr< M > &message) const
Collection of tests checking the functionality of the SystemInfo class.
FirmwareCont getFirmwareVersions()
static void waitForService(const std::string service_name, const double retry_timeout=DEFAULT_RETRY_TIMEOUT, const double msg_output_period=DEFAULT_MSG_OUTPUT_PERIOD)
TEST_F(SystemInfoTests, TestExceptions)
Tests that exception stores and returns correct error message.
static const std::string GET_OBJECT_TOPIC_NAME
Provides easy access to system information which are of importance when analyzing bugs...
#define EXPECT_TRUE(args)
std::thread publisher_thread_