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