Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: base/win/scoped_handle_unittest.cc

Issue 1780513002: Remove LOG(FATAL) as this can't be called late in Chrome shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments here are actually useful. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/win/scoped_handle.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <winternl.h> 6 #include <winternl.h>
7 7
8 #include "base/win/scoped_handle.h" 8 #include "base/win/scoped_handle.h"
9 9
10 #include <utility> 10 #include <utility>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 ASSERT_NE(HANDLE(nullptr), handle); 44 ASSERT_NE(HANDLE(nullptr), handle);
45 typedef NTSTATUS(WINAPI * NtCloseFunc)(HANDLE); 45 typedef NTSTATUS(WINAPI * NtCloseFunc)(HANDLE);
46 NtCloseFunc ntclose = reinterpret_cast<NtCloseFunc>( 46 NtCloseFunc ntclose = reinterpret_cast<NtCloseFunc>(
47 GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtClose")); 47 GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtClose"));
48 ASSERT_NE(nullptr, ntclose); 48 ASSERT_NE(nullptr, ntclose);
49 49
50 ASSERT_DEATH({ 50 ASSERT_DEATH({
51 base::win::ScopedHandle handle_holder(handle); 51 base::win::ScopedHandle handle_holder(handle);
52 ntclose(handle); 52 ntclose(handle);
53 // Destructing a ScopedHandle with an illegally closed handle should fail. 53 // Destructing a ScopedHandle with an illegally closed handle should fail.
54 }, "CloseHandle failed."); 54 }, "");
55 } 55 }
56 56
57 TEST(ScopedHandleTest, ActiveVerifierDoubleTracking) { 57 TEST(ScopedHandleTest, ActiveVerifierDoubleTracking) {
58 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); 58 HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
59 ASSERT_NE(HANDLE(nullptr), handle); 59 ASSERT_NE(HANDLE(nullptr), handle);
60 60
61 base::win::ScopedHandle handle_holder(handle); 61 base::win::ScopedHandle handle_holder(handle);
62 62
63 ASSERT_DEATH({ 63 ASSERT_DEATH({
64 base::win::ScopedHandle handle_holder2(handle); 64 base::win::ScopedHandle handle_holder2(handle);
65 }, "Attempt to start tracking already tracked handle."); 65 }, "");
66 } 66 }
67 67
68 TEST(ScopedHandleTest, ActiveVerifierWrongOwner) { 68 TEST(ScopedHandleTest, ActiveVerifierWrongOwner) {
69 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); 69 HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
70 ASSERT_NE(HANDLE(nullptr), handle); 70 ASSERT_NE(HANDLE(nullptr), handle);
71 71
72 base::win::ScopedHandle handle_holder(handle); 72 base::win::ScopedHandle handle_holder(handle);
73 ASSERT_DEATH({ 73 ASSERT_DEATH({
74 base::win::ScopedHandle handle_holder2; 74 base::win::ScopedHandle handle_holder2;
75 handle_holder2.handle_ = handle; 75 handle_holder2.handle_ = handle;
76 }, "Attempting to close a handle not owned by opener."); 76 }, "");
77 ASSERT_TRUE(handle_holder.IsValid()); 77 ASSERT_TRUE(handle_holder.IsValid());
78 handle_holder.Close(); 78 handle_holder.Close();
79 } 79 }
80 80
81 TEST(ScopedHandleTest, ActiveVerifierUntrackedHandle) { 81 TEST(ScopedHandleTest, ActiveVerifierUntrackedHandle) {
82 HANDLE handle = ::CreateMutex(nullptr, false, nullptr); 82 HANDLE handle = ::CreateMutex(nullptr, false, nullptr);
83 ASSERT_NE(HANDLE(nullptr), handle); 83 ASSERT_NE(HANDLE(nullptr), handle);
84 84
85 ASSERT_DEATH({ 85 ASSERT_DEATH({
86 base::win::ScopedHandle handle_holder; 86 base::win::ScopedHandle handle_holder;
87 handle_holder.handle_ = handle; 87 handle_holder.handle_ = handle;
88 }, "Attempting to close an untracked handle."); 88 }, "");
89 89
90 ASSERT_TRUE(::CloseHandle(handle)); 90 ASSERT_TRUE(::CloseHandle(handle));
91 } 91 }
92 92
93 } // namespace win 93 } // namespace win
94 } // namespace base 94 } // namespace base
OLDNEW
« no previous file with comments | « base/win/scoped_handle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698