From: mike Date: Wed, 12 Oct 2005 13:26:26 +0000 (+0000) Subject: Proper test-suite -- eleven tests, no unauthorised output. X-Git-Tag: cpan_1_22~469 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=51a3404326b18d3ff6e7978e1be0046c54ab1770;p=ZOOM-Perl-moved-to-github.git Proper test-suite -- eleven tests, no unauthorised output. --- diff --git a/t/1-Net-Z3950-ZOOM.t b/t/1-Net-Z3950-ZOOM.t index 2c94f6e..2727e7d 100644 --- a/t/1-Net-Z3950-ZOOM.t +++ b/t/1-Net-Z3950-ZOOM.t @@ -1,4 +1,4 @@ -# $Id: 1-Net-Z3950-ZOOM.t,v 1.2 2005-10-12 11:56:31 mike Exp $ +# $Id: 1-Net-Z3950-ZOOM.t,v 1.3 2005-10-12 13:26:26 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl Net-Z3950-ZOOM.t' @@ -8,7 +8,7 @@ # change 'tests => 1' to 'tests => last_test_to_print'; use strict; -use Test::More tests => 1; +use Test::More tests => 11; BEGIN { use_ok('Net::Z3950::ZOOM') }; ######################### @@ -16,43 +16,49 @@ BEGIN { use_ok('Net::Z3950::ZOOM') }; # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. -my $host = "indexdata.com/gils"; -$host = "localhost:3950"; -my $port = 0; -my $errcode; -my($errmsg, $addinfo) = ("dummy", "dummy"); +my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy"); -my $conn = Net::Z3950::ZOOM::connection_new($host, $port); +my $host = "no.such.host"; +my $conn = Net::Z3950::ZOOM::connection_new($host, 0); $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); -if ($errcode != 0) { - die("Can't connect to host '$host', port '$port': ", - "errcode='$errcode', errmsg='$errmsg', addinfo='$addinfo'"); -} +ok($errcode == Net::Z3950::ZOOM::ERROR_CONNECT && $addinfo eq $host, + "connection to non-existent host '$host' fails"); + +$host = "indexdata.com/gils"; +$conn = Net::Z3950::ZOOM::connection_new($host, 0); +$errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); +ok($errcode == 0, "connection to '$host' OK"); my $syntax = "usmarc"; Net::Z3950::ZOOM::connection_option_set($conn, preferredRecordSyntax => $syntax); my $val = Net::Z3950::ZOOM::connection_option_get($conn, "preferredRecordSyntax"); -die "set preferredRecordSyntax to '$syntax' but got '$val'" - if $val ne $syntax; +ok($val eq $syntax, "preferred record syntax set to '$val'"); + +my $query = '@attr @and 1=4 minerals'; +my $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query); +$errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); +ok($errcode == Net::Z3950::ZOOM::ERROR_INVALID_QUERY, + "search for invalid query '$query' fails"); -my $query = '@attr 1=4 minerals'; +$query = '@attr 1=4 minerals'; my $rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query); $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); -if ($errcode != 0) { - die("Can't search for '$query': ", - "errcode='$errcode', errmsg='$errmsg', addinfo='$addinfo'"); -} +ok($errcode == 0, "search for '$query' OK"); my $n = Net::Z3950::ZOOM::resultset_size($rs); +ok($n == 1, "found 1 record as expected"); -for (my $i = 0; $i < $n; $i++) { - my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i); - my $len = 0; - my $data = Net::Z3950::ZOOM::record_get($rec, "render", $len); - my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len); -} +my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0); +my $len = 0; +my $data = Net::Z3950::ZOOM::record_get($rec, "render", $len); +ok($data =~ /245 +\$a ISOTOPIC DATES OF ROCKS AND MINERALS/, + "rendered record has expected title"); +my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len); +ok($raw =~ /^00981n/, "raw record contains expected header"); Net::Z3950::ZOOM::resultset_destroy($rs); +ok(1, "destroyed result-set"); Net::Z3950::ZOOM::connection_destroy($conn); +ok(1, "destroyed connection");