/[webpac2]/trunk/t/2-input.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/2-input.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 286 by dpavlin, Sun Dec 18 21:06:46 2005 UTC revision 290 by dpavlin, Sun Dec 18 23:10:02 2005 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use Test::More tests => 49;  use Test::More tests => 61;
4  use Test::Exception;  use Test::Exception;
5  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
6  use blib;  use blib;
# Line 8  use strict; Line 8  use strict;
8    
9  BEGIN {  BEGIN {
10  use_ok( 'WebPAC::Input::ISIS' );  use_ok( 'WebPAC::Input::ISIS' );
11    use_ok( 'WebPAC::Input::MARC' );
12  }  }
13    
14  ok(my $abs_path = abs_path($0), "abs_path");  ok(my $abs_path = abs_path($0), "abs_path");
15  $abs_path =~ s#/[^/]*$#/#;  $abs_path =~ s#/[^/]*$#/#;
16    
17  my $module = 'WebPAC::Input::ISIS';  my $module = 'WebPAC::Input::ISIS';
18    diag "testing with $module";
19    
20  throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module";  throws_ok { my $input = new WebPAC::Input( ) } qr/module/, "need module";
21  ok(my $input = new WebPAC::Input( module => $module, no_log => 0 ), "new");  ok(my $input = new WebPAC::Input( module => $module, no_log => 0 ), "new");
22  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");
23    
24  throws_ok { $input->open( ) } qr/path/, "need path";  throws_ok { $input->open( ) } qr/path/, "need path";
25    
# Line 26  throws_ok { $input->open( path => '/dev/ Line 28  throws_ok { $input->open( path => '/dev/
28  ok($input->open( path => "$abs_path/winisis/BIBL" ), "open");  ok($input->open( path => "$abs_path/winisis/BIBL" ), "open");
29  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");
30    
31  cmp_ok($input->pos, '==', -1, "mfn");  sub test_after_open($) {
32            my $input = shift;
33    
34  ok(my $size = $input->size, "size");          cmp_ok($input->pos, '==', -1, "mfn");
35            ok(my $size = $input->size, "size");
36            return $size;
37    }
38    
39  my @db1;  test_after_open($input);
40    my $size = test_after_open($input_lm);
41    
42  foreach my $mfn ( 1 ... $size ) {  sub test_fetch($$) {
43          ok(my $rec = $input->fetch, "fetch");          my ($input, $size) = @_;
44          cmp_ok($input->pos, '==', $mfn, "rec $mfn");  
45          push @db1, $rec;          my @db;
 }  
46    
47  my @db2;          foreach my $mfn ( 1 ... $size ) {
48                    ok(my $rec = $input->fetch, "fetch $mfn");
49                    cmp_ok($input->pos, '==', $mfn, "pos $mfn");
50                    push @db, $rec;
51            }
52    
53  foreach my $mfn ( 1 ... $size ) {          return @db;
         ok($input_lm->seek($mfn), "seek");  
         ok(my $rec = $input_lm->fetch, "fetch");  
         cmp_ok($input_lm->pos, '==', $mfn, "rec $mfn");  
         push @db2, $rec;  
54  }  }
55    
56    my @db1 = test_fetch($input, $size);
57    my @db2 = test_fetch($input_lm, $size);
58    
59  is_deeply(\@db1, \@db2, "seek working");  is_deeply(\@db1, \@db2, "seek working");
60    
61  sub test_start_limit($$$) {  sub test_start_limit($$$$) {
62          my ($s,$l,$e) = @_;          my ($input, $s,$l,$e) = @_;
63    
64          diag "offset $s, limit: $l, expected: $e";          diag "offset $s, limit: $l, expected: $e";
65    
# Line 59  sub test_start_limit($$$) { Line 68  sub test_start_limit($$$) {
68          cmp_ok($input->size, '==', $e, "input->size = $e");          cmp_ok($input->size, '==', $e, "input->size = $e");
69  }  }
70    
71  test_start_limit(1, 3, 3);  test_start_limit($input, 1, 3, 3);
72  test_start_limit($size, 3, 0);  test_start_limit($input, $size, 3, 0);
73  test_start_limit(3, $size, $size - 2);  test_start_limit($input, 3, $size, $size - 2);
74  test_start_limit(1, $size + 2, $size);  test_start_limit($input, 1, $size + 2, $size);
75    
76    $module = 'WebPAC::Input::MARC';
77    diag "testing with $module";
78    
79    ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1 ), "new $module");
80    
81    ok($input->open( path => "$abs_path/data/marc.iso" ), "open");
82    
83    test_after_open($input);
84    
85    test_fetch($input, $input->size);
86    

Legend:
Removed from v.286  
changed lines
  Added in v.290

  ViewVC Help
Powered by ViewVC 1.1.26