|
29 | 29 | // -- END LICENSE BLOCK ------------------------------------------------ |
30 | 30 |
|
31 | 31 | #include <gtest/gtest.h> |
| 32 | +#include <chrono> |
32 | 33 | #include <condition_variable> |
| 34 | +#include <cstddef> |
33 | 35 |
|
34 | 36 | #include <ur_client_library/comm/tcp_socket.h> |
35 | 37 | #include <ur_client_library/comm/tcp_server.h> |
@@ -101,15 +103,16 @@ class TCPSocketTest : public ::testing::Test |
101 | 103 | class Client : public comm::TCPSocket |
102 | 104 | { |
103 | 105 | public: |
104 | | - Client(int port) |
| 106 | + Client(int port, const std::string& ip = "127.0.0.1", const size_t max_num_tries = 0) |
105 | 107 | { |
106 | 108 | port_ = port; |
| 109 | + ip_ = ip; |
| 110 | + max_num_tries_ = max_num_tries; |
107 | 111 | } |
108 | 112 |
|
109 | 113 | bool setup() |
110 | 114 | { |
111 | | - std::string ip = "127.0.0.1"; |
112 | | - return TCPSocket::setup(ip, port_); |
| 115 | + return TCPSocket::setup(ip_, port_, max_num_tries_); |
113 | 116 | } |
114 | 117 |
|
115 | 118 | void setupClientBeforeServer() |
@@ -145,6 +148,8 @@ class TCPSocketTest : public ::testing::Test |
145 | 148 | private: |
146 | 149 | std::thread client_setup_thread_; |
147 | 150 | int port_; |
| 151 | + std::string ip_; |
| 152 | + size_t max_num_tries_; |
148 | 153 | bool done_setting_up_client_; |
149 | 154 |
|
150 | 155 | void setupClient(int port) |
@@ -341,6 +346,13 @@ TEST_F(TCPSocketTest, setup_while_client_is_connected) |
341 | 346 | EXPECT_FALSE(client_->setup()); |
342 | 347 | } |
343 | 348 |
|
| 349 | +TEST_F(TCPSocketTest, connect_non_running_robot) |
| 350 | +{ |
| 351 | + Client client(12321, "127.0.0.1", 2); |
| 352 | + client.setReconnectionTime(std::chrono::milliseconds(500)); |
| 353 | + EXPECT_FALSE(client.setup()); |
| 354 | +} |
| 355 | + |
344 | 356 | int main(int argc, char* argv[]) |
345 | 357 | { |
346 | 358 | ::testing::InitGoogleTest(&argc, argv); |
|
0 commit comments