Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1102)

Side by Side Diff: net/base/upload_bytes_element_reader_unittest.cc

Issue 10910268: net: Make UploadDataStream::Read() asynchronous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/upload_bytes_element_reader.cc ('k') | net/base/upload_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "net/base/io_buffer.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 12 #include "testing/platform_test.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 class UploadBytesElementReaderTest : public PlatformTest { 16 class UploadBytesElementReaderTest : public PlatformTest {
16 protected: 17 protected:
17 virtual void SetUp() OVERRIDE { 18 virtual void SetUp() OVERRIDE {
18 const char kData[] = "123abc"; 19 const char kData[] = "123abc";
19 bytes_.assign(kData, kData + arraysize(kData)); 20 bytes_.assign(kData, kData + arraysize(kData));
20 reader_.reset(new UploadBytesElementReader(&bytes_[0], bytes_.size())); 21 reader_.reset(new UploadBytesElementReader(&bytes_[0], bytes_.size()));
21 ASSERT_EQ(OK, reader_->InitSync()); 22 ASSERT_EQ(OK, reader_->InitSync());
22 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); 23 EXPECT_EQ(bytes_.size(), reader_->GetContentLength());
23 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); 24 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining());
24 EXPECT_TRUE(reader_->IsInMemory()); 25 EXPECT_TRUE(reader_->IsInMemory());
25 } 26 }
26 27
27 std::vector<char> bytes_; 28 std::vector<char> bytes_;
28 scoped_ptr<UploadElementReader> reader_; 29 scoped_ptr<UploadElementReader> reader_;
29 }; 30 };
30 31
31 TEST_F(UploadBytesElementReaderTest, ReadPartially) { 32 TEST_F(UploadBytesElementReaderTest, ReadPartially) {
32 const size_t kHalfSize = bytes_.size() / 2; 33 const size_t kHalfSize = bytes_.size() / 2;
33 std::vector<char> buf(kHalfSize); 34 std::vector<char> buf(kHalfSize);
35 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]);
34 EXPECT_EQ(static_cast<int>(buf.size()), 36 EXPECT_EQ(static_cast<int>(buf.size()),
35 reader_->ReadSync(&buf[0], buf.size())); 37 reader_->ReadSync(wrapped_buffer, buf.size()));
36 EXPECT_EQ(bytes_.size() - buf.size(), reader_->BytesRemaining()); 38 EXPECT_EQ(bytes_.size() - buf.size(), reader_->BytesRemaining());
37 bytes_.resize(kHalfSize); // Resize to compare. 39 bytes_.resize(kHalfSize); // Resize to compare.
38 EXPECT_EQ(bytes_, buf); 40 EXPECT_EQ(bytes_, buf);
39 } 41 }
40 42
41 TEST_F(UploadBytesElementReaderTest, ReadAll) { 43 TEST_F(UploadBytesElementReaderTest, ReadAll) {
42 std::vector<char> buf(bytes_.size()); 44 std::vector<char> buf(bytes_.size());
45 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]);
43 EXPECT_EQ(static_cast<int>(buf.size()), 46 EXPECT_EQ(static_cast<int>(buf.size()),
44 reader_->ReadSync(&buf[0], buf.size())); 47 reader_->ReadSync(wrapped_buffer, buf.size()));
45 EXPECT_EQ(0U, reader_->BytesRemaining()); 48 EXPECT_EQ(0U, reader_->BytesRemaining());
46 EXPECT_EQ(bytes_, buf); 49 EXPECT_EQ(bytes_, buf);
47 // Try to read again. 50 // Try to read again.
48 EXPECT_EQ(0, reader_->ReadSync(&buf[0], buf.size())); 51 EXPECT_EQ(0, reader_->ReadSync(wrapped_buffer, buf.size()));
49 } 52 }
50 53
51 TEST_F(UploadBytesElementReaderTest, ReadTooMuch) { 54 TEST_F(UploadBytesElementReaderTest, ReadTooMuch) {
52 const size_t kTooLargeSize = bytes_.size() * 2; 55 const size_t kTooLargeSize = bytes_.size() * 2;
53 std::vector<char> buf(kTooLargeSize); 56 std::vector<char> buf(kTooLargeSize);
57 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]);
54 EXPECT_EQ(static_cast<int>(bytes_.size()), 58 EXPECT_EQ(static_cast<int>(bytes_.size()),
55 reader_->ReadSync(&buf[0], buf.size())); 59 reader_->ReadSync(wrapped_buffer, buf.size()));
56 EXPECT_EQ(0U, reader_->BytesRemaining()); 60 EXPECT_EQ(0U, reader_->BytesRemaining());
57 buf.resize(bytes_.size()); // Resize to compare. 61 buf.resize(bytes_.size()); // Resize to compare.
58 EXPECT_EQ(bytes_, buf); 62 EXPECT_EQ(bytes_, buf);
59 } 63 }
60 64
61 } // namespace net 65 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_bytes_element_reader.cc ('k') | net/base/upload_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698