r12194@rob-kinyons-computer-2 (orig r10513): rkinyon | 2008-01-10 23:43:55 -0500
[dbsrgits/DBM-Deep.git] / t / 45_references.t
CommitLineData
1cff45d7 1##
2# DBM::Deep Test
3##
4use strict;
888453b9 5use Test::More tests => 15;
1cff45d7 6use Test::Exception;
7use t::common qw( new_fh );
8
9use_ok( 'DBM::Deep' );
10
11my ($fh, $filename) = new_fh();
12my $db = DBM::Deep->new(
888453b9 13 file => $filename,
14 locking => 1,
15 autoflush => 1,
16 num_txns => 16,
17);
18
19my $db2 = DBM::Deep->new(
20 file => $filename,
21 locking => 1,
22 autoflush => 1,
23 num_txns => 16,
1cff45d7 24);
25
26$db->{foo} = 5;
27$db->{bar} = $db->{foo};
28
29is( $db->{foo}, 5, "Foo is still 5" );
30is( $db->{bar}, 5, "Bar is now 5" );
31
32$db->{foo} = 6;
33
34is( $db->{foo}, 6, "Foo is now 6" );
35is( $db->{bar}, 5, "Bar is still 5" );
36
37$db->{foo} = [ 1 .. 3 ];
38$db->{bar} = $db->{foo};
39
40is( $db->{foo}[1], 2, "Foo[1] is still 2" );
41is( $db->{bar}[1], 2, "Bar[1] is now 2" );
42
43$db->{foo}[3] = 42;
44
45is( $db->{foo}[3], 42, "Foo[3] is now 42" );
46is( $db->{bar}[3], 42, "Bar[3] is also 42" );
47
48delete $db->{foo};
49is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
888453b9 50
51$db->{foo} = $db->{bar};
52$db2->begin_work;
53
54 delete $db2->{bar};
55 delete $db2->{foo};
56
57 is( $db2->{bar}, undef, "It's deleted in the transaction" );
58 is( $db->{bar}[3], 42, "... but not in the main" );
59
60$db2->rollback;
61
62# Why hasn't this failed!? Is it because stuff isn't getting deleted as expected?
63# I need a test that walks the sectors
64is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
65is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
66
67delete $db->{foo};
68
69is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
70
71__END__
72warn "-2\n";
73$db2->begin_work;
74
75warn "-1\n";
76 delete $db2->{bar};
77
78warn "0\n";
79$db2->commit;
80
81warn "1\n";
82ok( !exists $db->{bar}, "After commit, bar is gone" );
83warn "2\n";