File: JPEG_5_exif_GPS.t

package info (click to toggle)
libimage-metadata-jpeg-perl 0.159-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,236 kB
  • sloc: perl: 3,676; makefile: 2
file content (274 lines) | stat: -rw-r--r-- 10,292 bytes parent folder | download | duplicates (3)
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
use Test::More tests => 48;
BEGIN { require 't/test_setup.pl'; }

my $tphoto = 't/test_photo.jpg';
my $tdata  = 't/test_photo.desc';
my ($image, $image2, $seg, $hash, $lat, $long, $track, $str, $d1, $d2, $ref);

my $GPS_data = {
    'GPSLatitudeRef'  => "N\000",
    'GPSLatitude'     => [ 80, 1, 30, 1, 12, 1 ],
    'GPSLongitudeRef' => "W\000",
    'GPSLongitude'    => [ 15, 1, 49, 1, 50, 1 ],
    0x05              => 1, # 'GPSAltitude'
    0x06              => [ 2000, 100 ],
    0x07              => [12, 1, 13, 1, 0, 1],
    0x08              => "I really don't know",
    'GPSStatus'       => 'A',
    'GPSMeasureMode'  => '2',
    'GPSDOP'          => [ 125, 7 ],
    'GPSSpeedRef'     => 'K',
    0x0d              => [ 30000, 13 ],
    0x0e              => 'M',
    0x0f              => [ 125, 2 ],
    0x10              => 'T',
    'GPSImgDirection' => [ 12, 1 ],
    'GPSMapDatum'     => "Again, I don't know\000",
    'GPSDestLatitudeRef' => 'N',
    'GPSDestLatitude' => [ 118, 2, 3000, 100, 0, 1 ],
    0x15              => 'W',
    0x16              => [ 15, 3, 49, 3, 50, 3 ],
    0x17              => 'T',
    0x18              => [ 13940, 1000 ],
    'GPSDestDistanceRef' => 'M',
    'GPSDestDistance' => [ 49, 1 ],
    'GPSProcessingMethod' => "Jundefined string\000",
    'GPSAreaInformation' => "\000xyz\00uh",
    'GPSDateStamp'    => "1999:12:31",
    'GPSDifferential' => 0 };

#=======================================
diag "Testing APP1 Exif data routines (GPS_DATA)";
#=======================================

BEGIN { use_ok ($::pkgname) or exit; }

#########################
$image = newimage($tphoto, '^APP1$');
$seg   = $image->retrieve_app1_Exif_segment(0);
isnt( $seg, undef, "The Exif segment is there, hi!" );

#########################
$hash = $seg->set_Exif_data($GPS_data, 'GPL_DATA', 'REPLACE');
ok( exists $$hash{'ERROR'}, $$hash{'ERROR'} );

#########################
$hash = $seg->set_Exif_data($GPS_data, 'GPS_DATA', 'SPEAK');
ok( exists $$hash{'ERROR'}, $$hash{'ERROR'} );

#########################
$hash = $seg->set_Exif_data($GPS_data, 'GPS_DATA', 'ADD');
is_deeply( $hash, {}, "all test GPS records ADDed" );

#########################
$hash = $seg->get_Exif_data('GPS_DATA', 'TEXTUAL');
is_deeply( $$hash{'GPSAltitude'}, $$GPS_data{6}, "numeric keys work" );

#########################
$hash = $seg->get_Exif_data('GPS_DATA', 'TEXTUAL');
is_deeply( $$hash{'GPSLongitude'}, $$GPS_data{'GPSLongitude'},
	   "textual keys too" );

#########################
$hash = $seg->set_Exif_data($GPS_data, 'GPS_DATA', 'REPLACE');
is_deeply( $hash, {}, "also REPLACing works" );

#########################
$hash = $seg->get_Exif_data('GPS_DATA', 'TEXTUAL');
is_deeply( $$hash{'GPSVersionID'}, [2, 2, 0, 0], "Automatic VersionID works" );

#########################
$seg->set_Exif_data({'GPSVersionID' => [4, 5, 6, 7]}, 'GPS_DATA', 'ADD');
$hash = $seg->get_Exif_data('GPS_DATA', 'TEXTUAL');
is_deeply( $$hash{'GPSVersionID'}, [4, 5, 6, 7], "Manual VersionID works" );

#########################
$hash = $image->set_Exif_data($GPS_data, 'GPS_DATA', 'ADD');
is_deeply( $hash, {}, "adding through image object" );

#########################
$image->remove_app1_Exif_info(-1);
$hash = $image->set_Exif_data($GPS_data, 'GPS_DATA', 'ADD');
is_deeply( $hash, {}, "adding without the GPS dir" );

#########################
$ref = \ (my $buffer = "");
$image->save($ref);
$image2 = newimage($ref, '^APP1$');
is_deeply( $image2->{segments}, $image->{segments}, "Write and reread works");

#########################
$d1 =  $image->get_description();
$d2 = $image2->get_description();
$d1 =~ s/(.*REFERENCE.*-->).*/$1/g; $d1 =~ s/Original.*//g;
$d2 =~ s/(.*REFERENCE.*-->).*/$1/g; $d2 =~ s/Original.*//g;
is( $d1, $d2, "Descriptions after write/read cycle are coincident" );

