Completed unit testing and fixes for UtilApiSet.h

pull/83/head
David Hall 2019-07-20 10:29:06 -06:00
parent 0d042532a3
commit 57b2c23c1c
3 changed files with 76 additions and 11 deletions

View File

@ -6,10 +6,12 @@ namespace Vanara.PInvoke
public static partial class Kernel32
{
/// <summary>
/// Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to its caller until the
/// sound finishes.
/// Generates simple tones on the speaker. The function is synchronous; it performs an alertable wait and does not return control to
/// its caller until the sound finishes.
/// </summary>
/// <param name="dwFreq">The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).</param>
/// <param name="dwFreq">
/// The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).
/// </param>
/// <param name="dwDuration">The duration of the sound, in milliseconds.</param>
/// <returns>
/// <para>If the function succeeds, the return value is nonzero.</para>
@ -31,8 +33,8 @@ namespace Vanara.PInvoke
/// <summary>
/// <para>
/// [Some information relates to pre-released product which may be substantially modified before it's commercially released. Microsoft makes no
/// warranties, express or implied, with respect to the information provided here.]
/// [Some information relates to pre-released product which may be substantially modified before it's commercially released.
/// Microsoft makes no warranties, express or implied, with respect to the information provided here.]
/// </para>
/// <para>Decodes a pointer in a specified process that was previously encoded with <c>EncodePointer</c> or <c>EncodeRemotePointer</c>.</para>
/// </summary>
@ -41,7 +43,7 @@ namespace Vanara.PInvoke
/// <param name="DecodedPtr">The decoded pointer.</param>
/// <returns>Returns S_OK if successful, otherwise the function failed.</returns>
// HRESULT WINAPI DecodeRemotePointer( _In_ HANDLE ProcessHandle, _In_opt_ PVOID Ptr, _Out_ PVOID * DecodedPtr ); https://msdn.microsoft.com/en-us/library/dn877133(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true)]
[PInvokeData("UtilApiSet.h", MSDNShortId = "dn877133")]
public static extern HRESULT DecodeRemotePointer(HPROCESS ProcessHandle, IntPtr Ptr, out IntPtr DecodedPtr);
@ -63,22 +65,26 @@ namespace Vanara.PInvoke
/// <summary>
/// <para>
/// [Some information relates to pre-released product which may be substantially modified before it's commercially released. Microsoft makes no
/// warranties, express or implied, with respect to the information provided here.]
/// [Some information relates to pre-released product which may be substantially modified before it's commercially released.
/// Microsoft makes no warranties, express or implied, with respect to the information provided here.]
/// </para>
/// <para>
/// Encodes the specified pointer of the specified process. Encoded pointers can be used to provide another layer of protection for
/// pointer values.
/// </para>
/// <para>Encodes the specified pointer of the specified process. Encoded pointers can be used to provide another layer of protection for pointer values.</para>
/// </summary>
/// <param name="ProcessHandle">Handle to the remote process that owns the pointer.</param>
/// <param name="Ptr">The pointer to be encoded.</param>
/// <param name="EncodedPtr">The encoded pointer.</param>
/// <returns>Returns S_OK if successful, otherwise the function failed.</returns>
// HRESULT WINAPI EncodeRemotePointer( _In_ HANDLE ProcessHandle, _In_opt_ PVOID Ptr, _Out_ PVOID * EncodedPtr ); https://msdn.microsoft.com/en-us/library/dn877135(v=vs.85).aspx
[DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)]
[DllImport(Lib.KernelBase, SetLastError = false, ExactSpelling = true)]
[PInvokeData("UtilApiSet.h", MSDNShortId = "dn877135")]
public static extern HRESULT EncodeRemotePointer(HPROCESS ProcessHandle, IntPtr Ptr, out IntPtr EncodedPtr);
/// <summary>
/// Encodes the specified pointer with a system-specific value. Encoded pointers can be used to provide another layer of protection for pointer values.
/// Encodes the specified pointer with a system-specific value. Encoded pointers can be used to provide another layer of protection
/// for pointer values.
/// </summary>
/// <param name="Ptr">The system pointer to be encoded.</param>
/// <returns>The function returns the encoded pointer.</returns>

View File

@ -48,6 +48,7 @@
<Compile Include="AppModelTests.cs" />
<Compile Include="InterlockedApiTests.cs" />
<Compile Include="InteropServices\SafeLocalHandleTests.cs" />
<Compile Include="UtilApiSetTests.cs" />
<Compile Include="TimeZoneApiTests.cs" />
<Compile Include="ThreadPoolLegacyApiSetTests.cs" />
<Compile Include="ThreadPoolApiSetTests.cs" />

View File

@ -0,0 +1,58 @@
using NUnit.Framework;
using System;
using Vanara.InteropServices;
using static Vanara.PInvoke.Kernel32;
namespace Vanara.PInvoke.Tests
{
[TestFixture]
public class UtilApiSetTests
{
[Test]
public void BeepTest()
{
Assert.That(Beep(523, 500), Is.True);
Assert.That(Beep(587, 500), Is.True);
Assert.That(Beep(659, 500), Is.True);
}
[Test]
public void EncodePointerTest()
{
Assert.That(() =>
{
var pint = new PinnedObject(123);
var eptr = EncodePointer(pint);
Assert.That(eptr, Is.Not.EqualTo(IntPtr.Zero));
var dptr = DecodePointer(eptr);
Assert.That((IntPtr)pint, Is.EqualTo(dptr));
}, Throws.Nothing);
}
[Test]
public void EncodeRemotePointerTest()
{
Assert.That(() =>
{
var pint = new PinnedObject(123);
Assert.That(EncodeRemotePointer(GetCurrentProcess(), pint, out var eptr), ResultIs.Successful);
Assert.That(eptr, Is.Not.EqualTo(IntPtr.Zero));
Assert.That(DecodeRemotePointer(GetCurrentProcess(), eptr, out var dptr), ResultIs.Successful);
Assert.That((IntPtr)pint, Is.EqualTo(dptr));
}, Throws.Nothing);
}
[Test]
public void EncodeSystemPointerTest()
{
Assert.That(() =>
{
var pint = new PinnedObject(123);
var eptr = EncodeSystemPointer(pint);
Assert.That(eptr, Is.Not.EqualTo(IntPtr.Zero));
var dptr = DecodeSystemPointer(eptr);
Assert.That((IntPtr)pint, Is.EqualTo(dptr));
}, Throws.Nothing);
}
}
}