101_Document.t (gscan2pdf-2.13.1.tar.xz) | : | 101_Document.t (gscan2pdf-2.13.2.tar.xz) | ||
---|---|---|---|---|
use warnings; | use warnings; | |||
use strict; | use strict; | |||
use IPC::System::Simple qw(system); | use IPC::System::Simple qw(system); | |||
use Test::More tests => 70; | use Test::More tests => 72; | |||
use Glib 1.210 qw(TRUE FALSE); | use Glib 1.210 qw(TRUE FALSE); | |||
use Gtk3 -init; # Could just call init separately | use Gtk3 -init; # Could just call init separately | |||
use Encode; | use Encode; | |||
use PDF::Builder; | use PDF::Builder; | |||
use File::stat; | use File::stat; | |||
use Date::Calc qw(Time_to_Date); | use Date::Calc qw(Time_to_Date); | |||
BEGIN { | BEGIN { | |||
use_ok('Gscan2pdf::Document'); | use_ok('Gscan2pdf::Document'); | |||
} | } | |||
skipping to change at line 163 | skipping to change at line 163 | |||
is( length $fonts, 65537, 'exec_command returns more than 65537 bytes' ); | is( length $fonts, 65537, 'exec_command returns more than 65537 bytes' ); | |||
######################### | ######################### | |||
my @date = Gscan2pdf::Document::text_to_datetime('2016-02-01'); | my @date = Gscan2pdf::Document::text_to_datetime('2016-02-01'); | |||
is_deeply( \@date, [ 2016, 2, 1, 0, 0, 0 ], 'text_to_datetime just date' ); | is_deeply( \@date, [ 2016, 2, 1, 0, 0, 0 ], 'text_to_datetime just date' ); | |||
@date = Gscan2pdf::Document::text_to_datetime('2016-02-01 10:11:12'); | @date = Gscan2pdf::Document::text_to_datetime('2016-02-01 10:11:12'); | |||
is_deeply( \@date, [ 2016, 2, 1, 10, 11, 12 ], 'text_to_datetime' ); | is_deeply( \@date, [ 2016, 2, 1, 10, 11, 12 ], 'text_to_datetime' ); | |||
@date = Gscan2pdf::Document::text_to_datetime( '', 2016, 2, 1 ); | ||||
is_deeply( \@date, [ 2016, 2, 1, 0, 0, 0 ], 'text_to_datetime empty string' ); | ||||
@date = Gscan2pdf::Document::text_to_datetime( '0000-00-00', 2016, 2, 1 ); | ||||
is_deeply( \@date, [ 2016, 2, 1, 0, 0, 0 ], 'text_to_datetime invalid date' ); | ||||
######################### | ######################### | |||
is Gscan2pdf::Document::expand_metadata_pattern( | is Gscan2pdf::Document::expand_metadata_pattern( | |||
template => '%Da %Dt %Ds %Dk %DY %Y %Dm %m %Dd %d %H %M %S.%De', | template => '%Da %Dt %Ds %Dk %DY %Y %Dm %m %Dd %d %H %M %S.%De', | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
subject => 'subject', | subject => 'subject', | |||
keywords => 'keywords', | keywords => 'keywords', | |||
docdate => [ 2016, 02, 01 ], | docdate => [ 2016, 02, 01 ], | |||
today_and_now => [ 1970, 01, 12, 14, 46, 39 ], | today_and_now => [ 1970, 01, 12, 14, 46, 39 ], | |||
extension => 'png', | extension => 'png', | |||
), | ), | |||
'a.n.other title subject keywords 2016 1970 02 01 01 12 14 46 39.png', | 'a.n.other title subject keywords 2016 1970 02 01 01 12 14 46 39.png', | |||
'expand_metadata_pattern'; | 'expand_metadata_pattern'; | |||
is( | is( | |||
Gscan2pdf::Document::expand_metadata_pattern( | Gscan2pdf::Document::expand_metadata_pattern( | |||
template => '%Da %Dt %DY %Y %Dm %m %Dd %d %H %M %S %DH %DM %DS.%De', | template => '%Da %Dt %DY %Y %Dm %m %Dd %d %H %M %S %DH %DM %DS.%De', | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
docdate => [ 2016, 02, 01, 10, 11, 12 ], | docdate => [ 2016, 02, 01, 10, 11, 12 ], | |||
today_and_now => [ 1970, 01, 12, 14, 46, 39 ], | today_and_now => [ 1970, 01, 12, 14, 46, 39 ], | |||
extension => 'tif', | extension => 'tif', | |||
), | ), | |||
'a.n.other title 2016 1970 02 01 01 12 14 46 39 10 11 12.tif', | 'a.n.other title 2016 1970 02 01 01 12 14 46 39 10 11 12.tif', | |||
'expand_metadata_pattern with doc time' | 'expand_metadata_pattern with doc time' | |||
); | ); | |||
is( | is( | |||
Gscan2pdf::Document::expand_metadata_pattern( | Gscan2pdf::Document::expand_metadata_pattern( | |||
template => '%Da %Dt %DY %Y %Dm %m %Dd %d %H %M %S.%De', | template => '%Da %Dt %DY %Y %Dm %m %Dd %d %H %M %S.%De', | |||
skipping to change at line 247 | skipping to change at line 253 | |||
Keywords => 'keywords', | Keywords => 'keywords', | |||
CreationDate => "D:20160210000000+00'00'" | CreationDate => "D:20160210000000+00'00'" | |||
}, | }, | |||
'prepare_output_metadata' | 'prepare_output_metadata' | |||
); | ); | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::prepare_output_metadata( | Gscan2pdf::Document::prepare_output_metadata( | |||
'PDF', | 'PDF', | |||
{ | { | |||
datetime => [ 2016, 2, 10, 0, 0, 0 ], | datetime => [ 2016, 2, 10, 0, 0, 0 ], | |||
tz => [ 0, 0, 0, 1, 0, 0, 0 ], | tz => [ 0, 0, 0, 1, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
} | } | |||
), | ), | |||
{ | { | |||
ModDate => "D:20160210000000+01'00'", | ModDate => "D:20160210000000+01'00'", | |||
Creator => "gscan2pdf v$Gscan2pdf::Document::VERSION", | Creator => "gscan2pdf v$Gscan2pdf::Document::VERSION", | |||
Author => 'a.n.other', | Author => 'a.n.other', | |||
skipping to change at line 271 | skipping to change at line 277 | |||
Keywords => 'keywords', | Keywords => 'keywords', | |||
CreationDate => "D:20160210000000+01'00'" | CreationDate => "D:20160210000000+01'00'" | |||
}, | }, | |||
'prepare_output_metadata with tz' | 'prepare_output_metadata with tz' | |||
); | ); | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::prepare_output_metadata( | Gscan2pdf::Document::prepare_output_metadata( | |||
'PDF', | 'PDF', | |||
{ | { | |||
datetime => [ 2016, 2, 10, 19, 59, 5 ], | datetime => [ 2016, 2, 10, 19, 59, 5 ], | |||
tz => [ 0, 0, 0, 1, 0, 0, 0 ], | tz => [ 0, 0, 0, 1, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
} | } | |||
), | ), | |||
{ | { | |||
ModDate => "D:20160210195905+01'00'", | ModDate => "D:20160210195905+01'00'", | |||
Creator => "gscan2pdf v$Gscan2pdf::Document::VERSION", | Creator => "gscan2pdf v$Gscan2pdf::Document::VERSION", | |||
Author => 'a.n.other', | Author => 'a.n.other', | |||
skipping to change at line 299 | skipping to change at line 305 | |||
); | ); | |||
######################### | ######################### | |||
my %settings = ( | my %settings = ( | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
subject => 'subject', | subject => 'subject', | |||
keywords => 'keywords', | keywords => 'keywords', | |||
'datetime offset' => [ 2, 0, 59, 59 ], | 'datetime offset' => [ 2, 0, 59, 59 ], | |||
'timezone offset' => [ 0, 0, 0, 0, 0, 0, 0 ], | 'timezone offset' => [ 0, 0, 0, 0, 0, 0, 0 ], | |||
); | ); | |||
my @today_and_now = ( 2016, 2, 10, 1, 2, 3 ); | my @today_and_now = ( 2016, 2, 10, 1, 2, 3 ); | |||
my @timezone = ( 0, 0, 0, 1, 0, 0, 0 ); | my @timezone = ( 0, 0, 0, 1, 0, 0, 0 ); | |||
my @time = ( 19, 59, 5 ); | my @time = ( 19, 59, 5 ); | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::collate_metadata( | Gscan2pdf::Document::collate_metadata( | |||
\%settings, \@today_and_now, \@timezone | \%settings, \@today_and_now, \@timezone | |||
), | ), | |||
{ | { | |||
datetime => [ 2016, 2, 12, 0, 0, 0 ], | datetime => [ 2016, 2, 12, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
}, | }, | |||
'collate basic metadata' | 'collate basic metadata' | |||
); | ); | |||
$settings{'use_timezone'} = TRUE; | $settings{'use_timezone'} = TRUE; | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::collate_metadata( | Gscan2pdf::Document::collate_metadata( | |||
\%settings, \@today_and_now, \@timezone | \%settings, \@today_and_now, \@timezone | |||
), | ), | |||
{ | { | |||
datetime => [ 2016, 2, 12, 0, 0, 0 ], | datetime => [ 2016, 2, 12, 0, 0, 0 ], | |||
tz => [ 0, 0, 0, 1, 0, 0, 0 ], | tz => [ 0, 0, 0, 1, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
}, | }, | |||
'collate timezone' | 'collate timezone' | |||
); | ); | |||
$settings{'use_time'} = TRUE; | $settings{'use_time'} = TRUE; | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::collate_metadata( | Gscan2pdf::Document::collate_metadata( | |||
\%settings, \@today_and_now, \@timezone | \%settings, \@today_and_now, \@timezone | |||
), | ), | |||
{ | { | |||
datetime => [ 2016, 2, 12, 2, 2, 2 ], | datetime => [ 2016, 2, 12, 2, 2, 2 ], | |||
tz => [ 0, 0, 0, 1, 0, 0, 0 ], | tz => [ 0, 0, 0, 1, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
}, | }, | |||
'collate time' | 'collate time' | |||
); | ); | |||
@today_and_now = ( 2016, 6, 10, 1, 2, 3 ); | @today_and_now = ( 2016, 6, 10, 1, 2, 3 ); | |||
@timezone = ( 0, 0, 0, 2, 0, 0, 1 ); | @timezone = ( 0, 0, 0, 2, 0, 0, 1 ); | |||
$settings{'datetime offset'} = [ -119, 0, 59, 59 ]; | $settings{'datetime offset'} = [ -119, 0, 59, 59 ]; | |||
$settings{'timezone offset'} = [ 0, 0, 0, -1, 0, 0, -1 ]; | $settings{'timezone offset'} = [ 0, 0, 0, -1, 0, 0, -1 ]; | |||
is_deeply( | is_deeply( | |||
Gscan2pdf::Document::collate_metadata( | Gscan2pdf::Document::collate_metadata( | |||
\%settings, \@today_and_now, \@timezone | \%settings, \@today_and_now, \@timezone | |||
), | ), | |||
{ | { | |||
datetime => [ 2016, 2, 12, 2, 2, 2 ], | datetime => [ 2016, 2, 12, 2, 2, 2 ], | |||
tz => [ 0, 0, 0, 1, 0, 0, 0 ], | tz => [ 0, 0, 0, 1, 0, 0, 0 ], | |||
author => 'a.n.other', | author => 'a.n.other', | |||
title => 'title', | title => 'title', | |||
'subject' => 'subject', | 'subject' => 'subject', | |||
'keywords' => 'keywords' | 'keywords' => 'keywords' | |||
}, | }, | |||
'collate dst at time of docdate' | 'collate dst at time of docdate' | |||
); | ); | |||
######################### | ######################### | |||
my @tz1 = ( 0, 0, 0, 2, 0, 0, 1 ); | my @tz1 = ( 0, 0, 0, 2, 0, 0, 1 ); | |||
my @tz_delta = ( 0, 0, 0, -1, 0, 0, -1 ); | my @tz_delta = ( 0, 0, 0, -1, 0, 0, -1 ); | |||
my @tz2 = Gscan2pdf::Document::add_delta_timezone( @tz1, @tz_delta ); | my @tz2 = Gscan2pdf::Document::add_delta_timezone( @tz1, @tz_delta ); | |||
is_deeply \@tz2, [ 0, 0, 0, 1, 0, 0, 0 ], 'Add_Delta_Timezone'; | is_deeply \@tz2, [ 0, 0, 0, 1, 0, 0, 0 ], 'Add_Delta_Timezone'; | |||
@tz_delta = Gscan2pdf::Document::delta_timezone( @tz1, @tz2 ); | @tz_delta = Gscan2pdf::Document::delta_timezone( @tz1, @tz2 ); | |||
is_deeply \@tz_delta, [ 0, 0, 0, -1, 0, 0, -1 ], 'Delta_Timezone'; | is_deeply \@tz_delta, [ 0, 0, 0, -1, 0, 0, -1 ], 'Delta_Timezone'; | |||
# can't test exact result, as depends on timezone of test machine | # can't test exact result, as depends on timezone of test machine | |||
is Gscan2pdf::Document::delta_timezone_to_current( [ 2016, 1, 1, 2, 2, 2 ] ), | is Gscan2pdf::Document::delta_timezone_to_current( [ 2016, 1, 1, 2, 2, 2 ] ), | |||
7, 'delta_timezone_to_current()'; | 7, 'delta_timezone_to_current()'; | |||
is_deeply [ | is_deeply [ | |||
Gscan2pdf::Document::delta_timezone_to_current( [ 1966, 1, 1, 2, 2, 2 ] ) ], | Gscan2pdf::Document::delta_timezone_to_current( [ 1966, 1, 1, 2, 2, 2 ] ) ], | |||
skipping to change at line 459 | skipping to change at line 465 | |||
'_extract_metadata on error 2' | '_extract_metadata on error 2' | |||
); | ); | |||
######################### | ######################### | |||
my $filename = 'test.txt'; | my $filename = 'test.txt'; | |||
system( 'touch', $filename ); | system( 'touch', $filename ); | |||
my %options = ( | my %options = ( | |||
path => $filename, | path => $filename, | |||
options => { set_timestamp => TRUE }, | options => { set_timestamp => TRUE }, | |||
metadata => { datetime => [ 2016, 2, 10, 0, 0, 0 ], } | metadata => { datetime => [ 2016, 2, 10, 0, 0, 0 ], } | |||
); | ); | |||
Gscan2pdf::Document::_set_timestamp( undef, %options ); | Gscan2pdf::Document::_set_timestamp( undef, %options ); | |||
my $sb = stat($filename); | my $sb = stat($filename); | |||
is_deeply [ Time_to_Date( $sb->mtime ) ], [ 2016, 2, 10, 0, 0, 0 ], | is_deeply [ Time_to_Date( $sb->mtime ) ], [ 2016, 2, 10, 0, 0, 0 ], | |||
'timestamp no timezone'; | 'timestamp no timezone'; | |||
$options{metadata}{tz} = [ undef, undef, undef, 14, 0, undef, undef ]; | $options{metadata}{tz} = [ undef, undef, undef, 14, 0, undef, undef ]; | |||
Gscan2pdf::Document::_set_timestamp( undef, %options ); | Gscan2pdf::Document::_set_timestamp( undef, %options ); | |||
$sb = stat($filename); | $sb = stat($filename); | |||
is_deeply [ Time_to_Date( $sb->mtime ) ], [ 2016, 2, 9, 10, 0, 0 ], | is_deeply [ Time_to_Date( $sb->mtime ) ], [ 2016, 2, 9, 10, 0, 0 ], | |||
End of changes. 13 change blocks. | ||||
20 lines changed or deleted | 26 lines changed or added |