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 diag
("Checking dependencies...");
88 likecmd
("exifprobe -V", # {{{
89 "/Program: 'exifprobe' version [234]/",
91 "Check that exifprobe(1) is installed",
95 diag
("Testing --author option...");
96 testcmd
("$CMD -a sunny files/DSC_4426.JPG", # {{{
98 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\tsunny
101 "Read date from DSC_4426.JPG and set --author",
105 testcmd
("$CMD -a sunny -o xml files/DSC_4426.JPG", # {{{
107 <?xml version="1.0" encoding="UTF-8"?>
110 <filename>DSC_4426.JPG</filename>
111 <date>2008-09-18T17:02:27</date>
112 <author>sunny</author>
117 "Author info is included with -o xml",
121 # diag("Testing --debug option...");
122 diag
("Testing --description option...");
123 testcmd
("$CMD -d 'Skumle til\\stander i Bergen.' files/DSC_4426.JPG", # {{{
125 1\t2008-09-18T17:02:27\t\\N\tSkumle til\\\\stander i Bergen.\tDSC_4426.JPG\t\\N
128 "Read date from DSC_4426.JPG and set --description with backslash",
132 testcmd
("$CMD -d 'Skumle til\\stander &<> i Bergen.' -o xml files/DSC_4426.JPG", # {{{
134 <?xml version="1.0" encoding="UTF-8"?>
137 <filename>DSC_4426.JPG</filename>
138 <date>2008-09-18T17:02:27</date>
139 <desc>Skumle til\\stander &<> i Bergen.</desc>
144 "--description works witk XML output",
148 diag
("Testing -h (--help) option...");
149 likecmd
("$CMD -h", # {{{
150 '/ Show this help\./',
152 "Option -h prints help screen",
156 diag
("Testing --output-format option..."); # {{{
158 testcmd
("$CMD -o pgtab files/DSC_4426.JPG", # {{{
160 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
163 "Output pgtab format from DSC_4426.JPG",
168 testcmd
("$CMD -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 "Output XML information for DSC_4426.JPG",
184 testcmd
("$CMD -o blurfl files/DSC_4426.JPG", # {{{
186 "gpst-pic: blurfl: Unknown output format\n",
187 "Unknown output format specified",
191 # }}} --output-format
192 diag
("Testing -w (--strip-whitespace) option...");
193 testcmd
("$CMD -w -o xml files/DSC_4426.JPG", # {{{
195 <?xml version="1.0" encoding="UTF-8"?>
198 <filename>DSC_4426.JPG</filename>
199 <date>2008-09-18T17:02:27</date>
204 "Strip whitespace from XML",
208 diag
("Testing -T (--timezone) option...");
209 testcmd
("$CMD --timezone +1234 files/DSC_4426.JPG", # {{{
211 1\t2008-09-18T17:02:27+1234\t\\N\t\\N\tDSC_4426.JPG\t\\N
218 testcmd
("$CMD -T +0200 files/DSC_4426.JPG", # {{{
220 1\t2008-09-18T17:02:27+0200\t\\N\t\\N\tDSC_4426.JPG\t\\N
223 "Positive time zone",
227 testcmd
("$CMD -T-0600 files/DSC_4426.JPG", # {{{
229 1\t2008-09-18T17:02:27-0600\t\\N\t\\N\tDSC_4426.JPG\t\\N
232 "Negative time zone",
236 testcmd
("$CMD -T CET files/DSC_4426.JPG", # {{{
238 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
241 "Time zone abbreviation",
245 testcmd
("$CMD -T cet files/DSC_4426.JPG", # {{{
247 1\t2008-09-18T17:02:27 CET\t\\N\t\\N\tDSC_4426.JPG\t\\N
250 "Time zone is converted to upper case",
254 testcmd
("$CMD -T Z files/DSC_4426.JPG", # {{{
256 1\t2008-09-18T17:02:27Z\t\\N\t\\N\tDSC_4426.JPG\t\\N
263 testcmd
("$CMD -T erf324 files/DSC_4426.JPG", # {{{
265 "gpst-pic: erf324: Invalid time zone\n",
266 "Invalid time zone abbr, contains digits",
270 testcmd
("$CMD -T CET -o xml files/DSC_4426.JPG", # {{{
272 <?xml version="1.0" encoding="UTF-8"?>
275 <filename>DSC_4426.JPG</filename>
276 <date>2008-09-18T17:02:27 CET</date>
281 "Time zone abbr. works with -o xml",
285 testcmd
("$CMD -T Z -o xml files/DSC_4426.JPG", # {{{
287 <?xml version="1.0" encoding="UTF-8"?>
290 <filename>DSC_4426.JPG</filename>
291 <date>2008-09-18T17:02:27Z</date>
296 "Zulu time zone works with -o xml",
300 diag
("Testing -v (--verbose) option...");
301 likecmd
("$CMD -hv", # {{{
302 '/^\n\S+ v\d\.\d\d\n/s',
304 "Option --version with -h returns version number and help screen",
308 diag
("Testing --version option...");
309 likecmd
("$CMD --version", # {{{
310 '/^\S+ v\d\.\d\d\n/',
312 "Option --version returns version number",
317 testcmd
("$CMD files/DSC_4426.JPG", # {{{
319 1\t2008-09-18T17:02:27\t\\N\t\\N\tDSC_4426.JPG\t\\N
322 "Read date from DSC_4426.JPG, no options",
330 if ($Opt{'all'} || $Opt{'todo'}) {
331 diag
("Running TODO tests..."); # {{{
336 testcmd
("$CMD -o extxml files/DSC_4426.JPG", # {{{
338 <?xml version="1.0" encoding="UTF-8"?>
341 <filename>DSC_4426.JPG</filename>
342 <crc type="sha1">267e841cb6788c795541e36aea70e2a55d8ec3bb</crc>
343 <crc type="md5">19eb5c86f6b3662b57bc94c3ea428372</crc>
344 <date type="DateTimeOriginal">2008-03-02T17:51:39Z</date>
345 <date type="DateTimeDigitized">2008-03-02T17:51:39Z</date>
346 <date type="DateTime">2008-09-18T15:02:27Z</date>
349 <speed>0.333333</speed>
350 <fnumber>3.5 APEX</fnumber>
354 <make>NIKON CORPRORATION</make>
355 <model>NIKON D300</model>
356 <shuttercount>4610</shuttercount>
362 "Show extended XML information for DSC_4426.JPG",
371 diag
("Testing finished.");
375 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
377 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
384 my $TMP_STDERR = "gpst-pic-stderr.tmp";
386 if (defined($Exp_stderr) && !length($deb_str)) {
387 $stderr_cmd = " 2>$TMP_STDERR";
389 is
(`$Cmd$deb_str$stderr_cmd`, $Exp_stdout, $Txt);
390 if (defined($Exp_stderr)) {
391 if (!length($deb_str)) {
392 is
(file_data
($TMP_STDERR), $Exp_stderr, "$Txt (stderr)");
396 diag
("Warning: stderr not defined for '$Txt'");
403 my ($Cmd, $Exp_stdout, $Exp_stderr, $Desc) = @_;
405 my $deb_str = $Opt{'debug'} ?
" --debug" : "";
412 my $TMP_STDERR = "gpst-pic-stderr.tmp";
414 if (defined($Exp_stderr) && !length($deb_str)) {
415 $stderr_cmd = " 2>$TMP_STDERR";
417 like
(`$Cmd$deb_str$stderr_cmd`, "$Exp_stdout", $Txt);
418 if (defined($Exp_stderr)) {
419 if (!length($deb_str)) {
420 like
(file_data
($TMP_STDERR), "$Exp_stderr", "$Txt (stderr)");
424 diag
("Warning: stderr not defined for '$Txt'");
430 # Return file content as a string {{{
433 if (open(my $fp, "<", $File)) {
434 $Txt = join("", <$fp>);
444 # Print program version {{{
445 print("$progname v$VERSION\n");
450 # Send the help message to stdout {{{
453 if ($Opt{'verbose'}) {
459 Usage: $progname [options] [file [files [...]]]
461 Contains tests for the gpst-pic(1) program.
466 Run all tests, also TODOs.
470 Run only the TODO tests.
472 Increase level of verbosity. Can be repeated.
474 Print version information.
476 Print debugging messages.
484 # Print a status message to stderr based on verbosity level {{{
485 my ($verbose_level, $Txt) = @_;
487 if ($Opt{'verbose'} >= $verbose_level) {
488 print(STDERR
"$progname: $Txt\n");
495 # Plain Old Documentation (POD) {{{
505 gpst-pic.t [options] [file [files [...]]]
509 Contains tests for the gpst-pic(1) program.
515 =item B<-a>, B<--all>
517 Run all tests, also TODOs.
519 =item B<-h>, B<--help>
521 Print a brief help summary.
523 =item B<-t>, B<--todo>
525 Run only the TODO tests.
527 =item B<-v>, B<--verbose>
529 Increase level of verbosity. Can be repeated.
533 Print version information.
537 Print debugging messages.
543 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
547 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
548 This is free software; see the file F<COPYING> for legalese stuff.
552 This program is free software: you can redistribute it and/or modify it
553 under the terms of the GNU General Public License as published by the
554 Free Software Foundation, either version 3 of the License, or (at your
555 option) any later version.
557 This program is distributed in the hope that it will be useful, but
558 WITHOUT ANY WARRANTY; without even the implied warranty of
559 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
560 See the GNU General Public License for more details.
562 You should have received a copy of the GNU General Public License along
564 If not, see L<http://www.gnu.org/licenses/>.
574 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :