MWG.t 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Before "make install", this script should be runnable with "make test".
  2. # After "make install" it should work as "perl t/MWG.t".
  3. BEGIN { $| = 1; print "1..6\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::MWG;
  8. Image::ExifTool::MWG::Load();
  9. $loaded = 1;
  10. print "ok 1\n";
  11. use t::TestLib;
  12. my $testname = 'MWG';
  13. my $testnum = 1;
  14. # test 2: Extract MWG information from test image
  15. {
  16. ++$testnum;
  17. my $exifTool = new Image::ExifTool;
  18. $exifTool->Options(Duplicates => 0);
  19. my $info = $exifTool->ImageInfo('t/images/MWG.jpg', 'MWG:*');
  20. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  21. print "ok $testnum\n";
  22. }
  23. # tests 3-4: Write some MWG tags
  24. {
  25. my $exifTool = new Image::ExifTool;
  26. $exifTool->SetNewValue('MWG:DateTimeOriginal' => '2009:10:25 15:13:44.567-04:00');
  27. $exifTool->SetNewValue('MWG:Creator' => 'Creator One');
  28. $exifTool->SetNewValue('MWG:Creator' => 'Creator Two');
  29. $exifTool->SetNewValue('MWG:City' => 'Some city');
  30. my @tags = qw(
  31. EXIF:DateTimeOriginal EXIF:SubSecTimeOriginal
  32. IPTC:DateCreated IPTC:TimeCreated XMP-photoshop:DateCreated
  33. EXIF:Artist IPTC:By-line XMP-dc:Creator IPTC:City
  34. XMP-photoshop:City XMP-iptcExt:LocationShownCity
  35. );
  36. my $src;
  37. foreach $src('MWG.jpg', 'Writer.jpg') {
  38. ++$testnum;
  39. my $testfile = "t/${testname}_${testnum}_failed.jpg";
  40. unlink $testfile;
  41. $exifTool->WriteInfo("t/images/$src", $testfile);
  42. my $info = $exifTool->GetInfo('Warning');
  43. if ($$info{Warning}) {
  44. warn "\n Warning: $$info{Warning}\n";
  45. print 'not ';
  46. } else {
  47. $info = $exifTool->ImageInfo($testfile, @tags);
  48. if (check($exifTool, $info, $testname, $testnum)) {
  49. unlink $testfile;
  50. } else {
  51. print 'not ';
  52. }
  53. }
  54. print "ok $testnum\n";
  55. }
  56. }
  57. # test 5: Extract IPTC information from non-standard image while in strict MWG mode
  58. {
  59. ++$testnum;
  60. my $exifTool = new Image::ExifTool;
  61. my $info = $exifTool->ImageInfo('t/images/ExifTool.jpg', 'IPTC:*', 'Warning');
  62. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  63. print "ok $testnum\n";
  64. }
  65. # test 6: Copy a tag with MWG feature active
  66. {
  67. ++$testnum;
  68. my $exifTool = new Image::ExifTool;
  69. $exifTool->SetNewValuesFromFile('t/images/MWG.jpg', 'Creator');
  70. my $testfile = "t/${testname}_${testnum}_failed.xmp";
  71. unlink $testfile;
  72. $exifTool->WriteInfo(undef, $testfile);
  73. my $info = $exifTool->ImageInfo($testfile, 'Creator');
  74. if (check($exifTool, $info, $testname, $testnum)) {
  75. unlink $testfile;
  76. } else {
  77. print 'not ';
  78. }
  79. print "ok $testnum\n";
  80. }
  81. # end