X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=t%2F22-query.t;h=4ffbd632749b96275a359b48aec57c9049fcdbdb;hb=1033e0ddf7aff5acb977bebce871646e7bb83497;hp=77c7f4dbb6f4653211877243f19b0dd4da14266e;hpb=4314fa7d6d535b154d38771ffb1b66de639d3475;p=ZOOM-Perl-moved-to-github.git diff --git a/t/22-query.t b/t/22-query.t index 77c7f4d..4ffbd63 100644 --- a/t/22-query.t +++ b/t/22-query.t @@ -1,13 +1,13 @@ -# $Id: 22-query.t,v 1.2 2005-11-26 16:58:03 mike Exp $ - # Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl 22-query.t' use strict; use warnings; -use Test::More tests => 20; +use Test::More tests => 41; BEGIN { use_ok('ZOOM') }; +#ZOOM::Log::init_level(ZOOM::Log::mask_str("zoom")); + my $q; eval { $q = new ZOOM::Query() }; ok(defined $@ && $@ =~ /can.t create ZOOM::Query/, @@ -49,31 +49,83 @@ ok(1, "destroyed complex query"); # no other uses of query objects -- but we need to establish a # connection for it to work on first. -my $host = "indexdata.com/gils"; +my $host = "z3950.indexdata.com/gils"; my $conn; -eval { $conn = new ZOOM::Connection($host, 0) }; +eval { $conn = new ZOOM::Connection($host, 0, + preferredRecordSyntax => "usmarc") }; ok(!$@, "connection to '$host'"); -$conn->option(preferredRecordSyntax => "usmarc"); + ok(1, "[no need to create empty query]"); eval { $q = new ZOOM::Query::PQF('@and @attr 1=4 utah @attr 1=62 epicenter') }; ok(!$@, "created PQF query"); +check_record($conn, $q); +$q->destroy(); +# Now try a CQL query: this will fail due to lack of server support +ok(1, "[no need to create empty query]"); +eval { $q = new ZOOM::Query::CQL('title=utah and description=epicenter') }; +ok(!$@, "created CQL query"); my $rs; eval { $rs = $conn->search($q) }; -ok(!$@, "search"); +ok($@ && $@->isa("ZOOM::Exception") && + $@->code() == 107 && $@->diagset() eq "Bib-1", + "query rejected: error " . $@->code()); +$q->destroy(); -my $n = $rs->size(); -ok($n == 1, "found 1 record as expected"); +# Client-side compiled CQL: this will fail due to lack of config-file +ok(1, "[no need to create empty query]"); +eval { $q = new ZOOM::Query::CQL2RPN('title=utah and description=epicenter', + $conn) }; +ok($@ && $@->isa("ZOOM::Exception") && + $@->code() == ZOOM::Error::CQL_TRANSFORM && $@->diagset() eq "ZOOM", + "can't make CQL2RPN query: error " . $@->code()); -my $rec = $rs->record(0); -ok(1, "got record idenfified by query"); +# Do a successful client-compiled CQL search +ok(1, "[no need to create empty query]"); +$conn->option(cqlfile => "samples/cql/pqf.properties"); +eval { $q = new ZOOM::Query::CQL2RPN('title=utah and description=epicenter', + $conn) }; +ok(!$@, "created CQL2RPN query"); +check_record($conn, $q); +$q->destroy(); -my $data = $rec->render(); -ok(1, "rendered record"); -ok($data =~ /^035 +\$a ESDD0006$/m, "record is the expected one"); +# Client-side compiled CCL: this will fail due to lack of config-file +ok(1, "[no need to create empty query]"); +eval { $q = new ZOOM::Query::CCL2RPN('ti=utah and ab=epicenter', $conn) }; +ok($@ && $@->isa("ZOOM::Exception") && + $@->code() == ZOOM::Error::CCL_CONFIG && $@->diagset() eq "ZOOM", + "can't make CCL2RPN query: error " . $@->code()); -$rs->destroy(); +# Do a successful client-compiled CCL search +ok(1, "[no need to create empty query]"); +$conn->option(cclfile => "samples/ccl/default.bib"); +eval { $q = new ZOOM::Query::CCL2RPN('ti=utah and ab=epicenter', $conn) }; +ok(!$@, "created CCL2RPN query"); +check_record($conn, $q); $q->destroy(); + $conn->destroy(); ok(1, "destroyed all objects"); + + +sub check_record { + my($conn, $q) = @_; + + my $rs; + eval { $rs = $conn->search($q) }; + ok(!$@, "search"); + die $@ if $@; + + my $n = $rs->size(); + ok($n == 1, "found 1 record as expected"); + + my $rec = $rs->record(0); + ok(1, "got record idenfified by query"); + + my $data = $rec->render(); + ok(1, "rendered record"); + ok($data =~ /^035 +\$a ESDD0006$/m, "record is the expected one"); + + $rs->destroy(); +}