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
|
use Test::More tests => 55;
BEGIN { require 't/test_setup.pl'; }
my $tphoto = 't/test_photo.jpg';
my $shop = 'PHOTOSHOP';
my ($image, $seg1, $seg2, $rec, $val, $hash, $num, $segs, $fh, $desc1, $desc2);
#=======================================
diag "Testing APP13 IPTC basic routines";
#=======================================
BEGIN { use_ok ($::tabname, qw(:TagsAPP13)) or exit; }
BEGIN { use_ok ($::pkgname) or exit; } # this must be loaded second!
#########################
{open $fh, $0; is( (grep { /set_app13_data/ } <$fh>), 1, "No setters here" );}
#########################
$image = newimage($tphoto);
is( $image->get_segments('APP13'), 1, "Number of APP13 segments" );
#########################
is( $image->retrieve_app13_segment(-1, $shop), 1, "... of Photoshop APP13" );
#########################
is( $image->retrieve_app13_segment(-1, 'IPTC'), 1, "... of IPTC_2 APP13" );
#########################
is( $image->retrieve_app13_segment(-1, 'IPTC_1'), 0, "... of IPTC_1 APP13" );
#########################
is( $image->retrieve_app13_segment(1, $shop), undef, "Out-of-bound index" );
#########################
is( $image->retrieve_app13_segment(-2, 'IPTC_1'), undef, "Negative index" );
#########################
$seg1 = $image->retrieve_app13_segment(0, $shop);
$rec = $seg1->search_record('Identifier');
$val = $rec->get_value();
$rec->set_value('Paperino');# trick to mask segment
$seg2 = $image->provide_app13_segment($shop);
$rec->set_value($val); # we have two APP13 segs now
is( $image->retrieve_app13_segment(-1, $shop), 2, "2 Photoshop segments now" );
#########################
is( $image->retrieve_app13_segment(-1,'IPTC'), 1, "... but only one is IPTC" );
#########################
is( $image->retrieve_app13_segment(1, $shop), $seg2,
"You can ask for the 2nd Photoshop segment" );
#########################
$seg2->provide_app13_subdir('IPTC_1');
ok( $seg2->is_app13_ok('IPTC_1'), "... and make it IPTC_1 complaiant");
#########################
ok( ! $seg2->is_app13_ok('IPTC'), "... without making it IPTC complaiant");
#########################
ok( ! $seg2->is_app13_ok('IPTC_2'), "... asking for IPTC_2 is the same");
#########################
is( $image->retrieve_app13_segment(1, 'IPTC'), undef,
"You cannot ask for the 2nd IPTC segment" );
#########################
is( $image->provide_app13_segment('IPTC_1'), $seg2,
"Provide segment finds IPTC_1, does not create it" );
#########################
$image->remove_app13_info(0, $shop);
is( $image->retrieve_app13_segment(-1, $shop), 1, "First Photoshop deleted" );
#########################
$seg1 = $image->retrieve_app13_segment(0, $shop);
$seg2 = $image->retrieve_app13_segment(0, 'IPTC');
isnt( $seg1, $seg2, "Now \$index = 0 depends on \$what" );
#########################
$image->remove_app13_info(0, $shop);
$seg1 = $image->retrieve_app13_segment(0, $shop);
is( $seg1, undef, "We can erase Photoshop info from index = 0" );
#########################
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
is( $seg1, $seg2, "... without touching the other segment" );
#########################
$image->remove_app13_info(0, $shop);
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
is( $seg1, $seg2, "... even if we repeat remove_app13_info" );
#########################
$image->remove_app13_info(0, 'IPTC');
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
is( $seg1, undef, "Now also the IPTC segment is gone");
#########################
$image->remove_app13_info(0, 'IPTC_1');
is( $image->retrieve_app13_segment(-1), 0, "No APP13 segments currently" );
#########################
$seg1 = $image->provide_app13_segment($shop);
isnt( $seg1, undef, "provide_app13_segment creates a segment" );
#########################
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
is( $seg1, undef, "... but it does not insert too much information" );
#########################
eval { $image->retrieve_app13_segment(0, "iPtC") };
isnt( $@, '', "A wrong \$what hurts in retrieve_app13_segment" );
#########################
eval { $image->retrieve_app13_segment(0, "IPTC_3") };
isnt( $@, '', "... also a futuristic \$what hurts" );
#########################
eval { $image->provide_app13_segment("Fotoshop") };
isnt( $@, '', "It hurts also in provide_app13_segment" );
#########################
$seg1 = $image->provide_app13_segment('IPTC_2');
$hash = $seg1->get_app13_data(undef, $shop);
is( scalar keys %$hash, 0, "No non-IPTC record created by provide_..." );
#########################
$hash = $seg1->get_app13_data('NUMERIC', 'IPTC');
is( scalar keys %$hash, 1, "But one IPTC/IPTC_2 record is there" );
#########################
ok( exists $$hash{0}, "... and it is the version dataset" );
#########################
$image->provide_app13_segment('IPTC_1');
$hash = $image->get_app13_data('NUMERIC', 'IPTC_1');
is( scalar keys %$hash, 1, "One mandatory dataset inserted for IPTC_1" );
#########################
ok( exists $$hash{0}, "... and it is the version dataset" );
#########################
$image = newimage($tphoto); # reset
$seg1 = $image->retrieve_app13_segment(0, $shop);
$seg2 = $image->provide_app13_segment($shop);
is_deeply( $seg1, $seg2, "Get IPTC segment in two ways [Photoshop]" );
#########################
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
$seg2 = $image->provide_app13_segment('IPTC');
is_deeply( $seg1, $seg2, "Get IPTC segment in two ways [IPTC]" );
#########################
$num = scalar @{$seg1->search_record_value($APP13_PHOTOSHOP_DIRNAME.'_8BIM')};
$hash = $seg1->get_app13_data('NUMERIC', $shop);
is( scalar keys %$hash, $num, "Num elements from numeric get [Photoshop]" );
#########################
is( (grep {/^[0-9]*$/} keys %$hash), $num, "... all tags are numeric" );
#########################
$hash = $seg1->get_app13_data('TEXTUAL', $shop);
is( scalar keys %$hash, $num, "... num elements from textual get" );
#########################
is( (grep {!/^[0-9]*$/} keys %$hash), $num, "... all tags are textual" );
#########################
$num = scalar @{$seg1->search_record_value($APP13_IPTC_DIRNAME.'_2')};
$hash = $seg1->get_app13_data('NUMERIC', 'IPTC');
is( keys %$hash, $num, "Num elements from numeric get [IPTC]" );
#########################
is( exists $$hash{0} ? 1 : undef, 1, "Record Version exists" );
#########################
is( (grep {/^[0-9]*$/} keys %$hash), $num, "... all tags are numeric" );
#########################
$hash = $seg1->get_app13_data('TEXTUAL', 'IPTC');
is( scalar keys %$hash, $num, "... num elements from textual get" );
#########################
is( (grep {!/^[0-9]*$/} keys %$hash), $num, "... all tags are textual" );
#########################
$image->remove_app13_info(-1, 'IPTC');
$num = $image->retrieve_app13_segment(-1, 'IPTC');
is( $num, 0, "Removing IPTC information" );
#########################
$num = $image->get_segments('APP13');
is( $num, 1, "... but not the APP13 segment" );
#########################
$image->remove_app13_info(0, $shop);
$num = $image->retrieve_app13_segment(-1, $shop);
is( $num, 0, "Removing Photoshop info with index" );
#########################
$num = $image->get_segments('APP13');
is( $num, 0, "... this time, a real segment removal" );
#########################
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
is( $seg1, undef, "Retrieve not forcing a segment" );
#########################
$seg1 = $image->provide_app13_segment('IPTC');
isnt( $seg1, undef, "Provide forcing a segment" );
#########################
eval { $hash = $image->get_app13_data('NUMERICAL', 'IPTC') };
isnt( $@, undef, "get_app13_data fails with wrong label" );
#########################
eval { $hash = $image->get_app13_data('ILLEGAL', 'IPTC'); };
isnt( $@, undef, "get_app13_data fails with illegal type" );
#########################
$image = newimage($tphoto);
$seg1 = $image->retrieve_app13_segment(0, 'IPTC');
$desc1 = $seg1->get_description();
$hash = $seg1->get_app13_data('NUMERIC', 'IPTC');
$_ = 17 for values %$hash;
$desc2 = $seg1->get_description();
is( $desc1, $desc2, "get_app13_data [IPTC] returns a copy of actual data" );
#########################
$seg1 = $image->retrieve_app13_segment(0, $shop);
$desc1 = $seg1->get_description();
$hash = $seg1->get_app13_data('NUMERIC', $shop);
$_ = 27 for values %$hash;
$desc2 = $seg1->get_description();
is( $desc1, $desc2, "get_app13_data [PHOTOSHOP] behaves the same way" );
### Local Variables: ***
### mode:perl ***
### End: ***
|