1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use Test::More; |
4 |
use blib; |
5 |
|
6 |
use WAIT::Database; |
7 |
use WAIT::Wais; |
8 |
use Cwd; |
9 |
use strict; |
10 |
use File::Path qw(mkpath rmtree); |
11 |
|
12 |
plan tests => 10; |
13 |
|
14 |
$SIG{__DIE__} = $SIG{INT} = \&cleanup; |
15 |
|
16 |
my $pwd = getcwd(); |
17 |
mkpath "/tmp/wait-test-$$"; |
18 |
print "$^X -Mblib blib/script/bibdb -dir /tmp/wait-test-$$ -database sample\n"; |
19 |
system "$^X -Mblib blib/script/bibdb -dir /tmp/wait-test-$$ -database sample > /dev/null 2>&1"; |
20 |
|
21 |
use Fcntl; |
22 |
|
23 |
ok( |
24 |
my $db = WAIT::Database->open( |
25 |
name => 'sample', |
26 |
'directory' => "/tmp/wait-test-$$", |
27 |
'mode' => O_RDWR, |
28 |
), "open"); |
29 |
|
30 |
ok(my $tb = $db->table(name => 'bibdb'), "table"); |
31 |
|
32 |
ok($tb->open, "open"); |
33 |
|
34 |
ok($tb->set(top => 1), "set(top => 1)"); |
35 |
|
36 |
ok($tb->close, "tb->close"); |
37 |
ok($db->close, "db->close"); |
38 |
|
39 |
$db = "/tmp/wait-test-$$/sample/bibdb"; |
40 |
print "# Testing WAIT searches\n"; |
41 |
ok(my $result = WAIT::Wais::Search({ |
42 |
'query' => 'pfeifer', |
43 |
'database' => $db, |
44 |
}), |
45 |
"WAIT::Wais::Search"); |
46 |
|
47 |
ok(&headlines($result), "headlines"); |
48 |
|
49 |
my @header = $result->header; |
50 |
my $N; |
51 |
for (my $n=0;$n<@header;$n++) { |
52 |
$N = $n if ${$header[$n]->[6]} eq "wait;/tmp/wait-test-$$/sample/bibdb;13"; |
53 |
} |
54 |
my $id = ($result->header)[$N]->[6]; |
55 |
my $short = ($result->header)[$N]->[6]; |
56 |
|
57 |
my $result_text = $result->text; |
58 |
ok($#header >= 14, "\$\#header[$#header]result_text[$result_text]"); |
59 |
|
60 |
print "# Testing local retrieve\n"; |
61 |
$result = WAIT::Wais::Retrieve( |
62 |
'database' => $db, |
63 |
'docid' => $id, |
64 |
'query' => 'pfeifer', |
65 |
'type' => 'HTML', |
66 |
); |
67 |
$result_text = $result->text; |
68 |
$result_text =~ s/^/# /gm; |
69 |
ok($result_text =~ m!Pfeifer/Fuhr:93!, "result_text[$result_text]"); |
70 |
|
71 |
my @x = $short->split; |
72 |
ok($x[2] =~ /test.ste 3585 393$/ || $x[2] == 13, "\@x:[@x]"); |
73 |
|
74 |
|
75 |
####################################################################### |
76 |
|
77 |
sub headlines { |
78 |
my $result = shift; |
79 |
my ($tag, $score, $lines, $length, $headline, $types, $id); |
80 |
|
81 |
for ($result->header) { |
82 |
($tag, $score, $lines, $length, $headline, $types, $id) = @{$_}; |
83 |
printf "# %5d %5d %s %s\n", |
84 |
$score*1000, $lines, $headline, join(',', @{$types}); |
85 |
} |
86 |
} |
87 |
|
88 |
# releasing 1 pending lock... at .../LockFile/Simple.pm |
89 |
open STDERR, '>/dev/null'; |
90 |
|
91 |
sub cleanup |
92 |
{ |
93 |
rmtree "/tmp/wait-test-$$"; |
94 |
} |
95 |
|
96 |
|
97 |
sub END |
98 |
{ |
99 |
&cleanup; |
100 |
} |