3 #=======================================================================
4 # tests/gpst-pic/gpst-pic.t
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 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
18 push(@INC, "$ENV{'HOME'}/bin/src/gpstools");
19 use Test
::More
qw{no_plan
};
29 our $CMD = "../gpst-pic";
43 $progname =~ s/^.*\/(.*?)$/$1/;
44 our $VERSION = "0.00";
46 Getopt
::Long
::Configure
("bundling");
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'}) {
65 diag
(sprintf("========== Executing %s v%s ==========",
69 if ($Opt{'todo'} && !$Opt{'all'}) {
75 testcmd("$CMD command", # {{{
87 my $top = 'gpst-pic-files';
88 diag
("Checking dependencies...");
89 likecmd
("exifprobe -V", # {{{
90 "/Program: 'exifprobe' version [234]/",
92 "Check that exifprobe(1) is installed",
96 diag
("Testing --author option...");
97 testcmd
("$CMD -a sunny $top/DSC_4426.JPG", # {{{
99 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
102 "Read date from DSC_4426.JPG and set --author",
106 testcmd
("$CMD -a sunny -o xml $top/DSC_4426.JPG", # {{{
108 <?xml version="1.0" encoding="UTF-8"?>
111 <filename>DSC_4426.JPG</filename>
112 <date>2008-09-18T17:02:27</date>
113 <author>sunny</author>
118 "Author info is included with -o xml",
122 # diag("Testing --debug option...");
123 diag
("Testing --description option...");
124 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' $top/DSC_4426.JPG", # {{{
126 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
129 "Read date from DSC_4426.JPG and set --description with backslash",
133 testcmd
("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml $top/DSC_4426.JPG", # {{{
135 <?xml version="1.0" encoding="UTF-8"?>
138 <filename>DSC_4426.JPG</filename>
139 <date>2008-09-18T17:02:27</date>
140 <desc>Skumle til\\stander &<> i Bergen.</desc>
145 "--description works witk XML output",
149 diag
("Testing -h (--help) option...");
150 likecmd
("$CMD -h", # {{{
151 '/ Show this help\./',
153 "Option -h prints help screen",
157 diag
("Testing --output-format option..."); # {{{
159 testcmd
("$CMD -o pgtab $top/DSC_4426.JPG", # {{{
161 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
164 "Output pgtab format from DSC_4426.JPG",
169 testcmd
("$CMD -o xml $top/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 "Output XML information for DSC_4426.JPG",
185 testcmd
("$CMD -o blurfl $top/DSC_4426.JPG", # {{{
187 "gpst-pic: blurfl: Unknown output format\n",
188 "Unknown output format specified",
192 # }}} --output-format
193 diag
("Testing -w (--strip-whitespace) option...");
194 testcmd
("$CMD -w -o xml $top/DSC_4426.JPG", # {{{
196 <?xml version="1.0" encoding="UTF-8"?>
199 <filename>DSC_4426.JPG</filename>
200 <date>2008-09-18T17:02:27</date>
205 "Strip whitespace from XML",
209 diag
("Testing -T (--timezone) option...");
210 testcmd
("$CMD --timezone +1234 $top/DSC_4426.JPG", # {{{
212 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
219 testcmd
("$CMD -T +0200 $top/DSC_4426.JPG", # {{{
221 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
224 "Positive time zone",
228 testcmd
("$CMD -T-0600 $top/DSC_4426.JPG", # {{{
230 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
233 "Negative time zone",
237 testcmd
("$CMD -T CET $top/DSC_4426.JPG", # {{{
239 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
242 "Time zone abbreviation",
246 testcmd
("$CMD -T cet $top/DSC_4426.JPG", # {{{
248 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
251 "Time zone is converted to upper case",
255 testcmd
("$CMD -T Z $top/DSC_4426.JPG", # {{{
257 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
264 testcmd
("$CMD -T erf324 $top/DSC_4426.JPG", # {{{
266 "gpst-pic: erf324: Invalid time zone\n",
267 "Invalid time zone abbr, contains digits",
271 testcmd
("$CMD -T CET -o xml $top/DSC_4426.JPG", # {{{
273 <?xml version="1.0" encoding="UTF-8"?>
276 <filename>DSC_4426.JPG</filename>
277 <date>2008-09-18T17:02:27 CET</date>
282 "Time zone abbr. works with -o xml",
286 testcmd
("$CMD -T Z -o xml $top/DSC_4426.JPG", # {{{
288 <?xml version="1.0" encoding="UTF-8"?>
291 <filename>DSC_4426.JPG</filename>
292 <date>2008-09-18T17:02:27Z</date>
297 "Zulu time zone works with -o xml",
301 diag
("Testing -v (--verbose) option...");
302 likecmd
("$CMD -hv", # {{{
303 '/^\n\S+ v\d\.\d\d\n/s',
305 "Option --version with -h returns version number and help screen",
309 diag
("Testing --version option...");
310 likecmd
("$CMD --version", # {{{
311 '/^\S+ v\d\.\d\d\n/',
313 "Option --version returns version number",
318 testcmd
("$CMD $top/DSC_4426.JPG", # {{{
320 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
323 "Read date from DSC_4426.JPG, no options",
331 if ($Opt{'all'} || $Opt{'todo'}) {
332 diag
("Running TODO tests..."); # {{{
337 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
339 <?xml version="1.0" encoding="UTF-8"?>
342 <filename>DSC_4426.JPG</filename>
343 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
344 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
345 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
346 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
347 <date type="DateTime">2008-09-18T15:02:27Z</date>
350 <speed>0.333333</speed>
351 <fnumber>3.5 APEX</fnumber>
355 <make>NIKON CORPRORATION</make>
356 <model>NIKON D300</model>
357 <shuttercount>4610</shuttercount>
363 "Show extended XML information for DSC_4426.JPG",
372 diag
("Testing finished.");
376 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
378 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
385 my $TMP_STDERR = "gpst-pic-stderr.tmp";
387 if (defined($Exp_stderr) && !length($deb_str)) {
388 $stderr_cmd = " 2>$TMP_STDERR";
390 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
391 if (defined($Exp_stderr)) {
392 if (!length($deb_str)) {
393 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
397 diag
("Warning: stderr not defined for '$Txt'");
404 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
406 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
413 my $TMP_STDERR = "gpst-pic-stderr.tmp";
415 if (defined($Exp_stderr) && !length($deb_str)) {
416 $stderr_cmd = " 2>$TMP_STDERR";
418 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
419 if (defined($Exp_stderr)) {
420 if (!length($deb_str)) {
421 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
425 diag
("Warning: stderr not defined for '$Txt'");
431 # Return file content as a string {{{
434 if (open(my $fp, "<", $File)) {
435 $Txt = join("", <$fp>);
445 # Print program version {{{
446 print("$progname v$VERSION\n");
451 # Send the help message to stdout {{{
454 if ($Opt{'verbose'}) {
460 Usage: $progname [options] [file [files [...]]]
462 Contains tests for the gpst-pic(1) program.
467 Run all tests, also TODOs.
471 Run only the TODO tests.
473 Increase level of verbosity. Can be repeated.
475 Print version information.
477 Print debugging messages.
485 # Print a status message to stderr based on verbosity level {{{
486 my ($verbose_level, $Txt) = @_;
488 if ($Opt{'verbose'} >= $verbose_level) {
489 print(STDERR
"$progname: $Txt\n");
496 # Plain Old Documentation (POD) {{{
506 gpst-pic.t [options] [file [files [...]]]
510 Contains tests for the gpst-pic(1) program.
516 =item B<-a>, B<--all>
518 Run all tests, also TODOs.
520 =item B<-h>, B<--help>
522 Print a brief help summary.
524 =item B<-t>, B<--todo>
526 Run only the TODO tests.
528 =item B<-v>, B<--verbose>
530 Increase level of verbosity. Can be repeated.
534 Print version information.
538 Print debugging messages.
544 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
548 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
549 This is free software; see the file F<COPYING> for legalese stuff.
553 This program is free software: you can redistribute it and/or modify it
554 under the terms of the GNU General Public License as published by the
555 Free Software Foundation, either version 3 of the License, or (at your
556 option) any later version.
558 This program is distributed in the hope that it will be useful, but
559 WITHOUT ANY WARRANTY; without even the implied warranty of
560 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
561 See the GNU General Public License for more details.
563 You should have received a copy of the GNU General Public License along
565 If not, see L<http://www.gnu.org/licenses/>.
575 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :