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 "base/files/file_util_proxy.h" | 5 #include "base/files/file_util_proxy.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 | 20 |
21 class FileUtilProxyTest : public testing::Test { | 21 class FileUtilProxyTest : public testing::Test { |
22 public: | 22 public: |
23 FileUtilProxyTest() | 23 FileUtilProxyTest() |
24 : message_loop_(MessageLoop::TYPE_IO), | 24 : file_thread_("FileUtilProxyTestFileThread"), |
25 file_thread_("FileUtilProxyTestFileThread"), | |
26 error_(PLATFORM_FILE_OK), | 25 error_(PLATFORM_FILE_OK), |
27 created_(false), | 26 created_(false), |
28 file_(kInvalidPlatformFileValue), | 27 file_(kInvalidPlatformFileValue), |
29 bytes_written_(-1), | 28 bytes_written_(-1), |
30 weak_factory_(this) {} | 29 weak_factory_(this) {} |
31 | 30 |
32 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
33 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 32 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
34 ASSERT_TRUE(file_thread_.Start()); | 33 ASSERT_TRUE(file_thread_.Start()); |
35 } | 34 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 EXPECT_NE(kInvalidPlatformFileValue, file_); | 95 EXPECT_NE(kInvalidPlatformFileValue, file_); |
97 return file_; | 96 return file_; |
98 } | 97 } |
99 | 98 |
100 TaskRunner* file_task_runner() const { | 99 TaskRunner* file_task_runner() const { |
101 return file_thread_.message_loop_proxy().get(); | 100 return file_thread_.message_loop_proxy().get(); |
102 } | 101 } |
103 const FilePath& test_dir_path() const { return dir_.path(); } | 102 const FilePath& test_dir_path() const { return dir_.path(); } |
104 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } | 103 const FilePath test_path() const { return dir_.path().AppendASCII("test"); } |
105 | 104 |
106 MessageLoop message_loop_; | 105 MessageLoopForIO message_loop_; |
107 Thread file_thread_; | 106 Thread file_thread_; |
108 | 107 |
109 ScopedTempDir dir_; | 108 ScopedTempDir dir_; |
110 PlatformFileError error_; | 109 PlatformFileError error_; |
111 bool created_; | 110 bool created_; |
112 PlatformFile file_; | 111 PlatformFile file_; |
113 FilePath path_; | 112 FilePath path_; |
114 PlatformFileInfo file_info_; | 113 PlatformFileInfo file_info_; |
115 std::vector<char> buffer_; | 114 std::vector<char> buffer_; |
116 int bytes_written_; | 115 int bytes_written_; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 char buffer[53]; | 401 char buffer[53]; |
403 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); | 402 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); |
404 int i = 0; | 403 int i = 0; |
405 for (; i < 10; ++i) | 404 for (; i < 10; ++i) |
406 EXPECT_EQ(kTestData[i], buffer[i]); | 405 EXPECT_EQ(kTestData[i], buffer[i]); |
407 for (; i < 53; ++i) | 406 for (; i < 53; ++i) |
408 EXPECT_EQ(0, buffer[i]); | 407 EXPECT_EQ(0, buffer[i]); |
409 } | 408 } |
410 | 409 |
411 } // namespace base | 410 } // namespace base |
OLD | NEW |