Tweaks.
[ZOOM-Perl-moved-to-github.git] / t / 12-query.t
1 # $Id: 12-query.t,v 1.2 2005-10-26 16:31:39 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 12-query.t'
5
6 use strict;
7 use warnings;
8 use Test::More tests => 15;
9 BEGIN { use_ok('Net::Z3950::ZOOM') };
10
11 my $q = Net::Z3950::ZOOM::query_create();
12 ok(defined $q, "create empty query");
13
14 Net::Z3950::ZOOM::query_destroy($q);
15 ok(1, "destroyed empty query");
16
17 $q = Net::Z3950::ZOOM::query_create();
18 ok(defined $q, "recreated empty query");
19
20 # Invalid CQL is not recognised as such, because ZOOM-C does not
21 # attempt to parse it: it just gets passed to the server when the
22 # query is used.
23 my $res = Net::Z3950::ZOOM::query_cql($q, "creator=pike and");
24 ok($res == 0, "invalid CQL accepted (pass-through)");
25 $res = Net::Z3950::ZOOM::query_cql($q, "creator=pike and subject=unix");
26 ok($res == 0, "valid CQL accepted");
27
28 $res = Net::Z3950::ZOOM::query_prefix($q, '@and @attr 1=1003 pike');
29 ok($res < 0, "invalid PQF rejected");
30 $res = Net::Z3950::ZOOM::query_prefix($q, '@and @attr 1=1003 pike @attr 1=21 unix');
31 ok($res == 0, "set PQF into query");
32
33 $res = Net::Z3950::ZOOM::query_sortby($q, "");
34 ok($res < 0, "zero-length sort criteria rejected");
35
36 $res = Net::Z3950::ZOOM::query_sortby($q, "foo bar baz");
37 ok($res == 0, "sort criteria accepted");
38
39 Net::Z3950::ZOOM::query_destroy($q);
40 ok(1, "destroyed complex query");
41
42 # Up till now, we have been doing query management.  Now to actually
43 # use the query.  This is done using connection_search() -- there are
44 # no other uses of query objects -- but we need to establish a
45 # connection for it to work on first.
46
47 my $host = "indexdata.com/gils";
48 my $conn = Net::Z3950::ZOOM::connection_new($host, 0);
49 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
50 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
51 ok($errcode == 0, "connection to '$host'");
52
53 $q = Net::Z3950::ZOOM::query_create();
54 ok(defined $q, "create empty query");
55 $res = Net::Z3950::ZOOM::query_prefix($q, '@attr 1=21 mineral');
56 ok($res == 0, "set PQF into query");
57
58 my $rs = Net::Z3950::ZOOM::connection_search($conn, $q);
59 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
60 ok($errcode == 0, "search");