Moved find_bucket_list, traverse_index, and get_next_key to Engine
[dbsrgits/DBM-Deep.git] / t / 23_misc.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More;
6 use Test::Exception;
7
8 plan tests => 7;
9
10 use_ok( 'DBM::Deep' );
11
12 unlink "t/test.db";
13 my $db = DBM::Deep->new( "t/test.db" );
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.
19 #XXX WOW is this hacky ...
20 $db->_get_self->{engine}->open( $db->_get_self );
21
22 is( $db->{key1}, "value1", "Value still set after re-open" );
23
24 throws_ok {
25     my $db = DBM::Deep->new( 't' );
26 } qr/^DBM::Deep: Cannot sysopen file: t: /, "Can't open a file we aren't allowed to touch";
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";
31
32 {
33     my $db = DBM::Deep->new(
34         file => 't/test.db',
35         locking => 1,
36     );
37     $db->_get_self->{engine}->close( $db->_get_self );
38     ok( !$db->lock );
39 }
40
41 {
42     my $db = DBM::Deep->new(
43         file => 't/test.db',
44         locking => 1,
45     );
46     $db->lock;
47     $db->_get_self->{engine}->close( $db->_get_self );
48     ok( !$db->unlock );
49 }