1 # $Id: 14-sorting.t,v 1.1 2005-11-04 16:13:42 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 14-sorting.t'
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:
10 # ZOOM>open indexdata.dk/gils
11 # ZOOM>find @attr 1=4 map
15 # Hopefully Adam will fix the underlying code, and then this
20 use Test::More tests => 26;
23 BEGIN { use_ok('Net::Z3950::ZOOM') };
25 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
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'");
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 eq 5, "found $n records (expected 5)");
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");
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'");
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
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");
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'");
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");