gtest_logger_zmq.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 
4 #include "behaviortree_cpp/loggers/bt_zmq_publisher.h"
5 
6 TEST(LoggerZMQ, ZMQLoggerDeletesCleanlyAfterTickingTree)
7 {
8  // GIVEN we create a behavior tree through the BT factory and attach a ZMQ publisher to it
9  static constexpr auto XML = R"(
10 <root BTCPP_format="4">
11  <BehaviorTree>
12  <SetBlackboard output_key="arg1" value="1" />
13  </BehaviorTree>
14 </root>
15 )";
17  auto tree = factory.createTreeFromText(XML);
18 
19  {
20  BT::PublisherZMQ zmq_logger{ tree, 1 };
21  tree.tickWhileRunning();
22  // WHEN zmq_logger goes out of scope
23  }
24 
25  // THEN zmq_logger is destroyed cleanly without segfaulting
26  SUCCEED();
27 }
28 
29 TEST(LoggerZMQ, ZMQLoggerDeletesCleanlyAfterNotTickingTree)
30 {
31  // GIVEN we create a behavior tree through the BT factory and attach a ZMQ publisher to it
32  static constexpr auto XML = R"(
33 <root BTCPP_format="4">
34  <BehaviorTree>
35  <SetBlackboard output_key="arg1" value="1" />
36  </BehaviorTree>
37 </root>
38 )";
40  auto tree = factory.createTreeFromText(XML);
41 
42  {
43  BT::PublisherZMQ zmq_logger{ tree, 1 };
44  // GIVEN we haven't even ticked the tree, so ZMQ hasn't published any state change messages
45  // (meaning no send is pending and send_future_ has not been set)
46  // WHEN zmq_logger goes out of scope
47  }
48 
49  // THEN zmq_logger is destroyed cleanly without segfaulting
50  SUCCEED();
51 }
bt_factory.h
BT::Tree::tickWhileRunning
NodeStatus tickWhileRunning(std::chrono::milliseconds sleep_time=std::chrono::milliseconds(10))
Definition: bt_factory.cpp:610
BT::BehaviorTreeFactory::createTreeFromText
Tree createTreeFromText(const std::string &text, Blackboard::Ptr blackboard=Blackboard::create())
createTreeFromText will parse the XML directly from string. The XML needs to contain either a single ...
Definition: bt_factory.cpp:395
BT::BehaviorTreeFactory
The BehaviorTreeFactory is used to create instances of a TreeNode at run-time.
Definition: bt_factory.h:209
TEST
TEST(LoggerZMQ, ZMQLoggerDeletesCleanlyAfterTickingTree)
Definition: gtest_logger_zmq.cpp:6


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:16