File tree Expand file tree Collapse file tree
tests/ImageSharp.Tests/Memory/Allocators Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -418,4 +418,28 @@ static void RunTest()
418418 _ = MemoryAllocator . Create ( ) ;
419419 }
420420 }
421+
422+ [ Fact ]
423+ public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException ( )
424+ {
425+ MemoryAllocator allocator = MemoryAllocator . Create ( new MemoryAllocatorOptions ( )
426+ {
427+ AllocationLimitMegabytes = 4
428+ } ) ;
429+ const int oneMb = 1 << 20 ;
430+ allocator . Allocate < byte > ( 4 * oneMb ) . Dispose ( ) ; // Should work
431+ Assert . Throws < InvalidMemoryOperationException > ( ( ) => allocator . Allocate < byte > ( 5 * oneMb ) ) ;
432+ }
433+
434+ [ Fact ]
435+ public void AllocateGroup_OverLimit_ThrowsInvalidMemoryOperationException ( )
436+ {
437+ MemoryAllocator allocator = MemoryAllocator . Create ( new MemoryAllocatorOptions ( )
438+ {
439+ AllocationLimitMegabytes = 4
440+ } ) ;
441+ const int oneMb = 1 << 20 ;
442+ allocator . AllocateGroup < byte > ( 4 * oneMb , 1024 ) . Dispose ( ) ; // Should work
443+ Assert . Throws < InvalidMemoryOperationException > ( ( ) => allocator . AllocateGroup < byte > ( 5 * oneMb , 1024 ) ) ;
444+ }
421445}
You can’t perform that action at this time.
0 commit comments