Skip to content

Commit 7f611cc

Browse files
committed
Add unit tests for dashboard client's base functionalities failures
1 parent cd15163 commit 7f611cc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_dashboard_client.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,33 @@ TEST_F(DashboardClientTest, connect_non_running_robot)
219219
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
220220
}
221221

222+
TEST_F(DashboardClientTest, non_expected_result_returns_correctly)
223+
{
224+
std::unique_ptr<DashboardClient> dashboard_client;
225+
dashboard_client.reset(new DashboardClient("192.168.56.101"));
226+
ASSERT_TRUE(dashboard_client->connect());
227+
EXPECT_TRUE(dashboard_client->commandPowerOff());
228+
229+
// We will not get this answer
230+
EXPECT_FALSE(dashboard_client->sendRequest("brake release", "non-existing-response"));
231+
232+
// A non-matching answer should throw an exception for this call
233+
EXPECT_THROW(dashboard_client->sendRequestString("brake release", "non-existing-response"), UrException);
234+
235+
// Waiting for a non-matching answer should return false
236+
// Internally we wait 100ms between each attempt, hence the 300ms wait time
237+
EXPECT_FALSE(
238+
dashboard_client->waitForReply("brake_release", "non-existing-response", std::chrono::milliseconds(300)));
239+
}
240+
241+
TEST_F(DashboardClientTest, connecting_twoice_returns_false)
242+
{
243+
std::unique_ptr<DashboardClient> dashboard_client;
244+
dashboard_client.reset(new DashboardClient("192.168.56.101"));
245+
ASSERT_TRUE(dashboard_client->connect());
246+
EXPECT_FALSE(dashboard_client->connect());
247+
}
248+
222249
int main(int argc, char* argv[])
223250
{
224251
::testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)