1 # $Id: 25-scan.t,v 1.8 2006-06-13 16:44:21 mike Exp $
3 # Before `make install' is performed this script should be runnable with
4 # `make test'. After `make install' it should work as `perl 25-scan.t'
8 use Test::More tests => 87;
10 BEGIN { use_ok('ZOOM') };
12 my $host = "indexdata.com/gils";
14 eval { $conn = new ZOOM::Connection($host, 0) };
15 ok(!$@, "connection to '$host'");
17 my($ss, $n) = scan($conn, 0, "w", 10);
21 my $previous = ""; # Sorts before all legitimate terms
22 foreach my $i (1 .. $n) {
23 my($term, $occ) = $ss->term($i-1);
25 "got term $i of $n: '$term' ($occ occurences)");
26 ok($term ge $previous, "term '$term' ge previous '$previous'");
29 (my $disp, $occ) = $ss->display_term($i-1);
31 "display term $i of $n: '$disp' ($occ occurences)");
32 ok($disp eq $term, "display term $i identical to term");
36 ok(1, "destroyed scanset");
37 eval { $ss->destroy() };
38 ok(defined $@ && $@ =~ /been destroy\(\)ed/,
39 "can't re-destroy scanset");
41 # Now re-scan, but only for words that occur in the title
42 # This time, use a Query object for the start-term
43 ($ss, $n) = scan($conn, 1, new ZOOM::Query::PQF('@attr 1=4 w'), 6);
45 $previous = ""; # Sorts before all legitimate terms
46 foreach my $i (1 .. $n) {
47 my($term, $occ) = $ss->term($i-1);
49 "got title term $i of $n: '$term' ($occ occurences)");
50 ok($term ge $previous, "title term '$term' ge previous '$previous'");
52 ok((grep { $term eq $_ } @terms), "title term was in term list");
56 ok(1, "destroyed second scanset");
58 # Now re-do the same scan, but limiting the results to four terms at a
59 # time. This time, use a CQL query
60 $conn->option(number => 4);
61 $conn->option(cqlfile => "samples/cql/pqf.properties");
63 ($ss, $n) = scan($conn, 1, new ZOOM::Query::CQL('title=w'), 4);
64 # Get last term and use it as seed for next scan
65 my($term, $occ) = $ss->term($n-1);
66 ok($ss->option("position") == 1,
67 "seed-term is start of returned list");
69 "got last title term '$term' to use as seed");
72 ok(1, "destroyed third scanset");
74 $conn->option(cclfile => "samples/ccl/default.bib");
75 ($ss, $n) = scan($conn, 1, new ZOOM::Query::CCL2RPN('ti=w', $conn), 4);
76 # Get last term and use it as seed for next scan
77 ($term, $occ) = $ss->term($n-1);
78 ok($ss->option("position") == 1,
79 "seed-term is start of returned list");
81 "got last title term '$term' to use as seed");
84 ok(1, "destroyed fourth scanset");
86 # We want the seed-term to be in "position zero", i.e. just before the start
87 $conn->option(position => 0);
88 ($ss, $n) = scan($conn, 0, "\@attr 1=4 $term", 2);
89 ok($ss->option("position") == 0,
90 "seed-term before start of returned list");
92 # Silly test of option setting and getting
93 $ss->option(position => "fruit");
94 ok($ss->option("position") eq "fruit",
95 "option setting/getting works");
98 ok(1, "destroyed fifth scanset");
100 # Some more testing still to do: see comment in "15-scan.t"
104 my($conn, $startterm_is_query, $startterm, $nexpected) = @_;
108 if ($startterm_is_query) {
109 $ss = $conn->scan($startterm);
111 $ss = $conn->scan_pqf($startterm);
114 ok(!$@, "scan for '$startterm'");
117 ok(defined $n, "got size");
118 ok($n == $nexpected, "got $n terms (expected $nexpected)");