Skip to content

Commit 7c5f0d1

Browse files
committed
clang format
1 parent 5d59bb2 commit 7c5f0d1

20 files changed

+2315
-2358
lines changed

tests/gtest_async_action_node.cpp

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,30 @@
1515
// The mocked version of the base.
1616
struct MockedAsyncActionNode : public BT::AsyncActionNode
1717
{
18-
using BT::AsyncActionNode::AsyncActionNode;
19-
MOCK_METHOD0(tick, BT::NodeStatus());
18+
using BT::AsyncActionNode::AsyncActionNode;
19+
MOCK_METHOD0(tick, BT::NodeStatus());
2020

21-
// Tick while the node is running.
22-
BT::NodeStatus spinUntilDone()
21+
// Tick while the node is running.
22+
BT::NodeStatus spinUntilDone()
23+
{
24+
do
2325
{
24-
do
25-
{
26-
executeTick();
27-
} while (status() == BT::NodeStatus::RUNNING);
28-
return status();
29-
}
30-
31-
// Expose the setStatus method.
32-
using BT::AsyncActionNode::setStatus;
26+
executeTick();
27+
} while (status() == BT::NodeStatus::RUNNING);
28+
return status();
29+
}
30+
31+
// Expose the setStatus method.
32+
using BT::AsyncActionNode::setStatus;
3333
};
3434

3535
// The fixture taking care of the node-setup.
3636
struct MockedAsyncActionFixture : public testing::Test
3737
{
38-
BT::NodeConfiguration config;
39-
MockedAsyncActionNode sn;
40-
MockedAsyncActionFixture() : sn("node", config)
41-
{
42-
}
38+
BT::NodeConfiguration config;
39+
MockedAsyncActionNode sn;
40+
MockedAsyncActionFixture() : sn("node", config)
41+
{}
4342
};
4443

4544
// Parameters for the terminal node states.
@@ -49,94 +48,95 @@ struct NodeStatusFixture : public testing::WithParamInterface<BT::NodeStatus>,
4948
};
5049

5150
INSTANTIATE_TEST_CASE_P(/**/, NodeStatusFixture,
52-
testing::Values(BT::NodeStatus::SUCCESS, BT::NodeStatus::FAILURE));
51+
testing::Values(BT::NodeStatus::SUCCESS,
52+
BT::NodeStatus::FAILURE));
5353

5454
TEST_P(NodeStatusFixture, normal_routine)
5555
{
56-
// Test verifies the "normal" operation: We correctly propagate the result
57-
// from the tick to the caller.
58-
const BT::NodeStatus state = GetParam();
59-
60-
// Setup the mock-expectations.
61-
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
62-
std::this_thread::sleep_for(std::chrono::milliseconds(10));
63-
return state;
64-
}));
65-
66-
// Spin the node and check the final status.
67-
ASSERT_EQ(sn.spinUntilDone(), state);
56+
// Test verifies the "normal" operation: We correctly propagate the result
57+
// from the tick to the caller.
58+
const BT::NodeStatus state = GetParam();
59+
60+
// Setup the mock-expectations.
61+
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
62+
std::this_thread::sleep_for(std::chrono::milliseconds(10));
63+
return state;
64+
}));
65+
66+
// Spin the node and check the final status.
67+
ASSERT_EQ(sn.spinUntilDone(), state);
6868
}
6969

7070
TEST_F(MockedAsyncActionFixture, no_halt)
7171
{
72-
// Test verifies that halt returns immediately, if the node is idle. It
73-
// further checks if the halt-flag is resetted correctly.
74-
sn.halt();
75-
ASSERT_TRUE(sn.isHaltRequested());
76-
77-
// Below we further verify that the halt flag is cleaned up properly.
78-
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
79-
EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
80-
81-
// Spin the node and check.
82-
ASSERT_EQ(sn.spinUntilDone(), state);
83-
ASSERT_FALSE(sn.isHaltRequested());
72+
// Test verifies that halt returns immediately, if the node is idle. It
73+
// further checks if the halt-flag is resetted correctly.
74+
sn.halt();
75+
ASSERT_TRUE(sn.isHaltRequested());
76+
77+
// Below we further verify that the halt flag is cleaned up properly.
78+
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
79+
EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
80+
81+
// Spin the node and check.
82+
ASSERT_EQ(sn.spinUntilDone(), state);
83+
ASSERT_FALSE(sn.isHaltRequested());
8484
}
8585

