diff options
Diffstat (limited to 'sandbox/src/win_utils_unittest.cc')
-rw-r--r-- | sandbox/src/win_utils_unittest.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/sandbox/src/win_utils_unittest.cc b/sandbox/src/win_utils_unittest.cc index 3afa78d..99ce7e2 100644 --- a/sandbox/src/win_utils_unittest.cc +++ b/sandbox/src/win_utils_unittest.cc @@ -4,6 +4,7 @@ #include <windows.h> +#include "base/scoped_handle_win.h" #include "sandbox/src/win_utils.h" #include "sandbox/tests/common/test_utils.h" #include "testing/gtest/include/gtest/gtest.h" @@ -49,3 +50,32 @@ TEST(WinUtils, IsReparsePoint) { EXPECT_TRUE(::CloseHandle(dir)); EXPECT_TRUE(::RemoveDirectory(my_folder)); } + +TEST(WinUtils, SameObject) { + using sandbox::SameObject; + + // Create a temp file because we need write access to it. + wchar_t temp_directory[MAX_PATH]; + wchar_t my_folder[MAX_PATH]; + ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); + ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u); + + // Delete the file and create a directory instead. + ASSERT_TRUE(::DeleteFile(my_folder)); + ASSERT_TRUE(::CreateDirectory(my_folder, NULL)); + + std::wstring folder(my_folder); + std::wstring file_name = folder + L"\\foo.txt"; + const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE; + ScopedHandle file(CreateFile(file_name.c_str(), GENERIC_WRITE, kSharing, NULL, + CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL)); + + EXPECT_TRUE(file.IsValid()); + std::wstring file_name_nt1 = std::wstring(L"\\??\\") + file_name; + std::wstring file_name_nt2 = std::wstring(L"\\??\\") + folder + L"\\FOO.txT"; + EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str())); + EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str())); + + file.Close(); + EXPECT_TRUE(::RemoveDirectory(my_folder)); +} |