Browse Source

Refactor Identify tests

pull/2317/head
James Jackson-South 3 years ago
parent
commit
7139a52848
  1. 36
      src/ImageSharp/Image.FromBytes.cs
  2. 55
      src/ImageSharp/Image.FromFile.cs
  3. 71
      src/ImageSharp/Image.FromStream.cs
  4. 4
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  5. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs
  6. 4
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  7. 2
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  8. 6
      tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs
  9. 4
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  10. 6
      tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs
  11. 2
      tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs
  12. 4
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs
  13. 4
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  14. 4
      tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs
  15. 2
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  16. 2
      tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs
  17. 79
      tests/ImageSharp.Tests/Image/ImageTests.Identify.cs

36
src/ImageSharp/Image.FromBytes.cs

@ -55,41 +55,31 @@ public abstract partial class Image
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="buffer">The byte array containing encoded image data to read the header from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The data is null.</exception>
/// <exception cref="NotSupportedException">The data is not readable.</exception>
public static bool TryIdentify(ReadOnlySpan<byte> buffer, [NotNullWhen(true)] out ImageInfo? info)
=> TryIdentify(DecoderOptions.Default, buffer, out info);
/// <returns>The <see cref="ImageInfo"/>.</returns>
/// <exception cref="NotSupportedException">The image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static ImageInfo Identify(ReadOnlySpan<byte> buffer)
=> Identify(DecoderOptions.Default, buffer);
/// <summary>
/// Reads the raw image information from the specified span of bytes without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="buffer">The byte span containing encoded image data to read the header from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The data is null.</exception>
/// <exception cref="NotSupportedException">The data is not readable.</exception>
public static unsafe bool TryIdentify(DecoderOptions options, ReadOnlySpan<byte> buffer, [NotNullWhen(true)] out ImageInfo? info)
/// <returns>The <see cref="ImageInfo"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="NotSupportedException">The image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static unsafe ImageInfo Identify(DecoderOptions options, ReadOnlySpan<byte> buffer)
{
fixed (byte* ptr = buffer)
{
using UnmanagedMemoryStream stream = new(ptr, buffer.Length);
return TryIdentify(options, stream, out info);
return Identify(options, stream);
}
}

55
src/ImageSharp/Image.FromFile.cs

@ -84,70 +84,71 @@ public abstract partial class Image
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="path">The image file to open and to read the header from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
public static bool TryIdentify(string path, [NotNullWhen(true)] out ImageInfo? info)
=> TryIdentify(DecoderOptions.Default, path, out info);
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static ImageInfo Identify(string path)
=> Identify(DecoderOptions.Default, path);
/// <summary>
/// Reads the raw image information from the specified file path without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The image file to open and to read the header from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <returns>The <see cref="ImageInfo"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
public static bool TryIdentify(DecoderOptions options, string path, [NotNullWhen(true)] out ImageInfo? info)
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static ImageInfo Identify(DecoderOptions options, string path)
{
Guard.NotNull(options, nameof(options));
using Stream stream = options.Configuration.FileSystem.OpenRead(path);
return TryIdentify(options, stream, out info);
return Identify(options, stream);
}
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="path">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{ImageInfo}"/> representing the asynchronous operation.
/// </returns>
public static Task<Attempt<ImageInfo>> TryIdentifyAsync(
string path,
CancellationToken cancellationToken = default)
=> TryIdentifyAsync(DecoderOptions.Default, path, cancellationToken);
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task<ImageInfo> IdentifyAsync(string path, CancellationToken cancellationToken = default)
=> IdentifyAsync(DecoderOptions.Default, path, cancellationToken);
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{ImageInfo}"/> representing the asynchronous operation.
/// </returns>
public static async Task<Attempt<ImageInfo>> TryIdentifyAsync(
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static async Task<ImageInfo> IdentifyAsync(
DecoderOptions options,
string path,
CancellationToken cancellationToken = default)
{
Guard.NotNull(options, nameof(options));
using Stream stream = options.Configuration.FileSystem.OpenRead(path);
return await TryIdentifyAsync(options, stream, cancellationToken).ConfigureAwait(false);
return await IdentifyAsync(options, stream, cancellationToken).ConfigureAwait(false);
}
/// <summary>

71
src/ImageSharp/Image.FromStream.cs

@ -91,87 +91,70 @@ public abstract partial class Image
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="stream">The image stream to read the header from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
public static bool TryIdentify(Stream stream, [NotNullWhen(true)] out ImageInfo? info)
=> TryIdentify(DecoderOptions.Default, stream, out info);
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static ImageInfo Identify(Stream stream)
=> Identify(DecoderOptions.Default, stream);
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="stream">The image stream to read the information from.</param>
/// <param name="info">
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <returns>The <see cref="ImageInfo"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
public static bool TryIdentify(DecoderOptions options, Stream stream, [NotNullWhen(true)] out ImageInfo? info)
{
info = WithSeekableStream(options, stream, s => InternalIdentify(options, s));
return info is not null;
}
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static ImageInfo Identify(DecoderOptions options, Stream stream)
=> WithSeekableStream(options, stream, s => InternalIdentify(options, s));
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="stream">The image stream to read the information from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{ImageInfo}"/> representing the asynchronous operation.
/// </returns>
public static Task<Attempt<ImageInfo>> TryIdentifyAsync(
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task<ImageInfo> IdentifyAsync(
Stream stream,
CancellationToken cancellationToken = default)
=> TryIdentifyAsync(DecoderOptions.Default, stream, cancellationToken);
=> IdentifyAsync(DecoderOptions.Default, stream, cancellationToken);
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="stream">The image stream to read the information from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{ImageInfo}"/> representing the asynchronous operation.
/// </returns>
public static async Task<Attempt<ImageInfo>> TryIdentifyAsync(
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The stream is null.</exception>
/// <exception cref="NotSupportedException">The stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task<ImageInfo> IdentifyAsync(
DecoderOptions options,
Stream stream,
CancellationToken cancellationToken = default)
{
ImageInfo? info = await WithSeekableStreamAsync(
=> WithSeekableStreamAsync(
options,
stream,
(s, ct) => InternalIdentifyAsync(options, s, ct),
cancellationToken).ConfigureAwait(false);
return new() { Value = info };
}
cancellationToken);
/// <summary>
/// Creates a new instance of the <see cref="Image"/> class from the given stream.

4
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -475,7 +475,7 @@ public class BmpDecoderTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedPixelSize, imageInfo.PixelType?.BitsPerPixel);
}
@ -493,7 +493,7 @@ public class BmpDecoderTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedWidth, imageInfo.Width);
Assert.Equal(expectedHeight, imageInfo.Height);

