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

Side by Side Diff: base/files/file_util_proxy_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/files/file_util_proxy.cc ('k') | base/files/important_file_writer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 FileUtilProxy::CreateOrOpen( 121 FileUtilProxy::CreateOrOpen(
122 file_task_runner(), 122 file_task_runner(),
123 test_path(), 123 test_path(),
124 PLATFORM_FILE_CREATE | PLATFORM_FILE_READ, 124 PLATFORM_FILE_CREATE | PLATFORM_FILE_READ,
125 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 125 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
126 MessageLoop::current()->Run(); 126 MessageLoop::current()->Run();
127 127
128 EXPECT_EQ(PLATFORM_FILE_OK, error_); 128 EXPECT_EQ(PLATFORM_FILE_OK, error_);
129 EXPECT_TRUE(created_); 129 EXPECT_TRUE(created_);
130 EXPECT_NE(kInvalidPlatformFileValue, file_); 130 EXPECT_NE(kInvalidPlatformFileValue, file_);
131 EXPECT_TRUE(file_util::PathExists(test_path())); 131 EXPECT_TRUE(PathExists(test_path()));
132 } 132 }
133 133
134 TEST_F(FileUtilProxyTest, CreateOrOpen_Open) { 134 TEST_F(FileUtilProxyTest, CreateOrOpen_Open) {
135 // Creates a file. 135 // Creates a file.
136 file_util::WriteFile(test_path(), NULL, 0); 136 file_util::WriteFile(test_path(), NULL, 0);
137 ASSERT_TRUE(file_util::PathExists(test_path())); 137 ASSERT_TRUE(PathExists(test_path()));
138 138
139 // Opens the created file. 139 // Opens the created file.
140 FileUtilProxy::CreateOrOpen( 140 FileUtilProxy::CreateOrOpen(
141 file_task_runner(), 141 file_task_runner(),
142 test_path(), 142 test_path(),
143 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ, 143 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
144 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 144 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
145 MessageLoop::current()->Run(); 145 MessageLoop::current()->Run();
146 146
147 EXPECT_EQ(PLATFORM_FILE_OK, error_); 147 EXPECT_EQ(PLATFORM_FILE_OK, error_);
148 EXPECT_FALSE(created_); 148 EXPECT_FALSE(created_);
149 EXPECT_NE(kInvalidPlatformFileValue, file_); 149 EXPECT_NE(kInvalidPlatformFileValue, file_);
150 } 150 }
151 151
152 TEST_F(FileUtilProxyTest, CreateOrOpen_OpenNonExistent) { 152 TEST_F(FileUtilProxyTest, CreateOrOpen_OpenNonExistent) {
153 FileUtilProxy::CreateOrOpen( 153 FileUtilProxy::CreateOrOpen(
154 file_task_runner(), 154 file_task_runner(),
155 test_path(), 155 test_path(),
156 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ, 156 PLATFORM_FILE_OPEN | PLATFORM_FILE_READ,
157 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); 157 Bind(&FileUtilProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr()));
158 MessageLoop::current()->Run(); 158 MessageLoop::current()->Run();
159 EXPECT_EQ(PLATFORM_FILE_ERROR_NOT_FOUND, error_); 159 EXPECT_EQ(PLATFORM_FILE_ERROR_NOT_FOUND, error_);
160 EXPECT_FALSE(created_); 160 EXPECT_FALSE(created_);
161 EXPECT_EQ(kInvalidPlatformFileValue, file_); 161 EXPECT_EQ(kInvalidPlatformFileValue, file_);
162 EXPECT_FALSE(file_util::PathExists(test_path())); 162 EXPECT_FALSE(PathExists(test_path()));
163 } 163 }
164 164
165 TEST_F(FileUtilProxyTest, Close) { 165 TEST_F(FileUtilProxyTest, Close) {
166 // Creates a file. 166 // Creates a file.
167 PlatformFile file = GetTestPlatformFile( 167 PlatformFile file = GetTestPlatformFile(
168 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE); 168 PLATFORM_FILE_CREATE | PLATFORM_FILE_WRITE);
169 169
170 #if defined(OS_WIN) 170 #if defined(OS_WIN)
171 // This fails on Windows if the file is not closed. 171 // This fails on Windows if the file is not closed.
172 EXPECT_FALSE(base::Move(test_path(), 172 EXPECT_FALSE(base::Move(test_path(),
(...skipping 10 matching lines...) Expand all
183 // Now it should pass on all platforms. 183 // Now it should pass on all platforms.
184 EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new"))); 184 EXPECT_TRUE(base::Move(test_path(), test_dir_path().AppendASCII("new")));
185 } 185 }
186 186
187 TEST_F(FileUtilProxyTest, CreateTemporary) { 187 TEST_F(FileUtilProxyTest, CreateTemporary) {
188 FileUtilProxy::CreateTemporary( 188 FileUtilProxy::CreateTemporary(
189 file_task_runner(), 0 /* additional_file_flags */, 189 file_task_runner(), 0 /* additional_file_flags */,
190 Bind(&FileUtilProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr())); 190 Bind(&FileUtilProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr()));
191 MessageLoop::current()->Run(); 191 MessageLoop::current()->Run();
192 EXPECT_EQ(PLATFORM_FILE_OK, error_); 192 EXPECT_EQ(PLATFORM_FILE_OK, error_);
193 EXPECT_TRUE(file_util::PathExists(path_)); 193 EXPECT_TRUE(PathExists(path_));
194 EXPECT_NE(kInvalidPlatformFileValue, file_); 194 EXPECT_NE(kInvalidPlatformFileValue, file_);
195 195
196 // The file should be writable. 196 // The file should be writable.
197 #if defined(OS_WIN) 197 #if defined(OS_WIN)
198 HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); 198 HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
199 OVERLAPPED overlapped = {0}; 199 OVERLAPPED overlapped = {0};
200 overlapped.hEvent = hEvent; 200 overlapped.hEvent = hEvent;
201 DWORD bytes_written; 201 DWORD bytes_written;
202 if (!::WriteFile(file_, "test", 4, &bytes_written, &overlapped)) { 202 if (!::WriteFile(file_, "test", 4, &bytes_written, &overlapped)) {
203 // Temporary file is created with ASYNC flag, so WriteFile may return 0 203 // Temporary file is created with ASYNC flag, so WriteFile may return 0
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 char buffer[53]; 402 char buffer[53];
403 EXPECT_EQ(53, file_util::ReadFile(test_path(), buffer, 53)); 403 EXPECT_EQ(53, file_util::ReadFile(test_path(), buffer, 53));
404 int i = 0; 404 int i = 0;
405 for (; i < 10; ++i) 405 for (; i < 10; ++i)
406 EXPECT_EQ(kTestData[i], buffer[i]); 406 EXPECT_EQ(kTestData[i], buffer[i]);
407 for (; i < 53; ++i) 407 for (; i < 53; ++i)
408 EXPECT_EQ(0, buffer[i]); 408 EXPECT_EQ(0, buffer[i]);
409 } 409 }
410 410
411 } // namespace base 411 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util_proxy.cc ('k') | base/files/important_file_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698