Пример #1
0
        public void LeakDetectorWorks()
        {
            var allocator = new LeakDetectorWrapperAllocator(new HGlobalAllocator());
            var ptr1      = allocator.Allocate((IntPtr)4);
            var ptr2      = allocator.Allocate((IntPtr)8);
            var ptr3      = allocator.Allocate((IntPtr)16);

            allocator.Deallocate(ptr2);
            var leaks = allocator.QueryAllocations();

            Assert.Equal(2u, leaks.Count);
            Assert.Equal(20ul, leaks.Size);
            allocator.Deallocate(ptr1);
            allocator.Deallocate(ptr3);
            Assert.Throws <InvalidOperationException>(() => allocator.Deallocate(ptr1));
        }
Пример #2
0
        public void LeakDetectorDisposesLeaks()
        {
            var mainAllocator = new LeakDetectorWrapperAllocator(new HGlobalAllocator());
            var allocator     = new LeakDetectorWrapperAllocator(mainAllocator);

            allocator.Allocate((IntPtr)4);
            allocator.Dispose();
            Assert.Equal(0u, mainAllocator.QueryAllocations().Count);
        }