From 08360a9d45a520896cf4770da25d638e82ff76d1 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 9 Nov 2023 23:37:50 +0100 Subject: [PATCH] add extra test --- .../ReadMetaHelpers/ReadMetaExif.cs | 2 +- .../ReadMetaHelpers/ReadMetaExifTest.cs | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs diff --git a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs index b6fd86690b..a03bee9d17 100644 --- a/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs +++ b/starsky/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExif.cs @@ -786,7 +786,7 @@ private static double GetGeoLocationAltitude(List allExifItems) return (int) altitude; } - private static double GetXmpGeoAlt(List allExifItems) + internal static double GetXmpGeoAlt(List allExifItems) { var altitudeRef = true; var altitude = 0d; diff --git a/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs b/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs new file mode 100644 index 0000000000..9c9afccc8b --- /dev/null +++ b/starsky/starskytest/starsky.foundation.readmeta/ReadMetaHelpers/ReadMetaExifTest.cs @@ -0,0 +1,75 @@ +using System.Collections.Generic; +using MetadataExtractor; +using MetadataExtractor.Formats.Xmp; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using starsky.foundation.readmeta.ReadMetaHelpers; +using XmpCore.Impl; + +namespace starskytest.starsky.foundation.readmeta.ReadMetaHelpers; + +[TestClass] +public class ReadMetaExifTest +{ + [TestMethod] + public void GetXmpGeoAlt_PositiveAltitude_ReturnsPositiveAltitude() + { + // Arrange + var dir2 = new XmpDirectory(); + dir2.SetXmpMeta(new XmpMeta()); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitude","1/1" ); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitudeRef","0" ); + + var allExifItems = new List + { + dir2 + }; + + // Act + var result = ReadMetaExif.GetXmpGeoAlt(allExifItems); + + // Assert + Assert.AreEqual(1, result, 0.001); // Use an appropriate tolerance + } + + [TestMethod] + public void GetXmpGeoAlt_NegativeAltitude_ReturnsNegativeAltitude() + { + // Arrange + var dir2 = new XmpDirectory(); + dir2.SetXmpMeta(new XmpMeta()); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitude","10/1" ); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitudeRef","1" ); + + var allExifItems = new List + { + dir2 + }; + + // Act + var result = ReadMetaExif.GetXmpGeoAlt(allExifItems); + + // Assert + Assert.AreEqual(-10, result, 0.001); // Use an appropriate tolerance + } + + [TestMethod] + public void GetXmpGeoAlt_ZeroAltitude_ReturnsZeroAltitude() + { + // Arrange + var dir2 = new XmpDirectory(); + dir2.SetXmpMeta(new XmpMeta()); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitude","0/1" ); + dir2.XmpMeta?.SetProperty("http://ns.adobe.com/exif/1.0/", "GPSAltitudeRef","1" ); + var allExifItems = new List + { + dir2 + }; + + // Act + var result = ReadMetaExif.GetXmpGeoAlt(allExifItems); + + // Assert + Assert.AreEqual(0, result, 0.001); // Use an appropriate tolerance + } + +}