#########################
$image = newimage($tphoto, '^APP1$', 'FASTREADONLY');
$hash = $image->set_Exif_data({'GPSLatitudeRef' =>"W\000"}, 'GPS_DATA', 'ADD');
ok( exists $$hash{1}, "Malformed LatitudeRef rejected" );

#########################
$hash = $image->set_Exif_data({'GPSLatitudeRef' => 'N'}, 'GPS_DATA', 'ADD');
is_deeply( $hash, {}, "Non-null-terminated ASCII strings are patched" );

#########################
$lat = [12, 1, 7, 1, 77, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{2}, "Malformed Latitude rejected" );

#########################
$lat = [12, 0, 7, 0, 47, 0];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{2}, "... rejected again ..." );

#########################
$lat = [92, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{2}, "Overflowing Latitude rejected" );

#########################
$lat = [57, 1, 1400, 100, 0, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{2}, "Atypical but valid latitude format accepted" );

#########################
$lat = [21, 3, 14, 7, 35, 11];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{2}, "... very atypical but valid (?) and accepted again" );

#########################
$lat = [89, 1, 5930, 100, 35, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{2}, "... this, really, must be invalid" );

#########################
$lat = [57, 1, -1400, -100, 0, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{2}, "... negative elements are invalid" );

#########################
$lat = [90, 1, 0, 100, 0, 1];
$hash = $image->set_Exif_data({'GPSLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{2}, "You can write North Pole" );

#########################
$lat = [133, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSDestLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( exists $$hash{0x14}, "Overflowing DestLatitude rejected" );

#########################
$lat = [77, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSDestLatitude' => $lat}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{0x14}, "Correct DestLatitude accepted" );

#########################
$long = [182, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSLongitude' => $long}, 'GPS_DATA', 'ADD');
ok( exists $$hash{4}, "Overflowing Longitude rejected" );

#########################
$long = [123, 1, 744, 100, 0, 1];
$hash = $image->set_Exif_data({'GPSLongitude' => $long}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{4}, "Longitude in [0,180] accepted" );

#########################
$long = [211, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSDestLongitude' => $long}, 'GPS_DATA','ADD');
ok( exists $$hash{0x16}, "Overflowing DestLongitude rejected" );

#########################
$long = [177, 1, 7, 1, 47, 1];
$hash = $image->set_Exif_data({'GPSDestLongitude' => $long}, 'GPS_DATA','ADD');
ok( ! exists $$hash{0x16}, "Correct DestLongitude accepted" );

#########################
$track = [3500, 10];
$hash = $image->set_Exif_data({'GPSTrack' => $track}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{15}, "GPS direction accepted" );

#########################
$track = [800, 2];
$hash = $image->set_Exif_data({'GPSTrack' => $track}, 'GPS_DATA', 'ADD');
ok( exists $$hash{15}, "... direction >= 360 is invalid" );

#########################
$track = [-3500, -10];
$hash = $image->set_Exif_data({'GPSTrack' => $track}, 'GPS_DATA', 'ADD');
ok( exists $$hash{15}, "... direction with negative rationals is invalid" );

#########################
$track = [35132, 1000];
$hash = $image->set_Exif_data({'GPSTrack' => $track}, 'GPS_DATA', 'ADD');
ok( exists $$hash{15}, "... direction with > 2 decimal digits is invalid" );

#########################
$track = [3513, 100];
$hash = $image->set_Exif_data({'GPSTrack' => $track}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{15}, "... but 2 decimal digits are OK" );

#########################
$str = "AAN ASCII string";
$hash = $image->set_Exif_data({'GPSAreaInformation'=>$str}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{28}, "GPS non-C strings start with an identifier" );

#########################
$str = "BAN ASCII string";
$hash = $image->set_Exif_data({'GPSAreaInformation'=>$str}, 'GPS_DATA', 'ADD');
ok( exists $$hash{28}, "... invalid identifiers are trapped" );

#########################
$str = "2002:07:13";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{29}, "Accepting dates in YYYY:MM:DD" );

#########################
$str = "1944:11:18";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{29}, "... a good date in the 20th century" );

#########################
$str = "1802:07:13";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{29}, "... a good date in the 19th century" );

#########################
$str = "1799:11:31";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( exists $$hash{29}, "... not accepting a year before 1800" );

#########################
$str = "2002:47:13";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( exists $$hash{29}, "... not accepting a wrong month" );

#########################
$str = "2002:07:53";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( exists $$hash{29}, "... not accepting a wrong day" );

#########################
$str = "2002:07:c3";
$hash = $image->set_Exif_data({'GPSDateStamp' => $str}, 'GPS_DATA', 'ADD');
ok( exists $$hash{29}, "... not accepting non numeric characters" );

#########################
$hash = $image->set_Exif_data({'GPSDifferential' => 1}, 'GPS_DATA', 'ADD');
ok( ! exists $$hash{30}, "byte field accepted" );

#########################
$hash = $image->set_Exif_data({'GPSDifferential' => 2}, 'GPS_DATA', 'ADD');
ok( exists $$hash{30}, "... but not with a wrong value" );

#########################
$hash = $image->set_Exif_data({9999 => 2}, 'GPS_DATA', 'ADD');
ok( exists $$hash{9999}, "unknown numeric tags are rejected" );

#########################
$hash = $image->set_Exif_data({'Pippero' => 2}, 'GPS_DATA', 'ADD');
ok( exists $$hash{'Pippero'}, "unknown textual tags are rejected" );

### Local Variables: ***
### mode:perl ***
### End: ***