1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
4 ######################### We start with some black magic to print on failure.
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
9 BEGIN { $| = 1; print "1..1\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use Net::Z3950::SimpleServer;
15 ######################### End of black magic.
17 # Insert your test code below (better if it prints "ok 13"
18 # (correspondingly "not ok 13") depending on the success of chunk 13
26 $href->{HANDLE} = \%log;
29 sub my_search_handler {
31 my %log = %{$href->{HANDLE}};
33 $log{"search"} = "Ok";
34 $href->{HANDLE} = \%log;
38 sub my_fetch_handler {
40 my %log = %{$href->{HANDLE}};
41 my $record = "<xml><head>Headline</head><body>I am a record</body></xml>";
44 $href->{HANDLE} = \%log;
45 $href->{RECORD} = $record;
46 $href->{LEN} = length($record);
48 $href->{BASENAME} = "Test";
51 sub my_close_handler {
52 my @services = ("init", "search", "fetch", "close");
54 my %log = %{$href->{HANDLE}};
61 print "\n-----------------------------------------------\n";
62 print "Available Z39.50 services:\n\n";
64 foreach $service (@services) {
65 print "Called $service: ";
66 if (defined($status = $log{$service})) {
74 print "make test: Failed due to lack of required Z39.50 service\n";
76 print "\nEverything is ok!\n";
78 print "-----------------------------------------------\n";
82 if (!defined($pid = fork() )) {
83 die "Cannot fork: $!\n";
84 } elsif ($pid) { ## Parent launches server
85 my $handler = Net::Z3950::SimpleServer->new(
86 INIT => \&my_init_handler,
87 CLOSE => \&my_close_handler,
88 SEARCH => \&my_search_handler,
89 FETCH => \&my_fetch_handler);
91 $handler->launch_server("test.pl", "-1", @ARGV);
92 } else { ## Child starts the client
94 open(CLIENT, "| yaz-client tcp:localhost:9999 > /dev/null")
95 or die "Couldn't fork client: $!\n";
96 print CLIENT "f test\n";
98 print CLIENT "close\n";
99 print CLIENT "quit\n";
100 close(CLIENT) or die "Couldn't close: $!\n";