Nikon.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Before "make install", this script should be runnable with "make test".
  2. # After "make install" it should work as "perl t/Nikon.t".
  3. BEGIN { $| = 1; print "1..9\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::Nikon;
  8. $loaded = 1;
  9. print "ok 1\n";
  10. use t::TestLib;
  11. my $testname = 'Nikon';
  12. my $testnum = 1;
  13. # test 2: Extract information from Nikon.jpg
  14. {
  15. ++$testnum;
  16. my $exifTool = new Image::ExifTool;
  17. my $info = $exifTool->ImageInfo('t/images/Nikon.jpg');
  18. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  19. print "ok $testnum\n";
  20. }
  21. # test 3: Write some new information
  22. {
  23. ++$testnum;
  24. my @writeInfo = (
  25. [ Creator => 'Phil' ],
  26. [ ImageAdjustment => 'Yes, lots of it' ],
  27. );
  28. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum);
  29. print "ok $testnum\n";
  30. }
  31. # test 4: Test writing all D70 image information
  32. {
  33. ++$testnum;
  34. my $exifTool = new Image::ExifTool;
  35. $exifTool->SetNewValuesFromFile('t/images/NikonD70.jpg');
  36. my $testfile = "t/${testname}_${testnum}_failed.jpg";
  37. unlink $testfile;
  38. $exifTool->WriteInfo('t/images/Writer.jpg', $testfile);
  39. my $info = $exifTool->ImageInfo($testfile);
  40. if (check($exifTool, $info, $testname, $testnum)) {
  41. unlink $testfile;
  42. } else {
  43. print 'not ';
  44. }
  45. print "ok $testnum\n";
  46. }
  47. # test 5: Extract information from a D2Hs image
  48. {
  49. ++$testnum;
  50. my $exifTool = new Image::ExifTool;
  51. my $info = $exifTool->ImageInfo('t/images/NikonD2Hs.jpg');
  52. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  53. print "ok $testnum\n";
  54. }
  55. # test 6: Test Nikon decryption
  56. {
  57. ++$testnum;
  58. my $data = pack('N', 0x34a290d3);
  59. $data = Image::ExifTool::Nikon::Decrypt(\$data, 0x12345678, 0x00000123);
  60. my $expected = 0xcae17d2f;
  61. my $got = unpack('N', $data);
  62. unless ($got == $expected) {
  63. warn "\n Test $testnum (decryption) returned wrong value:\n";
  64. warn sprintf(" Expected 0x%x but got 0x%x\n", $expected, $got);
  65. print 'not ';
  66. }
  67. print "ok $testnum\n";
  68. }
  69. # test 7: Test reading NEF image
  70. {
  71. ++$testnum;
  72. my $exifTool = new Image::ExifTool;
  73. $exifTool->Options(Duplicates => 1);
  74. my $info = $exifTool->ImageInfo('t/images/Nikon.nef');
  75. print 'not ' unless check($exifTool, $info, $testname, $testnum);
  76. print "ok $testnum\n";
  77. }
  78. # test 8: Test writing Nikon Capture information in NEF image
  79. {
  80. ++$testnum;
  81. my @writeInfo = (
  82. ['PhotoEffects' => 'Off'],
  83. ['Caption-abstract' => 'A new caption'],
  84. ['VignetteControlIntensity' => '70'],
  85. );
  86. print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/Nikon.nef', 1);
  87. print "ok $testnum\n";
  88. }
  89. # test 9: Validate Nikon LensID values (internal check)
  90. {
  91. ++$testnum;
  92. my $lensIDs = $Image::ExifTool::Nikon::Composite{LensID}->{PrintConv};
  93. foreach (sort keys %$lensIDs) {
  94. next if /^(([0-9A-F]{2} ){7}[0-9A-F]{2}(\.\d+)?|Notes|OTHER)$/;
  95. warn "\n Bad LensID '$_' in test $testnum\n";
  96. print 'not ';
  97. last;
  98. }
  99. print "ok $testnum\n";
  100. }
  101. # end