File: CanonRaw.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 (148 lines) | stat: -rw-r--r-- 5,094 bytes parent folder | download
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/CanonRaw.t".

BEGIN {
    $| = 1; print "1..8\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::CanonRaw;
$loaded = 1;
print "ok 1\n";

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

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

# test 3: Extract JpgFromRaw from CRW
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(PrintConv => 0, IgnoreMinorErrors => 1);
    my $info = $exifTool->ImageInfo('t/images/CanonRaw.crw','JpgFromRaw');
    print 'not ' unless ${$info->{JpgFromRaw}} eq '<Dummy JpgFromRaw image data>';
    print "ok $testnum\n";
}

# test 4: Write a whole pile of tags to a CRW
{
    ++$testnum;
    if (eval { require Time::Local }) {
        my $exifTool = new Image::ExifTool;
        # set IgnoreMinorErrors option to allow invalid JpgFromRaw to be written
        $exifTool->Options(IgnoreMinorErrors => 1);
        $exifTool->SetNewValuesFromFile('t/images/Canon.jpg');
        $exifTool->SetNewValue(SerialNumber => 1234);
        $exifTool->SetNewValue(OwnerName => 'Phil Harvey');
        $exifTool->SetNewValue(JpgFromRaw => 'not a real image');
        $exifTool->SetNewValue(ROMOperationMode => 'CDN');
        $exifTool->SetNewValue(FocalPlaneXSize => '35 mm');
        $exifTool->SetNewValue(FocalPlaneYSize => '24 mm');
        my $testfile = "t/${testname}_${testnum}_failed.crw";
        unlink $testfile;
        $exifTool->WriteInfo('t/images/CanonRaw.crw', $testfile);
        my $info = $exifTool->ImageInfo($testfile);
        if (check($exifTool, $info, $testname, $testnum)) {
            unlink $testfile;
        } else {
            print 'not ';
        }
        print "ok $testnum\n";
    } else {
        print "ok $testnum # skip Requires Time::Local\n";
    }
}

# test 5: Test verbose output
{
    ++$testnum;
    print 'not ' unless testVerbose($testname, $testnum, 't/images/CanonRaw.crw', 1);
    print "ok $testnum\n";
}

# test 6: Write to CR2 file
{
    ++$testnum;
    if (eval { require Time::Local }) {
        my $exifTool = new Image::ExifTool;
        # set IgnoreMinorErrors option to allow invalid JpgFromRaw to be written
        $exifTool->SetNewValue(Keywords => 'CR2 test');
        $exifTool->SetNewValue(OwnerName => 'Phil Harvey');
        $exifTool->SetNewValue(FocalPlaneXSize => '35mm');
        my $testfile = "t/${testname}_${testnum}_failed.cr2";
        unlink $testfile;
        $exifTool->WriteInfo('t/images/CanonRaw.cr2', $testfile);
        my $info = $exifTool->ImageInfo($testfile);
        my $success = check($exifTool, $info, $testname, $testnum);
        # make sure file suffix was copied properly
        while ($success) {
            open(TESTFILE, $testfile) or last;
            binmode(TESTFILE);
            my $endStr = '<Dummy preview image data>Non-TIFF data test';
            my $len = length $endStr;
            seek(TESTFILE, -$len, 2) or last;
            my $buff;
            read(TESTFILE, $buff, $len) == $len or last;
            close(TESTFILE);
            if ($buff eq $endStr) {
                unlink $testfile;
                $success = 2;
            } else {
                warn "\n  Test $testnum failed to copy file suffix:\n";
                warn "    Test gave: '$buff'\n";
                warn "    Should be: '$endStr'\n";
                $success = 0;
            }
            last;
        }
        warn "\n  Test $testnum: Error reading file suffix\n" if $success == 1;
        print 'not ' unless $success == 2;
        print "ok $testnum\n";
    } else {
        print "ok $testnum # skip Requires Time::Local\n";
    }
}

# test 7: Test copying all information from a CR2 image to a JPEG
{
    ++$testnum;
    if (eval { require Time::Local }) {
        my $exifTool = new Image::ExifTool;
        $exifTool->SetNewValuesFromFile('t/images/CanonRaw.cr2');
        $testfile = "t/${testname}_${testnum}_failed.jpg";
        unlink $testfile;
        $exifTool->WriteInfo('t/images/Writer.jpg', $testfile);
        $exifTool->Options(Unknown => 1);
        my $info = $exifTool->ImageInfo($testfile);
        if (check($exifTool, $info, $testname, $testnum)) {
            unlink $testfile;
        } else {
            print 'not ';
        }
        print "ok $testnum\n";
    } else {
        print "ok $testnum # skip Requires Time::Local\n";
    }
}

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

# end