From 19d483e57a65cadc4c1d4f7f284636c07f78ea26 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 12 Apr 2006 11:02:42 +0000 Subject: [PATCH] Check sequence of events involved in connect/init. --- t/19-events.t | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/t/19-events.t b/t/19-events.t index 45c7f01..36b430f 100644 --- a/t/19-events.t +++ b/t/19-events.t @@ -1,11 +1,11 @@ -# $Id: 19-events.t,v 1.2 2006-04-07 11:47:33 mike Exp $ +# $Id: 19-events.t,v 1.3 2006-04-12 11:02:42 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 19-events.t' use strict; use warnings; -use Test::More tests => 7; +use Test::More tests => 19; BEGIN { use_ok('Net::Z3950::ZOOM') }; @@ -32,7 +32,41 @@ ok($val == -3, "empty array reference argument rejected"); $val = Net::Z3950::ZOOM::event([1..32767]); ok($val == -4, "huge array reference argument rejected"); -$val = Net::Z3950::ZOOM::event([$conn]); -ok($val == 1, "call with an good connection returns its index"); +# Test the sequence of events that come from just creating the +# connection: there's the physical connect; the sending the Init +# request (sending the APDU results in sending the data); the +# receiving of the Init response (receiving the data results in +# receiving the APDU); then the END "event" indicating that there are +# no further events on the specific connection we're using; finally, +# event() will return 0 to indicate that there are no events pending +# on any of the connections we pass in. + +assert_event($conn, Net::Z3950::ZOOM::EVENT_CONNECT); +assert_event($conn, Net::Z3950::ZOOM::EVENT_SEND_APDU); +assert_event($conn, Net::Z3950::ZOOM::EVENT_SEND_DATA); +assert_event($conn, Net::Z3950::ZOOM::EVENT_RECV_DATA); +assert_event($conn, Net::Z3950::ZOOM::EVENT_RECV_APDU); +assert_event($conn, Net::Z3950::ZOOM::EVENT_END); +assert_event($conn, 0); ### Now we need to actually do something. + + +sub assert_event { + my($conn, $expected) = @_; + + my $val = Net::Z3950::ZOOM::event([$conn]); + if ($expected == 0) { + ok($val == 0, "no events left"); + return; + } + + ok($val == 1, "call with an good connection returns its index"); + + my $ev = Net::Z3950::ZOOM::connection_last_event($conn); + ok($ev == $expected, ("event is $ev (" . + Net::Z3950::ZOOM::event_str($ev) . + "), expected $expected (" . + Net::Z3950::ZOOM::event_str($expected) . ")")); +} + -- 1.7.10.4