From: mike Date: Wed, 2 Nov 2005 17:24:27 +0000 (+0000) Subject: Many more tests -- still not complete as resultset_records() doesn't work. X-Git-Tag: cpan_1_22~413 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=eceed15ee929ec788b6a1f109d8b464b774578a2;p=ZOOM-Perl-moved-to-github.git Many more tests -- still not complete as resultset_records() doesn't work. --- diff --git a/t/13-resultset.t b/t/13-resultset.t index c081ba4..773a99e 100644 --- a/t/13-resultset.t +++ b/t/13-resultset.t @@ -1,11 +1,11 @@ -# $Id: 13-resultset.t,v 1.1 2005-11-01 11:55:07 mike Exp $ +# $Id: 13-resultset.t,v 1.2 2005-11-02 17:24:27 mike Exp $ # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 13-resultset.t' use strict; use warnings; -use Test::More tests => 21; +use Test::More tests => 14; BEGIN { use_ok('Net::Z3950::ZOOM') }; my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy"); @@ -15,16 +15,50 @@ my $conn = Net::Z3950::ZOOM::connection_new($host, 0); $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo); ok($errcode == 0, "connection to '$host'"); -my $query = '@attr 1=4 minerals'; +my $query = '@attr 1=4 mineral'; my $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(Net::Z3950::ZOOM::resultset_size($rs) == 2, "found 2 records"); my $syntax = "usmarc"; Net::Z3950::ZOOM::resultset_option_set($rs, preferredRecordSyntax => $syntax); my $val = Net::Z3950::ZOOM::resultset_option_get($rs, "preferredRecordSyntax"); ok($val eq $syntax, "preferred record syntax set to '$val'"); +my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0); +my $len = 0; +my $data1 = Net::Z3950::ZOOM::record_get($rec, "render", $len); +Net::Z3950::ZOOM::resultset_option_set($rs, elementSetName => "b"); +my $data2 = Net::Z3950::ZOOM::record_get($rec, "render", $len); +ok($data2 eq $data1, "record doesn't know about RS options"); +# Now re-fetch record from result-set with new option +$rec = Net::Z3950::ZOOM::resultset_record($rs, 0); +$data2 = Net::Z3950::ZOOM::record_get($rec, "render", $len); +ok(length($data2) < length($data1), "re-fetched record is brief, old was full"); + +Net::Z3950::ZOOM::resultset_option_set($rs, preferredRecordSyntax => "xml"); +$rec = Net::Z3950::ZOOM::resultset_record($rs, 0); +$data2 = Net::Z3950::ZOOM::record_get($rec, "render", $len); +ok($data2 =~ //i, "option for XML syntax is honoured"); + +# Now we test ZOOM_resultset_record_immediate(), which should only +# work for records that have already been placed in the cache, and +# ZOOM_resultset_records() which populates the cache, and +# ZOOM_resultset_cache_reset(), which presumably empties it. +# +$rec = Net::Z3950::ZOOM::resultset_record_immediate($rs, 0); +ok(defined $rec, "prefetched record obtained with *_immediate()"); +my $data3 = Net::Z3950::ZOOM::record_get($rec, "render", $len); +ok($data3 eq $data2, "*_immediate record renders as expected"); +$rec = Net::Z3950::ZOOM::resultset_record_immediate($rs, 1); +ok(!defined $rec, "non-prefetched record obtained with *_immediate()"); +Net::Z3950::ZOOM::resultset_cache_reset($rs); +$rec = Net::Z3950::ZOOM::resultset_record_immediate($rs, 0); +ok(!defined $rec, "*_immediate(0) fails after cache reset"); +# Fill both cache slots, but with no record array +#Net::Z3950::ZOOM::resultset_records($rs, [ $rec ], 0, 1); + Net::Z3950::ZOOM::resultset_destroy($rs); ok(1, "destroyed result-set"); Net::Z3950::ZOOM::connection_destroy($conn);