/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 506 - (hide annotations)
Mon May 15 09:59:05 2006 UTC (18 years ago) by dpavlin
File MIME type: application/x-troff
File size: 2412 byte(s)
 r663@llin:  dpavlin | 2006-05-15 12:02:43 +0200
 added stats gathering

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26