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

Unified Diff: net/base/upload_bytes_element_reader_unittest.cc

Issue 10868064: net: Move data reading functionalities from UploadElement to UploadElementReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/upload_bytes_element_reader.cc ('k') | net/base/upload_data_stream.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/upload_bytes_element_reader_unittest.cc
diff --git a/net/base/upload_bytes_element_reader_unittest.cc b/net/base/upload_bytes_element_reader_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e68febd493aa58f4157041e2f52241bb1422643
--- /dev/null
+++ b/net/base/upload_bytes_element_reader_unittest.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/base/upload_bytes_element_reader.h"
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "net/base/net_errors.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace net {
+
+class UploadBytesElementReaderTest : public PlatformTest {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ const char kData[] = "123abc";
+ bytes_.assign(kData, kData + arraysize(kData));
+ reader_.reset(new UploadBytesElementReader(&bytes_[0], bytes_.size()));
+ ASSERT_EQ(OK, reader_->InitSync());
+ EXPECT_EQ(bytes_.size(), reader_->GetContentLength());
+ EXPECT_EQ(bytes_.size(), reader_->BytesRemaining());
+ EXPECT_TRUE(reader_->IsInMemory());
+ }
+
+ std::vector<char> bytes_;
+ scoped_ptr<UploadElementReader> reader_;
+};
+
+TEST_F(UploadBytesElementReaderTest, ReadPartially) {
+ const size_t kHalfSize = bytes_.size() / 2;
+ std::vector<char> buf(kHalfSize);
+ EXPECT_EQ(static_cast<int>(buf.size()),
+ reader_->ReadSync(&buf[0], buf.size()));
+ EXPECT_EQ(bytes_.size() - buf.size(), reader_->BytesRemaining());
+ bytes_.resize(kHalfSize); // Resize to compare.
+ EXPECT_EQ(bytes_, buf);
+}
+
+TEST_F(UploadBytesElementReaderTest, ReadAll) {
+ std::vector<char> buf(bytes_.size());
+ EXPECT_EQ(static_cast<int>(buf.size()),
+ reader_->ReadSync(&buf[0], buf.size()));
+ EXPECT_EQ(0U, reader_->BytesRemaining());
+ EXPECT_EQ(bytes_, buf);
+ // Try to read again.
+ EXPECT_EQ(0, reader_->ReadSync(&buf[0], buf.size()));
+}
+
+TEST_F(UploadBytesElementReaderTest, ReadTooMuch) {
+ const size_t kTooLargeSize = bytes_.size() * 2;
+ std::vector<char> buf(kTooLargeSize);
+ EXPECT_EQ(static_cast<int>(bytes_.size()),
+ reader_->ReadSync(&buf[0], buf.size()));
+ EXPECT_EQ(0U, reader_->BytesRemaining());
+ buf.resize(bytes_.size()); // Resize to compare.
+ EXPECT_EQ(bytes_, buf);
+}
+
+} // namespace net
« no previous file with comments | « net/base/upload_bytes_element_reader.cc ('k') | net/base/upload_data_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698