3 #=======================================================================
5 # File ID: f210dafc-f924-11dd-9315-0001805bf4b1
6 # Test suite for gpst-pic(1).
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 #=======================================================================
15 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
17 use Test
::More
qw{no_plan
};
28 our $CMD = "../../gpst-pic";
42 $progname =~ s/^.*\/(.*?)$/$1/;
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");
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'}) {
71 diag
(sprintf("========== Executing \"%s%s%s\" ==========",
73 scalar(@cmdline_array) ?
" " : "",
74 join(" ", @cmdline_array)));
76 if ($Opt{'todo'} && !$Opt{'all'}) {
82 testcmd("$CMD command", # {{{
94 diag
("Checking dependencies...");
95 likecmd
("exifprobe -V", # {{{
96 "/Program: 'exifprobe' version [234]/",
98 "Check that exifprobe(1) is installed",
102 diag
("Testing --author option...");
103 testcmd
("$CMD -a sunny files/DSC_4426.JPG", # {{{
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",
112 # diag("Testing --debug option...");
113 diag
("Testing --description option...");
114 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
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",
123 diag
("Testing -h (--help) option...");
124 likecmd
("$CMD -h", # {{{
125 '/ Show this help\./',
127 "Option -h prints help screen",
131 ok
(`$CMD -h` !~ /\$Id: /s, "\"$CMD -h\" - No Id with only -h");
132 diag
("Testing --output-format option..."); # {{{
134 testcmd
("$CMD -o pgtab files/DSC_4426.JPG", # {{{
136 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
139 "Output pgtab format from DSC_4426.JPG",
144 testcmd
("$CMD -o xml files/DSC_4426.JPG", # {{{
146 <?xml version="1.0" encoding="UTF-8"?>
149 <filename>DSC_4426.JPG</filename>
150 <date>2008-09-18T17:02:27</date>
155 "Output XML information for DSC_4426.JPG",
160 testcmd
("$CMD -o blurfl files/DSC_4426.JPG", # {{{
162 "gpst-pic: blurfl: Unknown output format\n",
163 "Unknown output format specified",
167 # }}} --output-format
168 diag
("Testing -w (--strip-whitespace) option...");
169 testcmd
("$CMD -w -o xml files/DSC_4426.JPG", # {{{
171 <?xml version="1.0" encoding="UTF-8"?>
174 <filename>DSC_4426.JPG</filename>
175 <date>2008-09-18T17:02:27</date>
180 "Strip whitespace from XML",
184 diag
("Testing -T (--timezone) option...");
185 testcmd
("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
187 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
194 testcmd
("$CMD -T +0200 files/DSC_4426.JPG", # {{{
196 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
199 "Positive time zone",
203 testcmd
("$CMD -T-0600 files/DSC_4426.JPG", # {{{
205 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
208 "Negative time zone",
212 testcmd
("$CMD -T CET files/DSC_4426.JPG", # {{{
214 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
217 "Time zone abbreviation",
221 testcmd
("$CMD -T Z files/DSC_4426.JPG", # {{{
223 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
230 testcmd
("$CMD -T erf324 files/DSC_4426.JPG", # {{{
232 "gpst-pic: erf324: Invalid time zone\n",
233 "Invalid time zone abbr, contains digits",
237 diag
("Testing -v (--verbose) option...");
238 likecmd
("$CMD -hv", # {{{
239 '/\$Id: .*? \$.* Show this help\./s',
241 "Option --version with -h returns Id string and help screen",
245 diag
("Testing --version option...");
246 likecmd
("$CMD --version", # {{{
249 "Option --version returns Id string",
254 testcmd
("$CMD files/DSC_4426.JPG", # {{{
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",
267 if ($Opt{'all'} || $Opt{'todo'}) {
268 diag
("Running TODO tests..."); # {{{
273 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
275 <?xml version="1.0" encoding="UTF-8"?>
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>
286 <speed>0.333333</speed>
287 <fnumber>3.5 APEX</fnumber>
291 <make>NIKON CORPRORATION</make>
292 <model>NIKON D300</model>
293 <shuttercount>4610</shuttercount>
299 "Show extended XML information for DSC_4426.JPG",
308 diag
("Testing finished.");
312 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
314 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
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)");
333 diag
("Warning: stderr not defined for '$Txt'");
340 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
342 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
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)");
361 diag
("Warning: stderr not defined for '$Txt'");
367 # Return file content as a string {{{
370 if (open(FP
, "<", $File)) {
371 $Txt = join("", <FP
>);
381 # Print program version {{{
382 for (@main::version_array
) {
389 # Send the help message to stdout {{{
392 if ($Opt{'verbose'}) {
398 Usage: $progname [options] [file [files [...]]]
400 Contains tests for the gpst-pic(1) program.
405 Run all tests, also TODOs.
409 Run only the TODO tests.
411 Increase level of verbosity. Can be repeated.
413 Print version information.
415 Print debugging messages.
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");
434 # Plain Old Documentation (POD) {{{
448 gpst-pic.t [options] [file [files [...]]]
452 Contains tests for the gpst-pic(1) program.
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.
476 Print version information.
480 Print debugging messages.
486 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
490 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
491 This is free software; see the file F<COPYING> for legalese stuff.
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
517 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :