OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 SourceDirForPath(empty, base::FilePath("/source/foo")).value()); | 574 SourceDirForPath(empty, base::FilePath("/source/foo")).value()); |
575 #endif | 575 #endif |
576 } | 576 } |
577 | 577 |
578 TEST(FilesystemUtils, ContentsEqual) { | 578 TEST(FilesystemUtils, ContentsEqual) { |
579 base::ScopedTempDir temp_dir; | 579 base::ScopedTempDir temp_dir; |
580 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 580 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
581 | 581 |
582 std::string data = "foo"; | 582 std::string data = "foo"; |
583 | 583 |
584 base::FilePath file_path = temp_dir.path().AppendASCII("foo.txt"); | 584 base::FilePath file_path = temp_dir.GetPath().AppendASCII("foo.txt"); |
585 base::WriteFile(file_path, data.c_str(), static_cast<int>(data.size())); | 585 base::WriteFile(file_path, data.c_str(), static_cast<int>(data.size())); |
586 | 586 |
587 EXPECT_TRUE(ContentsEqual(file_path, data)); | 587 EXPECT_TRUE(ContentsEqual(file_path, data)); |
588 | 588 |
589 // Different length and contents. | 589 // Different length and contents. |
590 data += "bar"; | 590 data += "bar"; |
591 EXPECT_FALSE(ContentsEqual(file_path, data)); | 591 EXPECT_FALSE(ContentsEqual(file_path, data)); |
592 | 592 |
593 // The same length, different contents. | 593 // The same length, different contents. |
594 EXPECT_FALSE(ContentsEqual(file_path, "bar")); | 594 EXPECT_FALSE(ContentsEqual(file_path, "bar")); |
595 } | 595 } |
596 | 596 |
597 TEST(FilesystemUtils, WriteFileIfChanged) { | 597 TEST(FilesystemUtils, WriteFileIfChanged) { |
598 base::ScopedTempDir temp_dir; | 598 base::ScopedTempDir temp_dir; |
599 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 599 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
600 | 600 |
601 std::string data = "foo"; | 601 std::string data = "foo"; |
602 | 602 |
603 // Write if file doesn't exist. Create also directory. | 603 // Write if file doesn't exist. Create also directory. |
604 base::FilePath file_path = | 604 base::FilePath file_path = |
605 temp_dir.path().AppendASCII("bar").AppendASCII("foo.txt"); | 605 temp_dir.GetPath().AppendASCII("bar").AppendASCII("foo.txt"); |
606 EXPECT_TRUE(WriteFileIfChanged(file_path, data, nullptr)); | 606 EXPECT_TRUE(WriteFileIfChanged(file_path, data, nullptr)); |
607 | 607 |
608 base::File::Info file_info; | 608 base::File::Info file_info; |
609 ASSERT_TRUE(base::GetFileInfo(file_path, &file_info)); | 609 ASSERT_TRUE(base::GetFileInfo(file_path, &file_info)); |
610 base::Time last_modified = file_info.last_modified; | 610 base::Time last_modified = file_info.last_modified; |
611 | 611 |
612 #if defined(OS_MACOSX) | 612 #if defined(OS_MACOSX) |
613 // Modification times are in seconds in HFS on Mac. | 613 // Modification times are in seconds in HFS on Mac. |
614 base::TimeDelta sleep_time = base::TimeDelta::FromSeconds(1); | 614 base::TimeDelta sleep_time = base::TimeDelta::FromSeconds(1); |
615 #else | 615 #else |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 GetBuildDirAsSourceDir(context, BuildDirType::OBJ).value()); | 797 GetBuildDirAsSourceDir(context, BuildDirType::OBJ).value()); |
798 | 798 |
799 EXPECT_EQ("", | 799 EXPECT_EQ("", |
800 GetBuildDirAsOutputFile(context, BuildDirType::TOOLCHAIN_ROOT) | 800 GetBuildDirAsOutputFile(context, BuildDirType::TOOLCHAIN_ROOT) |
801 .value()); | 801 .value()); |
802 EXPECT_EQ("gen/", | 802 EXPECT_EQ("gen/", |
803 GetBuildDirAsOutputFile(context, BuildDirType::GEN).value()); | 803 GetBuildDirAsOutputFile(context, BuildDirType::GEN).value()); |
804 EXPECT_EQ("obj/", | 804 EXPECT_EQ("obj/", |
805 GetBuildDirAsOutputFile(context, BuildDirType::OBJ).value()); | 805 GetBuildDirAsOutputFile(context, BuildDirType::OBJ).value()); |
806 } | 806 } |
OLD | NEW |