1 # $Id: 22-query.t,v 1.1 2005-10-31 15:11:08 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]");
27 my $res; ### not needed in OO interface
34 # Invalid CQL is not recognised as such, because ZOOM-C does not
35 # attempt to parse it: it just gets passed to the server when the
37 $q = new ZOOM::Query::CQL("creator=pike and");
38 ok(defined $q, "invalid CQL accepted (pass-through)");
39 $q = new ZOOM::Query::CQL("creator=pike and subject=unix");
40 ok(defined $q, "valid CQL accepted");
42 eval { $q = new ZOOM::Query::PQF('@and @attr 1=1003 pike') };
43 ok($@ && $@->isa("ZOOM::Exception") &&
44 $@->code() == ZOOM::Error::QUERY_PQF,
45 "invalid PQF rejected");
47 eval { $q = new ZOOM::Query::PQF('@and @attr 1=1003 pike @attr 1=21 unix') };
48 ok(!$@, "set PQF into query");
50 eval { $q->sortby("") };
51 ok($@ && $@->isa("ZOOM::Exception") &&
52 $@->code() == ZOOM::Error::SORTBY,
53 "zero-length sort criteria rejected");
55 eval { $q->sortby("foo bar baz") };
56 ok(!$@, "sort criteria accepted");
59 ok(1, "destroyed complex query");
61 # Up till now, we have been doing query management. Now to actually
62 # use the query. This is done using Connection::search() -- there are
63 # no other uses of query objects -- but we need to establish a
64 # connection for it to work on first.
66 my $host = "indexdata.com/gils";
68 eval { $conn = new ZOOM::Connection($host, 0) };
69 ok(!$@, "connection to '$host'");
70 $conn->option(preferredRecordSyntax => "usmarc");
72 ok(1, "[no need to create empty query]");
73 eval { $q = new ZOOM::Query::PQF('@and @attr 1=4 utah @attr 1=62 epicenter') };
74 ok(!$@, "created PQF query");
77 eval { $rs = $conn->search($q) };
81 ok($n == 1, "found 1 record as expected");
83 my $rec = $rs->record(0);
84 ok(1, "got record idenfified by query");
86 my $data = $rec->render();
87 ok(1, "rendered record");
88 ok($data =~ /^035 +\$a ESDD0006$/m, "record is the expected one");
93 ok(1, "destroyed all objects");