OLD | NEW |
1 // Copyright (c) 2010 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/scoped_handle_win.h" | 7 #include "base/win/scoped_handle.h" |
8 #include "sandbox/src/win_utils.h" | 8 #include "sandbox/src/win_utils.h" |
9 #include "sandbox/tests/common/test_utils.h" | 9 #include "sandbox/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]; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); | 60 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); |
61 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u); | 61 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u); |
62 | 62 |
63 // Delete the file and create a directory instead. | 63 // Delete the file and create a directory instead. |
64 ASSERT_TRUE(::DeleteFile(my_folder)); | 64 ASSERT_TRUE(::DeleteFile(my_folder)); |
65 ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); | 65 ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); |
66 | 66 |
67 std::wstring folder(my_folder); | 67 std::wstring folder(my_folder); |
68 std::wstring file_name = folder + L"\\foo.txt"; | 68 std::wstring file_name = folder + L"\\foo.txt"; |
69 const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; | 69 const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; |
70 ScopedHandle file(CreateFile(file_name.c_str(), GENERIC_WRITE, kSharing, NULL, | 70 base::win::ScopedHandle file(CreateFile( |
71 CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL)); | 71 file_name.c_str(), GENERIC_WRITE, kSharing, NULL, CREATE_ALWAYS, |
| 72 FILE_FLAG_DELETE_ON_CLOSE, NULL)); |
72 | 73 |
73 EXPECT_TRUE(file.IsValid()); | 74 EXPECT_TRUE(file.IsValid()); |
74 std::wstring file_name_nt1 = std::wstring(L"\\??\\") + file_name; | 75 std::wstring file_name_nt1 = std::wstring(L"\\??\\") + file_name; |
75 std::wstring file_name_nt2 = std::wstring(L"\\??\\") + folder + L"\\FOO.txT"; | 76 std::wstring file_name_nt2 = std::wstring(L"\\??\\") + folder + L"\\FOO.txT"; |
76 EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str())); | 77 EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str())); |
77 EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str())); | 78 EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str())); |
78 | 79 |
79 file.Close(); | 80 file.Close(); |
80 EXPECT_TRUE(::RemoveDirectory(my_folder)); | 81 EXPECT_TRUE(::RemoveDirectory(my_folder)); |
81 } | 82 } |
OLD | NEW |