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

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

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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
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/elements_upload_data_stream.h" 5 #include "net/base/elements_upload_data_stream.h"
6 6
7 #include <stdint.h>
8
7 #include <algorithm> 9 #include <algorithm>
10 #include <limits>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/basictypes.h" 13 #include "base/basictypes.h"
11 #include "base/bind.h" 14 #include "base/bind.h"
12 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 17 #include "base/files/scoped_temp_dir.h"
15 #include "base/location.h" 18 #include "base/location.h"
16 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h" 20 #include "base/message_loop/message_loop.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 179 }
177 180
178 TEST_F(ElementsUploadDataStreamTest, File) { 181 TEST_F(ElementsUploadDataStreamTest, File) {
179 base::FilePath temp_file_path; 182 base::FilePath temp_file_path;
180 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 183 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
181 &temp_file_path)); 184 &temp_file_path));
182 ASSERT_EQ(static_cast<int>(kTestDataSize), 185 ASSERT_EQ(static_cast<int>(kTestDataSize),
183 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 186 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
184 187
185 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 188 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
186 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 189 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
187 base::Time()))); 190 std::numeric_limits<uint64_t>::max(), base::Time())));
188 191
189 TestCompletionCallback init_callback; 192 TestCompletionCallback init_callback;
190 scoped_ptr<UploadDataStream> stream( 193 scoped_ptr<UploadDataStream> stream(
191 new ElementsUploadDataStream(std::move(element_readers_), 0)); 194 new ElementsUploadDataStream(std::move(element_readers_), 0));
192 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback.callback())); 195 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback.callback()));
193 ASSERT_EQ(OK, init_callback.WaitForResult()); 196 ASSERT_EQ(OK, init_callback.WaitForResult());
194 EXPECT_FALSE(stream->IsInMemory()); 197 EXPECT_FALSE(stream->IsInMemory());
195 EXPECT_EQ(kTestDataSize, stream->size()); 198 EXPECT_EQ(kTestDataSize, stream->size());
196 EXPECT_EQ(0U, stream->position()); 199 EXPECT_EQ(0U, stream->position());
197 EXPECT_FALSE(stream->IsEOF()); 200 EXPECT_FALSE(stream->IsEOF());
(...skipping 14 matching lines...) Expand all
212 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 215 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
213 &temp_file_path)); 216 &temp_file_path));
214 ASSERT_EQ(static_cast<int>(kTestDataSize), 217 ASSERT_EQ(static_cast<int>(kTestDataSize),
215 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 218 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
216 const uint64_t kFakeSize = kTestDataSize * 2; 219 const uint64_t kFakeSize = kTestDataSize * 2;
217 220
218 UploadFileElementReader::ScopedOverridingContentLengthForTests 221 UploadFileElementReader::ScopedOverridingContentLengthForTests
219 overriding_content_length(kFakeSize); 222 overriding_content_length(kFakeSize);
220 223
221 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 224 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
222 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 225 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
223 base::Time()))); 226 std::numeric_limits<uint64_t>::max(), base::Time())));
224 227
225 TestCompletionCallback init_callback; 228 TestCompletionCallback init_callback;
226 scoped_ptr<UploadDataStream> stream( 229 scoped_ptr<UploadDataStream> stream(
227 new ElementsUploadDataStream(std::move(element_readers_), 0)); 230 new ElementsUploadDataStream(std::move(element_readers_), 0));
228 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback.callback())); 231 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback.callback()));
229 ASSERT_EQ(OK, init_callback.WaitForResult()); 232 ASSERT_EQ(OK, init_callback.WaitForResult());
230 EXPECT_FALSE(stream->IsInMemory()); 233 EXPECT_FALSE(stream->IsInMemory());
231 EXPECT_EQ(kFakeSize, stream->size()); 234 EXPECT_EQ(kFakeSize, stream->size());
232 EXPECT_EQ(0U, stream->position()); 235 EXPECT_EQ(0U, stream->position());
233 EXPECT_FALSE(stream->IsEOF()); 236 EXPECT_FALSE(stream->IsEOF());
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 base::FilePath temp_file_path; 565 base::FilePath temp_file_path;
563 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 566 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
564 &temp_file_path)); 567 &temp_file_path));
565 ASSERT_EQ(static_cast<int>(kTestDataSize), 568 ASSERT_EQ(static_cast<int>(kTestDataSize),
566 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 569 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
567 570
568 // Prepare data. 571 // Prepare data.
569 element_readers_.push_back( 572 element_readers_.push_back(
570 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize))); 573 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize)));
571 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 574 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
572 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 575 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
573 base::Time()))); 576 std::numeric_limits<uint64_t>::max(), base::Time())));
574 scoped_ptr<UploadDataStream> stream( 577 scoped_ptr<UploadDataStream> stream(
575 new ElementsUploadDataStream(std::move(element_readers_), 0)); 578 new ElementsUploadDataStream(std::move(element_readers_), 0));
576 579
577 std::string expected_data(kTestData, kTestData + kTestDataSize); 580 std::string expected_data(kTestData, kTestData + kTestDataSize);
578 expected_data += expected_data; 581 expected_data += expected_data;
579 582
580 // Call Init(). 583 // Call Init().
581 TestCompletionCallback init_callback1; 584 TestCompletionCallback init_callback1;
582 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback())); 585 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback()));
583 ASSERT_EQ(OK, init_callback1.WaitForResult()); 586 ASSERT_EQ(OK, init_callback1.WaitForResult());
(...skipping 21 matching lines...) Expand all
605 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 608 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
606 &temp_file_path)); 609 &temp_file_path));
607 ASSERT_EQ(static_cast<int>(kTestDataSize), 610 ASSERT_EQ(static_cast<int>(kTestDataSize),
608 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 611 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
609 TestCompletionCallback test_callback; 612 TestCompletionCallback test_callback;
610 613
611 // Prepare data. 614 // Prepare data.
612 element_readers_.push_back( 615 element_readers_.push_back(
613 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize))); 616 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize)));
614 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 617 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
615 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 618 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
616 base::Time()))); 619 std::numeric_limits<uint64_t>::max(), base::Time())));
617 scoped_ptr<UploadDataStream> stream( 620 scoped_ptr<UploadDataStream> stream(
618 new ElementsUploadDataStream(std::move(element_readers_), 0)); 621 new ElementsUploadDataStream(std::move(element_readers_), 0));
619 622
620 std::string expected_data(kTestData, kTestData + kTestDataSize); 623 std::string expected_data(kTestData, kTestData + kTestDataSize);
621 expected_data += expected_data; 624 expected_data += expected_data;
622 625
623 // Call Init(). 626 // Call Init().
624 ASSERT_EQ(ERR_IO_PENDING, stream->Init(test_callback.callback())); 627 ASSERT_EQ(ERR_IO_PENDING, stream->Init(test_callback.callback()));
625 EXPECT_EQ(OK, test_callback.WaitForResult()); 628 EXPECT_EQ(OK, test_callback.WaitForResult());
626 EXPECT_FALSE(stream->IsEOF()); 629 EXPECT_FALSE(stream->IsEOF());
(...skipping 18 matching lines...) Expand all
645 base::FilePath temp_file_path; 648 base::FilePath temp_file_path;
646 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 649 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
647 &temp_file_path)); 650 &temp_file_path));
648 ASSERT_EQ(static_cast<int>(kTestDataSize), 651 ASSERT_EQ(static_cast<int>(kTestDataSize),
649 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 652 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
650 653
651 // Prepare data. 654 // Prepare data.
652 element_readers_.push_back( 655 element_readers_.push_back(
653 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize))); 656 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize)));
654 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 657 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
655 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 658 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
656 base::Time()))); 659 std::numeric_limits<uint64_t>::max(), base::Time())));
657 scoped_ptr<UploadDataStream> stream( 660 scoped_ptr<UploadDataStream> stream(
658 new ElementsUploadDataStream(std::move(element_readers_), 0)); 661 new ElementsUploadDataStream(std::move(element_readers_), 0));
659 662
660 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); 663 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize);
661 expected_data.insert(expected_data.end(), kTestData, 664 expected_data.insert(expected_data.end(), kTestData,
662 kTestData + kTestDataSize); 665 kTestData + kTestDataSize);
663 666
664 // Call Init(). 667 // Call Init().
665 TestCompletionCallback init_callback1; 668 TestCompletionCallback init_callback1;
666 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback())); 669 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback()));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 base::FilePath temp_file_path; 704 base::FilePath temp_file_path;
702 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 705 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
703 &temp_file_path)); 706 &temp_file_path));
704 ASSERT_EQ(static_cast<int>(kTestDataSize), 707 ASSERT_EQ(static_cast<int>(kTestDataSize),
705 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 708 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
706 709
707 // Prepare data. 710 // Prepare data.
708 element_readers_.push_back( 711 element_readers_.push_back(
709 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize))); 712 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize)));
710 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 713 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
711 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 714 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
712 base::Time()))); 715 std::numeric_limits<uint64_t>::max(), base::Time())));
713 scoped_ptr<UploadDataStream> stream( 716 scoped_ptr<UploadDataStream> stream(
714 new ElementsUploadDataStream(std::move(element_readers_), 0)); 717 new ElementsUploadDataStream(std::move(element_readers_), 0));
715 718
716 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); 719 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize);
717 expected_data.insert(expected_data.end(), kTestData, 720 expected_data.insert(expected_data.end(), kTestData,
718 kTestData + kTestDataSize); 721 kTestData + kTestDataSize);
719 722
720 // Start Init. 723 // Start Init.
721 TestCompletionCallback init_callback1; 724 TestCompletionCallback init_callback1;
722 EXPECT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback())); 725 EXPECT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback()));
(...skipping 24 matching lines...) Expand all
747 base::FilePath temp_file_path; 750 base::FilePath temp_file_path;
748 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), 751 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(),
749 &temp_file_path)); 752 &temp_file_path));
750 ASSERT_EQ(static_cast<int>(kTestDataSize), 753 ASSERT_EQ(static_cast<int>(kTestDataSize),
751 base::WriteFile(temp_file_path, kTestData, kTestDataSize)); 754 base::WriteFile(temp_file_path, kTestData, kTestDataSize));
752 755
753 // Prepare data. 756 // Prepare data.
754 element_readers_.push_back( 757 element_readers_.push_back(
755 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize))); 758 make_scoped_ptr(new UploadBytesElementReader(kTestData, kTestDataSize)));
756 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader( 759 element_readers_.push_back(make_scoped_ptr(new UploadFileElementReader(
757 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, kuint64max, 760 base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0,
758 base::Time()))); 761 std::numeric_limits<uint64_t>::max(), base::Time())));
759 scoped_ptr<UploadDataStream> stream( 762 scoped_ptr<UploadDataStream> stream(
760 new ElementsUploadDataStream(std::move(element_readers_), 0)); 763 new ElementsUploadDataStream(std::move(element_readers_), 0));
761 764
762 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize); 765 std::vector<char> expected_data(kTestData, kTestData + kTestDataSize);
763 expected_data.insert(expected_data.end(), kTestData, 766 expected_data.insert(expected_data.end(), kTestData,
764 kTestData + kTestDataSize); 767 kTestData + kTestDataSize);
765 768
766 // Call Init(). 769 // Call Init().
767 TestCompletionCallback init_callback1; 770 TestCompletionCallback init_callback1;
768 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback())); 771 ASSERT_EQ(ERR_IO_PENDING, stream->Init(init_callback1.callback()));
(...skipping 26 matching lines...) Expand all
795 wrapped_buffer2.get(), buf2.size(), read_callback2.callback())); 798 wrapped_buffer2.get(), buf2.size(), read_callback2.callback()));
796 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult()); 799 EXPECT_EQ(static_cast<int>(buf2.size()), read_callback2.WaitForResult());
797 EXPECT_EQ(expected_data, buf2); 800 EXPECT_EQ(expected_data, buf2);
798 EXPECT_TRUE(stream->IsEOF()); 801 EXPECT_TRUE(stream->IsEOF());
799 802
800 // Make sure callbacks are not called for cancelled operations. 803 // Make sure callbacks are not called for cancelled operations.
801 EXPECT_FALSE(read_callback1.have_result()); 804 EXPECT_FALSE(read_callback1.have_result());
802 } 805 }
803 806
804 } // namespace net 807 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698