New.
[ZOOM-Perl-moved-to-github.git] / t / 15-scan.t
1 # $Id: 15-scan.t,v 1.1 2005-11-08 10:20:59 mike Exp $
2
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl 15-scan.t'
5
6 use strict;
7 use warnings;
8 use Test::More tests => 46;
9 use MARC::Record;
10
11 BEGIN { use_ok('Net::Z3950::ZOOM') };
12
13 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
14
15 my $host = "indexdata.com/gils";
16 my $conn = Net::Z3950::ZOOM::connection_new($host, 0);
17 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
18 ok($errcode == 0, "connection to '$host'");
19
20 my $startterm = "coelophysis";
21 my $ss = Net::Z3950::ZOOM::connection_scan($conn, $startterm);
22 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
23 ok($errcode == 0, "scan for '$startterm'");
24
25 my $n = Net::Z3950::ZOOM::scanset_size($ss);
26 ok(defined $n, "got size");
27 ok($n == 10, "got 10 terms");
28
29 my $previous = "";              # Sorts before all legitimate terms
30 my($occ, $len) = (0, 0);
31 foreach my $i (1 .. $n) {
32     my $term = Net::Z3950::ZOOM::scanset_term($ss, $i-1, $occ, $len);
33     ok(defined $term && $len eq length($term),
34        "got term $i of $n: '$term' ($occ occurences)");
35     ok($term ge $previous, "term '$term' ge previous '$previous'");
36     $previous = $term;
37     my $disp = Net::Z3950::ZOOM::scanset_display_term($ss, $i-1, $occ, $len);
38     ok(defined $disp && $len eq length($disp),
39        "display term $i of $n: '$disp' ($occ occurences)");
40     ok($disp eq $term, "display term $i identical to term");
41 }
42
43 Net::Z3950::ZOOM::scanset_destroy($ss);
44 ok(1, "destroyed scanset");
45
46 #   ### There remains much testing still to do with scan, but I can't
47 #       do it until Adam better explains ZOOM-C's scan functionality.
48 #       Specifically, there is no obvious way to scan more than ten
49 #       terms, nor any obvious use for scanset_option_set() and
50 #       scanset_option_get(); nor can I find a server that returns
51 #       display terms different from its terms.