1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl 24-sorting.t'
6 use Test::More tests => 29;
9 BEGIN { use_ok('ZOOM') };
11 my $host = "z3950.indexdata.com/gils";
13 eval { $conn = new ZOOM::Connection($host, 0) };
14 ok(!$@, "connection to '$host'");
16 my $qstr = '@attr 1=4 map';
17 my $query = new ZOOM::Query::PQF($qstr);
18 eval { $query->sortby("1=4 <i") };
19 ok(!$@, "sort specification accepted");
21 eval { $rs = $conn->search($query) };
22 ok(!$@, "search for '$qstr'");
24 ok($n == 5, "found $n records (expected 5)");
26 $rs->option(preferredRecordSyntax => "usmarc");
27 my $previous = ""; # Sorts before all legitimate titles
28 foreach my $i (1 .. $n) {
29 my $rec = $rs->record($i-1);
30 ok(defined $rec, "got record $i of $n");
31 my $raw = $rec->raw();
32 my $marc = new_from_usmarc MARC::Record($raw);
33 my $title = $marc->title();
34 ok($title ge $previous, "title '$title' ge previous '$previous'");
38 # Now reverse the order of sorting
39 my $status = $rs->sort("yaz", "1=4>i");
40 ok($status < 0, "malformed sort criterion rejected");
41 $status = $rs->sort("yaz", "1=4 >i");
42 ok($status == 0, "sort criterion accepted");
44 $previous = "z"; # Sorts after all legitimate titles
45 foreach my $i (1 .. $n) {
46 my $rec = $rs->record($i-1);
47 ok(defined $rec, "got record $i of $n");
48 my $raw = $rec->raw();
49 my $marc = new_from_usmarc MARC::Record($raw);
50 my $title = $marc->title();
51 ok($title le $previous, "title '$title' le previous '$previous'");
56 ok(1, "destroyed result-set");
58 ok(1, "destroyed connection");