Add Ubuntu quantal
[ZOOM-Perl-moved-to-github.git] / t / 12-query.t
index fac08b3..d21204b 100644 (file)
@@ -1,11 +1,9 @@
-# $Id: 12-query.t,v 1.5 2005-12-22 09:23:52 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"));
@@ -46,7 +44,7 @@ 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 = Net::Z3950::ZOOM::connection_new($host, 0);
 my($errcode, $errmsg, $addinfo) = (undef, "dummy", "dummy");
 $errcode = Net::Z3950::ZOOM::connection_error($conn, $errmsg, $addinfo);
@@ -90,7 +88,7 @@ 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 =>
@@ -102,6 +100,33 @@ ok($res == 0, "created CQL2RPN query");
 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);
+
+$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");
+$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");
 
@@ -120,8 +145,7 @@ sub check_record {
     my $rec = Net::Z3950::ZOOM::resultset_record($rs, 0);
     ok(1, "got record idenfified by query");
 
-    my $len = 0;
-    my $data = Net::Z3950::ZOOM::record_get($rec, "render", $len);
+    my $data = Net::Z3950::ZOOM::record_get($rec, "render");
     ok(1, "rendered record");
     ok($data =~ /^035    \$a ESDD0006$/m, "record is the expected one");