예제 #1
0
        public void WriteImageRegionMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp4);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            string testValueSuffix = DateTime.Now.ToUniversalTime().ToString();

            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonDisplayName = "PersonDisplayName" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonEmailDigest = "PersonEmailDigest" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonLiveIdCID   = "PersonLiveIdCID" + testValueSuffix;
            testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].RectangleString   = "0.1, 0.2, 0.3, 0.4";

            // And save
            testPhoto.WriteMetadata();

            // Now read it from scratch
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp4);

            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonDisplayName, new Regex("PersonDisplayName" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonEmailDigest, new Regex("PersonEmailDigest" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].PersonLiveIdCID, new Regex("PersonLiveIdCID" + testValueSuffix));
            StringAssert.Matches(testPhoto.Metadata.MicrosoftRegionInfo.Regions[0].RectangleString, new Regex("0.1, 0.2, 0.3, 0.4"));

            File.Delete(testPhoto.FileFullName);
        }
예제 #2
0
        public void ReadCameraMake()
        {
            // Read photos from a couple of different cameras, the aim is to ensure no exception is thrown reading the data
            JpgPhoto photo = TestPhotos.Load(TestPhotos.MakeKodakDX4900);

            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeNikonCoolPixP80);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeNikonD70);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakePentaxOptioS);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeSonyDSCT30);
            photo.ReadMetadata();

            photo = TestPhotos.Load(TestPhotos.MakeiPhone3GsUntouched);
            photo.ReadMetadata();

            Assert.AreEqual <string>(photo.Metadata.CameraManufacturer, "Apple", "CameraManufacturer");
            Assert.AreEqual <string>(photo.Metadata.CameraModel, "iPhone 3GS", "CameraModel");
            Assert.AreEqual <DateTime>(photo.Metadata.DateDigitised, new DateTime(2010, 02, 01, 08, 24, 40), "DateDigitised");
            Assert.AreEqual <MetadataEnums.MeteringModes>(photo.Metadata.MeteringMode, MetadataEnums.MeteringModes.Average, "MeteringMode");
            Assert.AreEqual <string>(photo.Metadata.Aperture.ToString(), "f/2.8", "Aperture");
            Assert.AreEqual <string>(photo.Metadata.ShutterSpeed.ToString(), "1/170 sec.", "ShutterSpeed");

            photo = TestPhotos.Load(TestPhotos.MakeiPhone3GsWithTags);
            photo.ReadMetadata();

            Assert.AreEqual <Tag>(photo.Metadata.Tags.First(), new Tag("Test"), "Tag");
        }
