/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 491 - (hide annotations)
Sun May 14 12:39:39 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2742 byte(s)
 r642@llin:  dpavlin | 2006-05-14 14:43:11 +0200
 use new WebPAC::Normalize::Set::data_structure

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26