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

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

Issue 101143006: Convert base::file_util to use File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove base:: Created 6 years, 11 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.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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 EXPECT_TRUE(ReadFileToString(path_, &data)); 218 EXPECT_TRUE(ReadFileToString(path_, &data));
219 EXPECT_EQ("test", data); 219 EXPECT_EQ("test", data);
220 220
221 // Make sure we can & do delete the created file to prevent leaks on the bots. 221 // Make sure we can & do delete the created file to prevent leaks on the bots.
222 EXPECT_TRUE(base::DeleteFile(path_, false)); 222 EXPECT_TRUE(base::DeleteFile(path_, false));
223 } 223 }
224 224
225 TEST_F(FileUtilProxyTest, GetFileInfo_File) { 225 TEST_F(FileUtilProxyTest, GetFileInfo_File) {
226 // Setup. 226 // Setup.
227 ASSERT_EQ(4, file_util::WriteFile(test_path(), "test", 4)); 227 ASSERT_EQ(4, file_util::WriteFile(test_path(), "test", 4));
228 PlatformFileInfo expected_info; 228 File::Info expected_info;
229 GetFileInfo(test_path(), &expected_info); 229 GetFileInfo(test_path(), &expected_info);
230 230
231 // Run. 231 // Run.
232 FileUtilProxy::GetFileInfo( 232 FileUtilProxy::GetFileInfo(
233 file_task_runner(), 233 file_task_runner(),
234 test_path(), 234 test_path(),
235 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 235 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
236 MessageLoop::current()->Run(); 236 MessageLoop::current()->Run();
237 237
238 // Verify. 238 // Verify.
239 EXPECT_EQ(PLATFORM_FILE_OK, error_); 239 EXPECT_EQ(PLATFORM_FILE_OK, error_);
240 EXPECT_EQ(expected_info.size, file_info_.size); 240 EXPECT_EQ(expected_info.size, file_info_.size);
241 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory); 241 EXPECT_EQ(expected_info.is_directory, file_info_.is_directory);
242 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link); 242 EXPECT_EQ(expected_info.is_symbolic_link, file_info_.is_symbolic_link);
243 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified); 243 EXPECT_EQ(expected_info.last_modified, file_info_.last_modified);
244 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed); 244 EXPECT_EQ(expected_info.last_accessed, file_info_.last_accessed);
245 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time); 245 EXPECT_EQ(expected_info.creation_time, file_info_.creation_time);
246 } 246 }
247 247
248 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) { 248 TEST_F(FileUtilProxyTest, GetFileInfo_Directory) {
249 // Setup. 249 // Setup.
250 ASSERT_TRUE(base::CreateDirectory(test_path())); 250 ASSERT_TRUE(base::CreateDirectory(test_path()));
251 PlatformFileInfo expected_info; 251 File::Info expected_info;
252 GetFileInfo(test_path(), &expected_info); 252 GetFileInfo(test_path(), &expected_info);
253 253
254 // Run. 254 // Run.
255 FileUtilProxy::GetFileInfo( 255 FileUtilProxy::GetFileInfo(
256 file_task_runner(), 256 file_task_runner(),
257 test_path(), 257 test_path(),
258 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); 258 Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr()));
259 MessageLoop::current()->Run(); 259 MessageLoop::current()->Run();
260 260
261 // Verify. 261 // Verify.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 file_task_runner(), 334 file_task_runner(),
335 GetTestPlatformFile(PLATFORM_FILE_CREATE | 335 GetTestPlatformFile(PLATFORM_FILE_CREATE |
336 PLATFORM_FILE_WRITE | 336 PLATFORM_FILE_WRITE |
337 PLATFORM_FILE_WRITE_ATTRIBUTES), 337 PLATFORM_FILE_WRITE_ATTRIBUTES),
338 last_accessed_time, 338 last_accessed_time,
339 last_modified_time, 339 last_modified_time,
340 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 340 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
341 MessageLoop::current()->Run(); 341 MessageLoop::current()->Run();
342 EXPECT_EQ(PLATFORM_FILE_OK, error_); 342 EXPECT_EQ(PLATFORM_FILE_OK, error_);
343 343
344 PlatformFileInfo info; 344 File::Info info;
345 GetFileInfo(test_path(), &info); 345 GetFileInfo(test_path(), &info);
346 346
347 // The returned values may only have the seconds precision, so we cast 347 // The returned values may only have the seconds precision, so we cast
348 // the double values to int here. 348 // the double values to int here.
349 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()), 349 EXPECT_EQ(static_cast<int>(last_modified_time.ToDoubleT()),
350 static_cast<int>(info.last_modified.ToDoubleT())); 350 static_cast<int>(info.last_modified.ToDoubleT()));
351 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()), 351 EXPECT_EQ(static_cast<int>(last_accessed_time.ToDoubleT()),
352 static_cast<int>(info.last_accessed.ToDoubleT())); 352 static_cast<int>(info.last_accessed.ToDoubleT()));
353 } 353 }
354 354
355 TEST_F(FileUtilProxyTest, Truncate_Shrink) { 355 TEST_F(FileUtilProxyTest, Truncate_Shrink) {
356 // Setup. 356 // Setup.
357 const char kTestData[] = "0123456789"; 357 const char kTestData[] = "0123456789";
358 ASSERT_EQ(10, file_util::WriteFile(test_path(), kTestData, 10)); 358 ASSERT_EQ(10, file_util::WriteFile(test_path(), kTestData, 10));
359 PlatformFileInfo info; 359 File::Info info;
360 GetFileInfo(test_path(), &info); 360 GetFileInfo(test_path(), &info);
361 ASSERT_EQ(10, info.size); 361 ASSERT_EQ(10, info.size);
362 362
363 // Run. 363 // Run.
364 FileUtilProxy::Truncate( 364 FileUtilProxy::Truncate(
365 file_task_runner(), 365 file_task_runner(),
366 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE), 366 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE),
367 7, 367 7,
368 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 368 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
369 MessageLoop::current()->Run(); 369 MessageLoop::current()->Run();
370 370
371 // Verify. 371 // Verify.
372 GetFileInfo(test_path(), &info); 372 GetFileInfo(test_path(), &info);
373 ASSERT_EQ(7, info.size); 373 ASSERT_EQ(7, info.size);
374 374
375 char buffer[7]; 375 char buffer[7];
376 EXPECT_EQ(7, base::ReadFile(test_path(), buffer, 7)); 376 EXPECT_EQ(7, base::ReadFile(test_path(), buffer, 7));
377 int i = 0; 377 int i = 0;
378 for (; i < 7; ++i) 378 for (; i < 7; ++i)
379 EXPECT_EQ(kTestData[i], buffer[i]); 379 EXPECT_EQ(kTestData[i], buffer[i]);
380 } 380 }
381 381
382 TEST_F(FileUtilProxyTest, Truncate_Expand) { 382 TEST_F(FileUtilProxyTest, Truncate_Expand) {
383 // Setup. 383 // Setup.
384 const char kTestData[] = "9876543210"; 384 const char kTestData[] = "9876543210";
385 ASSERT_EQ(10, file_util::WriteFile(test_path(), kTestData, 10)); 385 ASSERT_EQ(10, file_util::WriteFile(test_path(), kTestData, 10));
386 PlatformFileInfo info; 386 File::Info info;
387 GetFileInfo(test_path(), &info); 387 GetFileInfo(test_path(), &info);
388 ASSERT_EQ(10, info.size); 388 ASSERT_EQ(10, info.size);
389 389
390 // Run. 390 // Run.
391 FileUtilProxy::Truncate( 391 FileUtilProxy::Truncate(
392 file_task_runner(), 392 file_task_runner(),
393 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE), 393 GetTestPlatformFile(PLATFORM_FILE_OPEN | PLATFORM_FILE_WRITE),
394 53, 394 53,
395 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); 395 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr()));
396 MessageLoop::current()->Run(); 396 MessageLoop::current()->Run();
397 397
398 // Verify. 398 // Verify.
399 GetFileInfo(test_path(), &info); 399 GetFileInfo(test_path(), &info);
400 ASSERT_EQ(53, info.size); 400 ASSERT_EQ(53, info.size);
401 401
402 char buffer[53]; 402 char buffer[53];
403 EXPECT_EQ(53, base::ReadFile(test_path(), buffer, 53)); 403 EXPECT_EQ(53, base::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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698