OLD | NEW |
---|---|
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 "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> |
11 #include <tchar.h> | |
11 #endif | 12 #endif |
12 | 13 |
13 #include <fstream> | 14 #include <fstream> |
14 #include <iostream> | 15 #include <iostream> |
15 #include <set> | 16 #include <set> |
16 | 17 |
17 #include "base/base_paths.h" | 18 #include "base/base_paths.h" |
18 #include "base/file_path.h" | 19 #include "base/file_path.h" |
19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 ASSERT_FALSE(file_util::PathExists(dir_name_to)); | 767 ASSERT_FALSE(file_util::PathExists(dir_name_to)); |
767 | 768 |
768 EXPECT_TRUE(file_util::CopyAndDeleteDirectory(dir_name_from, dir_name_to)); | 769 EXPECT_TRUE(file_util::CopyAndDeleteDirectory(dir_name_from, dir_name_to)); |
769 | 770 |
770 // Check everything has been moved. | 771 // Check everything has been moved. |
771 EXPECT_FALSE(file_util::PathExists(dir_name_from)); | 772 EXPECT_FALSE(file_util::PathExists(dir_name_from)); |
772 EXPECT_FALSE(file_util::PathExists(file_name_from)); | 773 EXPECT_FALSE(file_util::PathExists(file_name_from)); |
773 EXPECT_TRUE(file_util::PathExists(dir_name_to)); | 774 EXPECT_TRUE(file_util::PathExists(dir_name_to)); |
774 EXPECT_TRUE(file_util::PathExists(file_name_to)); | 775 EXPECT_TRUE(file_util::PathExists(file_name_to)); |
775 } | 776 } |
776 #endif | 777 |
778 TEST_F(FileUtilTest, GetTempDirTest) { | |
779 static const TCHAR* kTmpKey = _T("TMP"); | |
780 static const TCHAR* kTmpValues[] = { | |
781 _T(""), _T("C:"), _T("C:\\"), _T("C:\\tmp"), _T("C:\\tmp\\") | |
Erik does not do reviews
2009/10/09 14:16:33
Isn't this saying that "" and "C:" should be consi
Mark Mentovai
2009/10/09 14:31:16
I guess Win32's ::GetTempPath always returns an ab
tkent
2009/10/09 15:09:34
Right.
May EXPECT_TRUE(path.isAbsolute()) was mis
| |
782 }; | |
783 // Save the original $TMP. | |
784 size_t original_tmp_size; | |
785 TCHAR* original_tmp; | |
786 ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey)); | |
787 // original_tmp may be NULL. | |
788 | |
789 for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) { | |
790 FilePath path; | |
791 ::_tputenv_s(kTmpKey, kTmpValues[i]); | |
792 file_util::GetTempDir(&path); | |
793 EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] << | |
794 " result=" << path.value(); | |
795 } | |
796 | |
797 // Restore the original $TMP. | |
798 if (original_tmp) { | |
799 ::_tputenv_s(kTmpKey, original_tmp); | |
800 free(original_tmp); | |
801 } else { | |
802 ::_tputenv_s(kTmpKey, _T("")); | |
803 } | |
804 } | |
805 #endif // OS_WIN | |
777 | 806 |
778 TEST_F(FileUtilTest, CreateTemporaryFileTest) { | 807 TEST_F(FileUtilTest, CreateTemporaryFileTest) { |
779 FilePath temp_files[3]; | 808 FilePath temp_files[3]; |
780 for (int i = 0; i < 3; i++) { | 809 for (int i = 0; i < 3; i++) { |
781 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); | 810 ASSERT_TRUE(file_util::CreateTemporaryFile(&(temp_files[i]))); |
782 EXPECT_TRUE(file_util::PathExists(temp_files[i])); | 811 EXPECT_TRUE(file_util::PathExists(temp_files[i])); |
783 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i])); | 812 EXPECT_FALSE(file_util::DirectoryExists(temp_files[i])); |
784 } | 813 } |
785 for (int i = 0; i < 3; i++) | 814 for (int i = 0; i < 3; i++) |
786 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); | 815 EXPECT_FALSE(temp_files[i] == temp_files[(i+1)%3]); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1071 #elif defined(OS_LINUX) | 1100 #elif defined(OS_LINUX) |
1072 EXPECT_FALSE(file_util::ContainsPath(foo, | 1101 EXPECT_FALSE(file_util::ContainsPath(foo, |
1073 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); | 1102 foo_caps.Append(FILE_PATH_LITERAL("bar.txt")))); |
1074 #else | 1103 #else |
1075 // We can't really do this test on osx since the case-sensitivity of the | 1104 // We can't really do this test on osx since the case-sensitivity of the |
1076 // filesystem is configurable. | 1105 // filesystem is configurable. |
1077 #endif | 1106 #endif |
1078 } | 1107 } |
1079 | 1108 |
1080 } // namespace | 1109 } // namespace |
OLD | NEW |