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/file_stream.h" | 5 #include "net/base/file_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 class FileStreamTest : public PlatformTest { | 38 class FileStreamTest : public PlatformTest { |
39 public: | 39 public: |
40 virtual void SetUp() { | 40 virtual void SetUp() { |
41 PlatformTest::SetUp(); | 41 PlatformTest::SetUp(); |
42 | 42 |
43 file_util::CreateTemporaryFile(&temp_file_path_); | 43 file_util::CreateTemporaryFile(&temp_file_path_); |
44 file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize); | 44 file_util::WriteFile(temp_file_path_, kTestData, kTestDataSize); |
45 } | 45 } |
46 virtual void TearDown() { | 46 virtual void TearDown() { |
47 EXPECT_TRUE(base::Delete(temp_file_path_, false)); | 47 EXPECT_TRUE(base::DeleteFile(temp_file_path_, false)); |
48 | 48 |
49 PlatformTest::TearDown(); | 49 PlatformTest::TearDown(); |
50 } | 50 } |
51 | 51 |
52 const base::FilePath temp_file_path() const { return temp_file_path_; } | 52 const base::FilePath temp_file_path() const { return temp_file_path_; } |
53 | 53 |
54 private: | 54 private: |
55 base::FilePath temp_file_path_; | 55 base::FilePath temp_file_path_; |
56 }; | 56 }; |
57 | 57 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 ASSERT_EQ(0, read_stream->SeekSync(FROM_BEGIN, 0)); | 109 ASSERT_EQ(0, read_stream->SeekSync(FROM_BEGIN, 0)); |
110 ASSERT_EQ(kTestDataSize, read_stream->Available()); | 110 ASSERT_EQ(kTestDataSize, read_stream->Available()); |
111 // Read into buffer and compare. | 111 // Read into buffer and compare. |
112 char buffer[kTestDataSize]; | 112 char buffer[kTestDataSize]; |
113 ASSERT_EQ(kTestDataSize, | 113 ASSERT_EQ(kTestDataSize, |
114 read_stream->ReadSync(buffer, kTestDataSize)); | 114 read_stream->ReadSync(buffer, kTestDataSize)); |
115 ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); | 115 ASSERT_EQ(0, memcmp(kTestData, buffer, kTestDataSize)); |
116 read_stream.reset(); | 116 read_stream.reset(); |
117 | 117 |
118 // 2. Test writing with a file handle. | 118 // 2. Test writing with a file handle. |
119 base::Delete(temp_file_path(), false); | 119 base::DeleteFile(temp_file_path(), false); |
120 flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE; | 120 flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE; |
121 file = base::CreatePlatformFile(temp_file_path(), flags, &created, NULL); | 121 file = base::CreatePlatformFile(temp_file_path(), flags, &created, NULL); |
122 | 122 |
123 scoped_ptr<FileStream> write_stream(new FileStream(file, flags, NULL)); | 123 scoped_ptr<FileStream> write_stream(new FileStream(file, flags, NULL)); |
124 ASSERT_EQ(0, write_stream->SeekSync(FROM_BEGIN, 0)); | 124 ASSERT_EQ(0, write_stream->SeekSync(FROM_BEGIN, 0)); |
125 ASSERT_EQ(kTestDataSize, | 125 ASSERT_EQ(kTestDataSize, |
126 write_stream->WriteSync(kTestData, kTestDataSize)); | 126 write_stream->WriteSync(kTestData, kTestDataSize)); |
127 write_stream.reset(); | 127 write_stream.reset(); |
128 | 128 |
129 // Read into buffer and compare to make sure the handle worked fine. | 129 // Read into buffer and compare to make sure the handle worked fine. |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL); | 1073 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL); |
1074 rv = stream->Read(buf.get(), 1, callback.callback()); | 1074 rv = stream->Read(buf.get(), 1, callback.callback()); |
1075 if (rv == ERR_IO_PENDING) | 1075 if (rv == ERR_IO_PENDING) |
1076 rv = callback.WaitForResult(); | 1076 rv = callback.WaitForResult(); |
1077 EXPECT_LT(rv, 0); | 1077 EXPECT_LT(rv, 0); |
1078 } | 1078 } |
1079 | 1079 |
1080 } // namespace | 1080 } // namespace |
1081 | 1081 |
1082 } // namespace net | 1082 } // namespace net |
OLD | NEW |