24 #include <gtest/gtest.h> 27 #include <sensor_msgs/JointState.h> 37 using sensor_msgs::JointState;
38 using sensor_msgs::JointStatePtr;
39 using sensor_msgs::JointStateConstPtr;
46 if (msg1->name.size() != msg2->name.size())
48 return ::testing::AssertionFailure() <<
"Joint numbers in joint state messages do not match.";
50 if (!std::equal(msg1->name.begin(), msg1->name.end(), msg2->name.begin(),
51 [](std::string name1, std::string name2) {
return name1 == name2; }))
53 return ::testing::AssertionFailure() <<
"Joint names in joint state messages do not match.";
55 if (msg1->position.size() != msg2->position.size())
57 return ::testing::AssertionFailure() <<
"Joint numbers in joint state messages do not match.";
61 return ::testing::AssertionFailure() <<
"Joint positions in joint state messages do not match.";
64 return ::testing::AssertionSuccess();
71 TEST(BrakeTestUtilsTest, testExceptionDtor)
96 TEST(BrakeTestUtilsTest, testCompareJointStatePositions)
101 JointStatePtr msg1{boost::make_shared<JointState>()};
102 msg1->name = {
"joint1",
"joint2"};
103 msg1->position = {0.1, 0.11};
105 JointStatePtr msg2{boost::make_shared<JointState>()};
106 msg2->name = {
"joint1",
"joint2"};
107 msg2->position = {0.1, 0.11};
114 double tolerance = 0.0001;
115 for (
size_t i = 0; i < msg2->position.size(); ++i)
117 msg2->position[i] += 0.9 * tolerance;
125 for (
size_t i = 0; i < msg2->position.size(); ++i)
127 for (
size_t j = 0; j < msg2->position.size(); ++j)
129 msg2->position[j] = msg1->position[j];
131 msg2->position[i] += 1.1 * tolerance;
148 TEST(BrakeTestUtilsTest, testGetCurrentJointStates)
167 catch (
const std::exception &e)
169 ADD_FAILURE() << e.what();
186 TEST(BrakeTestUtilsTest, testDetectRobotMotion)
208 int main(
int argc,
char *argv[])
210 ros::init(argc, argv,
"unittest_brake_test_utils");
213 testing::InitGoogleTest(&argc, argv);
214 return RUN_ALL_TESTS();
int main(int argc, char *argv[])
static bool detectRobotMotion(double timeout_s=DEFAULT_ROBOT_MOTION_TIMEOUT_S)
return true if a robot motion was detected, false otherwise.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
::testing::AssertionResult compareJointStateMessages(const JointStateConstPtr &msg1, const JointStateConstPtr &msg2)
Checks for identical names and positions in joint state messages.
static sensor_msgs::JointStateConstPtr getCurrentJointStates()
wait for a single message on the joint_states topic and return it.
void startAsync(bool move=false)
Start a new thread publishing joint states.
Asynchronously publishes predefined messages on the /joint_states topic with rate ~100Hz...
Expection thrown by BrakeTestUtils::getCurrentJointStates().
TEST(BrakeTestUtilsTest, testExceptionDtor)
Test increases function coverage by ensuring that all Dtor variants are called.
Exception thrown by a BrakeTestUtils function.
sensor_msgs::JointStateConstPtr getNextMessage()
Obtain the message that is published next.
static bool compareJointStatePositions(const sensor_msgs::JointStateConstPtr &msg1, const sensor_msgs::JointStateConstPtr &msg2, const double tol=DEFAULT_JOINT_STATES_COMPARISON_TOLERANCE)
return true if the joint state positions are equal up to a given tolerance, false otherwise...