コード例 #1
0
        public void Attach_NullPointerWorks()
        {
            //Act
            using (var target = new SafeHGlobalHandle())
            {
                target.Attach(IntPtr.Zero);

                //Assert
                target.Pointer.Should().BeZero();
                target.IsInvalid.Should().BeTrue();
            };
        }
コード例 #2
0
        public void Dispose_AttachedPointerWorks()
        {
            var ptr = AllocateMemory(10);

            //Act
            var target = new SafeHGlobalHandle();

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

            //Assert - doesn't really confirm the memory was released
            target.Pointer.Should().BeZero();
            target.IsInvalid.Should().BeTrue();
        }
コード例 #3
0
        public void Attach_ValidPointerWorks()
        {
            var expected = AllocateMemory(100);

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

                //Assert
                target.Pointer.Should().Be(expected);
                target.IsInvalid.Should().BeFalse();
            };
        }