예제 #3
0
        public void ReadShuttersSpeedProperties()
        {
            JpgPhoto shutterSpeed10Seconds = TestPhotos.Load(TestPhotos.ShutterSpeed10Seconds);
            JpgPhoto shutterSpeed1Over10   = TestPhotos.Load(TestPhotos.ShutterSpeed1Over10);
            JpgPhoto shutterSpeed1Over1000 = TestPhotos.Load(TestPhotos.ShutterSpeed1Over1000);
            JpgPhoto shutterSpeed1Over2    = TestPhotos.Load(TestPhotos.ShutterSpeed1Over2);
            JpgPhoto shutterSpeed1Over285  = TestPhotos.Load(TestPhotos.ShutterSpeed1Over285);
            JpgPhoto shutterSpeed1Over60   = TestPhotos.Load(TestPhotos.ShutterSpeed1Over60);
            JpgPhoto shutterSpeed2Seconds5 = TestPhotos.Load(TestPhotos.ShutterSpeed2Seconds5);

            // Read as Property
            Assert.AreEqual <ShutterSpeed>(shutterSpeed10Seconds.Metadata.ShutterSpeed, new ShutterSpeed(10), "ShutterSpeed 10 secs As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over10.Metadata.ShutterSpeed, new ShutterSpeed(0.1), "ShutterSpeed 1/10 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over1000.Metadata.ShutterSpeed, new ShutterSpeed(0.001), "ShutterSpeed 1/1000 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over2.Metadata.ShutterSpeed, new ShutterSpeed(0.5), "ShutterSpeed 1/2 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over285.Metadata.ShutterSpeed, new ShutterSpeed(0.003509), "ShutterSpeed 1/285 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed1Over60.Metadata.ShutterSpeed, new ShutterSpeed(0.016667), "ShutterSpeed 1/60 As Property");
            Assert.AreEqual <ShutterSpeed>(shutterSpeed2Seconds5.Metadata.ShutterSpeed, new ShutterSpeed(2.5), "ShutterSpeed 2.5 secs As Property");

            // Read as String
            Assert.AreEqual <string>(shutterSpeed10Seconds.Metadata.ShutterSpeed.ToString(), "10 sec.", "ShutterSpeed 10 secs As String");
            Assert.AreEqual <string>(shutterSpeed1Over10.Metadata.ShutterSpeed.ToString(), "1/10 sec.", "ShutterSpeed 1/10 As String");
            Assert.AreEqual <string>(shutterSpeed1Over1000.Metadata.ShutterSpeed.ToString(), "1/1000 sec.", "ShutterSpeed 1/1000 As String");
            Assert.AreEqual <string>(shutterSpeed1Over2.Metadata.ShutterSpeed.ToString(), "1/2 sec.", "ShutterSpeed 1/2 As String");
            Assert.AreEqual <string>(shutterSpeed1Over285.Metadata.ShutterSpeed.ToString(), "1/285 sec.", "ShutterSpeed 1/285 As String");
            Assert.AreEqual <string>(shutterSpeed1Over60.Metadata.ShutterSpeed.ToString(), "1/60 sec.", "ShutterSpeed 1/60 As String");
            Assert.AreEqual <string>(shutterSpeed2Seconds5.Metadata.ShutterSpeed.ToString(), "2.5 sec.", "ShutterSpeed 2.5 secs As String");
        }
예제 #4
0
        public void ReadExposureBias()
        {
            // 0
            Assert.AreEqual <ExposureBias>(this.jpgPhotoOne.Metadata.ExposureBias, new ExposureBias());

            // -1.3 step
            JpgPhoto jpgPhoto = TestPhotos.Load(TestPhotos.ExposureBiasMinus13);

            Assert.AreEqual <ExposureBias>(jpgPhoto.Metadata.ExposureBias, new ExposureBias("-4/3"));

            // +1.3 step
            jpgPhoto = TestPhotos.Load(TestPhotos.ExposureBiasPlus13);
            Assert.AreEqual <ExposureBias>(jpgPhoto.Metadata.ExposureBias, new ExposureBias("4/3"));
        }
예제 #5
0
        public void WriteMetadataAndCheckForMetadataLoss()
        {
            JpgPhoto beforePhoto = TestPhotos.Load(TestPhotos.UnitTest3);
            JpgPhoto afterPhoto  = TestPhotos.Load(TestPhotos.UnitTestTemp5);

            // Copy Test file
            File.Copy(beforePhoto.FileFullName, afterPhoto.FileFullName, true);

            // Change date and save
            afterPhoto.Metadata.FotoflyDateLastSave = DateTime.Now.AddTicks(-DateTime.Now.TimeOfDay.Ticks);
            afterPhoto.WriteMetadata();

            MetadataDump beforeDump;
            MetadataDump afterDump;

            using (WpfFileManager wpfFileManager = new WpfFileManager(beforePhoto.FileFullName))
            {
                beforeDump = new MetadataDump(wpfFileManager.BitmapMetadata);
                beforeDump.GenerateStringList();
            }

            using (WpfFileManager wpfFileManager = new WpfFileManager(afterPhoto.FileFullName))
            {
                afterDump = new MetadataDump(wpfFileManager.BitmapMetadata);
                afterDump.GenerateStringList();
            }

            for (int i = 0; i < beforeDump.StringList.Count; i++)
            {
                // Ignore schema changes, edit dates and created software
                if (beforeDump.StringList[i] != afterDump.StringList[i] &&
                    !beforeDump.StringList[i].Contains("DateLastSave") &&
                    !beforeDump.StringList[i].Contains("LastEditDate") &&
                    !beforeDump.StringList[i].Contains("ushort=513") &&
                    !beforeDump.StringList[i].Contains("OffsetSchema"))
                {
                    Assert.Fail("Metadata mismatch " + beforeDump.StringList[i] + " != " + afterDump.StringList[i]);
                }
            }

            if (new FileInfo(afterPhoto.FileFullName).Length > new FileInfo(beforePhoto.FileFullName).Length)
            {
                Assert.Fail("Photo has decreased in size after saving");
            }

            // Clean up
            File.Delete(afterPhoto.FileFullName);
        }
예제 #6
0
        public void ReadApertureProperties()
        {
            JpgPhoto aperture28 = TestPhotos.Load(TestPhotos.Aperture28);
            JpgPhoto aperture71 = TestPhotos.Load(TestPhotos.Aperture71);
            JpgPhoto aperture80 = TestPhotos.Load(TestPhotos.Aperture80);

            // Read as Property
            Assert.AreEqual <Aperture>(aperture28.Metadata.Aperture, new Aperture(2.8), "Aperture28 As Property");
            Assert.AreEqual <Aperture>(aperture71.Metadata.Aperture, new Aperture(7.1), "Aperture71 As Property");
            Assert.AreEqual <Aperture>(aperture80.Metadata.Aperture, new Aperture(8.0), "Aperture80 As Property");

            // Read as String
            Assert.AreEqual <string>(aperture28.Metadata.Aperture.ToString(), "f/2.8", "Aperture28 As String");
            Assert.AreEqual <string>(aperture71.Metadata.Aperture.ToString(), "f/7.1", "Aperture71 As String");
            Assert.AreEqual <string>(aperture80.Metadata.Aperture.ToString(), "f/8", "Aperture80 As String");
        }
예제 #7
0
        public void WriteGpsMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            // Test data, includes Unicode strings
            GpsPosition positionCreated = new GpsPosition(101.23, -34.321, -99.8);
            GpsPosition positionShow    = new GpsPosition(-123.0, 179);

            // Scrub existing data
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // Check for empty data
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "Blank GpsPosition Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "Blank GpsPosition Shown");

            // Write GpsPosition Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = positionCreated;
            testPhoto.Metadata.GpsPositionOfLocationShown   = new GpsPosition();
            testPhoto.WriteMetadata();

            // And Check Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, positionCreated, "WriteCreated Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, new GpsPosition(), "WriteCreated Shown");

            // Write GpsPosition Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            testPhoto.Metadata.GpsPositionOfLocationCreated = new GpsPosition();
            testPhoto.Metadata.GpsPositionOfLocationShown   = positionShow;
            testPhoto.WriteMetadata();

            // And Check Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp9);
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationCreated, new GpsPosition(), "WriteShown Created");
            Assert.AreEqual <GpsPosition>(testPhoto.Metadata.GpsPositionOfLocationShown, positionShow, "WriteShown Shown");

            // Tidy up
            File.Delete(testPhoto.FileFullName);
        }
