Basic socket send & receive test
| 23 | |
| 24 | // Basic socket send & receive test |
| 25 | TEST(Socket, SendRecv) { |
| 26 | const char* port = "19021"; |
| 27 | |
| 28 | auto server = dap::Socket("localhost", port); |
| 29 | |
| 30 | auto client = dap::Socket::connect("localhost", port, 0); |
| 31 | ASSERT_TRUE(client != nullptr); |
| 32 | |
| 33 | const std::string expect = "Hello World!"; |
| 34 | std::string read; |
| 35 | |
| 36 | auto thread = std::thread([&] { |
| 37 | auto conn = server.accept(); |
| 38 | ASSERT_TRUE(conn != nullptr); |
| 39 | char c; |
| 40 | while (conn->read(&c, 1) != 0) { |
| 41 | read += c; |
| 42 | } |
| 43 | }); |
| 44 | |
| 45 | ASSERT_TRUE(client->write(expect.data(), expect.size())); |
| 46 | |
| 47 | client->close(); |
| 48 | thread.join(); |
| 49 | |
| 50 | ASSERT_EQ(read, expect); |
| 51 | } |
| 52 | |
| 53 | // See https://github.com/google/cppdap/issues/37 |
| 54 | TEST(Socket, CloseOnDifferentThread) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…