X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=t%2F1-Net-Z3950-ZOOM.t;h=a35894eedfe2b8eb5acba0f667f37f9d4d4514bc;hb=08672ace7ae2c0112e1ded649f59c5ffb379d764;hp=2c94f6e1a5073ece93a9aa764cb8cb06d944b14e;hpb=9f3877d67edcf78024841bbe8291d742c861a368;p=ZOOM-Perl-moved-to-github.git diff --git a/t/1-Net-Z3950-ZOOM.t b/t/1-Net-Z3950-ZOOM.t index 2c94f6e..a35894e 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.4 2005-10-12 14:36:17 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 1=4 minerals'; +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); -if ($errcode != 0) { - die("Can't search for '$query': ", - "errcode='$errcode', errmsg='$errmsg', addinfo='$addinfo'"); -} +ok($errcode == Net::Z3950::ZOOM::ERROR_INVALID_QUERY, + "search for invalid query '$query' fails"); + +$query = '@attr 1=4 minerals'; +$rs = Net::Z3950::ZOOM::connection_search_pqf($conn, $query); +$errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $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");