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