| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "net/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
| 6 | 6 |
| 7 #include "testing/platform_test.h" | 7 #include "testing/platform_test.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 //----------------------------------------------------------------------------- | 10 //----------------------------------------------------------------------------- |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 ASSERT_EQ(rv, sock_->Read(read_buf_, len, &read_callback_)); | 124 ASSERT_EQ(rv, sock_->Read(read_buf_, len, &read_callback_)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void DeterministicSocketDataTest::AssertReadBufferEquals(const char* data, | 127 void DeterministicSocketDataTest::AssertReadBufferEquals(const char* data, |
| 128 int len) { | 128 int len) { |
| 129 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); | 129 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void DeterministicSocketDataTest::AssertSyncWriteEquals(const char* data, | 132 void DeterministicSocketDataTest::AssertSyncWriteEquals(const char* data, |
| 133 int len) { | 133 int len) { |
| 134 scoped_refptr<IOBuffer> buf = new IOBuffer(len); | 134 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
| 135 memcpy(buf->data(), data, len); | 135 memcpy(buf->data(), data, len); |
| 136 | 136 |
| 137 // Issue the write, which will complete immediately | 137 // Issue the write, which will complete immediately |
| 138 ASSERT_EQ(len, sock_->Write(buf, len, &write_callback_)); | 138 ASSERT_EQ(len, sock_->Write(buf, len, &write_callback_)); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void DeterministicSocketDataTest::AssertAsyncWriteEquals(const char* data, | 141 void DeterministicSocketDataTest::AssertAsyncWriteEquals(const char* data, |
| 142 int len) { | 142 int len) { |
| 143 // Issue the read, which will be completed asynchronously | 143 // Issue the read, which will be completed asynchronously |
| 144 AssertWriteReturns(data, len, ERR_IO_PENDING); | 144 AssertWriteReturns(data, len, ERR_IO_PENDING); |
| 145 | 145 |
| 146 EXPECT_FALSE(read_callback_.have_result()); | 146 EXPECT_FALSE(read_callback_.have_result()); |
| 147 EXPECT_TRUE(sock_->IsConnected()); | 147 EXPECT_TRUE(sock_->IsConnected()); |
| 148 data_->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked | 148 data_->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked |
| 149 | 149 |
| 150 ASSERT_EQ(len, write_callback_.WaitForResult()); | 150 ASSERT_EQ(len, write_callback_.WaitForResult()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void DeterministicSocketDataTest::AssertWriteReturns(const char* data, | 153 void DeterministicSocketDataTest::AssertWriteReturns(const char* data, |
| 154 int len, int rv) { | 154 int len, int rv) { |
| 155 scoped_refptr<IOBuffer> buf = new IOBuffer(len); | 155 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
| 156 memcpy(buf->data(), data, len); | 156 memcpy(buf->data(), data, len); |
| 157 | 157 |
| 158 // Issue the read, which will complete asynchronously | 158 // Issue the read, which will complete asynchronously |
| 159 ASSERT_EQ(rv, sock_->Write(buf, len, &write_callback_)); | 159 ASSERT_EQ(rv, sock_->Write(buf, len, &write_callback_)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // ----------- Read | 162 // ----------- Read |
| 163 | 163 |
| 164 TEST_F(DeterministicSocketDataTest, SingleSyncReadWhileStopped) { | 164 TEST_F(DeterministicSocketDataTest, SingleSyncReadWhileStopped) { |
| 165 MockRead reads[] = { | 165 MockRead reads[] = { |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 // Issue the writes which will complete immediately | 521 // Issue the writes which will complete immediately |
| 522 data_->StopAfter(1); | 522 data_->StopAfter(1); |
| 523 AssertSyncWriteEquals(kMsg3, kLen3); | 523 AssertSyncWriteEquals(kMsg3, kLen3); |
| 524 | 524 |
| 525 data_->RunFor(1); | 525 data_->RunFor(1); |
| 526 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); | 526 ASSERT_EQ(kLen2, read_callback_.WaitForResult()); |
| 527 AssertReadBufferEquals(kMsg2, kLen2); | 527 AssertReadBufferEquals(kMsg2, kLen2); |
| 528 } | 528 } |
| 529 | 529 |
| 530 } // namespace net | 530 } // namespace net |
| OLD | NEW |