Use ZEND only for callbacks, rather than RECV_*
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Boolean.pm
1 # $Id: Boolean.pm,v 1.4 2007-02-23 15:03:44 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Search::Boolean;
6
7 use 5.008;
8 use strict;
9 use warnings;
10
11 use ZOOM::IRSpy::Test;
12 our @ISA = qw(ZOOM::IRSpy::Test);
13
14
15 sub start {
16     my $class = shift();
17     my($conn) = @_;
18     my %pqfs = ('and'   => '@and @attr 1=4 mineral @attr 1=4 water',
19                 'or'    => '@or @attr 1=4 mineral @attr 1=4 water',
20                 'not'   => '@not @attr 1=4 mineral @attr 1=4 water',
21                 'and-or'=> '@and @or @attr 1=4 mineral @attr 1=4 water ' .
22                            '@attr 1=4 of' 
23                 );
24
25     foreach my $operator (keys %pqfs) {
26         $conn->irspy_search_pqf($pqfs{$operator},
27                                 {'operator' => $operator}, {},
28                                 ZOOM::Event::ZEND, \&found,
29                                 exception => \&error);
30     }
31 }
32
33
34 sub found {
35     my($conn, $task, $test_args, $event) = @_;
36     my $operator = $test_args->{'operator'};
37     my $n = $task->{rs}->size();
38
39     $conn->log("irspy_test", "search using boolean operator ", $operator,
40                              " found $n record", $n==1 ? "" : "s");
41     update($conn, $operator, 1);
42
43     return ZOOM::IRSpy::Status::TASK_DONE;
44 }
45
46
47 sub error {
48     my($conn, $task, $test_args, $exception) = @_;
49     my $operator = $test_args->{'operator'};
50
51     $conn->log("irspy_test", "search using boolean operator ", $operator,
52                              " had error: ", $exception);
53     update($conn, $operator, 0);
54     return ZOOM::IRSpy::Status::TASK_DONE;
55 }
56
57
58 sub update {
59     my ($conn, $operator, $ok) = @_;
60
61     $conn->record()->store_result('boolean', 'operator' => $operator,
62                                              'ok'       => $ok);
63 }
64
65
66 1;