Added unflocks to all tests so that the tests run on OSX
[dbsrgits/DBM-Deep.git] / t / 19_crossref.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 5;
6 use File::Temp qw( tempfile tempdir );
7 use Fcntl qw( :flock );
8
9 use_ok( 'DBM::Deep' );
10
11 my $dir = tempdir( CLEANUP => 1 );
12 my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
13 flock $fh2, LOCK_UN;
14 my $db2 = DBM::Deep->new( $filename2 );
15
16 {
17     my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
18     flock $fh, LOCK_UN;
19     my $db = DBM::Deep->new( $filename );
20
21     ##
22     # Create structure in $db
23     ##
24     $db->import(
25         hash1 => {
26             subkey1 => "subvalue1",
27             subkey2 => "subvalue2",
28         }
29     );
30     is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" );
31     is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" );
32
33     ##
34     # Cross-ref nested hash accross DB objects
35     ##
36     $db2->{copy} = $db->{hash1};
37 }
38
39 ##
40 # Make sure $db2 has copy of $db's hash structure
41 ##
42 is( $db2->{copy}{subkey1}, 'subvalue1', "Value copied correctly" );
43 is( $db2->{copy}{subkey2}, 'subvalue2', "Value copied correctly" );