1# Before "make install", this script should be runnable with "make test". 2# After "make install" it should work as "perl t/ExifTool.t". 3 4BEGIN { 5 $| = 1; print "1..32\n"; $Image::ExifTool::configFile = ''; 6 require './t/TestLib.pm'; t::TestLib->import(); 7} 8END {print "not ok 1\n" unless $loaded;} 9 10# test 1: Load the module(s) 11use Image::ExifTool 'ImageInfo'; 12$loaded = 1; 13print "ok 1\n"; 14 15my $testname = 'ExifTool'; 16my $testnum = 1; 17 18# test 2: extract information from JPG file using name 19{ 20 ++$testnum; 21 my $exifTool = new Image::ExifTool; 22 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg'); 23 print 'not ' unless check($exifTool, $info, $testname, $testnum); 24 print "ok $testnum\n"; 25} 26 27# test 3: TIFF file using file reference and ExifTool object with options 28{ 29 ++$testnum; 30 my $exifTool = new Image::ExifTool; 31 $exifTool->Options(Duplicates => 1, Unknown => 1); 32 open(TESTFILE, 't/images/ExifTool.tif'); 33 my $info = $exifTool->ImageInfo(\*TESTFILE); 34 close(TESTFILE); 35 print 'not ' unless check($exifTool, $info, $testname, $testnum); 36 print "ok $testnum\n"; 37} 38 39# test 4: test the Group option to extract EXIF info only 40{ 41 ++$testnum; 42 my $info = ImageInfo('t/images/Canon.jpg', {Group0 => 'EXIF'}); 43 print 'not ' unless check($info, $testname, $testnum); 44 print "ok $testnum\n"; 45} 46 47# test 5: extract specified tags only 48{ 49 ++$testnum; 50 my $exifTool = new Image::ExifTool; 51# don't test DateFormat because strftime output varies with locale 52# $exifTool->Options(DateFormat => '%H:%M:%S %a. %b. %e, %Y'); 53 my @tags = ('CreateDate', 'DateTimeOriginal', 'ModifyDate', 'Orientation#', '?Resolution'); 54 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', \@tags); 55 print 'not ' unless check($exifTool, $info, $testname, $testnum); 56 print "ok $testnum\n"; 57} 58 59# test 6: test the 5 different ways to exclude tags... 60{ 61 ++$testnum; 62 my $exifTool = new Image::ExifTool; 63 $exifTool->Options(Exclude => 'ImageWidth'); 64 my @tagList = ( '-ImageHeight', '-Make' ); 65 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', '-FileSize', '-*resolution', 66 \@tagList, {Group0 => '-MakerNotes'}); 67 print 'not ' unless check($exifTool, $info, $testname, $testnum); 68 print "ok $testnum\n"; 69} 70 71# tests 7/8: test ExtractInfo(), GetInfo(), CombineInfo() 72{ 73 ++$testnum; 74 my $exifTool = new Image::ExifTool; 75 $exifTool->Options(Duplicates => 0); # don't allow duplicates 76 $exifTool->ExtractInfo('t/images/Canon.jpg'); 77 my $info1 = $exifTool->GetInfo({Group0 => 'MakerNotes'}); 78 my $info2 = $exifTool->GetInfo({Group0 => 'EXIF'}); 79 my $info = $exifTool->CombineInfo($info1, $info2); 80 print 'not ' unless check($exifTool, $info, $testname, $testnum); 81 print "ok $testnum\n"; 82 83 # combine information in different order 84 ++$testnum; 85 $info = $exifTool->CombineInfo($info2, $info1); 86 print 'not ' unless check($exifTool, $info, $testname, $testnum); 87 print "ok $testnum\n"; 88} 89 90# test 9: test group options across different families 91{ 92 ++$testnum; 93 my $exifTool = new Image::ExifTool; 94 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', 95 { Group1 => 'Canon', Group2 => '-Camera' }); 96 print 'not ' unless check($exifTool, $info, $testname, $testnum); 97 print "ok $testnum\n"; 98} 99 100# tests 10/11: test ExtractInfo() and GetInfo() 101# (uses output from test 5 for comparison) 102{ 103 ++$testnum; 104 my $exifTool = new Image::ExifTool; 105# don't test DateFormat because strftime output is system dependent 106# $exifTool->Options(DateFormat => '%H:%M:%S %a. %b. %e, %Y'); 107 $exifTool->ExtractInfo('t/images/Canon.jpg'); 108 my @tags = ('createdate', 'datetimeoriginal', 'modifydate', 'orientation#', '?resolution'); 109 my $info = $exifTool->GetInfo(\@tags); 110 my $good = 1; 111 my @expectedTags = ('CreateDate', 'DateTimeOriginal', 'ModifyDate', 'Orientation', 112 'XResolution', 'YResolution'); 113 for (my $i=0; $i<scalar(@tags); ++$i) { 114 $tags[$i] = $expectedTags[$i] or $good = 0; 115 } 116 print 'not ' unless $good; 117 print "ok $testnum\n"; 118 119 ++$testnum; 120 print 'not ' unless check($exifTool, $info, $testname, $testnum, 5); 121 print "ok $testnum\n"; 122} 123 124# tests 12/13: check precedence of tags extracted from groups 125# (Note: these tests should produce the same output as 7/8, 126# so the .out files from tests 7/8 are used) 127{ 128 ++$testnum; 129 my $exifTool = new Image::ExifTool; 130 $exifTool->Options(Duplicates => 0); # don't allow duplicates 131 my $info = $exifTool->ImageInfo('t/images/Canon.jpg',{Group0=>['MakerNotes','EXIF']}); 132 print 'not ' unless check($exifTool, $info, $testname, $testnum, 7); 133 print "ok $testnum\n"; 134 135 # combine information in different order 136 ++$testnum; 137 $info = $exifTool->ImageInfo('t/images/Canon.jpg',{Group0=>['EXIF','MakerNotes']}); 138 print 'not ' unless check($exifTool, $info, $testname, $testnum, 8); 139 print "ok $testnum\n"; 140} 141 142# tests 14/15/16: test GetGroups() 143{ 144 ++$testnum; 145 my $exifTool = new Image::ExifTool; 146 $exifTool->ExtractInfo('t/images/Canon.jpg'); 147 my @groups = $exifTool->GetGroups(2); 148 my $not; 149 foreach ('Camera','ExifTool','Image','Other','Time') { 150 my $g = shift @groups || ''; 151 $_ eq $g or warn("\nWrong group: $_ ne $g\n"), $not = 1; 152 } 153 @groups and $not = 1; 154 print 'not ' if $not; 155 print "ok $testnum\n"; 156 157 ++$testnum; 158 my $info = $exifTool->GetInfo({Group0 => 'EXIF'}); 159 @groups = $exifTool->GetGroups($info,0); 160 print 'not ' unless @groups==1 and $groups[0] eq 'EXIF'; 161 print "ok $testnum\n"; 162 163 ++$testnum; 164 my $testfile = "t/ExifTool_$testnum"; 165 open(TESTFILE,">$testfile.failed"); 166 my $oldSep = $/; 167 $/ = "\x0a"; # set input line separator 168 $exifTool->ExtractInfo('t/images/Canon.jpg'); 169 my $family = '1:2'; 170 @groups = $exifTool->GetGroups($family); 171 my $group; 172 foreach $group (@groups) { 173 next if $group eq 'ExifTool'; 174 print TESTFILE "---- $group ----\n"; 175 my $info = $exifTool->GetInfo({"Group$family" => $group}); 176 foreach (sort $exifTool->GetTagList($info)) { 177 print TESTFILE "$_ : $$info{$_}\n"; 178 } 179 } 180 $/ = $oldSep; # restore input line separator 181 close(TESTFILE); 182 print 'not ' unless testCompare("$testfile.out","$testfile.failed",$testnum); 183 print "ok $testnum\n"; 184} 185 186# test 17: Test verbose output 187{ 188 ++$testnum; 189 print 'not ' unless testVerbose($testname, $testnum, 't/images/Canon.jpg', 3); 190 print "ok $testnum\n"; 191} 192 193# tests 18/19: Test Group# option with multiple groups and no duplicates 194{ 195 ++$testnum; 196 my $exifTool = new Image::ExifTool; 197 $exifTool->Options(Duplicates => 0); # don't allow duplicates 198 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', 199 { Group0 => ['MakerNotes','EXIF'] }); 200 print 'not ' unless check($exifTool, $info, $testname, $testnum, 7); 201 print "ok $testnum\n"; 202 203 ++$testnum; 204 $info = $exifTool->ImageInfo('t/images/Canon.jpg', 205 { Group0 => ['EXIF','MakerNotes'] }); 206 print 'not ' unless check($exifTool, $info, $testname, $testnum, 8); 207 print "ok $testnum\n"; 208} 209 210# test 20: Test extracting a single, non-priority tag with duplicates set to 0 211{ 212 ++$testnum; 213 my $exifTool = new Image::ExifTool; 214 $exifTool->Options(Duplicates => 0); 215 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', 'EXIF:WhiteBalance'); 216 print 'not ' unless check($exifTool, $info, $testname, $testnum); 217 print "ok $testnum\n"; 218} 219 220# test 21: Test extracting ICC_Profile as a block 221{ 222 ++$testnum; 223 my $exifTool = new Image::ExifTool; 224 my $info = $exifTool->ImageInfo('t/images/ExifTool.tif', 'ICC_Profile'); 225 print 'not ' unless check($exifTool, $info, $testname, $testnum); 226 print "ok $testnum\n"; 227} 228 229# test 22: Test InsertTagValues 230{ 231 ++$testnum; 232 my $exifTool = new Image::ExifTool; 233 my @foundTags; 234 $exifTool->ImageInfo('t/images/ExifTool.jpg', \@foundTags); 235 my $str = $exifTool->InsertTagValues(\@foundTags, '${ifd0:model;tr/i/_/} - $1ciff:3main:model'); 236 my $testfile = "t/ExifTool_$testnum"; 237 open(TESTFILE,">$testfile.failed"); 238 my $oldSep = $/; 239 $/ = "\x0a"; # set input line separator 240 print TESTFILE $str, "\n"; 241 $/ = $oldSep; # restore input line separator 242 close(TESTFILE); 243 print 'not ' unless testCompare("$testfile.out","$testfile.failed",$testnum); 244 print "ok $testnum\n"; 245} 246 247# test 23: Test the multi-group feature in a tag name 248{ 249 ++$testnum; 250 my $exifTool = new Image::ExifTool; 251 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'main:Author:IPTC3:all'); 252 print 'not ' unless check($exifTool, $info, $testname, $testnum); 253 print "ok $testnum\n"; 254} 255 256# test 24: Test a shortcut with multiple group names and a ValueConv suffix 257{ 258 ++$testnum; 259 my $exifTool = new Image::ExifTool; 260 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', 'exififd:camera:common#'); 261 print 'not ' unless check($exifTool, $info, $testname, $testnum); 262 print "ok $testnum\n"; 263} 264 265# test 25: Test GlobalTimeShift option 266{ 267 ++$testnum; 268 if (eval { require Time::Local }) { 269 my $exifTool = new Image::ExifTool; 270 $exifTool->Options(GlobalTimeShift => '-0:1:0 0:0:0'); 271 # Note: can't extract system times because this could result in a different 272 # calculated global time offset (since I am shifting by 1 month) 273 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'time:all', '-system:all'); 274 print 'not ' unless check($exifTool, $info, $testname, $testnum); 275 print "ok $testnum\n"; 276 } else { 277 print "ok $testnum # skip Requires Time::Local\n"; 278 } 279} 280 281# test 26: Test wildcards using '#' suffix with duplicate PrintConv tags and exclusions 282{ 283 ++$testnum; 284 my $exifTool = new Image::ExifTool; 285 # (hack to avoid sorting in TestLib.pm because order of duplicate tags would be indeterminate) 286 $$exifTool{NO_SORT} = 1; 287 my $info = $exifTool->ImageInfo('t/images/Canon.jpg', 'encodingprocess', 'E*#', 'exposureMode', 288 '-ExifVersion'); 289 print 'not ' unless check($exifTool, $info, $testname, $testnum); 290 print "ok $testnum\n"; 291} 292 293# test 27: Test ListItem option 294{ 295 ++$testnum; 296 my $exifTool = new Image::ExifTool; 297 $exifTool->Options(ListItem => -3); 298 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'Subject', 'SupplementalCategories'); 299 print 'not ' unless check($exifTool, $info, $testname, $testnum); 300 print "ok $testnum\n"; 301} 302 303# test 28: Test FastScan = 3 304{ 305 ++$testnum; 306 my $exifTool = new Image::ExifTool; 307 $exifTool->Options(FastScan => 3); 308 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg'); 309 print 'not ' unless check($exifTool, $info, $testname, $testnum); 310 print "ok $testnum\n"; 311} 312 313# test 29: Test Filter 314{ 315 ++$testnum; 316 my $exifTool = new Image::ExifTool; 317 $exifTool->Options(Filter => 'tr/ /_/;tr/0-9/#/'); 318 my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', '-ExifToolVersion'); 319 print 'not ' unless check($exifTool, $info, $testname, $testnum); 320 print "ok $testnum\n"; 321} 322 323# test 30: Calculate JPEGDigest and JPEGQualityEstimate 324{ 325 ++$testnum; 326 my $skip = ''; 327 if (eval 'require Digest::MD5') { 328 my $exifTool = new Image::ExifTool; 329 my $info = $exifTool->ImageInfo('t/images/Writer.jpg', 'JPEGDigest', 'JPEGQualityEstimate'); 330 print 'not ' unless check($exifTool, $info, $testname, $testnum); 331 } else { 332 $skip = ' # skip Requires Digest::MD5'; 333 } 334 print "ok $testnum$skip\n"; 335} 336 337# test 31: Test Validate feature 338{ 339 ++$testnum; 340 my $exifTool = new Image::ExifTool; 341 my $info = $exifTool->ImageInfo('t/images/CanonRaw.cr2', 'Validate', 'Warning', 'Error'); 342 print 'not ' unless check($exifTool, $info, $testname, $testnum); 343 print "ok $testnum\n"; 344} 345 346# test 32: Read JPS file 347{ 348 ++$testnum; 349 my $exifTool = new Image::ExifTool; 350 my $info = $exifTool->ImageInfo('t/images/ExifTool.jps', 'jps:all'); 351 print 'not ' unless check($exifTool, $info, $testname, $testnum); 352 print "ok $testnum\n"; 353} 354 355# end 356