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