Class StaticMocksRegistry

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

Class Documentation

class StaticMocksRegistry : private rtest::SingleInstance<StaticMocksRegistry>

Whenever the ROS 2 Node creates a Subscriber, Publisher or Timer it is registered in this static registry, so the user can retrieve a handle to the mock object in the test.

Public Types

using TopicNameT = std::string
using FullyQualifiedNodeNameT = std::string
using TopicToPublishersMapT = std::map<TopicNameT, std::weak_ptr<rclcpp::PublisherBase>>
using TopicToSubscriptionsMapT = std::map<TopicNameT, std::weak_ptr<rclcpp::SubscriptionBase>>
using ServiceNameT = std::string
using ServiceToServicesMapT = std::map<ServiceNameT, std::weak_ptr<rclcpp::ServiceBase>>
using ServiceToClientsMapT = std::map<ServiceNameT, std::weak_ptr<rclcpp::ClientBase>>
using ActionNameT = std::string
using ActionToServersMapT = std::map<ActionNameT, std::weak_ptr<rclcpp_action::ServerBase>>
using ActionToClientsMapT = std::map<ActionNameT, std::weak_ptr<rclcpp_action::ClientBase>>

Public Functions

template<typename MessageT>
inline void registerPublisher(const FullyQualifiedNodeNameT &nodeName, const TopicNameT &topicName, std::weak_ptr<rclcpp::PublisherBase> pub)

Register the newly created Publisher in the regisrtry. This function shall be used by the rclcpp::Publisher only.

Parameters:
  • nodeName – Fully-qualified Node name

  • topicName – Topic name

  • pub – Newly created Publisher object

inline std::vector<std::weak_ptr<rclcpp::PublisherBase>> getNodePublishers(const FullyQualifiedNodeNameT &nodeName)

Get list of all publishers created by the selected Node.

Parameters:

nodeName – Fully-qualified Node name

Returns:

std::vector<std::weak_ptr<rclcpp::PublisherBase>>

inline std::weak_ptr<rclcpp::PublisherBase> getPublisher(const FullyQualifiedNodeNameT &nodeName, const TopicNameT &topicName)

Get a publisher created by a selected Node for a particular Topic.

Parameters:
  • nodeName – Fully-qualified Node name

  • topicName – Topic name

Returns:

std::weak_ptr<rclcpp::PublisherBase>

template<typename MessageT>
inline void registerSubscription(const FullyQualifiedNodeNameT &nodeName, const TopicNameT &topicName, std::weak_ptr<rclcpp::SubscriptionBase> sub)

Register the newly created Subscription in the regisrtry. This function shall be used by the rclcpp::Publisher only.

Parameters:
  • nodeName – Fully-qualified Node name

  • topicName – Topic name

  • sub – Newly created Subscription object

inline std::vector<std::weak_ptr<rclcpp::SubscriptionBase>> getNodeSubscriptions(const FullyQualifiedNodeNameT &nodeName)

Get list of all subscriptions created by the selected Node.

Parameters:

nodeName

Returns:

std::vector<std::weak_ptr<rclcpp::SubscriptionBase>>

inline std::weak_ptr<rclcpp::SubscriptionBase> getSubscription(const FullyQualifiedNodeNameT &nodeName, const TopicNameT &topicName)

Get a subscription created by a selected Node for a particular Topic.

Parameters:
  • nodeName – Fully-qualified Node name

  • topicName – Topic name

Returns:

std::weak_ptr<rclcpp::SubscriptionBase>

inline bool registerTimer(const FullyQualifiedNodeNameT &nodeName, std::weak_ptr<rclcpp::TimerBase> timer)

Register the newly created Timer in the regisrtry. This function shall be used by the rclcpp::create_timer() function only.

Parameters:
  • nodeName – Fully-qualified Node name

  • timer – Newly created Timer object

Returns:

true

Returns:

false

inline std::vector<std::weak_ptr<rclcpp::TimerBase>> getTimers(const FullyQualifiedNodeNameT &nodeName)

Get list of all Timers created by the selected Node.

Parameters:

nodeName – Fully-qualified Node name

Returns:

std::vector<std::weak_ptr<rclcpp::TimerBase>>

inline void enableVerboseLogs(bool on)

Enable additional verbose logs to trace registry events.

Parameters:

on

inline std::weak_ptr<MockBase> getMock(void *ptr)
inline void attachMock(void *ptr, std::weak_ptr<MockBase> mock)
inline void detachMock(void *ptr)
template<typename ServiceT>
inline void registerService(const FullyQualifiedNodeNameT &nodeName, const ServiceNameT &serviceName, std::weak_ptr<rclcpp::ServiceBase> service)

Register the newly created Service in the registry.

inline std::vector<std::weak_ptr<rclcpp::ServiceBase>> getNodeServices(const FullyQualifiedNodeNameT &nodeName)

Get list of all services created by the selected Node.

inline std::weak_ptr<rclcpp::ServiceBase> getService(const FullyQualifiedNodeNameT &nodeName, const ServiceNameT &serviceName)

Get a service created by a selected Node.

template<typename ServiceT>
inline void registerServiceClient(const FullyQualifiedNodeNameT &nodeName, const ServiceNameT &serviceName, std::weak_ptr<rclcpp::ClientBase> client)
inline std::vector<std::weak_ptr<rclcpp::ClientBase>> getNodeServiceClients(const FullyQualifiedNodeNameT &nodeName)
inline std::weak_ptr<rclcpp::ClientBase> getServiceClient(const FullyQualifiedNodeNameT &nodeName, const ServiceNameT &serviceName)
template<typename ActionT>
inline void registerActionServer(const FullyQualifiedNodeNameT &nodeName, const ActionNameT &actionName, std::weak_ptr<rclcpp_action::ServerBase> server)
template<typename ActionT>
inline void registerActionClient(const FullyQualifiedNodeNameT &nodeName, const ActionNameT &actionName, std::weak_ptr<rclcpp_action::ClientBase> client)
inline std::weak_ptr<rclcpp_action::ServerBase> getActionServer(const FullyQualifiedNodeNameT &nodeName, const ActionNameT &actionName)
inline void tryLazyInit(std::vector<LazyInitEntry> &lazyInitVector)
inline std::weak_ptr<rclcpp_action::ClientBase> getActionClient(const FullyQualifiedNodeNameT &nodeName, const ActionNameT &actionName)
inline void registerLazyInitClient(void *raw_ptr, const std::string &node_name, const std::string &action_name, std::function<void()> callback)
inline void removeLazyInitClient(void *raw_ptr)
inline void registerLazyInitServer(void *raw_ptr, const std::string &node_name, const std::string &action_name, std::function<void()> callback)
inline void removeLazyInitServer(void *raw_ptr)
inline void reset()

Public Static Functions

static inline StaticMocksRegistry &instance()

Get the static instance of the Mock Registry.

Returns:

StaticMocksRegistry&

struct LazyInitEntry

Public Members

void *raw_ptr
std::string node_name
std::string action_name
std::function<void()> init_callback