5 use Test::More tests => 13;
6 use File::Temp qw( tempfile tempdir );
7 use Fcntl qw( :flock );
11 my $dir = tempdir( CLEANUP => 1 );
12 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
14 my $db = DBM::Deep->new( $filename );
17 # Create structure in $db
21 subkey1 => "subvalue1",
22 subkey2 => "subvalue2",
25 subkey3 => 'subvalue3',
29 is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
30 is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
32 $db->{copy} = $db->{hash1};
34 is( $db->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
35 is( $db->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );
37 $db->{copy}{subkey1} = "another value";
38 is( $db->{copy}{subkey1}, 'another value', "New value is set correctly" );
39 is( $db->{hash1}{subkey1}, 'another value', "Old value is set to the new one" );
41 is( scalar(keys %{$db->{hash1}}), 2, "Start with 2 keys in the original" );
42 is( scalar(keys %{$db->{copy}}), 2, "Start with 2 keys in the copy" );
44 delete $db->{copy}{subkey2};
46 is( scalar(keys %{$db->{copy}}), 1, "Now only have 1 key in the copy" );
47 is( scalar(keys %{$db->{hash1}}), 1, "... and only 1 key in the original" );
49 $db->{copy} = $db->{hash2};
50 is( $db->{copy}{subkey3}, 'subvalue3', "After the second copy, we're still good" );
54 my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
57 my $db = DBM::Deep->new( $filename2 );
59 $db->{foo} = [ 1 .. 3 ];
60 for ( 0 .. $max_keys ) {
61 $db->{'foo' . $_} = $db->{foo};
66 my $db = DBM::Deep->new( $filename2 );
68 my $base_offset = $db->{foo}->_base_offset;
70 for ( 0 .. $max_keys ) {
72 unless ( $base_offset == $db->{'foo'.$_}->_base_offset ) {
76 is( $count, $max_keys, "We read $count keys" );