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

Diff of /trunk/t/pgest.t

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 25 by dpavlin, Fri May 27 21:06:01 2005 UTC revision 45 by dpavlin, Sat Sep 10 23:08:47 2005 UTC
# Line 2  Line 2 
2    
3  use strict;  use strict;
4    
5  use Test::More tests => 67;  use Test::More tests => 94;
6    
7  BEGIN {  BEGIN {
8          use_ok('DBI');          use_ok('DBI');
# Line 25  if ($pwd !~ m#^/#) { Line 25  if ($pwd !~ m#^/#) {
25  ok($pwd, "pwd: $pwd");  ok($pwd, "pwd: $pwd");
26  my $index = "$pwd/../data/casket/";  my $index = "$pwd/../data/casket/";
27    
28  my $sql = "select * from pgest('$index',?,?,?,?,?) as (id text)";  my $sql = "select id from pgest('$index',?,?,?,?,?,array['\@id']) as (id text)";
29  diag "$sql";  diag "$sql";
30    
31  my $sth = $dbh->prepare($sql) || die $dbh->errstr();  my $sth = $dbh->prepare($sql) || die $dbh->errstr();
32  ok($sth, "sth");  ok($sth, "sth");
33    
34    my $sql_node = "select id from pgest('http://localhost:1978/node/trivia','admin','admin',?,?,?,?,?,array['\@id']) as (id text)";
35    my $sth_node = $dbh->prepare($sql_node) || die $dbh->errstr();
36    ok($sth_node, "sth_node");
37    
38  sub pgest {  sub pgest {
39          $sth->execute(@_, "{'\@id'}" ) || die $sth->errstr();          $sth->execute(@_) || die $sth->errstr();
40            $sth_node->execute(@_) || die $sth_node->errstr();
41          {          {
42                  no warnings;                  no warnings;
43                  ok($sth, "execute(".join(",",@_).")");                  ok($sth, "execute(".join(",",@_).")");
44                    ok($sth_node, "execute on node");
45          }          }
46    
47          my @arr;          my @arr;
48          while (my $row = $sth->fetchrow_hashref() ) {          while (my ($id) = $sth->fetchrow_array() ) {
49                  push @arr, $row;                  push @arr, $id;
50            }
51            my @arr_node;
52            while (my ($id) = $sth_node->fetchrow_array() ) {
53                    push @arr_node, $id;
54          }          }
55          ok(@arr, "results ".($#arr + 1));          cmp_ok($#arr, '==', $#arr_node, "pgest direct and node results");
56    
57          return @arr;          return @arr;
58  }  }
# Line 53  sub estcmd { Line 63  sub estcmd {
63    
64          my $cmd = "estcmd search ";          my $cmd = "estcmd search ";
65          $cmd .= " -attr '$attr' " if ($attr);          $cmd .= " -attr '$attr' " if ($attr);
66            $cmd .= " -max 999999 ";                # why do I need this?
67          $q ||= '';          $q ||= '';
68          $cmd .= "$index '$q'";          $cmd .= "$index '$q'";
69          diag $cmd;          diag $cmd;
70    
71          open(my $fh, "$cmd |") || die "cmd: $!";          open(my $fh, "$cmd |") || die "cmd: $!";
72            my $del = <$fh>;
73            chomp($del);
74            while(<$fh>) {
75                    last if (/^\Q$del\E/);
76            }
77            my @arr;
78          while(<$fh>) {          while(<$fh>) {
79                  if (/^HIT=(\d+)/) {                  chomp;
80                          return $1;                  last if (/^\Q$del\E/);
81                  }                  push @arr, $_;
82          }          }
83          return undef;  
84            return @arr;
85  }  }
86    
87  # test simple query  # test simple query
# Line 73  foreach my $q (qw(blade runner Philip k. Line 91  foreach my $q (qw(blade runner Philip k.
91    
92          diag "$hits hits";          diag "$hits hits";
93    
94          cmp_ok(scalar pgest($q, '', 0, 0), '==', $hits, 'blade runner');          cmp_ok(scalar pgest($q, '', undef, 0, 0), '==', $hits, 'blade runner');
95  }  }
96    
97  # test attr query  # test attr query
# Line 83  foreach my $q (('@title STRINC Blade Run Line 101  foreach my $q (('@title STRINC Blade Run
101    
102          diag "$hits hits";          diag "$hits hits";
103    
104          cmp_ok(scalar pgest('', $q, 0, 0), '==', $hits, 'blade runner');          cmp_ok(scalar pgest(undef, $q, undef, 0, 0), '==', $hits, 'blade runner');
105  }  }
106    
107  diag "Error handling test follows, ignore messages...";  diag "Error handling test follows, ignore messages...";
108  # test NULL handling  # test NULL handling
109  ok(! $dbh->do(qq`select * from pgest(null, '', '', 0, 0, array['\@id']) as (id text)`), "null index_path");  ok(! $dbh->do(qq`select * from pgest(null, '', '', null, 0, 0, array['\@id']) as (id text)`), "null index_path");
110  ok(my $hits = pgest('blade runner', '', 0, 0), "test search");  ok(my $hits = pgest('blade runner', '', undef, 0, 0), "test search");
111  cmp_ok($hits, '==', pgest('blade runner', undef, 0, 0), "null attr");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, 0, 0), "null attr");
112  cmp_ok($hits, '==', pgest('blade runner', '', undef, 0), "null limit");  cmp_ok($hits, '==', pgest('blade runner', '', undef, undef, 0), "null limit");
113  cmp_ok($hits, '==', pgest('blade runner', '', 0, undef), "null offset");  cmp_ok($hits, '==', pgest('blade runner', '', undef, 0, undef), "null offset");
114  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "null optional");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "null optional");
115    
116  # test limit, offset and global mess  # test limit, offset and global mess
117  my $d = int($hits / 3);  my $d = int($hits / 3);
118  cmp_ok($d, '==', pgest('blade runner',undef, $d, undef), "limit $d");  cmp_ok($d, '==', pgest('blade runner',undef, undef, $d, undef), "limit $d");
119  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
120    
121    cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, undef, $d), "offset $d");
122    cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
123    
124    cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, ($hits - $d), $d), "limit ".($hits - $d)." offset $d");
125    cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef, undef), "check");
126    
127  cmp_ok(($hits - $d), '==', pgest('blade runner',undef, undef, $d), "offset $d");  # test sort
128  cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");  my @arr_asc = pgest('blade runner', undef, '@id NUMA', undef, undef);
129    my @arr_desc = pgest('blade runner', undef, '@id NUMD', undef, undef);
130    
131    cmp_ok(@arr_asc, '==', @arr_desc, "same number of results");
132    my $errors = 0;
133    foreach my $i (0 .. $#arr_asc) {
134            my ($a, $b) = ($arr_asc[$i], $arr_desc[$#arr_desc - $i]);
135            if ($a ne $b) {
136                    $errors++;
137                    diag "element $i: $a != $b";
138            }
139    }
140    
141  cmp_ok(($hits - $d - $d), '==', pgest('blade runner',undef, ($hits - $d), $d), "limit $d offset $d");  cmp_ok($errors, '==', 0, "errors in ordering");
 cmp_ok($hits, '==', pgest('blade runner', undef, undef, undef), "check");  

Legend:
Removed from v.25  
changed lines
  Added in v.45

  ViewVC Help
Powered by ViewVC 1.1.26