8686
TEST_F(MockedAsyncActionFixture, halt)
8787
{
88-
// Test verifies that calling halt() is blocking.
89-
bool release = false;
90-
std::mutex m;
91-
std::condition_variable cv;
92-
93-
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
94-
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
95-
// Sleep until we send the release signal.
96-
std::unique_lock<std::mutex> l(m);
97-
while (!release)
98-
cv.wait(l);
99-
100-
return state;
101-
}));
102-
103-
// Start the execution.
104-
sn.executeTick();
105-
106-
// Try to halt the node (cv will block it...)
107-
std::future<void> halted = std::async(std::launch::async, [&]() { sn.halt(); });
108-
ASSERT_EQ(halted.wait_for(std::chrono::milliseconds(10)), std::future_status::timeout);
109-
ASSERT_EQ(sn.status(), BT::NodeStatus::RUNNING);
110-
111-
// Release the method.
112-
{
113-
std::unique_lock<std::mutex> l(m);
114-
release = true;
115-
cv.notify_one();
116-
}
117-
118-
// Wait for the future to return.
119-
halted.wait();
120-
ASSERT_EQ(sn.status(), state);
88+
// Test verifies that calling halt() is blocking.
89+
bool release = false;
90+
std::mutex m;
91+
std::condition_variable cv;
92+
93+
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
94+
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
95+
// Sleep until we send the release signal.
96+
std::unique_lock<std::mutex> l(m);
97+
while (!release)
98+
cv.wait(l);
99+
100+
return state;
101+
}));
102+
103+
// Start the execution.
104+
sn.executeTick();
105+
106+
// Try to halt the node (cv will block it...)
107+
std::future<void> halted = std::async(std::launch::async, [&]() { sn.halt(); });
108+
ASSERT_EQ(halted.wait_for(std::chrono::milliseconds(10)), std::future_status::timeout);
109+
ASSERT_EQ(sn.status(), BT::NodeStatus::RUNNING);
110+
111+
// Release the method.
112+
{
113+
std::unique_lock<std::mutex> l(m);
114+
release = true;
115+
cv.notify_one();
116+
}
117+
118+
// Wait for the future to return.
119+
halted.wait();
120+
ASSERT_EQ(sn.status(), state);
121121
}
122122

123123
TEST_F(MockedAsyncActionFixture, exception)
124124
{
125-
// Verifies that we can recover from the exceptions in the tick method:
126-
// 1) catch the exception, 2) re-raise it in the caller thread.
127-
128-
// Setup the mock.
129-
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
130-
throw std::runtime_error("This is not good!");
131-
return BT::NodeStatus::SUCCESS;
132-
}));
133-
134-
ASSERT_ANY_THROW(sn.spinUntilDone());
135-
testing::Mock::VerifyAndClearExpectations(&sn);
136-
137-
// Now verify that the exception is cleared up (we succeed).
138-
sn.setStatus(BT::NodeStatus::IDLE);
139-
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
140-
EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
141-
ASSERT_EQ(sn.spinUntilDone(), state);
125+
// Verifies that we can recover from the exceptions in the tick method:
126+
// 1) catch the exception, 2) re-raise it in the caller thread.
127+
128+
// Setup the mock.
129+
EXPECT_CALL(sn, tick()).WillOnce(testing::Invoke([&]() {
130+
throw std::runtime_error("This is not good!");
131+
return BT::NodeStatus::SUCCESS;
132+
}));
133+
134+
ASSERT_ANY_THROW(sn.spinUntilDone());
135+
testing::Mock::VerifyAndClearExpectations(&sn);
136+
137+
// Now verify that the exception is cleared up (we succeed).
138+
sn.setStatus(BT::NodeStatus::IDLE);
139+
const BT::NodeStatus state{BT::NodeStatus::SUCCESS};
140+
EXPECT_CALL(sn, tick()).WillOnce(testing::Return(state));
141+
ASSERT_EQ(sn.spinUntilDone(), state);
142142
}

0 commit comments

Comments
 (0)