3 #=======================================================================
5 # Test suite for gpst-pic(1).
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 #=======================================================================
14 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
16 use Test
::More
qw{no_plan
};
27 our $CMD = "../../gpst-pic";
41 $progname =~ s/^.*\/(.*?)$/$1/;
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");
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'}) {
70 diag
(sprintf("========== Executing \"%s%s%s\" ==========",
72 scalar(@cmdline_array) ?
" " : "",
73 join(" ", @cmdline_array)));
75 if ($Opt{'todo'} && !$Opt{'all'}) {
81 testcmd("$CMD command", # {{{
93 diag
("Checking dependencies...");
94 likecmd
("exifprobe -V", # {{{
95 "/Program: 'exifprobe' version [234]/",
97 "Check that exifprobe(1) is installed",
101 diag
("Testing --author option...");
102 testcmd
("$CMD -a sunny files/DSC_4426.JPG", # {{{
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",
111 # diag("Testing --debug option...");
112 diag
("Testing --description option...");
113 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
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",
122 diag
("Testing -h (--help) option...");
123 likecmd
("$CMD -h", # {{{
124 '/ Show this help\./',
126 "Option -h prints help screen",
130 ok
(`$CMD -h` !~ /\$Id: /s, "\"$CMD -h\" - No Id with only -h");
131 diag
("Testing --output-format option..."); # {{{
133 testcmd
("$CMD -o pgtab files/DSC_4426.JPG", # {{{
135 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
138 "Output pgtab format from DSC_4426.JPG",
143 testcmd
("$CMD -o xml files/DSC_4426.JPG", # {{{
145 <?xml version="1.0" encoding="UTF-8"?>
148 <filename>DSC_4426.JPG</filename>
149 <date>2008-09-18T17:02:27</date>
154 "Output XML information for DSC_4426.JPG",
159 testcmd
("$CMD -o blurfl files/DSC_4426.JPG", # {{{
161 "gpst-pic: blurfl: Unknown output format\n",
162 "Unknown output format specified",
166 # }}} --output-format
167 diag
("Testing -w (--strip-whitespace) option...");
168 testcmd
("$CMD -w -o xml files/DSC_4426.JPG", # {{{
170 <?xml version="1.0" encoding="UTF-8"?>
173 <filename>DSC_4426.JPG</filename>
174 <date>2008-09-18T17:02:27</date>
179 "Strip whitespace from XML",
183 diag
("Testing -T (--timezone) option...");
184 testcmd
("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
186 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
193 testcmd
("$CMD -T +0200 files/DSC_4426.JPG", # {{{
195 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
198 "Positive time zone",
202 testcmd
("$CMD -T-0600 files/DSC_4426.JPG", # {{{
204 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
207 "Negative time zone",
211 testcmd
("$CMD -T CET files/DSC_4426.JPG", # {{{
213 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
216 "Time zone abbreviation",
220 testcmd
("$CMD -T Z files/DSC_4426.JPG", # {{{
222 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
229 testcmd
("$CMD -T erf324 files/DSC_4426.JPG", # {{{
231 "gpst-pic: erf324: Invalid time zone\n",
232 "Invalid time zone abbr, contains digits",
236 diag
("Testing -v (--verbose) option...");
237 likecmd
("$CMD -hv", # {{{
238 '/\$Id: .*? \$.* Show this help\./s',
240 "Option --version with -h returns Id string and help screen",
244 diag
("Testing --version option...");
245 likecmd
("$CMD --version", # {{{
248 "Option --version returns Id string",
253 testcmd
("$CMD files/DSC_4426.JPG", # {{{
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",
266 if ($Opt{'all'} || $Opt{'todo'}) {
267 diag
("Running TODO tests..."); # {{{
272 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
274 <?xml version="1.0" encoding="UTF-8"?>
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>
285 <speed>0.333333</speed>
286 <fnumber>3.5 APEX</fnumber>
290 <make>NIKON CORPRORATION</make>
291 <model>NIKON D300</model>
292 <shuttercount>4610</shuttercount>
298 "Show extended XML information for DSC_4426.JPG",
307 diag
("Testing finished.");
311 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
313 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
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)");
332 diag
("Warning: stderr not defined for '$Txt'");
339 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
341 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
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)");
360 diag
("Warning: stderr not defined for '$Txt'");
366 # Return file content as a string {{{
369 if (open(FP
, "<", $File)) {
370 $Txt = join("", <FP
>);
380 # Print program version {{{
381 for (@main::version_array
) {
388 # Send the help message to stdout {{{
391 if ($Opt{'verbose'}) {
397 Usage: $progname [options] [file [files [...]]]
399 Contains tests for the gpst-pic(1) program.
404 Run all tests, also TODOs.
408 Run only the TODO tests.
410 Increase level of verbosity. Can be repeated.
412 Print version information.
414 Print debugging messages.
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");
433 # Plain Old Documentation (POD) {{{
447 gpst-pic.t [options] [file [files [...]]]
451 Contains tests for the gpst-pic(1) program.
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.
475 Print version information.
479 Print debugging messages.
485 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
489 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
490 This is free software; see the file F<COPYING> for legalese stuff.
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
516 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :