Browse Source

Use StringComparison.Ordinal and fix some minor warnings

pull/1635/head
Brian Popow 5 years ago
parent
commit
b49313e1dc
  1. 10
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 40
      tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs
  3. 22
      tests/ImageSharp.Tests/Image/ImageFrameCollectionTests.Generic.cs
  4. 20
      tests/ImageSharp.Tests/Image/ImageTests.Identify.cs
  5. 38
      tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs
  6. 2
      tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs
  7. 5
      tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs
  8. 2
      tests/ImageSharp.Tests/Processing/ImageOperationTests.cs
  9. 5
      tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs
  10. 22
      tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs
  11. 34
      tests/ImageSharp.Tests/TestFormat.cs
  12. 2
      tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs
  13. 5
      tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs

10
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -141,9 +141,9 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
TestEnvironment.InputImagesDirectoryFullPath, TestEnvironment.InputImagesDirectoryFullPath,
fileName); fileName);
const int NumberOfRuns = 5; const int numberOfRuns = 5;
for (int i = 0; i < NumberOfRuns; i++) for (int i = 0; i < numberOfRuns; i++)
{ {
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
if (cancellationDelayMs == 0) if (cancellationDelayMs == 0)
@ -157,16 +157,16 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
try try
{ {
using var image = await Image.LoadAsync(hugeFile, cts.Token); using Image image = await Image.LoadAsync(hugeFile, cts.Token);
} }
catch (TaskCanceledException) catch (TaskCanceledException)
{ {
// Succesfully observed a cancellation // Successfully observed a cancellation
return; return;
} }
} }
throw new Exception($"No cancellation happened out of {NumberOfRuns} runs!"); throw new Exception($"No cancellation happened out of {numberOfRuns} runs!");
} }
[Theory(Skip = "Identify is too fast, doesn't work reliably.")] [Theory(Skip = "Identify is too fast, doesn't work reliably.")]

40
tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs

@ -90,12 +90,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
using (Image<TPixel> image = provider.GetImage(new PngDecoder())) using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{ {
PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance); PngMetadata meta = image.Metadata.GetFormatMetadata(PngFormat.Instance);
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("leading space")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("leading space", System.StringComparison.Ordinal));
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("trailing space")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("trailing space", System.StringComparison.Ordinal));
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("space")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("space", System.StringComparison.Ordinal));
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("empty")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("empty", System.StringComparison.Ordinal));
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("invalid characters")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("invalid characters", System.StringComparison.Ordinal));
Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("too large")); Assert.DoesNotContain(meta.TextData, m => m.Value.Equals("too large", System.StringComparison.Ordinal));
} }
} }
@ -277,20 +277,20 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
private static void VerifyTextDataIsPresent(PngMetadata meta) private static void VerifyTextDataIsPresent(PngMetadata meta)
{ {
Assert.NotNull(meta); Assert.NotNull(meta);
Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment") && m.Value.Equals("comment")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("Comment", System.StringComparison.Ordinal) && m.Value.Equals("comment", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author") && m.Value.Equals("ImageSharp")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("Author", System.StringComparison.Ordinal) && m.Value.Equals("ImageSharp", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright") && m.Value.Equals("ImageSharp")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("Copyright", System.StringComparison.Ordinal) && m.Value.Equals("ImageSharp", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title") && m.Value.Equals("unittest")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("Title", System.StringComparison.Ordinal) && m.Value.Equals("unittest", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description") && m.Value.Equals("compressed-text")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("Description", System.StringComparison.Ordinal) && m.Value.Equals("compressed-text", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("International") && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'") && Assert.Contains(meta.TextData, m => m.Keyword.Equals("International", System.StringComparison.Ordinal) && m.Value.Equals("'e', mu'tlheghvam, ghaH yu'", System.StringComparison.Ordinal) &&
m.LanguageTag.Equals("x-klingon") && m.TranslatedKeyword.Equals("warning")); m.LanguageTag.Equals("x-klingon", System.StringComparison.Ordinal) && m.TranslatedKeyword.Equals("warning", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2") && m.Value.Equals("ИМАГЕШАРП") && m.LanguageTag.Equals("rus")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("International2", System.StringComparison.Ordinal) && m.Value.Equals("ИМАГЕШАРП", System.StringComparison.Ordinal) && m.LanguageTag.Equals("rus", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational") && m.Value.Equals("la plume de la mante") && Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational", System.StringComparison.Ordinal) && m.Value.Equals("la plume de la mante", System.StringComparison.Ordinal) &&
m.LanguageTag.Equals("fra") && m.TranslatedKeyword.Equals("foobar")); m.LanguageTag.Equals("fra", System.StringComparison.Ordinal) && m.TranslatedKeyword.Equals("foobar", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2") && m.Value.Equals("這是一個考驗") && Assert.Contains(meta.TextData, m => m.Keyword.Equals("CompressedInternational2", System.StringComparison.Ordinal) && m.Value.Equals("這是一個考驗", System.StringComparison.Ordinal) &&
m.LanguageTag.Equals("chinese")); m.LanguageTag.Equals("chinese", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang") && m.Value.Equals("this text chunk is missing a language tag")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoLang", System.StringComparison.Ordinal) && m.Value.Equals("this text chunk is missing a language tag", System.StringComparison.Ordinal));
Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword") && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort")); Assert.Contains(meta.TextData, m => m.Keyword.Equals("NoTranslatedKeyword", System.StringComparison.Ordinal) && m.Value.Equals("dieser chunk hat kein übersetztes Schlüßelwort", System.StringComparison.Ordinal));
} }
} }
} }

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

