mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 234 additions and 119 deletions
@ -1,83 +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 |
|||
{ |
|||
using Moq; |
|||
|
|||
using SixLabors.ImageSharp.IO; |
|||
|
|||
public partial class ImageTests |
|||
{ |
|||
public class Load_FileSystemPath : ImageLoadTestBase |
|||
{ |
|||
[Fact] |
|||
public void BasicCase() |
|||
{ |
|||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, this.MockFilePath); |
|||
|
|||
Assert.NotNull(img); |
|||
|
|||
this.TestFormat.VerifySpecificDecodeCall<Rgba32>(this.Marker, this.TopLevelConfiguration); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UseLocalConfiguration() |
|||
{ |
|||
var img = Image.Load<Rgba32>(this.LocalConfiguration, this.MockFilePath); |
|||
|
|||
Assert.NotNull(img); |
|||
|
|||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.LocalConfiguration, this.DataStream)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void UseCustomDecoder() |
|||
{ |
|||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, this.MockFilePath, this.localDecoder.Object); |
|||
|
|||
Assert.NotNull(img); |
|||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.TopLevelConfiguration, this.DataStream)); |
|||
} |
|||
|
|||
|
|||
[Fact] |
|||
public void UseGlobalConfigration() |
|||
{ |
|||
var file = TestFile.Create(TestImages.Bmp.Car); |
|||
using (var image = Image.Load<Rgba32>(file.FullPath)) |
|||
{ |
|||
Assert.Equal(600, image.Width); |
|||
Assert.Equal(450, image.Height); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void WhenFileNotFound_Throws() |
|||
{ |
|||
System.IO.FileNotFoundException ex = Assert.Throws<System.IO.FileNotFoundException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>(Guid.NewGuid().ToString()); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void WhenPathIsNull_Throws() |
|||
{ |
|||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>((string)null); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,100 @@ |
|||
// // Copyright (c) Six Labors and contributors.
|
|||
// // Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests |
|||
{ |
|||
public partial class ImageTests |
|||
{ |
|||
public class Load_FileSystemPath_PassLocalConfiguration : ImageLoadTestBase |
|||
{ |
|||
[Fact] |
|||
public void Configuration_Path_Specific() |
|||
{ |
|||
var img = Image.Load<Rgb24>(this.TopLevelConfiguration, this.MockFilePath); |
|||
|
|||
Assert.NotNull(img); |
|||
Assert.Equal(this.TestFormat.Sample<Rgb24>(), img); |
|||
|
|||
this.TestFormat.VerifySpecificDecodeCall<Rgb24>(this.Marker, this.TopLevelConfiguration); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Configuration_Path_Agnostic() |
|||
{ |
|||
var img = Image.Load(this.TopLevelConfiguration, this.MockFilePath); |
|||
|
|||
Assert.NotNull(img); |
|||
Assert.Equal(this.TestFormat.SampleAgnostic(), img); |
|||
|
|||
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Configuration_Path_Decoder_Specific() |
|||
{ |
|||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, this.MockFilePath, this.localDecoder.Object); |
|||
|
|||
Assert.NotNull(img); |
|||
this.localDecoder.Verify(x => x.Decode<Rgba32>(this.TopLevelConfiguration, this.DataStream)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Configuration_Path_Decoder_Agnostic() |
|||
{ |
|||
var img = Image.Load(this.TopLevelConfiguration, this.MockFilePath, this.localDecoder.Object); |
|||
|
|||
Assert.NotNull(img); |
|||
this.localDecoder.Verify(x => x.Decode(this.TopLevelConfiguration, this.DataStream)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Configuration_Path_OutFormat_Specific() |
|||
{ |
|||
var img = Image.Load<Rgba32>(this.TopLevelConfiguration, this.MockFilePath, out IImageFormat format); |
|||
|
|||
Assert.NotNull(img); |
|||
Assert.Equal(this.TestFormat, format); |
|||
|
|||
this.TestFormat.VerifySpecificDecodeCall<Rgba32>(this.Marker, this.TopLevelConfiguration); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Configuration_Path_OutFormat_Agnostic() |
|||
{ |
|||
var img = Image.Load(this.TopLevelConfiguration, this.MockFilePath, out IImageFormat format); |
|||
|
|||
Assert.NotNull(img); |
|||
Assert.Equal(this.TestFormat, format); |
|||
|
|||
this.TestFormat.VerifyAgnosticDecodeCall(this.Marker, this.TopLevelConfiguration); |
|||
} |
|||
|
|||
[Fact] |
|||
public void WhenFileNotFound_Throws() |
|||
{ |
|||
System.IO.FileNotFoundException ex = Assert.Throws<System.IO.FileNotFoundException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>(this.TopLevelConfiguration, Guid.NewGuid().ToString()); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void WhenPathIsNull_Throws() |
|||
{ |
|||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>(this.TopLevelConfiguration,(string)null); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,103 @@ |
|||
// // Copyright (c) Six Labors and contributors.
|
|||
// // Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
|
|||
using SixLabors.ImageSharp.Formats; |
|||
using SixLabors.ImageSharp.Formats.Bmp; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using SixLabors.Primitives; |
|||
|
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests |
|||
{ |
|||
public partial class ImageTests |
|||
{ |
|||
public class Load_FileSystemPath_UseDefaultConfiguration |
|||
{ |
|||
private string Path { get; } = TestFile.GetInputFileFullPath(TestImages.Bmp.Bit8); |
|||
|
|||
private static void VerifyDecodedImage(Image img) |
|||
{ |
|||
Assert.Equal(new Size(127, 64), img.Size()); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Path_Specific() |
|||
{ |
|||
using (var img = Image.Load<Rgba32>(this.Path)) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Path_Agnostic() |
|||
{ |
|||
using (var img = Image.Load(this.Path)) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
} |
|||
} |
|||
|
|||
|
|||
[Fact] |
|||
public void Path_Decoder_Specific() |
|||
{ |
|||
using (var img = Image.Load<Rgba32>(this.Path, new BmpDecoder())) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Path_Decoder_Agnostic() |
|||
{ |
|||
using (var img = Image.Load(this.Path, new BmpDecoder())) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Path_OutFormat_Specific() |
|||
{ |
|||
using (var img = Image.Load<Rgba32>(this.Path, out IImageFormat format)) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
Assert.IsType<BmpFormat>(format); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void Path_OutFormat_Agnostic() |
|||
{ |
|||
using (var img = Image.Load(this.Path, out IImageFormat format)) |
|||
{ |
|||
VerifyDecodedImage(img); |
|||
Assert.IsType<BmpFormat>(format); |
|||
} |
|||
} |
|||
[Fact] |
|||
public void WhenFileNotFound_Throws() |
|||
{ |
|||
System.IO.FileNotFoundException ex = Assert.Throws<System.IO.FileNotFoundException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>(Guid.NewGuid().ToString()); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public void WhenPathIsNull_Throws() |
|||
{ |
|||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>( |
|||
() => |
|||
{ |
|||
Image.Load<Rgba32>((string)null); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue