Rename of Scalar -> Ref
[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;
2a81bf9e 7use File::Temp qw( tempfile tempdir );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
2a81bf9e 11my $dir = tempdir( CLEANUP => 1 );
12my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
13my $db = DBM::Deep->new( $filename );
ffed8b01 14
15$db->{key1} = "value1";
16is( $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 21is( $db->{key1}, "value1", "Value still set after re-open" );
22
23throws_ok {
24 my $db = DBM::Deep->new( 't' );
d5d7c51d 25} qr/^DBM::Deep: Cannot sysopen file 't': /, "Can't open a file we aren't allowed to touch";
ffed8b01 26
27throws_ok {
28 my $db = DBM::Deep->new( __FILE__ );
29} qr/^DBM::Deep: Signature not found -- file is not a Deep DB/, "Only DBM::Deep DB files will be opened";
ebbe4093 30
7f441181 31{
ebbe4093 32 my $db = DBM::Deep->new(
2a81bf9e 33 file => $filename,
ebbe4093 34 locking => 1,
35 );
3d1b8be9 36 $db->_get_self->{engine}->close_fh( $db->_get_self );
ebbe4093 37 ok( !$db->lock );
38}
39
7f441181 40{
ebbe4093 41 my $db = DBM::Deep->new(
2a81bf9e 42 file => $filename,
ebbe4093 43 locking => 1,
44 );
45 $db->lock;
3d1b8be9 46 $db->_get_self->{engine}->close_fh( $db->_get_self );
ebbe4093 47 ok( !$db->unlock );
48}