--- trunk/t/2-input.t 2006/05/14 09:34:05 483 +++ trunk/t/2-input.t 2006/10/25 17:10:08 761 @@ -1,16 +1,21 @@ #!/usr/bin/perl -w -use Test::More tests => 61; +use Test::More tests => 89; use Test::Exception; use Cwd qw/abs_path/; use blib; use strict; +use Data::Dump qw/dump/; + BEGIN { use_ok( 'WebPAC::Input::ISIS' ); use_ok( 'WebPAC::Input::MARC' ); } +my $debug = shift @ARGV; +my $no_log = $debug ? 0 : 1; + ok(my $abs_path = abs_path($0), "abs_path"); $abs_path =~ s#/[^/]*$#/#; @@ -18,15 +23,39 @@ 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, no_progress_bar => 1 ), "new"); -ok(my $input_lm = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1, no_progress_bar => 1 ), "new $module"); +ok(my $input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1, stats => 1 ), "new $module"); +ok(my $input_lm = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); throws_ok { $input->open( ) } qr/path/, "need path"; throws_ok { $input->open( path => '/dev/null', ) } qr/can't find database/ , "open"; -ok($input->open( path => "$abs_path/winisis/BIBL" ), "open"); -ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "open"); +my $store; + +ok($input->open( path => "$abs_path/winisis/BIBL" ), "open winisis"); +ok($input_lm->open( + path => "$abs_path/winisis/BIBL", + save_row => sub { + my $a = shift; + $store->{ $a->{id} } = $a->{row}; + }, + load_row => sub { + my $a = shift; + return defined($store->{ $a->{id} }) && + $store->{ $a->{id} }; + }, +), "open winisis"); + +cmp_ok( keys %$store, '==', 5, 'have 5 rows'); + +foreach my $i ( 1 .. 5 ) { + ok(my $r = $store->{$i}, "row $i"); + ok($r->{'000'}, "have 000"); + isa_ok($r->{'000'}, 'ARRAY', "is ARRAY"); + cmp_ok($r->{'000'}->[0], '==', $i, 'sane value'); +} + +diag "store = ",dump( $store ) if ($debug); sub test_after_open($) { my $input = shift; @@ -63,7 +92,7 @@ diag "offset $s, limit: $l, expected: $e"; - ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => 1 ), "open"); + ok($s = $input->open( path => "$abs_path/winisis/BIBL", offset => $s, limit => $l, debug => $debug ), "open winisis"); cmp_ok($s, '==', $size, "db size from open = $size"); cmp_ok($input->size, '==', $e, "input->size = $e"); } @@ -73,14 +102,37 @@ test_start_limit($input, 3, $size, $size - 2); test_start_limit($input, 1, $size + 2, $size); +ok(my $s = $input->stats, 'stats'); +diag "stats:\n$s"; + $module = 'WebPAC::Input::MARC'; diag "testing with $module"; -ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => 1, no_progress_bar => 1 ), "new $module"); +ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); -ok($input->open( path => "$abs_path/data/marc.iso" ), "open"); +ok($input->open( path => "$abs_path/data/marc.iso" ), "open marc.iso"); test_after_open($input); test_fetch($input, $input->size); +# test modify_record +$module = 'WebPAC::Input::ISIS'; +ok($input = new WebPAC::Input( module => $module, no_log => $no_log, no_progress_bar => 1 ), "new $module"); + +ok($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)"); +ok(my $rec_p = $input->fetch, 'fetch'); + +ok($input->open( + path => "$abs_path/modify_isis/LIBRI", + modify_records => { + 200 => { + '*' => { '^c' => '. ' }, + } + }, +), "open modify_isis (with modify_records)"); + +ok(my $rec = $input->fetch, 'fetch'); + +cmp_ok($rec_p->{200}->[0]->{f} . '. ' . $rec_p->{200}->[0]->{c}, 'eq' ,$rec->{200}->[0]->{f}, 'modify_records working'); +