mirror of https://github.com/dahall/Vanara.git
Updated tests for #122
parent
db2ab70ff1
commit
6ac3605005
|
@ -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<User32.POWERBROADCAST_SETTING>();
|
||||
if (pbSetting.DataLength == Marshal.SizeOf(typeof(uint)))
|
||||
timeOut = BitConverter.ToUInt32(pbSetting.Data, 0);
|
||||
}
|
||||
evt.Set();
|
||||
return Win32Error.ERROR_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,14 @@
|
|||
<Project>{a5e519e9-feba-4fe3-93a5-b8269bef72f4}</Project>
|
||||
<Name>Vanara.PInvoke.Shared</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\PInvoke\User32\Vanara.PInvoke.User32.csproj">
|
||||
<Project>{a6771907-addc-49fc-8444-a97aa65e77e2}</Project>
|
||||
<Name>Vanara.PInvoke.User32</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\CSharpRunner\Shared.csproj">
|
||||
<Project>{a96cff10-0967-429a-8700-4a86c97c5603}</Project>
|
||||
<Name>Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NUnit">
|
||||
|
|
Loading…
Reference in New Issue