예제 #8
0
        public void WriteAddressMetadata()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            // Test data, includes Unicode strings
            Address addressCreated = new Address(@"CòuntryCreàted/RegÎon/Ĉity/Stréét");
            Address addressShown   = new Address(@"CòuntryShówn/RegÎon/Ĉity/Stréét");

            // Scrub existing data
            testPhoto.Metadata.AddressOfLocationCreated = new Address();
            testPhoto.Metadata.AddressOfLocationShown   = new Address();
            testPhoto.WriteMetadata();

            // Check for empty data
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, new Address(), "Blank Address Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, new Address(), "Blank Address Shown");

            // Write Address Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            testPhoto.Metadata.AddressOfLocationCreated = addressCreated;
            testPhoto.Metadata.AddressOfLocationShown   = new Address();
            testPhoto.WriteMetadata();

            // And Check Created
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, addressCreated, "WriteAddress Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, new Address(), "WriteAddress Shown");

            // Write Address Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            testPhoto.Metadata.AddressOfLocationCreated = new Address();
            testPhoto.Metadata.AddressOfLocationShown   = addressShown;
            testPhoto.WriteMetadata();

            // And Check Shown
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp10);
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationCreated, new Address(), "WriteShown Created");
            Assert.AreEqual <Address>(testPhoto.Metadata.AddressOfLocationShown, addressShown, "WriteShown Shown");

            // Tidy up
            File.Delete(testPhoto.FileFullName);
        }
