Remove "No Id with only -h" from all tests.
[gpstools.git] / tests / gpst-pic / gpst-pic.t
blob911a8adf67f9e04dd0fb18060b2a0ee05c4328ed
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # tests/gpst-pic/gpst-pic.t
5 # File ID: f210dafc-f924-11dd-9315-0001805bf4b1
6 # Test suite for gpst-pic(1).
8 # Character set: UTF-8
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 #=======================================================================
14 BEGIN {
15 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
16 use Test::More qw{no_plan};
17 use_ok(GPST);
18 use_ok(GPSTxml);
21 use strict;
22 use Getopt::Long;
24 $| = 1;
26 our $Debug = 0;
27 our $CMD = "../../gpst-pic";
29 our %Opt = (
31 'all' => 0,
32 'debug' => 0,
33 'help' => 0,
34 'todo' => 0,
35 'verbose' => 0,
36 'version' => 0,
40 our $progname = $0;
41 $progname =~ s/^.*\/(.*?)$/$1/;
42 our $VERSION = "0.00";
44 Getopt::Long::Configure("bundling");
45 GetOptions(
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'}) {
59 print_version();
60 exit(0);
63 diag(sprintf("========== Executing %s v%s ==========",
64 $progname,
65 $VERSION));
67 if ($Opt{'todo'} && !$Opt{'all'}) {
68 goto todo_section;
71 =pod
73 testcmd("$CMD command", # {{{
74 <<END,
75 [expected stdin]
76 END
77 "",
78 "description",
81 # }}}
83 =cut
85 diag("Checking dependencies...");
86 likecmd("exifprobe -V", # {{{
87 "/Program: 'exifprobe' version [234]/",
88 '/^$/',
89 "Check that exifprobe(1) is installed",
92 # }}}
93 diag("Testing --author option...");
94 testcmd("$CMD -a sunny files/DSC_4426.JPG", # {{{
95 <<END,
96 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
97 END
98 "",
99 "Read date from DSC_4426.JPG and set --author",
102 # }}}
103 testcmd("$CMD -a sunny -o xml files/DSC_4426.JPG", # {{{
104 <<END,
105 <?xml version="1.0" encoding="UTF-8"?>
106 <gpstpic>
107 <img>
108 <filename>DSC_4426.JPG</filename>
109 <date>2008-09-18T17:02:27</date>
110 <author>sunny</author>
111 </img>
112 </gpstpic>
115 "Author info is included with -o xml",
118 # }}}
119 # diag("Testing --debug option...");
120 diag("Testing --description option...");
121 testcmd("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
122 <<END,
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",
129 # }}}
130 testcmd("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml files/DSC_4426.JPG", # {{{
131 <<END,
132 <?xml version="1.0" encoding="UTF-8"?>
133 <gpstpic>
134 <img>
135 <filename>DSC_4426.JPG</filename>
136 <date>2008-09-18T17:02:27</date>
137 <desc>Skumle til\\stander &amp;&lt;&gt; i Bergen.</desc>
138 </img>
139 </gpstpic>
142 "--description works witk XML output",
145 # }}}
146 diag("Testing -h (--help) option...");
147 likecmd("$CMD -h", # {{{
148 '/ Show this help\./',
149 '/^$/',
150 "Option -h prints help screen",
153 # }}}
154 diag("Testing --output-format option..."); # {{{
155 # pgtab
156 testcmd("$CMD -o pgtab files/DSC_4426.JPG", # {{{
157 <<END,
158 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
161 "Output pgtab format from DSC_4426.JPG",
164 # }}}
165 # xml
166 testcmd("$CMD -o xml files/DSC_4426.JPG", # {{{
167 <<END,
168 <?xml version="1.0" encoding="UTF-8"?>
169 <gpstpic>
170 <img>
171 <filename>DSC_4426.JPG</filename>
172 <date>2008-09-18T17:02:27</date>
173 </img>
174 </gpstpic>
177 "Output XML information for DSC_4426.JPG",
180 # }}}
181 # Unknown format
182 testcmd("$CMD -o blurfl files/DSC_4426.JPG", # {{{
184 "gpst-pic: blurfl: Unknown output format\n",
185 "Unknown output format specified",
188 # }}}
189 # }}} --output-format
190 diag("Testing -w (--strip-whitespace) option...");
191 testcmd("$CMD -w -o xml files/DSC_4426.JPG", # {{{
192 <<END,
193 <?xml version="1.0" encoding="UTF-8"?>
194 <gpstpic>
195 <img>
196 <filename>DSC_4426.JPG</filename>
197 <date>2008-09-18T17:02:27</date>
198 </img>
199 </gpstpic>
202 "Strip whitespace from XML",
205 # }}}
206 diag("Testing -T (--timezone) option...");
207 testcmd("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
208 <<END,
209 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
212 "--timezone works",
215 # }}}
216 testcmd("$CMD -T +0200 files/DSC_4426.JPG", # {{{
217 <<END,
218 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
221 "Positive time zone",
224 # }}}
225 testcmd("$CMD -T-0600 files/DSC_4426.JPG", # {{{
226 <<END,
227 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
230 "Negative time zone",
233 # }}}
234 testcmd("$CMD -T CET files/DSC_4426.JPG", # {{{
235 <<END,
236 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
239 "Time zone abbreviation",
242 # }}}
243 testcmd("$CMD -T cet files/DSC_4426.JPG", # {{{
244 <<END,
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",
251 # }}}
252 testcmd("$CMD -T Z files/DSC_4426.JPG", # {{{
253 <<END,
254 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
257 "Zulu abbreviation",
260 # }}}
261 testcmd("$CMD -T erf324 files/DSC_4426.JPG", # {{{
263 "gpst-pic: erf324: Invalid time zone\n",
264 "Invalid time zone abbr, contains digits",
267 # }}}
268 testcmd("$CMD -T CET -o xml files/DSC_4426.JPG", # {{{
269 <<END,
270 <?xml version="1.0" encoding="UTF-8"?>
271 <gpstpic>
272 <img>
273 <filename>DSC_4426.JPG</filename>
274 <date>2008-09-18T17:02:27 CET</date>
275 </img>
276 </gpstpic>
279 "Time zone abbr. works with -o xml",
282 # }}}
283 testcmd("$CMD -T Z -o xml files/DSC_4426.JPG", # {{{
284 <<END,
285 <?xml version="1.0" encoding="UTF-8"?>
286 <gpstpic>
287 <img>
288 <filename>DSC_4426.JPG</filename>
289 <date>2008-09-18T17:02:27Z</date>
290 </img>
291 </gpstpic>
294 "Zulu time zone works with -o xml",
297 # }}}
298 diag("Testing -v (--verbose) option...");
299 likecmd("$CMD -hv", # {{{
300 '/^\n\S+ v\d\.\d\d\n/s',
301 '/^$/',
302 "Option --version with -h returns version number and help screen",
305 # }}}
306 diag("Testing --version option...");
307 likecmd("$CMD --version", # {{{
308 '/^\S+ v\d\.\d\d\n/',
309 '/^$/',
310 "Option --version returns version number",
313 # }}}
314 diag("Various...");
315 testcmd("$CMD files/DSC_4426.JPG", # {{{
316 <<END,
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",
323 # }}}
325 todo_section:
328 if ($Opt{'all'} || $Opt{'todo'}) {
329 diag("Running TODO tests..."); # {{{
331 TODO: {
333 local $TODO = "";
334 testcmd("$CMD -o extxml files/DSC_4426.JPG", # {{{
335 <<END,
336 <?xml version="1.0" encoding="UTF-8"?>
337 <gpstpic>
338 <img>
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>
345 <exposure>
346 <iso>200</iso>
347 <speed>0.333333</speed>
348 <fnumber>3.5 APEX</fnumber>
349 <flash>0</flash>
350 </exposure>
351 <camera>
352 <make>NIKON CORPRORATION</make>
353 <model>NIKON D300</model>
354 <shuttercount>4610</shuttercount>
355 </camera>
356 </img>
357 </gpstpic>
360 "Show extended XML information for DSC_4426.JPG",
363 # }}}
366 # TODO tests }}}
369 diag("Testing finished.");
371 sub testcmd {
372 # {{{
373 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
374 my $stderr_cmd = "";
375 my $deb_str = $Opt{'debug'} ? " --debug" : "";
376 my $Txt = join("",
377 "\"$Cmd\"",
378 defined($Desc)
379 ? " - $Desc"
380 : ""
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)");
391 unlink($TMP_STDERR);
393 } else {
394 diag("Warning: stderr not defined for '$Txt'");
396 # }}}
397 } # testcmd()
399 sub likecmd {
400 # {{{
401 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
402 my $stderr_cmd = "";
403 my $deb_str = $Opt{'debug'} ? " --debug" : "";
404 my $Txt = join("",
405 "\"$Cmd\"",
406 defined($Desc)
407 ? " - $Desc"
408 : ""
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)");
419 unlink($TMP_STDERR);
421 } else {
422 diag("Warning: stderr not defined for '$Txt'");
424 # }}}
425 } # likecmd()
427 sub file_data {
428 # Return file content as a string {{{
429 my $File = shift;
430 my $Txt;
431 if (open(FP, "<", $File)) {
432 $Txt = join("", <FP>);
433 close(FP);
434 return($Txt);
435 } else {
436 return undef;
438 # }}}
439 } # file_data()
441 sub print_version {
442 # Print program version {{{
443 print("$progname v$VERSION\n");
444 # }}}
445 } # print_version()
447 sub usage {
448 # Send the help message to stdout {{{
449 my $Retval = shift;
451 if ($Opt{'verbose'}) {
452 print("\n");
453 print_version();
455 print(<<END);
457 Usage: $progname [options] [file [files [...]]]
459 Contains tests for the gpst-pic(1) program.
461 Options:
463 -a, --all
464 Run all tests, also TODOs.
465 -h, --help
466 Show this help.
467 -t, --todo
468 Run only the TODO tests.
469 -v, --verbose
470 Increase level of verbosity. Can be repeated.
471 --version
472 Print version information.
473 --debug
474 Print debugging messages.
477 exit($Retval);
478 # }}}
479 } # usage()
481 sub msg {
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");
488 # }}}
489 } # msg()
491 __END__
493 # Plain Old Documentation (POD) {{{
495 =pod
497 =head1 NAME
499 run-tests.pl
501 =head1 SYNOPSIS
503 gpst-pic.t [options] [file [files [...]]]
505 =head1 DESCRIPTION
507 Contains tests for the gpst-pic(1) program.
509 =head1 OPTIONS
511 =over 4
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.
529 =item B<--version>
531 Print version information.
533 =item B<--debug>
535 Print debugging messages.
537 =back
539 =head1 AUTHOR
541 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
543 =head1 COPYRIGHT
545 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
546 This is free software; see the file F<COPYING> for legalese stuff.
548 =head1 LICENCE
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
561 with this program.
562 If not, see L<http://www.gnu.org/licenses/>.
564 =head1 SEE ALSO
566 gpst(1)
568 =cut
570 # }}}
572 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :