| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/upload_bytes_element_reader.h" | 5 #include "net/base/upload_bytes_element_reader.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/test/gtest_util.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 13 | 15 |
| 16 using net::test::IsOk; |
| 17 |
| 14 namespace net { | 18 namespace net { |
| 15 | 19 |
| 16 class UploadBytesElementReaderTest : public PlatformTest { | 20 class UploadBytesElementReaderTest : public PlatformTest { |
| 17 protected: | 21 protected: |
| 18 void SetUp() override { | 22 void SetUp() override { |
| 19 const char kData[] = "123abc"; | 23 const char kData[] = "123abc"; |
| 20 bytes_.assign(kData, kData + arraysize(kData)); | 24 bytes_.assign(kData, kData + arraysize(kData)); |
| 21 reader_.reset(new UploadBytesElementReader(&bytes_[0], bytes_.size())); | 25 reader_.reset(new UploadBytesElementReader(&bytes_[0], bytes_.size())); |
| 22 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); | 26 ASSERT_THAT(reader_->Init(CompletionCallback()), IsOk()); |
| 23 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); | 27 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); |
| 24 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); | 28 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); |
| 25 EXPECT_TRUE(reader_->IsInMemory()); | 29 EXPECT_TRUE(reader_->IsInMemory()); |
| 26 } | 30 } |
| 27 | 31 |
| 28 std::vector<char> bytes_; | 32 std::vector<char> bytes_; |
| 29 std::unique_ptr<UploadElementReader> reader_; | 33 std::unique_ptr<UploadElementReader> reader_; |
| 30 }; | 34 }; |
| 31 | 35 |
| 32 TEST_F(UploadBytesElementReaderTest, ReadPartially) { | 36 TEST_F(UploadBytesElementReaderTest, ReadPartially) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); | 75 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); |
| 72 | 76 |
| 73 // Read all. | 77 // Read all. |
| 74 EXPECT_EQ( | 78 EXPECT_EQ( |
| 75 static_cast<int>(buf.size()), | 79 static_cast<int>(buf.size()), |
| 76 reader_->Read(wrapped_buffer.get(), buf.size(), CompletionCallback())); | 80 reader_->Read(wrapped_buffer.get(), buf.size(), CompletionCallback())); |
| 77 EXPECT_EQ(0U, reader_->BytesRemaining()); | 81 EXPECT_EQ(0U, reader_->BytesRemaining()); |
| 78 EXPECT_EQ(bytes_, buf); | 82 EXPECT_EQ(bytes_, buf); |
| 79 | 83 |
| 80 // Call Init() again to reset the state. | 84 // Call Init() again to reset the state. |
| 81 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); | 85 ASSERT_THAT(reader_->Init(CompletionCallback()), IsOk()); |
| 82 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); | 86 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); |
| 83 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); | 87 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); |
| 84 | 88 |
| 85 // Read again. | 89 // Read again. |
| 86 EXPECT_EQ( | 90 EXPECT_EQ( |
| 87 static_cast<int>(buf.size()), | 91 static_cast<int>(buf.size()), |
| 88 reader_->Read(wrapped_buffer.get(), buf.size(), CompletionCallback())); | 92 reader_->Read(wrapped_buffer.get(), buf.size(), CompletionCallback())); |
| 89 EXPECT_EQ(0U, reader_->BytesRemaining()); | 93 EXPECT_EQ(0U, reader_->BytesRemaining()); |
| 90 EXPECT_EQ(bytes_, buf); | 94 EXPECT_EQ(bytes_, buf); |
| 91 } | 95 } |
| 92 | 96 |
| 93 } // namespace net | 97 } // namespace net |
| OLD | NEW |