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

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

Issue 202002: Replaces the windows function CreateDirectory with the CreateDirectory method... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 11 years, 3 months 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 | « no previous file | chrome/installer/util/create_dir_work_item_unittest.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <iostream> 8 #include <iostream>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 TEST_F(CopyTreeWorkItemTest, CopyFile) { 93 TEST_F(CopyTreeWorkItemTest, CopyFile) {
94 // Create source file 94 // Create source file
95 FilePath file_name_from(test_dir_); 95 FilePath file_name_from(test_dir_);
96 file_name_from = file_name_from.AppendASCII("File_From.txt"); 96 file_name_from = file_name_from.AppendASCII("File_From.txt");
97 CreateTextFile(file_name_from.value(), text_content_1); 97 CreateTextFile(file_name_from.value(), text_content_1);
98 ASSERT_TRUE(file_util::PathExists(file_name_from)); 98 ASSERT_TRUE(file_util::PathExists(file_name_from));
99 99
100 // Create destination path 100 // Create destination path
101 FilePath dir_name_to(test_dir_); 101 FilePath dir_name_to(test_dir_);
102 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 102 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
103 CreateDirectory(dir_name_to.value().c_str(), NULL); 103 file_util::CreateDirectory(dir_name_to);
104 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 104 ASSERT_TRUE(file_util::PathExists(dir_name_to));
105 105
106 FilePath file_name_to(dir_name_to); 106 FilePath file_name_to(dir_name_to);
107 file_name_to = file_name_to.AppendASCII("File_To.txt"); 107 file_name_to = file_name_to.AppendASCII("File_To.txt");
108 108
109 // test Do() 109 // test Do()
110 scoped_ptr<CopyTreeWorkItem> work_item( 110 scoped_ptr<CopyTreeWorkItem> work_item(
111 WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), 111 WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(),
112 file_name_to.ToWStringHack(), 112 file_name_to.ToWStringHack(),
113 temp_dir_.ToWStringHack(), 113 temp_dir_.ToWStringHack(),
(...skipping 18 matching lines...) Expand all
132 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { 132 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
133 // Create source file 133 // Create source file
134 FilePath file_name_from(test_dir_); 134 FilePath file_name_from(test_dir_);
135 file_name_from = file_name_from.AppendASCII("File_From.txt"); 135 file_name_from = file_name_from.AppendASCII("File_From.txt");
136 CreateTextFile(file_name_from.value(), text_content_1); 136 CreateTextFile(file_name_from.value(), text_content_1);
137 ASSERT_TRUE(file_util::PathExists(file_name_from)); 137 ASSERT_TRUE(file_util::PathExists(file_name_from));
138 138
139 // Create destination file 139 // Create destination file
140 FilePath dir_name_to(test_dir_); 140 FilePath dir_name_to(test_dir_);
141 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 141 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
142 CreateDirectory(dir_name_to.value().c_str(), NULL); 142 file_util::CreateDirectory(dir_name_to);
143 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 143 ASSERT_TRUE(file_util::PathExists(dir_name_to));
144 144
145 FilePath file_name_to(dir_name_to); 145 FilePath file_name_to(dir_name_to);
146 file_name_to = file_name_to.AppendASCII("File_To.txt"); 146 file_name_to = file_name_to.AppendASCII("File_To.txt");
147 CreateTextFile(file_name_to.value(), text_content_2); 147 CreateTextFile(file_name_to.value(), text_content_2);
148 ASSERT_TRUE(file_util::PathExists(file_name_to)); 148 ASSERT_TRUE(file_util::PathExists(file_name_to));
149 149
150 // test Do() with always_overwrite being true. 150 // test Do() with always_overwrite being true.
151 scoped_ptr<CopyTreeWorkItem> work_item( 151 scoped_ptr<CopyTreeWorkItem> work_item(
152 WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(), 152 WorkItem::CreateCopyTreeWorkItem(file_name_from.ToWStringHack(),
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { 200 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
201 // Create source file 201 // Create source file
202 FilePath file_name_from(test_dir_); 202 FilePath file_name_from(test_dir_);
203 file_name_from = file_name_from.AppendASCII("File_From.txt"); 203 file_name_from = file_name_from.AppendASCII("File_From.txt");
204 CreateTextFile(file_name_from.value(), text_content_1); 204 CreateTextFile(file_name_from.value(), text_content_1);
205 ASSERT_TRUE(file_util::PathExists(file_name_from)); 205 ASSERT_TRUE(file_util::PathExists(file_name_from));
206 206
207 // Create destination file 207 // Create destination file
208 FilePath dir_name_to(test_dir_); 208 FilePath dir_name_to(test_dir_);
209 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 209 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
210 CreateDirectory(dir_name_to.value().c_str(), NULL); 210 file_util::CreateDirectory(dir_name_to);
211 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 211 ASSERT_TRUE(file_util::PathExists(dir_name_to));
212 212
213 FilePath file_name_to(dir_name_to); 213 FilePath file_name_to(dir_name_to);
214 file_name_to = file_name_to.AppendASCII("File_To.txt"); 214 file_name_to = file_name_to.AppendASCII("File_To.txt");
215 CreateTextFile(file_name_to.value(), text_content_1); 215 CreateTextFile(file_name_to.value(), text_content_1);
216 ASSERT_TRUE(file_util::PathExists(file_name_to)); 216 ASSERT_TRUE(file_util::PathExists(file_name_to));
217 217
218 // Get the path of backup file 218 // Get the path of backup file
219 FilePath backup_file(temp_dir_); 219 FilePath backup_file(temp_dir_);
220 backup_file = backup_file.AppendASCII("File_To.txt"); 220 backup_file = backup_file.AppendASCII("File_To.txt");
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { 278 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
279 // Create source file 279 // Create source file
280 FilePath file_name_from(test_dir_); 280 FilePath file_name_from(test_dir_);
281 file_name_from = file_name_from.AppendASCII("File_From.txt"); 281 file_name_from = file_name_from.AppendASCII("File_From.txt");
282 CreateTextFile(file_name_from.value(), text_content_1); 282 CreateTextFile(file_name_from.value(), text_content_1);
283 ASSERT_TRUE(file_util::PathExists(file_name_from)); 283 ASSERT_TRUE(file_util::PathExists(file_name_from));
284 284
285 // Create destination file 285 // Create destination file
286 FilePath dir_name_to(test_dir_); 286 FilePath dir_name_to(test_dir_);
287 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 287 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
288 CreateDirectory(dir_name_to.value().c_str(), NULL); 288 file_util::CreateDirectory(dir_name_to);
289 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 289 ASSERT_TRUE(file_util::PathExists(dir_name_to));
290 290
291 FilePath file_name_to(dir_name_to); 291 FilePath file_name_to(dir_name_to);
292 file_name_to = file_name_to.AppendASCII("File_To.txt"); 292 file_name_to = file_name_to.AppendASCII("File_To.txt");
293 CreateTextFile(file_name_to.value(), text_content_2); 293 CreateTextFile(file_name_to.value(), text_content_2);
294 ASSERT_TRUE(file_util::PathExists(file_name_to)); 294 ASSERT_TRUE(file_util::PathExists(file_name_to));
295 295
296 // Get the path of backup file 296 // Get the path of backup file
297 FilePath backup_file(temp_dir_); 297 FilePath backup_file(temp_dir_);
298 backup_file = backup_file.AppendASCII("File_To.txt"); 298 backup_file = backup_file.AppendASCII("File_To.txt");
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 CreateTextFile(file_name_from.value(), text_content_1); 330 CreateTextFile(file_name_from.value(), text_content_1);
331 ASSERT_TRUE(file_util::PathExists(file_name_from)); 331 ASSERT_TRUE(file_util::PathExists(file_name_from));
332 332
333 // Create an executable in destination path by copying ourself to it. 333 // Create an executable in destination path by copying ourself to it.
334 wchar_t exe_full_path_str[MAX_PATH]; 334 wchar_t exe_full_path_str[MAX_PATH];
335 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 335 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
336 FilePath exe_full_path(exe_full_path_str); 336 FilePath exe_full_path(exe_full_path_str);
337 337
338 FilePath dir_name_to(test_dir_); 338 FilePath dir_name_to(test_dir_);
339 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 339 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
340 CreateDirectory(dir_name_to.value().c_str(), NULL); 340 file_util::CreateDirectory(dir_name_to);
341 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 341 ASSERT_TRUE(file_util::PathExists(dir_name_to));
342 342
343 FilePath file_name_to(dir_name_to); 343 FilePath file_name_to(dir_name_to);
344 file_name_to = file_name_to.AppendASCII("File_To"); 344 file_name_to = file_name_to.AppendASCII("File_To");
345 file_util::CopyFile(exe_full_path, file_name_to); 345 file_util::CopyFile(exe_full_path, file_name_to);
346 ASSERT_TRUE(file_util::PathExists(file_name_to)); 346 ASSERT_TRUE(file_util::PathExists(file_name_to));
347 347
348 LOG(INFO) << "copy ourself from " 348 LOG(INFO) << "copy ourself from "
349 << exe_full_path.value() << " to " << file_name_to.value(); 349 << exe_full_path.value() << " to " << file_name_to.value();
350 350
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 CreateTextFile(file_name_from.value(), text_content_1); 407 CreateTextFile(file_name_from.value(), text_content_1);
408 ASSERT_TRUE(file_util::PathExists(file_name_from)); 408 ASSERT_TRUE(file_util::PathExists(file_name_from));
409 409
410 // Create an executable in destination path by copying ourself to it. 410 // Create an executable in destination path by copying ourself to it.
411 wchar_t exe_full_path_str[MAX_PATH]; 411 wchar_t exe_full_path_str[MAX_PATH];
412 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 412 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
413 FilePath exe_full_path(exe_full_path_str); 413 FilePath exe_full_path(exe_full_path_str);
414 414
415 FilePath dir_name_to(test_dir_); 415 FilePath dir_name_to(test_dir_);
416 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 416 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
417 CreateDirectory(dir_name_to.value().c_str(), NULL); 417 file_util::CreateDirectory(dir_name_to);
418 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 418 ASSERT_TRUE(file_util::PathExists(dir_name_to));
419 419
420 FilePath file_name_to(dir_name_to), alternate_to(dir_name_to); 420 FilePath file_name_to(dir_name_to), alternate_to(dir_name_to);
421 file_name_to = file_name_to.AppendASCII("File_To"); 421 file_name_to = file_name_to.AppendASCII("File_To");
422 alternate_to = alternate_to.AppendASCII("Alternate_To"); 422 alternate_to = alternate_to.AppendASCII("Alternate_To");
423 file_util::CopyFile(exe_full_path, file_name_to); 423 file_util::CopyFile(exe_full_path, file_name_to);
424 ASSERT_TRUE(file_util::PathExists(file_name_to)); 424 ASSERT_TRUE(file_util::PathExists(file_name_to));
425 425
426 LOG(INFO) << "copy ourself from " 426 LOG(INFO) << "copy ourself from "
427 << exe_full_path.value() << " to " << file_name_to.value(); 427 << exe_full_path.value() << " to " << file_name_to.value();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 CreateTextFile(file_name_from.value(), text_content_1); 516 CreateTextFile(file_name_from.value(), text_content_1);
517 ASSERT_TRUE(file_util::PathExists(file_name_from)); 517 ASSERT_TRUE(file_util::PathExists(file_name_from));
518 518
519 // Create an executable in destination path by copying ourself to it. 519 // Create an executable in destination path by copying ourself to it.
520 wchar_t exe_full_path_str[MAX_PATH]; 520 wchar_t exe_full_path_str[MAX_PATH];
521 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 521 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
522 FilePath exe_full_path(exe_full_path_str); 522 FilePath exe_full_path(exe_full_path_str);
523 523
524 FilePath dir_name_to(test_dir_); 524 FilePath dir_name_to(test_dir_);
525 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 525 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
526 CreateDirectory(dir_name_to.value().c_str(), NULL); 526 file_util::CreateDirectory(dir_name_to);
527 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 527 ASSERT_TRUE(file_util::PathExists(dir_name_to));
528 FilePath file_name_to(dir_name_to); 528 FilePath file_name_to(dir_name_to);
529 file_name_to = file_name_to.AppendASCII("File_To"); 529 file_name_to = file_name_to.AppendASCII("File_To");
530 file_util::CopyFile(exe_full_path, file_name_to); 530 file_util::CopyFile(exe_full_path, file_name_to);
531 ASSERT_TRUE(file_util::PathExists(file_name_to)); 531 ASSERT_TRUE(file_util::PathExists(file_name_to));
532 532
533 // Get the path of backup file 533 // Get the path of backup file
534 FilePath backup_file(temp_dir_); 534 FilePath backup_file(temp_dir_);
535 backup_file = backup_file.AppendASCII("File_To"); 535 backup_file = backup_file.AppendASCII("File_To");
536 536
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 CreateTextFile(file_name_from.value(), text_content_1); 594 CreateTextFile(file_name_from.value(), text_content_1);
595 ASSERT_TRUE(file_util::PathExists(file_name_from)); 595 ASSERT_TRUE(file_util::PathExists(file_name_from));
596 596
597 // Create an executable in destination path by copying ourself to it. 597 // Create an executable in destination path by copying ourself to it.
598 wchar_t exe_full_path_str[MAX_PATH]; 598 wchar_t exe_full_path_str[MAX_PATH];
599 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 599 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
600 FilePath exe_full_path(exe_full_path_str); 600 FilePath exe_full_path(exe_full_path_str);
601 601
602 FilePath dir_name_to(test_dir_); 602 FilePath dir_name_to(test_dir_);
603 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 603 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
604 CreateDirectory(dir_name_to.value().c_str(), NULL); 604 file_util::CreateDirectory(dir_name_to);
605 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 605 ASSERT_TRUE(file_util::PathExists(dir_name_to));
606 606
607 FilePath file_name_to(dir_name_to); 607 FilePath file_name_to(dir_name_to);
608 file_name_to = file_name_to.AppendASCII("File_To"); 608 file_name_to = file_name_to.AppendASCII("File_To");
609 file_util::CopyFile(exe_full_path, file_name_to); 609 file_util::CopyFile(exe_full_path, file_name_to);
610 ASSERT_TRUE(file_util::PathExists(file_name_to)); 610 ASSERT_TRUE(file_util::PathExists(file_name_to));
611 611
612 LOG(INFO) << "copy ourself from " 612 LOG(INFO) << "copy ourself from "
613 << exe_full_path.value() << " to " << file_name_to.value(); 613 << exe_full_path.value() << " to " << file_name_to.value();
614 614
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 652 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
653 CloseHandle(pi.hProcess); 653 CloseHandle(pi.hProcess);
654 CloseHandle(pi.hThread); 654 CloseHandle(pi.hThread);
655 } 655 }
656 656
657 // Copy a tree from source to destination. 657 // Copy a tree from source to destination.
658 TEST_F(CopyTreeWorkItemTest, CopyTree) { 658 TEST_F(CopyTreeWorkItemTest, CopyTree) {
659 // Create source tree 659 // Create source tree
660 FilePath dir_name_from(test_dir_); 660 FilePath dir_name_from(test_dir_);
661 dir_name_from = dir_name_from.AppendASCII("from"); 661 dir_name_from = dir_name_from.AppendASCII("from");
662 CreateDirectory(dir_name_from.value().c_str(), NULL); 662 file_util::CreateDirectory(dir_name_from);
663 ASSERT_TRUE(file_util::PathExists(dir_name_from)); 663 ASSERT_TRUE(file_util::PathExists(dir_name_from));
664 664
665 FilePath dir_name_from_1(dir_name_from); 665 FilePath dir_name_from_1(dir_name_from);
666 dir_name_from_1 = dir_name_from_1.AppendASCII("1"); 666 dir_name_from_1 = dir_name_from_1.AppendASCII("1");
667 CreateDirectory(dir_name_from_1.value().c_str(), NULL); 667 file_util::CreateDirectory(dir_name_from_1);
668 ASSERT_TRUE(file_util::PathExists(dir_name_from_1)); 668 ASSERT_TRUE(file_util::PathExists(dir_name_from_1));
669 669
670 FilePath dir_name_from_2(dir_name_from); 670 FilePath dir_name_from_2(dir_name_from);
671 dir_name_from_2 = dir_name_from_2.AppendASCII("2"); 671 dir_name_from_2 = dir_name_from_2.AppendASCII("2");
672 CreateDirectory(dir_name_from_2.value().c_str(), NULL); 672 file_util::CreateDirectory(dir_name_from_2);
673 ASSERT_TRUE(file_util::PathExists(dir_name_from_2)); 673 ASSERT_TRUE(file_util::PathExists(dir_name_from_2));
674 674
675 FilePath file_name_from_1(dir_name_from_1); 675 FilePath file_name_from_1(dir_name_from_1);
676 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt"); 676 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt");
677 CreateTextFile(file_name_from_1.value(), text_content_1); 677 CreateTextFile(file_name_from_1.value(), text_content_1);
678 ASSERT_TRUE(file_util::PathExists(file_name_from_1)); 678 ASSERT_TRUE(file_util::PathExists(file_name_from_1));
679 679
680 FilePath file_name_from_2(dir_name_from_2); 680 FilePath file_name_from_2(dir_name_from_2);
681 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt"); 681 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt");
682 CreateTextFile(file_name_from_2.value(), text_content_1); 682 CreateTextFile(file_name_from_2.value(), text_content_1);
(...skipping 22 matching lines...) Expand all
705 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1)); 705 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1));
706 706
707 FilePath file_name_to_2(dir_name_to); 707 FilePath file_name_to_2(dir_name_to);
708 file_name_to_2 = file_name_to_2.AppendASCII("2"); 708 file_name_to_2 = file_name_to_2.AppendASCII("2");
709 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 709 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
710 EXPECT_TRUE(file_util::PathExists(file_name_to_2)); 710 EXPECT_TRUE(file_util::PathExists(file_name_to_2));
711 LOG(INFO) << "compare " 711 LOG(INFO) << "compare "
712 << file_name_from_2.value() << " and " << file_name_to_2.value(); 712 << file_name_from_2.value() << " and " << file_name_to_2.value();
713 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2)); 713 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2));
714 } 714 }
OLDNEW
« no previous file with comments | « no previous file | chrome/installer/util/create_dir_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698