public string GetLangAltNodeTest( [PexAssumeUnderTest] XmpTag target, string ns, string name, string value ) { PexAssume.IsNotNull(ns); PexAssume.IsNotNull(name); target.SetLangAltNode(ns, name, value); string result = target.GetLangAltNode(ns, name); PexAssert.AreEqual(result, value); return(result); // TODO: add assertions to method XmpTagTest.GetLangAltNodeTest(XmpTag, String, String) }
private void AddAllQualifiersTo(XmlNode xml) { if (qualifiers == null) { return; } foreach (var collection in qualifiers.Values) { foreach (XmpNode node in collection.Values) { XmlAttribute attr = XmpTag.CreateAttribute(xml.OwnerDocument, node.Name, node.Namespace); attr.Value = node.Value; xml.Attributes.Append(attr); } } }
/// <summary> /// Set the copyright. This is tricky because when we do tagMain.Copyright = value, /// this sets the rights:default langauge to that string (as we wish), as well as setting /// copyright in any other tag that may be present and support it. We don't want to bypass /// setting copyright on other tags, so we need to set it on tagMain, not just do something /// to the xmp. /// However, taglib clears all other alternatives of rights when it does this. /// We don't want that, because it might include our rights statement, which we store in the /// English language alternative. /// This is probably excessively cautious for right now, since the only client of this method /// sets rights AFTER setting copyright; but I wanted a method that would be safe for any /// future use. /// (Though...it will need enhancing if we store yet more information in yet other alternatives.) /// </summary> /// <param name="tagMain"></param> /// <param name="copyright"></param> void SetCopyright(ImageTag tagMain, string copyright) { XmpTag xmp = tagMain as XmpTag; if (xmp == null) { xmp = ((CombinedImageTag)tagMain).Xmp; } var oldRights = GetRights(xmp); tagMain.Copyright = copyright; if (oldRights != null) { SetRights(xmp, oldRights); } }
private ByteVector RenderXMPBlock() { XmpTag xmp = ImageTag.Xmp; if (xmp == null) { return(null); } ByteVector xmp_data = new ByteVector(); xmp_data.Add(new byte[] { 0x21, 0xFF, 0x0B }); xmp_data.Add(XMP_IDENTIFIER); xmp_data.Add(XMP_AUTH_CODE); xmp_data.Add(xmp.Render()); xmp_data.Add(XMP_MAGIC_TRAILER); return(xmp_data); }
private void TestAltNode(XmpTag tag, string ns, string name, string[] values) { var node = tag.FindNode(ns, name); Assert.IsFalse(node == null); Assert.AreEqual(XmpNodeType.Alt, node.Type); Assert.AreEqual(values.Length, node.Children.Count); int i = 0; foreach (var childNode in node.Children) { Assert.AreEqual(values[i], childNode.Value); Assert.AreEqual(0, childNode.Children.Count); i++; } }
public void SetCollectionNodeTest( [PexAssumeUnderTest] XmpTag target, string ns, string name, string[] values, XmpNodeType type ) { PexAssume.IsNotNull(ns); PexAssume.IsNotNull(name); PexAssume.IsNotNull(values); PexAssume.IsTrue(!values.Contains(null)); PexAssume.IsTrue(type != XmpNodeType.Simple && type != XmpNodeType.Alt); target.SetCollectionNode(ns, name, values, type); PexAssert.IsTrue(values.SequenceEqual(target.GetCollectionNode(ns, name))); // TODO: add assertions to method XmpTagTest.SetCollectionNodeTest(XmpTag, String, String, String[], XmpNodeType) }
public uint?GetUIntNodeTest( [PexAssumeUnderTest] XmpTag target, string ns, string name, uint value ) { PexAssume.IsNotNull(ns); PexAssume.IsNotNull(name); PexAssume.IsNotNull(value); target.SetTextNode(ns, name, value.ToString()); uint?result = target.GetUIntNode(ns, name); PexAssert.AreEqual(result, value); return(result); // TODO: add assertions to method XmpTagTest.GetUIntNodeTest(XmpTag, String, String) }
public string[] GetCollectionNodeTest( [PexAssumeUnderTest] XmpTag target, string ns, string name, string[] values ) { PexAssume.IsNotNull(ns); PexAssume.IsNotNull(name); PexAssume.IsNotNull(values); PexAssume.IsTrue(!values.Contains(null)); target.SetCollectionNode(ns, name, values, XmpNodeType.Seq); string[] result = target.GetCollectionNode(ns, name); PexAssert.IsTrue(result.SequenceEqual(values)); return(result); // TODO: add assertions to method XmpTagTest.GetCollectionNodeTest(XmpTag, String, String) }
private ByteVector RenderXMPChunk() { XmpTag xmp = ImageTag.Xmp; if (xmp == null) { return(null); } ByteVector chunk = new ByteVector(); ByteVector xmp_data = xmp.Render(); chunk.Add(ByteVector.FromUInt((uint)xmp_data.Count + (uint)XMP_CHUNK_HEADER.Length)); chunk.Add(iTXt_CHUNK_TYPE); chunk.Add(XMP_CHUNK_HEADER); chunk.Add(xmp_data); chunk.Add(ComputeCRC(iTXt_CHUNK_TYPE, XMP_CHUNK_HEADER, xmp_data)); return(chunk); }
static string GetRights(XmpTag xmp) { var rightsNode = xmp.FindNode("http://purl.org/dc/elements/1.1/", "rights"); if (rightsNode == null) { return(null); } foreach (var child in rightsNode.Children) { if (child.Namespace == "http://www.w3.org/1999/02/22-rdf-syntax-ns#" && child.Name == "li" && HasLangQualifier(child, "en")) { return(child.Value); } } return(null); }
public double?GetRationalNodeTest( [PexAssumeUnderTest] XmpTag target, string ns, string name, double value ) { PexAssume.IsNotNull(ns); PexAssume.IsNotNull(name); PexAssume.IsNotNull(value); target.SetRationalNode(ns, name, value); double result = target.GetRationalNode(ns, name).Value; PexAssert.AreEqual(result, value, 0.001); return(result); // TODO: add assertions to method XmpTagTest.GetRationalNodeTest(XmpTag, String, String) }
public override TagLib.Tag GetTag(TagLib.TagTypes type, bool create) { foreach (Tag tag in ImageTag.AllTags) { if ((tag.TagTypes & type) == type) { return(tag); } } if (!create || (type & ImageTag.AllowedTypes) == 0) { return(null); } ImageTag new_tag = null; switch (type) { case TagTypes.JpegComment: new_tag = new JpegCommentTag(); break; case TagTypes.GifComment: new_tag = new GifCommentTag(); break; case TagTypes.Png: new_tag = new PngTag(); break; case TagTypes.TiffIFD: new_tag = new IFDTag(); break; case TagTypes.XMP: new_tag = new XmpTag(); break; } if (new_tag != null) { ImageTag.AddTag(new_tag); return(new_tag); } throw new NotImplementedException(String.Format("Adding tag of type {0} not supported!", type)); }
/// <summary> /// Load the properties of the specified MetaData object from the specified ImageTag. /// tagMain may be a CombinedImageTag (when working with a real image file) or an XmpTag (when working with an XMP file). /// Most of the data is read simply from the XmpTag (which is the Xmp property of the combined tag, if it is not tagMain itself). /// But, we don't want to pass combinedTag.Xmp when working with a file, because some files may have CopyRightNotice or Creator /// stored (only) in some other tag; /// and we need to handle the case where we only have an XmpTag, because there appears to be no way to create a /// combinedTag that just has an XmpTag inside it (or indeed any way to create any combinedTag except as part of /// reading a real image file). /// </summary> private static void LoadProperties(ImageTag tagMain, Metadata m) { m.CopyrightNotice = tagMain.Copyright; m.Creator = tagMain.Creator; XmpTag xmpTag = tagMain as XmpTag; if (xmpTag == null) { xmpTag = ((CombinedImageTag)tagMain).Xmp; } var licenseProperties = new Dictionary <string, string>(); if (xmpTag != null) { m.CollectionUri = xmpTag.GetTextNode(kNsCollections, "CollectionURI"); m.CollectionName = xmpTag.GetTextNode( kNsCollections, "CollectionName"); m.AttributionUrl = xmpTag.GetTextNode(kNsCc, "attributionURL"); var licenseUrl = xmpTag.GetTextNode(kNsCc, "license"); if (!string.IsNullOrWhiteSpace(licenseUrl)) { licenseProperties["license"] = licenseUrl; } var rights = GetRights(xmpTag); if (rights != null) { licenseProperties["rights (en)"] = rights; } } m.License = LicenseInfo.FromXmp(licenseProperties); //NB: we're loosing non-ascii somewhere... the copyright symbol is just the most obvious if (!string.IsNullOrEmpty(m.CopyrightNotice)) { m.CopyrightNotice = m.CopyrightNotice.Replace("Copyright �", "Copyright ©"); } //clear out the change-setting we just caused, because as of right now, we are clean with respect to what is on disk, no need to save. m.HasChanges = false; }
public void ValidateWithBrokenSidecar() { // Tests the file with a sidecar var uri = ImageTestHelper.CreateTempFile("taglib-sample.jpg"); var res = new GIOTagLibFileAbstraction() { Uri = uri }; var sidecar_uri = ImageTestHelper.CopySidecarToTest(uri, "taglib-sample-broken.xmp"); var sidecar_res = new GIOTagLibFileAbstraction() { Uri = sidecar_uri }; var file = File.Create(res) as TagLib.Image.File; Assert.IsNotNull(file); // Override by sidecar file should fail bool success = file.ParseXmpSidecar(sidecar_res); Assert.IsFalse(success); XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.MicrosoftPhoto_1_.DateAcquired (XmpText/20) "2009-08-04T20:42:36Z" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.MS_PHOTO_NS, "DateAcquired"); Assert.AreEqual("2009-08-04T20:42:36Z", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } Assert.AreEqual(new string [] { "Kirche Sulzbach" }, file.ImageTag.Keywords); ImageTestHelper.DeleteTempFile(uri); ImageTestHelper.DeleteTempFile(sidecar_uri); }
private ByteVector RenderXMPSegment() { XmpTag xmp = ImageTag.Xmp; if (xmp == null) { return(null); } ByteVector xmp_data = XmpTag.XAP_NS + "\0"; xmp_data.Add(xmp.Render()); uint segment_size = (uint)(2 + xmp_data.Count); if (segment_size > ushort.MaxValue) { throw new Exception("XMP Segment is too big to render"); } ByteVector data = new ByteVector(new byte[] { 0xFF, (byte)Marker.APP1 }); data.Add(ByteVector.FromUShort((ushort)segment_size)); data.Add(xmp_data); return(data); }
public void ValidateWithSidecar() { // Tests the file with a sidecar var uri = ImageTestHelper.CreateTempFile("taglib-sample.jpg"); var res = new GIOTagLibFileAbstraction() { Uri = uri }; var sidecar_uri = ImageTestHelper.CopySidecarToTest(uri, "taglib-sample.xmp"); var sidecar_res = new GIOTagLibFileAbstraction() { Uri = sidecar_uri }; var file = File.Create(res) as TagLib.Image.File; Assert.IsNotNull(file); // Override by sidecar file bool success = file.ParseXmpSidecar(sidecar_res); Assert.IsTrue(success); XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.MicrosoftPhoto_1_.DateAcquired (XmpText/20) "2009-08-04T20:42:36Z" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.MS_PHOTO_NS, "DateAcquired"); Assert.IsNull(node); } Assert.AreEqual(new string [] { "F-Spot", "metadata", "test" }, file.ImageTag.Keywords); ImageTestHelper.DeleteTempFile(uri); ImageTestHelper.DeleteTempFile(sidecar_uri); }
/// <summary> /// Creates a Chunk containing the XMP data. /// </summary> /// <returns> /// A <see cref="ByteVector"/> with the XMP data chunk /// or <see langword="null" /> if no XMP data is contained. /// </returns> private ByteVector RenderXMPChunk() { // Check, if XmpTag is contained XmpTag xmp = ImageTag.Xmp; if (xmp == null) { return(null); } ByteVector chunk = new ByteVector(); // render the XMP data itself ByteVector xmp_data = xmp.Render(); // TODO check uint size. chunk.Add(ByteVector.FromUInt((uint)xmp_data.Count + (uint)XMP_CHUNK_HEADER.Length)); chunk.Add(iTXt_CHUNK_TYPE); chunk.Add(XMP_CHUNK_HEADER); chunk.Add(xmp_data); chunk.Add(ComputeCRC(iTXt_CHUNK_TYPE, XMP_CHUNK_HEADER, xmp_data)); return(chunk); }
public void ValidateWithSidecar() { // Tests the file with a sidecar var uri = ImageTestHelper.CreateTempFile("taglib-sample.jpg"); var sidecar_uri = ImageTestHelper.CopySidecarToTest(uri, "taglib-sample.xmp"); var file = Metadata.Parse(uri); Assert.IsNotNull(file); XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.MicrosoftPhoto_1_.DateAcquired (XmpText/20) "2009-08-04T20:42:36Z" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.MS_PHOTO_NS, "DateAcquired"); Assert.IsNull(node); } Assert.AreEqual(new string [] { "F-Spot", "metadata", "test" }, file.ImageTag.Keywords); ImageTestHelper.DeleteTempFile(uri); ImageTestHelper.DeleteTempFile(sidecar_uri); }
public void RatingSetTest([PexAssumeUnderTest] XmpTag target, uint?value) { target.Rating = value; PexAssert.AreEqual(value, target.GetUIntNode(XmpTag.XAP_NS, "Rating")); // TODO: add assertions to method XmpTagTest.RatingSetTest(XmpTag, Nullable`1<UInt32>) }
public string SoftwareGetTest([PexAssumeUnderTest] XmpTag target) { PexAssert.AreEqual(target.Software, target.GetTextNode(XmpTag.XAP_NS, "CreatorTool")); return(target.Software); // TODO: add assertions to method XmpTagTest.SoftwareGetTest(XmpTag) }
public void ValidateMetadataInvariants(Image.File file) { Assert.IsNotNull(file); // ---------- Start of IFD tests ---------- var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull(tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010E (ImageDescription/Ascii/15) "Communications" // --> Test removed because of CommentModificationValidator, value is checked there. // Image.0x010F (Make/Ascii/9) "FUJIFILM" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("FUJIFILM", (entry as StringIFDEntry).Value); } // Image.0x0110 (Model/Ascii/13) "FinePixS1Pro" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("FinePixS1Pro", (entry as StringIFDEntry).Value); } // Image.0x0112 (Orientation/Short/1) "1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Orientation); Assert.IsNotNull(entry, "Entry 0x0112 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Image.0x011A (XResolution/Rational/1) "300/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(300, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x011B (YResolution/Rational/1) "300/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(300, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0131 (Software/Ascii/20) "Adobe Photoshop 7.0" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Software); Assert.IsNotNull(entry, "Entry 0x0131 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Adobe Photoshop 7.0", (entry as StringIFDEntry).Value); } // Image.0x0132 (DateTime/Ascii/20) "2002:07:19 13:28:10" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.DateTime); Assert.IsNotNull(entry, "Entry 0x0132 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2002:07:19 13:28:10", (entry as StringIFDEntry).Value); } // Image.0x013B (Artist/Ascii/12) "Ian Britton" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Artist); Assert.IsNotNull(entry, "Entry 0x013B missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Ian Britton", (entry as StringIFDEntry).Value); } // Image.0x0213 (YCbCrPositioning/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YCbCrPositioning); Assert.IsNotNull(entry, "Entry 0x0213 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0214 (ReferenceBlackWhite/Rational/6) "0/1 255/1 128/1 255/1 128/1 255/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ReferenceBlackWhite); Assert.IsNotNull(entry, "Entry 0x0214 missing in IFD 0"); Assert.IsNotNull(entry as RationalArrayIFDEntry, "Entry is not a rational array!"); var parts = (entry as RationalArrayIFDEntry).Values; Assert.AreEqual(6, parts.Length); Assert.AreEqual(0, parts[0].Numerator); Assert.AreEqual(1, parts[0].Denominator); Assert.AreEqual(255, parts[1].Numerator); Assert.AreEqual(1, parts[1].Denominator); Assert.AreEqual(128, parts[2].Numerator); Assert.AreEqual(1, parts[2].Denominator); Assert.AreEqual(255, parts[3].Numerator); Assert.AreEqual(1, parts[3].Denominator); Assert.AreEqual(128, parts[4].Numerator); Assert.AreEqual(1, parts[4].Denominator); Assert.AreEqual(255, parts[5].Numerator); Assert.AreEqual(1, parts[5].Denominator); } // Image.0x8298 (Copyright/Ascii/27) "ian Britton - FreeFoto.com" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Copyright); Assert.IsNotNull(entry, "Entry 0x8298 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("ian Britton - FreeFoto.com", (entry as StringIFDEntry).Value); } // Image.0x8769 (ExifTag/SubIFD/1) "376" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD); Assert.IsNotNull(entry, "Entry 0x8769 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; Assert.IsNotNull(exif, "Exif tag not found"); var exif_structure = exif.Structure; // Photo.0x829D (FNumber/Rational/1) "1074135040/1677721600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FNumber); Assert.IsNotNull(entry, "Entry 0x829D missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1074135040, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1677721600, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x8822 (ExposureProgram/Short/1) "4" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureProgram); Assert.IsNotNull(entry, "Entry 0x8822 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(4, (entry as ShortIFDEntry).Value); } // Photo.0x8827 (ISOSpeedRatings/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ISOSpeedRatings); Assert.IsNotNull(entry, "Entry 0x8827 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0x9000 (ExifVersion/Undefined/4) "48 50 48 48 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExifVersion); Assert.IsNotNull(entry, "Entry 0x9000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var bytes = new byte [] { 48, 50, 48, 48 }; var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9003 (DateTimeOriginal/Ascii/20) "2002:07:13 15:58:28" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2002:07:13 15:58:28", (entry as StringIFDEntry).Value); } // Photo.0x9004 (DateTimeDigitized/Ascii/20) "2002:07:13 15:58:28" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9004 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2002:07:13 15:58:28", (entry as StringIFDEntry).Value); } // Photo.0x9101 (ComponentsConfiguration/Undefined/4) "1 2 3 0 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ComponentsConfiguration); Assert.IsNotNull(entry, "Entry 0x9101 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var bytes = new byte [] { 1, 2, 3, 0 }; var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9201 (ShutterSpeedValue/SRational/1) "1275068416/134217728" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue); Assert.IsNotNull(entry, "Entry 0x9201 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(1275068416, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(134217728, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9202 (ApertureValue/Rational/1) "1610612736/201326592" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue); Assert.IsNotNull(entry, "Entry 0x9202 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1610612736, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(201326592, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9203 (BrightnessValue/SRational/1) "436469760/1677721600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.BrightnessValue); Assert.IsNotNull(entry, "Entry 0x9203 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(436469760, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(1677721600, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9204 (ExposureBiasValue/SRational/1) "-1090519041/1677721600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureBiasValue); Assert.IsNotNull(entry, "Entry 0x9204 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(-1090519041, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(1677721600, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9207 (MeteringMode/Short/1) "5" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MeteringMode); Assert.IsNotNull(entry, "Entry 0x9207 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(5, (entry as ShortIFDEntry).Value); } // Photo.0x9209 (Flash/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Flash); Assert.IsNotNull(entry, "Entry 0x9209 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0x920A (FocalLength/Rational/1) "0/16777216" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLength); Assert.IsNotNull(entry, "Entry 0x920A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(0, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(16777216, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA000 (FlashpixVersion/Undefined/4) "48 49 48 48 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FlashpixVersion); Assert.IsNotNull(entry, "Entry 0xA000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var bytes = new byte [] { 48, 49, 48, 48 }; var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA001 (ColorSpace/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ColorSpace); Assert.IsNotNull(entry, "Entry 0xA001 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA002 (PixelXDimension/Long/1) "2400" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelXDimension); Assert.IsNotNull(entry, "Entry 0xA002 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(2400, (entry as LongIFDEntry).Value); } // Photo.0xA003 (PixelYDimension/Long/1) "1600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelYDimension); Assert.IsNotNull(entry, "Entry 0xA003 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(1600, (entry as LongIFDEntry).Value); } // Photo.0xA20E (FocalPlaneXResolution/Rational/1) "202178560/16777216" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneXResolution); Assert.IsNotNull(entry, "Entry 0xA20E missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(202178560, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(16777216, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA20F (FocalPlaneYResolution/Rational/1) "202178560/16777216" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneYResolution); Assert.IsNotNull(entry, "Entry 0xA20F missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(202178560, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(16777216, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA210 (FocalPlaneResolutionUnit/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneResolutionUnit); Assert.IsNotNull(entry, "Entry 0xA210 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0xA217 (SensingMethod/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SensingMethod); Assert.IsNotNull(entry, "Entry 0xA217 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0xA300 (FileSource/Undefined/1) "0 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FileSource); Assert.IsNotNull(entry, "Entry 0xA300 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var bytes = new byte [] { 0 }; var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA301 (SceneType/Undefined/1) "0 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SceneType); Assert.IsNotNull(entry, "Entry 0xA301 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var bytes = new byte [] { 0 }; var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // Image.0x8825 (GPSTag/SubIFD/1) "776" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.GPSIFD); Assert.IsNotNull(entry, "Entry 0x8825 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var gps = structure.GetEntry(0, (ushort)IFDEntryTag.GPSIFD) as SubIFDEntry; Assert.IsNotNull(gps, "GPS tag not found"); var gps_structure = gps.Structure; // GPSInfo.0x0000 (GPSVersionID/Byte/4) "2 0 0 0 " { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSVersionID); Assert.IsNotNull(entry, "Entry 0x0000 missing in IFD 0"); Assert.IsNotNull(entry as ByteVectorIFDEntry, "Entry is not a byte array!"); var bytes = new byte [] { 2, 0, 0, 0 }; var parsed_bytes = (entry as ByteVectorIFDEntry).Data.Data; Assert.AreEqual(bytes, parsed_bytes); } // GPSInfo.0x0001 (GPSLatitudeRef/Ascii/2) "N" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSLatitudeRef); Assert.IsNotNull(entry, "Entry 0x0001 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("N", (entry as StringIFDEntry).Value); } // GPSInfo.0x0002 (GPSLatitude/Rational/3) "54/1 5938/100 0/1" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSLatitude); Assert.IsNotNull(entry, "Entry 0x0002 missing in IFD 0"); Assert.IsNotNull(entry as RationalArrayIFDEntry, "Entry is not a rational array!"); var parts = (entry as RationalArrayIFDEntry).Values; Assert.AreEqual(3, parts.Length); Assert.AreEqual(54, parts[0].Numerator); Assert.AreEqual(1, parts[0].Denominator); Assert.AreEqual(5938, parts[1].Numerator); Assert.AreEqual(100, parts[1].Denominator); Assert.AreEqual(0, parts[2].Numerator); Assert.AreEqual(1, parts[2].Denominator); } // GPSInfo.0x0003 (GPSLongitudeRef/Ascii/2) "W" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSLongitudeRef); Assert.IsNotNull(entry, "Entry 0x0003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("W", (entry as StringIFDEntry).Value); } // GPSInfo.0x0004 (GPSLongitude/Rational/3) "1/1 5485/100 0/1" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSLongitude); Assert.IsNotNull(entry, "Entry 0x0004 missing in IFD 0"); Assert.IsNotNull(entry as RationalArrayIFDEntry, "Entry is not a rational array!"); var parts = (entry as RationalArrayIFDEntry).Values; Assert.AreEqual(3, parts.Length); Assert.AreEqual(1, parts[0].Numerator); Assert.AreEqual(1, parts[0].Denominator); Assert.AreEqual(5485, parts[1].Numerator); Assert.AreEqual(100, parts[1].Denominator); Assert.AreEqual(0, parts[2].Numerator); Assert.AreEqual(1, parts[2].Denominator); } // GPSInfo.0x0007 (GPSTimeStamp/Rational/3) "14/1 58/1 24/1" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSTimeStamp); Assert.IsNotNull(entry, "Entry 0x0007 missing in IFD 0"); Assert.IsNotNull(entry as RationalArrayIFDEntry, "Entry is not a rational array!"); var parts = (entry as RationalArrayIFDEntry).Values; Assert.AreEqual(3, parts.Length); Assert.AreEqual(14, parts[0].Numerator); Assert.AreEqual(1, parts[0].Denominator); Assert.AreEqual(58, parts[1].Numerator); Assert.AreEqual(1, parts[1].Denominator); Assert.AreEqual(24, parts[2].Numerator); Assert.AreEqual(1, parts[2].Denominator); } // GPSInfo.0x0012 (GPSMapDatum/Ascii/6) "WGS84" { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSMapDatum); Assert.IsNotNull(entry, "Entry 0x0012 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("WGS84", (entry as StringIFDEntry).Value); } // Thumbnail.0x0103 (Compression/Short/1) "6" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.Compression); Assert.IsNotNull(entry, "Entry 0x0103 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(6, (entry as ShortIFDEntry).Value); } // Thumbnail.0x011A (XResolution/Rational/1) "72/1" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x011B (YResolution/Rational/1) "72/1" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Thumbnail.0x0201 (JPEGInterchangeFormat/ThumbnailDataIFD/1) "1038" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormat); Assert.IsNotNull(entry, "Entry 0x0201 missing in IFD 1"); Assert.IsNotNull(entry as ThumbnailDataIFDEntry, "Entry is not a thumbnail IFD!"); } // Thumbnail.0x0202 (JPEGInterchangeFormatLength/Long/1) "3662" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormatLength); Assert.IsNotNull(entry, "Entry 0x0202 missing in IFD 1"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(3662, (entry as LongIFDEntry).Value); } // ---------- End of IFD tests ---------- // ---------- Start of XMP tests ---------- XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.photoshop.CaptionWriter (XmpText/11) "Ian Britton" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "CaptionWriter"); Assert.IsNotNull(node); Assert.AreEqual("Ian Britton", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Headline (XmpText/14) "Communications" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Headline"); Assert.IsNotNull(node); Assert.AreEqual("Communications", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.AuthorsPosition (XmpText/12) "Photographer" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "AuthorsPosition"); Assert.IsNotNull(node); Assert.AreEqual("Photographer", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Credit (XmpText/11) "Ian Britton" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Credit"); Assert.IsNotNull(node); Assert.AreEqual("Ian Britton", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Source (XmpText/12) "FreeFoto.com" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Source"); Assert.IsNotNull(node); Assert.AreEqual("FreeFoto.com", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.City (XmpText/1) "" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "City"); Assert.IsNotNull(node); Assert.AreEqual("", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.State (XmpText/1) "" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "State"); Assert.IsNotNull(node); Assert.AreEqual("", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Country (XmpText/14) "Ubited Kingdom" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Country"); Assert.IsNotNull(node); Assert.AreEqual("Ubited Kingdom", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Category (XmpText/3) "BUS" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Category"); Assert.IsNotNull(node); Assert.AreEqual("BUS", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.DateCreated (XmpText/10) "2002-06-20" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "DateCreated"); Assert.IsNotNull(node); Assert.AreEqual("2002-06-20", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.Urgency (XmpText/1) "5" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "Urgency"); Assert.IsNotNull(node); Assert.AreEqual("5", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.SupplementalCategories (XmpBag/1) "Communications" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "SupplementalCategories"); Assert.IsNotNull(node); Assert.AreEqual(XmpNodeType.Bag, node.Type); Assert.AreEqual("", node.Value); Assert.AreEqual(1, node.Children.Count); Assert.AreEqual("Communications", node.Children [0].Value); } // Xmp.xmpBJ.JobRef (XmpText/0) "type="Bag"" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_BJ_NS, "JobRef"); Assert.IsNotNull(node); Assert.AreEqual(XmpNodeType.Bag, node.Type); } // Xmp.xmpBJ.JobRef[1] (XmpText/0) "type="Struct"" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_BJ_NS, "JobRef"); Assert.IsNotNull(node); node = node.Children [0]; Assert.IsNotNull(node); Assert.AreEqual(XmpNodeType.Struct, node.Type); } // Xmp.xmpBJ.JobRef[1]/stJob:name (XmpText/12) "Photographer" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_BJ_NS, "JobRef"); Assert.IsNotNull(node); node = node.Children [0]; Assert.IsNotNull(node); node = node.GetChild(XmpTag.JOB_NS, "name"); Assert.IsNotNull(node); Assert.AreEqual("Photographer", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmpMM.DocumentID (XmpText/58) "adobe:docid:photoshop:84d4dba8-9b11-11d6-895d-c4d063a70fb0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_MM_NS, "DocumentID"); Assert.IsNotNull(node); Assert.AreEqual("adobe:docid:photoshop:84d4dba8-9b11-11d6-895d-c4d063a70fb0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmpRights.WebStatement (XmpText/16) "www.freefoto.com" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_RIGHTS_NS, "WebStatement"); Assert.IsNotNull(node); Assert.AreEqual("www.freefoto.com", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmpRights.Marked (XmpText/4) "True" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_RIGHTS_NS, "Marked"); Assert.IsNotNull(node); Assert.AreEqual("True", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); } // Xmp.dc.description (LangAlt/1) "lang="x-default" Communications" // --> Test removed because of CommentModificationValidator, value is checked there. // Xmp.dc.creator (XmpSeq/1) "Ian Britton" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.DC_NS, "creator"); Assert.IsNotNull(node); Assert.AreEqual(XmpNodeType.Seq, node.Type); Assert.AreEqual("", node.Value); Assert.AreEqual(1, node.Children.Count); Assert.AreEqual("Ian Britton", node.Children [0].Value); } // Xmp.dc.title (LangAlt/1) "lang="x-default" Communications" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.DC_NS, "title"); Assert.IsNotNull(node); Assert.AreEqual("x-default", node.Children [0].GetQualifier(XmpTag.XML_NS, "lang").Value); Assert.AreEqual("Communications", node.Children [0].Value); } // Xmp.dc.rights (LangAlt/1) "lang="x-default" ian Britton - FreeFoto.com" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.DC_NS, "rights"); Assert.IsNotNull(node); Assert.AreEqual("x-default", node.Children [0].GetQualifier(XmpTag.XML_NS, "lang").Value); Assert.AreEqual("ian Britton - FreeFoto.com", node.Children [0].Value); } // Xmp.dc.subject (XmpBag/1) "Communications" // --> Test removed because of KeywordsModificationValidator, value is checked there. // ---------- End of XMP tests ---------- }
public void SoftwareSetTest([PexAssumeUnderTest] XmpTag target, string value) { target.Software = value; PexAssert.AreEqual(value, target.GetTextNode(XmpTag.XAP_NS, "CreatorTool")); // TODO: add assertions to method XmpTagTest.SoftwareSetTest(XmpTag, String) }
public void ValidateMetadataInvariants(Image.File file) { Assert.IsNotNull(file); // ---------- Start of IFD tests ---------- var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull(tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010F (Make/Ascii/6) "Canon" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon", (entry as StringIFDEntry).Value); } // Image.0x0110 (Model/Ascii/21) "Canon EOS 5D Mark II" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon EOS 5D Mark II", (entry as StringIFDEntry).Value); } // Image.0x0112 (Orientation/Short/1) "1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Orientation); Assert.IsNotNull(entry, "Entry 0x0112 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Image.0x011A (XResolution/Rational/1) "72/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x011B (YResolution/Rational/1) "72/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0131 (Software/Ascii/23) "f-spot version 0.6.1.5" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Software); Assert.IsNotNull(entry, "Entry 0x0131 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("f-spot version 0.6.1.5", (entry as StringIFDEntry).Value); } // Image.0x0132 (DateTime/Ascii/20) "2010:09:29 20:49:37" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.DateTime); Assert.IsNotNull(entry, "Entry 0x0132 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2010:09:29 20:49:37", (entry as StringIFDEntry).Value); } // Image.0x013B (Artist/Ascii/1) "" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Artist); Assert.IsNotNull(entry, "Entry 0x013B missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("", (entry as StringIFDEntry).Value.Trim()); } // Image.0x0213 (YCbCrPositioning/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YCbCrPositioning); Assert.IsNotNull(entry, "Entry 0x0213 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x8298 (Copyright/Ascii/1) "" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Copyright); Assert.IsNotNull(entry, "Entry 0x8298 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("", (entry as StringIFDEntry).Value.Trim()); } // Image.0x8769 (ExifTag/SubIFD/1) "258" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD); Assert.IsNotNull(entry, "Entry 0x8769 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; Assert.IsNotNull(exif, "Exif tag not found"); var exif_structure = exif.Structure; // Photo.0x829A (ExposureTime/Rational/1) "1/125" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureTime); Assert.IsNotNull(entry, "Entry 0x829A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(125, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x829D (FNumber/Rational/1) "4/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FNumber); Assert.IsNotNull(entry, "Entry 0x829D missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(4, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x8822 (ExposureProgram/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureProgram); Assert.IsNotNull(entry, "Entry 0x8822 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0x8827 (ISOSpeedRatings/Short/1) "1600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ISOSpeedRatings); Assert.IsNotNull(entry, "Entry 0x8827 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1600, (entry as ShortIFDEntry).Value); } // Photo.0x9000 (ExifVersion/Undefined/4) "48 50 50 49 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExifVersion); Assert.IsNotNull(entry, "Entry 0x9000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 48, 50, 50, 49 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9003 (DateTimeOriginal/Ascii/20) "2009:05:16 20:37:35" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2009:05:16 20:37:35", (entry as StringIFDEntry).Value); } // Photo.0x9004 (DateTimeDigitized/Ascii/20) "2009:05:16 18:58:35" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9004 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2009:05:16 18:58:35", (entry as StringIFDEntry).Value); } // Photo.0x9101 (ComponentsConfiguration/Undefined/4) "1 2 3 0 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ComponentsConfiguration); Assert.IsNotNull(entry, "Entry 0x9101 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 1, 2, 3, 0 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9201 (ShutterSpeedValue/SRational/1) "458752/65536" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue); Assert.IsNotNull(entry, "Entry 0x9201 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(458752, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(65536, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9202 (ApertureValue/Rational/1) "262144/65536" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue); Assert.IsNotNull(entry, "Entry 0x9202 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(262144, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(65536, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9204 (ExposureBiasValue/SRational/1) "0/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureBiasValue); Assert.IsNotNull(entry, "Entry 0x9204 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(0, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9207 (MeteringMode/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MeteringMode); Assert.IsNotNull(entry, "Entry 0x9207 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0x9209 (Flash/Short/1) "9" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Flash); Assert.IsNotNull(entry, "Entry 0x9209 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(9, (entry as ShortIFDEntry).Value); } // Photo.0x920A (FocalLength/Rational/1) "95/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLength); Assert.IsNotNull(entry, "Entry 0x920A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(95, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9286 (UserComment/UserComment/8) "charset="Ascii" " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.UserComment); Assert.IsNotNull(entry, "Entry 0x9286 missing in IFD 0"); Assert.IsNotNull(entry as UserCommentIFDEntry, "Entry is not a user comment!"); Assert.AreEqual("", (entry as UserCommentIFDEntry).Value.Trim()); } // Photo.0x9290 (SubSecTime/Ascii/3) "09" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTime); Assert.IsNotNull(entry, "Entry 0x9290 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("09", (entry as StringIFDEntry).Value); } // Photo.0x9291 (SubSecTimeOriginal/Ascii/3) "09" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9291 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("09", (entry as StringIFDEntry).Value); } // Photo.0x9292 (SubSecTimeDigitized/Ascii/3) "09" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9292 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("09", (entry as StringIFDEntry).Value); } // Photo.0xA000 (FlashpixVersion/Undefined/4) "48 49 48 48 " { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FlashpixVersion); Assert.IsNotNull(entry, "Entry 0xA000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 48, 49, 48, 48 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA001 (ColorSpace/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ColorSpace); Assert.IsNotNull(entry, "Entry 0xA001 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA002 (PixelXDimension/Long/1) "3253" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelXDimension); Assert.IsNotNull(entry, "Entry 0xA002 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(3253, (entry as LongIFDEntry).Value); } // Photo.0xA003 (PixelYDimension/Long/1) "4880" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelYDimension); Assert.IsNotNull(entry, "Entry 0xA003 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(4880, (entry as LongIFDEntry).Value); } // Photo.0xA20E (FocalPlaneXResolution/Rational/1) "5616000/1459" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneXResolution); Assert.IsNotNull(entry, "Entry 0xA20E missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(5616000, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1459, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA20F (FocalPlaneYResolution/Rational/1) "3744000/958" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneYResolution); Assert.IsNotNull(entry, "Entry 0xA20F missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(3744000, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(958, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA210 (FocalPlaneResolutionUnit/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalPlaneResolutionUnit); Assert.IsNotNull(entry, "Entry 0xA210 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0xA401 (CustomRendered/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.CustomRendered); Assert.IsNotNull(entry, "Entry 0xA401 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA402 (ExposureMode/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureMode); Assert.IsNotNull(entry, "Entry 0xA402 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA403 (WhiteBalance/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.WhiteBalance); Assert.IsNotNull(entry, "Entry 0xA403 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA406 (SceneCaptureType/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SceneCaptureType); Assert.IsNotNull(entry, "Entry 0xA406 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Image.0x8825 (GPSTag/SubIFD/1) "724" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.GPSIFD); Assert.IsNotNull(entry, "Entry 0x8825 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var gps = structure.GetEntry(0, (ushort)IFDEntryTag.GPSIFD) as SubIFDEntry; Assert.IsNotNull(gps, "GPS tag not found"); var gps_structure = gps.Structure; // GPSInfo.0x0000 (GPSVersionID/Byte/4) "2 2 0 0 " { var entry = gps_structure.GetEntry(0, (ushort)GPSEntryTag.GPSVersionID); Assert.IsNotNull(entry, "Entry 0x0000 missing in IFD 0"); Assert.IsNotNull(entry as ByteVectorIFDEntry, "Entry is not a byte array!"); var parsed_bytes = (entry as ByteVectorIFDEntry).Data.Data; var bytes = new byte [] { 2, 2, 0, 0 }; Assert.AreEqual(bytes, parsed_bytes); } // Thumbnail.0x0103 (Compression/Short/1) "6" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.Compression); Assert.IsNotNull(entry, "Entry 0x0103 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(6, (entry as ShortIFDEntry).Value); } // Thumbnail.0x011A (XResolution/Rational/1) "72/1" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x011B (YResolution/Rational/1) "72/1" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(72, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Thumbnail.0x0201 (JPEGInterchangeFormat/ThumbnailDataIFD/1) "836" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormat); Assert.IsNotNull(entry, "Entry 0x0201 missing in IFD 1"); Assert.IsNotNull(entry as ThumbnailDataIFDEntry, "Entry is not a thumbnail IFD!"); } // Thumbnail.0x0202 (JPEGInterchangeFormatLength/Long/1) "4463" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormatLength); Assert.IsNotNull(entry, "Entry 0x0202 missing in IFD 1"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(4463, (entry as LongIFDEntry).Value); } // ---------- End of IFD tests ---------- // ---------- Start of XMP tests ---------- XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.tiff.Software (XmpText/46) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "Software"); Assert.IsNotNull(node); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.software (XmpText/46) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "software"); Assert.IsNotNull(node); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmp.CreatorTool (XmpText/49) "Adobe Photoshop Elements for Windows, version 2.0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_NS, "CreatorTool"); Assert.IsNotNull(node); Assert.AreEqual("Adobe Photoshop Elements for Windows, version 2.0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmp.creatortool (XmpText/46) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_NS, "creatortool"); Assert.IsNotNull(node); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmpMM.DocumentID (XmpText/58) "adobe:docid:photoshop:f48fd669-42b3-11de-a9a9-b4912218066d" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_MM_NS, "DocumentID"); Assert.IsNotNull(node); Assert.AreEqual("adobe:docid:photoshop:f48fd669-42b3-11de-a9a9-b4912218066d", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.dc.subject (XmpBag/2) "TASI, 50v-juhlat" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.DC_NS, "subject"); Assert.IsNotNull(node); Assert.AreEqual(XmpNodeType.Bag, node.Type); Assert.AreEqual("", node.Value); Assert.AreEqual(2, node.Children.Count); var children_array = new System.Collections.Generic.List <string> (); foreach (var child in node.Children) { children_array.Add(child.Value); } Assert.IsTrue(children_array.Contains("TASI")); Assert.IsTrue(children_array.Contains("50v-juhlat")); } // ---------- End of XMP tests ---------- }
public void TitleSetTest([PexAssumeUnderTest] XmpTag target, string value) { target.Title = value; PexAssert.AreEqual(value, target.GetLangAltNode(XmpTag.DC_NS, "title")); // TODO: add assertions to method XmpTagTest.TitleSetTest(XmpTag, String) }
public void CopyrightSetTest([PexAssumeUnderTest] XmpTag target, string value) { target.Copyright = value; PexAssert.AreEqual(target.GetLangAltNode(XmpTag.DC_NS, "rights"), value); // TODO: add assertions to method XmpTagTest.CopyrightSetTest(XmpTag, String) }
public void ValidateMetadataInvariants(Image.File file) { Assert.IsNotNull(file); // ---------- Start of IFD tests ---------- var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull(tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010F (Make/Ascii/6) "Canon" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon", (entry as StringIFDEntry).Value); } // Image.0x0110 (Model/Ascii/23) "Canon EOS 400D DIGITAL" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon EOS 400D DIGITAL", (entry as StringIFDEntry).Value); } // Image.0x011A (XResolution/Rational/1) "150/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(150, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x011B (YResolution/Rational/1) "150/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(150, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0131 (Software/Ascii/17) "Bibble 5 Pro 5.0" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Software); Assert.IsNotNull(entry, "Entry 0x0131 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Bibble 5 Pro 5.0", (entry as StringIFDEntry).Value); } // Image.0x8769 (ExifTag/SubIFD/1) "8" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD); Assert.IsNotNull(entry, "Entry 0x8769 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; Assert.IsNotNull(exif, "Exif tag not found"); var exif_structure = exif.Structure; // Photo.0x010F (0x010f/Ascii/6) "Canon" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon", (entry as StringIFDEntry).Value); } // Photo.0x0110 (0x0110/Ascii/23) "Canon EOS 400D DIGITAL" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Canon EOS 400D DIGITAL", (entry as StringIFDEntry).Value); } // Photo.0x0132 (0x0132/Ascii/20) "2010:02:03 10:51:35" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.DateTime); Assert.IsNotNull(entry, "Entry 0x0132 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2010:02:03 10:51:35", (entry as StringIFDEntry).Value); } // Photo.0x829A (ExposureTime/Rational/1) "1/200" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureTime); Assert.IsNotNull(entry, "Entry 0x829A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(200, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x829D (FNumber/Rational/1) "5/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FNumber); Assert.IsNotNull(entry, "Entry 0x829D missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(5, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x8822 (ExposureProgram/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureProgram); Assert.IsNotNull(entry, "Entry 0x8822 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0x8827 (ISOSpeedRatings/Short/1) "100" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ISOSpeedRatings); Assert.IsNotNull(entry, "Entry 0x8827 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(100, (entry as ShortIFDEntry).Value); } // Photo.0x9003 (DateTimeOriginal/Ascii/20) "2010:01:06 19:50:44" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2010:01:06 19:50:44", (entry as StringIFDEntry).Value); } // Photo.0x9004 (DateTimeDigitized/Ascii/20) "2010:01:06 19:50:44" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9004 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2010:01:06 19:50:44", (entry as StringIFDEntry).Value); } // Photo.0x9201 (ShutterSpeedValue/Rational/1) "500948/65536" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue); Assert.IsNotNull(entry, "Entry 0x9201 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(500948, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(65536, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9202 (ApertureValue/Rational/1) "304340/65536" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue); Assert.IsNotNull(entry, "Entry 0x9202 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(304340, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(65536, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9204 (ExposureBiasValue/SRational/1) "0/3" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureBiasValue); Assert.IsNotNull(entry, "Entry 0x9204 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(0, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(3, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9205 (MaxApertureValue/Rational/1) "85/32" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MaxApertureValue); Assert.IsNotNull(entry, "Entry 0x9205 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(85, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(32, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9207 (MeteringMode/Short/1) "5" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MeteringMode); Assert.IsNotNull(entry, "Entry 0x9207 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(5, (entry as ShortIFDEntry).Value); } // Photo.0x9209 (Flash/Short/1) "9" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Flash); Assert.IsNotNull(entry, "Entry 0x9209 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(9, (entry as ShortIFDEntry).Value); } // Photo.0x920A (FocalLength/Rational/1) "21/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLength); Assert.IsNotNull(entry, "Entry 0x920A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(21, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9290 (SubSecTime/Ascii/4) "976" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTime); Assert.IsNotNull(entry, "Entry 0x9290 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("976", (entry as StringIFDEntry).Value); } // Photo.0xA402 (ExposureMode/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureMode); Assert.IsNotNull(entry, "Entry 0xA402 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA403 (WhiteBalance/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.WhiteBalance); Assert.IsNotNull(entry, "Entry 0xA403 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA406 (SceneCaptureType/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SceneCaptureType); Assert.IsNotNull(entry, "Entry 0xA406 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // ---------- End of IFD tests ---------- // ---------- Start of XMP tests ---------- XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.tiff.Model (XmpText/22) "Canon EOS 400D DIGITAL" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "Model"); Assert.IsNotNull(node); Assert.AreEqual("Canon EOS 400D DIGITAL", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.Make (XmpText/5) "Canon" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "Make"); Assert.IsNotNull(node); Assert.AreEqual("Canon", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ImageWidth (XmpText/4) "3888" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ImageWidth"); Assert.IsNotNull(node); Assert.AreEqual("3888", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ImageLength (XmpText/4) "2592" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ImageLength"); Assert.IsNotNull(node); Assert.AreEqual("2592", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.FNumber (XmpText/5) "50/10" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "FNumber"); Assert.IsNotNull(node); Assert.AreEqual("50/10", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.XResolution (XmpText/5) "150/1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "XResolution"); Assert.IsNotNull(node); Assert.AreEqual("150/1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.YResolution (XmpText/5) "150/1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "YResolution"); Assert.IsNotNull(node); Assert.AreEqual("150/1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ResolutionUnit (XmpText/1) "2" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ResolutionUnit"); Assert.IsNotNull(node); Assert.AreEqual("2", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureProgram (XmpText/1) "1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureProgram"); Assert.IsNotNull(node); Assert.AreEqual("1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.MeteringMode (XmpText/1) "5" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "MeteringMode"); Assert.IsNotNull(node); Assert.AreEqual("5", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureMode (XmpText/1) "1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureMode"); Assert.IsNotNull(node); Assert.AreEqual("1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.WhiteBalance (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "WhiteBalance"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.SceneCaptureType (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "SceneCaptureType"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ISOSpeedRating (XmpText/3) "100" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ISOSpeedRating"); Assert.IsNotNull(node); Assert.AreEqual("100", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.Flash (XmpText/1) "9" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "Flash"); Assert.IsNotNull(node); Assert.AreEqual("9", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ApertureValue (XmpText/12) "304340/65536" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ApertureValue"); Assert.IsNotNull(node); Assert.AreEqual("304340/65536", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ShutterSpeedValue (XmpText/12) "500948/65536" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ShutterSpeedValue"); Assert.IsNotNull(node); Assert.AreEqual("500948/65536", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureTime (XmpText/5) "1/200" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureTime"); Assert.IsNotNull(node); Assert.AreEqual("1/200", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureBiasValue (XmpText/3) "0/3" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureBiasValue"); Assert.IsNotNull(node); Assert.AreEqual("0/3", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.FocalLength (XmpText/4) "21/1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "FocalLength"); Assert.IsNotNull(node); Assert.AreEqual("21/1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.DateCreated (XmpText/24) "2010-01-06T19:50:44.000Z" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "DateCreated"); Assert.IsNotNull(node); Assert.AreEqual("2010-01-06T19:50:44.000Z", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmp.Rating (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_NS, "Rating"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // ---------- End of XMP tests ---------- }
public void ModelSetTest([PexAssumeUnderTest] XmpTag target, string value) { target.Model = value; PexAssert.AreEqual(value, target.GetTextNode(XmpTag.TIFF_NS, "Model")); // TODO: add assertions to method XmpTagTest.ModelSetTest(XmpTag, String) }
/// <summary> /// Renders the current instance as child of the given node to the /// given <see cref="XmlNode"/> /// </summary> /// <param name="parent"> /// A <see cref="XmlNode"/> to render the current instance as child of. /// </param> public void RenderInto(XmlNode parent) { if (IsRootNode) { AddAllChildrenTo(parent); } else if (IsReallySimpleType && parent.Attributes.GetNamedItem(XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS) == null) { // Simple values can be added as attributes of the parent node. Not allowed when the parent has an rdf:parseType. XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, Name, Namespace); attr.Value = Value; parent.Attributes.Append(attr); } else if (Type == XmpNodeType.Simple || Type == XmpNodeType.Struct) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); node.InnerText = Value; if (Type == XmpNodeType.Struct) { // Structured types are always handled as a parseType=Resource node. This way, IsReallySimpleType will // not match for child nodes, which makes sure they are added as extra nodes to this node. Does the // trick well, unit tests that prove this are in XmpSpecTest. XmlAttribute attr = XmpTag.CreateAttribute(parent.OwnerDocument, XmpTag.PARSE_TYPE_URI, XmpTag.RDF_NS); attr.Value = "Resource"; node.Attributes.Append(attr); } AddAllQualifiersTo(node); AddAllChildrenTo(node); parent.AppendChild(node); } else if (Type == XmpNodeType.Bag) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); // TODO: Add all qualifiers. if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.BAG_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Alt) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); // TODO: Add all qualifiers. if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.ALT_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else if (Type == XmpNodeType.Seq) { var node = XmpTag.CreateNode(parent.OwnerDocument, Name, Namespace); // TODO: Add all qualifiers. if (QualifierCount > 0) { throw new NotImplementedException(); } var bag = XmpTag.CreateNode(parent.OwnerDocument, XmpTag.SEQ_URI, XmpTag.RDF_NS); foreach (var child in Children) { child.RenderInto(bag); } node.AppendChild(bag); parent.AppendChild(node); } else { // Probably some combination of things we don't fully cover yet. Dump(); throw new NotImplementedException(); } }
public void ValidateMetadataInvariants(Image.File file) { Assert.IsNotNull(file); // ---------- Start of IFD tests ---------- var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull(tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010E (ImageDescription/Ascii/32) "OLYMPUS DIGITAL CAMERA " { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ImageDescription); Assert.IsNotNull(entry, "Entry 0x010E missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("OLYMPUS DIGITAL CAMERA ", (entry as StringIFDEntry).Value); } // Image.0x010F (Make/Ascii/24) "OLYMPUS IMAGING CORP. " { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("OLYMPUS IMAGING CORP. ", (entry as StringIFDEntry).Value); } // Image.0x0110 (Model/Ascii/17) "u740,S740 " { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("u740,S740 ", (entry as StringIFDEntry).Value); } // Image.0x0112 (Orientation/Short/1) "1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Orientation); Assert.IsNotNull(entry, "Entry 0x0112 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Image.0x011A (XResolution/Rational/1) "314/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(314, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x011B (YResolution/Rational/1) "314/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(314, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0131 (Software/Ascii/47) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Software); Assert.IsNotNull(entry, "Entry 0x0131 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", (entry as StringIFDEntry).Value); } // Image.0x0132 (DateTime/Ascii/20) "2008:10:04 22:00:22" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.DateTime); Assert.IsNotNull(entry, "Entry 0x0132 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2008:10:04 22:00:22", (entry as StringIFDEntry).Value); } // Image.0x0213 (YCbCrPositioning/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YCbCrPositioning); Assert.IsNotNull(entry, "Entry 0x0213 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x8769 (ExifTag/SubIFD/1) "316" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD); Assert.IsNotNull(entry, "Entry 0x8769 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; Assert.IsNotNull(exif, "Exif tag not found"); var exif_structure = exif.Structure; // Photo.0x829A (ExposureTime/Rational/1) "1/50" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureTime); Assert.IsNotNull(entry, "Entry 0x829A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(50, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x829D (FNumber/Rational/1) "38/10" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FNumber); Assert.IsNotNull(entry, "Entry 0x829D missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(38, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(10, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x8822 (ExposureProgram/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureProgram); Assert.IsNotNull(entry, "Entry 0x8822 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0x8827 (ISOSpeedRatings/Short/1) "100" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ISOSpeedRatings); Assert.IsNotNull(entry, "Entry 0x8827 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(100, (entry as ShortIFDEntry).Value); } // Photo.0x9000 (ExifVersion/Undefined/4) "48 50 50 49" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExifVersion); Assert.IsNotNull(entry, "Entry 0x9000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 48, 50, 50, 49 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9003 (DateTimeOriginal/Ascii/20) "2008:10:04 18:33:50" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2008:10:04 18:33:50", (entry as StringIFDEntry).Value); } // Photo.0x9004 (DateTimeDigitized/Ascii/20) "2008:10:04 18:33:50" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9004 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2008:10:04 18:33:50", (entry as StringIFDEntry).Value); } // Photo.0x9101 (ComponentsConfiguration/Undefined/4) "1 2 3 0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ComponentsConfiguration); Assert.IsNotNull(entry, "Entry 0x9101 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 1, 2, 3, 0 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0x9204 (ExposureBiasValue/SRational/1) "0/10" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureBiasValue); Assert.IsNotNull(entry, "Entry 0x9204 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(0, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(10, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9205 (MaxApertureValue/Rational/1) "344/100" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MaxApertureValue); Assert.IsNotNull(entry, "Entry 0x9205 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(344, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(100, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9207 (MeteringMode/Short/1) "5" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MeteringMode); Assert.IsNotNull(entry, "Entry 0x9207 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(5, (entry as ShortIFDEntry).Value); } // Photo.0x9208 (LightSource/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.LightSource); Assert.IsNotNull(entry, "Entry 0x9208 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0x9209 (Flash/Short/1) "25" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Flash); Assert.IsNotNull(entry, "Entry 0x9209 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(25, (entry as ShortIFDEntry).Value); } // Photo.0x920A (FocalLength/Rational/1) "886/100" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLength); Assert.IsNotNull(entry, "Entry 0x920A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(886, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(100, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x927C (MakerNote/MakerNote/1622) "(Value ommitted)" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MakerNote); Assert.IsNotNull(entry, "Entry 0x927C missing in IFD 0"); Assert.IsNotNull(entry as MakernoteIFDEntry, "Entry is not a makernote IFD!"); } // Photo.0xA000 (FlashpixVersion/Undefined/4) "48 49 48 48" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FlashpixVersion); Assert.IsNotNull(entry, "Entry 0xA000 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 48, 49, 48, 48 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA001 (ColorSpace/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ColorSpace); Assert.IsNotNull(entry, "Entry 0xA001 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA002 (PixelXDimension/Long/1) "1536" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelXDimension); Assert.IsNotNull(entry, "Entry 0xA002 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(1536, (entry as LongIFDEntry).Value); } // Photo.0xA003 (PixelYDimension/Long/1) "2048" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.PixelYDimension); Assert.IsNotNull(entry, "Entry 0xA003 missing in IFD 0"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(2048, (entry as LongIFDEntry).Value); } // Photo.0xA005 (InteroperabilityTag/SubIFD/1) "2534" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.InteroperabilityIFD); Assert.IsNotNull(entry, "Entry 0xA005 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var iop = exif_structure.GetEntry(0, (ushort)IFDEntryTag.InteroperabilityIFD) as SubIFDEntry; Assert.IsNotNull(iop, "Iop tag not found"); var iop_structure = iop.Structure; // Iop.0x0001 (InteroperabilityIndex/Ascii/4) "R98" { var entry = iop_structure.GetEntry(0, (ushort)IOPEntryTag.InteroperabilityIndex); Assert.IsNotNull(entry, "Entry 0x0001 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("R98", (entry as StringIFDEntry).Value); } // Iop.0x0002 (InteroperabilityVersion/Undefined/4) "48 49 48 48" { var entry = iop_structure.GetEntry(0, (ushort)IOPEntryTag.InteroperabilityVersion); Assert.IsNotNull(entry, "Entry 0x0002 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 48, 49, 48, 48 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA300 (FileSource/Undefined/1) "3" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FileSource); Assert.IsNotNull(entry, "Entry 0xA300 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var bytes = new byte [] { 3 }; Assert.AreEqual(bytes, parsed_bytes); } // Photo.0xA401 (CustomRendered/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.CustomRendered); Assert.IsNotNull(entry, "Entry 0xA401 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA402 (ExposureMode/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureMode); Assert.IsNotNull(entry, "Entry 0xA402 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA403 (WhiteBalance/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.WhiteBalance); Assert.IsNotNull(entry, "Entry 0xA403 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA404 (DigitalZoomRatio/Rational/1) "100/100" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DigitalZoomRatio); Assert.IsNotNull(entry, "Entry 0xA404 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(100, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(100, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0xA406 (SceneCaptureType/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SceneCaptureType); Assert.IsNotNull(entry, "Entry 0xA406 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA407 (GainControl/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.GainControl); Assert.IsNotNull(entry, "Entry 0xA407 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA408 (Contrast/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Contrast); Assert.IsNotNull(entry, "Entry 0xA408 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA409 (Saturation/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Saturation); Assert.IsNotNull(entry, "Entry 0xA409 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA40A (Sharpness/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Sharpness); Assert.IsNotNull(entry, "Entry 0xA40A missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xEA1D (0xea1d/SLong/1) "34" { // TODO: Unknown IFD tag: Photo / 0xEA1D var entry = exif_structure.GetEntry(0, (ushort)0xEA1D); Assert.IsNotNull(entry, "Entry 0xEA1D missing in IFD 0"); Assert.IsNotNull(entry as SLongIFDEntry, "Entry is not a signed long!"); Assert.AreEqual(34, (entry as SLongIFDEntry).Value); } // Image.0xC4A5 (PrintImageMatching/Undefined/528) "(Value ommitted)" { // TODO: Unknown IFD tag: Image / 0xC4A5 var entry = structure.GetEntry(0, (ushort)0xC4A5); Assert.IsNotNull(entry, "Entry 0xC4A5 missing in IFD 0"); Assert.IsNotNull(entry as UndefinedIFDEntry, "Entry is not an undefined IFD entry!"); var parsed_bytes = (entry as UndefinedIFDEntry).Data.Data; var parsed_hash = Utils.Md5Encode(parsed_bytes); Assert.AreEqual("785d55d75dffafdef5947fb2bfd6c84b", parsed_hash); Assert.AreEqual(528, parsed_bytes.Length); } // Thumbnail.0x0103 (Compression/Short/1) "6" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.Compression); Assert.IsNotNull(entry, "Entry 0x0103 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(6, (entry as ShortIFDEntry).Value); } // Thumbnail.0x011A (XResolution/Rational/1) "1/96" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(96, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x011B (YResolution/Rational/1) "1/96" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 1"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(96, (entry as RationalIFDEntry).Value.Denominator); } // Thumbnail.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 1"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Thumbnail.0x0201 (JPEGInterchangeFormat/ThumbnailDataIFD/1) "3194" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormat); Assert.IsNotNull(entry, "Entry 0x0201 missing in IFD 1"); Assert.IsNotNull(entry as ThumbnailDataIFDEntry, "Entry is not a thumbnail IFD!"); } // Thumbnail.0x0202 (JPEGInterchangeFormatLength/Long/1) "5804" { var entry = structure.GetEntry(1, (ushort)IFDEntryTag.JPEGInterchangeFormatLength); Assert.IsNotNull(entry, "Entry 0x0202 missing in IFD 1"); Assert.IsNotNull(entry as LongIFDEntry, "Entry is not a long!"); Assert.AreEqual(5804, (entry as LongIFDEntry).Value); } // ---------- End of IFD tests ---------- // ---------- Start of XMP tests ---------- XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.xmp.creatortool (XmpText/46) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_NS, "creatortool"); Assert.IsNotNull(node); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.software (XmpText/46) "Microsoft Windows Photo Gallery 6.0.6000.16386" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "software"); Assert.IsNotNull(node); Assert.AreEqual("Microsoft Windows Photo Gallery 6.0.6000.16386", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // ---------- End of XMP tests ---------- }
public void ValidateMetadataInvariants(Image.File file) { Assert.IsNotNull(file); // ---------- Start of IFD tests ---------- var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; Assert.IsNotNull(tag, "IFD tag not found"); var structure = tag.Structure; // Image.0x010F (Make/Ascii/18) "NIKON CORPORATION" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("NIKON CORPORATION", (entry as StringIFDEntry).Value); } // Image.0x0110 (Model/Ascii/11) "NIKON D70s" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("NIKON D70s", (entry as StringIFDEntry).Value); } // Image.0x011A (XResolution/Rational/1) "150/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.XResolution); Assert.IsNotNull(entry, "Entry 0x011A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(150, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x011B (YResolution/Rational/1) "150/1" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.YResolution); Assert.IsNotNull(entry, "Entry 0x011B missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(150, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Image.0x0128 (ResolutionUnit/Short/1) "2" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ResolutionUnit); Assert.IsNotNull(entry, "Entry 0x0128 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Image.0x0131 (Software/Ascii/17) "Bibble 5 Pro 5.0" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.Software); Assert.IsNotNull(entry, "Entry 0x0131 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("Bibble 5 Pro 5.0", (entry as StringIFDEntry).Value); } // Image.0x8769 (ExifTag/SubIFD/1) "8" { var entry = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD); Assert.IsNotNull(entry, "Entry 0x8769 missing in IFD 0"); Assert.IsNotNull(entry as SubIFDEntry, "Entry is not a sub IFD!"); } var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; Assert.IsNotNull(exif, "Exif tag not found"); var exif_structure = exif.Structure; // Photo.0x010F (0x010f/Ascii/18) "NIKON CORPORATION" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.Make); Assert.IsNotNull(entry, "Entry 0x010F missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("NIKON CORPORATION", (entry as StringIFDEntry).Value); } // Photo.0x0110 (0x0110/Ascii/11) "NIKON D70s" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.Model); Assert.IsNotNull(entry, "Entry 0x0110 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("NIKON D70s", (entry as StringIFDEntry).Value); } // Photo.0x0132 (0x0132/Ascii/20) "2010:02:03 11:02:18" { var entry = exif_structure.GetEntry(0, (ushort)IFDEntryTag.DateTime); Assert.IsNotNull(entry, "Entry 0x0132 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2010:02:03 11:02:18", (entry as StringIFDEntry).Value); } // Photo.0x829A (ExposureTime/Rational/1) "10/7500" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureTime); Assert.IsNotNull(entry, "Entry 0x829A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(10, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(7500, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x829D (FNumber/Rational/1) "13/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FNumber); Assert.IsNotNull(entry, "Entry 0x829D missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(13, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x8822 (ExposureProgram/Short/1) "2" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureProgram); Assert.IsNotNull(entry, "Entry 0x8822 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(2, (entry as ShortIFDEntry).Value); } // Photo.0x8827 (ISOSpeedRatings/Short/1) "1600" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ISOSpeedRatings); Assert.IsNotNull(entry, "Entry 0x8827 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1600, (entry as ShortIFDEntry).Value); } // Photo.0x9003 (DateTimeOriginal/Ascii/20) "2007:02:15 17:07:48" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9003 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2007:02:15 17:07:48", (entry as StringIFDEntry).Value); } // Photo.0x9004 (DateTimeDigitized/Ascii/20) "2007:02:15 17:07:48" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.DateTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9004 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("2007:02:15 17:07:48", (entry as StringIFDEntry).Value); } // Photo.0x9204 (ExposureBiasValue/SRational/1) "0/6" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureBiasValue); Assert.IsNotNull(entry, "Entry 0x9204 missing in IFD 0"); Assert.IsNotNull(entry as SRationalIFDEntry, "Entry is not a srational!"); Assert.AreEqual(0, (entry as SRationalIFDEntry).Value.Numerator); Assert.AreEqual(6, (entry as SRationalIFDEntry).Value.Denominator); } // Photo.0x9205 (MaxApertureValue/Rational/1) "50/10" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MaxApertureValue); Assert.IsNotNull(entry, "Entry 0x9205 missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(50, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(10, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9207 (MeteringMode/Short/1) "5" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.MeteringMode); Assert.IsNotNull(entry, "Entry 0x9207 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(5, (entry as ShortIFDEntry).Value); } // Photo.0x9208 (LightSource/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.LightSource); Assert.IsNotNull(entry, "Entry 0x9208 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0x920A (FocalLength/Rational/1) "50/1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLength); Assert.IsNotNull(entry, "Entry 0x920A missing in IFD 0"); Assert.IsNotNull(entry as RationalIFDEntry, "Entry is not a rational!"); Assert.AreEqual(50, (entry as RationalIFDEntry).Value.Numerator); Assert.AreEqual(1, (entry as RationalIFDEntry).Value.Denominator); } // Photo.0x9290 (SubSecTime/Ascii/4) "889" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTime); Assert.IsNotNull(entry, "Entry 0x9290 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("889", (entry as StringIFDEntry).Value); } // Photo.0x9291 (SubSecTimeOriginal/Ascii/4) "800" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTimeOriginal); Assert.IsNotNull(entry, "Entry 0x9291 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("800", (entry as StringIFDEntry).Value); } // Photo.0x9292 (SubSecTimeDigitized/Ascii/4) "800" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubsecTimeDigitized); Assert.IsNotNull(entry, "Entry 0x9292 missing in IFD 0"); Assert.IsNotNull(entry as StringIFDEntry, "Entry is not a string!"); Assert.AreEqual("800", (entry as StringIFDEntry).Value); } // Photo.0xA402 (ExposureMode/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.ExposureMode); Assert.IsNotNull(entry, "Entry 0xA402 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA403 (WhiteBalance/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.WhiteBalance); Assert.IsNotNull(entry, "Entry 0xA403 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA405 (FocalLengthIn35mmFilm/Short/1) "75" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.FocalLengthIn35mmFilm); Assert.IsNotNull(entry, "Entry 0xA405 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(75, (entry as ShortIFDEntry).Value); } // Photo.0xA406 (SceneCaptureType/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SceneCaptureType); Assert.IsNotNull(entry, "Entry 0xA406 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA408 (Contrast/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Contrast); Assert.IsNotNull(entry, "Entry 0xA408 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA409 (Saturation/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Saturation); Assert.IsNotNull(entry, "Entry 0xA409 missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // Photo.0xA40A (Sharpness/Short/1) "1" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.Sharpness); Assert.IsNotNull(entry, "Entry 0xA40A missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(1, (entry as ShortIFDEntry).Value); } // Photo.0xA40C (SubjectDistanceRange/Short/1) "0" { var entry = exif_structure.GetEntry(0, (ushort)ExifEntryTag.SubjectDistanceRange); Assert.IsNotNull(entry, "Entry 0xA40C missing in IFD 0"); Assert.IsNotNull(entry as ShortIFDEntry, "Entry is not a short!"); Assert.AreEqual(0, (entry as ShortIFDEntry).Value); } // ---------- End of IFD tests ---------- // ---------- Start of XMP tests ---------- XmpTag xmp = file.GetTag(TagTypes.XMP) as XmpTag; // Xmp.tiff.Model (XmpText/10) "NIKON D70s" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "Model"); Assert.IsNotNull(node); Assert.AreEqual("NIKON D70s", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.Make (XmpText/17) "NIKON CORPORATION" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "Make"); Assert.IsNotNull(node); Assert.AreEqual("NIKON CORPORATION", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ImageWidth (XmpText/4) "3024" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ImageWidth"); Assert.IsNotNull(node); Assert.AreEqual("3024", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ImageLength (XmpText/4) "1998" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ImageLength"); Assert.IsNotNull(node); Assert.AreEqual("1998", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.FNumber (XmpText/6) "130/10" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "FNumber"); Assert.IsNotNull(node); Assert.AreEqual("130/10", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.XResolution (XmpText/5) "150/1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "XResolution"); Assert.IsNotNull(node); Assert.AreEqual("150/1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.YResolution (XmpText/5) "150/1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "YResolution"); Assert.IsNotNull(node); Assert.AreEqual("150/1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.tiff.ResolutionUnit (XmpText/1) "2" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.TIFF_NS, "ResolutionUnit"); Assert.IsNotNull(node); Assert.AreEqual("2", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureProgram (XmpText/1) "2" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureProgram"); Assert.IsNotNull(node); Assert.AreEqual("2", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.MeteringMode (XmpText/1) "5" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "MeteringMode"); Assert.IsNotNull(node); Assert.AreEqual("5", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.LightSource (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "LightSource"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureMode (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureMode"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.WhiteBalance (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "WhiteBalance"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.FocalLengthIn35mmFilm (XmpText/2) "75" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "FocalLengthIn35mmFilm"); Assert.IsNotNull(node); Assert.AreEqual("75", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.SceneCaptureType (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "SceneCaptureType"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.Contrast (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "Contrast"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.Saturation (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "Saturation"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.Sharpness (XmpText/1) "1" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "Sharpness"); Assert.IsNotNull(node); Assert.AreEqual("1", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.SubjectDistanceRange (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "SubjectDistanceRange"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ISOSpeedRating (XmpText/4) "1600" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ISOSpeedRating"); Assert.IsNotNull(node); Assert.AreEqual("1600", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.MaxApertureValue (XmpText/5) "50/10" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "MaxApertureValue"); Assert.IsNotNull(node); Assert.AreEqual("50/10", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureTime (XmpText/7) "10/7500" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureTime"); Assert.IsNotNull(node); Assert.AreEqual("10/7500", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.ExposureBiasValue (XmpText/3) "0/6" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "ExposureBiasValue"); Assert.IsNotNull(node); Assert.AreEqual("0/6", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.exif.FocalLength (XmpText/6) "500/10" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.EXIF_NS, "FocalLength"); Assert.IsNotNull(node); Assert.AreEqual("500/10", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.photoshop.DateCreated (XmpText/24) "2007-02-15T17:07:48.800Z" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.PHOTOSHOP_NS, "DateCreated"); Assert.IsNotNull(node); Assert.AreEqual("2007-02-15T17:07:48.800Z", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // Xmp.xmp.Rating (XmpText/1) "0" { var node = xmp.NodeTree; node = node.GetChild(XmpTag.XAP_NS, "Rating"); Assert.IsNotNull(node); Assert.AreEqual("0", node.Value); Assert.AreEqual(XmpNodeType.Simple, node.Type); Assert.AreEqual(0, node.Children.Count); } // ---------- End of XMP tests ---------- }