diff --git a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs index a6f6600f0..f10a4ce84 100644 --- a/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs +++ b/tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs @@ -20,12 +20,12 @@ namespace SixLabors.ImageSharp.Tests { public class ImageFormatManagerTests { - public ImageFormatManager FormatsManagerEmpty { get; private set; } - public ImageFormatManager DefaultFormatsManager { get; private set; } + public ImageFormatManager FormatsManagerEmpty { get; } + public ImageFormatManager DefaultFormatsManager { get; } public ImageFormatManagerTests() { - this.DefaultFormatsManager = Configuration.Default.ImageFormatsManager; + this.DefaultFormatsManager = Configuration.CreateDefaultInstance().ImageFormatsManager; this.FormatsManagerEmpty = new ImageFormatManager(); } diff --git a/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs b/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs index 1a2275062..b05d83204 100644 --- a/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs +++ b/tests/ImageSharp.Tests/Image/ImageDiscoverMimeType.cs @@ -42,7 +42,6 @@ namespace SixLabors.ImageSharp.Tests this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); - TestFormat.RegisterGlobalTestFormat(); this.Marker = Guid.NewGuid().ToByteArray(); this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); diff --git a/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs new file mode 100644 index 000000000..86e73fb9f --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.ImageLoadTestBase.cs @@ -0,0 +1,86 @@ +namespace SixLabors.ImageSharp.Tests +{ + using System; + using System.IO; + + using Moq; + + using SixLabors.ImageSharp.Formats; + using SixLabors.ImageSharp.IO; + using SixLabors.ImageSharp.PixelFormats; + + public partial class ImageTests + { + public abstract class ImageLoadTestBase : IDisposable + { + + + protected Image returnImage; + + protected Mock localDecoder; + + + + protected IImageFormatDetector localMimeTypeDetector; + + protected Mock localImageFormatMock; + + public Configuration LocalConfiguration { get; } + + public TestFormat TestFormat { get; } = new TestFormat(); + + /// + /// Gets the top-level configuration in the context of this test case. + /// It has registered. + /// + public Configuration TopLevelConfiguration { get; } + + public byte[] Marker { get; private set; } + + public MemoryStream DataStream { get; private set; } + + public byte[] DecodedData { get; private set; } + + protected ImageLoadTestBase() + { + this.returnImage = new Image(1, 1); + + this.localImageFormatMock = new Mock(); + + this.localDecoder = new Mock(); + this.localMimeTypeDetector = new MockImageFormatDetector(this.localImageFormatMock.Object); + this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny())) + + .Callback((c, s) => + { + using (var ms = new MemoryStream()) + { + s.CopyTo(ms); + this.DecodedData = ms.ToArray(); + } + }) + .Returns(this.returnImage); + + + + this.LocalConfiguration = new Configuration + { + }; + this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); + this.LocalConfiguration.ImageFormatsManager.SetDecoder(this.localImageFormatMock.Object, this.localDecoder.Object); + + this.TopLevelConfiguration = new Configuration(this.TestFormat); + + this.Marker = Guid.NewGuid().ToByteArray(); + this.DataStream = this.TestFormat.CreateStream(this.Marker); + + + } + public void Dispose() + { + // clean up the global object; + this.returnImage?.Dispose(); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs b/tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs new file mode 100644 index 000000000..e45602a9e --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.LoadPixelData.cs @@ -0,0 +1,31 @@ +namespace SixLabors.ImageSharp.Tests +{ + using SixLabors.ImageSharp.PixelFormats; + + using Xunit; + + public partial class ImageTests + { + public class LoadPixelData + { + [Fact] + public void LoadFromPixelData_Bytes() + { + var img = Image.LoadPixelData(new byte[] { + 0,0,0,255, // 0,0 + 255,255,255,255, // 0,1 + 255,255,255,255, // 1,0 + 0,0,0,255, // 1,1 + }, 2, 2); + + Assert.NotNull(img); + Assert.Equal(Rgba32.Black, img[0, 0]); + Assert.Equal(Rgba32.White, img[0, 1]); + + Assert.Equal(Rgba32.White, img[1, 0]); + Assert.Equal(Rgba32.Black, img[1, 1]); + } + + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs deleted file mode 100644 index e442b5654..000000000 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_BasicCases.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using SixLabors.ImageSharp.PixelFormats; -using Xunit; -// ReSharper disable InconsistentNaming - -namespace SixLabors.ImageSharp.Tests -{ - public partial class ImageTests - { - public class Load_BasicCases - { - [Fact] - public void ByteArray() - { - Assert.Throws(() => - { - Image.Load((byte[])null); - }); - - var file = TestFile.Create(TestImages.Bmp.Car); - using (var image = Image.Load(file.Bytes)) - { - Assert.Equal(600, image.Width); - Assert.Equal(450, image.Height); - } - } - - [Fact] - public void FileSystemPath() - { - var file = TestFile.Create(TestImages.Bmp.Car); - using (var image = Image.Load(file.FullPath)) - { - Assert.Equal(600, image.Width); - Assert.Equal(450, image.Height); - } - } - - [Fact] - public void FileSystemPath_FileNotFound() - { - System.IO.FileNotFoundException ex = Assert.Throws( - () => - { - Image.Load(Guid.NewGuid().ToString()); - }); - } - - [Fact] - public void FileSystemPath_NullPath() - { - ArgumentNullException ex = Assert.Throws( - () => - { - Image.Load((string)null); - }); - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs deleted file mode 100644 index 957e5c40a..000000000 --- a/tests/ImageSharp.Tests/Image/ImageTests.Load_ComplexCases.cs +++ /dev/null @@ -1,338 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; - -using Moq; - -using SixLabors.ImageSharp.Advanced; -using SixLabors.ImageSharp.Formats; -using SixLabors.ImageSharp.IO; -using SixLabors.ImageSharp.PixelFormats; - -using Xunit; -// ReSharper disable InconsistentNaming - -namespace SixLabors.ImageSharp.Tests -{ - public partial class ImageTests - { - /// - /// Tests the class. - /// - public class Load_ComplexCases : IDisposable - { - private readonly Mock fileSystem; - private readonly Image returnImage; - private readonly Mock localDecoder; - private readonly string FilePath; - private readonly IImageFormatDetector localMimeTypeDetector; - private readonly Mock localImageFormatMock; - - public Configuration LocalConfiguration { get; private set; } - public byte[] Marker { get; private set; } - public MemoryStream DataStream { get; private set; } - public byte[] DecodedData { get; private set; } - - public Load_ComplexCases() - { - this.returnImage = new Image(1, 1); - - this.localImageFormatMock = new Mock(); - - this.localDecoder = new Mock(); - this.localMimeTypeDetector = new MockImageFormatDetector(this.localImageFormatMock.Object); - this.localDecoder.Setup(x => x.Decode(It.IsAny(), It.IsAny())) - - .Callback((c, s) => - { - using (var ms = new MemoryStream()) - { - s.CopyTo(ms); - this.DecodedData = ms.ToArray(); - } - }) - .Returns(this.returnImage); - - this.fileSystem = new Mock(); - - this.LocalConfiguration = new Configuration - { - FileSystem = this.fileSystem.Object - }; - this.LocalConfiguration.ImageFormatsManager.AddImageFormatDetector(this.localMimeTypeDetector); - this.LocalConfiguration.ImageFormatsManager.SetDecoder(this.localImageFormatMock.Object, this.localDecoder.Object); - - TestFormat.RegisterGlobalTestFormat(); - this.Marker = Guid.NewGuid().ToByteArray(); - this.DataStream = TestFormat.GlobalTestFormat.CreateStream(this.Marker); - - this.FilePath = Guid.NewGuid().ToString(); - this.fileSystem.Setup(x => x.OpenRead(this.FilePath)).Returns(this.DataStream); - - TestFileSystem.RegisterGlobalTestFormat(); - TestFileSystem.Global.AddFile(this.FilePath, this.DataStream); - } - - [Fact] - public void LoadFromStream() - { - var img = Image.Load(this.DataStream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromNoneSeekableStream() - { - var stream = new NoneSeekableStream(this.DataStream); - var img = Image.Load(stream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromStreamWithType() - { - var img = Image.Load(this.DataStream); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - - [Fact] - public void LoadFromStreamWithConfig() - { - Stream stream = new MemoryStream(); - var img = Image.Load(this.LocalConfiguration, stream); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); - } - - [Fact] - public void LoadFromStreamWithTypeAndConfig() - { - Stream stream = new MemoryStream(); - var img = Image.Load(this.LocalConfiguration, stream); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); - } - - - [Fact] - public void LoadFromStreamWithDecoder() - { - Stream stream = new MemoryStream(); - var img = Image.Load(stream, this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); - } - - [Fact] - public void LoadFromStreamWithTypeAndDecoder() - { - Stream stream = new MemoryStream(); - var img = Image.Load(stream, this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, stream)); - } - - [Fact] - public void LoadFromBytes() - { - var img = Image.Load(this.DataStream.ToArray()); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromBytesWithType() - { - var img = Image.Load(this.DataStream.ToArray()); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - - } - - [Fact] - public void LoadFromBytesWithConfig() - { - var img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); - - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithTypeAndConfig() - { - var img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); - - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithDecoder() - { - var img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromBytesWithTypeAndDecoder() - { - var img = Image.Load(this.DataStream.ToArray(), this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, It.IsAny())); - Assert.Equal(this.DataStream.ToArray(), this.DecodedData); - } - - [Fact] - public void LoadFromFile() - { - var img = Image.Load(this.DataStream); - - Assert.NotNull(img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromFileWithType() - { - var img = Image.Load(this.DataStream); - - Assert.NotNull(img); - Assert.Equal(TestFormat.GlobalTestFormat.Sample(), img); - - TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, Configuration.Default); - } - - [Fact] - public void LoadFromFileWithConfig() - { - var img = Image.Load(this.LocalConfiguration, this.FilePath); - - Assert.NotNull(img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithTypeAndConfig() - { - var img = Image.Load(this.LocalConfiguration, this.FilePath); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - - this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithDecoder() - { - var img = Image.Load(this.FilePath, this.localDecoder.Object); - - Assert.NotNull(img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); - } - - [Fact] - public void LoadFromFileWithTypeAndDecoder() - { - var img = Image.Load(this.FilePath, this.localDecoder.Object); - - Assert.NotNull(img); - Assert.Equal(this.returnImage, img); - this.localDecoder.Verify(x => x.Decode(Configuration.Default, this.DataStream)); - } - - [Fact] - public void LoadFromPixelData_Pixels() - { - var img = Image.LoadPixelData(new Rgba32[] { - Rgba32.Black, Rgba32.White, - Rgba32.White, Rgba32.Black, - }, 2, 2); - - Assert.NotNull(img); - Assert.Equal(Rgba32.Black, img[0, 0]); - Assert.Equal(Rgba32.White, img[0, 1]); - - Assert.Equal(Rgba32.White, img[1, 0]); - Assert.Equal(Rgba32.Black, img[1, 1]); - } - - [Fact] - public void LoadFromPixelData_Bytes() - { - var img = Image.LoadPixelData(new byte[] { - 0,0,0,255, // 0,0 - 255,255,255,255, // 0,1 - 255,255,255,255, // 1,0 - 0,0,0,255, // 1,1 - }, 2, 2); - - Assert.NotNull(img); - Assert.Equal(Rgba32.Black, img[0, 0]); - Assert.Equal(Rgba32.White, img[0, 1]); - - Assert.Equal(Rgba32.White, img[1, 0]); - Assert.Equal(Rgba32.Black, img[1, 1]); - } - - - [Fact] - public void LoadsImageWithoutThrowingCrcException() - { - var image1Provider = TestImageProvider.File(TestImages.Png.VersioningImage1); - - using (Image img = image1Provider.GetImage()) - { - Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); - } - } - - public void Dispose() - { - // clean up the global object; - this.returnImage?.Dispose(); - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath.cs new file mode 100644 index 000000000..70e8f729f --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FileSystemPath.cs @@ -0,0 +1,96 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests +{ + using Moq; + + using SixLabors.ImageSharp.IO; + + public partial class ImageTests + { + public class Load_FileSystemPath : ImageLoadTestBase + { + private readonly string filePath = Guid.NewGuid().ToString(); + private readonly Mock localFileSystemMock = new Mock(); + private readonly TestFileSystem topLevelFileSystem = new TestFileSystem(); + + public Load_FileSystemPath() + { + this.localFileSystemMock.Setup(x => x.OpenRead(this.filePath)).Returns(this.DataStream); + + this.topLevelFileSystem.AddFile(this.filePath, this.DataStream); + this.LocalConfiguration.FileSystem = this.localFileSystemMock.Object; + this.TopLevelConfiguration.FileSystem = this.topLevelFileSystem; + } + + [Fact] + public void BasicCase() + { + var img = Image.Load(this.TopLevelConfiguration, this.filePath); + + Assert.NotNull(img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void UseLocalConfiguration() + { + var img = Image.Load(this.LocalConfiguration, this.filePath); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, this.DataStream)); + } + + [Fact] + public void UseCustomDecoder() + { + var img = Image.Load(this.TopLevelConfiguration, this.filePath, this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream)); + } + + + [Fact] + public void UseGlobalConfigration() + { + var file = TestFile.Create(TestImages.Bmp.Car); + using (var image = Image.Load(file.FullPath)) + { + Assert.Equal(600, image.Width); + Assert.Equal(450, image.Height); + } + } + + [Fact] + public void WhenFileNotFound_Throws() + { + System.IO.FileNotFoundException ex = Assert.Throws( + () => + { + Image.Load(Guid.NewGuid().ToString()); + }); + } + + [Fact] + public void WhenPathIsNull_Throws() + { + ArgumentNullException ex = Assert.Throws( + () => + { + Image.Load((string)null); + }); + } + } + + + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes.cs new file mode 100644 index 000000000..23738758d --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromBytes.cs @@ -0,0 +1,64 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.IO; +using Moq; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; + +// ReSharper disable InconsistentNaming +namespace SixLabors.ImageSharp.Tests +{ + public partial class ImageTests + { + public class Load_FromBytes : ImageLoadTestBase + { + [Fact] + public void BasicCase() + { + var img = Image.Load(this.TopLevelConfiguration, this.DataStream.ToArray()); + + Assert.NotNull(img); + Assert.Equal(this.TestFormat.Sample(), img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void NonDefaultPixelType() + { + var img = Image.Load(this.TopLevelConfiguration, this.DataStream.ToArray()); + + Assert.NotNull(img); + Assert.Equal(this.TestFormat.Sample(), img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void UseLocalConfiguration() + { + var img = Image.Load(this.LocalConfiguration, this.DataStream.ToArray()); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, It.IsAny())); + + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + + [Fact] + public void UseCustomDecoder() + { + var img = Image.Load( + this.TopLevelConfiguration, + this.DataStream.ToArray(), + this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, It.IsAny())); + Assert.Equal(this.DataStream.ToArray(), this.DecodedData); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream.cs b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream.cs new file mode 100644 index 000000000..1b880a461 --- /dev/null +++ b/tests/ImageSharp.Tests/Image/ImageTests.Load_FromStream.cs @@ -0,0 +1,104 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.IO; + +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; + +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests +{ + public partial class ImageTests + { + /// + /// Tests the class. + /// + public class Load_FromStream : ImageLoadTestBase + { + [Fact] + public void BasicCase() + { + var img = Image.Load(this.TopLevelConfiguration, this.DataStream); + + Assert.NotNull(img); + Assert.Equal(this.TestFormat.Sample(), img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void NonDefaultPixelTypeImage() + { + var img = Image.Load(this.TopLevelConfiguration, this.DataStream); + + Assert.NotNull(img); + Assert.Equal(this.TestFormat.Sample(), img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void NonSeekableStream() + { + var stream = new NoneSeekableStream(this.DataStream); + var img = Image.Load(this.TopLevelConfiguration, stream); + + Assert.NotNull(img); + + this.TestFormat.VerifyDecodeCall(this.Marker, this.TopLevelConfiguration); + } + + [Fact] + public void UseLocalConfiguration() + { + Stream stream = new MemoryStream(); + var img = Image.Load(this.LocalConfiguration, stream); + + Assert.NotNull(img); + + this.localDecoder.Verify(x => x.Decode(this.LocalConfiguration, stream)); + } + + [Fact] + public void UseCustomDecoder() + { + Stream stream = new MemoryStream(); + var img = Image.Load(this.TopLevelConfiguration, stream, this.localDecoder.Object); + + Assert.NotNull(img); + this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, stream)); + } + + [Fact] + public void LoadFromPixelData_Pixels() + { + var img = Image.LoadPixelData(new Rgba32[] { + Rgba32.Black, Rgba32.White, + Rgba32.White, Rgba32.Black, + }, 2, 2); + + Assert.NotNull(img); + Assert.Equal(Rgba32.Black, img[0, 0]); + Assert.Equal(Rgba32.White, img[0, 1]); + + Assert.Equal(Rgba32.White, img[1, 0]); + Assert.Equal(Rgba32.Black, img[1, 1]); + } + + // TODO: This should be a png decoder test! + [Fact] + public void LoadsImageWithoutThrowingCrcException() + { + var image1Provider = TestImageProvider.File(TestImages.Png.VersioningImage1); + + using (Image img = image1Provider.GetImage()) + { + Assert.Equal(166036, img.Frames.RootFrame.GetPixelSpan().Length); + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestFormat.cs b/tests/ImageSharp.Tests/TestFormat.cs index 70e6c498a..64357a17e 100644 --- a/tests/ImageSharp.Tests/TestFormat.cs +++ b/tests/ImageSharp.Tests/TestFormat.cs @@ -18,13 +18,10 @@ namespace SixLabors.ImageSharp.Tests /// public class TestFormat : IConfigurationModule, IImageFormat { + // We should not change Configuration.Default in individual tests! + // Create new configuration instances with new Configuration(TestFormat.GlobalTestFormat) instead! public static TestFormat GlobalTestFormat { get; } = new TestFormat(); - public static void RegisterGlobalTestFormat() - { - Configuration.Default.Configure(GlobalTestFormat); - } - public TestFormat() { this.Encoder = new TestEncoder(this); @@ -155,12 +152,12 @@ namespace SixLabors.ImageSharp.Tests private TestFormat testFormat; - public int HeaderSize => testFormat.HeaderSize; + public int HeaderSize => this.testFormat.HeaderSize; public IImageFormat DetectFormat(ReadOnlySpan header) { - if (testFormat.IsSupportedFileFormat(header)) - return testFormat; + if (this.testFormat.IsSupportedFileFormat(header)) + return this.testFormat; return null; }