From: rkinyon Date: Fri, 7 Apr 2006 01:49:12 +0000 (+0000) Subject: Added a test to make sure that the header really works X-Git-Tag: 0-99_01~31 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9b2370e0391bb968f797bd69a86ec6fa5bdad8ee;p=dbsrgits%2FDBM-Deep.git Added a test to make sure that the header really works --- diff --git a/lib/DBM/Deep/Engine.pm b/lib/DBM/Deep/Engine.pm index 62ee2d7..ba9185e 100644 --- a/lib/DBM/Deep/Engine.pm +++ b/lib/DBM/Deep/Engine.pm @@ -118,15 +118,17 @@ sub read_file_header { ); if ( $bytes_read ) { - my ($signature, $version, @values) = unpack( 'A4 N S A S A S', $buffer ); + my ($signature, $version, @values) = unpack( 'A4 S S A S A S', $buffer ); unless ($signature eq SIG_FILE) { $self->close_fh( $obj ); $obj->_throw_error("Signature not found -- file is not a Deep DB"); } - if ( if @values < 5 || grep { !defined } @values ) { + if ( @values < 5 || grep { !defined } @values ) { die "DBM::Deep: Corrupted file - bad header\n"; } + + #XXX Add warnings if values weren't set right @{$self}{qw( long_size long_pack data_size data_pack max_buckets )} = @values; } diff --git a/t/13_setpack.t b/t/13_setpack.t index 3dbc18f..8f6d2cc 100644 --- a/t/13_setpack.t +++ b/t/13_setpack.t @@ -2,7 +2,7 @@ # DBM::Deep Test ## use strict; -use Test::More tests => 2; +use Test::More tests => 4; use t::common qw( new_fh ); use_ok( 'DBM::Deep' ); @@ -22,15 +22,27 @@ my ($before, $after); { my ($fh, $filename) = new_fh(); - my $db = DBM::Deep->new( - file => $filename, - autoflush => 1, - pack_size => 'small', - ); + { + my $db = DBM::Deep->new( + file => $filename, + autoflush => 1, + pack_size => 'small', + ); - $db->{key1} = "value1"; - $db->{key2} = "value2"; - $after = (stat($db->_fh()))[7]; + $db->{key1} = "value1"; + $db->{key2} = "value2"; + $after = (stat($db->_fh()))[7]; + } + + # This tests the header to verify that the pack_size is really there + { + my $db = DBM::Deep->new( + file => $filename, + ); + + is( $db->{key1}, 'value1', 'Can read key1' ); + is( $db->{key2}, 'value2', 'Can read key2' ); + } } -ok( $after < $before, "The new packsize reduced the size of the file" ); +cmp_ok( $after, '<', $before, "The new packsize reduced the size of the file" );