2
tests/ImageSharp.Tests/Formats/Bmp/BmpMetadataTests.cs

@ -38,7 +38,7 @@ public class BmpMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
BmpMetadata bitmapMetadata = imageInfo.Metadata.GetBmpMetadata();
Assert.NotNull(bitmapMetadata);

4
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -256,7 +256,7 @@ public class GeneralFormatTests
image.Save(memoryStream, format);
memoryStream.Position = 0;
Image.TryIdentify(memoryStream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(memoryStream);
Assert.Equal(imageInfo.Width, width);
Assert.Equal(imageInfo.Height, height);
@ -270,7 +270,7 @@ public class GeneralFormatTests
using MemoryStream memoryStream = new(invalid);
Assert.Throws<UnknownImageFormatException>(() => Image.TryIdentify(invalid, out ImageInfo imageInfo));
Assert.Throws<UnknownImageFormatException>(() => Image.Identify(invalid));
}
private static IImageFormat GetFormat(string format)

2
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -123,7 +123,7 @@ public class GifDecoderTests
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel);

6
tests/ImageSharp.Tests/Formats/Pbm/PbmMetadataTests.cs

@ -36,7 +36,7 @@ public class PbmMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata();
Assert.NotNull(bitmapMetadata);
@ -55,7 +55,7 @@ public class PbmMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata();
Assert.NotNull(bitmapMetadata);
@ -74,7 +74,7 @@ public class PbmMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
PbmMetadata bitmapMetadata = imageInfo.Metadata.GetPbmMetadata();
Assert.NotNull(bitmapMetadata);

4
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -307,7 +307,7 @@ public partial class PngDecoderTests
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedPixelSize, imageInfo.PixelType.BitsPerPixel);
@ -508,7 +508,7 @@ public partial class PngDecoderTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
PngMetadata metadata = imageInfo.Metadata.GetPngMetadata();
Assert.True(metadata.HasTransparency);
}

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

@ -232,7 +232,7 @@ public class PngMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
PngMetadata meta = imageInfo.Metadata.GetFormatMetadata(PngFormat.Instance);
VerifyTextDataIsPresent(meta);
@ -244,7 +244,7 @@ public class PngMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.NotNull(imageInfo.Metadata.ExifProfile);
ExifProfile exif = imageInfo.Metadata.ExifProfile;
@ -281,7 +281,7 @@ public class PngMetadataTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.NotNull(imageInfo.Metadata.ExifProfile);

2
tests/ImageSharp.Tests/Formats/Tga/TgaFileHeaderTests.cs

@ -41,7 +41,7 @@ public class TgaFileHeaderTests
{
using MemoryStream stream = new(data);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
TgaMetadata tgaData = info.Metadata.GetTgaMetadata();
Assert.Equal(bitsPerPixel, tgaData.BitsPerPixel);
Assert.Equal(width, info.Width);

4
tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs

@ -62,7 +62,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel);
Assert.Equal(expectedWidth, info.Width);
@ -84,7 +84,7 @@ public class BigTiffDecoderTests : TiffDecoderBaseTester
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.NotNull(info.Metadata);
Assert.Equal(expectedByteOrder, info.Metadata.GetTiffMetadata().ByteOrder);

