3 #=======================================================================
4 # tests/gpst-pic/gpst-pic.t
5 # File ID: f210dafc-f924-11dd-9315-0001805bf4b1
6 # Test suite for gpst-pic(1).
9 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
15 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
16 use Test
::More
qw{no_plan
};
27 our $CMD = "../../gpst-pic";
41 $progname =~ s/^.*\/(.*?)$/$1/;
42 our $VERSION = "0.00";
44 Getopt
::Long
::Configure
("bundling");
47 "all|a" => \
$Opt{'all'},
48 "debug" => \
$Opt{'debug'},
49 "help|h" => \
$Opt{'help'},
50 "todo|t" => \
$Opt{'todo'},
51 "verbose|v+" => \
$Opt{'verbose'},
52 "version" => \
$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage
(0);
58 if ($Opt{'version'}) {
63 diag
(sprintf("========== Executing %s v%s ==========",
67 if ($Opt{'todo'} && !$Opt{'all'}) {
73 testcmd("$CMD command", # {{{
85 diag
("Checking dependencies...");
86 likecmd
("exifprobe -V", # {{{
87 "/Program: 'exifprobe' version [234]/",
89 "Check that exifprobe(1) is installed",
93 diag
("Testing --author option...");
94 testcmd
("$CMD -a sunny files/DSC_4426.JPG", # {{{
96 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
99 "Read date from DSC_4426.JPG and set --author",
103 testcmd
("$CMD -a sunny -o xml files/DSC_4426.JPG", # {{{
105 <?xml version="1.0" encoding="UTF-8"?>
108 <filename>DSC_4426.JPG</filename>
109 <date>2008-09-18T17:02:27</date>
110 <author>sunny</author>
115 "Author info is included with -o xml",
119 # diag("Testing --debug option...");
120 diag
("Testing --description option...");
121 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
123 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
126 "Read date from DSC_4426.JPG and set --description with backslash",
130 testcmd
("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml files/DSC_4426.JPG", # {{{
132 <?xml version="1.0" encoding="UTF-8"?>
135 <filename>DSC_4426.JPG</filename>
136 <date>2008-09-18T17:02:27</date>
137 <desc>Skumle til\\stander &<> i Bergen.</desc>
142 "--description works witk XML output",
146 diag
("Testing -h (--help) option...");
147 likecmd
("$CMD -h", # {{{
148 '/ Show this help\./',
150 "Option -h prints help screen",
154 diag
("Testing --output-format option..."); # {{{
156 testcmd
("$CMD -o pgtab files/DSC_4426.JPG", # {{{
158 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
161 "Output pgtab format from DSC_4426.JPG",
166 testcmd
("$CMD -o xml files/DSC_4426.JPG", # {{{
168 <?xml version="1.0" encoding="UTF-8"?>
171 <filename>DSC_4426.JPG</filename>
172 <date>2008-09-18T17:02:27</date>
177 "Output XML information for DSC_4426.JPG",
182 testcmd
("$CMD -o blurfl files/DSC_4426.JPG", # {{{
184 "gpst-pic: blurfl: Unknown output format\n",
185 "Unknown output format specified",
189 # }}} --output-format
190 diag
("Testing -w (--strip-whitespace) option...");
191 testcmd
("$CMD -w -o xml files/DSC_4426.JPG", # {{{
193 <?xml version="1.0" encoding="UTF-8"?>
196 <filename>DSC_4426.JPG</filename>
197 <date>2008-09-18T17:02:27</date>
202 "Strip whitespace from XML",
206 diag
("Testing -T (--timezone) option...");
207 testcmd
("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
209 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
216 testcmd
("$CMD -T +0200 files/DSC_4426.JPG", # {{{
218 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
221 "Positive time zone",
225 testcmd
("$CMD -T-0600 files/DSC_4426.JPG", # {{{
227 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
230 "Negative time zone",
234 testcmd
("$CMD -T CET files/DSC_4426.JPG", # {{{
236 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
239 "Time zone abbreviation",
243 testcmd
("$CMD -T cet files/DSC_4426.JPG", # {{{
245 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
248 "Time zone is converted to upper case",
252 testcmd
("$CMD -T Z files/DSC_4426.JPG", # {{{
254 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
261 testcmd
("$CMD -T erf324 files/DSC_4426.JPG", # {{{
263 "gpst-pic: erf324: Invalid time zone\n",
264 "Invalid time zone abbr, contains digits",
268 testcmd
("$CMD -T CET -o xml files/DSC_4426.JPG", # {{{
270 <?xml version="1.0" encoding="UTF-8"?>
273 <filename>DSC_4426.JPG</filename>
274 <date>2008-09-18T17:02:27 CET</date>
279 "Time zone abbr. works with -o xml",
283 testcmd
("$CMD -T Z -o xml files/DSC_4426.JPG", # {{{
285 <?xml version="1.0" encoding="UTF-8"?>
288 <filename>DSC_4426.JPG</filename>
289 <date>2008-09-18T17:02:27Z</date>
294 "Zulu time zone works with -o xml",
298 diag
("Testing -v (--verbose) option...");
299 likecmd
("$CMD -hv", # {{{
300 '/^\n\S+ v\d\.\d\d\n/s',
302 "Option --version with -h returns version number and help screen",
306 diag
("Testing --version option...");
307 likecmd
("$CMD --version", # {{{
308 '/^\S+ v\d\.\d\d\n/',
310 "Option --version returns version number",
315 testcmd
("$CMD files/DSC_4426.JPG", # {{{
317 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
320 "Read date from DSC_4426.JPG, no options",
328 if ($Opt{'all'} || $Opt{'todo'}) {
329 diag
("Running TODO tests..."); # {{{
334 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
336 <?xml version="1.0" encoding="UTF-8"?>
339 <filename>DSC_4426.JPG</filename>
340 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
341 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
342 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
343 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
344 <date type="DateTime">2008-09-18T15:02:27Z</date>
347 <speed>0.333333</speed>
348 <fnumber>3.5 APEX</fnumber>
352 <make>NIKON CORPRORATION</make>
353 <model>NIKON D300</model>
354 <shuttercount>4610</shuttercount>
360 "Show extended XML information for DSC_4426.JPG",
369 diag
("Testing finished.");
373 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
375 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
382 my $TMP_STDERR = "gpst-pic-stderr.tmp";
384 if (defined($Exp_stderr) && !length($deb_str)) {
385 $stderr_cmd = " 2>$TMP_STDERR";
387 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
388 if (defined($Exp_stderr)) {
389 if (!length($deb_str)) {
390 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
394 diag
("Warning: stderr not defined for '$Txt'");
401 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
403 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
410 my $TMP_STDERR = "gpst-pic-stderr.tmp";
412 if (defined($Exp_stderr) && !length($deb_str)) {
413 $stderr_cmd = " 2>$TMP_STDERR";
415 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
416 if (defined($Exp_stderr)) {
417 if (!length($deb_str)) {
418 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
422 diag
("Warning: stderr not defined for '$Txt'");
428 # Return file content as a string {{{
431 if (open(FP
, "<", $File)) {
432 $Txt = join("", <FP
>);
442 # Print program version {{{
443 print("$progname v$VERSION\n");
448 # Send the help message to stdout {{{
451 if ($Opt{'verbose'}) {
457 Usage: $progname [options] [file [files [...]]]
459 Contains tests for the gpst-pic(1) program.
464 Run all tests, also TODOs.
468 Run only the TODO tests.
470 Increase level of verbosity. Can be repeated.
472 Print version information.
474 Print debugging messages.
482 # Print a status message to stderr based on verbosity level {{{
483 my ($verbose_level, $Txt) = @_;
485 if ($Opt{'verbose'} >= $verbose_level) {
486 print(STDERR
"$progname: $Txt\n");
493 # Plain Old Documentation (POD) {{{
503 gpst-pic.t [options] [file [files [...]]]
507 Contains tests for the gpst-pic(1) program.
513 =item B<-a>, B<--all>
515 Run all tests, also TODOs.
517 =item B<-h>, B<--help>
519 Print a brief help summary.
521 =item B<-t>, B<--todo>
523 Run only the TODO tests.
525 =item B<-v>, B<--verbose>
527 Increase level of verbosity. Can be repeated.
531 Print version information.
535 Print debugging messages.
541 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
545 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
546 This is free software; see the file F<COPYING> for legalese stuff.
550 This program is free software: you can redistribute it and/or modify it
551 under the terms of the GNU General Public License as published by the
552 Free Software Foundation, either version 3 of the License, or (at your
553 option) any later version.
555 This program is distributed in the hope that it will be useful, but
556 WITHOUT ANY WARRANTY; without even the implied warranty of
557 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
558 See the GNU General Public License for more details.
560 You should have received a copy of the GNU General Public License along
562 If not, see L<http://www.gnu.org/licenses/>.
572 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :