mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
// Copyright (c) Six Labors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Reflection;
|
|
using Xunit.Sdk;
|
|
|
|
namespace SixLabors.ImageSharp.Tests
|
|
{
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
|
public class ValidateDisposedMemoryAllocationsAttribute : BeforeAfterTestAttribute
|
|
{
|
|
private readonly int max = 0;
|
|
|
|
public ValidateDisposedMemoryAllocationsAttribute()
|
|
: this(0)
|
|
{
|
|
}
|
|
|
|
public ValidateDisposedMemoryAllocationsAttribute(int max)
|
|
{
|
|
this.max = max;
|
|
if (max > 0)
|
|
{
|
|
Debug.WriteLine("Needs fixing, we shoudl have Zero undisposed memory allocations.");
|
|
}
|
|
}
|
|
|
|
public override void Before(MethodInfo methodUnderTest)
|
|
=> MemoryAllocatorValidator.MonitorAllocations(this.max); // the disposable isn't important cause the validate below does the same thing
|
|
|
|
public override void After(MethodInfo methodUnderTest)
|
|
=> MemoryAllocatorValidator.ValidateAllocation(this.max);
|
|
}
|
|
}
|
|
|