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