From: mike Date: Thu, 3 Nov 2005 16:32:41 +0000 (+0000) Subject: New -- tests OO interface to advanced result-set functionality. X-Git-Tag: cpan_1_22~404 X-Git-Url: http://lists.indexdata.com/cgi-bin?a=commitdiff_plain;h=5909129b2f0dda765dfbf1de46a2f9b7e179a04d;p=ZOOM-Perl-moved-to-github.git New -- tests OO interface to advanced result-set functionality. --- diff --git a/t/23-resultset.t b/t/23-resultset.t new file mode 100644 index 0000000..2c5c3be --- /dev/null +++ b/t/23-resultset.t @@ -0,0 +1,81 @@ +# $Id: 23-resultset.t,v 1.1 2005-11-03 16:32:41 mike Exp $ + +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl 23-resultset.t' + +use strict; +use warnings; +use Test::More tests => 19; +BEGIN { use_ok('ZOOM') }; + + + + +my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy"); + + + + +my $host = "indexdata.com/gils"; +my $conn; +eval { $conn = new ZOOM::Connection($host, 0) }; +ok(!$@, "connection to '$host'"); + +my $query = '@attr 1=4 mineral'; +my $rs; +eval { $rs = $conn->search_pqf($query) }; +ok(!$@, "search for '$query'"); +ok($rs->size() == 2, "found 2 records"); + +my $syntax = "usmarc"; +$rs->option(preferredRecordSyntax => $syntax); +my $val = $rs->option("preferredRecordSyntax"); +ok($val eq $syntax, "preferred record syntax set to '$val'"); + +my $rec = $rs->record(0); +my $data1 = $rec->render(); +$rs->option(elementSetName => "b"); +my $data2 = $rec->render(); +ok($data2 eq $data1, "record doesn't know about RS options"); +# Now re-fetch record from result-set with new option +$rec = $rs->record(0); +$data2 = $rec->render(); +ok(length($data2) < length($data1), "re-fetched record is brief, old was full"); + +$rs->option(preferredRecordSyntax => "xml"); +$rec = $rs->record(0); +$data2 = $rec->render(); +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 = $rs->record_immediate(0); +ok(defined $rec, "prefetched record obtained with _immediate()"); +my $data3 = $rec->render(); +ok($data3 eq $data2, "_immediate record renders as expected"); +$rec = $rs->record_immediate(1); +#{ use Data::Dumper; print "rec=$rec = ", Dumper($rec) } +ok(!defined $rec, "non-prefetched record obtained with _immediate()"); +$rs->cache_reset(); +$rec = $rs->record_immediate(0); +ok(!defined $rec, "_immediate(0) fails after cache reset"); +# Fill both cache slots, but with no record array +my $tmp = $rs->records(0, 2, 0); +ok(!defined $tmp, "resultset_records() returns undef as expected"); +$rec = $rs->record_immediate(0); +ok(defined $rec, "_immediate(0) ok after resultset_records()"); +# Fetch all records at once using records() +$tmp = $rs->records(0, 2, 1); +ok(@$tmp == 2, "resultset_records() returned two records"); +$data3 = $tmp->[0]->render(); +ok($data3 eq $data2, "record returned from resultset_records() renders as expected"); +$rec = $rs->record_immediate(1); +ok(defined $rec, "_immediate(1) ok after resultset_records()"); + +$rs->destroy(); +ok(1, "destroyed result-set"); +$conn->destroy(); +ok(1, "destroyed connection");