Browse Source

Add long8 tests

pull/1760/head
Ildar Khayrutdinov 5 years ago
parent
commit
dfcb74305b
  1. 13
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs
  2. 3
      src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs
  3. 7
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffDecoderTests.cs
  4. 90
      tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs

13
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8.cs

@ -35,6 +35,18 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
switch (value)
{
case int intValue:
if (intValue >= uint.MinValue)
{
this.Value = (uint)intValue;
return true;
}
return false;
case uint uintValue:
this.Value = uintValue;
return true;
case long intValue:
if (intValue >= 0)
{
@ -44,6 +56,7 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
return false;
default:
return false;
}
}

3
src/ImageSharp/Metadata/Profiles/Exif/Values/ExifLong8Array.cs

@ -64,6 +64,9 @@ namespace SixLabors.ImageSharp.Metadata.Profiles.Exif
case ushort val:
return this.SetSingle((ulong)val);
case long val:
return this.SetSingle((ulong)Numerics.Clamp(val, 0, long.MaxValue));
case long[] array:
{
if (value.GetType() == typeof(ulong[]))

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

@ -3,22 +3,19 @@
// ReSharper disable InconsistentNaming
using System;
using System.Linq;
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
using static SixLabors.ImageSharp.Tests.TestImages.BigTiff;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Collection("RunSerial")]
[Trait("Format", "Tiff")]
[Trait("Format", "BigTiff")]
public class BigTiffDecoderTests : TiffDecoderBaseTester
{
[Theory]

90
tests/ImageSharp.Tests/Formats/Tiff/BigTiffMetadataTests.cs

@ -0,0 +1,90 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats.Tiff;
using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Tiff
{
[Trait("Format", "Tiff")]
public class BigTiffMetadataTests
{
private static TiffDecoder TiffDecoder => new TiffDecoder();
[Fact]
public void ExifLong8()
{
var long8 = new ExifLong8(ExifTagValue.StripByteCounts);
Assert.True(long8.TrySetValue(0));
Assert.Equal(0UL, long8.GetValue());
Assert.True(long8.TrySetValue(100u));
Assert.Equal(100UL, long8.GetValue());
Assert.True(long8.TrySetValue(ulong.MaxValue));
Assert.Equal(ulong.MaxValue, long8.GetValue());
Assert.False(long8.TrySetValue(-65));
Assert.Equal(ulong.MaxValue, long8.GetValue());
}
[Fact]
public void ExifSignedLong8()
{
var long8 = new ExifSignedLong8(ExifTagValue.ImageID);
Assert.False(long8.TrySetValue(0));
Assert.True(long8.TrySetValue(0L));
Assert.Equal(0L, long8.GetValue());
Assert.True(long8.TrySetValue(-100L));
Assert.Equal(-100L, long8.GetValue());
Assert.True(long8.TrySetValue(100L));
Assert.Equal(100L, long8.GetValue());
}
[Fact]
public void ExifLong8Array()
{
var long8 = new ExifLong8Array(ExifTagValue.StripOffsets);
Assert.True(long8.TrySetValue((short)-123));
Assert.Equal(new[] { 0UL }, long8.GetValue());
Assert.True(long8.TrySetValue((ushort)123));
Assert.Equal(new[] { 123UL }, long8.GetValue());
Assert.True(long8.TrySetValue((short)123));
Assert.Equal(new[] { 123UL }, long8.GetValue());
Assert.True(long8.TrySetValue(123));
Assert.Equal(new[] { 123UL }, long8.GetValue());
Assert.True(long8.TrySetValue(123L));
Assert.Equal(new[] { 123UL }, long8.GetValue());
Assert.True(long8.TrySetValue(123UL));
Assert.Equal(new[] { 123UL }, long8.GetValue());
Assert.True(long8.TrySetValue(new[] { 1, 2, 3, 4 }));
Assert.Equal(new[] { 1UL, 2UL, 3UL, 4UL }, long8.GetValue());
}
[Fact]
public void ExifSignedLong8Array()
{
var long8 = new ExifSignedLong8Array(ExifTagValue.StripOffsets);
Assert.True(long8.TrySetValue(new[] { 0L }));
Assert.Equal(new[] { 0L }, long8.GetValue());
Assert.True(long8.TrySetValue(new[] { -1L, 2L, -3L, 4L }));
Assert.Equal(new[] { -1L, 2L, -3L, 4L }, long8.GetValue());
}
}
}
Loading…
Cancel
Save