All the tests now pass with the broken out classes
[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,
45f047f8 14 fh => $fh,
888453b9 15 locking => 1,
16 autoflush => 1,
17 num_txns => 16,
18);
19
f1879fdc 20seek $db->_get_self->_engine->storage->{fh}, 0, 0;
45f047f8 21
888453b9 22my $db2 = DBM::Deep->new(
23 file => $filename,
45f047f8 24 fh => $fh,
888453b9 25 locking => 1,
26 autoflush => 1,
27 num_txns => 16,
1cff45d7 28);
29
30$db->{foo} = 5;
31$db->{bar} = $db->{foo};
32
33is( $db->{foo}, 5, "Foo is still 5" );
34is( $db->{bar}, 5, "Bar is now 5" );
35
36$db->{foo} = 6;
37
38is( $db->{foo}, 6, "Foo is now 6" );
39is( $db->{bar}, 5, "Bar is still 5" );
40
41$db->{foo} = [ 1 .. 3 ];
42$db->{bar} = $db->{foo};
43
44is( $db->{foo}[1], 2, "Foo[1] is still 2" );
45is( $db->{bar}[1], 2, "Bar[1] is now 2" );
46
47$db->{foo}[3] = 42;
48
49is( $db->{foo}[3], 42, "Foo[3] is now 42" );
50is( $db->{bar}[3], 42, "Bar[3] is also 42" );
51
52delete $db->{foo};
53is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
888453b9 54
55$db->{foo} = $db->{bar};
56$db2->begin_work;
57
58 delete $db2->{bar};
59 delete $db2->{foo};
60
61 is( $db2->{bar}, undef, "It's deleted in the transaction" );
62 is( $db->{bar}[3], 42, "... but not in the main" );
63
64$db2->rollback;
65
66# Why hasn't this failed!? Is it because stuff isn't getting deleted as expected?
67# I need a test that walks the sectors
68is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
69is( $db2->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
70
71delete $db->{foo};
72
73is( $db->{bar}[3], 42, "After delete Foo, Bar[3] is still 42" );
74
75__END__
76warn "-2\n";
77$db2->begin_work;
78
79warn "-1\n";
80 delete $db2->{bar};
81
82warn "0\n";
83$db2->commit;
84
85warn "1\n";
86ok( !exists $db->{bar}, "After commit, bar is gone" );
87warn "2\n";