 Chromium Code Reviews
 Chromium Code Reviews Issue 1320673016:
  Get GenericScopedHandle::Set to preserve LastError code  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1320673016:
  Get GenericScopedHandle::Set to preserve LastError code  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: base/win/scoped_handle_unittest.cc | 
| diff --git a/base/win/scoped_handle_unittest.cc b/base/win/scoped_handle_unittest.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..b683021f68191e0ad2b0ecf396050a63a914f375 | 
| --- /dev/null | 
| +++ b/base/win/scoped_handle_unittest.cc | 
| @@ -0,0 +1,38 @@ | 
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "base/win/scoped_handle.h" | 
| + | 
| +#include "testing/gtest/include/gtest/gtest.h" | 
| + | 
| +namespace base { | 
| +namespace win { | 
| 
rvargas (doing something else)
2015/09/10 22:42:02
nit: Could you remove these namespaces?
long reas
 
brucedawson
2015/09/10 23:21:46
We should probably do a code-cleanup pass at some
 | 
| + | 
| +TEST(ScopedHandleTest, ScopedHandle) { | 
| + // Any illegal error code will do. We just need to test that it is preserved | 
| + // by ScopedHandle to avoid bug 528394. | 
| + const DWORD magic_error = 0x12345678; | 
| + | 
| + HANDLE handle = CreateMutex(nullptr, FALSE, nullptr); | 
| 
rvargas (doing something else)
2015/09/10 22:42:02
nit: related to the previous one... use ::CreateMu
 
brucedawson
2015/09/10 23:21:46
Done, for CreateMutex(), SetLastError(), and GetLa
 | 
| + // Call SetLastError after creating the handle. | 
| + SetLastError(magic_error); | 
| + ScopedHandle handle_holder(handle); | 
| + EXPECT_EQ(magic_error, GetLastError()); | 
| + | 
| + // Create a new handle and then set LastError again. | 
| + handle = CreateMutex(nullptr, FALSE, nullptr); | 
| + SetLastError(magic_error); | 
| + handle_holder.Set(handle); | 
| + EXPECT_EQ(magic_error, GetLastError()); | 
| + | 
| + // Create a new handle and then set LastError again. | 
| + handle = CreateMutex(nullptr, FALSE, nullptr); | 
| + ScopedHandle handle_source(handle); | 
| + SetLastError(magic_error); | 
| + handle_holder = std::move(handle_source); | 
| + EXPECT_EQ(magic_error, GetLastError()); | 
| +} | 
| + | 
| +} // namespace win | 
| +} // namespace base |