GIF.t 2.5 KB

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