OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/file_proxy.h" | 5 #include "base/files/file_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 for (size_t i = 0; i < buffer_.size(); ++i) { | 260 for (size_t i = 0; i < buffer_.size(); ++i) { |
261 EXPECT_EQ(expected_data[i], buffer_[i]); | 261 EXPECT_EQ(expected_data[i], buffer_[i]); |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 TEST_F(FileProxyTest, WriteAndFlush) { | 265 TEST_F(FileProxyTest, WriteAndFlush) { |
266 FileProxy proxy(file_task_runner()); | 266 FileProxy proxy(file_task_runner()); |
267 CreateProxy(File::FLAG_CREATE | File::FLAG_WRITE, &proxy); | 267 CreateProxy(File::FLAG_CREATE | File::FLAG_WRITE, &proxy); |
268 | 268 |
269 const char data[] = "foo!"; | 269 const char data[] = "foo!"; |
270 int data_bytes = ARRAYSIZE_UNSAFE(data); | 270 int data_bytes = arraysize(data); |
271 proxy.Write(0, data, data_bytes, | 271 proxy.Write(0, data, data_bytes, |
272 Bind(&FileProxyTest::DidWrite, weak_factory_.GetWeakPtr())); | 272 Bind(&FileProxyTest::DidWrite, weak_factory_.GetWeakPtr())); |
273 MessageLoop::current()->Run(); | 273 MessageLoop::current()->Run(); |
274 EXPECT_EQ(File::FILE_OK, error_); | 274 EXPECT_EQ(File::FILE_OK, error_); |
275 EXPECT_EQ(data_bytes, bytes_written_); | 275 EXPECT_EQ(data_bytes, bytes_written_); |
276 | 276 |
277 // Flush the written data. (So that the following read should always | 277 // Flush the written data. (So that the following read should always |
278 // succeed. On some platforms it may work with or without this flush.) | 278 // succeed. On some platforms it may work with or without this flush.) |
279 proxy.Flush(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); | 279 proxy.Flush(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); |
280 MessageLoop::current()->Run(); | 280 MessageLoop::current()->Run(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 char buffer[53]; | 361 char buffer[53]; |
362 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); | 362 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); |
363 int i = 0; | 363 int i = 0; |
364 for (; i < 10; ++i) | 364 for (; i < 10; ++i) |
365 EXPECT_EQ(kTestData[i], buffer[i]); | 365 EXPECT_EQ(kTestData[i], buffer[i]); |
366 for (; i < 53; ++i) | 366 for (; i < 53; ++i) |
367 EXPECT_EQ(0, buffer[i]); | 367 EXPECT_EQ(0, buffer[i]); |
368 } | 368 } |
369 | 369 |
370 } // namespace base | 370 } // namespace base |
OLD | NEW |