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 #=======================================================================
18 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
19 use Test
::More
qw{no_plan
};
29 our $CMD = "../gpst-pic";
43 $progname =~ s/^.*\/(.*?)$/$1/;
44 our $VERSION = "0.00";
46 Getopt
::Long
::Configure
("bundling");
49 "all|a" => \
$Opt{'all'},
50 "debug" => \
$Opt{'debug'},
51 "help|h" => \
$Opt{'help'},
52 "todo|t" => \
$Opt{'todo'},
53 "verbose|v+" => \
$Opt{'verbose'},
54 "version" => \
$Opt{'version'},
56 ) || die("$progname: Option error. Use -h for help.\n");
58 $Opt{'debug'} && ($Debug = 1);
59 $Opt{'help'} && usage
(0);
60 if ($Opt{'version'}) {
65 diag
(sprintf("========== Executing %s v%s ==========",
69 my $top = 'gpst-pic-files';
71 if ($Opt{'todo'} && !$Opt{'all'}) {
77 testcmd("$CMD command", # {{{
89 diag
("Checking dependencies...");
90 likecmd
("exifprobe -V", # {{{
91 "/Program: 'exifprobe' version [234]/",
93 "Check that exifprobe(1) is installed",
97 diag
("Testing --author option...");
98 testcmd
("$CMD -a sunny $top/DSC_4426.JPG", # {{{
100 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
103 "Read date from DSC_4426.JPG and set --author",
107 testcmd
("$CMD -a sunny -o xml $top/DSC_4426.JPG", # {{{
109 <?xml version="1.0" encoding="UTF-8"?>
112 <filename>DSC_4426.JPG</filename>
113 <date>2008-09-18T17:02:27</date>
114 <author>sunny</author>
119 "Author info is included with -o xml",
123 # diag("Testing --debug option...");
124 diag
("Testing --description option...");
125 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' $top/DSC_4426.JPG", # {{{
127 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
130 "Read date from DSC_4426.JPG and set --description with backslash",
134 testcmd
("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml $top/DSC_4426.JPG", # {{{
136 <?xml version="1.0" encoding="UTF-8"?>
139 <filename>DSC_4426.JPG</filename>
140 <date>2008-09-18T17:02:27</date>
141 <desc>Skumle til\\stander &<> i Bergen.</desc>
146 "--description works witk XML output",
150 diag
("Testing -h (--help) option...");
151 likecmd
("$CMD -h", # {{{
152 '/ Show this help\./',
154 "Option -h prints help screen",
158 diag
("Testing --output-format option..."); # {{{
160 testcmd
("$CMD -o pgtab $top/DSC_4426.JPG", # {{{
162 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
165 "Output pgtab format from DSC_4426.JPG",
170 testcmd
("$CMD -o xml $top/DSC_4426.JPG", # {{{
172 <?xml version="1.0" encoding="UTF-8"?>
175 <filename>DSC_4426.JPG</filename>
176 <date>2008-09-18T17:02:27</date>
181 "Output XML information for DSC_4426.JPG",
186 testcmd
("$CMD -o blurfl $top/DSC_4426.JPG", # {{{
188 "gpst-pic: blurfl: Unknown output format\n",
189 "Unknown output format specified",
193 # }}} --output-format
194 diag
("Testing -w (--strip-whitespace) option...");
195 testcmd
("$CMD -w -o xml $top/DSC_4426.JPG", # {{{
197 <?xml version="1.0" encoding="UTF-8"?>
200 <filename>DSC_4426.JPG</filename>
201 <date>2008-09-18T17:02:27</date>
206 "Strip whitespace from XML",
210 diag
("Testing -T (--timezone) option...");
211 testcmd
("$CMD --timezone +1234 $top/DSC_4426.JPG", # {{{
213 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
220 testcmd
("$CMD -T +0200 $top/DSC_4426.JPG", # {{{
222 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
225 "Positive time zone",
229 testcmd
("$CMD -T-0600 $top/DSC_4426.JPG", # {{{
231 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
234 "Negative time zone",
238 testcmd
("$CMD -T CET $top/DSC_4426.JPG", # {{{
240 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
243 "Time zone abbreviation",
247 testcmd
("$CMD -T cet $top/DSC_4426.JPG", # {{{
249 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
252 "Time zone is converted to upper case",
256 testcmd
("$CMD -T Z $top/DSC_4426.JPG", # {{{
258 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
265 testcmd
("$CMD -T erf324 $top/DSC_4426.JPG", # {{{
267 "gpst-pic: erf324: Invalid time zone\n",
268 "Invalid time zone abbr, contains digits",
272 testcmd
("$CMD -T CET -o xml $top/DSC_4426.JPG", # {{{
274 <?xml version="1.0" encoding="UTF-8"?>
277 <filename>DSC_4426.JPG</filename>
278 <date>2008-09-18T17:02:27 CET</date>
283 "Time zone abbr. works with -o xml",
287 testcmd
("$CMD -T Z -o xml $top/DSC_4426.JPG", # {{{
289 <?xml version="1.0" encoding="UTF-8"?>
292 <filename>DSC_4426.JPG</filename>
293 <date>2008-09-18T17:02:27Z</date>
298 "Zulu time zone works with -o xml",
302 diag
("Testing -v (--verbose) option...");
303 likecmd
("$CMD -hv", # {{{
304 '/^\n\S+ v\d\.\d\d\n/s',
306 "Option --version with -h returns version number and help screen",
310 diag
("Testing --version option...");
311 likecmd
("$CMD --version", # {{{
312 '/^\S+ v\d\.\d\d\n/',
314 "Option --version returns version number",
319 testcmd
("$CMD $top/DSC_4426.JPG", # {{{
321 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
324 "Read date from DSC_4426.JPG, no options",
332 if ($Opt{'all'} || $Opt{'todo'}) {
333 diag
("Running TODO tests..."); # {{{
338 testcmd
("$CMD -o extxml $top/DSC_4426.JPG", # {{{
340 <?xml version="1.0" encoding="UTF-8"?>
343 <filename>DSC_4426.JPG</filename>
344 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
345 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
346 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
347 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
348 <date type="DateTime">2008-09-18T15:02:27Z</date>
351 <speed>0.333333</speed>
352 <fnumber>3.5 APEX</fnumber>
356 <make>NIKON CORPRORATION</make>
357 <model>NIKON D300</model>
358 <shuttercount>4610</shuttercount>
364 "Show extended XML information for DSC_4426.JPG",
373 diag
("Testing finished.");
377 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
379 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
386 my $TMP_STDERR = "gpst-pic-stderr.tmp";
388 if (defined($Exp_stderr) && !length($deb_str)) {
389 $stderr_cmd = " 2>$TMP_STDERR";
391 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
392 if (defined($Exp_stderr)) {
393 if (!length($deb_str)) {
394 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
398 diag
("Warning: stderr not defined for '$Txt'");
405 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
407 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
414 my $TMP_STDERR = "gpst-pic-stderr.tmp";
416 if (defined($Exp_stderr) && !length($deb_str)) {
417 $stderr_cmd = " 2>$TMP_STDERR";
419 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
420 if (defined($Exp_stderr)) {
421 if (!length($deb_str)) {
422 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
426 diag
("Warning: stderr not defined for '$Txt'");
432 # Return file content as a string {{{
435 if (open(my $fp, "<", $File)) {
436 $Txt = join("", <$fp>);
446 # Print program version {{{
447 print("$progname v$VERSION\n");
452 # Send the help message to stdout {{{
455 if ($Opt{'verbose'}) {
461 Usage: $progname [options] [file [files [...]]]
463 Contains tests for the gpst-pic(1) program.
468 Run all tests, also TODOs.
472 Run only the TODO tests.
474 Increase level of verbosity. Can be repeated.
476 Print version information.
478 Print debugging messages.
486 # Print a status message to stderr based on verbosity level {{{
487 my ($verbose_level, $Txt) = @_;
489 if ($Opt{'verbose'} >= $verbose_level) {
490 print(STDERR
"$progname: $Txt\n");
497 # Plain Old Documentation (POD) {{{
507 gpst-pic.t [options] [file [files [...]]]
511 Contains tests for the gpst-pic(1) program.
517 =item B<-a>, B<--all>
519 Run all tests, also TODOs.
521 =item B<-h>, B<--help>
523 Print a brief help summary.
525 =item B<-t>, B<--todo>
527 Run only the TODO tests.
529 =item B<-v>, B<--verbose>
531 Increase level of verbosity. Can be repeated.
535 Print version information.
539 Print debugging messages.
545 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
549 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
550 This is free software; see the file F<COPYING> for legalese stuff.
554 This program is free software: you can redistribute it and/or modify it
555 under the terms of the GNU General Public License as published by the
556 Free Software Foundation, either version 3 of the License, or (at your
557 option) any later version.
559 This program is distributed in the hope that it will be useful, but
560 WITHOUT ANY WARRANTY; without even the implied warranty of
561 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
562 See the GNU General Public License for more details.
564 You should have received a copy of the GNU General Public License along
566 If not, see L<http://www.gnu.org/licenses/>.
576 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :