Browse Source

fix processor invocation tests

af/merge-core
Anton Firszov 7 years ago
parent
commit
475cf843bb
  1. 16
      tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs
  2. 21
      tests/ImageSharp.Tests/FakeImageOperationsProvider.cs
  3. 14
      tests/ImageSharp.Tests/ImageOperationTests.cs
  4. 4
      tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs
  5. 8
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

16
tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
@ -33,7 +34,12 @@ namespace SixLabors.ImageSharp.Tests
FakeImageOperationsProvider.FakeImageOperations<Rgba32>.AppliedOperation operation = this.internalOperations.Applied[index]; FakeImageOperationsProvider.FakeImageOperations<Rgba32>.AppliedOperation operation = this.internalOperations.Applied[index];
return Assert.IsType<T>(operation.Processor); if (operation.NonGenericProcessor != null)
{
return Assert.IsType<T>(operation.NonGenericProcessor);
}
return Assert.IsType<T>(operation.GenericProcessor);
} }
public T Verify<T>(Rectangle rect, int index = 0) public T Verify<T>(Rectangle rect, int index = 0)
@ -43,7 +49,13 @@ namespace SixLabors.ImageSharp.Tests
FakeImageOperationsProvider.FakeImageOperations<Rgba32>.AppliedOperation operation = this.internalOperations.Applied[index]; FakeImageOperationsProvider.FakeImageOperations<Rgba32>.AppliedOperation operation = this.internalOperations.Applied[index];
Assert.Equal(rect, operation.Rectangle); Assert.Equal(rect, operation.Rectangle);
return Assert.IsType<T>(operation.Processor);
if (operation.NonGenericProcessor != null)
{
return Assert.IsType<T>(operation.NonGenericProcessor);
}
return Assert.IsType<T>(operation.GenericProcessor);
} }
} }
} }

21
tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

@ -69,19 +69,28 @@ namespace SixLabors.ImageSharp.Tests
public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
{ {
throw new System.NotImplementedException(); this.Applied.Add(new AppliedOperation()
{
Rectangle = rectangle,
NonGenericProcessor = processor
});
return this;
} }
public IImageProcessingContext ApplyProcessor(IImageProcessor processor) public IImageProcessingContext ApplyProcessor(IImageProcessor processor)
{ {
throw new System.NotImplementedException(); this.Applied.Add(new AppliedOperation()
{
NonGenericProcessor = processor
});
return this;
} }
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle) public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
{ {
this.Applied.Add(new AppliedOperation this.Applied.Add(new AppliedOperation
{ {
Processor = processor, GenericProcessor = processor,
Rectangle = rectangle Rectangle = rectangle
}); });
return this; return this;
@ -91,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
this.Applied.Add(new AppliedOperation this.Applied.Add(new AppliedOperation
{ {
Processor = processor GenericProcessor = processor
}); });
return this; return this;
} }
@ -99,7 +108,9 @@ namespace SixLabors.ImageSharp.Tests
public struct AppliedOperation public struct AppliedOperation
{ {
public Rectangle? Rectangle { get; set; } public Rectangle? Rectangle { get; set; }
public IImageProcessor<TPixel> Processor { get; set; } public IImageProcessor<TPixel> GenericProcessor { get; set; }
public IImageProcessor NonGenericProcessor { get; set; }
} }
} }
} }

14
tests/ImageSharp.Tests/ImageOperationTests.cs