4
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

@ -32,7 +32,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.Equal(expectedPixelSize, info.PixelType?.BitsPerPixel);
Assert.Equal(expectedWidth, info.Width);
@ -50,7 +50,7 @@ public class TiffDecoderTests : TiffDecoderBaseTester
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.NotNull(info.Metadata);
Assert.Equal(expectedByteOrder, info.Metadata.GetTiffMetadata().ByteOrder);

4
tests/ImageSharp.Tests/Formats/Tiff/TiffMetadataTests.cs

@ -80,7 +80,7 @@ public class TiffMetadataTests
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();
@ -96,7 +96,7 @@ public class TiffMetadataTests
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
TiffMetadata tiffMetadata = imageInfo.Metadata.GetTiffMetadata();

2
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -41,7 +41,7 @@ public class WebpDecoderTests
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
Image.TryIdentify(stream, out ImageInfo imageInfo);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedWidth, imageInfo.Width);
Assert.Equal(expectedHeight, imageInfo.Height);

2
tests/ImageSharp.Tests/Image/ImageTests.Decode_Cancellation.cs

@ -34,7 +34,7 @@ public partial class ImageTests
{
using FileStream fs = File.OpenRead(TestFile.GetInputFileFullPath(file));
CancellationToken preCancelled = new(canceled: true);
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await Image.TryIdentifyAsync(fs, preCancelled));
await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await Image.IdentifyAsync(fs, preCancelled));
}
private static TheoryData<bool, string, double> CreateLoadData()

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

