gpsfold: Remove $Id$ at EOF.
[gpstools.git] / branches / gpst.gpxfix / tests / gpst-pic / gpst-pic.t
blobc5fb7c4af6a3226ae8fca401b6a274ea9c5c9535
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
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 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 BEGIN {
15 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
16 our @version_array;
17 use Test::More qw{no_plan};
18 use_ok(GPST);
19 use_ok(GPSTxml);
22 use strict;
23 use Getopt::Long;
25 $| = 1;
27 our $Debug = 0;
28 our $CMD = "../../gpst-pic";
30 our %Opt = (
32 'all' => 0,
33 'debug' => 0,
34 'help' => 0,
35 'todo' => 0,
36 'verbose' => 0,
37 'version' => 0,
41 our $progname = $0;
42 $progname =~ s/^.*\/(.*?)$/$1/;
44 my $rcs_id = '$Id$';
45 my $id_date = $rcs_id;
46 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
48 push(@main::version_array, $rcs_id);
50 my @cmdline_array = @ARGV;
52 Getopt::Long::Configure("bundling");
53 GetOptions(
55 "all|a" => \$Opt{'all'},
56 "debug" => \$Opt{'debug'},
57 "help|h" => \$Opt{'help'},
58 "todo|t" => \$Opt{'todo'},
59 "verbose|v+" => \$Opt{'verbose'},
60 "version" => \$Opt{'version'},
62 ) || die("$progname: Option error. Use -h for help.\n");
64 $Opt{'debug'} && ($Debug = 1);
65 $Opt{'help'} && usage(0);
66 if ($Opt{'version'}) {
67 print_version();
68 exit(0);
71 diag(sprintf("========== Executing \"%s%s%s\" ==========",
72 $progname,
73 scalar(@cmdline_array) ? " " : "",
74 join(" ", @cmdline_array)));
76 if ($Opt{'todo'} && !$Opt{'all'}) {
77 goto todo_section;
80 =pod
82 testcmd("$CMD command", # {{{
83 <<END,
84 [expected stdin]
85 END
86 "",
87 "description",
90 # }}}
92 =cut
94 diag("Checking dependencies...");
95 likecmd("exifprobe -V", # {{{
96 "/Program: 'exifprobe' version [234]/",
97 '/^$/',
98 "Check that exifprobe(1) is installed",
101 # }}}
102 diag("Testing --author option...");
103 testcmd("$CMD -a sunny files/DSC_4426.JPG", # {{{
104 <<END,
105 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
108 "Read date from DSC_4426.JPG and set --author",
111 # }}}
112 # diag("Testing --debug option...");
113 diag("Testing --description option...");
114 testcmd("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
115 <<END,
116 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
119 "Read date from DSC_4426.JPG and set --description with backslash",
122 # }}}
123 diag("Testing -h (--help) option...");
124 likecmd("$CMD -h", # {{{
125 '/ Show this help\./',
126 '/^$/',
127 "Option -h prints help screen",
130 # }}}
131 ok(`$CMD -h` !~ /\$Id: /s, "\"$CMD -h\" - No Id with only -h");
132 diag("Testing --output-format option..."); # {{{
133 # pgtab
134 testcmd("$CMD -o pgtab files/DSC_4426.JPG", # {{{
135 <<END,
136 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
139 "Output pgtab format from DSC_4426.JPG",
142 # }}}
143 # xml
144 testcmd("$CMD -o xml files/DSC_4426.JPG", # {{{
145 <<END,
146 <?xml version="1.0" encoding="UTF-8"?>
147 <gpstpic>
148 <img>
149 <filename>DSC_4426.JPG</filename>
150 <date>2008-09-18T17:02:27</date>
151 </img>
152 </gpstpic>
155 "Output XML information for DSC_4426.JPG",
158 # }}}
159 # Unknown format
160 testcmd("$CMD -o blurfl files/DSC_4426.JPG", # {{{
162 "gpst-pic: blurfl: Unknown output format\n",
163 "Unknown output format specified",
166 # }}}
167 # }}} --output-format
168 diag("Testing -w (--strip-whitespace) option...");
169 testcmd("$CMD -w -o xml files/DSC_4426.JPG", # {{{
170 <<END,
171 <?xml version="1.0" encoding="UTF-8"?>
172 <gpstpic>
173 <img>
174 <filename>DSC_4426.JPG</filename>
175 <date>2008-09-18T17:02:27</date>
176 </img>
177 </gpstpic>
180 "Strip whitespace from XML",
183 # }}}
184 diag("Testing -T (--timezone) option...");
185 testcmd("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
186 <<END,
187 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
190 "--timezone works",
193 # }}}
194 testcmd("$CMD -T +0200 files/DSC_4426.JPG", # {{{
195 <<END,
196 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
199 "Positive time zone",
202 # }}}
203 testcmd("$CMD -T-0600 files/DSC_4426.JPG", # {{{
204 <<END,
205 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
208 "Negative time zone",
211 # }}}
212 testcmd("$CMD -T CET files/DSC_4426.JPG", # {{{
213 <<END,
214 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
217 "Time zone abbreviation",
220 # }}}
221 testcmd("$CMD -T Z files/DSC_4426.JPG", # {{{
222 <<END,
223 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
226 "Zulu abbreviation",
229 # }}}
230 testcmd("$CMD -T erf324 files/DSC_4426.JPG", # {{{
232 "gpst-pic: erf324: Invalid time zone\n",
233 "Invalid time zone abbr, contains digits",
236 # }}}
237 diag("Testing -v (--verbose) option...");
238 likecmd("$CMD -hv", # {{{
239 '/\$Id: .*? \$.* Show this help\./s',
240 '/^$/',
241 "Option --version with -h returns Id string and help screen",
244 # }}}
245 diag("Testing --version option...");
246 likecmd("$CMD --version", # {{{
247 '/\$Id: .*? \$/',
248 '/^$/',
249 "Option --version returns Id string",
252 # }}}
253 diag("Various...");
254 testcmd("$CMD files/DSC_4426.JPG", # {{{
255 <<END,
256 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
259 "Read date from DSC_4426.JPG, no options",
262 # }}}
264 todo_section:
267 if ($Opt{'all'} || $Opt{'todo'}) {
268 diag("Running TODO tests..."); # {{{
270 TODO: {
272 local $TODO = "";
273 testcmd("$CMD -o extxml files/DSC_4426.JPG", # {{{
274 <<END,
275 <?xml version="1.0" encoding="UTF-8"?>
276 <gpstpic>
277 <img>
278 <filename>DSC_4426.JPG</filename>
279 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
280 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
281 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
282 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
283 <date type="DateTime">2008-09-18T15:02:27Z</date>
284 <exposure>
285 <iso>200</iso>
286 <speed>0.333333</speed>
287 <fnumber>3.5 APEX</fnumber>
288 <flash>0</flash>
289 </exposure>
290 <camera>
291 <make>NIKON CORPRORATION</make>
292 <model>NIKON D300</model>
293 <shuttercount>4610</shuttercount>
294 </camera>
295 </img>
296 </gpstpic>
299 "Show extended XML information for DSC_4426.JPG",
302 # }}}
305 # TODO tests }}}
308 diag("Testing finished.");
310 sub testcmd {
311 # {{{
312 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
313 my $stderr_cmd = "";
314 my $deb_str = $Opt{'debug'} ? " --debug" : "";
315 my $Txt = join("",
316 "\"$Cmd\"",
317 defined($Desc)
318 ? " - $Desc"
319 : ""
321 my $TMP_STDERR = "gpst-pic-stderr.tmp";
323 if (defined($Exp_stderr) && !length($deb_str)) {
324 $stderr_cmd = " 2>$TMP_STDERR";
326 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
327 if (defined($Exp_stderr)) {
328 if (!length($deb_str)) {
329 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
330 unlink($TMP_STDERR);
332 } else {
333 diag("Warning: stderr not defined for '$Txt'");
335 # }}}
338 sub likecmd {
339 # {{{
340 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
341 my $stderr_cmd = "";
342 my $deb_str = $Opt{'debug'} ? " --debug" : "";
343 my $Txt = join("",
344 "\"$Cmd\"",
345 defined($Desc)
346 ? " - $Desc"
347 : ""
349 my $TMP_STDERR = "gpst-pic-stderr.tmp";
351 if (defined($Exp_stderr) && !length($deb_str)) {
352 $stderr_cmd = " 2>$TMP_STDERR";
354 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
355 if (defined($Exp_stderr)) {
356 if (!length($deb_str)) {
357 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
358 unlink($TMP_STDERR);
360 } else {
361 diag("Warning: stderr not defined for '$Txt'");
363 # }}}
366 sub file_data {
367 # Return file content as a string {{{
368 my $File = shift;
369 my $Txt;
370 if (open(FP, "<", $File)) {
371 $Txt = join("", <FP>);
372 close(FP);
373 return($Txt);
374 } else {
375 return undef;
377 # }}}
380 sub print_version {
381 # Print program version {{{
382 for (@main::version_array) {
383 print("$_\n");
385 # }}}
386 } # print_version()
388 sub usage {
389 # Send the help message to stdout {{{
390 my $Retval = shift;
392 if ($Opt{'verbose'}) {
393 print("\n");
394 print_version();
396 print(<<END);
398 Usage: $progname [options] [file [files [...]]]
400 Contains tests for the gpst-pic(1) program.
402 Options:
404 -a, --all
405 Run all tests, also TODOs.
406 -h, --help
407 Show this help.
408 -t, --todo
409 Run only the TODO tests.
410 -v, --verbose
411 Increase level of verbosity. Can be repeated.
412 --version
413 Print version information.
414 --debug
415 Print debugging messages.
418 exit($Retval);
419 # }}}
420 } # usage()
422 sub msg {
423 # Print a status message to stderr based on verbosity level {{{
424 my ($verbose_level, $Txt) = @_;
426 if ($Opt{'verbose'} >= $verbose_level) {
427 print(STDERR "$progname: $Txt\n");
429 # }}}
430 } # msg()
432 __END__
434 # Plain Old Documentation (POD) {{{
436 =pod
438 =head1 NAME
440 run-tests.pl
442 =head1 REVISION
444 $Id$
446 =head1 SYNOPSIS
448 gpst-pic.t [options] [file [files [...]]]
450 =head1 DESCRIPTION
452 Contains tests for the gpst-pic(1) program.
454 =head1 OPTIONS
456 =over 4
458 =item B<-a>, B<--all>
460 Run all tests, also TODOs.
462 =item B<-h>, B<--help>
464 Print a brief help summary.
466 =item B<-t>, B<--todo>
468 Run only the TODO tests.
470 =item B<-v>, B<--verbose>
472 Increase level of verbosity. Can be repeated.
474 =item B<--version>
476 Print version information.
478 =item B<--debug>
480 Print debugging messages.
482 =back
484 =head1 AUTHOR
486 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
488 =head1 COPYRIGHT
490 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
491 This is free software; see the file F<COPYING> for legalese stuff.
493 =head1 LICENCE
495 This program is free software; you can redistribute it and/or modify it
496 under the terms of the GNU General Public License as published by the
497 Free Software Foundation; either version 2 of the License, or (at your
498 option) any later version.
500 This program is distributed in the hope that it will be useful, but
501 WITHOUT ANY WARRANTY; without even the implied warranty of
502 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
503 See the GNU General Public License for more details.
505 You should have received a copy of the GNU General Public License along
506 with this program; if not, write to the Free Software Foundation, Inc.,
507 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
509 =head1 SEE ALSO
511 gpst(1)
513 =cut
515 # }}}
517 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
518 # End of file $Id$