Fixing things around
[dbsrgits/DBM-Deep.git] / t / 13_setpack.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 4;
6 use t::common qw( new_fh );
7
8 use_ok( 'DBM::Deep' );
9
10 my ($before, $after);
11
12 {
13     my ($fh, $filename) = new_fh();
14     my $db = DBM::Deep->new(
15         file => $filename,
16         autoflush => 1,
17     );
18     $db->{key1} = "value1";
19     $db->{key2} = "value2";
20     $before = (stat($db->_fh()))[7];
21 }
22
23 {
24     my ($fh, $filename) = new_fh();
25     {
26         my $db = DBM::Deep->new(
27             file => $filename,
28             autoflush => 1,
29             pack_size => 'small',
30         );
31
32         $db->{key1} = "value1";
33         $db->{key2} = "value2";
34         $after = (stat($db->_fh()))[7];
35     }
36
37     # This tests the header to verify that the pack_size is really there
38     {
39         my $db = DBM::Deep->new(
40             file => $filename,
41         );
42
43         is( $db->{key1}, 'value1', 'Can read key1' );
44         is( $db->{key2}, 'value2', 'Can read key2' );
45     }
46 }
47
48 cmp_ok( $after, '<', $before, "The new packsize reduced the size of the file" );