Browse Source

Added tests for issues#1628

pull/1629/head
Dmitry Pentin 5 years ago
parent
commit
009e9357bd
  1. 42
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs
  2. 35
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs

42
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs

@ -323,6 +323,48 @@ namespace SixLabors.ImageSharp.Tests
var frame = new ImageFrame<Rgba32>(Configuration.Default, 10, 10);
Assert.False(this.Image.Frames.Contains(frame));
}
[Fact]
public void DisposeCall_NoThrowIfCalledMultiple()
{
var image = new Image<Rgba32>(Configuration.Default, 10, 10);
var frameCollection = image.Frames as ImageFrameCollection;
image.Dispose(); // this should invalidate underlying collection as well
frameCollection.Dispose();
}
[Fact]
public void PublicProperties_ThrowIfDisposed()
{
var image = new Image<Rgba32>(Configuration.Default, 10, 10);
var frameCollection = image.Frames as ImageFrameCollection;
image.Dispose(); // this should invalidate underlying collection as well
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.RootFrame; });
}
[Fact]
public void PublicMethods_ThrowIfDisposed()
{
var image = new Image<Rgba32>(Configuration.Default, 10, 10);
var frameCollection = image.Frames as ImageFrameCollection;
image.Dispose(); // this should invalidate underlying collection as well
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.AddFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CloneFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.Contains(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CreateFrame(); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CreateFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.ExportFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.GetEnumerator(); });
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.IndexOf(default); });
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.InsertFrame(default, default); });
Assert.Throws<ObjectDisposedException>(() => { frameCollection.RemoveFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { frameCollection.MoveFrame(default, default); });
}
}
}
}

35
tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.NonGeneric.cs

@ -263,6 +263,41 @@ namespace SixLabors.ImageSharp.Tests
Assert.False(this.Image.Frames.Contains(frame));
}
[Fact]
public void PublicProperties_ThrowIfDisposed()
{
var image = new Image<Rgba32>(Configuration.Default, 10, 10);
var frameCollection = image.Frames;
image.Dispose(); // this should invalidate underlying collection as well
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.RootFrame; });
}
[Fact]
public void PublicMethods_ThrowIfDisposed()
{
var image = new Image<Rgba32>(Configuration.Default, 10, 10);
var frameCollection = image.Frames;
image.Dispose(); // this should invalidate underlying collection as well
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.AddFrame((ImageFrame)null); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.AddFrame((Rgba32[])null); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.AddFrame((ImageFrame<Rgba32>)null); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.AddFrame(stackalloc Rgba32[0]); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CloneFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.Contains(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CreateFrame(); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.CreateFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.ExportFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { var res = frameCollection.GetEnumerator(); });
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.IndexOf(default); });
Assert.Throws<ObjectDisposedException>(() => { var prop = frameCollection.InsertFrame(default, default); });
Assert.Throws<ObjectDisposedException>(() => { frameCollection.RemoveFrame(default); });
Assert.Throws<ObjectDisposedException>(() => { frameCollection.MoveFrame(default, default); });
}
/// <summary>
/// Integration test for end-to end API validation.
/// </summary>

Loading…
Cancel
Save