-# $Id: 12-query.t,v 1.4 2005-12-22 09:16:43 mike Exp $
+# $Id: 12-query.t,v 1.7 2006-06-15 15:43:19 mike Exp $
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 12-query.t'
use strict;
use warnings;
-use Test::More tests => 32;
+use Test::More tests => 41;
BEGIN { use_ok('Net::Z3950::ZOOM') };
# Net::Z3950::ZOOM::yaz_log_init_level(Net::Z3950::ZOOM::yaz_log_mask_str("zoom"));
ok(defined $q, "create empty query");
$res = Net::Z3950::ZOOM::query_cql($q, 'title=utah and description=epicenter');
ok($res == 0, "valid CQL accepted");
-check_failure($conn, $q, 107, "Bib-1");
+my $rs = Net::Z3950::ZOOM::connection_search($conn, $q);
+my $diagset = "dummy";
+$errcode = Net::Z3950::ZOOM::connection_error_x($conn, $errmsg, $addinfo,
+ $diagset);
+ok($errcode == 107 && $diagset eq "Bib-1",
+ "query rejected: error " . $errcode);
Net::Z3950::ZOOM::query_destroy($q);
# Client-side compiled CQL: this will fail due to lack of config-file
$res = Net::Z3950::ZOOM::query_cql2rpn($q,
'title=utah and description=epicenter',
$conn);
-my $diagset = "";
$errcode = Net::Z3950::ZOOM::connection_error_x($conn, $errmsg, $addinfo,
$diagset);
ok($res < 0 &&
"can't make CQL2RPN query: error " . $errcode);
Net::Z3950::ZOOM::query_destroy($q);
-# Finally, do a successful client-compiled CQL search
+# Do a successful client-compiled CQL search
$q = Net::Z3950::ZOOM::query_create();
ok(defined $q, "create empty query");
Net::Z3950::ZOOM::connection_option_set($conn, cqlfile =>
check_record($conn, $q);
Net::Z3950::ZOOM::query_destroy($q);
+# Client-side compiled CCL: this will fail due to incorrect syntax
+$q = Net::Z3950::ZOOM::query_create();
+ok(defined $q, "create empty query");
+my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0);
+
+### change documentation
+$res = Net::Z3950::ZOOM::query_ccl2rpn($q,
+ 'ti=utah and',
+ "ti u=4 s=pw\nab u=62 s=pw",
+ $ccl_errcode, $ccl_errstr, $ccl_errpos);
+ok($res < 0 &&
+ $ccl_errcode == Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED,
+ "can't make CCL2RPN query: error $ccl_errcode ($ccl_errstr)");
+Net::Z3950::ZOOM::query_destroy($q);
+
+# Do a successful client-compiled CCL search
+$q = Net::Z3950::ZOOM::query_create();
+ok(defined $q, "create empty query");
+Net::Z3950::ZOOM::connection_option_set($conn, cclfile =>
+ "samples/ccl/default.bib");
+$res = Net::Z3950::ZOOM::query_ccl2rpn($q,
+ 'ti=utah and ab=epicenter',
+ "ti u=4 s=pw\nab u=62 s=pw",
+ $ccl_errcode,
+ $ccl_errstr,
+ $ccl_errpos);
+ok($res == 0, "created CCL2RPN query");
+check_record($conn, $q);
+Net::Z3950::ZOOM::query_destroy($q);
+
Net::Z3950::ZOOM::connection_destroy($conn);
ok(1, "destroyed all objects");
Net::Z3950::ZOOM::resultset_destroy($rs);
}
-
-
-sub check_failure {
- my($conn, $q, $expected_error, $expected_dset) = @_;
-
- my $rs = Net::Z3950::ZOOM::connection_search($conn, $q);
- my($errcode, $errmsg, $addinfo, $diagset) = (undef, "dummy", "dummy", "");
- $errcode = Net::Z3950::ZOOM::connection_error_x($conn, $errmsg, $addinfo,
- $diagset);
- ok($errcode == $expected_error && $diagset eq $expected_dset,
- "query rejected: error " . $errcode);
-}