1# Before "make install", this script should be runnable with "make test". 2# After "make install" it should work as "perl t/GIF.t". 3 4BEGIN { 5 $| = 1; print "1..5\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'; 12use Image::ExifTool::GIF; 13$loaded = 1; 14print "ok 1\n"; 15 16my $testname = 'GIF'; 17my $testnum = 1; 18 19# test 2: GIF file using data in memory 20{ 21 ++$testnum; 22 open(TESTFILE, 't/images/GIF.gif'); 23 binmode(TESTFILE); 24 my $gifImage; 25 read(TESTFILE, $gifImage, 100000); 26 close(TESTFILE); 27 my $info = ImageInfo(\$gifImage); 28 print 'not ' unless check($info, $testname, $testnum); 29 print "ok $testnum\n"; 30} 31 32# tests 3-5: Test adding/editing/deleting various types of metadata for GIF images in memory 33{ 34 ++$testnum; 35 open(TESTFILE, 't/images/GIF.gif'); 36 binmode(TESTFILE); 37 my $gifImage; 38 read(TESTFILE, $gifImage, 100000); 39 close(TESTFILE); 40 my $exifTool = new Image::ExifTool; 41 $exifTool->SetNewValue(Comment => 'a new comment'); 42 $exifTool->SetNewValue(City => 'Kingston'); 43 my $image1; 44 $exifTool->WriteInfo(\$gifImage, \$image1); 45 $info = ImageInfo(\$image1); 46 print 'not ' unless check($info, $testname, $testnum); 47 print "ok $testnum\n"; 48 49 ++$testnum; 50 $exifTool->SetNewValue(); # clear previous new values 51 $exifTool->SetNewValue('all'); # delete everything... 52 # add back some XMP tags 53 $exifTool->SetNewValue(Comment => 'x'); 54 $exifTool->SetNewValue(Subject => ['one','two','three']); 55 $exifTool->SetNewValue(Country => 'Canada'); 56 my $image2; 57 $exifTool->WriteInfo(\$image1, \$image2); 58 $info = ImageInfo(\$image2); 59 print 'not ' unless check($info, $testname, $testnum); 60 print "ok $testnum\n"; 61 62 ++$testnum; 63 $info = ImageInfo(\$gifImage, 'Comment', 'XMP', 'ICC_Profile'); 64 $exifTool->SetNewValue(); # clear previous new values 65 $exifTool->SetNewValue(Comment => $$info{Comment}); 66 $exifTool->SetNewValue(XMP => $$info{XMP}, Protected => 1); 67 $exifTool->SetNewValue(ICC_Profile => $$info{ICC_Profile}, Protected => 1); 68 my $image3; 69 $exifTool->WriteInfo(\$image2, \$image3); 70 my $testfile = "t/${testname}_${testnum}_failed.gif"; 71 if ($image3 eq $gifImage) { 72 unlink $testfile; 73 } else { 74 # save the bad image 75 open(TESTFILE,">$testfile"); 76 binmode(TESTFILE); 77 print TESTFILE $image3; 78 close(TESTFILE); 79 print 'not '; 80 } 81 print "ok $testnum\n"; 82} 83 84# end 85