--- trunk/t/2-input.t 2006/07/13 13:55:19 599 +++ trunk/t/2-input.t 2006/10/25 17:10:08 761 @@ -1,19 +1,19 @@ #!/usr/bin/perl -w -use Test::More tests => 68; +use Test::More tests => 89; use Test::Exception; use Cwd qw/abs_path/; use blib; use strict; -use Data::Dumper; +use Data::Dump qw/dump/; BEGIN { use_ok( 'WebPAC::Input::ISIS' ); use_ok( 'WebPAC::Input::MARC' ); } -my $debug = 1; +my $debug = shift @ARGV; my $no_log = $debug ? 0 : 1; ok(my $abs_path = abs_path($0), "abs_path"); @@ -23,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 => $no_log, no_progress_bar => 1, stats => 1 ), "new"); -ok(my $input_lm = new WebPAC::Input( module => $module, low_mem => 1, no_log => $no_log, 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"; +my $store; + ok($input->open( path => "$abs_path/winisis/BIBL" ), "open winisis"); -ok($input_lm->open( path => "$abs_path/winisis/BIBL", low_mem => 1 ), "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; @@ -68,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 winisis"); + 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"); } @@ -84,7 +108,7 @@ $module = 'WebPAC::Input::MARC'; diag "testing with $module"; -ok($input = new WebPAC::Input( module => $module, low_mem => 1, no_log => $no_log, 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 marc.iso"); @@ -96,7 +120,7 @@ $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($input->open( path => "$abs_path/modify_isis/LIBRI", ), "open modify_isis (plain)"); ok(my $rec_p = $input->fetch, 'fetch'); ok($input->open( @@ -111,3 +135,4 @@ 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'); +