2022-06-10 04:26:19 +03:00
|
|
|
using Moq;
|
|
|
|
using NAPS2.Images.Gdi;
|
|
|
|
using NAPS2.Scan;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace NAPS2.Sdk.Tests.Scan;
|
|
|
|
|
|
|
|
public class ScanningContextTests : ContextualTexts
|
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void CreateAndNormallyDisposeImages()
|
|
|
|
{
|
|
|
|
var context = new ScanningContext(new GdiImageContext());
|
|
|
|
var storage1 = new Mock<IImageStorage>();
|
|
|
|
var storage2 = new Mock<IImageStorage>();
|
2022-06-10 20:34:00 +03:00
|
|
|
var image1 = context.CreateProcessedImage(storage1.Object);
|
|
|
|
var image2 = context.CreateProcessedImage(storage2.Object);
|
2022-06-10 04:26:19 +03:00
|
|
|
|
|
|
|
storage1.VerifyNoOtherCalls();
|
|
|
|
image1.Dispose();
|
|
|
|
storage1.Verify(x => x.Dispose());
|
|
|
|
storage2.VerifyNoOtherCalls();
|
|
|
|
image2.Dispose();
|
|
|
|
storage2.Verify(x => x.Dispose());
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void CreateAndDisposeImagesByDisposingContext()
|
|
|
|
{
|
|
|
|
var context = new ScanningContext(new GdiImageContext());
|
|
|
|
var storage1 = new Mock<IImageStorage>();
|
|
|
|
var storage2 = new Mock<IImageStorage>();
|
2022-06-11 09:18:11 +03:00
|
|
|
// Create a simple image
|
2022-06-10 20:34:00 +03:00
|
|
|
context.CreateProcessedImage(storage1.Object);
|
2022-06-11 09:18:11 +03:00
|
|
|
// Create an image, clone it a couple times, and dispose the original
|
|
|
|
// The underling storage shouldn't be disposed yet due to refcounting
|
|
|
|
// This tests the interaction between refcounting and context disposal
|
|
|
|
var imageToClone = context.CreateProcessedImage(storage2.Object);
|
|
|
|
imageToClone.Clone();
|
|
|
|
imageToClone.Clone();
|
|
|
|
imageToClone.Dispose();
|
2022-06-10 04:26:19 +03:00
|
|
|
|
|
|
|
storage1.VerifyNoOtherCalls();
|
|
|
|
storage2.VerifyNoOtherCalls();
|
|
|
|
context.Dispose();
|
|
|
|
storage1.Verify(x => x.Dispose());
|
|
|
|
storage2.Verify(x => x.Dispose());
|
|
|
|
}
|
|
|
|
}
|