2 # See the "Main" test package for documentation
4 package ZOOM::IRSpy::Test::Ping;
10 use ZOOM::IRSpy::Test;
11 our @ISA = qw(ZOOM::IRSpy::Test);
13 use ZOOM::IRSpy::Utils qw(isodate);
16 my $conv = new Text::Iconv("LATIN1", "UTF-8");
24 my $xc = $conn->record()->xpath_context();
25 my $user = $xc->find("e:serverInfo/e:authentication/e:user");
26 my $password = $xc->find("e:serverInfo/e:authentication/e:password");
27 $options{"*user"} = $user if $user;
28 $options{"*password"} = $password if $password;
30 $conn->irspy_connect(undef, \%options,
31 ZOOM::Event::ZEND, \&connected,
32 exception => \¬_connected);
37 my($conn, $__UNUSED_task, $__UNUSED_udata, $__UNUSED_event) = @_;
39 $conn->log("irspy_test", "connected");
40 $conn->record()->store_result("probe", ok => 1);
42 foreach my $opt (qw(search present delSet resourceReport
43 triggerResourceCtrl resourceCtrl
44 accessCtrl scan sort extendedServices
45 level_1Segmentation level_2Segmentation
46 concurrentOperations namedResultSets
47 encapsulation resultCount negotiationModel
48 duplicationDetection queryType104
49 pQESCorrection stringSchema)) {
50 #print STDERR "\$conn->option('init_opt_$opt') = '", $conn->option("init_opt_$opt"), "'\n";
51 $conn->record()->store_result('init_opt', option => $opt)
52 if $conn->option("init_opt_$opt");
55 my %params = (serverImplementationId => "id",
56 serverImplementationName => "name",
57 serverImplementationVersion => "version",
59 foreach my $opt (keys %params) {
60 my $val = $conn->option($opt);
61 next if !defined $val; # not defined for SRU, for example
63 # There doesn't seem to be a reliable way to tell what
64 # character set the server uses for these. At least one
65 # server (z3950.bcl.jcyl.es:210/AbsysCCFL) returns an ISO
66 # 8859-1 string containing an o-acute, which breaks the XML
67 # parser if we just insert it naively. It seems reasonable,
68 # though, to guess that the great majority of servers will use
69 # ASCII, Latin-1 or Unicode. The first of these is a subset
70 # of the second, so that brings it to down to two. The
71 # strategy is simply this: assume it's ASCII-Latin-1, and try
72 # to convert to UTF-8. If that conversion works, fine; if
73 # not, assume it's because the string was already UTF-8, so
75 Text::Iconv->raise_error(1);
78 $maybe = $conv->convert($val);
79 }; if (!$@ && $maybe ne $val) {
80 $conn->log("irspy", "converted '$val' from Latin-1 to UTF-8");
83 $conn->record()->store_result($opt, value => $val);
84 $conn->irspy()->var($params{$opt}, $val);
87 return ZOOM::IRSpy::Status::TEST_GOOD;
92 my($conn, $__UNUSED_task, $__UNUSED_udata, $exception) = @_;
94 $conn->log("irspy", "not connected: $exception");
95 $conn->record()->store_result("probe",
97 errcode => $exception->code(),
98 errmsg => $exception->message(),
99 addinfo => $exception->addinfo(),
100 diagset => $exception->diagset());
102 return ZOOM::IRSpy::Status::TEST_BAD;