@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Tests
this.image.Mutate(x => x.ApplyProcessor(this.processor)); this.image.Mutate(x => x.ApplyProcessor(this.processor));
Assert.True(this.provider.HasCreated(this.image)); Assert.True(this.provider.HasCreated(this.image));
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests
this.image.Mutate(this.processor); this.image.Mutate(this.processor);
Assert.True(this.provider.HasCreated(this.image)); Assert.True(this.provider.HasCreated(this.image));
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Tests
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor));
Assert.True(this.provider.HasCreated(returned)); Assert.True(this.provider.HasCreated(returned));
Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests
Image<Rgba32> returned = this.image.Clone(this.processor); Image<Rgba32> returned = this.image.Clone(this.processor);
Assert.True(this.provider.HasCreated(returned)); Assert.True(this.provider.HasCreated(returned));
Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor));
Assert.False(this.provider.HasCreated(this.image)); Assert.False(this.provider.HasCreated(this.image));
Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -84,7 +84,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
Image<Rgba32> returned = this.image.Clone(this.processor); Image<Rgba32> returned = this.image.Clone(this.processor);
Assert.False(this.provider.HasCreated(this.image)); Assert.False(this.provider.HasCreated(this.image));
Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor));
} }
[Fact] [Fact]
@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests
{ {
var operations = new FakeImageOperationsProvider.FakeImageOperations<Rgba32>(null, false); var operations = new FakeImageOperationsProvider.FakeImageOperations<Rgba32>(null, false);
operations.ApplyProcessors(this.processor); operations.ApplyProcessors(this.processor);
Assert.Contains(this.processor, operations.Applied.Select(x => x.Processor)); Assert.Contains(this.processor, operations.Applied.Select(x => x.GenericProcessor));
} }
public void Dispose() => this.image.Dispose(); public void Dispose() => this.image.Dispose();

4
tests/ImageSharp.Tests/Processing/Filters/FilterTest.cs

@ -17,14 +17,14 @@ namespace SixLabors.ImageSharp.Tests.Processing.Filters
public void Filter_CorrectProcessor() public void Filter_CorrectProcessor()
{ {
this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F)); this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F));
FilterProcessorImplementation<Rgba32> p = this.Verify<FilterProcessorImplementation<Rgba32>>(); FilterProcessor p = this.Verify<FilterProcessor>();
} }
[Fact] [Fact]
public void Filter_rect_CorrectProcessor() public void Filter_rect_CorrectProcessor()
{ {
this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F), this.rect); this.operations.Filter(KnownFilterMatrices.AchromatomalyFilter * KnownFilterMatrices.CreateHueFilter(90F), this.rect);
FilterProcessorImplementation<Rgba32> p = this.Verify<FilterProcessorImplementation<Rgba32>>(this.rect); FilterProcessor p = this.Verify<FilterProcessor>(this.rect);
} }
} }
} }

8
tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
int width = 50; int width = 50;
int height = 100; int height = 100;
this.operations.Resize(width, height); this.operations.Resize(width, height);
ResizeProcessorImplementation<Rgba32> resizeProcessor = this.Verify<ResizeProcessorImplementation<Rgba32>>(); ResizeProcessor resizeProcessor = this.Verify<ResizeProcessor>();
Assert.Equal(width, resizeProcessor.Width); Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height); Assert.Equal(height, resizeProcessor.Height);
@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
int height = 100; int height = 100;
IResampler sampler = KnownResamplers.Lanczos3; IResampler sampler = KnownResamplers.Lanczos3;
this.operations.Resize(width, height, sampler); this.operations.Resize(width, height, sampler);
ResizeProcessorImplementation<Rgba32> resizeProcessor = this.Verify<ResizeProcessorImplementation<Rgba32>>(); ResizeProcessor resizeProcessor = this.Verify<ResizeProcessor>();
Assert.Equal(width, resizeProcessor.Width); Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height); Assert.Equal(height, resizeProcessor.Height);
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
// ReSharper disable once ConditionIsAlwaysTrueOrFalse // ReSharper disable once ConditionIsAlwaysTrueOrFalse
this.operations.Resize(width, height, sampler, compand); this.operations.Resize(width, height, sampler, compand);
ResizeProcessorImplementation<Rgba32> resizeProcessor = this.Verify<ResizeProcessorImplementation<Rgba32>>(); ResizeProcessor resizeProcessor = this.Verify<ResizeProcessor>();
Assert.Equal(width, resizeProcessor.Width); Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height); Assert.Equal(height, resizeProcessor.Height);
@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
}; };
this.operations.Resize(resizeOptions); this.operations.Resize(resizeOptions);
ResizeProcessorImplementation<Rgba32> resizeProcessor = this.Verify<ResizeProcessorImplementation<Rgba32>>(); ResizeProcessor resizeProcessor = this.Verify<ResizeProcessor>();
Assert.Equal(width, resizeProcessor.Width); Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height); Assert.Equal(height, resizeProcessor.Height);

Loading…
Cancel
Save