Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
2a81bf9e |
5 | use Test::More tests => 7; |
ffed8b01 |
6 | use Test::Exception; |
2a81bf9e |
7 | use File::Temp qw( tempfile tempdir ); |
58910373 |
8 | use Fcntl qw( :flock ); |
ffed8b01 |
9 | |
10 | use_ok( 'DBM::Deep' ); |
11 | |
2a81bf9e |
12 | my $dir = tempdir( CLEANUP => 1 ); |
13 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
58910373 |
14 | flock $fh, LOCK_UN; |
2a81bf9e |
15 | my $db = DBM::Deep->new( $filename ); |
ffed8b01 |
16 | |
17 | $db->{key1} = "value1"; |
18 | is( $db->{key1}, "value1", "Value set correctly" ); |
19 | |
20 | # Testing to verify that the close() will occur if open is called on an open DB. |
a20d9a3f |
21 | #XXX WOW is this hacky ... |
22 | $db->_get_self->{engine}->open( $db->_get_self ); |
ffed8b01 |
23 | is( $db->{key1}, "value1", "Value still set after re-open" ); |
24 | |
25 | throws_ok { |
26 | my $db = DBM::Deep->new( 't' ); |
d5d7c51d |
27 | } qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch"; |
ffed8b01 |
28 | |
29 | throws_ok { |
30 | my $db = DBM::Deep->new( __FILE__ ); |
31 | } qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened"; |
ebbe4093 |
32 | |
7f441181 |
33 | { |
ebbe4093 |
34 | my $db = DBM::Deep->new( |
2a81bf9e |
35 | file => $filename, |
ebbe4093 |
36 | locking => 1, |
37 | ); |
3d1b8be9 |
38 | $db->_get_self->{engine}->close_fh( $db->_get_self ); |
ebbe4093 |
39 | ok( !$db->lock ); |
40 | } |
41 | |
7f441181 |
42 | { |
ebbe4093 |
43 | my $db = DBM::Deep->new( |
2a81bf9e |
44 | file => $filename, |
ebbe4093 |
45 | locking => 1, |
46 | ); |
47 | $db->lock; |
3d1b8be9 |
48 | $db->_get_self->{engine}->close_fh( $db->_get_self ); |
ebbe4093 |
49 | ok( !$db->unlock ); |
50 | } |