mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.5 KiB
112 lines
3.5 KiB
// <copyright file="PixelAccessorTests.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp.Tests
|
|
{
|
|
using System;
|
|
|
|
using ImageSharp.Formats;
|
|
using ImageSharp.PixelFormats;
|
|
|
|
using Xunit;
|
|
|
|
/// <summary>
|
|
/// Tests the <see cref="Image"/> class.
|
|
/// </summary>
|
|
public class ImageTests
|
|
{
|
|
[Fact]
|
|
public void ConstructorByteArray()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Image.Load<Rgba32>((byte[])null);
|
|
});
|
|
|
|
TestFile file = TestFile.Create(TestImages.Bmp.Car);
|
|
using (Image<Rgba32> image = Image.Load<Rgba32>(file.Bytes))
|
|
{
|
|
Assert.Equal(600, image.Width);
|
|
Assert.Equal(450, image.Height);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstructorFileSystem()
|
|
{
|
|
TestFile file = TestFile.Create(TestImages.Bmp.Car);
|
|
using (Image<Rgba32> image = Image.Load<Rgba32>(file.FilePath))
|
|
{
|
|
Assert.Equal(600, image.Width);
|
|
Assert.Equal(450, image.Height);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstructorFileSystem_FileNotFound()
|
|
{
|
|
System.IO.FileNotFoundException ex = Assert.Throws<System.IO.FileNotFoundException>(
|
|
() =>
|
|
{
|
|
Image.Load<Rgba32>(Guid.NewGuid().ToString());
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void ConstructorFileSystem_NullPath()
|
|
{
|
|
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
|
|
() =>
|
|
{
|
|
Image.Load<Rgba32>((string)null);
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void Save_DetecedEncoding()
|
|
{
|
|
string file = TestFile.GetPath("../../TestOutput/Save_DetecedEncoding.png");
|
|
System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file));
|
|
using (Image<Rgba32> image = new Image<Rgba32>(10, 10))
|
|
{
|
|
image.Save(file);
|
|
}
|
|
|
|
using (Image<Rgba32> img = Image.Load(file, out var mime))
|
|
{
|
|
Assert.Equal("image/png", mime.DefaultMimeType);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Save_UnknownExtensionsEncoding()
|
|
{
|
|
string file = TestFile.GetPath("../../TestOutput/Save_DetecedEncoding.tmp");
|
|
NotSupportedException ex = Assert.Throws<NotSupportedException>(
|
|
() =>
|
|
{
|
|
using (Image<Rgba32> image = new Image<Rgba32>(10, 10))
|
|
{
|
|
image.Save(file);
|
|
}
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void Save_SetEncoding()
|
|
{
|
|
string file = TestFile.GetPath("../../TestOutput/Save_SetEncoding.dat");
|
|
System.IO.DirectoryInfo dir = System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(file));
|
|
using (Image<Rgba32> image = new Image<Rgba32>(10, 10))
|
|
{
|
|
image.Save(file, new PngEncoder());
|
|
}
|
|
using (Image<Rgba32> img = Image.Load(file, out var mime))
|
|
{
|
|
Assert.Equal("image/png", mime.DefaultMimeType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|