/[webpac2]/trunk/t/6-unit.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/t/6-unit.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 491 by dpavlin, Sun May 14 12:39:39 2006 UTC revision 767 by dpavlin, Tue Oct 31 13:44:42 2006 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 41;  use Test::More tests => 31;
6  use Test::Exception;  use Test::Exception;
7  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
8  use File::Temp qw/tempdir/;  use File::Temp qw/tempdir/;
# Line 13  use blib; Line 13  use blib;
13    
14  my $debug = shift @ARGV;  my $debug = shift @ARGV;
15    
16    #
17    # FIXME add lookup testing!
18    #
19    
20  BEGIN {  BEGIN {
 use_ok( 'WebPAC::Lookup' );  
21  use_ok( 'WebPAC::Input' );  use_ok( 'WebPAC::Input' );
22  use_ok( 'WebPAC::Store' );  use_ok( 'WebPAC::Store' );
23  use_ok( 'WebPAC::Normalize::XML' );  use_ok( 'WebPAC::Normalize' );
 use_ok( 'WebPAC::Normalize::Set' );  
24  use_ok( 'WebPAC::Output::TT' );  use_ok( 'WebPAC::Output::TT' );
25  }  }
26    
# Line 28  diag "abs_path: $abs_path" if ($debug); Line 30  diag "abs_path: $abs_path" if ($debug);
30    
31  my $isis_file = "$abs_path../t/winisis/BIBL";  my $isis_file = "$abs_path../t/winisis/BIBL";
32  #$isis_file = '/data/hidra/THS/THS';  #$isis_file = '/data/hidra/THS/THS';
33  $isis_file = '/data/isis_data/ffkk/';  #$isis_file = '/data/isis_data/ffkk/';
34    
35  diag "isis_file: $isis_file" if ($debug);  diag "isis_file: $isis_file" if ($debug);
36    
37  my $normalize_set_pl = "$abs_path/data/normalize.pl";  my $normalize_set_pl = "$abs_path/data/normalize.pl";
38  my $lookup_file = "$abs_path../conf/lookup/isis.pm";  my $lookup_file = "$abs_path../conf/lookup/isis.pm";
39    
 my ($t1,$t2) = (0,0);  
   
 ok(my $lookup = new WebPAC::Lookup(  
         lookup_file => $lookup_file,  
 ), "new Lookup");  
   
40  ok(my $isis = new WebPAC::Input(  ok(my $isis = new WebPAC::Input(
41          module => 'WebPAC::Input::ISIS',          module => 'WebPAC::Input::ISIS',
42          code_page => 'ISO-8859-2',      # application encoding          code_page => 'ISO-8859-2',      # application encoding
# Line 50  ok(my $isis = new WebPAC::Input( Line 46  ok(my $isis = new WebPAC::Input(
46    
47  ok(my $maxmfn = $isis->open(  ok(my $maxmfn = $isis->open(
48          path => $isis_file,          path => $isis_file,
49          code_page => '852',             # database encoding          code_page => 'cp852',           # database encoding
50          lookup => $lookup,          lookup_coderef => sub {
51                    my $rec = shift || return;
52                    ok($rec, 'lookup_coderef has rec');
53                    ok(defined($rec->{'000'}->[0]), 'have mfn');
54            },
55  ), "Input::ISIS->open");  ), "Input::ISIS->open");
56    
57  ok(my $path = tempdir( CLEANUP => 1 ), "path");  ok(my $path = tempdir( CLEANUP => 1 ), "path");
# Line 61  ok(my $db = new WebPAC::Store( Line 61  ok(my $db = new WebPAC::Store(
61          database => '.',          database => '.',
62  ), "new Store");  ), "new Store");
63    
 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");  
   
64  ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );  ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" );
65    
66  ok(my $out = new WebPAC::Output::TT(  ok(my $out = new WebPAC::Output::TT(
# Line 81  ok(my $out = new WebPAC::Output::TT( Line 68  ok(my $out = new WebPAC::Output::TT(
68          filters => { foo => sub { shift } },          filters => { foo => sub { shift } },
69  ), "new Output::TT");  ), "new Output::TT");
70    
71  diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug);  my $t_norm = 0;
72    
73  foreach my $pos ( 0 ... $isis->size ) {  foreach my $pos ( 0 ... $isis->size ) {
74    
# Line 90  foreach my $pos ( 0 ... $isis->size ) { Line 77  foreach my $pos ( 0 ... $isis->size ) {
77          diag " row $pos => ",Dumper($row) if ($debug);          diag " row $pos => ",Dumper($row) if ($debug);
78    
79          my $t = time();          my $t = time();
80          ok(my $ds = $n->data_structure($row), "XML data_structure");          ok( my $ds = WebPAC::Normalize::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,  
81                  row => $row,                  row => $row,
82                  rules => $norm_pl,                  rules => $norm_pl,
83          ), "Set data_structure");          ), "Set data_structure");
84          $t2 += time() - $t;          $t_norm += time() - $t;
85    
86          diag " ds2 $pos => ",Dumper($ds2) if ($debug);          diag " ds $pos => ",Dumper($ds) if ($debug);
         is_deeply( $ds, $ds2, 'ds same for xml and sets');  
87    
88          ok(my $html = $out->apply(          ok(my $html = $out->apply(
89                  template => 'html.tt',                  template => 'html.tt',
# Line 117  foreach my $pos ( 0 ... $isis->size ) { Line 96  foreach my $pos ( 0 ... $isis->size ) {
96    
97  };  };
98    
99  diag sprintf("timings: %.2fs vs %.2fs [%1.2f%%]\n", $t1, $t2, ($t1 / $t2) * 100);  diag sprintf("timings: %.2fs\n", $t_norm);

Legend:
Removed from v.491  
changed lines
  Added in v.767

  ViewVC Help
Powered by ViewVC 1.1.26