CanonRaw.t 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. # Before "make install", this script should be runnable with "make test".
  2. # After "make install" it should work as "perl t/CanonRaw.t".
  3. BEGIN { $| = 1; print "1..7\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::CanonRaw;
  8. $loaded = 1;
  9. print "ok 1\n";
  10. use t::TestLib;
  11. my $testname = 'CanonRaw';
  12. my $testnum = 1;
  13. # test 2: Extract information from CRW
  14. {
  15. ++$testnum;
  16. my $exifTool = new Image::ExifTool;
  17. my $info = $exifTool->ImageInfo('t/images/CanonRaw.crw');
  18. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  19. print "ok $testnum\n";
  20. }
  21. # test 3: Extract JpgFromRaw from CRW
  22. {
  23. ++$testnum;
  24. my $exifTool = new Image::ExifTool;
  25. $exifTool->Options(PrintConv => 0, IgnoreMinorErrors => 1);
  26. my $info = $exifTool->ImageInfo('t/images/CanonRaw.crw','JpgFromRaw');
  27. print 'not ' unless ${$info->{JpgFromRaw}} eq '<Dummy JpgFromRaw image data>';
  28. print "ok $testnum\n";
  29. }
  30. # test 4: Write a whole pile of tags to a CRW
  31. {
  32. ++$testnum;
  33. my $exifTool = new Image::ExifTool;
  34. # set IgnoreMinorErrors option to allow invalid JpgFromRaw to be written
  35. $exifTool->Options(IgnoreMinorErrors => 1);
  36. $exifTool->SetNewValuesFromFile('t/images/Canon.jpg');
  37. $exifTool->SetNewValue(SerialNumber => 1234);
  38. $exifTool->SetNewValue(OwnerName => 'Phil Harvey');
  39. $exifTool->SetNewValue(JpgFromRaw => 'not a real image');
  40. $exifTool->SetNewValue(ROMOperationMode => 'CDN');
  41. $exifTool->SetNewValue(FocalPlaneXSize => '35 mm');
  42. $exifTool->SetNewValue(FocalPlaneYSize => '24 mm');
  43. my $testfile = "t/${testname}_${testnum}_failed.crw";
  44. unlink $testfile;
  45. $exifTool->WriteInfo('t/images/CanonRaw.crw', $testfile);
  46. my $info = $exifTool->ImageInfo($testfile);
  47. if (check($exifTool, $info, $testname, $testnum)) {
  48. unlink $testfile;
  49. } else {
  50. print 'not ';
  51. }
  52. print "ok $testnum\n";
  53. }
  54. # test 5: Test verbose output
  55. {
  56. ++$testnum;
  57. print 'not ' unless testVerbose($testname, $testnum, 't/images/CanonRaw.crw', 1);
  58. print "ok $testnum\n";
  59. }
  60. # test 6: Write to CR2 file
  61. {
  62. ++$testnum;
  63. my $exifTool = new Image::ExifTool;
  64. # set IgnoreMinorErrors option to allow invalid JpgFromRaw to be written
  65. $exifTool->SetNewValue(Keywords => 'CR2 test');
  66. $exifTool->SetNewValue(OwnerName => 'Phil Harvey');
  67. $exifTool->SetNewValue(FocalPlaneXSize => '35mm');
  68. my $testfile = "t/${testname}_${testnum}_failed.cr2";
  69. unlink $testfile;
  70. $exifTool->WriteInfo('t/images/CanonRaw.cr2', $testfile);
  71. my $info = $exifTool->ImageInfo($testfile);
  72. my $success = check($exifTool, $info, $testname, $testnum);
  73. # make sure file suffix was copied properly
  74. while ($success) {
  75. open(TESTFILE, $testfile) or last;
  76. binmode(TESTFILE);
  77. my $endStr = '<Dummy preview image data>Non-TIFF data test';
  78. my $len = length $endStr;
  79. seek(TESTFILE, -$len, 2) or last;
  80. my $buff;
  81. read(TESTFILE, $buff, $len) == $len or last;
  82. close(TESTFILE);
  83. if ($buff eq $endStr) {
  84. unlink $testfile;
  85. $success = 2;
  86. } else {
  87. warn "\n Test $testnum failed to copy file suffix:\n";
  88. warn " Test gave: '$buff'\n";
  89. warn " Should be: '$endStr'\n";
  90. $success = 0;
  91. }
  92. last;
  93. }
  94. warn "\n Test $testnum: Error reading file suffix\n" if $success == 1;
  95. print 'not ' unless $success == 2;
  96. print "ok $testnum\n";
  97. }
  98. # test 7: Test copying all information from a CR2 image to a JPEG
  99. {
  100. ++$testnum;
  101. my $exifTool = new Image::ExifTool;
  102. $exifTool->SetNewValuesFromFile('t/images/CanonRaw.cr2');
  103. $testfile = "t/${testname}_${testnum}_failed.jpg";
  104. unlink $testfile;
  105. $exifTool->WriteInfo('t/images/Writer.jpg', $testfile);
  106. $exifTool->Options(Unknown => 1);
  107. my $info = $exifTool->ImageInfo($testfile);
  108. if (check($exifTool, $info, $testname, $testnum)) {
  109. unlink $testfile;
  110. } else {
  111. print 'not ';
  112. }
  113. print "ok $testnum\n";
  114. }
  115. # end