예제 #9
0
        public void WriteAndReadMetadataToXmlFile()
        {
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp8);
            string   xmlFile   = testPhoto.FileFullName.Replace(".jpg", ".xml");

            // Clean up from previous test
            if (File.Exists(xmlFile))
            {
                File.Delete(xmlFile);
            }

            File.Copy(this.jpgPhotoOne.FileFullName, testPhoto.FileFullName, true);

            testPhoto.ReadMetadata();
            testPhoto.WriteMetadataToXml(xmlFile);

            if (!File.Exists(xmlFile))
            {
                Assert.Fail("Serialised File was not found: " + xmlFile);
            }

            JpgPhoto xmlPhoto = new JpgPhoto(testPhoto.FileFullName);

            xmlPhoto.ReadMetadataFromXml(xmlFile);

            List <CompareResult> changes = new List <CompareResult>();

            PhotoMetadataTools.CompareMetadata(testPhoto.Metadata, xmlPhoto.Metadata, ref changes);

            if (changes.Count > 0)
            {
                Assert.Fail("Serialised File was incompleted: " + changes[0]);
            }

            File.Delete(testPhoto.FileFullName);
            File.Delete(xmlFile);
        }
예제 #10
0
        public void WriteMetadataToFile()
        {
            // Copy Test file
            JpgPhoto testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp3);

            File.Copy(this.jpgPhotoTwo.FileFullName, testPhoto.FileFullName, true);

            // Test value to write
            string   testString = "Test " + DateTime.Now.ToString();
            DateTime testDate   = DateTime.Now.AddTicks(-DateTime.Now.TimeOfDay.Ticks);
            string   testTag    = "Test Tag Î";

            // Write text
            testPhoto.Metadata.Description = testString;
            testPhoto.Metadata.Comment     = testString;
            testPhoto.Metadata.Copyright   = testString;
            testPhoto.Metadata.AddressOfLocationCreatedSource = testString;
            testPhoto.Metadata.Tags = new TagList();
            testPhoto.Metadata.Tags.Add(new Tag(testTag));

            // Write dates
            testPhoto.Metadata.DateAquired   = testDate;
            testPhoto.Metadata.DateDigitised = testDate;
            testPhoto.Metadata.DateTaken     = testDate;
            testPhoto.Metadata.DateUtc       = testDate;
            testPhoto.Metadata.AddressOfLocationCreatedLookupDate = testDate;

            // Save Photo Three
            testPhoto.WriteMetadata();

            // Check the file was created
            if (!File.Exists(testPhoto.FileFullName))
            {
                Assert.Fail("File save failed");
            }

            // Read metadata
            testPhoto = TestPhotos.Load(TestPhotos.UnitTestTemp3);
            testPhoto.ReadMetadata();

            // Check the file was created
            if (testPhoto.Metadata == null)
            {
                Assert.Fail("Unable to read saved files metadata");
            }

            // Check the text was set correctly
            StringAssert.Matches(testPhoto.Metadata.Description, new Regex(testString), "Description");
            StringAssert.Matches(testPhoto.Metadata.Comment, new Regex(testString), "Comment");
            StringAssert.Matches(testPhoto.Metadata.Copyright, new Regex(testString), "Copyright");
            StringAssert.Matches(testPhoto.Metadata.AddressOfLocationCreatedSource, new Regex(testString), "AddressOfLocationCreatedSource");

            // Check date was written
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateAquired, testDate, "DateAquired");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateDigitised, testDate, "DateDigitised");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateTaken, testDate, "DateTaken");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.DateUtc, testDate, "UtcDate");
            Assert.AreEqual <DateTime>(testPhoto.Metadata.AddressOfLocationCreatedLookupDate, testDate, "AddressOfLocationCreatedLookupDate");
            Assert.AreEqual <Tag>(testPhoto.Metadata.Tags.Last(), new Tag(testTag), "Tags");

            if (new FileInfo(this.jpgPhotoTwo.FileFullName).Length > new FileInfo(testPhoto.FileFullName).Length)
            {
                Assert.Fail("Photo has decreased in size after saving");
            }

            File.Delete(testPhoto.FileFullName);
        }
예제 #11
0
 public JpgPhotoUnitTests()
 {
     this.jpgPhotoOne = TestPhotos.Load(TestPhotos.UnitTest1);
     this.jpgPhotoTwo = TestPhotos.Load(TestPhotos.UnitTest2);
 }