| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Tests TelnetServer. | 5 // Tests TelnetServer. |
| 6 | 6 |
| 7 #include "net/base/listen_socket_unittest.h" | 7 #include "net/base/listen_socket_unittest.h" |
| 8 #include "net/base/telnet_server.h" | 8 #include "net/base/telnet_server.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 const std::string CRLF("\r\n"); | 12 const std::string CRLF("\r\n"); |
| 13 | 13 |
| 14 class TelnetServerTester : public ListenSocketTester { | 14 class TelnetServerTester : public ListenSocketTester { |
| 15 public: | 15 public: |
| 16 virtual ListenSocket* DoListen() { | 16 virtual ListenSocket* DoListen() { |
| 17 return TelnetServer::Listen("127.0.0.1", TEST_PORT, this); | 17 return TelnetServer::Listen("127.0.0.1", TEST_PORT, this); |
| 18 } | 18 } |
| 19 | 19 |
| 20 virtual void SetUp() { | 20 virtual void SetUp() { |
| 21 ListenSocketTester::SetUp(); | 21 ListenSocketTester::SetUp(); |
| 22 // With TelnetServer, there's some control codes sent at connect time, | 22 // With TelnetServer, there's some control codes sent at connect time, |
| 23 // so we need to eat those to avoid affecting the subsequent tests. | 23 // so we need to eat those to avoid affecting the subsequent tests. |
| 24 // TODO(erikkay): Unfortunately, without the sleep, we don't seem to | |
| 25 // reliably get the 15 bytes without an EWOULDBLOCK. It would be nice if | |
| 26 // there were a more reliable mechanism here. | |
| 27 Sleep(10); | |
| 28 ASSERT_EQ(ClearTestSocket(), 15); | 24 ASSERT_EQ(ClearTestSocket(), 15); |
| 29 } | 25 } |
| 30 | 26 |
| 31 virtual bool Send(SOCKET sock, const std::string& str) { | 27 virtual bool Send(SOCKET sock, const std::string& str) { |
| 32 if (ListenSocketTester::Send(sock, str)) { | 28 if (ListenSocketTester::Send(sock, str)) { |
| 33 // TelnetServer currently calls DidRead after a CRLF, so we need to | 29 // TelnetServer currently calls DidRead after a CRLF, so we need to |
| 34 // append one to the end of the data that we send. | 30 // append one to the end of the data that we send. |
| 35 if (ListenSocketTester::Send(sock, CRLF)) { | 31 if (ListenSocketTester::Send(sock, CRLF)) { |
| 36 return true; | 32 return true; |
| 37 } | 33 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 66 } | 62 } |
| 67 | 63 |
| 68 TEST_F(TelnetServerTest, ClientSendLong) { | 64 TEST_F(TelnetServerTest, ClientSendLong) { |
| 69 tester_->TestClientSendLong(); | 65 tester_->TestClientSendLong(); |
| 70 } | 66 } |
| 71 | 67 |
| 72 TEST_F(TelnetServerTest, ServerSend) { | 68 TEST_F(TelnetServerTest, ServerSend) { |
| 73 tester_->TestServerSend(); | 69 tester_->TestServerSend(); |
| 74 } | 70 } |
| 75 | 71 |
| OLD | NEW |