1 # $Id: 22-query.t,v 1.2 2005-11-26 16:58:03 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 22-query.t'
8 use Test::More tests => 20;
9 BEGIN { use_ok('ZOOM') };
12 eval { $q = new ZOOM::Query() };
13 ok(defined $@ && $@ =~ /can.t create ZOOM::Query/,
14 "instantiation of ZOOM::Query base class rejected");
16 ok(1, "[no query to destroy]");
18 ok(1, "[no need to recreate 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 $q = new ZOOM::Query::CQL("creator=pike and");
24 ok(defined $q, "invalid CQL accepted (pass-through)");
25 $q = new ZOOM::Query::CQL("creator=pike and subject=unix");
26 ok(defined $q, "valid CQL accepted");
28 eval { $q = new ZOOM::Query::PQF('@and @attr 1=1003 pike') };
29 ok($@ && $@->isa("ZOOM::Exception") &&
30 $@->code() == ZOOM::Error::QUERY_PQF,
31 "invalid PQF rejected");
33 eval { $q = new ZOOM::Query::PQF('@and @attr 1=1003 pike @attr 1=21 unix') };
34 ok(!$@, "set PQF into query");
36 eval { $q->sortby("") };
37 ok($@ && $@->isa("ZOOM::Exception") &&
38 $@->code() == ZOOM::Error::SORTBY,
39 "zero-length sort criteria rejected");
41 eval { $q->sortby("foo bar baz") };
42 ok(!$@, "sort criteria accepted");
45 ok(1, "destroyed complex query");
47 # Up till now, we have been doing query management. Now to actually
48 # use the query. This is done using Connection::search() -- there are
49 # no other uses of query objects -- but we need to establish a
50 # connection for it to work on first.
52 my $host = "indexdata.com/gils";
54 eval { $conn = new ZOOM::Connection($host, 0) };
55 ok(!$@, "connection to '$host'");
56 $conn->option(preferredRecordSyntax => "usmarc");
58 ok(1, "[no need to create empty query]");
59 eval { $q = new ZOOM::Query::PQF('@and @attr 1=4 utah @attr 1=62 epicenter') };
60 ok(!$@, "created PQF query");
63 eval { $rs = $conn->search($q) };
67 ok($n == 1, "found 1 record as expected");
69 my $rec = $rs->record(0);
70 ok(1, "got record idenfified by query");
72 my $data = $rec->render();
73 ok(1, "rendered record");
74 ok($data =~ /^035 +\$a ESDD0006$/m, "record is the expected one");
79 ok(1, "destroyed all objects");