File: Nikon.t

package info (click to toggle)
libimage-exiftool-perl 11.16-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,024 kB
  • sloc: perl: 245,177; xml: 120; makefile: 9
file content (123 lines) | stat: -rw-r--r-- 3,669 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/Nikon.t".

BEGIN {
    $| = 1; print "1..9\n"; $Image::ExifTool::configFile = '';
    require './t/TestLib.pm'; t::TestLib->import();
}
END {print "not ok 1\n" unless $loaded;}

# test 1: Load the module(s)
use Image::ExifTool 'ImageInfo';
use Image::ExifTool::Nikon;
$loaded = 1;
print "ok 1\n";

my $testname = 'Nikon';
my $testnum = 1;

# test 2: Extract information from Nikon.jpg
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    my $info = $exifTool->ImageInfo('t/images/Nikon.jpg');
    print 'not ' unless check($exifTool, $info, $testname, $testnum);
    print "ok $testnum\n";
}

# test 3: Write some new information
{
    ++$testnum;
    my @writeInfo = (
        [ Creator => 'Phil' ],
        [ ImageAdjustment => 'Yes, lots of it' ],
    );
    print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum);
    print "ok $testnum\n";
}

# test 4: Test writing all D70 image information
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->SetNewValuesFromFile('t/images/NikonD70.jpg');
    my $testfile = "t/${testname}_${testnum}_failed.jpg";
    unlink $testfile;
    $exifTool->WriteInfo('t/images/Writer.jpg', $testfile);
    my $info = $exifTool->ImageInfo($testfile);
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 5: Extract information from a D2Hs image
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    my $info = $exifTool->ImageInfo('t/images/NikonD2Hs.jpg');
    print 'not ' unless check($exifTool, $info, $testname, $testnum);
    print "ok $testnum\n";
}

# test 6: Test Nikon decryption
{
    ++$testnum;
    my $data = pack('N', 0x34a290d3);
    $data = Image::ExifTool::Nikon::Decrypt(\$data, 0x12345678, 0x00000123);
    my $expected = 0xcae17d2f;
    my $got = unpack('N', $data);
    unless ($got == $expected) {
        warn "\n  Test $testnum (decryption) returned wrong value:\n";
        warn sprintf("    Expected 0x%x but got 0x%x\n", $expected, $got);
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 7: Test reading NEF image
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(Duplicates => 1);
    my $info = $exifTool->ImageInfo('t/images/Nikon.nef');
    print 'not ' unless check($exifTool, $info, $testname, $testnum);
    print "ok $testnum\n";
}

# test 8: Test writing Nikon Capture information in NEF image
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(IgnoreMinorErrors => 1);
    $exifTool->SetNewValue('PhotoEffects' => 'Off');
    $exifTool->SetNewValue('Caption-abstract' => 'A new caption');
    $exifTool->SetNewValue('VignetteControlIntensity' => '70');
    my $testfile = "t/${testname}_${testnum}_failed.nef";
    unlink $testfile;
    $exifTool->WriteInfo('t/images/Nikon.nef', $testfile);
    my $info = $exifTool->ImageInfo($testfile, qw(PhotoEffects Caption-abstract VignetteControlIntensity));
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 9: Validate Nikon LensID values (internal check)
{
    ++$testnum;
    my $lensIDs = $Image::ExifTool::Nikon::Composite{LensID}->{PrintConv};
    foreach (sort keys %$lensIDs) {
        next if /^(([0-9A-F]{2} ){7}[0-9A-F]{2}(\.\d+)?|Notes|OTHER)$/;
        warn "\n  Bad LensID '$_' in test $testnum\n";
        print 'not ';
        last;
    }
    print "ok $testnum\n";
}

# end