31 #include <gtest/gtest.h> 45 std::string host =
"127.0.0.1";
46 TCPSocket::setup(host, port);
50 TCPSocket::setReceiveTimeout(tv);
53 void send(
const std::string& text)
55 size_t len = text.size();
56 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(text.c_str());
58 TCPSocket::write(data, len, written);
63 std::stringstream result;
65 size_t read_chars = 99;
66 while (read_chars > 0)
68 if (!TCPSocket::read((uint8_t*)&character, 1, read_chars))
73 if (character ==
'\n')
82 virtual bool open(
int socket_fd,
struct sockaddr* address,
size_t address_len)
84 return ::connect(socket_fd, address, address_len) == 0;
90 program_ =
"test program\n";
92 client_.reset(
new Client(50002));
110 std::string wrong_request =
"request\n";
111 client_->send(wrong_request);
115 std::string actual_answer = client_->recv();
116 std::string expected_answer =
"";
117 EXPECT_EQ(expected_answer, actual_answer);
122 std::string request =
"request_program\n";
123 client_->send(request);
125 std::string received_program = client_->recv();
126 EXPECT_EQ(program_, received_program);
129 int main(
int argc,
char* argv[])
131 ::testing::InitGoogleTest(&argc, argv);
133 return RUN_ALL_TESTS();
std::unique_ptr< control::ScriptSender > script_sender_
TEST_F(ScriptSenderTest, wrong_request_command)
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
The ScriptSender class starts a TCPServer for a robot to connect to and waits for a request to receiv...
void send(const std::string &text)
Class for TCP socket abstraction.
Socket is connected and ready to use.
std::unique_ptr< Client > client_
int main(int argc, char *argv[])