#!/usr/bin/perl -w
-use Test::More tests => 49;
+use Test::More tests => 61;
use Test::Exception;
use Cwd qw/abs_path/;
use blib;
BEGIN {
use_ok( 'WebPAC::Input::ISIS' );
+use_ok( 'WebPAC::Input::MARC' );
}
ok(my $abs_path = abs_path($0), "abs_path");
$abs_path =~ s#/[^/]*$#/#;
my $module = 'WebPAC::Input::ISIS';
+diag "testing with $module";
throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module";
ok(my $input = new WebPAC::Input( module => $module, no_log => 0 ), "new");
-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 => 1 ), "new $module");
throws_ok { $input->open( ) } qr/path/, "need path";
ok($input->open( path => "$abs_path/winisis/BIBL" ), "open");
ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open");
-cmp_ok($input->pos, '==', -1, "mfn");
+sub test_after_open($) {
+ my $input = shift;
-ok(my $size = $input->size, "size");
+ cmp_ok($input->pos, '==', -1, "mfn");
+ ok(my $size = $input->size, "size");
+ return $size;
+}
-my @db1;
+test_after_open($input);
+my $size = test_after_open($input_lm);
-foreach my $mfn ( 1 ... $size ) {
- ok(my $rec = $input->fetch, "fetch");
- cmp_ok($input->pos, '==', $mfn, "rec $mfn");
- push @db1, $rec;
-}
+sub test_fetch($$) {
+ my ($input, $size) = @_;
+
+ my @db;
-my @db2;
+ foreach my $mfn ( 1 ... $size ) {
+ ok(my $rec = $input->fetch, "fetch $mfn");
+ cmp_ok($input->pos, '==', $mfn, "pos $mfn");
+ push @db, $rec;
+ }
-foreach my $mfn ( 1 ... $size ) {
- ok($input_lm->seek($mfn), "seek");
- ok(my $rec = $input_lm->fetch, "fetch");
- cmp_ok($input_lm->pos, '==', $mfn, "rec $mfn");
- push @db2, $rec;
+ return @db;
}
+my @db1 = test_fetch($input, $size);
+my @db2 = test_fetch($input_lm, $size);
+
is_deeply(\@db1, \@db2, "seek working");
-sub test_start_limit($$$) {
- my ($s,$l,$e) = @_;
+sub test_start_limit($$$$) {
+ my ($input, $s,$l,$e) = @_;
diag "offset $s, limit: $l, expected: $e";
cmp_ok($input->size, '==', $e, "input->size = $e");
}
-test_start_limit(1, 3, 3);
-test_start_limit($size, 3, 0);
-test_start_limit(3, $size, $size - 2);
-test_start_limit(1, $size + 2, $size);
+test_start_limit($input, 1, 3, 3);
+test_start_limit($input, $size, 3, 0);
+test_start_limit($input, 3, $size, $size - 2);
+test_start_limit($input, 1, $size + 2, $size);
+
+$module = 'WebPAC::Input::MARC';
+diag "testing with $module";
+
+ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1 ), "new $module");
+
+ok($input->open( path => "$abs_path/data/marc.iso" ), "open");
+
+test_after_open($input);
+
+test_fetch($input, $input->size);