Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions rclcpp/include/rclcpp/detail/qos_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ inline
int64_t
rmw_duration_to_int64_t(rmw_time_t rmw_duration)
{
return ::rclcpp::Duration(
static_cast<int32_t>(rmw_duration.sec),
static_cast<uint32_t>(rmw_duration.nsec)
).nanoseconds();
return ::rclcpp::Duration::from_rmw_time(rmw_duration).nanoseconds();
}

/// \internal Throw an exception if `policy_value_stringified` is NULL.
Expand Down
49 changes: 49 additions & 0 deletions rclcpp/test/rclcpp/test_qos_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <cstdint>
#include <map>
#include <memory>
#include <stdexcept>
#include <string>

#include "gmock/gmock.h"

#include "rmw/time.h"

#include "rclcpp/detail/qos_parameters.hpp"
#include "rclcpp/duration.hpp"
#include "rclcpp/exceptions.hpp"
#include "rclcpp/node.hpp"
#include "rclcpp/node_options.hpp"
Expand Down Expand Up @@ -196,6 +200,51 @@ TEST(TestQosParameters, declare_qos_subscription_parameters) {
rclcpp::shutdown();
}

TEST(TestQosParameters, declare_infinite_durations) {
// RMW_DURATION_INFINITE, and the "best available" deadline and liveliness lease
// sentinels, all carry 9223372036 seconds, which does not fit in the int32_t
// seconds field of rclcpp::Duration(int32_t, uint32_t).
constexpr rmw_time_t infinite = RMW_DURATION_INFINITE;
const int64_t infinite_ns = rclcpp::Duration::from_rmw_time(infinite).nanoseconds();

rclcpp::init(0, nullptr);
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");

rclcpp::QoS qos{rclcpp::KeepLast{10}};
qos.deadline(infinite);
qos.lifespan(infinite);
qos.liveliness_lease_duration(infinite);

EXPECT_EQ(
infinite_ns,
rclcpp::detail::get_default_qos_param_value(
rclcpp::QosPolicyKind::Deadline, qos).get<int64_t>());
EXPECT_EQ(
infinite_ns,
rclcpp::detail::get_default_qos_param_value(
rclcpp::QosPolicyKind::Lifespan, qos).get<int64_t>());
EXPECT_EQ(
infinite_ns,
rclcpp::detail::get_default_qos_param_value(
rclcpp::QosPolicyKind::LivelinessLeaseDuration, qos).get<int64_t>());

// Without a parameter override, declaring the overrides must hand back the profile
// it was given.
rclcpp::QoS declared = rclcpp::detail::declare_qos_parameters(
{rclcpp::QosPolicyKind::Deadline, rclcpp::QosPolicyKind::Lifespan,
rclcpp::QosPolicyKind::LivelinessLeaseDuration},
node,
"/my/fully/qualified/topic_name",
qos,
rclcpp::detail::PublisherQosParametersTraits{});

EXPECT_EQ(infinite_ns, declared.deadline().nanoseconds());
EXPECT_EQ(infinite_ns, declared.lifespan().nanoseconds());
EXPECT_EQ(infinite_ns, declared.liveliness_lease_duration().nanoseconds());

rclcpp::shutdown();
}

TEST(TestQosParameters, declare_with_id) {
rclcpp::init(0, nullptr);
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
Expand Down
Loading