public void Ctor_NullPointerIsZero() { //Act using (var target = new SafeComMemoryHandle(IntPtr.Zero)) { //Assert target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }; }
public void StringToUnicode_NullStringWorks() { //Act using (var target = SafeComMemoryHandle.StringToUnicode(null)) { //Assert target.IsInvalid.Should().BeTrue(); target.Pointer.Should().BeZero(); }; }
public void SecureStringToUnicode_ZeroesMemoryWhenClosed() { var str = CreateSecureString("Hello"); var target = SafeComMemoryHandle.SecureStringToUnicode(str); //Act target.Close(); //Assert - All we can do is verify it doesn't blow up target.IsClosed.Should().BeTrue(); }
public void Dispose_NullPointerWorks() { //Act var target = new SafeComMemoryHandle(); target.Dispose(); //Assert - No real way to confirm the memory was released target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }
public void Ctor_ValidPointerIsSet() { var expected = AllocateMemory(200); //Act using (var target = new SafeComMemoryHandle(expected)) { //Assert target.Pointer.Should().Be(expected); target.IsInvalid.Should().BeFalse(); }; }
public void StringToUnicode_ValidStringWorks() { string str = "Hello"; //Act using (var target = SafeComMemoryHandle.StringToUnicode(str)) { //Assert target.IsInvalid.Should().BeFalse(); AssertMemory(target.Pointer, Encoding.Unicode.GetBytes("Hello")); }; }
public void SecureStringToAnsi_ValidStringWorks() { var str = CreateSecureString("Hello"); //Act using (var target = SafeComMemoryHandle.SecureStringToAnsi(str)) { //Assert target.IsInvalid.Should().BeFalse(); AssertMemory(target.Pointer, Encoding.ASCII.GetBytes("Hello")); }; }
public void Attach_NullPointerWorks() { //Act using (var target = new SafeComMemoryHandle()) { target.Attach(IntPtr.Zero); //Assert target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }; }
public void Detach_NullPointerWorks() { //Act using (var target = new SafeComMemoryHandle()) { var actual = target.Detach(); //Assert actual.Should().BeZero(); target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }; }
public void Allocate_ValidSizeWorks() { //Act using (var target = SafeComMemoryHandle.Allocate(256)) { var actual = target.Pointer; var written = WriteMemory(target.Pointer, 256); //Assert target.IsInvalid.Should().BeFalse(); AssertMemory(target.Pointer, written); }; }
public void Dispose_AttachedPointerWorks() { var ptr = AllocateMemory(10); //Act var target = new SafeComMemoryHandle(); target.Attach(ptr); target.Dispose(); //Assert - doesn't really confirm the memory was released target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }
public void Attach_ValidPointerWorks() { var expected = AllocateMemory(100); //Act using (var target = new SafeComMemoryHandle()) { target.Attach(expected); //Assert target.Pointer.Should().Be(expected); target.IsInvalid.Should().BeFalse(); }; }
public void Detach_ValidPointerWorks() { var ptr = AllocateMemory(50); try { //Act using (var target = new SafeComMemoryHandle(ptr)) { var actual = target.Detach(); //Assert actual.Should().Be(ptr); target.Pointer.Should().BeZero(); target.IsInvalid.Should().BeTrue(); }; } finally { FreeMemory(ptr); }; }
public void Allocate_InvalidSizeFails() { Action action = () => SafeComMemoryHandle.Allocate(-5); action.ShouldThrowArgumentOutOfRangeException(); }