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

Side by Side Diff: chrome/installer/util/duplicate_tree_detector_unittest.cc

Issue 11340049: Move CopyFileHierarchy to a common test namespace and also use it in MoveTreeWorkItemTest.MoveDirec… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: shellapi.h needs windows.h Created 8 years, 1 month 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 | « chrome/chrome_installer.gypi ('k') | chrome/installer/util/installer_util_test_common.h » ('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) 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 #include <shellapi.h>
7 6
8 #include <fstream> 7 #include <fstream>
9 8
10 #include "base/file_util.h" 9 #include "base/file_util.h"
11 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
12 #include "base/string16.h" 11 #include "base/string16.h"
13 #include "base/string_util.h" 12 #include "base/string_util.h"
14 #include "chrome/installer/util/duplicate_tree_detector.h" 13 #include "chrome/installer/util/duplicate_tree_detector.h"
14 #include "chrome/installer/util/installer_util_test_common.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace { 17 namespace {
18 18
19 class DuplicateTreeDetectorTest : public testing::Test { 19 class DuplicateTreeDetectorTest : public testing::Test {
20 protected: 20 protected:
21 virtual void SetUp() { 21 virtual void SetUp() {
22 ASSERT_TRUE(temp_source_dir_.CreateUniqueTempDir()); 22 ASSERT_TRUE(temp_source_dir_.CreateUniqueTempDir());
23 ASSERT_TRUE(temp_dest_dir_.CreateUniqueTempDir()); 23 ASSERT_TRUE(temp_dest_dir_.CreateUniqueTempDir());
24 } 24 }
(...skipping 25 matching lines...) Expand all
50 FilePath d2(d1); 50 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(file_util::PathExists(d2));
54 54
55 FilePath f2(d2); 55 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(file_util::PathExists(f2));
59 59
60 CopyFileHierarchy(d1, second_root); 60 ASSERT_TRUE(installer::test::CopyFileHierarchy(d1, second_root));
61 }
62
63 // Copies the hierarcy in |from| to |to|.
64 void CopyFileHierarchy(const FilePath& from, const FilePath& to) {
65 // In SHFILEOPSTRUCT below, |pFrom| and |pTo| have to be double-null
66 // terminated: http://msdn.microsoft.com/library/bb759795.aspx
67 string16 double_null_from(from.value());
68 double_null_from.push_back(L'\0');
69 string16 double_null_to(to.value());
70 double_null_to.push_back(L'\0');
71
72 SHFILEOPSTRUCT file_op = {};
73 file_op.wFunc = FO_COPY;
74 file_op.pFrom = double_null_from.c_str();
75 file_op.pTo = double_null_to.c_str();
76 file_op.fFlags = FOF_NO_UI;
77
78 ASSERT_EQ(0, SHFileOperation(&file_op));
79
80 ASSERT_FALSE(file_op.fAnyOperationsAborted);
81 } 61 }
82 62
83 ScopedTempDir temp_source_dir_; 63 ScopedTempDir temp_source_dir_;
84 ScopedTempDir temp_dest_dir_; 64 ScopedTempDir temp_dest_dir_;
85 65
86 static const wchar_t text_content_1_[]; 66 static const wchar_t text_content_1_[];
87 static const wchar_t text_content_2_[]; 67 static const wchar_t text_content_2_[];
88 static const wchar_t text_content_3_[]; 68 static const wchar_t text_content_3_[];
89 }; 69 };
90 70
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Test on single files. 137 // Test on single files.
158 TEST_F(DuplicateTreeDetectorTest, TestSingleFiles) { 138 TEST_F(DuplicateTreeDetectorTest, TestSingleFiles) {
159 // Create a source file. 139 // Create a source file.
160 FilePath source_file(temp_source_dir_.path()); 140 FilePath source_file(temp_source_dir_.path());
161 source_file = source_file.AppendASCII("F1"); 141 source_file = source_file.AppendASCII("F1");
162 CreateTextFile(source_file.MaybeAsASCII(), text_content_1_); 142 CreateTextFile(source_file.MaybeAsASCII(), text_content_1_);
163 143
164 // This file should be the same. 144 // This file should be the same.
165 FilePath dest_file(temp_dest_dir_.path()); 145 FilePath dest_file(temp_dest_dir_.path());
166 dest_file = dest_file.AppendASCII("F1"); 146 dest_file = dest_file.AppendASCII("F1");
167 CopyFileHierarchy(source_file, dest_file); 147 ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file));
168 148
169 // This file should be different. 149 // This file should be different.
170 FilePath other_file(temp_dest_dir_.path()); 150 FilePath other_file(temp_dest_dir_.path());
171 other_file = other_file.AppendASCII("F2"); 151 other_file = other_file.AppendASCII("F2");
172 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_); 152 CreateTextFile(other_file.MaybeAsASCII(), text_content_2_);
173 153
174 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file)); 154 EXPECT_TRUE(installer::IsIdenticalFileHierarchy(source_file, dest_file));
175 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file)); 155 EXPECT_FALSE(installer::IsIdenticalFileHierarchy(source_file, other_file));
176 } 156 }
OLDNEW
« no previous file with comments | « chrome/chrome_installer.gypi ('k') | chrome/installer/util/installer_util_test_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698