3a5a950c5d4b6b2a67459e069b21a7e32f611109
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / ResultSet / Named.pm
1 # $Id: Named.pm,v 1.1 2006-11-02 11:46:40 sondberg Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::ResultSet::Named;
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
19     $conn->log('irspy_test', 'Testing for named resultset support');
20
21     $conn->irspy_search_pqf("\@attr 1=4 mineral", {},
22                             {'setname' => 'a', 'start' => 0, 'count' => 0},     
23                             ZOOM::Event::RECV_SEARCH, \&completed_search_a,
24                             exception => \&error);
25 }
26
27
28 sub completed_search_a {
29     my ($conn, $task, $test_args, $event) = @_;
30     my $rs = $task->{rs};
31     my $record = '';
32     my $hits = $rs->size();
33
34     ## How should be handle the situation when there is 0 hits?
35     if ($hits > 0) {
36         $record = $rs->record(0)->raw(); 
37     } 
38
39     $conn->irspy_search_pqf("\@attr 1=4 4ds9da94",
40                             {'record_a' => $record, 'hits_a' => $hits,
41                              'rs_a' => $rs},
42                             {'setname' => 'b'}, 
43                             ZOOM::Event::RECV_SEARCH, \&completed_search_b,
44                             exception => \&error);
45
46     return ZOOM::IRSpy::Status::TASK_DONE;
47 }
48
49
50 sub completed_search_b {
51     my($conn, $task, $test_args, $event) = @_;
52     my $rs = $test_args->{rs_a};
53     my $record = '';
54     my $error = '';
55
56     $rs->cache_reset();
57
58     if ($test_args->{'hits_a'} > 0) {
59         my $hits = $rs->size();
60         my $record = $rs->record(0)->raw();
61
62         if ($hits != $test_args->{'hits_a'}) {
63             $conn->log('irspy_test', 'Named result set not supported: ',
64                                      'Mis-matching hit counts');
65             $error = 'hitcount';
66         }
67
68         if ($record ne $test_args->{'record_a'}) {
69             $conn->log('irspy_test', 'Named result set not supported: ',
70                                      'Mis-matching records');
71             $error = 'record';
72         }
73     }
74
75     update($conn, $error eq '' ? 1 : 0, $error);
76
77     return ZOOM::IRSpy::Status::TASK_DONE;
78 }
79
80
81 sub error {
82     my($conn, $task, $test_args, $exception) = @_;
83
84     $conn->log("irspy_test", "Named resultset check failed:", $exception);
85     return ZOOM::IRSpy::Status::TASK_DONE;
86 }
87
88
89 sub update {
90     my ($conn, $ok, $error) = @_;
91     my %args = ('ok' => $ok);
92
93     if (!$ok) {
94         $args{'error'} = $error;
95     }
96
97     $conn->record()->store_result('named_resultset', %args); 
98 }
99
100 1;