Typo.
[ZOOM-Perl-moved-to-github.git] / t / 14-sorting.t
1 # $Id: 14-sorting.t,v 1.2 2005-11-04 16:34:16 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 #   ### At present, this test fails -- so far as I can see, because
7 #       the underlying ZOOM-C sorting functionality is broken, as
8 #       verified using "zoomsh" with the commands:
9 #
10 #               ZOOM>open indexdata.dk/gils
11 #               ZOOM>find @attr 1=4 map
12 #               ZOOM>sort 1=4
13 #               ZOOM>show 0 5
14 #
15 #       Hopefully Adam will fix the underlying code, and then this
16 #       will Just Work.
17
18 use strict;
19 use warnings;
20 use Test::More tests => 26;
21 use MARC::Record;
22
23 BEGIN { use_ok('Net::Z3950::ZOOM') };
24
25 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
26
27 my $host = "indexdata.com/gils";
28 my $conn = Net::Z3950::ZOOM::connection_new($host, 0);
29 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
30 ok($errcode == 0, "connection to '$host'");
31
32 my $qstr = '@attr 1=4 map';
33 my $query = Net::Z3950::ZOOM::query_create();
34 Net::Z3950::ZOOM::query_prefix($query, $qstr);
35 Net::Z3950::ZOOM::query_sortby($query, "1=4<i");
36 my $rs = Net::Z3950::ZOOM::connection_search($conn, $query);
37 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
38 ok($errcode == 0, "search for '$qstr'");
39 my $n = Net::Z3950::ZOOM::resultset_size($rs);
40 ok($n == 5, "found $n records (expected 5)");
41
42 Net::Z3950::ZOOM::resultset_option_set($rs, preferredRecordSyntax => "usmarc");
43 my $previous = "";              # Sorts before all legitimate titles
44 foreach my $i (1 .. $n) {
45     my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i-1);
46     ok(defined $rec, "got record $i of $n");
47     my $len = 0;
48     my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
49     my $marc = new_from_usmarc MARC::Record($raw);
50     my $title = $marc->title();
51     ok($title ge $previous, "title '$title' ge previous '$previous'");
52     $previous = $title;
53 }
54
55 # Now reverse the order of sorting
56 Net::Z3950::ZOOM::resultset_sort($rs, "dummy", "1=4>i");
57 ### There's no way to check for success, as this is a void function
58
59 $previous = "z";                # Sorts after all legitimate titles
60 foreach my $i (1 .. $n) {
61     my $rec = Net::Z3950::ZOOM::resultset_record($rs, $i-1);
62     ok(defined $rec, "got record $i of $n");
63     my $len = 0;
64     my $raw = Net::Z3950::ZOOM::record_get($rec, "raw", $len);
65     my $marc = new_from_usmarc MARC::Record($raw);
66     my $title = $marc->title();
67     ok($title le $previous, "title '$title' le previous '$previous'");
68     $previous = $title;
69 }
70
71 Net::Z3950::ZOOM::resultset_destroy($rs);
72 ok(1, "destroyed result-set");
73 Net::Z3950::ZOOM::connection_destroy($conn);
74 ok(1, "destroyed connection");