| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <fstream> | 9 #include <fstream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 // Restore the original $TMP. | 1704 // Restore the original $TMP. |
| 1705 if (original_tmp) { | 1705 if (original_tmp) { |
| 1706 ::_tputenv_s(kTmpKey, original_tmp); | 1706 ::_tputenv_s(kTmpKey, original_tmp); |
| 1707 free(original_tmp); | 1707 free(original_tmp); |
| 1708 } else { | 1708 } else { |
| 1709 ::_tputenv_s(kTmpKey, _T("")); | 1709 ::_tputenv_s(kTmpKey, _T("")); |
| 1710 } | 1710 } |
| 1711 } | 1711 } |
| 1712 | |
| 1713 TEST_F(FileUtilTest, IsOnNetworkDrive) { | |
| 1714 struct LocalTestData { | |
| 1715 const FilePath::CharType* input; | |
| 1716 bool expected; | |
| 1717 }; | |
| 1718 | |
| 1719 const LocalTestData local_cases[] = { | |
| 1720 { FPL(""), false }, | |
| 1721 { FPL("c:\\"), false }, | |
| 1722 { FPL("c:"), false }, | |
| 1723 { FPL("c:\\windows\\notepad.exe"), false } | |
| 1724 }; | |
| 1725 | |
| 1726 for (const auto& test_case : local_cases) { | |
| 1727 FilePath input(test_case.input); | |
| 1728 bool observed = IsOnNetworkDrive(input); | |
| 1729 EXPECT_EQ(test_case.expected, observed) << " input: " << input.value(); | |
| 1730 } | |
| 1731 | |
| 1732 std::unique_ptr<Environment> env(Environment::Create()); | |
| 1733 // To test IsOnNetworkDrive() for remote cases, set up a file server | |
| 1734 // and place a file called file.txt on the server e.g. | |
| 1735 // \\DC01\TESTSHARE\file.txt | |
| 1736 // then set the two environment variables: | |
| 1737 // set BASE_TEST_FILE_SERVER=DC01 | |
| 1738 // set BASE_TEST_FILE_SHARE=TESTSHARE | |
| 1739 if (!env->HasVar("BASE_TEST_FILE_SERVER") || | |
| 1740 !env->HasVar("BASE_TEST_FILE_SHARE")) { | |
| 1741 return; | |
| 1742 } | |
| 1743 | |
| 1744 struct NetworkTestData { | |
| 1745 const wchar_t* input; | |
| 1746 bool expected; | |
| 1747 }; | |
| 1748 | |
| 1749 const NetworkTestData network_cases[] = { | |
| 1750 { L"\\\\%BASE_TEST_FILE_SERVER%", false }, | |
| 1751 { L"\\\\%BASE_TEST_FILE_SERVER%\\", false }, | |
| 1752 { L"\\\\%BASE_TEST_FILE_SERVER%\\file.txt", false }, | |
| 1753 { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%", true }, | |
| 1754 { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\", true }, | |
| 1755 { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\file.txt", true }, | |
| 1756 { L"\\\\%BASE_TEST_FILE_SERVER%\\%BASE_TEST_FILE_SHARE%\\no.txt", false } | |
| 1757 }; | |
| 1758 | |
| 1759 for (const auto& test_case : network_cases) { | |
| 1760 wchar_t path[MAX_PATH] = {0}; | |
| 1761 ::ExpandEnvironmentStringsW(test_case.input, path, arraysize(path)); | |
| 1762 FilePath input(path); | |
| 1763 EXPECT_EQ(test_case.expected, IsOnNetworkDrive(input)) << " input : " | |
| 1764 << input.value(); | |
| 1765 } | |
| 1766 } | |
| 1767 #endif // OS_WIN | 1712 #endif // OS_WIN |
| 1768 | 1713 |
| 1769 TEST_F(FileUtilTest, CreateTemporaryFileTest) { | 1714 TEST_F(FileUtilTest, CreateTemporaryFileTest) { |
| 1770 FilePath temp_files[3]; | 1715 FilePath temp_files[3]; |
| 1771 for (int i = 0; i < 3; i++) { | 1716 for (int i = 0; i < 3; i++) { |
| 1772 ASSERT_TRUE(CreateTemporaryFile(&(temp_files[i]))); | 1717 ASSERT_TRUE(CreateTemporaryFile(&(temp_files[i]))); |
| 1773 EXPECT_TRUE(PathExists(temp_files[i])); | 1718 EXPECT_TRUE(PathExists(temp_files[i])); |
| 1774 EXPECT_FALSE(DirectoryExists(temp_files[i])); | 1719 EXPECT_FALSE(DirectoryExists(temp_files[i])); |
| 1775 } | 1720 } |
| 1776 for (int i = 0; i < 3; i++) | 1721 for (int i = 0; i < 3; i++) |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2623 // Trying to close it should crash. This is important for security. | 2568 // Trying to close it should crash. This is important for security. |
| 2624 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2569 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2625 #endif | 2570 #endif |
| 2626 } | 2571 } |
| 2627 | 2572 |
| 2628 #endif // defined(OS_POSIX) | 2573 #endif // defined(OS_POSIX) |
| 2629 | 2574 |
| 2630 } // namespace | 2575 } // namespace |
| 2631 | 2576 |
| 2632 } // namespace base | 2577 } // namespace base |
| OLD | NEW |