Add equality operators for QoS profile (#1032)
* Add equality operators for QoS profile Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> * Use == operator for rmw_time_t as well Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> * Add visibility macros for the new functions Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> * Add tests for every member of the profile Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com> * Remove dangling space Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
This commit is contained in:
parent
a985d6dd3a
commit
9017efbca0
4 changed files with 121 additions and 0 deletions
|
@ -347,6 +347,15 @@ if(BUILD_TESTING)
|
|||
)
|
||||
target_link_libraries(test_publisher_subscription_count_api ${PROJECT_NAME})
|
||||
endif()
|
||||
ament_add_gtest(test_qos test/test_qos.cpp)
|
||||
if(TARGET test_qos)
|
||||
ament_target_dependencies(test_qos
|
||||
"rmw"
|
||||
)
|
||||
target_link_libraries(test_qos
|
||||
${PROJECT_NAME}
|
||||
)
|
||||
endif()
|
||||
ament_add_gtest(test_rate test/test_rate.cpp)
|
||||
if(TARGET test_rate)
|
||||
ament_target_dependencies(test_rate
|
||||
|
|
|
@ -151,6 +151,12 @@ private:
|
|||
rmw_qos_profile_t rmw_qos_profile_;
|
||||
};
|
||||
|
||||
/// Check if two QoS profiles are exactly equal in all policy values.
|
||||
RCLCPP_PUBLIC
|
||||
bool operator==(const QoS & left, const QoS & right);
|
||||
RCLCPP_PUBLIC
|
||||
bool operator!=(const QoS & left, const QoS & right);
|
||||
|
||||
class RCLCPP_PUBLIC SensorDataQoS : public QoS
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -184,6 +184,35 @@ QoS::avoid_ros_namespace_conventions(bool avoid_ros_namespace_conventions)
|
|||
return *this;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Check if two rmw_time_t have the same values.
|
||||
bool operator==(const rmw_time_t & left, const rmw_time_t & right)
|
||||
{
|
||||
return left.sec == right.sec && left.nsec == right.nsec;
|
||||
}
|
||||
} // unnamed namespace
|
||||
|
||||
bool operator==(const QoS & left, const QoS & right)
|
||||
{
|
||||
const auto & pl = left.get_rmw_qos_profile();
|
||||
const auto & pr = right.get_rmw_qos_profile();
|
||||
return pl.history == pr.history &&
|
||||
pl.depth == pr.depth &&
|
||||
pl.reliability == pr.reliability &&
|
||||
pl.durability == pr.durability &&
|
||||
pl.deadline == pr.deadline &&
|
||||
pl.lifespan == pr.lifespan &&
|
||||
pl.liveliness == pr.liveliness &&
|
||||
pl.liveliness_lease_duration == pr.liveliness_lease_duration &&
|
||||
pl.avoid_ros_namespace_conventions == pr.avoid_ros_namespace_conventions;
|
||||
}
|
||||
|
||||
bool operator!=(const QoS & left, const QoS & right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
SensorDataQoS::SensorDataQoS(const QoSInitialization & qos_initialization)
|
||||
: QoS(qos_initialization, rmw_qos_profile_sensor_data)
|
||||
{}
|
||||
|
|
77
rclcpp/test/test_qos.cpp
Normal file
77
rclcpp/test/test_qos.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "rclcpp/qos.hpp"
|
||||
|
||||
TEST(TestQoS, equality_history) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
EXPECT_EQ(a, b);
|
||||
a.keep_last(5);
|
||||
EXPECT_NE(a, b);
|
||||
a.keep_all();
|
||||
b.keep_all();
|
||||
EXPECT_EQ(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_reliability) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
b.best_effort();
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_durability) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
a.transient_local();
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_deadline) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
rmw_time_t deadline{0, 1000};
|
||||
a.deadline(deadline);
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_lifespan) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
rmw_time_t lifespan{3, 0};
|
||||
a.lifespan(lifespan);
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_liveliness) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
rmw_time_t duration{0, 1000000};
|
||||
a.liveliness_lease_duration(duration);
|
||||
EXPECT_NE(a, b);
|
||||
b.liveliness_lease_duration(duration);
|
||||
EXPECT_EQ(a, b);
|
||||
a.liveliness(RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_NODE);
|
||||
EXPECT_NE(a, b);
|
||||
}
|
||||
|
||||
TEST(TestQoS, equality_namespace) {
|
||||
rclcpp::QoS a(10);
|
||||
rclcpp::QoS b(10);
|
||||
a.avoid_ros_namespace_conventions(true);
|
||||
EXPECT_NE(a, b);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue