X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=t%2F6-unit.t;h=a9a69359d80a0c1ab18bcb536266278092a6fe37;hb=5afbb46eafaaf540446794c65776142055397484;hp=dc1431b7a073b8564fdaa14317b958bc43afcf22;hpb=1de01d69fc6ac0ecdadf814e7ac653302af3e15f;p=webpac2 diff --git a/t/6-unit.t b/t/6-unit.t index dc1431b..a9a6935 100755 --- a/t/6-unit.t +++ b/t/6-unit.t @@ -2,22 +2,25 @@ use strict; -use Test::More tests => 66; +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' ); } @@ -26,47 +29,35 @@ $abs_path =~ s#/[^/]*$#/#; diag "abs_path: $abs_path" if ($debug); my $isis_file = "$abs_path../t/winisis/BIBL"; -$isis_file = '/data/hidra/THS/THS'; +#$isis_file = '/data/hidra/THS/THS'; +#$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"; -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 => 10, + 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, -), "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" ); @@ -75,29 +66,22 @@ ok(my $out = new WebPAC::Output::TT( filters => { foo => sub { shift } }, ), "new Output::TT"); -while (my $row = $isis->fetch) { +my $t_norm = 0; - diag " row => ",Dumper($row) if ($debug); - set_rec( $row ); +foreach my $pos ( 0 ... $isis->size ) { - ok(my $ds = $n->data_structure($row), "data_structure"); + my $row = $isis->fetch || next; - diag " ds => ",Dumper($ds) if ($debug); + diag " row $pos => ",dump($row) if ($debug); - # TODO move somewhere - { - no strict 'subs'; - use WebPAC::Normalize::Set; - diag " lookup => ",Dumper($lookup) if ($debug); - set_lookup( $lookup->lookup_hash ); - clean_ds(); - eval "$norm_pl"; - ok(! $@, $@ ? "error: $@" : "no error"); - ok(my $ds2 = get_ds(), "get_ds"); - is_deeply( $ds, $ds2, 'ds same for xml and sets'); + my $t = time(); + ok( my $ds = WebPAC::Normalize::data_structure( + row => $row, + rules => $norm_pl, + ), "Set data_structure"); + $t_norm += time() - $t; - diag " ds2 => ",Dumper($ds2) if ($debug); - } + diag " ds $pos => ",dump($ds) if ($debug); ok(my $html = $out->apply( template => 'html.tt', @@ -109,3 +93,5 @@ while (my $row = $isis->fetch) { #diag $html; }; + +diag sprintf("timings: %.2fs\n", $t_norm);