Beispiel #1
0
        public void Attach_ValidPointerWorks()
        {
            var expected = AllocateMemory(10);

            //Act
            using (var target = new SafeBStrHandle())
            {
                target.Attach(expected);

                //Assert
                target.Pointer.Should().Be(expected);
                target.IsInvalid.Should().BeFalse();
            };
        }
Beispiel #2
0
        public void Dispose_AttachedPointerWorks()
        {
            var ptr = AllocateMemory(10);

            //Act
            var target = new SafeBStrHandle();

            target.Attach(ptr);
            target.Dispose();

            //Assert - doesn't really confirm the memory was released
            target.Pointer.Should().BeZero();
            target.IsInvalid.Should().BeTrue();
        }
Beispiel #3
0
        public void Attach_NullPointerWorks()
        {
            var original = AllocateMemory(10);

            //Act
            using (var target = new SafeBStrHandle(original))
            {
                target.Attach(IntPtr.Zero);

                //Assert
                target.Pointer.Should().BeZero();
                target.IsInvalid.Should().BeTrue();
            };
        }
Beispiel #4
0
        public void Attach_ZeroFreeMemory()
        {
            var ptr      = Marshal.StringToBSTR("Hello");
            var expected = new byte[10];
            var target   = new SafeBStrHandle();

            //Act
            target.Attach(ptr, true);
            target.Close();

            var actual = new byte[10];

            Marshal.Copy(ptr, actual, 0, actual.Length);

            //Assert
            actual.Should().ContainInOrder(expected);
        }