Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/irspy
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Boolean.pm
1
2 # See the "Main" test package for documentation
3
4 package ZOOM::IRSpy::Test::Search::Boolean;
5
6 use 5.008;
7 use strict;
8 use warnings;
9
10 use ZOOM::IRSpy::Test;
11 our @ISA = qw(ZOOM::IRSpy::Test);
12
13
14 sub start {
15     my $class = shift();
16     my($conn) = @_;
17     my %pqfs = ('and'   => '@and @attr 1=4 mineral @attr 1=4 water',
18                 'or'    => '@or @attr 1=4 mineral @attr 1=4 water',
19                 'not'   => '@not @attr 1=4 mineral @attr 1=4 water',
20                 'and-or'=> '@and @or @attr 1=4 mineral @attr 1=4 water ' .
21                            '@attr 1=4 of' 
22                 );
23
24     foreach my $operator (keys %pqfs) {
25         $conn->irspy_search_pqf($pqfs{$operator},
26                                 {'operator' => $operator}, {},
27                                 ZOOM::Event::ZEND, \&found,
28                                 exception => \&error);
29     }
30 }
31
32
33 sub found {
34     my($conn, $task, $test_args, $event) = @_;
35     my $operator = $test_args->{'operator'};
36
37     my $n = $task->{rs}->size();
38     $task->{rs}->destroy();
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     $task->{rs}->destroy();
52     $conn->log("irspy_test", "search using boolean operator ", $operator,
53                              " had error: ", $exception);
54     update($conn, $operator, 0);
55     zoom_error_timeout_update($conn, $exception);
56     return ZOOM::IRSpy::Status::TASK_DONE;
57 }
58
59
60 sub update {
61     my ($conn, $operator, $ok) = @_;
62
63     $conn->record()->store_result('boolean', 'operator' => $operator,
64                                              'ok'       => $ok);
65 }
66
67
68 1;