5 use Test::More tests => 11;
7 use t::common qw( new_fh );
11 my ($fh, $filename) = new_fh();
13 # Create the datafile to be used
15 my $db = DBM::Deep->new( $filename );
16 $db->{hash} = { foo => [ 'a' .. 'c' ] };
20 open(FILE, $filename) || die("Can't open '$filename' for reading: $!\n");
24 # test if we can open and read a db using its filehandle
26 ok(($db = DBM::Deep->new(fh => *FILE)), "open db in filehandle");
27 ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
30 } qr/Cannot write to a readonly filehandle/,
31 "Can't write to a read-only filehandle";
32 ok( !$db->exists( 'foo' ), "foo doesn't exist" );
34 my $db_obj = $db->_get_self;
35 ok( $db_obj->_root->{inode}, "The inode has been set" );
40 # now the same, but with an offset into the file. Use the database that's
41 # embedded in the test for the DATA filehandle. First, find the database ...
42 open(FILE, "t/28_DATA.t") || die("Can't open t/28_DATA.t\n");
43 while(my $line = <FILE>) {
44 last if($line =~ /^__DATA__/);
46 my $offset = tell(FILE);
50 skip "File header and format changed ... gah!", 5;
51 open(FILE, "t/28_DATA.t");
55 ok(($db = DBM::Deep->new(fh => *FILE, file_offset => $offset)), "open db in filehandle with offset");
57 ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
59 ok( !$db->exists( 'foo' ), "foo doesn't exist yet" );
62 } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
63 ok( !$db->exists( 'foo' ), "foo doesn't exist" );