--- trunk/t/6-unit.t 2006/05/14 12:39:39 491 +++ trunk/t/6-unit.t 2008/08/02 23:46:41 1100 @@ -2,23 +2,25 @@ use strict; -use Test::More tests => 41; +use Test::More tests => 31; use Test::Exception; use Cwd qw/abs_path/; use File::Temp qw/tempdir/; use File::Slurp; -use Data::Dumper; +use Data::Dump qw/dump/; use Time::HiRes qw/time/; use blib; my $debug = shift @ARGV; +# +# FIXME add lookup testing! +# + BEGIN { -use_ok( 'WebPAC::Lookup' ); use_ok( 'WebPAC::Input' ); use_ok( 'WebPAC::Store' ); -use_ok( 'WebPAC::Normalize::XML' ); -use_ok( 'WebPAC::Normalize::Set' ); +use_ok( 'WebPAC::Normalize' ); use_ok( 'WebPAC::Output::TT' ); } @@ -28,51 +30,34 @@ my $isis_file = "$abs_path../t/winisis/BIBL"; #$isis_file = '/data/hidra/THS/THS'; -$isis_file = '/data/isis_data/ffkk/'; +#$isis_file = '/data/isis_data/ffkk/'; diag "isis_file: $isis_file" if ($debug); my $normalize_set_pl = "$abs_path/data/normalize.pl"; my $lookup_file = "$abs_path../conf/lookup/isis.pm"; -my ($t1,$t2) = (0,0); - -ok(my $lookup = new WebPAC::Lookup( - lookup_file => $lookup_file, -), "new Lookup"); - ok(my $isis = new WebPAC::Input( module => 'WebPAC::Input::ISIS', - code_page => 'ISO-8859-2', # application encoding limit => 100, no_progress_bar => 1, ), "new Input::ISIS"); ok(my $maxmfn = $isis->open( path => $isis_file, - code_page => '852', # database encoding - lookup => $lookup, + input_encoding => 'cp852', # database encoding + lookup_coderef => sub { + my $rec = shift || return; + ok($rec, 'lookup_coderef has rec'); + ok(defined($rec->{'000'}->[0]), 'have mfn'); + }, ), "Input::ISIS->open"); ok(my $path = tempdir( CLEANUP => 1 ), "path"); -ok(my $db = new WebPAC::Store( - path => $path, +ok(my $db = new WebPAC::Store({ database => '.', -), "new Store"); - -ok(my $n = new WebPAC::Normalize::XML( -# filter => { 'foo' => sub { shift } }, - db => $db, - lookup_regex => $lookup->regex, - lookup => $lookup, - no_progress_bar => 1, -), "new Normalize::XML"); - -ok($n->open( - tag => 'isis', - xml_file => "$abs_path/data/normalize.xml", -), "Normalize::XML->open"); +}), "new Store"); ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); @@ -81,30 +66,22 @@ filters => { foo => sub { shift } }, ), "new Output::TT"); -diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug); +my $t_norm = 0; foreach my $pos ( 0 ... $isis->size ) { my $row = $isis->fetch || next; - diag " row $pos => ",Dumper($row) if ($debug); + diag " row $pos => ",dump($row) if ($debug); my $t = time(); - ok(my $ds = $n->data_structure($row), "XML data_structure"); - $t1 += time() - $t; - - diag " ds $pos => ",Dumper($ds) if ($debug); - - $t = time(); - ok( my $ds2 = WebPAC::Normalize::Set::data_structure( - lookup => $lookup->lookup_hash, + ok( my $ds = WebPAC::Normalize::data_structure( row => $row, rules => $norm_pl, ), "Set data_structure"); - $t2 += time() - $t; + $t_norm += time() - $t; - diag " ds2 $pos => ",Dumper($ds2) if ($debug); - is_deeply( $ds, $ds2, 'ds same for xml and sets'); + diag " ds $pos => ",dump($ds) if ($debug); ok(my $html = $out->apply( template => 'html.tt', @@ -117,4 +94,4 @@ }; -diag sprintf("timings: %.2fs vs %.2fs [%1.2f%%]\n", $t1, $t2, ($t1 / $t2) * 100); +diag sprintf("timings: %.2fs\n", $t_norm);