Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw committed Nov 10, 2023
1 parent ec77434 commit 82ffc3d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ private static string GetShutterSpeedValue(List<Directory> allExifItems)
return shutterSpeedString;
}

private static int GetIsoSpeedValue(List<Directory> allExifItems)
internal static int GetIsoSpeedValue(List<Directory> allExifItems)
{
var subIfdItem = allExifItems.OfType<ExifSubIfdDirectory>().FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MetadataExtractor;
using MetadataExtractor.Formats.Exif;
using MetadataExtractor.Formats.Exif.Makernotes;
using MetadataExtractor.Formats.Xmp;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using starsky.foundation.readmeta.ReadMetaHelpers;
using starskytest.FakeCreateAn;
using XmpCore.Impl;
using Directory = MetadataExtractor.Directory;

namespace starskytest.starsky.foundation.readmeta.ReadMetaHelpers;

Expand Down Expand Up @@ -72,4 +78,75 @@ public void GetXmpGeoAlt_ZeroAltitude_ReturnsZeroAltitude()
Assert.AreEqual(0, result, 0.001); // Use an appropriate tolerance
}

[TestMethod]
public void GetIsoSpeedValue_FromExifSubIfd_ReturnsIsoSpeed()
{
// Arrange
var subIfdItem = new ExifSubIfdDirectory();
subIfdItem.Set(ExifDirectoryBase.TagIsoEquivalent, "400");

var allExifItems = new List<Directory> { subIfdItem };

// Act
var result = ReadMetaExif.GetIsoSpeedValue(allExifItems);

// Assert
Assert.AreEqual(400, result);
}

[TestMethod]
public void GetIsoSpeedValue_FromCanonMakerNote_ReturnsIsoSpeed()
{
// Arrange
var canonMakerNoteDirectory = new CanonMakernoteDirectory();

// Magic Numbers
// 19 = ISO 400
canonMakerNoteDirectory.Set(CanonMakernoteDirectory.CameraSettings.TagIso, "19");

var allExifItems = new List<Directory> { canonMakerNoteDirectory };

// Act
var result = ReadMetaExif.GetIsoSpeedValue(allExifItems);

// Assert
Assert.AreEqual(400, result);
}

[TestMethod]
public void GetIsoSpeedValue_FromCanonMakerNote_AutoIso_ReturnsCalculatedIsoSpeed()
{
// Arrange
var canonMakerNoteDirectory = new CanonMakernoteDirectory();

// 15 is magic number for auto
canonMakerNoteDirectory.Set(CanonMakernoteDirectory.CameraSettings.TagIso, "15");
canonMakerNoteDirectory.Set(CanonMakernoteDirectory.ShotInfo.TagAutoIso, "200");
canonMakerNoteDirectory.Set(CanonMakernoteDirectory.ShotInfo.TagBaseIso, "400");

var allExifItems = new List<Directory> { canonMakerNoteDirectory };

// Act
var result = ReadMetaExif.GetIsoSpeedValue(allExifItems);

// Assert
Assert.AreEqual(800, result); // 400 * 200 / 100 = 800
}

[TestMethod]
public void GetIsoSpeedValue_FromXmp_ReturnsIsoSpeed()
{
// Arrange
var xmpStream = new MemoryStream(CreateAnImageA6600.Bytes);

var allExifItems = ImageMetadataReader.ReadMetadata(xmpStream).ToList();

// Act
var result = ReadMetaExif.GetIsoSpeedValue(allExifItems);

// Assert
Assert.AreEqual(800, result);

xmpStream.Dispose();
}
}

0 comments on commit 82ffc3d

Please sign in to comment.