1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
use Test::More tests => 49; |
use Test::More tests => 68; |
4 |
use Test::Exception; |
use Test::Exception; |
5 |
use Cwd qw/abs_path/; |
use Cwd qw/abs_path/; |
6 |
use blib; |
use blib; |
7 |
use strict; |
use strict; |
8 |
|
|
9 |
|
use Data::Dumper; |
10 |
|
|
11 |
BEGIN { |
BEGIN { |
12 |
use_ok( 'WebPAC::Input::ISIS' ); |
use_ok( 'WebPAC::Input::ISIS' ); |
13 |
|
use_ok( 'WebPAC::Input::MARC' ); |
14 |
} |
} |
15 |
|
|
16 |
|
my $debug = 1; |
17 |
|
my $no_log = $debug ? 0 : 1; |
18 |
|
|
19 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
20 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
21 |
|
|
22 |
my $module = 'WebPAC::Input::ISIS'; |
my $module = 'WebPAC::Input::ISIS'; |
23 |
|
diag "testing with $module"; |
24 |
|
|
25 |
throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module"; |
throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module"; |
26 |
ok(my $input = new WebPAC::Input( module => $module, no_log => 0 ), "new"); |
ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new"); |
27 |
ok(my $input_lm = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1 ), "new"); |
ok(my $input_lm = new WebPAC::Input( module => $module, low_mem => 1, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
28 |
|
|
29 |
throws_ok { $input->open( ) } qr/path/, "need path"; |
throws_ok { $input->open( ) } qr/path/, "need path"; |
30 |
|
|
31 |
throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open"; |
throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open"; |
32 |
|
|
33 |
ok($input->open( path => "$abs_path/winisis/BIBL" ), "open"); |
ok($input->open( path => "$abs_path/winisis/BIBL" ), "open winisis"); |
34 |
ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open"); |
ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open winisis"); |
35 |
|
|
36 |
cmp_ok($input->pos, '==', -1, "mfn"); |
sub test_after_open($) { |
37 |
|
my $input = shift; |
38 |
|
|
39 |
ok(my $size = $input->size, "size"); |
cmp_ok($input->pos, '==', -1, "mfn"); |
40 |
|
ok(my $size = $input->size, "size"); |
41 |
|
return $size; |
42 |
|
} |
43 |
|
|
44 |
my @db1; |
test_after_open($input); |
45 |
|
my $size = test_after_open($input_lm); |
46 |
|
|
47 |
foreach my $mfn ( 1 ... $size ) { |
sub test_fetch($$) { |
48 |
ok(my $rec = $input->fetch, "fetch"); |
my ($input, $size) = @_; |
|
cmp_ok($input->pos, '==', $mfn, "rec $mfn"); |
|
|
push @db1, $rec; |
|
|
} |
|
49 |
|
|
50 |
my @db2; |
my @db; |
51 |
|
|
52 |
foreach my $mfn ( 1 ... $size ) { |
foreach my $mfn ( 1 ... $size ) { |
53 |
ok($input_lm->seek($mfn), "seek"); |
ok(my $rec = $input->fetch, "fetch $mfn"); |
54 |
ok(my $rec = $input_lm->fetch, "fetch"); |
cmp_ok($input->pos, '==', $mfn, "pos $mfn"); |
55 |
cmp_ok($input_lm->pos, '==', $mfn, "rec $mfn"); |
push @db, $rec; |
56 |
push @db2, $rec; |
} |
57 |
|
|
58 |
|
return @db; |
59 |
} |
} |
60 |
|
|
61 |
|
my @db1 = test_fetch($input, $size); |
62 |
|
my @db2 = test_fetch($input_lm, $size); |
63 |
|
|
64 |
is_deeply(\@db1, \@db2, "seek working"); |
is_deeply(\@db1, \@db2, "seek working"); |
65 |
|
|
66 |
sub test_start_limit($$$) { |
sub test_start_limit($$$$) { |
67 |
my ($s,$l,$e) = @_; |
my ($input, $s,$l,$e) = @_; |
68 |
|
|
69 |
diag "offset $s, limit: $l, expected: $e"; |
diag "offset $s, limit: $l, expected: $e"; |
70 |
|
|
71 |
ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => 1 ), "open"); |
ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => 1 ), "open winisis"); |
72 |
cmp_ok($s, '==', $size, "db size from open = $size"); |
cmp_ok($s, '==', $size, "db size from open = $size"); |
73 |
cmp_ok($input->size, '==', $e, "input->size = $e"); |
cmp_ok($input->size, '==', $e, "input->size = $e"); |
74 |
} |
} |
75 |
|
|
76 |
test_start_limit(1, 3, 3); |
test_start_limit($input, 1, 3, 3); |
77 |
test_start_limit($size, 3, 0); |
test_start_limit($input, $size, 3, 0); |
78 |
test_start_limit(3, $size, $size - 2); |
test_start_limit($input, 3, $size, $size - 2); |
79 |
test_start_limit(1, $size + 2, $size); |
test_start_limit($input, 1, $size + 2, $size); |
80 |
|
|
81 |
|
ok(my $s = $input->stats, 'stats'); |
82 |
|
diag "stats:\n$s"; |
83 |
|
|
84 |
|
$module = 'WebPAC::Input::MARC'; |
85 |
|
diag "testing with $module"; |
86 |
|
|
87 |
|
ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
88 |
|
|
89 |
|
ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso"); |
90 |
|
|
91 |
|
test_after_open($input); |
92 |
|
|
93 |
|
test_fetch($input, $input->size); |
94 |
|
|
95 |
|
# test modify_record |
96 |
|
$module = 'WebPAC::Input::ISIS'; |
97 |
|
ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); |
98 |
|
|
99 |
|
ok($input->open( path => "$abs_path/modify_isis/LIBRI",), "open modify_isis (plain)"); |
100 |
|
ok(my $rec_p = $input->fetch, 'fetch'); |
101 |
|
|
102 |
|
ok($input->open( |
103 |
|
path => "$abs_path/modify_isis/LIBRI", |
104 |
|
modify_records => { |
105 |
|
200 => { |
106 |
|
'*' => { '^c' => '. ' }, |
107 |
|
} |
108 |
|
}, |
109 |
|
), "open modify_isis (with modify_records)"); |
110 |
|
|
111 |
|
ok(my $rec = $input->fetch, 'fetch'); |
112 |
|
|
113 |
|
cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working'); |