Hand-applied patch from David Cantrell to add file_offset to allow use of DATA filehandle
[dbsrgits/DBM-Deep.git] / t / 27_filehandle.t
1 ##
2 # DBM::Deep Test
3 ##
4 use strict;
5 use Test::More tests => 4;
6
7 use DBM::Deep;
8
9 open(FILE, "t/27_filehandle.t.db") || die("Can't open t/27_filehandle.t.db\n");
10
11 my $db;
12
13 # test if we can open and read a db using its filehandle
14
15 ok(($db = DBM::Deep->new(fh => *FILE)), "open db in filehandle");
16 ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
17
18 undef $db;
19 close(FILE);
20
21 # now the same, but with an offset into the file.  Use the database that's
22 # embedded in the test for the DATA filehandle.  First, find the database ...
23 open(FILE, "t/28_DATA.t") || die("Can't open t/28_DATA.t\n");
24 while(my $line = <FILE>) {
25     last if($line =~ /^__DATA__/);
26 }
27 my $offset = tell(FILE);
28 close(FILE);
29
30 open(FILE, "t/28_DATA.t");
31 ok(($db = DBM::Deep->new(fh => *FILE, file_offset => $offset)), "open db in filehandle with offset");
32 ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
33