More tests added
[dbsrgits/DBM-Deep.git] / t / 18_export.t
CommitLineData
ffed8b01 1##
2# DBM::Deep Test
3##
4use strict;
5use Test::More tests => 2;
2a81bf9e 6use File::Temp qw( tempfile tempdir );
58910373 7use Fcntl qw( :flock );
ffed8b01 8
9use_ok( 'DBM::Deep' );
10
2a81bf9e 11my $dir = tempdir( CLEANUP => 1 );
ffed8b01 12
2a81bf9e 13my $struct;
14{
15 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
58910373 16 flock $fh, LOCK_UN;
2a81bf9e 17 my $db = DBM::Deep->new( $filename );
ffed8b01 18
2a81bf9e 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 );
ffed8b01 31
2a81bf9e 32 ##
33 # Export entire thing
34 ##
35 $struct = $db->export();
36}
ffed8b01 37
38##
39# Make sure everything is here, outside DB
40##
41ok(
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") &&
02776a7e 47 ($struct->{array1}->[2] eq "elem2") &&
48 ($struct->{array1}->[3]{foo} eq "bar") &&
49 ($struct->{array1}->[4][0] eq "5")
ffed8b01 50 ) &&
51 ($struct->{hash1} &&
52 ($struct->{hash1}->{subkey1} eq "subvalue1") &&
53 ($struct->{hash1}->{subkey2} eq "subvalue2")
54 )
55);