Remove forgotten $rcs_id variable after the svn → git conversion
[gpstools.git] / branches / gpst.postgis / tests / gpst-pic / gpst-pic.t
blobbade83cc6071d775a3b5dc2296f0e637d3257c93
1 #!/usr/bin/perl -w
3 #=======================================================================
4 # $Id$
5 # Test suite for gpst-pic(1).
7 # Character set: UTF-8
8 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License version 2 or later, see end of
10 # file for legal stuff.
11 #=======================================================================
13 BEGIN {
14 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
15 our @version_array;
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/;
43 my $rcs_id = '$Id$';
44 my $id_date = $rcs_id;
45 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
47 push(@main::version_array, $rcs_id);
49 my @cmdline_array = @ARGV;
51 Getopt::Long::Configure("bundling");
52 GetOptions(
54 "all|a" => \$Opt{'all'},
55 "debug" => \$Opt{'debug'},
56 "help|h" => \$Opt{'help'},
57 "todo|t" => \$Opt{'todo'},
58 "verbose|v+" => \$Opt{'verbose'},
59 "version" => \$Opt{'version'},
61 ) || die("$progname: Option error. Use -h for help.\n");
63 $Opt{'debug'} && ($Debug = 1);
64 $Opt{'help'} && usage(0);
65 if ($Opt{'version'}) {
66 print_version();
67 exit(0);
70 diag(sprintf("========== Executing \"%s%s%s\" ==========",
71 $progname,
72 scalar(@cmdline_array) ? " " : "",
73 join(" ", @cmdline_array)));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
76 goto todo_section;
79 =pod
81 testcmd("$CMD command", # {{{
82 <<END,
83 [expected stdin]
84 END
85 "",
86 "description",
89 # }}}
91 =cut
93 diag("Checking dependencies...");
94 likecmd("exifprobe -V", # {{{
95 "/Program: 'exifprobe' version [234]/",
96 '/^$/',
97 "Check that exifprobe(1) is installed",
100 # }}}
101 diag("Testing --author option...");
102 testcmd("$CMD -a sunny files/DSC_4426.JPG", # {{{
103 <<END,
104 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
107 "Read date from DSC_4426.JPG and set --author",
110 # }}}
111 # diag("Testing --debug option...");
112 diag("Testing --description option...");
113 testcmd("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
114 <<END,
115 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
118 "Read date from DSC_4426.JPG and set --description with backslash",
121 # }}}
122 diag("Testing -h (--help) option...");
123 likecmd("$CMD -h", # {{{
124 '/ Show this help\./',
125 '/^$/',
126 "Option -h prints help screen",
129 # }}}
130 ok(`$CMD -h` !~ /\$Id: /s, "\"$CMD -h\" - No Id with only -h");
131 diag("Testing --output-format option..."); # {{{
132 # pgtab
133 testcmd("$CMD -o pgtab files/DSC_4426.JPG", # {{{
134 <<END,
135 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
138 "Output pgtab format from DSC_4426.JPG",
141 # }}}
142 # xml
143 testcmd("$CMD -o xml files/DSC_4426.JPG", # {{{
144 <<END,
145 <?xml version="1.0" encoding="UTF-8"?>
146 <gpstpic>
147 <img>
148 <filename>DSC_4426.JPG</filename>
149 <date>2008-09-18T17:02:27</date>
150 </img>
151 </gpstpic>
154 "Output XML information for DSC_4426.JPG",
157 # }}}
158 # Unknown format
159 testcmd("$CMD -o blurfl files/DSC_4426.JPG", # {{{
161 "gpst-pic: blurfl: Unknown output format\n",
162 "Unknown output format specified",
165 # }}}
166 # }}} --output-format
167 diag("Testing -w (--strip-whitespace) option...");
168 testcmd("$CMD -w -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 "Strip whitespace from XML",
182 # }}}
183 diag("Testing -T (--timezone) option...");
184 testcmd("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
185 <<END,
186 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
189 "--timezone works",
192 # }}}
193 testcmd("$CMD -T +0200 files/DSC_4426.JPG", # {{{
194 <<END,
195 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
198 "Positive time zone",
201 # }}}
202 testcmd("$CMD -T-0600 files/DSC_4426.JPG", # {{{
203 <<END,
204 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
207 "Negative time zone",
210 # }}}
211 testcmd("$CMD -T CET files/DSC_4426.JPG", # {{{
212 <<END,
213 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
216 "Time zone abbreviation",
219 # }}}
220 testcmd("$CMD -T Z files/DSC_4426.JPG", # {{{
221 <<END,
222 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
225 "Zulu abbreviation",
228 # }}}
229 testcmd("$CMD -T erf324 files/DSC_4426.JPG", # {{{
231 "gpst-pic: erf324: Invalid time zone\n",
232 "Invalid time zone abbr, contains digits",
235 # }}}
236 diag("Testing -v (--verbose) option...");
237 likecmd("$CMD -hv", # {{{
238 '/\$Id: .*? \$.* Show this help\./s',
239 '/^$/',
240 "Option --version with -h returns Id string and help screen",
243 # }}}
244 diag("Testing --version option...");
245 likecmd("$CMD --version", # {{{
246 '/\$Id: .*? \$/',
247 '/^$/',
248 "Option --version returns Id string",
251 # }}}
252 diag("Various...");
253 testcmd("$CMD files/DSC_4426.JPG", # {{{
254 <<END,
255 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
258 "Read date from DSC_4426.JPG, no options",
261 # }}}
263 todo_section:
266 if ($Opt{'all'} || $Opt{'todo'}) {
267 diag("Running TODO tests..."); # {{{
269 TODO: {
271 local $TODO = "";
272 testcmd("$CMD -o extxml files/DSC_4426.JPG", # {{{
273 <<END,
274 <?xml version="1.0" encoding="UTF-8"?>
275 <gpstpic>
276 <img>
277 <filename>DSC_4426.JPG</filename>
278 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
279 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
280 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
281 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
282 <date type="DateTime">2008-09-18T15:02:27Z</date>
283 <exposure>
284 <iso>200</iso>
285 <speed>0.333333</speed>
286 <fnumber>3.5 APEX</fnumber>
287 <flash>0</flash>
288 </exposure>
289 <camera>
290 <make>NIKON CORPRORATION</make>
291 <model>NIKON D300</model>
292 <shuttercount>4610</shuttercount>
293 </camera>
294 </img>
295 </gpstpic>
298 "Show extended XML information for DSC_4426.JPG",
301 # }}}
304 # TODO tests }}}
307 diag("Testing finished.");
309 sub testcmd {
310 # {{{
311 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
312 my $stderr_cmd = "";
313 my $deb_str = $Opt{'debug'} ? " --debug" : "";
314 my $Txt = join("",
315 "\"$Cmd\"",
316 defined($Desc)
317 ? " - $Desc"
318 : ""
320 my $TMP_STDERR = "gpst-pic-stderr.tmp";
322 if (defined($Exp_stderr) && !length($deb_str)) {
323 $stderr_cmd = " 2>$TMP_STDERR";
325 is(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
326 if (defined($Exp_stderr)) {
327 if (!length($deb_str)) {
328 is(file_data($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
329 unlink($TMP_STDERR);
331 } else {
332 diag("Warning: stderr not defined for '$Txt'");
334 # }}}
337 sub likecmd {
338 # {{{
339 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
340 my $stderr_cmd = "";
341 my $deb_str = $Opt{'debug'} ? " --debug" : "";
342 my $Txt = join("",
343 "\"$Cmd\"",
344 defined($Desc)
345 ? " - $Desc"
346 : ""
348 my $TMP_STDERR = "gpst-pic-stderr.tmp";
350 if (defined($Exp_stderr) && !length($deb_str)) {
351 $stderr_cmd = " 2>$TMP_STDERR";
353 like(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
354 if (defined($Exp_stderr)) {
355 if (!length($deb_str)) {
356 like(file_data($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
357 unlink($TMP_STDERR);
359 } else {
360 diag("Warning: stderr not defined for '$Txt'");
362 # }}}
365 sub file_data {
366 # Return file content as a string {{{
367 my $File = shift;
368 my $Txt;
369 if (open(FP, "<", $File)) {
370 $Txt = join("", <FP>);
371 close(FP);
372 return($Txt);
373 } else {
374 return undef;
376 # }}}
379 sub print_version {
380 # Print program version {{{
381 for (@main::version_array) {
382 print("$_\n");
384 # }}}
385 } # print_version()
387 sub usage {
388 # Send the help message to stdout {{{
389 my $Retval = shift;
391 if ($Opt{'verbose'}) {
392 print("\n");
393 print_version();
395 print(<<END);
397 Usage: $progname [options] [file [files [...]]]
399 Contains tests for the gpst-pic(1) program.
401 Options:
403 -a, --all
404 Run all tests, also TODOs.
405 -h, --help
406 Show this help.
407 -t, --todo
408 Run only the TODO tests.
409 -v, --verbose
410 Increase level of verbosity. Can be repeated.
411 --version
412 Print version information.
413 --debug
414 Print debugging messages.
417 exit($Retval);
418 # }}}
419 } # usage()
421 sub msg {
422 # Print a status message to stderr based on verbosity level {{{
423 my ($verbose_level, $Txt) = @_;
425 if ($Opt{'verbose'} >= $verbose_level) {
426 print(STDERR "$progname: $Txt\n");
428 # }}}
429 } # msg()
431 __END__
433 # Plain Old Documentation (POD) {{{
435 =pod
437 =head1 NAME
439 run-tests.pl
441 =head1 REVISION
443 $Id$
445 =head1 SYNOPSIS
447 gpst-pic.t [options] [file [files [...]]]
449 =head1 DESCRIPTION
451 Contains tests for the gpst-pic(1) program.
453 =head1 OPTIONS
455 =over 4
457 =item B<-a>, B<--all>
459 Run all tests, also TODOs.
461 =item B<-h>, B<--help>
463 Print a brief help summary.
465 =item B<-t>, B<--todo>
467 Run only the TODO tests.
469 =item B<-v>, B<--verbose>
471 Increase level of verbosity. Can be repeated.
473 =item B<--version>
475 Print version information.
477 =item B<--debug>
479 Print debugging messages.
481 =back
483 =head1 AUTHOR
485 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
487 =head1 COPYRIGHT
489 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
490 This is free software; see the file F<COPYING> for legalese stuff.
492 =head1 LICENCE
494 This program is free software; you can redistribute it and/or modify it
495 under the terms of the GNU General Public License as published by the
496 Free Software Foundation; either version 2 of the License, or (at your
497 option) any later version.
499 This program is distributed in the hope that it will be useful, but
500 WITHOUT ANY WARRANTY; without even the implied warranty of
501 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
502 See the GNU General Public License for more details.
504 You should have received a copy of the GNU General Public License along
505 with this program; if not, write to the Free Software Foundation, Inc.,
506 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
508 =head1 SEE ALSO
510 gpst(1)
512 =cut
514 # }}}
516 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
517 # End of file $Id$