diff --git a/UnitTests/PInvoke/PowrProf/PowrProf.cs b/UnitTests/PInvoke/PowrProf/PowrProf.cs index 5d608890..d966f2cf 100644 --- a/UnitTests/PInvoke/PowrProf/PowrProf.cs +++ b/UnitTests/PInvoke/PowrProf/PowrProf.cs @@ -4,7 +4,9 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Threading.Tasks; +using Vanara.Extensions; using static Vanara.PInvoke.PowrProf; namespace Vanara.PInvoke.Tests @@ -54,5 +56,29 @@ namespace Vanara.PInvoke.Tests attr = PowerReadSettingAttributes(GUID_SYSTEM_BUTTON_SUBGROUP, default); TestContext.WriteLine($"GUID_SYSTEM_BUTTON_SUBGROUP={attr}"); } + + [Test] + public void PowerSettingRegisterNotificationTest() + { + uint timeOut = 0; + var evt = new AutoResetEvent(false); + Assert.That(PowerSettingRegisterNotification(GUID_VIDEO_POWERDOWN_TIMEOUT, DEVICE_NOTIFY.DEVICE_NOTIFY_CALLBACK, new DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS { Callback = PowerSettingFunc }, out var powerNotification), ResultIs.Successful); + evt.WaitOne(1000); + Assert.That(PowerSettingUnregisterNotification(powerNotification), ResultIs.Successful); + Assert.That(timeOut, Is.Not.Zero); + TestContext.Write($"timeout={timeOut}"); + + Win32Error PowerSettingFunc(IntPtr Context, uint Type, IntPtr Setting) + { + if (Type == (uint)User32.PowerBroadcastType.PBT_POWERSETTINGCHANGE && Setting != IntPtr.Zero) + { + var pbSetting = Setting.ToStructure(); + if (pbSetting.DataLength == Marshal.SizeOf(typeof(uint))) + timeOut = BitConverter.ToUInt32(pbSetting.Data, 0); + } + evt.Set(); + return Win32Error.ERROR_SUCCESS; + } + } } } \ No newline at end of file diff --git a/UnitTests/PInvoke/PowrProf/PowrProf.csproj b/UnitTests/PInvoke/PowrProf/PowrProf.csproj index 6c74ebcc..0539328d 100644 --- a/UnitTests/PInvoke/PowrProf/PowrProf.csproj +++ b/UnitTests/PInvoke/PowrProf/PowrProf.csproj @@ -47,6 +47,14 @@ {a5e519e9-feba-4fe3-93a5-b8269bef72f4} Vanara.PInvoke.Shared + + {a6771907-addc-49fc-8444-a97aa65e77e2} + Vanara.PInvoke.User32 + + + {a96cff10-0967-429a-8700-4a86c97c5603} + Shared +