update wil to 0b2d6c2d822bb301e7558a14ee66d567c14f5dc7

This commit is contained in:
Shawn Hoffman 2023-02-22 13:12:56 -08:00
commit 69c335ca8c
66 changed files with 14776 additions and 2507 deletions

View file

@ -9,6 +9,7 @@
#include <memory>
#include <roapi.h>
#include <winstring.h>
#include <WinUser.h>
#include <wil/resource.h>
#include <wrl/implements.h>
@ -59,6 +60,14 @@ TEST_CASE("ResourceTests::TestLastErrorContext", "[resource][last_error_context]
SetLastError(1);
}
REQUIRE(GetLastError() == 1);
// The value in the context is unimpacted by other things changing the last error
{
SetLastError(42);
auto error42 = wil::last_error_context();
SetLastError(1);
REQUIRE(error42.value() == 42);
}
}
TEST_CASE("ResourceTests::TestScopeExit", "[resource][scope_exit]")
@ -267,6 +276,40 @@ void UniqueProcessInfo()
}
#endif
// Compilation only test...
#ifdef WIL_ENABLE_EXCEPTIONS
void NoexceptConstructibleTest()
{
using BaseStorage = wil::details::unique_storage<wil::details::handle_resource_policy>;
struct ThrowingConstructor : BaseStorage
{
ThrowingConstructor() = default;
explicit ThrowingConstructor(HANDLE) __WI_NOEXCEPT_(false) {}
};
struct ProtectedConstructor : BaseStorage
{
protected:
ProtectedConstructor() = default;
explicit ProtectedConstructor(HANDLE) WI_NOEXCEPT {}
};
// wil::unique_handle is one of the many types which are expected to be noexcept
// constructible since they don't perform any "advanced" initialization.
static_assert(wistd::is_nothrow_default_constructible_v<wil::unique_handle>, "wil::unique_any_t should always be nothrow default constructible");
static_assert(wistd::is_nothrow_constructible_v<wil::unique_handle, HANDLE>, "wil::unique_any_t should be noexcept if the storage is");
// The inverse: A throwing storage constructor.
static_assert(wistd::is_nothrow_default_constructible_v<wil::unique_any_t<ThrowingConstructor>>, "wil::unique_any_t should always be nothrow default constructible");
static_assert(!wistd::is_nothrow_constructible_v<wil::unique_any_t<ThrowingConstructor>, HANDLE>, "wil::unique_any_t shouldn't be noexcept if the storage isn't");
// With a protected constructor wil::unique_any_t will be unable to correctly
// "forward" the noexcept attribute, but the code should still compile.
wil::unique_any_t<ProtectedConstructor> p{ INVALID_HANDLE_VALUE };
}
#endif
struct FakeComInterface
{
void AddRef()
@ -732,4 +775,90 @@ TEST_CASE("DefaultTemplateParamCompiles", "[resource]")
wil::unique_midl_ptr<> g;
wil::unique_cotaskmem_ptr<> h;
wil::unique_mapview_ptr<> i;
}
TEST_CASE("UniqueInvokeCleanupMembers", "[resource]")
{
// Case 1 - unique_ptr<> for a T* that has a "destroy" member
struct ThingWithDestroy
{
bool destroyed = false;
void destroy() { destroyed = true; };
};
ThingWithDestroy toDestroy;
wil::unique_any<ThingWithDestroy*, decltype(&ThingWithDestroy::destroy), &ThingWithDestroy::destroy> p(&toDestroy);
p.reset();
REQUIRE(!p);
REQUIRE(toDestroy.destroyed);
// Case 2 - unique_struct calling a member, like above
struct ThingToDestroy2
{
bool* destroyed;
void destroy() { *destroyed = true; };
};
bool structDestroyed = false;
{
wil::unique_struct<ThingToDestroy2, decltype(&ThingToDestroy2::destroy), &ThingToDestroy2::destroy> other;
other.destroyed = &structDestroyed;
REQUIRE(!structDestroyed);
}
REQUIRE(structDestroyed);
}
struct ITokenTester : IUnknown
{
virtual void DirectClose(DWORD_PTR token) = 0;
};
struct TokenTester : ITokenTester
{
IFACEMETHOD_(ULONG, AddRef)() override { return 2; }
IFACEMETHOD_(ULONG, Release)() override { return 1; }
IFACEMETHOD(QueryInterface)(REFIID, void**) { return E_NOINTERFACE; }
void DirectClose(DWORD_PTR token) override {
m_closed = (token == m_closeToken);
}
bool m_closed = false;
DWORD_PTR m_closeToken;
};
void MyTokenTesterCloser(ITokenTester* tt, DWORD_PTR token)
{
tt->DirectClose(token);
}
TEST_CASE("ComTokenCloser", "[resource]")
{
using token_tester_t = wil::unique_com_token<ITokenTester, DWORD_PTR, decltype(MyTokenTesterCloser), &MyTokenTesterCloser>;
TokenTester tt;
tt.m_closeToken = 4;
{
token_tester_t tmp{ &tt, 4 };
}
REQUIRE(tt.m_closed);
}
TEST_CASE("ComTokenDirectCloser", "[resource]")
{
using token_tester_t = wil::unique_com_token<ITokenTester, DWORD_PTR, decltype(&ITokenTester::DirectClose), &ITokenTester::DirectClose>;
TokenTester tt;
tt.m_closeToken = 4;
{
token_tester_t tmp{ &tt, 4 };
}
REQUIRE(tt.m_closed);
}
TEST_CASE("UniqueCloseClipboardCall", "[resource]")
{
#if defined(__WIL__WINUSER_) && !defined(NOCLIPBOARD)
if (auto clip = wil::open_clipboard(nullptr))
{
REQUIRE(::EmptyClipboard());
}
#endif
}