Remove outdated comment about sorting not working.
[ZOOM-Perl-moved-to-github.git] / t / 14-sorting.t
1 # $Id: 14-sorting.t,v 1.4 2005-11-07 16:30:41 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 14-sorting.t'
5
6 use strict;
7 use warnings;
8 use Test::More tests => 27;
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 $qstr = '@attr 1=4 map';
21 my $query = Net::Z3950::ZOOM::query_create();
22 Net::Z3950::ZOOM::query_prefix($query, $qstr);
23 my $res = Net::Z3950::ZOOM::query_sortby($query, "1=4 <i");
24 ok($res == 0, "sort specification accepted");
25 my $rs = Net::Z3950::ZOOM::connection_search($conn, $query);
26 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
27 ok($errcode == 0, "search for '$qstr'");
28 my $n = Net::Z3950::ZOOM::resultset_size($rs);
29 ok($n == 5, "found $n records (expected 5)");
30
31 Net::Z3950::ZOOM::resultset_option_set($rs, preferredRecordSyntax => "usmarc");
32 my $previous = "";              # Sorts before all legitimate titles
33 foreach my $i (1 .. $n) {
34     my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i-1);
35     ok(defined $rec, "got record $i of $n");
36     my $len = 0;
37     my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
38     my $marc = new_from_usmarc MARC::Record($raw);
39     my $title = $marc->title();
40     ok($title ge $previous, "title '$title' ge previous '$previous'");
41     $previous = $title;
42 }
43
44 # Now reverse the order of sorting
45 Net::Z3950::ZOOM::resultset_sort($rs, "dummy", "1=4 >i");
46 ### There's no way to check for success, as this is a void function
47
48 $previous = "z";                # Sorts after all legitimate titles
49 foreach my $i (1 .. $n) {
50     my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i-1);
51     ok(defined $rec, "got record $i of $n");
52     my $len = 0;
53     my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
54     my $marc = new_from_usmarc MARC::Record($raw);
55     my $title = $marc->title();
56     ok($title le $previous, "title '$title' le previous '$previous'");
57     $previous = $title;
58 }
59
60 Net::Z3950::ZOOM::resultset_destroy($rs);
61 ok(1, "destroyed result-set");
62 Net::Z3950::ZOOM::connection_destroy($conn);
63 ok(1, "destroyed connection");