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
|
use Test::More tests => 34;
BEGIN { require 't/test_setup.pl'; }
my $tphoto = 't/test_photo.jpg';
my ($image, $hash, $bighash, $date);
#=======================================
diag "Testing APP13 IPTC format checker";
#=======================================
BEGIN { use_ok ($::pkgname) or exit; }
#########################
$image = newimage($tphoto);
$hash = $image->set_app13_data({ 80 => "ciao" }); # ByLine
is( scalar keys %$hash, 0, "regular tag" );
#########################
$hash = $image->set_app13_data({ 1 => "ciao" });
is( scalar keys %$hash, 1, "unknown numeric tag" );
#########################
$hash = $image->set_app13_data({ -3 => "ciao" });
is( scalar keys %$hash, 1, "negative tag" );
#########################
$hash = $image->set_app13_data({ 313 => "ciao" });
is( scalar keys %$hash, 1, "tag larger than 255" );
#########################
$hash = $image->set_app13_data({ "XYZ" => "ciao" });
is( scalar keys %$hash, 1, "unkwnon textual tag" );
#########################
$hash = $image->set_app13_data({ 80 => [] });
is( scalar keys %$hash, 1, "value array with zero elements" );
#########################
$hash = $image->set_app13_data({ 90 => ["Milano", "Roma"] }); # City
is( scalar keys %$hash, 1, "non repeateable tag (1)" );
#########################
$hash = $image->set_app13_data({ 90 => "Roma" });
is( scalar keys %$hash, 0, "non repeateable tag (2)" );
#########################
$hash = $image->set_app13_data({ 45 => "ciao" }); # RefereceService
is( scalar keys %$hash, 1, "invalid tag" );
#########################
$hash = $image->set_app13_data({ 125 => "\001\377\013" }); # RasterizedCaption
is( scalar keys %$hash, 1, "binary tag not passing because of length" );
#########################
$hash = $image->set_app13_data({ 125 => "z" x 7360 });
is( scalar keys %$hash, 0, "binary tag now passing" );
#########################
$hash = $image->set_app13_data({ 135 => 'I' }); # LanguageIdentifier
is( scalar keys %$hash, 1, "length too small" );
#########################
$hash = $image->set_app13_data({ 135 => "IT" });
is( scalar keys %$hash, 0, "length OK (1)" );
#########################
$hash = $image->set_app13_data({ 135 => "ITA" });
is( scalar keys %$hash, 0, "length OK (2)" );
#########################
$hash = $image->set_app13_data({ 135 => "ITAL" });
is( scalar keys %$hash, 1, "length too large" );
#########################
$hash = $image->set_app13_data({ 3 => "ciao:ate" }); # ObjectTypeReference
is( scalar keys %$hash, 1, "invalid regex (1)" );
#########################
$hash = $image->set_app13_data({ 3 => "riga\nacapo" }); # ObjectName
is( scalar keys %$hash, 1, "invalid regex (2)" );
#########################
$hash = $image->set_app13_data({ 10 => 9 }); # Urgency
is( scalar keys %$hash, 1, "invalid regex (3)" );
#########################
$hash = $image->set_app13_data({ 120 => "uno\fdue" }); # Caption/Abstract
is( scalar keys %$hash, 1, "form feed not allowed in 'paragraph'" );
#########################
$date = "19920223";
$hash = $image->set_app13_data({'ReleaseDate' => $date,
'ExpirationDate' => $date,
'DigitalCreationDate' => $date,
'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "Dates in the 20th century accepted" );
#########################
$date = "18620223";
$hash = $image->set_app13_data({'ReleaseDate' => $date,
'ExpirationDate' => $date,
'DigitalCreationDate' => $date,
'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "Dates in the 19th century accepted" );
#########################
$date = "17500223";
$hash = $image->set_app13_data({'ExpirationDate' => $date,
'DigitalCreationDate' => $date,
'ReleaseDate' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 3, "Dates in the 18th century not accepted" );
#########################
$hash = $image->set_app13_data({'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "... except in DateCreated" );
#########################
$date = "07500223";
$hash = $image->set_app13_data({'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "DateCreated accepts also the 1st millennium" );
#########################
$date = "00750223";
$hash = $image->set_app13_data({'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "... and the 1st century" );
#########################
$date = "00000101";
$hash = $image->set_app13_data({'DateCreated' => $date}, 'ADD', 'IPTC');
is( scalar keys %$hash, 0, "... and the very early days" );
#########################
$bighash = {
'RecordVersion' => "\000\002",
'ObjectTypeReference' => "23:ciao a te",
'ObjectAttributeReference' => "234:ciao a te",
'ObjectName' => "nome",
'EditorialUpdate' => "01",
'Urgency' => 3,
'SubjectReference' => "IPTC:12345678:alpha:beta:gamma",
'Category' => "ao",
'SupplementalCategory' => [ "alci", "daini", "capri oli" ],
'FixtureIdentifier' => "paperino",
'ContentLocationCode' => "ABC",
'ReleaseDate' => "19341230",
'ReleaseTime' => "130612+0100",
'ActionAdvised' => "03",
'ObjectCycle' => 'p',
'Country/PrimaryLocationCode' => "ITA",
'Caption/Abstract' => "line 1\nline 2\n\rline 3",
'RasterizedCaption' => "\013" x 7360,
'ImageType' => "9R",
'ImageOrientation' => 'L',
'LanguageIdentifier' => "it",
'AudioType' => "1M",
'AudioSamplingRate' => 928346,
'AudioSamplingResolution' => 20,
'AudioDuration' => 121325 };
$hash = $image->set_app13_data($bighash);
is( scalar keys %$hash, 0, "a group of valid tags" );
#########################
$image->provide_app13_segment('IPTC_1');
$hash = $image->set_app13_data({5 => "Paperopoli"}, 'ADD', 'IPTC_1');
is( scalar keys %$hash, 0, "regular tag (IPTC_1)" ); # Destination
#########################
$hash = $image->set_app13_data({30 => ["Fax", "Tel"]}, 'ADD', 'IPTC_1');
is( scalar keys %$hash, 1, "non repeateable tag (IPTC_1)" ); # ServIdent
#########################
$hash = $image->set_app13_data({60 => 8}, 'ADD', 'IPTC_1');
is( scalar keys %$hash, 1, "invalid tag (IPTC_1)" ); # Envelope priority
#########################
$hash = $image->set_app13_data({3 => "some where"}, 'ADD', 'IPTC_1'); # Dest.
is( scalar keys %$hash, 1, "invalid regex (1, IPTC_1), no spaces allowed" );
#########################
$hash = $image->set_app13_data({90 => "ABC"}, 'ADD', 'IPTC_1');
is( scalar keys %$hash, 1, "invalid regex (2, IPTC_1)" ); # Character set
#########################
$bighash = {'ModelVersion' => "\000\007",
'Destination' => [ 'Reggio_Emilia', 'Roma' ],
'ServiceIdentifier' => 'Telephone',
'ProductID' => [ 'beautiful', 'wonderful' ],
'CodedCharacterSet' => "\033\045G" };
$hash = $image->set_app13_data($bighash, 'ADD', 'IPTC_1');
is( scalar keys %$hash, 0, "a group of valid tags (IPTC_1)" );
### Local Variables: ***
### mode:perl ***
### End: ***
|