1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use Test::More tests => 49; |
4 |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
6 |
use blib; |
7 |
use strict; |
8 |
|
9 |
BEGIN { |
10 |
use_ok( 'WebPAC::Input::ISIS' ); |
11 |
} |
12 |
|
13 |
ok(my $abs_path = abs_path($0), "abs_path"); |
14 |
$abs_path =~ s#/[^/]*$#/#; |
15 |
|
16 |
my $module = 'WebPAC::Input::ISIS'; |
17 |
|
18 |
throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module"; |
19 |
ok(my $input = new WebPAC::Input( module => $module, no_log => 0 ), "new"); |
20 |
ok(my $input_lm = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1 ), "new"); |
21 |
|
22 |
throws_ok { $input->open( ) } qr/path/, "need path"; |
23 |
|
24 |
throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open"; |
25 |
|
26 |
ok($input->open( path => "$abs_path/winisis/BIBL" ), "open"); |
27 |
ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open"); |
28 |
|
29 |
cmp_ok($input->pos, '==', -1, "mfn"); |
30 |
|
31 |
ok(my $size = $input->size, "size"); |
32 |
|
33 |
my @db1; |
34 |
|
35 |
foreach my $mfn ( 1 ... $size ) { |
36 |
ok(my $rec = $input->fetch, "fetch"); |
37 |
cmp_ok($input->pos, '==', $mfn, "rec $mfn"); |
38 |
push @db1, $rec; |
39 |
} |
40 |
|
41 |
my @db2; |
42 |
|
43 |
foreach my $mfn ( 1 ... $size ) { |
44 |
ok($input_lm->seek($mfn), "seek"); |
45 |
ok(my $rec = $input_lm->fetch, "fetch"); |
46 |
cmp_ok($input_lm->pos, '==', $mfn, "rec $mfn"); |
47 |
push @db2, $rec; |
48 |
} |
49 |
|
50 |
is_deeply(\@db1, \@db2, "seek working"); |
51 |
|
52 |
sub test_start_limit($$$) { |
53 |
my ($s,$l,$e) = @_; |
54 |
|
55 |
diag "offset $s, limit: $l, expected: $e"; |
56 |
|
57 |
ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => 1 ), "open"); |
58 |
cmp_ok($s, '==', $size, "db size from open = $size"); |
59 |
cmp_ok($input->size, '==', $e, "input->size = $e"); |
60 |
} |
61 |
|
62 |
test_start_limit(1, 3, 3); |
63 |
test_start_limit($size, 3, 0); |
64 |
test_start_limit(3, $size, $size - 2); |
65 |
test_start_limit(1, $size + 2, $size); |
66 |
|