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 "base/win/scoped_handle.h" | 5 #include "base/win/scoped_handle.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
8 | 10 |
9 TEST(ScopedHandleTest, ScopedHandle) { | 11 TEST(ScopedHandleTest, ScopedHandle) { |
10 // Any illegal error code will do. We just need to test that it is preserved | 12 // Any illegal error code will do. We just need to test that it is preserved |
11 // by ScopedHandle to avoid bug 528394. | 13 // by ScopedHandle to avoid bug 528394. |
12 const DWORD magic_error = 0x12345678; | 14 const DWORD magic_error = 0x12345678; |
13 | 15 |
14 HANDLE handle = ::CreateMutex(nullptr, FALSE, nullptr); | 16 HANDLE handle = ::CreateMutex(nullptr, FALSE, nullptr); |
15 // Call SetLastError after creating the handle. | 17 // Call SetLastError after creating the handle. |
16 ::SetLastError(magic_error); | 18 ::SetLastError(magic_error); |
17 base::win::ScopedHandle handle_holder(handle); | 19 base::win::ScopedHandle handle_holder(handle); |
18 EXPECT_EQ(magic_error, ::GetLastError()); | 20 EXPECT_EQ(magic_error, ::GetLastError()); |
19 | 21 |
20 // Create a new handle and then set LastError again. | 22 // Create a new handle and then set LastError again. |
21 handle = ::CreateMutex(nullptr, FALSE, nullptr); | 23 handle = ::CreateMutex(nullptr, FALSE, nullptr); |
22 ::SetLastError(magic_error); | 24 ::SetLastError(magic_error); |
23 handle_holder.Set(handle); | 25 handle_holder.Set(handle); |
24 EXPECT_EQ(magic_error, ::GetLastError()); | 26 EXPECT_EQ(magic_error, ::GetLastError()); |
25 | 27 |
26 // Create a new handle and then set LastError again. | 28 // Create a new handle and then set LastError again. |
27 handle = ::CreateMutex(nullptr, FALSE, nullptr); | 29 handle = ::CreateMutex(nullptr, FALSE, nullptr); |
28 base::win::ScopedHandle handle_source(handle); | 30 base::win::ScopedHandle handle_source(handle); |
29 ::SetLastError(magic_error); | 31 ::SetLastError(magic_error); |
30 handle_holder = handle_source.Pass(); | 32 handle_holder = std::move(handle_source); |
31 EXPECT_EQ(magic_error, ::GetLastError()); | 33 EXPECT_EQ(magic_error, ::GetLastError()); |
32 } | 34 } |
OLD | NEW |