Commit | Line | Data |
714618f0 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
70b55428 |
5 | use Test::More tests => 10; |
acd4faf2 |
6 | use Test::Exception; |
714618f0 |
7 | |
8 | use DBM::Deep; |
9 | |
70b55428 |
10 | { |
11 | open(FILE, "t/27_filehandle.t.db") || die("Can't open t/27_filehandle.t.db\n"); |
714618f0 |
12 | |
70b55428 |
13 | my $db; |
714618f0 |
14 | |
70b55428 |
15 | # test if we can open and read a db using its filehandle |
714618f0 |
16 | |
70b55428 |
17 | ok(($db = DBM::Deep->new(fh => *FILE)), "open db in filehandle"); |
18 | ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database"); |
19 | throws_ok { |
20 | $db->{foo} = 1; |
21 | } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle"; |
22 | ok( !$db->exists( 'foo' ), "foo doesn't exist" ); |
714618f0 |
23 | |
70b55428 |
24 | my $db_obj = $db->_get_self; |
25 | ok( $db_obj->_root->{inode}, "The inode has been set" ); |
26 | |
27 | close(FILE); |
28 | } |
714618f0 |
29 | |
30 | # now the same, but with an offset into the file. Use the database that's |
31 | # embedded in the test for the DATA filehandle. First, find the database ... |
32 | open(FILE, "t/28_DATA.t") || die("Can't open t/28_DATA.t\n"); |
33 | while(my $line = <FILE>) { |
34 | last if($line =~ /^__DATA__/); |
35 | } |
36 | my $offset = tell(FILE); |
37 | close(FILE); |
38 | |
70b55428 |
39 | { |
40 | open(FILE, "t/28_DATA.t"); |
41 | |
42 | my $db; |
714618f0 |
43 | |
70b55428 |
44 | ok(($db = DBM::Deep->new(fh => *FILE, file_offset => $offset)), "open db in filehandle with offset"); |
45 | |
46 | ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database"); |
47 | |
48 | ok( !$db->exists( 'foo' ), "foo doesn't exist yet" ); |
49 | throws_ok { |
50 | $db->{foo} = 1; |
51 | } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle"; |
52 | ok( !$db->exists( 'foo' ), "foo doesn't exist" ); |
53 | |
54 | close FILE; |
55 | } |