Fixing things around
[dbsrgits/DBM-Deep.git] / t / 23_misc.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
2a81bf9e 5use Test::More tests => 7;
ffed8b01 6use Test::Exception;
fde3db1a 7use t::common qw( new_fh );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
fde3db1a 11my ($fh, $filename) = new_fh();
2a81bf9e 12my $db = DBM::Deep->new( $filename );
ffed8b01 13
14$db->{key1} = "value1";
15is( $db->{key1}, "value1", "Value set correctly" );
16
17# Testing to verify that the close() will occur if open is called on an open DB.
a20d9a3f 18#XXX WOW is this hacky ...
83371fe3 19$db->_get_self->_storage->open;
ffed8b01 20is( $db->{key1}, "value1", "Value still set after re-open" );
21
22throws_ok {
23 my $db = DBM::Deep->new( 't' );
d5d7c51d 24} qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch";
ffed8b01 25
26throws_ok {
27 my $db = DBM::Deep->new( __FILE__ );
28} qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
ebbe4093 29
7f441181 30{
ebbe4093 31 my $db = DBM::Deep->new(
2a81bf9e 32 file => $filename,
ebbe4093 33 locking => 1,
34 );
83371fe3 35 $db->_get_self->_storage->close( $db->_get_self );
460b1067 36 ok( !$db->lock, "Calling lock() on a closed database returns false" );
ebbe4093 37}
38
7f441181 39{
ebbe4093 40 my $db = DBM::Deep->new(
2a81bf9e 41 file => $filename,
ebbe4093 42 locking => 1,
43 );
44 $db->lock;
83371fe3 45 $db->_get_self->_storage->close( $db->_get_self );
460b1067 46 ok( !$db->unlock, "Calling unlock() on a closed database returns false" );
ebbe4093 47}