Added handlers for other types of ZOOM events so that the test case can run.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Search / Bib1.pm
1 # $Id: Bib1.pm,v 1.4 2006-10-02 13:02:10 sondberg Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Search::Bib1;
6
7 use 5.008;
8 use strict;
9 use warnings;
10 use Data::Dumper;
11
12 use ZOOM::IRSpy::Test;
13 our @ISA = qw(ZOOM::IRSpy::Test);
14 our @Bib1_Attr = qw(1 2 3 4 5 6 7 8 9); 
15
16
17 sub run {
18     my $this = shift();
19     my $irspy = $this->irspy();
20     my $pod = $irspy->pod();
21
22     $pod->callback(ZOOM::Event::RECV_SEARCH, \&found);
23     $pod->callback("exception", \&error_handler);
24     $pod->callback(ZOOM::Event::ZEND, \&continue);
25
26     foreach my $attr (@Bib1_Attr) {
27         $pod->search_pqf('@attr 1=' . $attr . ' water' );
28         $irspy->{'handle'}->{'attr'} = $attr;
29         my $err = $pod->wait($irspy);
30     }
31
32     return 0;
33 }
34
35
36 sub found {
37     my($conn, $irspy, $rs, $event) = @_;
38     my $href = $irspy->{'handle'};
39     my $attr = $href->{'attr'};
40     my $n = $rs->size();
41     my $rec = $irspy->record($conn);
42
43     $irspy->log("irspy_test", $conn->option("host"),
44                 " Bib-1 attribute=$attr search found $n record",
45                 $n==1 ? "" : "s");
46
47     $rec->append_entry("irspy:status", "<irspy:search set='bib1' attr='$attr'" .
48                        " ok='1'>" . $irspy->isodate(time()) .
49                        "</irspy:search>");
50     return 0;
51 }
52
53
54 sub continue { 
55     my ($conn, $irspy, $rs, $event) = @_;
56
57     print "ZEND\n";
58 }
59
60
61
62 sub error_handler { maybe_connected(@_, 0) }
63
64 sub maybe_connected {
65     my($conn, $irspy, $rs, $event, $ok) = @_;
66
67     $irspy->log("irspy_test", $conn->option("host"),
68                 ($ok ? "" : " not"), " connected");
69     my $rec = $irspy->record($conn);
70     $rec->append_entry("irspy:status", "<irspy:probe ok='$ok'>" .
71                        $irspy->isodate(time()) . "</irspy:probe>");
72     $conn->option(pod_omit => 1) if !$ok;
73     return 0;
74 }
75
76 1;