Less verbose: don't log targets whose hashes mean they get overlooked.
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Test / Ping.pm
1 # $Id: Ping.pm,v 1.27 2007-05-09 11:19:36 mike Exp $
2
3 # See the "Main" test package for documentation
4
5 package ZOOM::IRSpy::Test::Ping;
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 use ZOOM::IRSpy::Utils qw(isodate);
15
16 use Text::Iconv;
17 my $conv = new Text::Iconv("LATIN1", "UTF8");
18
19
20 sub start {
21     my $class = shift();
22     my($conn) = @_;
23
24     my %options = ();
25     my $xc = $conn->record()->xpath_context();
26     my $user = $xc->find("e:serverInfo/e:authentication/e:user");
27     my $password = $xc->find("e:serverInfo/e:authentication/e:password");
28     $options{"*user"} = $user if $user;
29     $options{"*password"} = $password if $password;
30
31     $conn->irspy_connect(undef, \%options,
32                          ZOOM::Event::ZEND, \&connected,
33                          exception => \&not_connected);
34 }
35
36
37 sub connected {
38     my($conn, $__UNUSED_task, $__UNUSED_udata, $__UNUSED_event) = @_;
39
40     $conn->log("irspy_test", "connected");
41     $conn->record()->store_result("probe", ok => 1);
42
43     foreach my $opt (qw(search present delSet resourceReport
44                         triggerResourceCtrl resourceCtrl
45                         accessCtrl scan sort extendedServices
46                         level_1Segmentation level_2Segmentation
47                         concurrentOperations namedResultSets
48                         encapsulation resultCount negotiationModel
49                         duplicationDetection queryType104
50                         pQESCorrection stringSchema)) {
51         #print STDERR "\$conn->option('init_opt_$opt') = '", $conn->option("init_opt_$opt"), "'\n";
52         $conn->record()->store_result('init_opt', option => $opt)
53             if $conn->option("init_opt_$opt");
54     }
55
56     foreach my $opt (qw(serverImplementationId
57                         serverImplementationName
58                         serverImplementationVersion)) {
59         my $val = $conn->option($opt);
60         next if !defined $val; # not defined for SRU, for example
61
62         # There doesn't seem to be a reliable way to tell what
63         # character set the server uses for these.  At least one
64         # server (z3950.bcl.jcyl.es:210/AbsysCCFL) returns an ISO
65         # 8859-1 string containing an o-acute, which breaks the XML
66         # parser if we just insert it naively.  It seems reasonable,
67         # though, to guess that the great majority of servers will use
68         # ASCII, Latin-1 or Unicode.  The first of these is a subset
69         # of the second, so that brings it to down to two.  The
70         # strategy is simply this: assume it's ASCII-Latin-1, and try
71         # to convert to UTF-8.  If that conversion works, fine; if
72         # not, assume it's because the string was already UTF-8, so
73         # use it as is.
74         Text::Iconv->raise_error(1);
75         my $maybe;
76         eval {
77             $maybe = $conv->convert($val);
78         }; if (!$@ && $maybe ne $val) {
79             $conn->log("irspy", "converted '$val' from Latin-1 to UTF-8");
80             $val = $maybe;
81         }
82         $conn->record()->store_result($opt, value => $val);
83     }
84
85     return ZOOM::IRSpy::Status::TEST_GOOD;
86 }
87
88
89 sub not_connected {
90     my($conn, $__UNUSED_task, $__UNUSED_udata, $exception) = @_;
91
92     $conn->log("irspy_test", "not connected: $exception");
93     $conn->record()->store_result("probe",
94                                   ok => 0,
95                                   errcode => $exception->code(),
96                                   errmsg => $exception->message(),
97                                   addinfo => $exception->addinfo(),
98                                   diagset => $exception->diagset());
99
100     return ZOOM::IRSpy::Status::TEST_BAD;
101 }
102
103
104 1;