2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 41; |
use Test::More tests => 24; |
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/; |
17 |
use_ok( 'WebPAC::Lookup' ); |
use_ok( 'WebPAC::Lookup' ); |
18 |
use_ok( 'WebPAC::Input' ); |
use_ok( 'WebPAC::Input' ); |
19 |
use_ok( 'WebPAC::Store' ); |
use_ok( 'WebPAC::Store' ); |
20 |
use_ok( 'WebPAC::Normalize::XML' ); |
use_ok( 'WebPAC::Lookup::Normalize' ); |
21 |
use_ok( 'WebPAC::Normalize::Set' ); |
use_ok( 'WebPAC::Normalize' ); |
22 |
use_ok( 'WebPAC::Output::TT' ); |
use_ok( 'WebPAC::Output::TT' ); |
23 |
} |
} |
24 |
|
|
28 |
|
|
29 |
my $isis_file = "$abs_path../t/winisis/BIBL"; |
my $isis_file = "$abs_path../t/winisis/BIBL"; |
30 |
#$isis_file = '/data/hidra/THS/THS'; |
#$isis_file = '/data/hidra/THS/THS'; |
31 |
$isis_file = '/data/isis_data/ffkk/'; |
#$isis_file = '/data/isis_data/ffkk/'; |
32 |
|
|
33 |
diag "isis_file: $isis_file" if ($debug); |
diag "isis_file: $isis_file" if ($debug); |
34 |
|
|
35 |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
36 |
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
37 |
|
|
|
my ($t1,$t2) = (0,0); |
|
|
|
|
38 |
ok(my $lookup = new WebPAC::Lookup( |
ok(my $lookup = new WebPAC::Lookup( |
39 |
lookup_file => $lookup_file, |
lookup_file => $lookup_file, |
40 |
), "new Lookup"); |
), "new Lookup"); |
59 |
database => '.', |
database => '.', |
60 |
), "new Store"); |
), "new Store"); |
61 |
|
|
|
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"); |
|
|
|
|
62 |
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" ); |
63 |
|
|
64 |
ok(my $out = new WebPAC::Output::TT( |
ok(my $out = new WebPAC::Output::TT( |
68 |
|
|
69 |
diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug); |
diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug); |
70 |
|
|
71 |
|
my $t_norm = 0; |
72 |
|
|
73 |
foreach my $pos ( 0 ... $isis->size ) { |
foreach my $pos ( 0 ... $isis->size ) { |
74 |
|
|
75 |
my $row = $isis->fetch || next; |
my $row = $isis->fetch || next; |
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 = WebPAC::Normalize::data_structure( |
81 |
ok(my $ds = $n->data_structure($row), "data_structure"); |
lookup => $lookup->lookup_hash, |
82 |
|
row => $row, |
83 |
$t1 += time() - $t; |
rules => $norm_pl, |
84 |
|
), "Set data_structure"); |
85 |
|
$t_norm += time() - $t; |
86 |
|
|
87 |
diag " ds $pos => ",Dumper($ds) if ($debug); |
diag " ds $pos => ",Dumper($ds) if ($debug); |
88 |
|
|
|
$t = time(); |
|
|
my $ds2; |
|
|
|
|
|
# TODO move somewhere |
|
|
{ |
|
|
no strict 'subs'; |
|
|
use WebPAC::Normalize::Set; |
|
|
set_lookup( $lookup->lookup_hash ); |
|
|
set_rec( $row ); |
|
|
clean_ds(); |
|
|
eval "$norm_pl"; |
|
|
ok(! $@, $@ ? "error: $@" : "no error"); |
|
|
ok($ds2 = get_ds(), "get_ds"); |
|
|
|
|
|
} |
|
|
|
|
|
$t2 += time() - $t; |
|
|
|
|
|
diag " ds2 $pos => ",Dumper($ds2) if ($debug); |
|
|
is_deeply( $ds, $ds2, 'ds same for xml and sets'); |
|
|
|
|
89 |
ok(my $html = $out->apply( |
ok(my $html = $out->apply( |
90 |
template => 'html.tt', |
template => 'html.tt', |
91 |
data => $ds, |
data => $ds, |
97 |
|
|
98 |
}; |
}; |
99 |
|
|
100 |
diag sprintf("timings: %.2fs vs %.2fs [%1.2f%%]\n", $t1, $t2, ($t1 / $t2) * 100); |
diag sprintf("timings: %.2fs\n", $t_norm); |