summaryrefslogtreecommitdiff
path: root/t/QuickTime.t
blob: ac11aac2141eb37947d995c090723ff6db41f3a3 (plain)
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# Before "make install", this script should be runnable with "make test".
# After "make install" it should work as "perl t/QuickTime.t".

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

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

# tests 2-3: Extract information from QuickTime.mov and QuickTime.m4a
{
    my $ext;
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        my $exifTool = new Image::ExifTool;
        my $info = $exifTool->ImageInfo("t/images/QuickTime.$ext");
        print 'not ' unless check($exifTool, $info, $testname, $testnum);
        print "ok $testnum\n";
    }
}

# tests 4-5: Try writing XMP to the different file formats
{
    my $ext;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(SavePath => 1); # to save group 5 names
    $exifTool->SetNewValue('XMP:Title' => 'x');
    $exifTool->SetNewValue('TrackCreateDate' => '2000:01:02 03:04:05');
    $exifTool->SetNewValue('Track1:TrackModifyDate' => '2013:11:04 10:32:15');
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        unless (eval { require Time::Local }) {
            print "ok $testnum # skip Requires Time::Local\n";
            next;
        }
        my $testfile = "t/${testname}_${testnum}_failed.$ext";
        unlink $testfile;
        my $rtnVal = $exifTool->WriteInfo("t/images/QuickTime.$ext", $testfile);
        my $info = $exifTool->ImageInfo($testfile, 'title', 'time:all');
        if (check($exifTool, $info, $testname, $testnum, undef, 5)) {
            unlink $testfile;
        } else {
            print 'not ';
        }
        print "ok $testnum\n";
    }
}

# test 6: Write video rotation
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->SetNewValue('Rotation' => '270', Protected => 1);
    my $testfile = "t/${testname}_${testnum}_failed.mov";
    unlink $testfile;
    my $rtnVal = $exifTool->WriteInfo('t/images/QuickTime.mov', $testfile);
    my $info = $exifTool->ImageInfo($testfile, 'Rotation', 'MatrixStructure');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 7: Add a bunch of new tags and delete one
{
    ++$testnum;
    my @writeInfo = (
        ['QuickTime:Artist' => 'me'],
        ['QuickTime:Model' => 'model'],
        ['UserData:Genre' => 'rock'],
        ['UserData:Album' => 'albumA'],
        ['ItemList:Album' => 'albumB'],
        ['ItemList:ID-albm:Album' => 'albumC'],
        ['QuickTime:Comment-fra-FR' => 'fr comment'],
        ['Keys:Director' => 'director'],
        ['Keys:CameraDirection' => '90'],
        ['Keys:Album' => undef ],
    );
    my @extract = ('ItemList:all', 'UserData:all', 'Keys:all');
    print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, 't/images/QuickTime.mov', \@extract);
    print "ok $testnum\n";
}

# test 8-9: Delete everything then add back some tags in one step
{
    my $ext;
    my $exifTool = new Image::ExifTool;
    my @writeInfo = (
        ['all' => undef],
        ['artist' => 'me'],
        ['keys:director' => 'dir'],
        ['userdata:arranger' => 'arr'],
    );
    my @extract = ('QuickTime:all', 'XMP:all');
    foreach $ext (qw(mov m4a)) {
        ++$testnum;
        print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, "t/images/QuickTime.$ext", \@extract);
        print "ok $testnum\n";
    }
}

# test 10: Delete everything then add back some tags in two steps
{
    ++$testnum;
    my $testfile = "t/${testname}_${testnum}a_failed.mov";
    unlink $testfile;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(QuickTimeHandler => 1);
    $exifTool->SetNewValue('all' => undef);
    writeInfo($exifTool, 't/images/QuickTime.mov', $testfile);
    my @writeInfo = (
        ['quicktime:artist' => 'me'],
        ['keys:director' => 'dir'],
        ['userdata:arranger' => 'arr'],
    );
    my @extract = ('QuickTime:all', 'XMP:all', '-Track1:all', '-Track2:all');
    print 'not ' unless writeCheck(\@writeInfo, $testname, $testnum, $testfile, \@extract);
    print "ok $testnum\n";
}

# tests 11-13: HEIC write tests
{
    ++$testnum;
    my $testfile = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(Composite => 0);
    $exifTool->SetNewValue('XMP-dc:Title' => 'a title');
    writeInfo($exifTool, 't/images/QuickTime.heic', $testfile);
    my $info = $exifTool->ImageInfo($testfile, '-file:all');
    unless (check($exifTool, $info, $testname, $testnum)) {
        print 'not ';
    }
    print "ok $testnum\n";

    ++$testnum;
    my $testfile2 = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile2;
    $exifTool->SetNewValue();
    $exifTool->SetNewValue('XMP:all' => undef);
    $exifTool->SetNewValue('EXIF:Artist' => 'an artist');
    writeInfo($exifTool, $testfile, $testfile2);
    $info = $exifTool->ImageInfo($testfile2, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";

    ++$testnum;
    $testfile = "t/${testname}_${testnum}_failed.heic";
    unlink $testfile;
    $exifTool->SetNewValue();
    $exifTool->SetNewValue('EXIF:all' => undef);
    $exifTool->SetNewValue('EXIF:UserComment' => 'a comment');
    $exifTool->SetNewValue('XMP:Subject' => 'a subject');
    $exifTool->SetNewValue('XMP:Subject' => 'another subject');
    writeInfo($exifTool, $testfile2, $testfile);
    $info = $exifTool->ImageInfo($testfile, '-file:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
        unlink $testfile2;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 14: Delete everything then add back a tag without specifying the group
{
    ++$testnum;
    my $testfile = "t/${testname}_10a_failed.mov";  # use source file from test 10
    my @writeInfo = ( ['publisher' => 'pub'] );
    my @extract = ('QuickTime:all', 'XMP:all', '-Track1:all', '-Track2:all');
    if (writeCheck(\@writeInfo, $testname, $testnum, $testfile, \@extract)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 15: Test WriteMode option with QuickTime tags
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->Options(WriteMode => 'c');
    $exifTool->SetNewValue('ItemList:Composer' => 'WRONG');
    $exifTool->SetNewValue('ItemList:Author' => 'aut');
    $exifTool->SetNewValue('Keys:Artist' => 'WRONG');
    $exifTool->SetNewValue('UserData:Artist' => 'art');
    my $testfile = "t/${testname}_${testnum}_failed.m4a";
    unlink $testfile;
    my $rtnVal = $exifTool->WriteInfo('t/images/QuickTime.m4a', $testfile);
    my $info = $exifTool->ImageInfo($testfile, 'ItemList:all', 'Keys:all', 'UserData:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}

# test 16: Write some Microsoft Xtra tags
{
    ++$testnum;
    my $exifTool = new Image::ExifTool;
    $exifTool->SetNewValue('Microsoft:Director' => 'dir1');
    $exifTool->SetNewValue('Microsoft:Director' => 'dir2');
    $exifTool->SetNewValue('Microsoft:SharedUserRating' => 75);
    my $testfile = "t/${testname}_${testnum}_failed.mov";
    unlink $testfile;
    my $rtnVal = $exifTool->WriteInfo('t/images/QuickTime.mov', $testfile);
    my $info = $exifTool->ImageInfo($testfile, 'Microsoft:all');
    if (check($exifTool, $info, $testname, $testnum)) {
        unlink $testfile;
    } else {
        print 'not ';
    }
    print "ok $testnum\n";
}


# end