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 ok
(`$CMD -h` !~ /^\n\S+ v\d\.\d\d\n/s, "\"$CMD -h\" - No Id with only -h");
155 diag
("Testing --output-format option..."); # {{{
157 testcmd
("$CMD -o pgtab files/DSC_4426.JPG", # {{{
159 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
162 "Output pgtab format from DSC_4426.JPG",
167 testcmd
("$CMD -o xml files/DSC_4426.JPG", # {{{
169 <?xml version="1.0" encoding="UTF-8"?>
172 <filename>DSC_4426.JPG</filename>
173 <date>2008-09-18T17:02:27</date>
178 "Output XML information for DSC_4426.JPG",
183 testcmd
("$CMD -o blurfl files/DSC_4426.JPG", # {{{
185 "gpst-pic: blurfl: Unknown output format\n",
186 "Unknown output format specified",
190 # }}} --output-format
191 diag
("Testing -w (--strip-whitespace) option...");
192 testcmd
("$CMD -w -o xml files/DSC_4426.JPG", # {{{
194 <?xml version="1.0" encoding="UTF-8"?>
197 <filename>DSC_4426.JPG</filename>
198 <date>2008-09-18T17:02:27</date>
203 "Strip whitespace from XML",
207 diag
("Testing -T (--timezone) option...");
208 testcmd
("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
210 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
217 testcmd
("$CMD -T +0200 files/DSC_4426.JPG", # {{{
219 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
222 "Positive time zone",
226 testcmd
("$CMD -T-0600 files/DSC_4426.JPG", # {{{
228 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
231 "Negative time zone",
235 testcmd
("$CMD -T CET files/DSC_4426.JPG", # {{{
237 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
240 "Time zone abbreviation",
244 testcmd
("$CMD -T cet files/DSC_4426.JPG", # {{{
246 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
249 "Time zone is converted to upper case",
253 testcmd
("$CMD -T Z files/DSC_4426.JPG", # {{{
255 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
262 testcmd
("$CMD -T erf324 files/DSC_4426.JPG", # {{{
264 "gpst-pic: erf324: Invalid time zone\n",
265 "Invalid time zone abbr, contains digits",
269 testcmd
("$CMD -T CET -o xml files/DSC_4426.JPG", # {{{
271 <?xml version="1.0" encoding="UTF-8"?>
274 <filename>DSC_4426.JPG</filename>
275 <date>2008-09-18T17:02:27 CET</date>
280 "Time zone abbr. works with -o xml",
284 testcmd
("$CMD -T Z -o xml files/DSC_4426.JPG", # {{{
286 <?xml version="1.0" encoding="UTF-8"?>
289 <filename>DSC_4426.JPG</filename>
290 <date>2008-09-18T17:02:27Z</date>
295 "Zulu time zone works with -o xml",
299 diag
("Testing -v (--verbose) option...");
300 likecmd
("$CMD -hv", # {{{
301 '/^\n\S+ v\d\.\d\d\n/s',
303 "Option --version with -h returns version number and help screen",
307 diag
("Testing --version option...");
308 likecmd
("$CMD --version", # {{{
309 '/^\S+ v\d\.\d\d\n/',
311 "Option --version returns version number",
316 testcmd
("$CMD files/DSC_4426.JPG", # {{{
318 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
321 "Read date from DSC_4426.JPG, no options",
329 if ($Opt{'all'} || $Opt{'todo'}) {
330 diag
("Running TODO tests..."); # {{{
335 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
337 <?xml version="1.0" encoding="UTF-8"?>
340 <filename>DSC_4426.JPG</filename>
341 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
342 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
343 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
344 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
345 <date type="DateTime">2008-09-18T15:02:27Z</date>
348 <speed>0.333333</speed>
349 <fnumber>3.5 APEX</fnumber>
353 <make>NIKON CORPRORATION</make>
354 <model>NIKON D300</model>
355 <shuttercount>4610</shuttercount>
361 "Show extended XML information for DSC_4426.JPG",
370 diag
("Testing finished.");
374 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
376 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
383 my $TMP_STDERR = "gpst-pic-stderr.tmp";
385 if (defined($Exp_stderr) && !length($deb_str)) {
386 $stderr_cmd = " 2>$TMP_STDERR";
388 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
389 if (defined($Exp_stderr)) {
390 if (!length($deb_str)) {
391 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
395 diag
("Warning: stderr not defined for '$Txt'");
402 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
404 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
411 my $TMP_STDERR = "gpst-pic-stderr.tmp";
413 if (defined($Exp_stderr) && !length($deb_str)) {
414 $stderr_cmd = " 2>$TMP_STDERR";
416 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
417 if (defined($Exp_stderr)) {
418 if (!length($deb_str)) {
419 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
423 diag
("Warning: stderr not defined for '$Txt'");
429 # Return file content as a string {{{
432 if (open(FP
, "<", $File)) {
433 $Txt = join("", <FP
>);
443 # Print program version {{{
444 print("$progname v$VERSION\n");
449 # Send the help message to stdout {{{
452 if ($Opt{'verbose'}) {
458 Usage: $progname [options] [file [files [...]]]
460 Contains tests for the gpst-pic(1) program.
465 Run all tests, also TODOs.
469 Run only the TODO tests.
471 Increase level of verbosity. Can be repeated.
473 Print version information.
475 Print debugging messages.
483 # Print a status message to stderr based on verbosity level {{{
484 my ($verbose_level, $Txt) = @_;
486 if ($Opt{'verbose'} >= $verbose_level) {
487 print(STDERR
"$progname: $Txt\n");
494 # Plain Old Documentation (POD) {{{
504 gpst-pic.t [options] [file [files [...]]]
508 Contains tests for the gpst-pic(1) program.
514 =item B<-a>, B<--all>
516 Run all tests, also TODOs.
518 =item B<-h>, B<--help>
520 Print a brief help summary.
522 =item B<-t>, B<--todo>
524 Run only the TODO tests.
526 =item B<-v>, B<--verbose>
528 Increase level of verbosity. Can be repeated.
532 Print version information.
536 Print debugging messages.
542 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
546 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
547 This is free software; see the file F<COPYING> for legalese stuff.
551 This program is free software: you can redistribute it and/or modify it
552 under the terms of the GNU General Public License as published by the
553 Free Software Foundation, either version 3 of the License, or (at your
554 option) any later version.
556 This program is distributed in the hope that it will be useful, but
557 WITHOUT ANY WARRANTY; without even the implied warranty of
558 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
559 See the GNU General Public License for more details.
561 You should have received a copy of the GNU General Public License along
563 If not, see L<http://www.gnu.org/licenses/>.
573 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :