gpst-pic.t: Also update path to datadir in TODO after the move
[gpstools.git] / tests / gpst-pic.t
blobcabec830f0dc52bfea8db182ab854bf9820c77d0
1 #!/usr/bin/env perl
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 use strict;
15 use warnings;
17 BEGIN {
18 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
19 use Test::More qw{no_plan};
20 use_ok('GPST');
21 use_ok('GPSTxml');
24 use Getopt::Long;
26 $| = 1;
28 our $Debug = 0;
29 our $CMD = "../gpst-pic";
31 our %Opt = (
33 'all' => 0,
34 'debug' => 0,
35 'help' => 0,
36 'todo' => 0,
37 'verbose' => 0,
38 'version' => 0,
42 our $progname = $0;
43 $progname =~ s/^.*\/(.*?)$/$1/;
44 our $VERSION = "0.00";
46 Getopt::Long::Configure("bundling");
47 GetOptions(
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'}) {
61 print_version();
62 exit(0);
65 diag(sprintf("========== Executing %s v%s ==========",
66 $progname,
67 $VERSION));
69 my $top = 'gpst-pic-files';
71 if ($Opt{'todo'} && !$Opt{'all'}) {
72 goto todo_section;
75 =pod
77 testcmd("$CMD command", # {{{
78 <<END,
79 [expected stdin]
80 END
81 "",
82 "description",
85 # }}}
87 =cut
89 diag("Checking dependencies...");
90 likecmd("exifprobe -V", # {{{
91 "/Program: 'exifprobe' version [234]/",
92 '/^$/',
93 "Check that exifprobe(1) is installed",
96 # }}}
97 diag("Testing --author option...");
98 testcmd("$CMD -a sunny $top/DSC_4426.JPG", # {{{
99 <<END,
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",
106 # }}}
107 testcmd("$CMD -a sunny -o xml $top/DSC_4426.JPG", # {{{
108 <<END,
109 <?xml version="1.0" encoding="UTF-8"?>
110 <gpstpic>
111 <img>
112 <filename>DSC_4426.JPG</filename>
113 <date>2008-09-18T17:02:27</date>
114 <author>sunny</author>
115 </img>
116 </gpstpic>
119 "Author info is included with -o xml",
122 # }}}
123 # diag("Testing --debug option...");
124 diag("Testing --description option...");
125 testcmd("$CMD -d 'Skumle til\\stander i Bergen.' $top/DSC_4426.JPG", # {{{
126 <<END,
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",
133 # }}}
134 testcmd("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml $top/DSC_4426.JPG", # {{{
135 <<END,
136 <?xml version="1.0" encoding="UTF-8"?>
137 <gpstpic>
138 <img>
139 <filename>DSC_4426.JPG</filename>
140 <date>2008-09-18T17:02:27</date>
141 <desc>Skumle til\\stander &amp;&lt;&gt; i Bergen.</desc>
142 </img>
143 </gpstpic>
146 "--description works witk XML output",
149 # }}}
150 diag("Testing -h (--help) option...");
151 likecmd("$CMD -h", # {{{
152 '/ Show this help\./',
153 '/^$/',
154 "Option -h prints help screen",
157 # }}}
158 diag("Testing --output-format option..."); # {{{
159 # pgtab
160 testcmd("$CMD -o pgtab $top/DSC_4426.JPG", # {{{
161 <<END,
162 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
165 "Output pgtab format from DSC_4426.JPG",
168 # }}}
169 # xml
170 testcmd("$CMD -o xml $top/DSC_4426.JPG", # {{{
171 <<END,
172 <?xml version="1.0" encoding="UTF-8"?>
173 <gpstpic>
174 <img>
175 <filename>DSC_4426.JPG</filename>
176 <date>2008-09-18T17:02:27</date>
177 </img>
178 </gpstpic>
181 "Output XML information for DSC_4426.JPG",
184 # }}}
185 # Unknown format
186 testcmd("$CMD -o blurfl $top/DSC_4426.JPG", # {{{
188 "gpst-pic: blurfl: Unknown output format\n",
189 "Unknown output format specified",
192 # }}}
193 # }}} --output-format
194 diag("Testing -w (--strip-whitespace) option...");
195 testcmd("$CMD -w -o xml $top/DSC_4426.JPG", # {{{
196 <<END,
197 <?xml version="1.0" encoding="UTF-8"?>
198 <gpstpic>
199 <img>
200 <filename>DSC_4426.JPG</filename>
201 <date>2008-09-18T17:02:27</date>
202 </img>
203 </gpstpic>
206 "Strip whitespace from XML",
209 # }}}
210 diag("Testing -T (--timezone) option...");
211 testcmd("$CMD --timezone +1234 $top/DSC_4426.JPG", # {{{
212 <<END,
213 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
216 "--timezone works",
219 # }}}
220 testcmd("$CMD -T +0200 $top/DSC_4426.JPG", # {{{
221 <<END,
222 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
225 "Positive time zone",
228 # }}}
229 testcmd("$CMD -T-0600 $top/DSC_4426.JPG", # {{{
230 <<END,
231 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
234 "Negative time zone",
237 # }}}
238 testcmd("$CMD -T CET $top/DSC_4426.JPG", # {{{
239 <<END,
240 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
243 "Time zone abbreviation",
246 # }}}
247 testcmd("$CMD -T cet $top/DSC_4426.JPG", # {{{
248 <<END,
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",
255 # }}}
256 testcmd("$CMD -T Z $top/DSC_4426.JPG", # {{{
257 <<END,
258 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
261 "Zulu abbreviation",
264 # }}}
265 testcmd("$CMD -T erf324 $top/DSC_4426.JPG", # {{{
267 "gpst-pic: erf324: Invalid time zone\n",
268 "Invalid time zone abbr, contains digits",
271 # }}}
272 testcmd("$CMD -T CET -o xml $top/DSC_4426.JPG", # {{{
273 <<END,
274 <?xml version="1.0" encoding="UTF-8"?>
275 <gpstpic>
276 <img>
277 <filename>DSC_4426.JPG</filename>
278 <date>2008-09-18T17:02:27 CET</date>
279 </img>
280 </gpstpic>
283 "Time zone abbr. works with -o xml",
286 # }}}
287 testcmd("$CMD -T Z -o xml $top/DSC_4426.JPG", # {{{
288 <<END,
289 <?xml version="1.0" encoding="UTF-8"?>
290 <gpstpic>
291 <img>
292 <filename>DSC_4426.JPG</filename>
293 <date>2008-09-18T17:02:27Z</date>
294 </img>
295 </gpstpic>
298 "Zulu time zone works with -o xml",
301 # }}}
302 diag("Testing -v (--verbose) option...");
303 likecmd("$CMD -hv", # {{{
304 '/^\n\S+ v\d\.\d\d\n/s',
305 '/^$/',
306 "Option --version with -h returns version number and help screen",
309 # }}}
310 diag("Testing --version option...");
311 likecmd("$CMD --version", # {{{
312 '/^\S+ v\d\.\d\d\n/',
313 '/^$/',
314 "Option --version returns version number",
317 # }}}
318 diag("Various...");
319 testcmd("$CMD $top/DSC_4426.JPG", # {{{
320 <<END,
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",
327 # }}}
329 todo_section:
332 if ($Opt{'all'} || $Opt{'todo'}) {
333 diag("Running TODO tests..."); # {{{
335 TODO: {
337 local $TODO = "";
338 testcmd("$CMD -o extxml $top/DSC_4426.JPG", # {{{
339 <<END,
340 <?xml version="1.0" encoding="UTF-8"?>
341 <gpstpic>
342 <img>
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>
349 <exposure>
350 <iso>200</iso>
351 <speed>0.333333</speed>
352 <fnumber>3.5 APEX</fnumber>
353 <flash>0</flash>
354 </exposure>
355 <camera>
356 <make>NIKON CORPRORATION</make>
357 <model>NIKON D300</model>
358 <shuttercount>4610</shuttercount>
359 </camera>
360 </img>
361 </gpstpic>
364 "Show extended XML information for DSC_4426.JPG",
367 # }}}
370 # TODO tests }}}
373 diag("Testing finished.");
375 sub testcmd {
376 # {{{
377 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
378 my $stderr_cmd = "";
379 my $deb_str = $Opt{'debug'} ? " --debug" : "";
380 my $Txt = join("",
381 "\"$Cmd\"",
382 defined($Desc)
383 ? " - $Desc"
384 : ""
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)");
395 unlink($TMP_STDERR);
397 } else {
398 diag("Warning: stderr not defined for '$Txt'");
400 # }}}
401 } # testcmd()
403 sub likecmd {
404 # {{{
405 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
406 my $stderr_cmd = "";
407 my $deb_str = $Opt{'debug'} ? " --debug" : "";
408 my $Txt = join("",
409 "\"$Cmd\"",
410 defined($Desc)
411 ? " - $Desc"
412 : ""
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)");
423 unlink($TMP_STDERR);
425 } else {
426 diag("Warning: stderr not defined for '$Txt'");
428 # }}}
429 } # likecmd()
431 sub file_data {
432 # Return file content as a string {{{
433 my $File = shift;
434 my $Txt;
435 if (open(my $fp, "<", $File)) {
436 $Txt = join("", <$fp>);
437 close($fp);
438 return($Txt);
439 } else {
440 return;
442 # }}}
443 } # file_data()
445 sub print_version {
446 # Print program version {{{
447 print("$progname v$VERSION\n");
448 # }}}
449 } # print_version()
451 sub usage {
452 # Send the help message to stdout {{{
453 my $Retval = shift;
455 if ($Opt{'verbose'}) {
456 print("\n");
457 print_version();
459 print(<<END);
461 Usage: $progname [options] [file [files [...]]]
463 Contains tests for the gpst-pic(1) program.
465 Options:
467 -a, --all
468 Run all tests, also TODOs.
469 -h, --help
470 Show this help.
471 -t, --todo
472 Run only the TODO tests.
473 -v, --verbose
474 Increase level of verbosity. Can be repeated.
475 --version
476 Print version information.
477 --debug
478 Print debugging messages.
481 exit($Retval);
482 # }}}
483 } # usage()
485 sub msg {
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");
492 # }}}
493 } # msg()
495 __END__
497 # Plain Old Documentation (POD) {{{
499 =pod
501 =head1 NAME
503 run-tests.pl
505 =head1 SYNOPSIS
507 gpst-pic.t [options] [file [files [...]]]
509 =head1 DESCRIPTION
511 Contains tests for the gpst-pic(1) program.
513 =head1 OPTIONS
515 =over 4
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.
533 =item B<--version>
535 Print version information.
537 =item B<--debug>
539 Print debugging messages.
541 =back
543 =head1 AUTHOR
545 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
547 =head1 COPYRIGHT
549 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
550 This is free software; see the file F<COPYING> for legalese stuff.
552 =head1 LICENCE
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
565 with this program.
566 If not, see L<http://www.gnu.org/licenses/>.
568 =head1 SEE ALSO
570 gpst(1)
572 =cut
574 # }}}
576 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :