Added unflocks to all tests so that the tests run on OSX
[dbsrgits/DBM-Deep.git] / t / 18_export.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 2;
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
13 my $struct;
14 {
15     my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
16     flock $fh, LOCK_UN;
17     my $db = DBM::Deep->new( $filename );
18
19     ##
20     # Create structure in DB
21     ##
22     $db->import(
23         key1 => "value1",
24         key2 => "value2",
25         array1 => [ "elem0", "elem1", "elem2", { foo => 'bar' }, [ 5 ] ],
26         hash1 => {
27             subkey1 => "subvalue1",
28             subkey2 => "subvalue2",
29         }
30     );
31
32     ##
33     # Export entire thing
34     ##
35     $struct = $db->export();
36 }
37
38 ##
39 # Make sure everything is here, outside DB
40 ##
41 ok(
42         ($struct->{key1} eq "value1") && 
43         ($struct->{key2} eq "value2") && 
44         ($struct->{array1} && 
45                 ($struct->{array1}->[0] eq "elem0") &&
46                 ($struct->{array1}->[1] eq "elem1") && 
47                 ($struct->{array1}->[2] eq "elem2") &&
48                 ($struct->{array1}->[3]{foo} eq "bar") &&
49                 ($struct->{array1}->[4][0] eq "5")
50         ) && 
51         ($struct->{hash1} &&
52                 ($struct->{hash1}->{subkey1} eq "subvalue1") && 
53                 ($struct->{hash1}->{subkey2} eq "subvalue2")
54         )
55 );