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", "UTF8");
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 foreach my $opt (qw(serverImplementationId
56 serverImplementationName
57 serverImplementationVersion)) {
58 my $val = $conn->option($opt);
59 next if !defined $val; # not defined for SRU, for example
61 # There doesn't seem to be a reliable way to tell what
62 # character set the server uses for these. At least one
63 # server (z3950.bcl.jcyl.es:210/AbsysCCFL) returns an ISO
64 # 8859-1 string containing an o-acute, which breaks the XML
65 # parser if we just insert it naively. It seems reasonable,
66 # though, to guess that the great majority of servers will use
67 # ASCII, Latin-1 or Unicode. The first of these is a subset
68 # of the second, so that brings it to down to two. The
69 # strategy is simply this: assume it's ASCII-Latin-1, and try
70 # to convert to UTF-8. If that conversion works, fine; if
71 # not, assume it's because the string was already UTF-8, so
73 Text::Iconv->raise_error(1);
76 $maybe = $conv->convert($val);
77 }; if (!$@ && $maybe ne $val) {
78 $conn->log("irspy", "converted '$val' from Latin-1 to UTF-8");
81 $conn->record()->store_result($opt, value => $val);
84 return ZOOM::IRSpy::Status::TEST_GOOD;
89 my($conn, $__UNUSED_task, $__UNUSED_udata, $exception) = @_;
91 $conn->log("irspy", "not connected: $exception");
92 $conn->record()->store_result("probe",
94 errcode => $exception->code(),
95 errmsg => $exception->message(),
96 addinfo => $exception->addinfo(),
97 diagset => $exception->diagset());
99 return ZOOM::IRSpy::Status::TEST_BAD;