📷 A modern, cross-platform, 2D Graphics library for .NET
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.
 
 

82 lines
2.5 KiB

// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
using SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder;
using SixLabors.ImageSharp.Formats.Jpeg.GolangPort;
using Xunit;
public class AdobeMarkerTests
{
// Taken from actual test image
private readonly byte[] bytes = { 0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x0, 0x0, 0x2 };
// Altered components
private readonly byte[] bytes2 = { 0x41, 0x64, 0x6F, 0x62, 0x65, 0x0, 0x64, 0x0, 0x0, 0x1, 0x1, 0x1 };
[Fact]
public void MarkerLengthIsCorrect()
{
Assert.Equal(12, AdobeMarker.Length);
}
[Fact]
public void MarkerReturnsCorrectParsedValue()
{
bool isAdobe = AdobeMarker.TryParse(this.bytes, out var marker);
Assert.True(isAdobe);
Assert.Equal(100, marker.DCTEncodeVersion);
Assert.Equal(0, marker.APP14Flags0);
Assert.Equal(0, marker.APP14Flags1);
Assert.Equal(OrigJpegConstants.Adobe.ColorTransformYcck, marker.ColorTransform);
}
[Fact]
public void MarkerIgnoresIncorrectValue()
{
bool isAdobe = AdobeMarker.TryParse(new byte[] { 0, 0, 0, 0 }, out var marker);
Assert.False(isAdobe);
Assert.Equal(default(AdobeMarker), marker);
}
[Fact]
public void MarkerEqualityIsCorrect()
{
AdobeMarker.TryParse(this.bytes, out var marker);
AdobeMarker.TryParse(this.bytes, out var marker2);
Assert.True(marker.Equals(marker2));
}
[Fact]
public void MarkerInEqualityIsCorrect()
{
AdobeMarker.TryParse(this.bytes, out var marker);
AdobeMarker.TryParse(this.bytes2, out var marker2);
Assert.False(marker.Equals(marker2));
}
[Fact]
public void MarkerHashCodeIsReplicable()
{
AdobeMarker.TryParse(this.bytes, out var marker);
AdobeMarker.TryParse(this.bytes, out var marker2);
Assert.True(marker.GetHashCode().Equals(marker2.GetHashCode()));
}
[Fact]
public void MarkerHashCodeIsUnique()
{
AdobeMarker.TryParse(this.bytes, out var marker);
AdobeMarker.TryParse(this.bytes2, out var marker2);
Assert.False(marker.GetHashCode().Equals(marker2.GetHashCode()));
}
}
}