2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 23; |
use Test::More tests => 41; |
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/; |
9 |
|
use File::Slurp; |
10 |
|
use Data::Dumper; |
11 |
|
use Time::HiRes qw/time/; |
12 |
use blib; |
use blib; |
13 |
|
|
14 |
|
my $debug = shift @ARGV; |
15 |
|
|
16 |
BEGIN { |
BEGIN { |
17 |
use_ok( 'WebPAC::Lookup' ); |
use_ok( 'WebPAC::Lookup' ); |
18 |
use_ok( 'WebPAC::Input::ISIS' ); |
use_ok( 'WebPAC::Input' ); |
19 |
use_ok( 'WebPAC::DB' ); |
use_ok( 'WebPAC::Store' ); |
20 |
use_ok( 'WebPAC::Normalize::XML' ); |
use_ok( 'WebPAC::Normalize::XML' ); |
21 |
|
use_ok( 'WebPAC::Normalize::Set' ); |
22 |
use_ok( 'WebPAC::Output::TT' ); |
use_ok( 'WebPAC::Output::TT' ); |
23 |
} |
} |
24 |
|
|
25 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
26 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
27 |
diag "abs_path: $abs_path"; |
diag "abs_path: $abs_path" if ($debug); |
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'; |
31 |
|
$isis_file = '/data/isis_data/ffkk/'; |
32 |
|
|
33 |
|
diag "isis_file: $isis_file" if ($debug); |
34 |
|
|
35 |
diag "isis_file: $isis_file"; |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
36 |
|
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
37 |
|
|
38 |
|
my ($t1,$t2) = (0,0); |
39 |
|
|
40 |
ok(my $lookup = new WebPAC::Lookup( |
ok(my $lookup = new WebPAC::Lookup( |
41 |
lookup_file => "$abs_path../conf/lookup/isis.pm", |
lookup_file => $lookup_file, |
42 |
), "new Lookup"); |
), "new Lookup"); |
43 |
|
|
44 |
ok(my $isis = new WebPAC::Input::ISIS( |
ok(my $isis = new WebPAC::Input( |
45 |
|
module => 'WebPAC::Input::ISIS', |
46 |
code_page => 'ISO-8859-2', # application encoding |
code_page => 'ISO-8859-2', # application encoding |
47 |
|
limit => 100, |
48 |
|
no_progress_bar => 1, |
49 |
), "new Input::ISIS"); |
), "new Input::ISIS"); |
50 |
|
|
51 |
ok(my $maxmfn = $isis->open( |
ok(my $maxmfn = $isis->open( |
52 |
filename => $isis_file, |
path => $isis_file, |
53 |
code_page => '852', # database encoding |
code_page => '852', # database encoding |
54 |
|
lookup => $lookup, |
55 |
), "Input::ISIS->open"); |
), "Input::ISIS->open"); |
56 |
|
|
57 |
ok(my $path = tempdir( CLEANUP => 1 ), "path"); |
ok(my $path = tempdir( CLEANUP => 1 ), "path"); |
58 |
|
|
59 |
ok(my $db = new WebPAC::DB( |
ok(my $db = new WebPAC::Store( |
60 |
path => $path, |
path => $path, |
61 |
), "new DB"); |
database => '.', |
62 |
|
), "new Store"); |
63 |
|
|
64 |
ok(my $n = new WebPAC::Normalize::XML( |
ok(my $n = new WebPAC::Normalize::XML( |
65 |
# filter => { 'foo' => sub { shift } }, |
# filter => { 'foo' => sub { shift } }, |
66 |
db => $db, |
db => $db, |
67 |
lookup_regex => $lookup->regex, |
lookup_regex => $lookup->regex, |
68 |
debug => 1, |
lookup => $lookup, |
69 |
|
no_progress_bar => 1, |
70 |
), "new Normalize::XML"); |
), "new Normalize::XML"); |
71 |
|
|
72 |
ok($n->open( |
ok($n->open( |
73 |
tag => 'isis', |
tag => 'isis', |
74 |
xml_file => "$abs_path../conf/normalize/isis.xml", |
xml_file => "$abs_path/data/normalize.xml", |
75 |
), "Normalize::XML->open"); |
), "Normalize::XML->open"); |
76 |
|
|
77 |
|
ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); |
78 |
|
|
79 |
ok(my $out = new WebPAC::Output::TT( |
ok(my $out = new WebPAC::Output::TT( |
80 |
include_path => "$abs_path../conf/output/tt", |
include_path => "$abs_path../conf/output/tt", |
81 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
82 |
), "new Output::TT"); |
), "new Output::TT"); |
83 |
|
|
84 |
while (my $row = $isis->fetch) { |
diag " lookup => ",Dumper($lookup->lookup_hash) if ($debug); |
85 |
|
|
86 |
|
foreach my $pos ( 0 ... $isis->size ) { |
87 |
|
|
88 |
|
my $row = $isis->fetch || next; |
89 |
|
|
90 |
|
diag " row $pos => ",Dumper($row) if ($debug); |
91 |
|
|
92 |
|
my $t = time(); |
93 |
|
|
94 |
|
ok(my $ds = $n->data_structure($row), "data_structure"); |
95 |
|
|
96 |
|
$t1 += time() - $t; |
97 |
|
|
98 |
|
diag " ds $pos => ",Dumper($ds) if ($debug); |
99 |
|
|
100 |
|
$t = time(); |
101 |
|
my $ds2; |
102 |
|
|
103 |
|
# TODO move somewhere |
104 |
|
{ |
105 |
|
no strict 'subs'; |
106 |
|
use WebPAC::Normalize::Set; |
107 |
|
set_lookup( $lookup->lookup_hash ); |
108 |
|
set_rec( $row ); |
109 |
|
clean_ds(); |
110 |
|
eval "$norm_pl"; |
111 |
|
ok(! $@, $@ ? "error: $@" : "no error"); |
112 |
|
ok($ds2 = get_ds(), "get_ds"); |
113 |
|
|
114 |
ok(my @ds = $n->data_structure($row), "data_structure"); |
} |
115 |
|
|
116 |
use Data::Dumper; |
$t2 += time() - $t; |
|
print Dumper(\@ds); |
|
117 |
|
|
118 |
ok($out->apply( |
diag " ds2 $pos => ",Dumper($ds2) if ($debug); |
119 |
|
is_deeply( $ds, $ds2, 'ds same for xml and sets'); |
120 |
|
|
121 |
|
ok(my $html = $out->apply( |
122 |
template => 'html.tt', |
template => 'html.tt', |
123 |
data => @ds, |
data => $ds, |
124 |
), "apply"); |
), "apply"); |
125 |
|
|
126 |
|
$html =~ s#\s*[\n\r]+\s*##gs; |
127 |
|
|
128 |
|
#diag $html; |
129 |
|
|
130 |
}; |
}; |
131 |
|
|
132 |
|
diag sprintf("timings: %.2fs vs %.2fs [%1.2f%%]\n", $t1, $t2, ($t1 / $t2) * 100); |