Tortuga-TestMonkey icon indicating copy to clipboard operation
Tortuga-TestMonkey copied to clipboard

Memory Tests

Open Grauenwolf opened this issue 3 years ago • 0 comments

foreach (var constructor in Class.Constructors.Where(c => c.IsCreatable)) 
{ 
	<text>
	
    @Tag("Memory")
	@TestAttribute
    public void @(Test.ClassName + "_Memory_" + constructor.SafeName)()
	{

        Func<WeakReference> ctr = () =>
        {
		    try
		    {
			    return new WeakReference( @constructor.GetConstructorCode() );
		    }
		    catch (ArgumentException)
		    {
                return null;
		    }
        };

        var wr = ctr();
        if (wr == null) 
            return; //unable to create object, test aborted
		
        GC.Collect();
		GC.WaitForPendingFinalizers();
		GC.Collect();

		//verify the object was collected
		Assert.IsFalse(wr.IsAlive);		
	}
			
	</text>	
}	

Grauenwolf avatar Jun 02 '21 01:06 Grauenwolf