1 # $Id: 12-query.t,v 1.1 2005-10-26 16:25:50 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 12-query.t'
8 use Test::More tests => 19;
9 BEGIN { use_ok('Net::Z3950::ZOOM') };
11 my $q = Net::Z3950::ZOOM::query_create();
12 ok(defined $q, "create empty query");
14 Net::Z3950::ZOOM::query_destroy($q);
15 ok(1, "destroyed empty query");
17 $q = Net::Z3950::ZOOM::query_create();
18 ok(defined $q, "recreated empty query");
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
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");
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");
33 $res = Net::Z3950::ZOOM::query_sortby($q, "");
34 ok($res < 0, "zero-length sort criteria rejected");
36 $res = Net::Z3950::ZOOM::query_sortby($q, "foo bar baz");
37 ok($res == 0, "sort criteria accepted");
39 Net::Z3950::ZOOM::query_destroy($q);
40 ok(1, "destroyed complex query");
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.
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'");
53 my $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");
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");