PNG.t 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Before "make install", this script should be runnable with "make test".
  2. # After "make install" it should work as "perl t/PNG.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::PNG;
  8. $loaded = 1;
  9. print "ok 1\n";
  10. use t::TestLib;
  11. my $testname = 'PNG';
  12. my $testnum = 1;
  13. # test 2: Extract information from PNG.png
  14. {
  15. ++$testnum;
  16. my $exifTool = new Image::ExifTool;
  17. my $info = $exifTool->ImageInfo('t/images/PNG.png');
  18. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  19. print "ok $testnum\n";
  20. }
  21. # test 3: Write a bunch of new information to a PNG in memory
  22. {
  23. ++$testnum;
  24. my $exifTool = new Image::ExifTool;
  25. $exifTool->SetNewValuesFromFile('t/images/IPTC.jpg');
  26. $exifTool->SetNewValuesFromFile('t/images/XMP.jpg');
  27. $exifTool->SetNewValue('PNG:Comment'); # and delete a tag
  28. $exifTool->SetNewValue('PixelsPerUnitX', 1234);
  29. my $image;
  30. my $rtnVal = $exifTool->WriteInfo('t/images/PNG.png', \$image);
  31. # must ignore FileSize because size is variable (depends on Zlib availability)
  32. my $info = $exifTool->ImageInfo(\$image, '-filesize');
  33. my $testfile = "t/${testname}_${testnum}_failed.png";
  34. if (check($exifTool, $info, $testname, $testnum)) {
  35. unlink $testfile; # erase results of any bad test
  36. } else {
  37. # save the bad image
  38. open(TESTFILE,">$testfile");
  39. binmode(TESTFILE);
  40. print TESTFILE $image;
  41. close(TESTFILE);
  42. print 'not ';
  43. }
  44. print "ok $testnum\n";
  45. }
  46. # test 4: Test group delete, alternate languages and special characters
  47. {
  48. ++$testnum;
  49. my $exifTool = new Image::ExifTool;
  50. $exifTool->Options(Charset => 'Latin');
  51. $exifTool->SetNewValue('PNG:*');
  52. $exifTool->SetNewValue('XMP:*');
  53. $exifTool->SetNewValue('PNG:Comment-fr', "Commentaire fran\xe7aise");
  54. $exifTool->SetNewValue('PNG:Copyright', "\xa9 2010 Phil Harvey");
  55. $exifTool->SetNewValue('XMP:Description-bar' => "A Br\xfcn is a Gst\xf6");
  56. my $testfile = "t/${testname}_${testnum}_failed.png";
  57. unlink $testfile;
  58. my $rtnVal = $exifTool->WriteInfo('t/images/PNG.png', $testfile);
  59. $exifTool->Options(Charset => 'UTF8');
  60. my $info = $exifTool->ImageInfo($testfile, 'PNG:*', 'XMP:*');
  61. if (check($exifTool, $info, $testname, $testnum)) {
  62. unlink $testfile; # erase results of any bad test
  63. } else {
  64. print 'not ';
  65. }
  66. print "ok $testnum\n";
  67. }
  68. # test 5: Try moving XMP from after IDAT to before
  69. {
  70. ++$testnum;
  71. my $exifTool = new Image::ExifTool;
  72. # start with a clean image
  73. $exifTool->SetNewValue('all');
  74. my $image;
  75. $exifTool->WriteInfo('t/images/PNG.png', \$image);
  76. # add new XMP (should go after IDAT)
  77. $exifTool->SetNewValue();
  78. $exifTool->SetNewValue('XMP:Subject' => 'test');
  79. $exifTool->WriteInfo(\$image);
  80. # delete all XMP then copy back again (should move to before IDAT)
  81. $exifTool->SetNewValue();
  82. my $txtfile = "t/${testname}_${testnum}.failed";
  83. open PNG_TEST_5, ">$txtfile" or warn "Error opening $txtfile\n";
  84. $exifTool->Options(Verbose => 2);
  85. $exifTool->Options(TextOut => \*PNG_TEST_5);
  86. $exifTool->SetNewValue('xmp:all');
  87. $exifTool->SetNewValuesFromFile(\$image, 'all:all<xmp:all');
  88. my $rtnVal = $exifTool->WriteInfo(\$image);
  89. close PNG_TEST_5;
  90. if (testCompare('t/PNG_5.out', $txtfile, $testnum)) {
  91. unlink $txtfile;
  92. } else {
  93. print 'not ';
  94. }
  95. print "ok $testnum\n";
  96. }
  97. # end