Remove "numpoints" column from wayp, wayp_new and wayp_rej + related code
[gpstools.git] / tests / gpst-pic / gpst-pic.t
blob8d4d753084eb766ebd6b2b7c3d31676f991a2944
1 #!/usr/bin/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 if ($Opt{'todo'} && !$Opt{'all'}) {
70 goto todo_section;
73 =pod
75 testcmd("$CMD command", # {{{
76 <<END,
77 [expected stdin]
78 END
79 "",
80 "description",
83 # }}}
85 =cut
87 diag("Checking dependencies...");
88 likecmd("exifprobe -V", # {{{
89 "/Program: 'exifprobe' version [234]/",
90 '/^$/',
91 "Check that exifprobe(1) is installed",
94 # }}}
95 diag("Testing --author option...");
96 testcmd("$CMD -a sunny files/DSC_4426.JPG", # {{{
97 <<END,
98 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
99 END
101 "Read date from DSC_4426.JPG and set --author",
104 # }}}
105 testcmd("$CMD -a sunny -o xml files/DSC_4426.JPG", # {{{
106 <<END,
107 <?xml version="1.0" encoding="UTF-8"?>
108 <gpstpic>
109 <img>
110 <filename>DSC_4426.JPG</filename>
111 <date>2008-09-18T17:02:27</date>
112 <author>sunny</author>
113 </img>
114 </gpstpic>
117 "Author info is included with -o xml",
120 # }}}
121 # diag("Testing --debug option...");
122 diag("Testing --description option...");
123 testcmd("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
124 <<END,
125 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
128 "Read date from DSC_4426.JPG and set --description with backslash",
131 # }}}
132 testcmd("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml files/DSC_4426.JPG", # {{{
133 <<END,
134 <?xml version="1.0" encoding="UTF-8"?>
135 <gpstpic>
136 <img>
137 <filename>DSC_4426.JPG</filename>
138 <date>2008-09-18T17:02:27</date>
139 <desc>Skumle til\\stander &amp;&lt;&gt; i Bergen.</desc>
140 </img>
141 </gpstpic>
144 "--description works witk XML output",
147 # }}}
148 diag("Testing -h (--help) option...");
149 likecmd("$CMD -h", # {{{
150 '/ Show this help\./',
151 '/^$/',
152 "Option -h prints help screen",
155 # }}}
156 diag("Testing --output-format option..."); # {{{
157 # pgtab
158 testcmd("$CMD -o pgtab files/DSC_4426.JPG", # {{{
159 <<END,
160 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
163 "Output pgtab format from DSC_4426.JPG",
166 # }}}
167 # xml
168 testcmd("$CMD -o xml files/DSC_4426.JPG", # {{{
169 <<END,
170 <?xml version="1.0" encoding="UTF-8"?>
171 <gpstpic>
172 <img>
173 <filename>DSC_4426.JPG</filename>
174 <date>2008-09-18T17:02:27</date>
175 </img>
176 </gpstpic>
179 "Output XML information for DSC_4426.JPG",
182 # }}}
183 # Unknown format
184 testcmd("$CMD -o blurfl files/DSC_4426.JPG", # {{{
186 "gpst-pic: blurfl: Unknown output format\n",
187 "Unknown output format specified",
190 # }}}
191 # }}} --output-format
192 diag("Testing -w (--strip-whitespace) option...");
193 testcmd("$CMD -w -o xml files/DSC_4426.JPG", # {{{
194 <<END,
195 <?xml version="1.0" encoding="UTF-8"?>
196 <gpstpic>
197 <img>
198 <filename>DSC_4426.JPG</filename>
199 <date>2008-09-18T17:02:27</date>
200 </img>
201 </gpstpic>
204 "Strip whitespace from XML",
207 # }}}
208 diag("Testing -T (--timezone) option...");
209 testcmd("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
210 <<END,
211 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
214 "--timezone works",
217 # }}}
218 testcmd("$CMD -T +0200 files/DSC_4426.JPG", # {{{
219 <<END,
220 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
223 "Positive time zone",
226 # }}}
227 testcmd("$CMD -T-0600 files/DSC_4426.JPG", # {{{
228 <<END,
229 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
232 "Negative time zone",
235 # }}}
236 testcmd("$CMD -T CET files/DSC_4426.JPG", # {{{
237 <<END,
238 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
241 "Time zone abbreviation",
244 # }}}
245 testcmd("$CMD -T cet files/DSC_4426.JPG", # {{{
246 <<END,
247 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
250 "Time zone is converted to upper case",
253 # }}}
254 testcmd("$CMD -T Z files/DSC_4426.JPG", # {{{
255 <<END,
256 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
259 "Zulu abbreviation",
262 # }}}
263 testcmd("$CMD -T erf324 files/DSC_4426.JPG", # {{{
265 "gpst-pic: erf324: Invalid time zone\n",
266 "Invalid time zone abbr, contains digits",
269 # }}}
270 testcmd("$CMD -T CET -o xml files/DSC_4426.JPG", # {{{
271 <<END,
272 <?xml version="1.0" encoding="UTF-8"?>
273 <gpstpic>
274 <img>
275 <filename>DSC_4426.JPG</filename>
276 <date>2008-09-18T17:02:27 CET</date>
277 </img>
278 </gpstpic>
281 "Time zone abbr. works with -o xml",
284 # }}}
285 testcmd("$CMD -T Z -o xml files/DSC_4426.JPG", # {{{
286 <<END,
287 <?xml version="1.0" encoding="UTF-8"?>
288 <gpstpic>
289 <img>
290 <filename>DSC_4426.JPG</filename>
291 <date>2008-09-18T17:02:27Z</date>
292 </img>
293 </gpstpic>
296 "Zulu time zone works with -o xml",
299 # }}}
300 diag("Testing -v (--verbose) option...");
301 likecmd("$CMD -hv", # {{{
302 '/^\n\S+ v\d\.\d\d\n/s',
303 '/^$/',
304 "Option --version with -h returns version number and help screen",
307 # }}}
308 diag("Testing --version option...");
309 likecmd("$CMD --version", # {{{
310 '/^\S+ v\d\.\d\d\n/',
311 '/^$/',
312 "Option --version returns version number",
315 # }}}
316 diag("Various...");
317 testcmd("$CMD files/DSC_4426.JPG", # {{{
318 <<END,
319 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
322 "Read date from DSC_4426.JPG, no options",
325 # }}}
327 todo_section:
330 if ($Opt{'all'} || $Opt{'todo'}) {
331 diag("Running TODO tests..."); # {{{
333 TODO: {
335 local $TODO = "";
336 testcmd("$CMD -o extxml files/DSC_4426.JPG", # {{{
337 <<END,
338 <?xml version="1.0" encoding="UTF-8"?>
339 <gpstpic>
340 <img>
341 <filename>DSC_4426.JPG</filename>
342 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
343 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
344 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
345 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
346 <date type="DateTime">2008-09-18T15:02:27Z</date>
347 <exposure>
348 <iso>200</iso>
349 <speed>0.333333</speed>
350 <fnumber>3.5 APEX</fnumber>
351 <flash>0</flash>
352 </exposure>
353 <camera>
354 <make>NIKON CORPRORATION</make>
355 <model>NIKON D300</model>
356 <shuttercount>4610</shuttercount>
357 </camera>
358 </img>
359 </gpstpic>
362 "Show extended XML information for DSC_4426.JPG",
365 # }}}
368 # TODO tests }}}
371 diag("Testing finished.");
373 sub testcmd {
374 # {{{
375 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
376 my $stderr_cmd = "";
377 my $deb_str = $Opt{'debug'} ? " --debug" : "";
378 my $Txt = join("",
379 "\"$Cmd\"",
380 defined($Desc)
381 ? " - $Desc"
382 : ""
384 my $TMP_STDERR = "gpst-pic-stderr.tmp";
386 if (defined($Exp_stderr) && !length($deb_str)) {
387 $stderr_cmd = " 2>$TMP_STDERR";
389 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
390 if (defined($Exp_stderr)) {
391 if (!length($deb_str)) {
392 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
393 unlink($TMP_STDERR);
395 } else {
396 diag("Warning: stderr not defined for '$Txt'");
398 # }}}
399 } # testcmd()
401 sub likecmd {
402 # {{{
403 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
404 my $stderr_cmd = "";
405 my $deb_str = $Opt{'debug'} ? " --debug" : "";
406 my $Txt = join("",
407 "\"$Cmd\"",
408 defined($Desc)
409 ? " - $Desc"
410 : ""
412 my $TMP_STDERR = "gpst-pic-stderr.tmp";
414 if (defined($Exp_stderr) && !length($deb_str)) {
415 $stderr_cmd = " 2>$TMP_STDERR";
417 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
418 if (defined($Exp_stderr)) {
419 if (!length($deb_str)) {
420 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
421 unlink($TMP_STDERR);
423 } else {
424 diag("Warning: stderr not defined for '$Txt'");
426 # }}}
427 } # likecmd()
429 sub file_data {
430 # Return file content as a string {{{
431 my $File = shift;
432 my $Txt;
433 if (open(my $fp, "<", $File)) {
434 $Txt = join("", <$fp>);
435 close($fp);
436 return($Txt);
437 } else {
438 return;
440 # }}}
441 } # file_data()
443 sub print_version {
444 # Print program version {{{
445 print("$progname v$VERSION\n");
446 # }}}
447 } # print_version()
449 sub usage {
450 # Send the help message to stdout {{{
451 my $Retval = shift;
453 if ($Opt{'verbose'}) {
454 print("\n");
455 print_version();
457 print(<<END);
459 Usage: $progname [options] [file [files [...]]]
461 Contains tests for the gpst-pic(1) program.
463 Options:
465 -a, --all
466 Run all tests, also TODOs.
467 -h, --help
468 Show this help.
469 -t, --todo
470 Run only the TODO tests.
471 -v, --verbose
472 Increase level of verbosity. Can be repeated.
473 --version
474 Print version information.
475 --debug
476 Print debugging messages.
479 exit($Retval);
480 # }}}
481 } # usage()
483 sub msg {
484 # Print a status message to stderr based on verbosity level {{{
485 my ($verbose_level, $Txt) = @_;
487 if ($Opt{'verbose'} >= $verbose_level) {
488 print(STDERR "$progname: $Txt\n");
490 # }}}
491 } # msg()
493 __END__
495 # Plain Old Documentation (POD) {{{
497 =pod
499 =head1 NAME
501 run-tests.pl
503 =head1 SYNOPSIS
505 gpst-pic.t [options] [file [files [...]]]
507 =head1 DESCRIPTION
509 Contains tests for the gpst-pic(1) program.
511 =head1 OPTIONS
513 =over 4
515 =item B<-a>, B<--all>
517 Run all tests, also TODOs.
519 =item B<-h>, B<--help>
521 Print a brief help summary.
523 =item B<-t>, B<--todo>
525 Run only the TODO tests.
527 =item B<-v>, B<--verbose>
529 Increase level of verbosity. Can be repeated.
531 =item B<--version>
533 Print version information.
535 =item B<--debug>
537 Print debugging messages.
539 =back
541 =head1 AUTHOR
543 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
545 =head1 COPYRIGHT
547 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
548 This is free software; see the file F<COPYING> for legalese stuff.
550 =head1 LICENCE
552 This program is free software: you can redistribute it and/or modify it
553 under the terms of the GNU General Public License as published by the
554 Free Software Foundation, either version 3 of the License, or (at your
555 option) any later version.
557 This program is distributed in the hope that it will be useful, but
558 WITHOUT ANY WARRANTY; without even the implied warranty of
559 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
560 See the GNU General Public License for more details.
562 You should have received a copy of the GNU General Public License along
563 with this program.
564 If not, see L<http://www.gnu.org/licenses/>.
566 =head1 SEE ALSO
568 gpst(1)
570 =cut
572 # }}}
574 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :