OLD | NEW |
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 | 6 |
7 #include "base/win/scoped_handle.h" | 7 #include "base/win/scoped_handle.h" |
8 #include "sandbox/win/src/win_utils.h" | 8 #include "sandbox/win/src/win_utils.h" |
9 #include "sandbox/win/tests/common/test_utils.h" | 9 #include "sandbox/win/tests/common/test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 TEST(WinUtils, IsReparsePoint) { | 12 TEST(WinUtils, IsReparsePoint) { |
13 using sandbox::IsReparsePoint; | 13 using sandbox::IsReparsePoint; |
14 | 14 |
15 // Create a temp file because we need write access to it. | 15 // Create a temp file because we need write access to it. |
16 wchar_t temp_directory[MAX_PATH]; | 16 wchar_t temp_directory[MAX_PATH]; |
17 wchar_t my_folder[MAX_PATH]; | 17 wchar_t my_folder[MAX_PATH]; |
18 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); | 18 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); |
19 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u); | 19 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u); |
20 | 20 |
21 // Delete the file and create a directory instead. | 21 // Delete the file and create a directory instead. |
22 ASSERT_TRUE(::DeleteFile(my_folder)); | 22 ASSERT_TRUE(::DeleteFile(my_folder)); |
23 ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); | 23 ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); |
24 | 24 |
25 EXPECT_EQ(ERROR_NOT_A_REPARSE_POINT, IsReparsePoint(my_folder)); | 25 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT), |
| 26 IsReparsePoint(my_folder)); |
26 | 27 |
27 base::string16 not_found = base::string16(my_folder) + L"\\foo\\bar"; | 28 base::string16 not_found = base::string16(my_folder) + L"\\foo\\bar"; |
28 EXPECT_EQ(ERROR_NOT_A_REPARSE_POINT, IsReparsePoint(not_found)); | 29 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT), |
| 30 IsReparsePoint(not_found)); |
29 | 31 |
30 base::string16 new_file = base::string16(my_folder) + L"\\foo"; | 32 base::string16 new_file = base::string16(my_folder) + L"\\foo"; |
31 EXPECT_EQ(ERROR_NOT_A_REPARSE_POINT, IsReparsePoint(new_file)); | 33 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT), |
| 34 IsReparsePoint(new_file)); |
32 | 35 |
33 // Replace the directory with a reparse point to %temp%. | 36 // Replace the directory with a reparse point to %temp%. |
34 HANDLE dir = ::CreateFile(my_folder, FILE_ALL_ACCESS, | 37 HANDLE dir = ::CreateFile(my_folder, FILE_ALL_ACCESS, |
35 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, | 38 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
36 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); | 39 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
37 EXPECT_NE(INVALID_HANDLE_VALUE, dir); | 40 EXPECT_NE(INVALID_HANDLE_VALUE, dir); |
38 | 41 |
39 base::string16 temp_dir_nt = base::string16(L"\\??\\") + temp_directory; | 42 base::string16 temp_dir_nt = base::string16(L"\\??\\") + temp_directory; |
40 EXPECT_TRUE(SetReparsePoint(dir, temp_dir_nt.c_str())); | 43 EXPECT_TRUE(SetReparsePoint(dir, temp_dir_nt.c_str())); |
41 | 44 |
42 EXPECT_EQ(ERROR_SUCCESS, IsReparsePoint(new_file)); | 45 EXPECT_EQ(static_cast<DWORD>(ERROR_SUCCESS), IsReparsePoint(new_file)); |
43 | 46 |
44 EXPECT_TRUE(DeleteReparsePoint(dir)); | 47 EXPECT_TRUE(DeleteReparsePoint(dir)); |
45 EXPECT_TRUE(::CloseHandle(dir)); | 48 EXPECT_TRUE(::CloseHandle(dir)); |
46 EXPECT_TRUE(::RemoveDirectory(my_folder)); | 49 EXPECT_TRUE(::RemoveDirectory(my_folder)); |
47 } | 50 } |
48 | 51 |
49 TEST(WinUtils, SameObject) { | 52 TEST(WinUtils, SameObject) { |
50 using sandbox::SameObject; | 53 using sandbox::SameObject; |
51 | 54 |
52 // Create a temp file because we need write access to it. | 55 // Create a temp file because we need write access to it. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Written as two strings to prevent trigraph '?' '?' '/'. | 102 // Written as two strings to prevent trigraph '?' '?' '/'. |
100 pipe_name = L"/?" L"?/pipe/mypipe"; | 103 pipe_name = L"/?" L"?/pipe/mypipe"; |
101 EXPECT_FALSE(IsPipe(pipe_name)); | 104 EXPECT_FALSE(IsPipe(pipe_name)); |
102 | 105 |
103 pipe_name = L"\\XX\\pipe\\mypipe"; | 106 pipe_name = L"\\XX\\pipe\\mypipe"; |
104 EXPECT_FALSE(IsPipe(pipe_name)); | 107 EXPECT_FALSE(IsPipe(pipe_name)); |
105 | 108 |
106 pipe_name = L"\\Device\\NamedPipe\\mypipe"; | 109 pipe_name = L"\\Device\\NamedPipe\\mypipe"; |
107 EXPECT_FALSE(IsPipe(pipe_name)); | 110 EXPECT_FALSE(IsPipe(pipe_name)); |
108 } | 111 } |
OLD | NEW |