@ -33,7 +33,7 @@ public partial class ImageTests
[Fact]
public void FromBytes_GlobalConfiguration()
{
Image.TryIdentify(ActualImageBytes, out ImageInfo info);
ImageInfo info = Image.Identify(ActualImageBytes);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
@ -42,7 +42,7 @@ public partial class ImageTests
public void FromBytes_CustomConfiguration()
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Image.TryIdentify(options, this.ByteArray, out ImageInfo info);
ImageInfo info = Image.Identify(options, this.ByteArray);
Assert.Equal(this.LocalImageInfo, info);
}
@ -50,7 +50,7 @@ public partial class ImageTests
[Fact]
public void FromFileSystemPath_GlobalConfiguration()
{
Image.TryIdentify(ActualImagePath, out ImageInfo info);
ImageInfo info = Image.Identify(ActualImagePath);
Assert.NotNull(info);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
@ -61,7 +61,7 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Image.TryIdentify(options, this.MockFilePath, out ImageInfo info);
ImageInfo info = Image.Identify(options, this.MockFilePath);
Assert.Equal(this.LocalImageInfo, info);
}
@ -70,7 +70,7 @@ public partial class ImageTests
public void FromStream_GlobalConfiguration()
{
using MemoryStream stream = new(ActualImageBytes);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.NotNull(info);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
@ -80,7 +80,7 @@ public partial class ImageTests
public void FromStream_GlobalConfiguration_NoFormat()
{
using MemoryStream stream = new(ActualImageBytes);
Image.TryIdentify(stream, out ImageInfo info);
ImageInfo info = Image.Identify(stream);
Assert.NotNull(info);
}
@ -91,7 +91,7 @@ public partial class ImageTests
using MemoryStream stream = new(ActualImageBytes);
using NonSeekableStream nonSeekableStream = new(stream);
Image.TryIdentify(nonSeekableStream, out ImageInfo info);
ImageInfo info = Image.Identify(nonSeekableStream);
Assert.NotNull(info);
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
@ -103,7 +103,7 @@ public partial class ImageTests
using MemoryStream stream = new(ActualImageBytes);
using NonSeekableStream nonSeekableStream = new(stream);
Image.TryIdentify(nonSeekableStream, out ImageInfo info);
ImageInfo info = Image.Identify(nonSeekableStream);
Assert.NotNull(info);
}
@ -113,7 +113,7 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Image.TryIdentify(options, this.DataStream, out ImageInfo info);
ImageInfo info = Image.Identify(options, this.DataStream);
Assert.Equal(this.LocalImageInfo, info);
}
@ -123,7 +123,7 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Image.TryIdentify(options, this.DataStream, out ImageInfo info);
ImageInfo info = Image.Identify(options, this.DataStream);
Assert.Equal(this.LocalImageInfo, info);
}
@ -133,7 +133,7 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = new() };
Assert.Throws<UnknownImageFormatException>(() => Image.TryIdentify(options, this.DataStream, out ImageInfo info));
Assert.Throws<UnknownImageFormatException>(() => Image.Identify(options, this.DataStream));
}
[Fact]
@ -156,7 +156,7 @@ public partial class ImageTests
}));
using Stream stream = zipFile.Entries[0].Open();
Assert.Throws<UnknownImageFormatException>(() => Image.TryIdentify(stream, out ImageInfo info));
Assert.Throws<UnknownImageFormatException>(() => Image.Identify(stream));
}
[Fact]
@ -165,10 +165,8 @@ public partial class ImageTests
using MemoryStream stream = new(ActualImageBytes);
AsyncStreamWrapper asyncStream = new(stream, () => false);
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(asyncStream);
Assert.True(attempt.Success);
Assert.NotNull(attempt.Value);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.NotNull(info);
}
[Fact]
@ -176,11 +174,10 @@ public partial class ImageTests
{
using MemoryStream stream = new(ActualImageBytes);
AsyncStreamWrapper asyncStream = new(stream, () => false);
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(asyncStream);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.True(attempt.Success);
Assert.Equal(ExpectedImageSize, attempt.Value.Size());
Assert.Equal(ExpectedGlobalFormat, attempt.Value.Metadata.DecodedImageFormat);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
[Fact]
@ -190,10 +187,9 @@ public partial class ImageTests
using NonSeekableStream nonSeekableStream = new(stream);
AsyncStreamWrapper asyncStream = new(nonSeekableStream, () => false);
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(asyncStream);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.True(attempt.Success);
Assert.NotNull(attempt.Value);
Assert.NotNull(info);
}
[Fact]
@ -203,11 +199,10 @@ public partial class ImageTests
using NonSeekableStream nonSeekableStream = new(stream);
AsyncStreamWrapper asyncStream = new(nonSeekableStream, () => false);
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(asyncStream);
ImageInfo info = await Image.IdentifyAsync(asyncStream);
Assert.True(attempt.Success);
Assert.Equal(ExpectedImageSize, attempt.Value.Size());
Assert.Equal(ExpectedGlobalFormat, attempt.Value.Metadata.DecodedImageFormat);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
[Fact]
@ -230,7 +225,7 @@ public partial class ImageTests
}));
using Stream stream = zipFile.Entries[0].Open();
await Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.TryIdentifyAsync(stream));
await Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.IdentifyAsync(stream));
}
[Fact]
@ -238,10 +233,9 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(options, this.MockFilePath);
ImageInfo info = await Image.IdentifyAsync(options, this.MockFilePath);
Assert.True(attempt.Success);
Assert.Equal(this.LocalImageInfo, attempt.Value);
Assert.Equal(this.LocalImageInfo, info);
}
[Fact]
@ -249,28 +243,26 @@ public partial class ImageTests
{
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(options, this.MockFilePath);
ImageInfo info = await Image.IdentifyAsync(options, this.MockFilePath);
Assert.True(attempt.Success);
Assert.NotNull(attempt.Value);
Assert.NotNull(info);
}
[Fact]
public async Task IdentifyWithFormatAsync_FromPath_GlobalConfiguration()
{
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(ActualImagePath);
ImageInfo info = await Image.IdentifyAsync(ActualImagePath);
Assert.Equal(ExpectedImageSize, attempt.Value.Size());
Assert.Equal(ExpectedGlobalFormat, attempt.Value.Metadata.DecodedImageFormat);
Assert.Equal(ExpectedImageSize, info.Size());
Assert.Equal(ExpectedGlobalFormat, info.Metadata.DecodedImageFormat);
}
[Fact]
public async Task FromPathAsync_GlobalConfiguration()
{
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(ActualImagePath);
ImageInfo info = await Image.IdentifyAsync(ActualImagePath);
Assert.True(attempt.Success);
Assert.Equal(ExpectedImageSize, attempt.Value.Size());
Assert.Equal(ExpectedImageSize, info.Size());
}
[Fact]
@ -279,10 +271,9 @@ public partial class ImageTests
DecoderOptions options = new() { Configuration = this.LocalConfiguration };
AsyncStreamWrapper asyncStream = new(this.DataStream, () => false);
Attempt<ImageInfo> attempt = await Image.TryIdentifyAsync(options, asyncStream);
ImageInfo info = await Image.IdentifyAsync(options, asyncStream);
Assert.True(attempt.Success);
Assert.Equal(this.LocalImageInfo, attempt.Value);
Assert.Equal(this.LocalImageInfo, info);
}
[Fact]
@ -291,7 +282,7 @@ public partial class ImageTests
DecoderOptions options = new() { Configuration = new() };
AsyncStreamWrapper asyncStream = new(this.DataStream, () => false);
return Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.TryIdentifyAsync(options, asyncStream));
return Assert.ThrowsAsync<UnknownImageFormatException>(async () => await Image.IdentifyAsync(options, asyncStream));
}
}
}

Loading…
Cancel
Save