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

Side by Side Diff: base/file_util_unittest.cc

Issue 173418: Avoids the use of ToWStringHack in a few places.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 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 | « app/l10n_util_unittest.cc ('k') | chrome/browser/privacy_blacklist/blacklist_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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 58
59 // the path to temporary directory used to contain the test operations 59 // the path to temporary directory used to contain the test operations
60 FilePath test_dir_; 60 FilePath test_dir_;
61 }; 61 };
62 62
63 // Collects all the results from the given file enumerator, and provides an 63 // Collects all the results from the given file enumerator, and provides an
64 // interface to query whether a given file is present. 64 // interface to query whether a given file is present.
65 class FindResultCollector { 65 class FindResultCollector {
66 public: 66 public:
67 FindResultCollector(file_util::FileEnumerator& enumerator) { 67 explicit FindResultCollector(file_util::FileEnumerator& enumerator) {
68 FilePath cur_file; 68 FilePath cur_file;
69 while (!(cur_file = enumerator.Next()).value().empty()) { 69 while (!(cur_file = enumerator.Next()).value().empty()) {
70 FilePath::StringType path = cur_file.value(); 70 FilePath::StringType path = cur_file.value();
71 // The file should not be returned twice. 71 // The file should not be returned twice.
72 EXPECT_TRUE(files_.end() == files_.find(path)) 72 EXPECT_TRUE(files_.end() == files_.find(path))
73 << "Same file returned twice"; 73 << "Same file returned twice";
74 74
75 // Save for later. 75 // Save for later.
76 files_.insert(path); 76 files_.insert(path);
77 } 77 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 {L"C:\\", L"C:"}, 299 {L"C:\\", L"C:"},
300 #elif defined(OS_POSIX) 300 #elif defined(OS_POSIX)
301 {L"/foo/bar/gdi32.dll", L"/foo/bar"}, 301 {L"/foo/bar/gdi32.dll", L"/foo/bar"},
302 {L"/foo/bar/not_exist_thx_1138", L"/foo/bar"}, 302 {L"/foo/bar/not_exist_thx_1138", L"/foo/bar"},
303 {L"/foo/bar/", L"/foo/bar"}, 303 {L"/foo/bar/", L"/foo/bar"},
304 {L"/foo/bar//", L"/foo/bar"}, 304 {L"/foo/bar//", L"/foo/bar"},
305 {L"/foo/bar", L"/foo"}, 305 {L"/foo/bar", L"/foo"},
306 {L"/foo/bar./", L"/foo/bar."}, 306 {L"/foo/bar./", L"/foo/bar."},
307 {L"/", L"/"}, 307 {L"/", L"/"},
308 {L".", L"."}, 308 {L".", L"."},
309 {L"..", L"."}, // yes, ".." technically lives in "." 309 {L"..", L"."}, // yes, ".." technically lives in "."
310 #endif 310 #endif
311 }; 311 };
312 312
313 TEST_F(FileUtilTest, GetDirectoryFromPath) { 313 TEST_F(FileUtilTest, GetDirectoryFromPath) {
314 for (unsigned int i = 0; i < arraysize(dir_cases); ++i) { 314 for (unsigned int i = 0; i < arraysize(dir_cases); ++i) {
315 const dir_case& dir = dir_cases[i]; 315 const dir_case& dir = dir_cases[i];
316 const std::wstring parent = 316 const std::wstring parent =
317 file_util::GetDirectoryFromPath(dir.full_path); 317 file_util::GetDirectoryFromPath(dir.full_path);
318 EXPECT_EQ(dir.directory, parent); 318 EXPECT_EQ(dir.directory, parent);
319 } 319 }
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); 517 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
518 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); 518 const std::wstring file_contents(L"Gooooooooooooooooooooogle");
519 CreateTextFile(file_name_from, file_contents); 519 CreateTextFile(file_name_from, file_contents);
520 ASSERT_TRUE(file_util::PathExists(file_name_from)); 520 ASSERT_TRUE(file_util::PathExists(file_name_from));
521 521
522 // Copy the file. 522 // Copy the file.
523 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); 523 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt"));
524 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file)); 524 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file));
525 525
526 // Copy the file to another location using '..' in the path. 526 // Copy the file to another location using '..' in the path.
527 std::wstring dest_file2(dir_name_from.ToWStringHack()); 527 FilePath dest_file2(dir_name_from);
528 file_util::AppendToPath(&dest_file2, L".."); 528 dest_file2 = dest_file2.AppendASCII("..");
529 file_util::AppendToPath(&dest_file2, L"DestFile.txt"); 529 dest_file2 = dest_file2.AppendASCII("DestFile.txt");
530 ASSERT_TRUE(file_util::CopyFile(file_name_from, 530 ASSERT_TRUE(file_util::CopyFile(file_name_from, dest_file2));
531 FilePath::FromWStringHack(dest_file2))); 531
532 std::wstring dest_file2_test(dir_name_from.ToWStringHack()); 532 FilePath dest_file2_test(dir_name_from);
533 file_util::UpOneDirectory(&dest_file2_test); 533 dest_file2_test = dest_file2_test.DirName();
534 file_util::AppendToPath(&dest_file2_test, L"DestFile.txt"); 534 dest_file2_test = dest_file2_test.AppendASCII("DestFile.txt");
535 535
536 // Check everything has been copied. 536 // Check everything has been copied.
537 EXPECT_TRUE(file_util::PathExists(file_name_from)); 537 EXPECT_TRUE(file_util::PathExists(file_name_from));
538 EXPECT_TRUE(file_util::PathExists(dest_file)); 538 EXPECT_TRUE(file_util::PathExists(dest_file));
539 const std::wstring read_contents = ReadTextFile(dest_file); 539 const std::wstring read_contents = ReadTextFile(dest_file);
540 EXPECT_EQ(file_contents, read_contents); 540 EXPECT_EQ(file_contents, read_contents);
541 EXPECT_TRUE(file_util::PathExists( 541 EXPECT_TRUE(file_util::PathExists(dest_file2_test));
542 FilePath::FromWStringHack(dest_file2_test))); 542 EXPECT_TRUE(file_util::PathExists(dest_file2));
543 EXPECT_TRUE(file_util::PathExists(FilePath::FromWStringHack(dest_file2)));
544 } 543 }
545 544
546 // TODO(erikkay): implement 545 // TODO(erikkay): implement
547 #if defined(OS_WIN) 546 #if defined(OS_WIN)
548 TEST_F(FileUtilTest, GetFileCreationLocalTime) { 547 TEST_F(FileUtilTest, GetFileCreationLocalTime) {
549 FilePath file_name = test_dir_.Append(L"Test File.txt"); 548 FilePath file_name = test_dir_.Append(L"Test File.txt");
550 549
551 SYSTEMTIME start_time; 550 SYSTEMTIME start_time;
552 GetLocalTime(&start_time); 551 GetLocalTime(&start_time);
553 Sleep(100); 552 Sleep(100);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 } 806 }
808 807
809 // Close and delete. 808 // Close and delete.
810 for (i = 0; i < 3; ++i) { 809 for (i = 0; i < 3; ++i) {
811 EXPECT_TRUE(file_util::CloseFile(fps[i])); 810 EXPECT_TRUE(file_util::CloseFile(fps[i]));
812 EXPECT_TRUE(file_util::Delete(names[i], false)); 811 EXPECT_TRUE(file_util::Delete(names[i], false));
813 } 812 }
814 } 813 }
815 814
816 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) { 815 TEST_F(FileUtilTest, CreateNewTempDirectoryTest) {
817 std::wstring temp_dir; 816 FilePath temp_dir;
818 ASSERT_TRUE(file_util::CreateNewTempDirectory(std::wstring(), &temp_dir)); 817 ASSERT_TRUE(file_util::CreateNewTempDirectory(FilePath::StringType(),
818 &temp_dir));
819 EXPECT_TRUE(file_util::PathExists(temp_dir)); 819 EXPECT_TRUE(file_util::PathExists(temp_dir));
820 EXPECT_TRUE(file_util::Delete(temp_dir, false)); 820 EXPECT_TRUE(file_util::Delete(temp_dir, false));
821 } 821 }
822 822
823 TEST_F(FileUtilTest, GetShmemTempDirTest) { 823 TEST_F(FileUtilTest, GetShmemTempDirTest) {
824 FilePath dir; 824 FilePath dir;
825 EXPECT_TRUE(file_util::GetShmemTempDir(&dir)); 825 EXPECT_TRUE(file_util::GetShmemTempDir(&dir));
826 EXPECT_TRUE(file_util::DirectoryExists(dir)); 826 EXPECT_TRUE(file_util::DirectoryExists(dir));
827 } 827 }
828 828
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 #elif defined(OS_LINUX) 1158 #elif defined(OS_LINUX)
1159 EXPECT_FALSE(file_util::ContainsPath(foo, 1159 EXPECT_FALSE(file_util::ContainsPath(foo,
1160 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); 1160 foo_caps.Append(FILE_PATH_LITERAL("bar.txt"))));
1161 #else 1161 #else
1162 // We can't really do this test on osx since the case-sensitivity of the 1162 // We can't really do this test on osx since the case-sensitivity of the
1163 // filesystem is configurable. 1163 // filesystem is configurable.
1164 #endif 1164 #endif
1165 } 1165 }
1166 1166
1167 } // namespace 1167 } // namespace
OLDNEW
« no previous file with comments | « app/l10n_util_unittest.cc ('k') | chrome/browser/privacy_blacklist/blacklist_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698