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" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // succeed. On some platforms it may work with or without this flush.) | 313 // succeed. On some platforms it may work with or without this flush.) |
314 FileUtilProxy::Flush( | 314 FileUtilProxy::Flush( |
315 file_task_runner(), | 315 file_task_runner(), |
316 file, | 316 file, |
317 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); | 317 Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); |
318 MessageLoop::current()->Run(); | 318 MessageLoop::current()->Run(); |
319 EXPECT_EQ(PLATFORM_FILE_OK, error_); | 319 EXPECT_EQ(PLATFORM_FILE_OK, error_); |
320 | 320 |
321 // Verify the written data. | 321 // Verify the written data. |
322 char buffer[10]; | 322 char buffer[10]; |
323 EXPECT_EQ(data_bytes, base::ReadFile(test_path(), buffer, data_bytes)); | 323 EXPECT_EQ(data_bytes, file_util::ReadFile(test_path(), buffer, data_bytes)); |
324 for (int i = 0; i < data_bytes; ++i) { | 324 for (int i = 0; i < data_bytes; ++i) { |
325 EXPECT_EQ(data[i], buffer[i]); | 325 EXPECT_EQ(data[i], buffer[i]); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 TEST_F(FileUtilProxyTest, Touch) { | 329 TEST_F(FileUtilProxyTest, Touch) { |
330 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345); | 330 Time last_accessed_time = Time::Now() - TimeDelta::FromDays(12345); |
331 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765); | 331 Time last_modified_time = Time::Now() - TimeDelta::FromHours(98765); |
332 | 332 |
333 FileUtilProxy::Touch( | 333 FileUtilProxy::Touch( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, file_util::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 PlatformFileInfo 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, 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 |
OLD | NEW |