libimage-exiftool-perl/t/MWG.t

101 lines
3.1 KiB
Perl
Raw Normal View History

2022-10-08 17:37:59 +08:00
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/MWG.t".
BEGIN {
$| = 1; print "1..7\n"; $Image::ExifTool::configFile = '';
require './t/TestLib.pm'; t::TestLib->import();
}
END {print "not ok 1\n" unless $loaded;}
# test 1: Load the module(s)
use Image::ExifTool 'ImageInfo';
use Image::ExifTool::MWG;
Image::ExifTool::MWG::Load();
$loaded = 1;
print "ok 1\n";
my $testname = 'MWG';
my $testnum = 1;
# test 2: Extract MWG information from test image
{
++$testnum;
2024-07-09 10:17:06 +08:00
my $exifTool = Image::ExifTool->new;
2022-10-08 17:37:59 +08:00
$exifTool->Options(Duplicates => 0);
my $info = $exifTool->ImageInfo('t/images/MWG.jpg', 'MWG:*');
2024-07-09 10:17:06 +08:00
notOK() unless check($exifTool, $info, $testname, $testnum);
2022-10-08 17:37:59 +08:00
print "ok $testnum\n";
}
# tests 3-4: Write some MWG tags
{
2024-07-09 10:17:06 +08:00
my $exifTool = Image::ExifTool->new;
2022-10-08 17:37:59 +08:00
$exifTool->SetNewValue('MWG:DateTimeOriginal' => '2009:10:25 15:13:44.567-04:00');
$exifTool->SetNewValue('MWG:Creator' => 'Creator One');
$exifTool->SetNewValue('MWG:Creator' => 'Creator Two');
$exifTool->SetNewValue('MWG:City' => 'Some city');
my @tags = qw(
EXIF:DateTimeOriginal EXIF:SubSecTimeOriginal
IPTC:DateCreated IPTC:TimeCreated XMP-photoshop:DateCreated
EXIF:Artist IPTC:By-line XMP-dc:Creator IPTC:City
XMP-photoshop:City XMP-iptcExt:LocationShownCity
);
my $src;
foreach $src('MWG.jpg', 'Writer.jpg') {
++$testnum;
my $testfile = "t/${testname}_${testnum}_failed.jpg";
unlink $testfile;
$exifTool->WriteInfo("t/images/$src", $testfile);
my $info = $exifTool->GetInfo('Warning');
if ($$info{Warning}) {
warn "\n Warning: $$info{Warning}\n";
2024-07-09 10:17:06 +08:00
notOK();
2022-10-08 17:37:59 +08:00
} else {
$info = $exifTool->ImageInfo($testfile, @tags);
if (check($exifTool, $info, $testname, $testnum)) {
unlink $testfile;
} else {
2024-07-09 10:17:06 +08:00
notOK();
2022-10-08 17:37:59 +08:00
}
}
print "ok $testnum\n";
}
}
# test 5: Extract IPTC information from non-standard image while in strict MWG mode
{
++$testnum;
2024-07-09 10:17:06 +08:00
my $exifTool = Image::ExifTool->new;
2022-10-08 17:37:59 +08:00
my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'IPTC:*', 'Warning');
2024-07-09 10:17:06 +08:00
notOK() unless check($exifTool, $info, $testname, $testnum);
2022-10-08 17:37:59 +08:00
print "ok $testnum\n";
}
# test 6: Copy a tag with MWG feature active
{
++$testnum;
2024-07-09 10:17:06 +08:00
my $exifTool = Image::ExifTool->new;
2022-10-08 17:37:59 +08:00
$exifTool->SetNewValuesFromFile('t/images/MWG.jpg', 'Creator');
my $testfile = "t/${testname}_${testnum}_failed.xmp";
unlink $testfile;
$exifTool->WriteInfo(undef, $testfile);
my $info = $exifTool->ImageInfo($testfile, 'Creator');
if (check($exifTool, $info, $testname, $testnum)) {
unlink $testfile;
} else {
2024-07-09 10:17:06 +08:00
notOK();
2022-10-08 17:37:59 +08:00
}
print "ok $testnum\n";
}
# test 7: Extract MWG information from ExifTool.jpg
{
++$testnum;
2024-07-09 10:17:06 +08:00
my $exifTool = Image::ExifTool->new;
2022-10-08 17:37:59 +08:00
my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'MWG:*');
2024-07-09 10:17:06 +08:00
notOK() unless check($exifTool, $info, $testname, $testnum);
2022-10-08 17:37:59 +08:00
print "ok $testnum\n";
}
2024-07-09 10:17:06 +08:00
done(); # end