diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 21:50:28 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 21:50:28 +0000 |
commit | 03ec25380e837518ede1b03d9a05669e9bc1746c (patch) | |
tree | ef0267608031c7d7a58301563190bab47bbd99be /net/socket/tcp_server_socket_unittest.cc | |
parent | 9815108ef72b28eab4c78fe43db9db171f24cd57 (diff) | |
download | chromium_src-03ec25380e837518ede1b03d9a05669e9bc1746c.zip chromium_src-03ec25380e837518ede1b03d9a05669e9bc1746c.tar.gz chromium_src-03ec25380e837518ede1b03d9a05669e9bc1746c.tar.bz2 |
Bind() methods for TCP sockets
BUG=80245
TEST=None
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=87077
Review URL: http://codereview.chromium.org/7004055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87095 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/tcp_server_socket_unittest.cc')
-rw-r--r-- | net/socket/tcp_server_socket_unittest.cc | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/net/socket/tcp_server_socket_unittest.cc b/net/socket/tcp_server_socket_unittest.cc index d4abe9d..c14f22e 100644 --- a/net/socket/tcp_server_socket_unittest.cc +++ b/net/socket/tcp_server_socket_unittest.cc @@ -26,13 +26,26 @@ class TCPServerSocketTest : public PlatformTest { : socket_(NULL, NetLog::Source()) { } - void SetUp() OVERRIDE { + void SetUpIPv4() { IPEndPoint address; ParseAddress("127.0.0.1", 0, &address); ASSERT_EQ(OK, socket_.Listen(address, kListenBacklog)); ASSERT_EQ(OK, socket_.GetLocalAddress(&local_address_)); } + void SetUpIPv6(bool* success) { + *success = false; + IPEndPoint address; + ParseAddress("::1", 0, &address); + if (socket_.Listen(address, kListenBacklog) != 0) { + LOG(ERROR) << "Failed to listen on ::1 - probably because IPv6 is " + "disabled. Skipping the test"; + return; + } + ASSERT_EQ(OK, socket_.GetLocalAddress(&local_address_)); + *success = true; + } + void ParseAddress(std::string ip_str, int port, IPEndPoint* address) { IPAddressNumber ip_number; bool rv = ParseIPLiteralToNumber(ip_str, &ip_number); @@ -60,6 +73,8 @@ class TCPServerSocketTest : public PlatformTest { }; TEST_F(TCPServerSocketTest, Accept) { + ASSERT_NO_FATAL_FAILURE(SetUpIPv4()); + TestCompletionCallback connect_callback; TCPClientSocket connecting_socket(local_address_list(), NULL, NetLog::Source()); @@ -83,6 +98,8 @@ TEST_F(TCPServerSocketTest, Accept) { // Test Accept() callback. TEST_F(TCPServerSocketTest, AcceptAsync) { + ASSERT_NO_FATAL_FAILURE(SetUpIPv4()); + TestCompletionCallback accept_callback; scoped_ptr<StreamSocket> accepted_socket; @@ -105,6 +122,8 @@ TEST_F(TCPServerSocketTest, AcceptAsync) { // Accept two connections simultaneously. TEST_F(TCPServerSocketTest, Accept2Connections) { + ASSERT_NO_FATAL_FAILURE(SetUpIPv4()); + TestCompletionCallback accept_callback; scoped_ptr<StreamSocket> accepted_socket; @@ -142,6 +161,33 @@ TEST_F(TCPServerSocketTest, Accept2Connections) { local_address_.address()); } +TEST_F(TCPServerSocketTest, AcceptIPv6) { + bool initialized = false; + ASSERT_NO_FATAL_FAILURE(SetUpIPv6(&initialized)); + if (!initialized) + return; + + TestCompletionCallback connect_callback; + TCPClientSocket connecting_socket(local_address_list(), + NULL, NetLog::Source()); + connecting_socket.Connect(&connect_callback); + + TestCompletionCallback accept_callback; + scoped_ptr<StreamSocket> accepted_socket; + int result = socket_.Accept(&accepted_socket, &accept_callback); + if (result == ERR_IO_PENDING) + result = accept_callback.WaitForResult(); + ASSERT_EQ(OK, result); + + ASSERT_TRUE(accepted_socket.get() != NULL); + + // Both sockets should be on the loopback network interface. + EXPECT_EQ(GetPeerAddress(accepted_socket.get()).address(), + local_address_.address()); + + EXPECT_EQ(OK, connect_callback.WaitForResult()); +} + } // namespace } // namespace net |