Test is split into parts now, to be used by Test::Harness
[idzebra-moved-to-github.git] / perl / t / 06_retrieval.t
1 #!perl
2 # =============================================================================
3 # $Id: 06_retrieval.t,v 1.1 2003-03-03 00:44:39 pop Exp $
4 #
5 # Perl API header
6 # =============================================================================
7 BEGIN {
8     if ($ENV{PERL_CORE}) {
9         chdir 't' if -d 't';
10     }
11     push (@INC,'demo','blib/lib','blib/arch');
12 }
13
14 use strict;
15 use warnings;
16
17 use Test::More tests => 18;
18
19 # ----------------------------------------------------------------------------
20 # Session opening and closing
21 BEGIN {
22     use IDZebra;
23     IDZebra::logFile("test.log");
24     use_ok('IDZebra::Session'); 
25     use_ok('pod');
26 }
27
28
29 # ----------------------------------------------------------------------------
30 # Session opening and closing
31 my $sess = IDZebra::Session->open(configFile => 'demo/zebra.cfg',
32                                   groupName => 'demo2');
33 # ----------------------------------------------------------------------------
34 # search
35 our $filecount = 6;
36
37 my ($hits, $expected);
38
39 # Search 1 database
40 my $rs1 = $sess->search(cqlmap    => 'demo/cql.map',
41                         cql       => 'IDZebra',
42                         databases => [qw(demo1)]);
43
44 $expected = $filecount;
45 $hits = $rs1->count;
46 ok(($hits == $expected), "CQL search - found $hits/$expected records");
47
48 foreach my $rec ($rs1->records(from =>1,
49                               to   =>5)) {
50     isa_ok($rec,'IDZebra::RetrievalRecord');
51 }
52
53 my (@recs) = $rs1->records(from=>1,to=>1);
54
55 ok ($#recs == 0, "Fetched 1 record");
56
57 my $rec1 = shift(@recs);
58
59 isa_ok($rec1,'IDZebra::RetrievalRecord');
60 ok (($rec1->{errCode} == 0), "err: $rec1->{errCode}");
61 ok (($rec1->{errString} eq ""), "errString: $rec1->{errString}");
62 ok (($rec1->{position} == 1), "position: $rec1->{position}");
63 ok (($rec1->{base} eq 'demo1'), "base: $rec1->{base}");
64 ok (($rec1->{sysno}), "sysno: $rec1->{sysno}");
65 ok (($rec1->{score}), "score: $rec1->{score}");
66 ok (($rec1->{format} eq 'SUTRS'), "format: $rec1->{format}");
67 ok ((length($rec1->{buf}) > 0), "buf: ". length($rec1->{buf})." bytes");
68
69 # ----------------------------------------------------------------------------
70 # Close session
71
72 $sess->close;