mirror of https://github.com/dahall/Vanara.git
parent
0b4032473b
commit
88ad038496
|
@ -1,4 +1,5 @@
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using NUnit.Framework.Constraints;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -9,10 +10,11 @@ namespace Vanara.PInvoke.Tests
|
||||||
public class HRESULTTests
|
public class HRESULTTests
|
||||||
{
|
{
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, 0x80070005, ExpectedResult = 0)]
|
[TestCase(HRESULT.E_ACCESSDENIED, 0x80070005, ExpectedResult = 0)]
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, 0, ExpectedResult = 1)]
|
[TestCase(HRESULT.E_ACCESSDENIED, 0, ExpectedResult = -1)]
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, 5U, ExpectedResult = 1)]
|
[TestCase(HRESULT.E_ACCESSDENIED, 5U, ExpectedResult = -1)]
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, HRESULT.E_INVALIDARG, ExpectedResult = -1)]
|
[TestCase(HRESULT.E_ACCESSDENIED, HRESULT.E_INVALIDARG, ExpectedResult = -1)]
|
||||||
[TestCase(HRESULT.E_INVALIDARG, HRESULT.E_ACCESSDENIED, ExpectedResult = 1)]
|
[TestCase(HRESULT.E_INVALIDARG, HRESULT.E_ACCESSDENIED, ExpectedResult = 1)]
|
||||||
|
[TestCase(HRESULT.S_OK, HRESULT.E_ACCESSDENIED, ExpectedResult = 1)]
|
||||||
public int CompareToTest(int c, object obj) => new HRESULT(c).CompareTo(obj);
|
public int CompareToTest(int c, object obj) => new HRESULT(c).CompareTo(obj);
|
||||||
|
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, HRESULT.E_INVALIDARG, ExpectedResult = -1)]
|
[TestCase(HRESULT.E_ACCESSDENIED, HRESULT.E_INVALIDARG, ExpectedResult = -1)]
|
||||||
|
@ -78,15 +80,15 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(() => c.ToByte(f), Throws.Exception);
|
Assert.That(() => c.ToByte(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToInt16(f), Throws.Exception);
|
Assert.That(() => c.ToInt16(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToUInt16(f), Throws.Exception);
|
Assert.That(() => c.ToUInt16(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToInt32(f), Throws.Exception);
|
Assert.That(c.ToUInt32(f), Is.EqualTo(unchecked((uint)HRESULT.E_ACCESSDENIED)));
|
||||||
Assert.That(c.ToUInt32(f), Is.EqualTo(cv.ToUInt32(f)));
|
Assert.That(c.ToInt32(f), Is.EqualTo(cv.ToInt32(f)));
|
||||||
Assert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
|
Assert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
|
||||||
Assert.That(c.ToUInt64(f), Is.EqualTo(cv.ToUInt64(f)));
|
Assert.That(c.ToUInt64(f), Is.EqualTo((ulong)unchecked((uint)HRESULT.E_ACCESSDENIED)));
|
||||||
Assert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
|
Assert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
|
||||||
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
||||||
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
||||||
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
||||||
Assert.That(c.ToString(f), Is.EqualTo("E_ACCESSDENIED"));
|
Assert.That(c.ToString(f), Does.StartWith("E_ACCESSDENIED"));
|
||||||
Assert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
|
Assert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,12 +122,14 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(() => HRESULT.ThrowIfFailed(0), Throws.Nothing);
|
Assert.That(() => HRESULT.ThrowIfFailed(0), Throws.Nothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(HRESULT.E_INVALIDARG, ExpectedResult = "E_INVALIDARG")]
|
[TestCase(HRESULT.E_INVALIDARG, "E_INVALIDARG")]
|
||||||
[TestCase(HRESULT.E_ACCESSDENIED, ExpectedResult = "E_ACCESSDENIED")]
|
[TestCase(HRESULT.E_ACCESSDENIED, "E_ACCESSDENIED")]
|
||||||
[TestCase(0x80070003, ExpectedResult = "HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)")]
|
public void ToStringTest(int c, string res) => Assert.That(new HRESULT(c).ToString(), Does.StartWith(res));
|
||||||
[TestCase(0x80990003, ExpectedResult = "0x80990003")]
|
|
||||||
[TestCase(0x80079254, ExpectedResult = "0x80079254")]
|
[TestCase(0x80070003, "HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)")]
|
||||||
public string ToStringTest(int c) => new HRESULT(c).ToString();
|
[TestCase(0x80990003, "0x80990003")]
|
||||||
|
[TestCase(0x80079254, "0x80079254")]
|
||||||
|
public void ToStringTestU(uint c, string res) => Assert.That(new HRESULT(c).ToString(), Does.StartWith(res));
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TypeConverterTest()
|
public void TypeConverterTest()
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace Vanara.PInvoke.Tests
|
||||||
nts = new NTStatus(0);
|
nts = new NTStatus(0);
|
||||||
Assert.That((int)nts, Is.Zero);
|
Assert.That((int)nts, Is.Zero);
|
||||||
nts = new NTStatus(NTStatus.STATUS_CANCELLED);
|
nts = new NTStatus(NTStatus.STATUS_CANCELLED);
|
||||||
Assert.That((int)nts, Is.EqualTo(0xC0000120));
|
Assert.That((uint)nts, Is.EqualTo(0xC0000120));
|
||||||
Assert.That(nts.Failed);
|
Assert.That(nts.Failed);
|
||||||
Assert.That(nts.CustomerDefined, Is.False);
|
Assert.That(nts.CustomerDefined, Is.False);
|
||||||
Assert.That(nts.Code, Is.EqualTo(0x120));
|
Assert.That(nts.Code, Is.EqualTo(0x120));
|
||||||
|
@ -29,8 +29,8 @@ namespace Vanara.PInvoke.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0xC0000022, ExpectedResult = 0)]
|
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0xC0000022, ExpectedResult = 0)]
|
||||||
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0, ExpectedResult = 1)]
|
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0, ExpectedResult = -1)]
|
||||||
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0x22U, ExpectedResult = 1)]
|
[TestCase(NTStatus.STATUS_ACCESS_DENIED, 0x22U, ExpectedResult = -1)]
|
||||||
[TestCase(NTStatus.STATUS_ACCESS_DENIED, NTStatus.STATUS_ACPI_INVALID_ARGUMENT, ExpectedResult = -1)]
|
[TestCase(NTStatus.STATUS_ACCESS_DENIED, NTStatus.STATUS_ACPI_INVALID_ARGUMENT, ExpectedResult = -1)]
|
||||||
[TestCase(NTStatus.STATUS_ACPI_INVALID_ARGUMENT, NTStatus.STATUS_ACCESS_DENIED, ExpectedResult = 1)]
|
[TestCase(NTStatus.STATUS_ACPI_INVALID_ARGUMENT, NTStatus.STATUS_ACCESS_DENIED, ExpectedResult = 1)]
|
||||||
public int CompareToTest(int c, object obj) => new NTStatus(c).CompareTo(obj);
|
public int CompareToTest(int c, object obj) => new NTStatus(c).CompareTo(obj);
|
||||||
|
@ -87,16 +87,16 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(() => c.ToByte(f), Throws.Exception);
|
Assert.That(() => c.ToByte(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToInt16(f), Throws.Exception);
|
Assert.That(() => c.ToInt16(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToUInt16(f), Throws.Exception);
|
Assert.That(() => c.ToUInt16(f), Throws.Exception);
|
||||||
Assert.That(() => c.ToInt32(f), Throws.Exception);
|
Assert.That(c.ToInt32(f), Is.EqualTo(cv.ToInt32(f)));
|
||||||
Assert.That(c.ToUInt32(f), Is.EqualTo(cv.ToUInt32(f)));
|
Assert.That(c.ToUInt32(f), Is.EqualTo((uint)nts));
|
||||||
Assert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
|
Assert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
|
||||||
Assert.That(c.ToUInt64(f), Is.EqualTo(cv.ToUInt64(f)));
|
Assert.That(c.ToUInt64(f), Is.EqualTo((ulong)(uint)nts));
|
||||||
Assert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
|
Assert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
|
||||||
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
||||||
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
||||||
Assert.That(c.ToBoolean(f), Is.EqualTo(nts.Succeeded));
|
Assert.That(c.ToBoolean(f), Is.EqualTo(nts.Succeeded));
|
||||||
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
||||||
Assert.That(c.ToString(f), Is.EqualTo("STATUS_ACCESS_DENIED"));
|
Assert.That(c.ToString(f), Does.StartWith("STATUS_ACCESS_DENIED"));
|
||||||
Assert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
|
Assert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,11 +130,11 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(() => NTStatus.ThrowIfFailed(0), Throws.Nothing);
|
Assert.That(() => NTStatus.ThrowIfFailed(0), Throws.Nothing);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(NTStatus.STATUS_ACPI_INVALID_ARGUMENT, ExpectedResult = "STATUS_ACPI_INVALID_ARGUMENT")]
|
[TestCase(NTStatus.STATUS_ACPI_INVALID_ARGUMENT, "STATUS_ACPI_INVALID_ARGUMENT")]
|
||||||
[TestCase(NTStatus.STATUS_ACCESS_DENIED, ExpectedResult = "STATUS_ACCESS_DENIED")]
|
[TestCase(NTStatus.STATUS_ACCESS_DENIED, "STATUS_ACCESS_DENIED")]
|
||||||
[TestCase(0xC0000022, ExpectedResult = "STATUS_ACCESS_DENIED")]
|
[TestCase(unchecked((int)0xC0000022), "STATUS_ACCESS_DENIED")]
|
||||||
[TestCase(0x80990003, ExpectedResult = "0x80990003")]
|
[TestCase(unchecked((int)0x80990003), "0x80990003")]
|
||||||
[TestCase(0x80079254, ExpectedResult = "0x80079254")]
|
[TestCase(unchecked((int)0x80079254), "0x80079254")]
|
||||||
public string ToStringTest(int c) => new NTStatus(c).ToString();
|
public void ToStringTest(int c, string val) => Assert.That(new NTStatus(c).ToString(), Does.StartWith(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -74,7 +74,7 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
Assert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
|
||||||
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
Assert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
|
||||||
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
Assert.That(() => c.ToDateTime(f), Throws.Exception);
|
||||||
Assert.That(c.ToString(f), Is.EqualTo("ERROR_ACCESS_DENIED"));
|
Assert.That(c.ToString(f), Does.StartWith("ERROR_ACCESS_DENIED"));
|
||||||
Assert.That(c.ToType(typeof(uint), f), Is.EqualTo(cv.ToType(typeof(uint), f)));
|
Assert.That(c.ToType(typeof(uint), f), Is.EqualTo(cv.ToType(typeof(uint), f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,11 +117,11 @@ namespace Vanara.PInvoke.Tests
|
||||||
Assert.That(() => Win32Error.ThrowLastError(), Throws.Exception);
|
Assert.That(() => Win32Error.ThrowLastError(), Throws.Exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(Win32Error.ERROR_INVALID_PARAMETER, ExpectedResult = "ERROR_INVALID_PARAMETER")]
|
[TestCase(Win32Error.ERROR_INVALID_PARAMETER, "ERROR_INVALID_PARAMETER")]
|
||||||
[TestCase(Win32Error.ERROR_ACCESS_DENIED, ExpectedResult = "ERROR_ACCESS_DENIED")]
|
[TestCase(Win32Error.ERROR_ACCESS_DENIED, "ERROR_ACCESS_DENIED")]
|
||||||
[TestCase(0x00000003, ExpectedResult = "ERROR_PATH_NOT_FOUND")]
|
[TestCase(0x00000003U, "ERROR_PATH_NOT_FOUND")]
|
||||||
[TestCase(0x00990003, ExpectedResult = "0x00990003")]
|
[TestCase(0x00990003U, "0x00990003")]
|
||||||
public string ToStringTest(uint c) => new Win32Error(c).ToString();
|
public void ToStringTest(uint c, string val) => Assert.That(new Win32Error(c).ToString(), Does.StartWith(val));
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TypeConverterTest()
|
public void TypeConverterTest()
|
||||||
|
|
Loading…
Reference in New Issue