3 ## $Id: ztest.pl,v 1.17 2007-03-08 14:51:32 mike Exp $
4 ## ------------------------------------------------------------------
6 ## Copyright (c) 2000-2004, Index Data.
8 ## Permission to use, copy, modify, distribute, and sell this software and
9 ## its documentation, in whole or in part, for any purpose, is hereby granted,
12 ## 1. This copyright and permission notice appear in all copies of the
13 ## software and its documentation. Notices of copyright or attribution
14 ## which appear at the beginning of any file must remain unchanged.
16 ## 2. The name of Index Data or the individual authors may not be used to
17 ## endorse or promote products derived from this software without specific
18 ## prior written permission.
20 ## THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
21 ## EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
22 ## WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
23 ## IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
24 ## INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
25 ## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
26 ## NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
27 ## LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
31 use ExtUtils::testlib;
33 use Net::Z3950::SimpleServer;
41 foreach $key (keys %$href) {
42 printf("%10s => %s\n", $key, $href->{$key});
51 $args->{IMP_NAME} = "DemoServer";
52 $args->{IMP_ID} = "81";
53 $args->{IMP_VER} = "3.14159";
54 $args->{ERR_CODE} = 0;
55 $args->{HANDLE} = $session;
56 if (defined($args->{PASS}) && defined($args->{USER})) {
57 printf("Received USER/PASS=%s/%s\n", $args->{USER},$args->{PASS});
66 print "Sort handler called\n";
67 print Dumper( $args );
72 my $term = $args->{TERM};
92 { TERM => 'Number 10',
96 $args->{ENTRIES} = $entries;
97 $args->{STATUS} = Net::Z3950::SimpleServer::ScanPartial;
98 print "Welcome to scan....\n";
99 print "You scanned for term '$term'\n";
103 my $_fail_frequency = 0;
106 sub my_search_handler {
110 name => "Peter Dornan",
111 title => "Spokesman",
112 collaboration => "ATLAS"
114 name => "Jorn Dines Hansen",
115 title => "Professor",
116 collaboration => "HERA-B"
118 name => "Alain Blondel",
119 title => "Head of coll.",
120 collaboration => "ALEPH"
123 my $session = $args->{HANDLE};
124 my $set_id = $args->{SETNAME};
125 my @database_list = @{ $args->{DATABASES} };
126 my $query = $args->{QUERY};
129 print "------------------------------------------------------------\n";
130 print "Processing query : $query\n";
131 printf("Database set : %s\n", join(" ", @database_list));
132 print "Setname : $set_id\n";
133 print "------------------------------------------------------------\n";
135 $args->{HITS} = $hits;
136 $session->{$set_id} = $data;
137 $session->{__HITS} = $hits;
138 if ($_fail_frequency != 0 && ++$_counter % $_fail_frequency == 0) {
139 print "Exiting to be nasty to client\n";
145 sub my_fetch_handler {
147 my $session = $args->{HANDLE};
148 my $set_id = $args->{SETNAME};
149 my $data = $session->{$set_id};
150 my $offset = $args->{OFFSET};
151 my $record = "<xml>";
153 my $hits = $session->{__HITS};
154 my $href = $data->[$offset - 1];
156 $args->{REP_FORM} = Net::Z3950::OID::xml;
157 foreach $field (keys %$href) {
158 $record .= "<" . $field . ">" . $href->{$field} . "</" . $field . ">";
162 $args->{RECORD} = $record;
163 if ($offset == $session->{__HITS}) {
168 Net::Z3950::SimpleServer::yazlog("hello");
170 my $handler = new Net::Z3950::SimpleServer(
171 INIT => "main::my_init_handler",
172 SEARCH => "main::my_search_handler",
173 SCAN => "main::my_scan_handler",
174 SORT => "main::my_sort_handler",
175 FETCH => "main::my_fetch_handler" );
177 if (@ARGV >= 2 && $ARGV[0] eq "-n") {
178 $_fail_frequency = $ARGV[1];
182 $handler->launch_server("ztest.pl", @ARGV);