3 use Test::More tests => 68;
12 use_ok( 'WebPAC::Input::ISIS' );
13 use_ok( 'WebPAC::Input::MARC' );
17 my $no_log = $debug ? 0 : 1;
19 ok(my $abs_path = abs_path($0), "abs_path");
20 $abs_path =~ s#/[^/]*$#/#;
22 my $module = 'WebPAC::Input::ISIS';
23 diag "testing with $module";
25 throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module";
26 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 => $no_log, no_progress_bar => 1 ), "new $module");
29 throws_ok { $input->open( ) } qr/path/, "need path";
31 throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open";
33 ok($input->open( path => "$abs_path/winisis/BIBL" ), "open winisis");
34 ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open winisis");
36 sub test_after_open($) {
39 cmp_ok($input->pos, '==', -1, "mfn");
40 ok(my $size = $input->size, "size");
44 test_after_open($input);
45 my $size = test_after_open($input_lm);
48 my ($input, $size) = @_;
52 foreach my $mfn ( 1 ... $size ) {
53 ok(my $rec = $input->fetch, "fetch $mfn");
54 cmp_ok($input->pos, '==', $mfn, "pos $mfn");
61 my @db1 = test_fetch($input, $size);
62 my @db2 = test_fetch($input_lm, $size);
64 is_deeply(\@db1, \@db2, "seek working");
66 sub test_start_limit($$$$) {
67 my ($input, $s,$l,$e) = @_;
69 diag "offset $s, limit: $l, expected: $e";
71 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");
73 cmp_ok($input->size, '==', $e, "input->size = $e");
76 test_start_limit($input, 1, 3, 3);
77 test_start_limit($input, $size, 3, 0);
78 test_start_limit($input, 3, $size, $size - 2);
79 test_start_limit($input, 1, $size + 2, $size);
81 ok(my $s = $input->stats, 'stats');
84 $module = 'WebPAC::Input::MARC';
85 diag "testing with $module";
87 ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => $no_log, no_progress_bar => 1 ), "new $module");
89 ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso");
91 test_after_open($input);
93 test_fetch($input, $input->size);
96 $module = 'WebPAC::Input::ISIS';
97 ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module");
99 ok($input->open( path => "$abs_path/modify_isis/LIBRI",), "open modify_isis (plain)");
100 ok(my $rec_p = $input->fetch, 'fetch');
103 path => "$abs_path/modify_isis/LIBRI",
106 '*' => { '^c' => '. ' },
109 ), "open modify_isis (with modify_records)");
111 ok(my $rec = $input->fetch, 'fetch');
113 cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working');