Commit | Line | Data |
ffed8b01 |
1 | use strict; |
0e3e3555 |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::More; |
ffed8b01 |
5 | use Test::Exception; |
fde3db1a |
6 | use t::common qw( new_fh ); |
ffed8b01 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
2120a181 |
10 | { |
11 | my ($fh, $filename) = new_fh(); |
12 | print $fh "Not a DBM::Deep file"; |
13 | |
14 | my $old_fh = select $fh; |
15 | my $old_af = $|; $| = 1; $| = $old_af; |
16 | select $old_fh; |
17 | |
18 | throws_ok { |
19 | my $db = DBM::Deep->new( $filename ); |
20 | } qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened"; |
21 | } |
22 | |
fde3db1a |
23 | my ($fh, $filename) = new_fh(); |
2a81bf9e |
24 | my $db = DBM::Deep->new( $filename ); |
ffed8b01 |
25 | |
26 | $db->{key1} = "value1"; |
27 | is( $db->{key1}, "value1", "Value set correctly" ); |
28 | |
29 | # Testing to verify that the close() will occur if open is called on an open DB. |
a20d9a3f |
30 | #XXX WOW is this hacky ... |
f1879fdc |
31 | $db->_get_self->_engine->storage->open; |
ffed8b01 |
32 | is( $db->{key1}, "value1", "Value still set after re-open" ); |
33 | |
34 | throws_ok { |
35 | my $db = DBM::Deep->new( 't' ); |
d5d7c51d |
36 | } qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch"; |
ffed8b01 |
37 | |
7f441181 |
38 | { |
ebbe4093 |
39 | my $db = DBM::Deep->new( |
2a81bf9e |
40 | file => $filename, |
ebbe4093 |
41 | locking => 1, |
42 | ); |
f1879fdc |
43 | $db->_get_self->_engine->storage->close( $db->_get_self ); |
460b1067 |
44 | ok( !$db->lock, "Calling lock() on a closed database returns false" ); |
ebbe4093 |
45 | } |
46 | |
7f441181 |
47 | { |
ebbe4093 |
48 | my $db = DBM::Deep->new( |
2a81bf9e |
49 | file => $filename, |
ebbe4093 |
50 | locking => 1, |
51 | ); |
52 | $db->lock; |
f1879fdc |
53 | $db->_get_self->_engine->storage->close( $db->_get_self ); |
460b1067 |
54 | ok( !$db->unlock, "Calling unlock() on a closed database returns false" ); |
ebbe4093 |
55 | } |
0e3e3555 |
56 | |
57 | done_testing; |