@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Tests
ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>( ArgumentOutOfRangeException ex = Assert.Throws<ArgumentOutOfRangeException>(
() => () =>
{ {
this.Collection.AddFrame(new Rgba32[0]); this.Collection.AddFrame(Array.Empty<Rgba32>());
}); });
Assert.StartsWith($"Parameter \"data\" ({typeof(int)}) must be greater than or equal to {100}, was {0}", ex.Message); Assert.StartsWith($"Parameter \"data\" ({typeof(int)}) must be greater than or equal to {100}, was {0}", ex.Message);
@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Tests
public void AddFrameFromPixelData() public void AddFrameFromPixelData()
{ {
Assert.True(this.Image.Frames.RootFrame.TryGetSinglePixelSpan(out Span<Rgba32> imgSpan)); Assert.True(this.Image.Frames.RootFrame.TryGetSinglePixelSpan(out Span<Rgba32> imgSpan));
var pixelData = imgSpan.ToArray(); Rgba32[] pixelData = imgSpan.ToArray();
this.Image.Frames.AddFrame(pixelData); this.Image.Frames.AddFrame(pixelData);
Assert.Equal(2, this.Image.Frames.Count); Assert.Equal(2, this.Image.Frames.Count);
} }
@ -276,46 +276,46 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void MoveFrame_LeavesFrameInCorrectLocation() public void MoveFrame_LeavesFrameInCorrectLocation()
{ {
for (var i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
this.Image.Frames.CreateFrame(); this.Image.Frames.CreateFrame();
} }
var frame = this.Image.Frames[4]; ImageFrame<Rgba32> frame = this.Image.Frames[4];
this.Image.Frames.MoveFrame(4, 7); this.Image.Frames.MoveFrame(4, 7);
var newIndex = this.Image.Frames.IndexOf(frame); int newIndex = this.Image.Frames.IndexOf(frame);
Assert.Equal(7, newIndex); Assert.Equal(7, newIndex);
} }
[Fact] [Fact]
public void IndexOf_ReturnsCorrectIndex() public void IndexOf_ReturnsCorrectIndex()
{ {
for (var i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
this.Image.Frames.CreateFrame(); this.Image.Frames.CreateFrame();
} }
var frame = this.Image.Frames[4]; ImageFrame<Rgba32> frame = this.Image.Frames[4];
var index = this.Image.Frames.IndexOf(frame); int index = this.Image.Frames.IndexOf(frame);
Assert.Equal(4, index); Assert.Equal(4, index);
} }
[Fact] [Fact]
public void Contains_TrueIfMember() public void Contains_TrueIfMember()
{ {
for (var i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
this.Image.Frames.CreateFrame(); this.Image.Frames.CreateFrame();
} }
var frame = this.Image.Frames[4]; ImageFrame<Rgba32> frame = this.Image.Frames[4];
Assert.True(this.Image.Frames.Contains(frame)); Assert.True(this.Image.Frames.Contains(frame));
} }
[Fact] [Fact]
public void Contains_FalseIfNonMember() public void Contains_FalseIfNonMember()
{ {
for (var i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
this.Image.Frames.CreateFrame(); this.Image.Frames.CreateFrame();
} }

20
tests/ImageSharp.Tests/Image/ImageTests.Identify.cs

@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Tests
private static readonly Size ExpectedImageSize = new Size(108, 202); private static readonly Size ExpectedImageSize = new Size(108, 202);
private byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes; private static byte[] ActualImageBytes => TestFile.Create(TestImages.Bmp.F).Bytes;
private IImageInfo LocalImageInfo => this.localImageInfoMock.Object; private IImageInfo LocalImageInfo => this.localImageInfoMock.Object;
@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void FromBytes_GlobalConfiguration() public void FromBytes_GlobalConfiguration()
{ {
IImageInfo info = Image.Identify(this.ActualImageBytes, out IImageFormat type); IImageInfo info = Image.Identify(ActualImageBytes, out IImageFormat type);
Assert.Equal(ExpectedImageSize, info.Size()); Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedGlobalFormat, type); Assert.Equal(ExpectedGlobalFormat, type);
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void FromStream_GlobalConfiguration() public void FromStream_GlobalConfiguration()
{ {
using (var stream = new MemoryStream(this.ActualImageBytes)) using (var stream = new MemoryStream(ActualImageBytes))
{ {
IImageInfo info = Image.Identify(stream, out IImageFormat type); IImageInfo info = Image.Identify(stream, out IImageFormat type);
@ -81,7 +81,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void FromStream_GlobalConfiguration_NoFormat() public void FromStream_GlobalConfiguration_NoFormat()
{ {
using (var stream = new MemoryStream(this.ActualImageBytes)) using (var stream = new MemoryStream(ActualImageBytes))
{ {
IImageInfo info = Image.Identify(stream); IImageInfo info = Image.Identify(stream);
@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void FromNonSeekableStream_GlobalConfiguration() public void FromNonSeekableStream_GlobalConfiguration()
{ {
using var stream = new MemoryStream(this.ActualImageBytes); using var stream = new MemoryStream(ActualImageBytes);
using var nonSeekableStream = new NonSeekableStream(stream); using var nonSeekableStream = new NonSeekableStream(stream);
IImageInfo info = Image.Identify(nonSeekableStream, out IImageFormat type); IImageInfo info = Image.Identify(nonSeekableStream, out IImageFormat type);
@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public void FromNonSeekableStream_GlobalConfiguration_NoFormat() public void FromNonSeekableStream_GlobalConfiguration_NoFormat()
{ {
using var stream = new MemoryStream(this.ActualImageBytes); using var stream = new MemoryStream(ActualImageBytes);
using var nonSeekableStream = new NonSeekableStream(stream); using var nonSeekableStream = new NonSeekableStream(stream);
IImageInfo info = Image.Identify(nonSeekableStream); IImageInfo info = Image.Identify(nonSeekableStream);
@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public async Task FromStreamAsync_GlobalConfiguration_NoFormat() public async Task FromStreamAsync_GlobalConfiguration_NoFormat()
{ {
using (var stream = new MemoryStream(this.ActualImageBytes)) using (var stream = new MemoryStream(ActualImageBytes))
{ {
var asyncStream = new AsyncStreamWrapper(stream, () => false); var asyncStream = new AsyncStreamWrapper(stream, () => false);
IImageInfo info = await Image.IdentifyAsync(asyncStream); IImageInfo info = await Image.IdentifyAsync(asyncStream);
@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public async Task FromStreamAsync_GlobalConfiguration() public async Task FromStreamAsync_GlobalConfiguration()
{ {
using (var stream = new MemoryStream(this.ActualImageBytes)) using (var stream = new MemoryStream(ActualImageBytes))
{ {
var asyncStream = new AsyncStreamWrapper(stream, () => false); var asyncStream = new AsyncStreamWrapper(stream, () => false);
(IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream); (IImageInfo ImageInfo, IImageFormat Format) res = await Image.IdentifyWithFormatAsync(asyncStream);
@ -166,7 +166,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public async Task FromNonSeekableStreamAsync_GlobalConfiguration_NoFormat() public async Task FromNonSeekableStreamAsync_GlobalConfiguration_NoFormat()
{ {
using var stream = new MemoryStream(this.ActualImageBytes); using var stream = new MemoryStream(ActualImageBytes);
using var nonSeekableStream = new NonSeekableStream(stream); using var nonSeekableStream = new NonSeekableStream(stream);
var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false);
@ -178,7 +178,7 @@ namespace SixLabors.ImageSharp.Tests
[Fact] [Fact]
public async Task FromNonSeekableStreamAsync_GlobalConfiguration() public async Task FromNonSeekableStreamAsync_GlobalConfiguration()
{ {
using var stream = new MemoryStream(this.ActualImageBytes); using var stream = new MemoryStream(ActualImageBytes);
using var nonSeekableStream = new NonSeekableStream(stream); using var nonSeekableStream = new NonSeekableStream(stream);
var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false); var asyncStream = new AsyncStreamWrapper(nonSeekableStream, () => false);

38
tests/ImageSharp.Tests/Memory/Allocators/BufferTestSuite.cs

@ -60,24 +60,24 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
} }
public static readonly TheoryData<int> LenthValues = new TheoryData<int> { 0, 1, 7, 1023, 1024 }; public static readonly TheoryData<int> LengthValues = new TheoryData<int> { 0, 1, 7, 1023, 1024 };
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void HasCorrectLength_byte(int desiredLength) public void HasCorrectLength_byte(int desiredLength)
{ {
this.TestHasCorrectLength<byte>(desiredLength); this.TestHasCorrectLength<byte>(desiredLength);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void HasCorrectLength_float(int desiredLength) public void HasCorrectLength_float(int desiredLength)
{ {
this.TestHasCorrectLength<float>(desiredLength); this.TestHasCorrectLength<float>(desiredLength);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void HasCorrectLength_CustomStruct(int desiredLength) public void HasCorrectLength_CustomStruct(int desiredLength)
{ {
this.TestHasCorrectLength<CustomStruct>(desiredLength); this.TestHasCorrectLength<CustomStruct>(desiredLength);
@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void CanAllocateCleanBuffer_byte(int desiredLength) public void CanAllocateCleanBuffer_byte(int desiredLength)
{ {
this.TestCanAllocateCleanBuffer<byte>(desiredLength, false); this.TestCanAllocateCleanBuffer<byte>(desiredLength, false);
@ -101,14 +101,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void CanAllocateCleanBuffer_double(int desiredLength) public void CanAllocateCleanBuffer_double(int desiredLength)
{ {
this.TestCanAllocateCleanBuffer<double>(desiredLength); this.TestCanAllocateCleanBuffer<double>(desiredLength);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void CanAllocateCleanBuffer_CustomStruct(int desiredLength) public void CanAllocateCleanBuffer_CustomStruct(int desiredLength)
{ {
this.TestCanAllocateCleanBuffer<CustomStruct>(desiredLength); this.TestCanAllocateCleanBuffer<CustomStruct>(desiredLength);
@ -145,14 +145,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void SpanPropertyIsAlwaysTheSame_int(int desiredLength) public void SpanPropertyIsAlwaysTheSame_int(int desiredLength)
{ {
this.TestSpanPropertyIsAlwaysTheSame<int>(desiredLength); this.TestSpanPropertyIsAlwaysTheSame<int>(desiredLength);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void SpanPropertyIsAlwaysTheSame_byte(int desiredLength) public void SpanPropertyIsAlwaysTheSame_byte(int desiredLength)
{ {
this.TestSpanPropertyIsAlwaysTheSame<byte>(desiredLength, false); this.TestSpanPropertyIsAlwaysTheSame<byte>(desiredLength, false);
@ -174,18 +174,18 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void WriteAndReadElements_float(int desiredLength) public void WriteAndReadElements_float(int desiredLength)
{ {
this.TestWriteAndReadElements<float>(desiredLength, x => x * 1.2f); this.TestWriteAndReadElements(desiredLength, x => x * 1.2f);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void WriteAndReadElements_byte(int desiredLength) public void WriteAndReadElements_byte(int desiredLength)
{ {
this.TestWriteAndReadElements<byte>(desiredLength, x => (byte)(x + 1), false); this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), false);
this.TestWriteAndReadElements<byte>(desiredLength, x => (byte)(x + 1), true); this.TestWriteAndReadElements(desiredLength, x => (byte)(x + 1), true);
} }
private void TestWriteAndReadElements<T>(int desiredLength, Func<int, T> getExpectedValue, bool testManagedByteBuffer = false) private void TestWriteAndReadElements<T>(int desiredLength, Func<int, T> getExpectedValue, bool testManagedByteBuffer = false)
@ -193,7 +193,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
{ {
using (IMemoryOwner<T> buffer = this.Allocate<T>(desiredLength, AllocationOptions.None, testManagedByteBuffer)) using (IMemoryOwner<T> buffer = this.Allocate<T>(desiredLength, AllocationOptions.None, testManagedByteBuffer))
{ {
T[] expectedVals = new T[buffer.Length()]; var expectedVals = new T[buffer.Length()];
for (int i = 0; i < buffer.Length(); i++) for (int i = 0; i < buffer.Length(); i++)
{ {
@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void IndexingSpan_WhenOutOfRange_Throws_byte(int desiredLength) public void IndexingSpan_WhenOutOfRange_Throws_byte(int desiredLength)
{ {
this.TestIndexOutOfRangeShouldThrow<byte>(desiredLength, false); this.TestIndexOutOfRangeShouldThrow<byte>(desiredLength, false);
@ -219,14 +219,14 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void IndexingSpan_WhenOutOfRange_Throws_long(int desiredLength) public void IndexingSpan_WhenOutOfRange_Throws_long(int desiredLength)
{ {
this.TestIndexOutOfRangeShouldThrow<long>(desiredLength); this.TestIndexOutOfRangeShouldThrow<long>(desiredLength);
} }
[Theory] [Theory]
[MemberData(nameof(LenthValues))] [MemberData(nameof(LengthValues))]
public void IndexingSpan_WhenOutOfRange_Throws_CustomStruct(int desiredLength) public void IndexingSpan_WhenOutOfRange_Throws_CustomStruct(int desiredLength)
{ {
this.TestIndexOutOfRangeShouldThrow<CustomStruct>(desiredLength); this.TestIndexOutOfRangeShouldThrow<CustomStruct>(desiredLength);
@ -316,4 +316,4 @@ namespace SixLabors.ImageSharp.Tests.Memory.Allocators
} }
} }
} }
} }

2
tests/ImageSharp.Tests/PixelFormats/PixelOperations/PixelOperationsTests.cs

@ -110,7 +110,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelOperations
[Fact] [Fact]
public void PixelTypeInfoHasCorrectBitsPerPixel() public void PixelTypeInfoHasCorrectBitsPerPixel()
{ {
var bits = this.Operations.GetPixelTypeInfo().BitsPerPixel; int bits = this.Operations.GetPixelTypeInfo().BitsPerPixel;
Assert.Equal(Unsafe.SizeOf<TPixel>() * 8, bits); Assert.Equal(Unsafe.SizeOf<TPixel>() * 8, bits);
} }

5
tests/ImageSharp.Tests/Processing/BaseImageOperationsExtensionTest.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
@ -9,7 +10,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing namespace SixLabors.ImageSharp.Tests.Processing
{ {
public abstract class BaseImageOperationsExtensionTest public abstract class BaseImageOperationsExtensionTest : IDisposable
{ {
protected readonly IImageProcessingContext operations; protected readonly IImageProcessingContext operations;
private readonly FakeImageOperationsProvider.FakeImageOperations<Rgba32> internalOperations; private readonly FakeImageOperationsProvider.FakeImageOperations<Rgba32> internalOperations;
@ -58,5 +59,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
return Assert.IsType<T>(operation.GenericProcessor); return Assert.IsType<T>(operation.GenericProcessor);
} }
public void Dispose() => this.source?.Dispose();
} }
} }

2
tests/ImageSharp.Tests/Processing/ImageOperationTests.cs

@ -171,7 +171,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
private static void CheckThrowsCorrectObjectDisposedException(Action action) private static void CheckThrowsCorrectObjectDisposedException(Action action)
{ {
var ex = Assert.Throws<ObjectDisposedException>(action); ObjectDisposedException ex = Assert.Throws<ObjectDisposedException>(action);
Assert.Equal(ExpectedExceptionMessage, ex.Message); Assert.Equal(ExpectedExceptionMessage, ex.Message);
} }
} }

5
tests/ImageSharp.Tests/Processing/ImageProcessingContextTests.cs

@ -1,6 +1,7 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using Moq; using Moq;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
@ -12,7 +13,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
/// <summary> /// <summary>
/// Contains test cases for default <see cref="IImageProcessingContext"/> implementation. /// Contains test cases for default <see cref="IImageProcessingContext"/> implementation.
/// </summary> /// </summary>
public class ImageProcessingContextTests public class ImageProcessingContextTests : IDisposable
{ {
private readonly Image image = new Image<Rgba32>(10, 10); private readonly Image image = new Image<Rgba32>(10, 10);
@ -195,5 +196,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
.Setup(p => p.CreatePixelSpecificProcessor(Configuration.Default, It.IsAny<Image<Rgba32>>(), It.IsAny<Rectangle>())) .Setup(p => p.CreatePixelSpecificProcessor(Configuration.Default, It.IsAny<Image<Rgba32>>(), It.IsAny<Rectangle>()))
.Returns(this.cloningProcessorImpl.Object); .Returns(this.cloningProcessorImpl.Object);
} }
public void Dispose() => this.image?.Dispose();
} }
} }

22
tests/ImageSharp.Tests/Processing/Normalization/HistogramEqualizationTests.cs

@ -9,8 +9,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Normalization namespace SixLabors.ImageSharp.Tests.Processing.Normalization
{ {
[Trait("Category", "Processors")]
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
[Trait("Category", "Processors")]
public class HistogramEqualizationTests public class HistogramEqualizationTests
{ {
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.0456F); private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.0456F);
@ -18,10 +18,10 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization
[Theory] [Theory]
[InlineData(256)] [InlineData(256)]
[InlineData(65536)] [InlineData(65536)]
public void GlobalHistogramEqualization_WithDifferentLumanceLevels(int luminanceLevels) public void GlobalHistogramEqualization_WithDifferentLuminanceLevels(int luminanceLevels)
{ {
// Arrange // Arrange
var pixels = new byte[] byte[] pixels =
{ {
52, 55, 61, 59, 70, 61, 76, 61, 52, 55, 61, 59, 70, 61, 76, 61,
62, 59, 55, 104, 94, 85, 59, 71, 62, 59, 55, 104, 94, 85, 59, 71,
@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization
} }
} }
var expected = new byte[] byte[] expected =
{ {
0, 12, 53, 32, 146, 53, 174, 53, 0, 12, 53, 32, 146, 53, 174, 53,
57, 32, 12, 227, 219, 202, 32, 154, 57, 32, 12, 227, 219, 202, 32, 154,
@ -150,13 +150,13 @@ namespace SixLabors.ImageSharp.Tests.Processing.Normalization
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
var options = new HistogramEqualizationOptions() var options = new HistogramEqualizationOptions()
{ {
Method = HistogramEqualizationMethod.AdaptiveTileInterpolation, Method = HistogramEqualizationMethod.AdaptiveTileInterpolation,
LuminanceLevels = 256, LuminanceLevels = 256,
ClipHistogram = true, ClipHistogram = true,
ClipLimit = 5, ClipLimit = 5,
NumberOfTiles = 10 NumberOfTiles = 10
}; };
image.Mutate(x => x.HistogramEqualization(options)); image.Mutate(x => x.HistogramEqualization(options));
image.DebugSave(provider); image.DebugSave(provider);
image.CompareToReferenceOutput(ValidatorComparer, provider); image.CompareToReferenceOutput(ValidatorComparer, provider);

34
tests/ImageSharp.Tests/TestFormat.cs

@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Tests
public TestDecoder Decoder { get; } public TestDecoder Decoder { get; }
private byte[] header = Guid.NewGuid().ToByteArray(); private readonly byte[] header = Guid.NewGuid().ToByteArray();
public MemoryStream CreateStream(byte[] marker = null) public MemoryStream CreateStream(byte[] marker = null)
{ {
@ -119,16 +119,16 @@ namespace SixLabors.ImageSharp.Tests
public IEnumerable<string> FileExtensions => this.SupportedExtensions; public IEnumerable<string> FileExtensions => this.SupportedExtensions;
public bool IsSupportedFileFormat(ReadOnlySpan<byte> header) public bool IsSupportedFileFormat(ReadOnlySpan<byte> fileHeader)
{ {
if (header.Length < this.header.Length) if (fileHeader.Length < this.header.Length)
{ {
return false; return false;
} }
for (int i = 0; i < this.header.Length; i++) for (int i = 0; i < this.header.Length; i++)
{ {
if (header[i] != this.header[i]) if (fileHeader[i] != this.header[i])
{ {
return false; return false;
} }
@ -137,11 +137,11 @@ namespace SixLabors.ImageSharp.Tests
return true; return true;
} }
public void Configure(Configuration host) public void Configure(Configuration configuration)
{ {
host.ImageFormatsManager.AddImageFormatDetector(new TestHeader(this)); configuration.ImageFormatsManager.AddImageFormatDetector(new TestHeader(this));
host.ImageFormatsManager.SetEncoder(this, new TestEncoder(this)); configuration.ImageFormatsManager.SetEncoder(this, new TestEncoder(this));
host.ImageFormatsManager.SetDecoder(this, new TestDecoder(this)); configuration.ImageFormatsManager.SetDecoder(this, new TestDecoder(this));
} }
public struct DecodeOperation public struct DecodeOperation
@ -177,7 +177,7 @@ namespace SixLabors.ImageSharp.Tests
public class TestHeader : IImageFormatDetector public class TestHeader : IImageFormatDetector
{ {
private TestFormat testFormat; private readonly TestFormat testFormat;
public int HeaderSize => this.testFormat.HeaderSize; public int HeaderSize => this.testFormat.HeaderSize;
@ -199,7 +199,7 @@ namespace SixLabors.ImageSharp.Tests
public class TestDecoder : IImageDecoder, IImageInfoDetector public class TestDecoder : IImageDecoder, IImageInfoDetector
{ {
private TestFormat testFormat; private readonly TestFormat testFormat;
public TestDecoder(TestFormat testFormat) public TestDecoder(TestFormat testFormat)
{ {
@ -212,20 +212,20 @@ namespace SixLabors.ImageSharp.Tests
public int HeaderSize => this.testFormat.HeaderSize; public int HeaderSize => this.testFormat.HeaderSize;
public Image<TPixel> Decode<TPixel>(Configuration config, Stream stream) public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
=> this.DecodeImpl<TPixel>(config, stream, default).GetAwaiter().GetResult(); => this.DecodeImpl<TPixel>(configuration, stream, default).GetAwaiter().GetResult();
public Task<Image<TPixel>> DecodeAsync<TPixel>(Configuration config, Stream stream, CancellationToken cancellationToken) public Task<Image<TPixel>> DecodeAsync<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
=> this.DecodeImpl<TPixel>(config, stream, cancellationToken); => this.DecodeImpl<TPixel>(configuration, stream, cancellationToken);
private async Task<Image<TPixel>> DecodeImpl<TPixel>(Configuration config, Stream stream, CancellationToken cancellationToken) private async Task<Image<TPixel>> DecodeImpl<TPixel>(Configuration config, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
var ms = new MemoryStream(); var ms = new MemoryStream();
await stream.CopyToAsync(ms, config.StreamProcessingBufferSize, cancellationToken); await stream.CopyToAsync(ms, config.StreamProcessingBufferSize, cancellationToken);
var marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray(); byte[] marker = ms.ToArray().Skip(this.testFormat.header.Length).ToArray();
this.testFormat.DecodeCalls.Add(new DecodeOperation this.testFormat.DecodeCalls.Add(new DecodeOperation
{ {
Marker = marker, Marker = marker,
@ -251,9 +251,9 @@ namespace SixLabors.ImageSharp.Tests
=> await this.DecodeImpl<Rgba32>(configuration, stream, cancellationToken); => await this.DecodeImpl<Rgba32>(configuration, stream, cancellationToken);
} }
public class TestEncoder : ImageSharp.Formats.IImageEncoder public class TestEncoder : IImageEncoder
{ {
private TestFormat testFormat; private readonly TestFormat testFormat;
public TestEncoder(TestFormat testFormat) public TestEncoder(TestFormat testFormat)
{ {

2
tests/ImageSharp.Tests/TestUtilities/Attributes/ImageDataAttributeBase.cs

@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Tests
if (!addedRows.Any()) if (!addedRows.Any())
{ {
addedRows = new[] { new object[0] }; addedRows = new[] { Array.Empty<object>() };
} }
bool firstIsProvider = this.FirstIsProvider(testMethod); bool firstIsProvider = this.FirstIsProvider(testMethod);

5
tests/ImageSharp.Tests/TestUtilities/Tests/SemaphoreReadMemoryStreamTests.cs

@ -1,13 +1,12 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using SixLabors.ImageSharp.Tests.TestUtilities;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests.TestUtilities.Tests
{ {
public class SemaphoreReadMemoryStreamTests public class SemaphoreReadMemoryStreamTests
{ {

Loading…
Cancel
Save