From 4c98cedc7dd307771716b74e36865795df11c2e4 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 12 Apr 2006 12:16:45 +0000 Subject: [PATCH] New, derived from 19-events.t --- t/29-events.t | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 t/29-events.t diff --git a/t/29-events.t b/t/29-events.t new file mode 100644 index 0000000..adc257a --- /dev/null +++ b/t/29-events.t @@ -0,0 +1,86 @@ +# $Id: 29-events.t,v 1.1 2006-04-12 12:16:45 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 => 23; + +BEGIN { use_ok('ZOOM') }; + +ok(ZOOM::event_str(ZOOM::Event::CONNECT) eq "connect", + "connect event properly translated"); + +my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy"); + +my $options = new ZOOM::Options(); +$options->option(async => 1); + +my $host = "indexdata.com/gils"; +my $conn = create ZOOM::Connection($options); +eval { $conn->connect($host) }; +ok(!$@, "connection to '$host'"); + +ok(1, "non-reference argument rejected"); +ok(1, "non-array reference argument rejected"); + +my $val = ZOOM::event([]); +ok($val == -3, "empty array reference argument rejected"); + +ok(1, "huge array reference argument rejected"); + +# See comments in 19-event.t +assert_event_stream($conn, + ZOOM::Event::CONNECT, + ZOOM::Event::SEND_APDU, + ZOOM::Event::SEND_DATA, + ZOOM::Event::RECV_DATA, + ZOOM::Event::RECV_APDU, + ZOOM::Event::ZEND, + 0); + +$conn->option(count => 1); +my $rs; +eval { $rs = $conn->search_pqf("mineral") }; +ok(!$@, "search for 'mineral'"); + +assert_event_stream($conn, + ZOOM::Event::SEND_APDU, + ZOOM::Event::SEND_DATA, + -(ZOOM::Event::RECV_DATA), + ZOOM::Event::RECV_APDU, + ZOOM::Event::RECV_SEARCH, + ZOOM::Event::RECV_RECORD, + ZOOM::Event::ZEND, + 0); + +# See comments in 19-event.t +sub assert_event_stream { + my($conn, @expected) = @_; + + my $previousExpected = -1; + my $expected = shift @expected; + while (defined $expected) { + my $val = ZOOM::event([$conn]); + if ($expected == 0) { + ok($val == 0, "no events left"); + $expected = shift @expected; + next; + } + + die "impossible" if $val != 1; + my $ev = $conn->last_event(); + next if $previousExpected > 0 && $ev == $previousExpected; + + if ($expected < 0) { + $expected = -$expected; + $previousExpected = $expected; + } + ok($ev == $expected, ("event is $ev (" . + ZOOM::event_str($ev) . + "), expected $expected (" . + ZOOM::event_str($expected) . ")")); + $expected = shift @expected; + } +} -- 1.7.10.4