| 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 "base/platform_test.h" |
| 7 #include "net/base/listen_socket_unittest.h" | 8 #include "net/base/listen_socket_unittest.h" |
| 8 #include "net/base/telnet_server.h" | 9 #include "net/base/telnet_server.h" |
| 9 | 10 |
| 10 namespace { | 11 static const char* kCRLF = "\r\n"; |
| 11 | |
| 12 const std::string CRLF("\r\n"); | |
| 13 | 12 |
| 14 class TelnetServerTester : public ListenSocketTester { | 13 class TelnetServerTester : public ListenSocketTester { |
| 15 public: | 14 public: |
| 16 virtual ListenSocket* DoListen() { | 15 virtual ListenSocket* DoListen() { |
| 17 return TelnetServer::Listen("127.0.0.1", TEST_PORT, this); | 16 return TelnetServer::Listen("127.0.0.1", kTestPort, this); |
| 18 } | 17 } |
| 19 | 18 |
| 20 virtual void SetUp() { | 19 virtual void SetUp() { |
| 21 ListenSocketTester::SetUp(); | 20 ListenSocketTester::SetUp(); |
| 22 // With TelnetServer, there's some control codes sent at connect time, | 21 // With TelnetServer, there's some control codes sent at connect time, |
| 23 // so we need to eat those to avoid affecting the subsequent tests. | 22 // so we need to eat those to avoid affecting the subsequent tests. |
| 24 // TODO(erikkay): Unfortunately, without the sleep, we don't seem to | 23 EXPECT_EQ(ClearTestSocket(), 15); |
| 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); | |
| 29 } | 24 } |
| 30 | 25 |
| 31 virtual bool Send(SOCKET sock, const std::string& str) { | 26 virtual bool Send(SOCKET sock, const std::string& str) { |
| 32 if (ListenSocketTester::Send(sock, str)) { | 27 if (ListenSocketTester::Send(sock, str)) { |
| 33 // TelnetServer currently calls DidRead after a CRLF, so we need to | 28 // TelnetServer currently calls DidRead after a CRLF, so we need to |
| 34 // append one to the end of the data that we send. | 29 // append one to the end of the data that we send. |
| 35 if (ListenSocketTester::Send(sock, CRLF)) { | 30 if (ListenSocketTester::Send(sock, kCRLF)) { |
| 36 return true; | 31 return true; |
| 37 } | 32 } |
| 38 } | 33 } |
| 39 return false; | 34 return false; |
| 40 } | 35 } |
| 41 }; | 36 }; |
| 42 | 37 |
| 43 class TelnetServerTest: public testing::Test { | 38 class TelnetServerTest: public PlatformTest { |
| 44 protected: | 39 protected: |
| 45 TelnetServerTest() { | 40 TelnetServerTest() { |
| 46 tester_ = NULL; | 41 tester_ = NULL; |
| 47 } | 42 } |
| 48 | 43 |
| 49 virtual void SetUp() { | 44 virtual void SetUp() { |
| 45 PlatformTest::SetUp(); |
| 50 tester_ = new TelnetServerTester(); | 46 tester_ = new TelnetServerTester(); |
| 51 tester_->SetUp(); | 47 tester_->SetUp(); |
| 52 } | 48 } |
| 53 | 49 |
| 54 virtual void TearDown() { | 50 virtual void TearDown() { |
| 51 PlatformTest::TearDown(); |
| 55 tester_->TearDown(); | 52 tester_->TearDown(); |
| 56 tester_ = NULL; | 53 tester_ = NULL; |
| 57 } | 54 } |
| 58 | 55 |
| 59 scoped_refptr<TelnetServerTester> tester_; | 56 scoped_refptr<TelnetServerTester> tester_; |
| 60 }; | 57 }; |
| 61 | 58 |
| 62 } // namespace | |
| 63 | |
| 64 TEST_F(TelnetServerTest, ServerClientSend) { | 59 TEST_F(TelnetServerTest, ServerClientSend) { |
| 65 tester_->TestClientSend(); | 60 tester_->TestClientSend(); |
| 66 } | 61 } |
| 67 | 62 |
| 68 TEST_F(TelnetServerTest, ClientSendLong) { | 63 TEST_F(TelnetServerTest, ClientSendLong) { |
| 69 tester_->TestClientSendLong(); | 64 tester_->TestClientSendLong(); |
| 70 } | 65 } |
| 71 | 66 |
| 72 TEST_F(TelnetServerTest, ServerSend) { | 67 TEST_F(TelnetServerTest, ServerSend) { |
| 73 tester_->TestServerSend(); | 68 tester_->TestServerSend(); |
| 74 } | 69 } |
| 75 | 70 |
| OLD | NEW |