2 |
|
|
3 |
use strict; |
use strict; |
4 |
|
|
5 |
use Test::More tests => 23; |
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/; |
9 |
|
use File::Slurp; |
10 |
|
use Data::Dump qw/dump/; |
11 |
|
use Time::HiRes qw/time/; |
12 |
use blib; |
use blib; |
13 |
|
|
14 |
|
my $debug = shift @ARGV; |
15 |
|
|
16 |
|
# |
17 |
|
# FIXME add lookup testing! |
18 |
|
# |
19 |
|
|
20 |
BEGIN { |
BEGIN { |
21 |
use_ok( 'WebPAC::Lookup' ); |
use_ok( 'WebPAC::Input' ); |
22 |
use_ok( 'WebPAC::Input::ISIS' ); |
use_ok( 'WebPAC::Store' ); |
23 |
use_ok( 'WebPAC::DB' ); |
use_ok( 'WebPAC::Normalize' ); |
|
use_ok( 'WebPAC::Normalize::XML' ); |
|
24 |
use_ok( 'WebPAC::Output::TT' ); |
use_ok( 'WebPAC::Output::TT' ); |
25 |
} |
} |
26 |
|
|
27 |
ok(my $abs_path = abs_path($0), "abs_path"); |
ok(my $abs_path = abs_path($0), "abs_path"); |
28 |
$abs_path =~ s#/[^/]*$#/#; |
$abs_path =~ s#/[^/]*$#/#; |
29 |
diag "abs_path: $abs_path"; |
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'; |
33 |
|
#$isis_file = '/data/isis_data/ffkk/'; |
34 |
|
|
35 |
diag "isis_file: $isis_file"; |
diag "isis_file: $isis_file" if ($debug); |
36 |
|
|
37 |
ok(my $lookup = new WebPAC::Lookup( |
my $normalize_set_pl = "$abs_path/data/normalize.pl"; |
38 |
lookup_file => "$abs_path../conf/lookup/isis.pm", |
my $lookup_file = "$abs_path../conf/lookup/isis.pm"; |
|
), "new Lookup"); |
|
39 |
|
|
40 |
ok(my $isis = new WebPAC::Input::ISIS( |
ok(my $isis = new WebPAC::Input( |
41 |
|
module => 'WebPAC::Input::ISIS', |
42 |
code_page => 'ISO-8859-2', # application encoding |
code_page => 'ISO-8859-2', # application encoding |
43 |
|
limit => 100, |
44 |
|
no_progress_bar => 1, |
45 |
), "new Input::ISIS"); |
), "new Input::ISIS"); |
46 |
|
|
47 |
ok(my $maxmfn = $isis->open( |
ok(my $maxmfn = $isis->open( |
48 |
filename => $isis_file, |
path => $isis_file, |
49 |
code_page => '852', # database encoding |
code_page => 'cp852', # database encoding |
50 |
|
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"); |
58 |
|
|
59 |
ok(my $db = new WebPAC::DB( |
ok(my $db = new WebPAC::Store({ |
60 |
path => $path, |
database => '.', |
61 |
), "new DB"); |
}), "new Store"); |
62 |
|
|
63 |
ok(my $n = new WebPAC::Normalize::XML( |
ok(my $norm_pl = read_file( $normalize_set_pl ), "set definitions: $normalize_set_pl" ); |
|
# filter => { 'foo' => sub { shift } }, |
|
|
db => $db, |
|
|
lookup_regex => $lookup->regex, |
|
|
debug => 1, |
|
|
), "new Normalize::XML"); |
|
|
|
|
|
ok($n->open( |
|
|
tag => 'isis', |
|
|
xml_file => "$abs_path../conf/normalize/isis.xml", |
|
|
), "Normalize::XML->open"); |
|
64 |
|
|
65 |
ok(my $out = new WebPAC::Output::TT( |
ok(my $out = new WebPAC::Output::TT( |
66 |
include_path => "$abs_path../conf/output/tt", |
include_path => "$abs_path../conf/output/tt", |
67 |
filters => { foo => sub { shift } }, |
filters => { foo => sub { shift } }, |
68 |
), "new Output::TT"); |
), "new Output::TT"); |
69 |
|
|
70 |
while (my $row = $isis->fetch) { |
my $t_norm = 0; |
71 |
|
|
72 |
ok(my @ds = $n->data_structure($row), "data_structure"); |
foreach my $pos ( 0 ... $isis->size ) { |
73 |
|
|
74 |
|
my $row = $isis->fetch || next; |
75 |
|
|
76 |
use Data::Dumper; |
diag " row $pos => ",dump($row) if ($debug); |
|
print Dumper(\@ds); |
|
77 |
|
|
78 |
ok($out->apply( |
my $t = time(); |
79 |
|
ok( my $ds = WebPAC::Normalize::data_structure( |
80 |
|
row => $row, |
81 |
|
rules => $norm_pl, |
82 |
|
), "Set data_structure"); |
83 |
|
$t_norm += time() - $t; |
84 |
|
|
85 |
|
diag " ds $pos => ",dump($ds) if ($debug); |
86 |
|
|
87 |
|
ok(my $html = $out->apply( |
88 |
template => 'html.tt', |
template => 'html.tt', |
89 |
data => @ds, |
data => $ds, |
90 |
), "apply"); |
), "apply"); |
91 |
|
|
92 |
|
$html =~ s#\s*[\n\r]+\s*##gs; |
93 |
|
|
94 |
|
#diag $html; |
95 |
|
|
96 |
}; |
}; |
97 |
|
|
98 |
|
diag sprintf("timings: %.2fs\n", $t_norm); |