mirror of https://github.com/SixLabors/ImageSharp
7 changed files with 162 additions and 19 deletions
@ -0,0 +1,88 @@ |
|||
// Copyright (c) Six Labors and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using SixLabors.ImageSharp.Formats.Jpeg; |
|||
using SixLabors.ImageSharp.Metadata.Profiles.Iptc; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
using Xunit; |
|||
|
|||
namespace SixLabors.ImageSharp.Tests.Metadata.Profiles.IPTC |
|||
{ |
|||
public class IptcProfileTests |
|||
{ |
|||
private static JpegDecoder JpegDecoder => new JpegDecoder() { IgnoreMetadata = false }; |
|||
|
|||
[Theory] |
|||
[WithFile(TestImages.Jpeg.Baseline.Iptc, PixelTypes.Rgba32)] |
|||
public void ReadIptcProfile<TPixel>(TestImageProvider<TPixel> provider) |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
using (Image<TPixel> image = provider.GetImage(JpegDecoder)) |
|||
{ |
|||
Assert.NotNull(image.Metadata.IptcProfile); |
|||
IEnumerable<IptcValue> iptcValues = image.Metadata.IptcProfile.Values; |
|||
ContainsIptcValue(iptcValues, IptcTag.Caption, "description"); |
|||
ContainsIptcValue(iptcValues, IptcTag.CaptionWriter, "description writer"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Headline, "headline"); |
|||
ContainsIptcValue(iptcValues, IptcTag.SpecialInstructions, "special instructions"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Byline, "author"); |
|||
ContainsIptcValue(iptcValues, IptcTag.BylineTitle, "author title"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Credit, "credits"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Source, "source"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Title, "title"); |
|||
ContainsIptcValue(iptcValues, IptcTag.CreatedDate, "20200414"); |
|||
ContainsIptcValue(iptcValues, IptcTag.City, "city"); |
|||
ContainsIptcValue(iptcValues, IptcTag.SubLocation, "sublocation"); |
|||
ContainsIptcValue(iptcValues, IptcTag.ProvinceState, "province-state"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Country, "country"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Category, "category"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Priority, "1"); |
|||
ContainsIptcValue(iptcValues, IptcTag.Keyword, "keywords"); |
|||
ContainsIptcValue(iptcValues, IptcTag.CopyrightNotice, "copyright"); |
|||
} |
|||
} |
|||
|
|||
[Fact] |
|||
public void IptcProfile_CloneIsDeep() |
|||
{ |
|||
// arrange
|
|||
var profile = new IptcProfile(); |
|||
var captionWriter = "unittest"; |
|||
var caption = "test"; |
|||
profile.SetValue(IptcTag.CaptionWriter, captionWriter); |
|||
profile.SetValue(IptcTag.Caption, caption); |
|||
|
|||
// act
|
|||
IptcProfile clone = profile.DeepClone(); |
|||
clone.SetValue(IptcTag.Caption, "changed"); |
|||
|
|||
// assert
|
|||
Assert.Equal(2, clone.Values.Count()); |
|||
ContainsIptcValue(clone.Values, IptcTag.CaptionWriter, captionWriter); |
|||
ContainsIptcValue(clone.Values, IptcTag.Caption, "changed"); |
|||
ContainsIptcValue(profile.Values, IptcTag.Caption, caption); |
|||
} |
|||
|
|||
[Fact] |
|||
public void IptcValue_CloneIsDeep() |
|||
{ |
|||
// arrange
|
|||
var iptcValue = new IptcValue(IptcTag.Caption, System.Text.Encoding.UTF8, "test"); |
|||
|
|||
// act
|
|||
IptcValue clone = iptcValue.DeepClone(); |
|||
clone.Value = "changed"; |
|||
|
|||
// assert
|
|||
Assert.NotEqual(iptcValue.Value, clone.Value); |
|||
} |
|||
|
|||
private static void ContainsIptcValue(IEnumerable<IptcValue> values, IptcTag tag, string value) |
|||
{ |
|||
Assert.True(values.Any(val => val.Tag == tag), $"Missing iptc tag {tag}"); |
|||
Assert.True(values.Contains(new IptcValue(tag, System.Text.Encoding.UTF8.GetBytes(value))), $"expected iptc value '{value}' was not found for tag '{tag}'"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:6c8a0747d9282bfd7e8e7f4a0119c53c702bf600384b786ef9b5263457f38ada |
|||
size 18611 |
|||
Loading…
Reference in new issue