| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include <fstream> | 7 #include <fstream> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const wchar_t DuplicateTreeDetectorTest::text_content_2_[] = | 73 const wchar_t DuplicateTreeDetectorTest::text_content_2_[] = |
| 74 L"Overwrite Me"; | 74 L"Overwrite Me"; |
| 75 const wchar_t DuplicateTreeDetectorTest::text_content_3_[] = | 75 const wchar_t DuplicateTreeDetectorTest::text_content_3_[] = |
| 76 L"I'd rather see your watermelon and raise you ham and a half."; | 76 L"I'd rather see your watermelon and raise you ham and a half."; |
| 77 | 77 |
| 78 }; // namespace | 78 }; // namespace |
| 79 | 79 |
| 80 // Test the DuplicateTreeChecker's definition of identity on two identical | 80 // Test the DuplicateTreeChecker's definition of identity on two identical |
| 81 // directory structures. | 81 // directory structures. |
| 82 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirs) { | 82 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirs) { |
| 83 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 83 CreateTwoIdenticalHierarchies(temp_source_dir_.GetPath(), |
| 84 temp_dest_dir_.GetPath()); |
| 84 | 85 |
| 85 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 86 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.GetPath(), |
| 86 temp_dest_dir_.path())); | 87 temp_dest_dir_.GetPath())); |
| 87 } | 88 } |
| 88 | 89 |
| 89 // Test when source entirely contains dest but contains other files as well. | 90 // Test when source entirely contains dest but contains other files as well. |
| 90 // IsIdenticalTo should return false in this case. | 91 // IsIdenticalTo should return false in this case. |
| 91 TEST_F(DuplicateTreeDetectorTest, TestSourceContainsDest) { | 92 TEST_F(DuplicateTreeDetectorTest, TestSourceContainsDest) { |
| 92 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 93 CreateTwoIdenticalHierarchies(temp_source_dir_.GetPath(), |
| 94 temp_dest_dir_.GetPath()); |
| 93 | 95 |
| 94 base::FilePath new_file(temp_source_dir_.path()); | 96 base::FilePath new_file(temp_source_dir_.GetPath()); |
| 95 new_file = new_file.AppendASCII("FNew"); | 97 new_file = new_file.AppendASCII("FNew"); |
| 96 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); | 98 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); |
| 97 ASSERT_TRUE(base::PathExists(new_file)); | 99 ASSERT_TRUE(base::PathExists(new_file)); |
| 98 | 100 |
| 99 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 101 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.GetPath(), |
| 100 temp_dest_dir_.path())); | 102 temp_dest_dir_.GetPath())); |
| 101 } | 103 } |
| 102 | 104 |
| 103 // Test when dest entirely contains source but contains other files as well. | 105 // Test when dest entirely contains source but contains other files as well. |
| 104 // IsIdenticalTo should return true in this case. | 106 // IsIdenticalTo should return true in this case. |
| 105 TEST_F(DuplicateTreeDetectorTest, TestDestContainsSource) { | 107 TEST_F(DuplicateTreeDetectorTest, TestDestContainsSource) { |
| 106 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 108 CreateTwoIdenticalHierarchies(temp_source_dir_.GetPath(), |
| 109 temp_dest_dir_.GetPath()); |
| 107 | 110 |
| 108 base::FilePath new_file(temp_dest_dir_.path()); | 111 base::FilePath new_file(temp_dest_dir_.GetPath()); |
| 109 new_file = new_file.AppendASCII("FNew"); | 112 new_file = new_file.AppendASCII("FNew"); |
| 110 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); | 113 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); |
| 111 ASSERT_TRUE(base::PathExists(new_file)); | 114 ASSERT_TRUE(base::PathExists(new_file)); |
| 112 | 115 |
| 113 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 116 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.GetPath(), |
| 114 temp_dest_dir_.path())); | 117 temp_dest_dir_.GetPath())); |
| 115 } | 118 } |
| 116 | 119 |
| 117 // Test when the file hierarchies are the same but one of the files is changed. | 120 // Test when the file hierarchies are the same but one of the files is changed. |
| 118 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirsDifferentFiles) { | 121 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirsDifferentFiles) { |
| 119 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 122 CreateTwoIdenticalHierarchies(temp_source_dir_.GetPath(), |
| 123 temp_dest_dir_.GetPath()); |
| 120 | 124 |
| 121 base::FilePath existing_file(temp_dest_dir_.path()); | 125 base::FilePath existing_file(temp_dest_dir_.GetPath()); |
| 122 existing_file = existing_file.AppendASCII("D1") | 126 existing_file = existing_file.AppendASCII("D1") |
| 123 .AppendASCII("D2") | 127 .AppendASCII("D2") |
| 124 .AppendASCII("F2"); | 128 .AppendASCII("F2"); |
| 125 CreateTextFile(existing_file.MaybeAsASCII(), text_content_3_); | 129 CreateTextFile(existing_file.MaybeAsASCII(), text_content_3_); |
| 126 | 130 |
| 127 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 131 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.GetPath(), |
| 128 temp_dest_dir_.path())); | 132 temp_dest_dir_.GetPath())); |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Test when both file hierarchies are empty. | 135 // Test when both file hierarchies are empty. |
| 132 TEST_F(DuplicateTreeDetectorTest, TestEmptyDirs) { | 136 TEST_F(DuplicateTreeDetectorTest, TestEmptyDirs) { |
| 133 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 137 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.GetPath(), |
| 134 temp_dest_dir_.path())); | 138 temp_dest_dir_.GetPath())); |
| 135 } | 139 } |
| 136 | 140 |
| 137 // Test on single files. | 141 // Test on single files. |
| 138 TEST_F(DuplicateTreeDetectorTest, TestSingleFiles) { | 142 TEST_F(DuplicateTreeDetectorTest, TestSingleFiles) { |
| 139 // Create a source file. | 143 // Create a source file. |
| 140 base::FilePath source_file(temp_source_dir_.path()); | 144 base::FilePath source_file(temp_source_dir_.GetPath()); |
| 141 source_file = source_file.AppendASCII("F1"); | 145 source_file = source_file.AppendASCII("F1"); |
| 142 CreateTextFile(source_file.MaybeAsASCII(), text_content_1_); | 146 CreateTextFile(source_file.MaybeAsASCII(), text_content_1_); |
| 143 | 147 |
| 144 // This file should be the same. | 148 // This file should be the same. |
| 145 base::FilePath dest_file(temp_dest_dir_.path()); | 149 base::FilePath dest_file(temp_dest_dir_.GetPath()); |
| 146 dest_file = dest_file.AppendASCII("F1"); | 150 dest_file = dest_file.AppendASCII("F1"); |
| 147 ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file)); | 151 ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file)); |
| 148 | 152 |
| 149 // This file should be different. | 153 // This file should be different. |
| 150 base::FilePath other_file(temp_dest_dir_.path()); | 154 base::FilePath other_file(temp_dest_dir_.GetPath()); |
| 151 other_file = other_file.AppendASCII("F2"); | 155 other_file = other_file.AppendASCII("F2"); |
| 152 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_); | 156 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_); |
| 153 | 157 |
| 154 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file)); | 158 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file)); |
| 155 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file)); | 159 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file)); |
| 156 } | 160 } |
| OLD | NEW |