| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 file.close(); | 33 file.close(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 // Creates a two level deep source dir with a file in each in |first_root| and | 36 // Creates a two level deep source dir with a file in each in |first_root| and |
| 37 // copy it (files properties will be identical) in |second_root|. | 37 // copy it (files properties will be identical) in |second_root|. |
| 38 void CreateTwoIdenticalHierarchies(const base::FilePath& first_root, | 38 void CreateTwoIdenticalHierarchies(const base::FilePath& first_root, |
| 39 const base::FilePath& second_root) { | 39 const base::FilePath& second_root) { |
| 40 base::FilePath d1(first_root); | 40 base::FilePath d1(first_root); |
| 41 d1 = d1.AppendASCII("D1"); | 41 d1 = d1.AppendASCII("D1"); |
| 42 file_util::CreateDirectory(d1); | 42 file_util::CreateDirectory(d1); |
| 43 ASSERT_TRUE(file_util::PathExists(d1)); | 43 ASSERT_TRUE(base::PathExists(d1)); |
| 44 | 44 |
| 45 base::FilePath f1(d1); | 45 base::FilePath f1(d1); |
| 46 f1 = f1.AppendASCII("F1"); | 46 f1 = f1.AppendASCII("F1"); |
| 47 CreateTextFile(f1.MaybeAsASCII(), text_content_1_); | 47 CreateTextFile(f1.MaybeAsASCII(), text_content_1_); |
| 48 ASSERT_TRUE(file_util::PathExists(f1)); | 48 ASSERT_TRUE(base::PathExists(f1)); |
| 49 | 49 |
| 50 base::FilePath d2(d1); | 50 base::FilePath d2(d1); |
| 51 d2 = d2.AppendASCII("D2"); | 51 d2 = d2.AppendASCII("D2"); |
| 52 file_util::CreateDirectory(d2); | 52 file_util::CreateDirectory(d2); |
| 53 ASSERT_TRUE(file_util::PathExists(d2)); | 53 ASSERT_TRUE(base::PathExists(d2)); |
| 54 | 54 |
| 55 base::FilePath f2(d2); | 55 base::FilePath f2(d2); |
| 56 f2 = f2.AppendASCII("F2"); | 56 f2 = f2.AppendASCII("F2"); |
| 57 CreateTextFile(f2.MaybeAsASCII(), text_content_2_); | 57 CreateTextFile(f2.MaybeAsASCII(), text_content_2_); |
| 58 ASSERT_TRUE(file_util::PathExists(f2)); | 58 ASSERT_TRUE(base::PathExists(f2)); |
| 59 | 59 |
| 60 ASSERT_TRUE(installer::test::CopyFileHierarchy(d1, second_root)); | 60 ASSERT_TRUE(installer::test::CopyFileHierarchy(d1, second_root)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 base::ScopedTempDir temp_source_dir_; | 63 base::ScopedTempDir temp_source_dir_; |
| 64 base::ScopedTempDir temp_dest_dir_; | 64 base::ScopedTempDir temp_dest_dir_; |
| 65 | 65 |
| 66 static const wchar_t text_content_1_[]; | 66 static const wchar_t text_content_1_[]; |
| 67 static const wchar_t text_content_2_[]; | 67 static const wchar_t text_content_2_[]; |
| 68 static const wchar_t text_content_3_[]; | 68 static const wchar_t text_content_3_[]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Test when source entirely contains dest but contains other files as well. | 89 // Test when source entirely contains dest but contains other files as well. |
| 90 // IsIdenticalTo should return false in this case. | 90 // IsIdenticalTo should return false in this case. |
| 91 TEST_F(DuplicateTreeDetectorTest, TestSourceContainsDest) { | 91 TEST_F(DuplicateTreeDetectorTest, TestSourceContainsDest) { |
| 92 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 92 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); |
| 93 | 93 |
| 94 base::FilePath new_file(temp_source_dir_.path()); | 94 base::FilePath new_file(temp_source_dir_.path()); |
| 95 new_file = new_file.AppendASCII("FNew"); | 95 new_file = new_file.AppendASCII("FNew"); |
| 96 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); | 96 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); |
| 97 ASSERT_TRUE(file_util::PathExists(new_file)); | 97 ASSERT_TRUE(base::PathExists(new_file)); |
| 98 | 98 |
| 99 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 99 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), |
| 100 temp_dest_dir_.path())); | 100 temp_dest_dir_.path())); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Test when dest entirely contains source but contains other files as well. | 103 // Test when dest entirely contains source but contains other files as well. |
| 104 // IsIdenticalTo should return true in this case. | 104 // IsIdenticalTo should return true in this case. |
| 105 TEST_F(DuplicateTreeDetectorTest, TestDestContainsSource) { | 105 TEST_F(DuplicateTreeDetectorTest, TestDestContainsSource) { |
| 106 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 106 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); |
| 107 | 107 |
| 108 base::FilePath new_file(temp_dest_dir_.path()); | 108 base::FilePath new_file(temp_dest_dir_.path()); |
| 109 new_file = new_file.AppendASCII("FNew"); | 109 new_file = new_file.AppendASCII("FNew"); |
| 110 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); | 110 CreateTextFile(new_file.MaybeAsASCII(), text_content_1_); |
| 111 ASSERT_TRUE(file_util::PathExists(new_file)); | 111 ASSERT_TRUE(base::PathExists(new_file)); |
| 112 | 112 |
| 113 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), | 113 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(temp_source_dir_.path(), |
| 114 temp_dest_dir_.path())); | 114 temp_dest_dir_.path())); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Test when the file hierarchies are the same but one of the files is changed. | 117 // Test when the file hierarchies are the same but one of the files is changed. |
| 118 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirsDifferentFiles) { | 118 TEST_F(DuplicateTreeDetectorTest, TestIdenticalDirsDifferentFiles) { |
| 119 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); | 119 CreateTwoIdenticalHierarchies(temp_source_dir_.path(), temp_dest_dir_.path()); |
| 120 | 120 |
| 121 base::FilePath existing_file(temp_dest_dir_.path()); | 121 base::FilePath existing_file(temp_dest_dir_.path()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 147 ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file)); | 147 ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file)); |
| 148 | 148 |
| 149 // This file should be different. | 149 // This file should be different. |
| 150 base::FilePath other_file(temp_dest_dir_.path()); | 150 base::FilePath other_file(temp_dest_dir_.path()); |
| 151 other_file = other_file.AppendASCII("F2"); | 151 other_file = other_file.AppendASCII("F2"); |
| 152 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_); | 152 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_); |
| 153 | 153 |
| 154 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file)); | 154 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file)); |
| 155 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file)); | 155 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file)); |
| 156 } | 156 } |
| OLD | NEW |