6 use Test::More tests => 23;
9 use t::common qw( new_fh );
11 use_ok( 'DBM::Deep' );
14 # test a corrupted file
17 my ($fh, $filename) = new_fh();
19 open FH, ">$filename";
24 DBM::Deep->new( $filename );
25 } qr/DBM::Deep: Pre-1.00 file version found/, "Fail if there's a bad header";
29 my ($fh, $filename) = new_fh();
31 tie %hash, 'DBM::Deep', $filename;
36 tie @array, 'DBM::Deep', $filename;
37 } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie a hash file with an array";
40 DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY )
41 } qr/DBM::Deep: File type mismatch/, "Fail if we try and open a hash file with an array";
45 my ($fh, $filename) = new_fh();
47 tie @array, 'DBM::Deep', $filename;
52 tie %hash, 'DBM::Deep', $filename;
53 } qr/DBM::Deep: File type mismatch/, "Fail if we try and tie an array file with a hash";
56 DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_HASH )
57 } qr/DBM::Deep: File type mismatch/, "Fail if we try and open an array file with a hash";
64 data_sector_size => 32,
67 while ( my ($attr, $floor) = each %floors ) {
69 my ($fh, $filename) = new_fh();
71 my $db = DBM::Deep->new(
75 } qr{Floor of $attr is $floor\. Setting it to $floor from '\Q(undef)\E'},
76 "Warning for $attr => undef is correct";
79 my ($fh, $filename) = new_fh();
81 my $db = DBM::Deep->new(
85 } qr{Floor of $attr is $floor\. Setting it to $floor from ''},
86 "Warning for $attr => '' is correct";
89 my ($fh, $filename) = new_fh();
91 my $db = DBM::Deep->new(
95 } qr{Floor of $attr is $floor\. Setting it to $floor from 'abcd'},
96 "Warning for $attr => 'abcd' is correct";
99 my ($fh, $filename) = new_fh();
100 my $val = $floor - 1;
102 my $db = DBM::Deep->new(
106 } qr{Floor of $attr is $floor\. Setting it to $floor from '$val'},
107 "Warning for $attr => $val is correct";
114 data_sector_size => 256,
117 while ( my ($attr, $ceiling) = each %ceilings ) {
118 my ($fh, $filename) = new_fh();
120 my $db = DBM::Deep->new(
124 } qr{Ceiling of $attr is $ceiling\. Setting it to $ceiling from '1000'},
125 "Warning for $attr => 1000 is correct";
131 DBM::Deep->new( 't/old_versions/db.0.983' );
132 } qr/DBM::Deep: Pre-1.00 file version found/, "Fail if opening a pre-1.00 file";
137 DBM::Deep->new( 't/old_versions/db.0.99_04' );
138 } qr/DBM::Deep: Wrong file version found - 1 - expected 2/, "Fail if opening a file version 1";