forked from BehaviorTree/BehaviorTree.CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtest_groot2_publisher.cpp
More file actions
48 lines (42 loc) · 1.23 KB
/
gtest_groot2_publisher.cpp
File metadata and controls
48 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <chrono>
#include <cstdlib>
#include <future>
#include <behaviortree_cpp/loggers/groot2_protocol.h>
#include <behaviortree_cpp/loggers/groot2_publisher.h>
#include <gtest/gtest.h>
using namespace std::chrono_literals;
namespace
{
static const char* xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<ThrowRuntimeError/>
</BehaviorTree>
</root>
)";
void throwRuntimeError()
{
BT::BehaviorTreeFactory factory;
factory.registerSimpleAction("ThrowRuntimeError", [](BT::TreeNode&) -> BT::NodeStatus {
throw BT::RuntimeError("Oops!");
});
auto tree = factory.createTreeFromText(xml_text);
BT::Groot2Publisher publisher(tree);
EXPECT_THROW(tree.tickExactlyOnce(), BT::RuntimeError);
}
} // namespace
TEST(Groot2PublisherTest, EnsureNoInfiniteLoopOnThrow)
{
EXPECT_EXIT(
{
auto fut = std::async(std::launch::async, throwRuntimeError);
auto status = fut.wait_for(1s); // shouldn't run for more than 1 second
if(status != std::future_status::ready)
{
std::cerr << "Test took too long. Possible infinite loop.\n";
std::exit(EXIT_FAILURE);
}
std::exit(EXIT_SUCCESS);
},
::testing::ExitedWithCode(EXIT_SUCCESS), ".*");
}