6 use Test::More tests => 124;
9 use_ok( 'WebPAC::Test' );
10 use_ok( 'WebPAC::Input::ISIS' );
11 use_ok( 'WebPAC::Input::MARC' );
12 use_ok( 'WebPAC::Input::Test' );
15 $LOG{no_progress_bar} = 1;
17 warn "# LOG = ",dump( %LOG );
19 my $module = 'WebPAC::Input::ISIS';
20 diag "testing with $module";
22 throws_ok { my $input = new WebPAC::Input( %LOG ) } qr/module/, "need module";
23 ok(my $input = new WebPAC::Input( module => $module, stats => 1, \%LOG ), "new $module");
24 ok(my $input_lm = new WebPAC::Input( module => $module, \%LOG ), "new $module");
26 throws_ok { $input->open( ) } qr/path/, "need path";
28 throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open";
32 ok($input->open( path => "$abs_path/winisis/BIBL" ), "open winisis");
34 path => "$abs_path/winisis/BIBL",
37 $store->{ $a->{id} } = $a->{row};
41 return defined($store->{ $a->{id} }) &&
46 cmp_ok( keys %$store, '==', 5, 'have 5 rows');
48 foreach my $i ( 1 .. 5 ) {
49 ok(my $r = $store->{$i}, "row $i");
50 ok($r->{'000'}, "have 000");
51 isa_ok($r->{'000'}, 'ARRAY', "is ARRAY");
52 cmp_ok($r->{'000'}->[0], '==', $i, 'sane value');
55 diag "store = ",dump( $store ) if ($debug);
57 sub test_after_open($) {
60 cmp_ok($input->pos, '==', -1, "mfn");
61 ok(my $size = $input->size, "size");
65 test_after_open($input);
66 my $size = test_after_open($input_lm);
69 my ($input, $size) = @_;
73 foreach my $mfn ( 1 ... $size ) {
74 ok(my $rec = $input->fetch, "fetch $mfn");
75 cmp_ok($input->pos, '==', $mfn, "pos $mfn");
77 ok(my $dump = $input->dump_ascii, "dump_ascii $mfn");
78 # XXX test count will help us keep this test in-line :-)
79 ok($rec->{leader}, "leader $mfn") if $rec->{leader};
80 diag $dump if ($debug);
86 my @db1 = test_fetch($input, $size);
87 my @db2 = test_fetch($input_lm, $size);
89 is_deeply(\@db1, \@db2, "seek working");
91 sub test_start_limit($$$$) {
92 my ($input, $s,$l,$e) = @_;
94 diag "offset $s, limit: $l, expected: $e";
96 ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => $debug ), "open winisis");
97 cmp_ok($s, '==', $size, "db size from open = $size");
98 cmp_ok($input->size, '==', $e, "input->size = $e");
101 test_start_limit($input, 1, 3, 3);
102 test_start_limit($input, $size, 3, 0);
103 test_start_limit($input, 3, $size, $size - 2);
104 test_start_limit($input, 1, $size + 2, $size);
106 ok(my $s = $input->stats, "$module stats");
107 diag "stats:\n$s" if ($debug);
109 $module = 'WebPAC::Input::MARC';
110 diag "testing with $module";
112 ok($input = new WebPAC::Input( module => $module, stats => 1, %LOG ), "new $module");
114 ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso");
116 test_after_open($input);
118 test_fetch($input, $input->size);
120 ok(my $s = $input->stats, "$module stats");
122 diag "stats:\n$s" if ($debug);
124 $module = 'WebPAC::Input::Test';
125 ok($input = new WebPAC::Input( module => $module, %LOG ), "new $module");
127 $WebPAC::Input::Test::rec = {
129 { 'a' => '[200 a]', 'b' => '[200 b]', 'c' => '[200 c]', 'f' => '[200 f] test : test' },
132 { 'x' => 'foobar', },
136 $WebPAC::Input::Test::size = 42;
138 ok($input->open( path => "/fake/path", ), "open modify_isis (plain)");
140 cmp_ok($input->size, '==', 42, 'size');
142 ok(my $rec_p = $input->fetch, 'fetch');
147 path => "/another/fake/path",
150 '*' => { '^c' => '. ' },
151 '^f' => { ' : ' => ' / ' },
154 ), "open (with modify_records)");
157 throws_ok { $input->seek } qr/without/, 'seek without position';
158 cmp_ok($input->seek(0), '==', -1, 'seek');
162 my $f = $WebPAC::Input::Test::filter_coderef;
163 ok(ref($f) eq 'CODE', 'filter_coderef');
165 my ($field, $from, $to) = @_;
166 cmp_ok( $f->( $from, $field, 1 ), 'eq', $to, "filter $field |$from| -> |$to|" );
170 '^afoo^cbar^fbing : bong',
171 '^afoo. bar^fbing / bong',
176 my $modify_file = "$abs_path/conf/modify/test.pl";
179 path => "/and/another/fake/path",
180 modify_file => $modify_file,
181 ), "open (with modify_file $modify_file)");
183 diag "regexps = ", dump($input->modify_file_regexps( $modify_file )) if ($debug);
186 '^a foo ; bar = baz : zzz',
187 '^a foo^kbar^dbaz : zzz',
190 # empty subfield removal
193 path => "/another/fake/path",
196 '^a' => { '^e' => ' : ^e' },
199 '^a' => { 'foo' => 'baz' },
202 ), "open (with modify_records for empty subfields)");