/[pgestraier]/trunk/t/pgest.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/pgest.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 22 - (hide annotations)
Thu May 26 20:16:34 2005 UTC (18 years, 11 months ago) by dpavlin
File MIME type: application/x-troff
File size: 2601 byte(s)
test new function instead of old one

1 dpavlin 8 #!/usr/bin/perl -w
2    
3     use strict;
4    
5 dpavlin 14 use Test::More tests => 67;
6 dpavlin 8
7     BEGIN {
8     use_ok('DBI');
9     use_ok('DBD::Pg');
10     };
11    
12     # hum?
13     my $connect = "DBI:Pg:dbname=test";
14    
15     my $dbh = DBI->connect($connect,"","") || die $DBI::errstr;
16     ok($dbh, "dbh");
17    
18     my $pwd = $0;
19     $pwd =~ s#/[^/]*$##;
20     if ($pwd !~ m#^/#) {
21     my $cwd = `pwd`;
22     chomp($cwd);
23     $pwd = $cwd . '/' . $pwd;
24     }
25     ok($pwd, "pwd: $pwd");
26     my $index = "$pwd/../data/casket/";
27    
28 dpavlin 22 my $sql = "select * from pgest('$index',?,?,?,?,?) as (id text)";
29 dpavlin 8 diag "$sql";
30    
31     my $sth = $dbh->prepare($sql) || die $dbh->errstr();
32     ok($sth, "sth");
33    
34     sub pgest {
35 dpavlin 22 $sth->execute(@_, "{'\@id'}" ) || die $sth->errstr();
36 dpavlin 12 {
37     no warnings;
38     ok($sth, "execute(".join(",",@_).")");
39     }
40 dpavlin 8
41     my @arr;
42     while (my $row = $sth->fetchrow_hashref() ) {
43     push @arr, $row;
44     }
45     ok(@arr, "results ".($#arr + 1));
46    
47     return @arr;
48     }
49    
50     sub estcmd {
51     my $q = shift;
52 dpavlin 9 my $attr = shift;
53 dpavlin 8
54 dpavlin 9 my $cmd = "estcmd search ";
55     $cmd .= " -attr '$attr' " if ($attr);
56     $q ||= '';
57     $cmd .= "$index '$q'";
58 dpavlin 8 diag $cmd;
59    
60     open(my $fh, "$cmd |") || die "cmd: $!";
61     while(<$fh>) {
62     if (/^HIT=(\d+)/) {
63     return $1;
64     }
65     }
66     return undef;
67     }
68    
69 dpavlin 9 # test simple query
70     foreach my $q (qw(blade runner Philip k. dick)) {
71 dpavlin 8
72     ok(my $hits = estcmd($q), "estcmd: $q");
73    
74     diag "$hits hits";
75    
76     cmp_ok(scalar pgest($q, '', 0, 0), '==', $hits, 'blade runner');
77     }
78 dpavlin 9
79     # test attr query
80     foreach my $q (('@title STRINC Blade Runner', '@title ISTRBW blade runner')) {
81    
82     ok(my $hits = estcmd('',$q), "estcmd: $q");
83    
84     diag "$hits hits";
85    
86     cmp_ok(scalar pgest('', $q, 0, 0), '==', $hits, 'blade runner');
87     }
88    
89 dpavlin 12 diag "Error handling test follows, ignore messages...";
90     # test NULL handling
91     ok(! $dbh->do(qq{select * from pgest(null, '', '', 0, 0)}), "null index_path");
92     ok(my $hits = pgest('blade runner', '', 0, 0), "test search");
93     cmp_ok($hits, '==', pgest('blade runner', undef, 0, 0), "null attr");
94     cmp_ok($hits, '==', pgest('blade runner', '', undef, 0), "null limit");
95     cmp_ok($hits, '==', pgest('blade runner', '', 0, undef), "null offset");
96     cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "null optional");
97    
98 dpavlin 14 # test limit, offset and global mess
99     my $d = int($hits / 3);
100     cmp_ok($d, '==', pgest('blade runner',undef, $d, undef), "limit $d");
101     cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");
102    
103     cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, $d), "offset $d");
104     cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");
105    
106     cmp_ok(($hits - $d - $d), '==', pgest('blade runner',undef, ($hits - $d), $d), "limit $d offset $d");
107     cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26